summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorHunter Haugen <hunter@puppetlabs.com>2014-06-18 13:54:51 -0700
committerHunter Haugen <hunter@puppetlabs.com>2014-07-11 14:18:29 -0700
commit6624f40651f44e184878a9fbb862bda886d899e8 (patch)
tree11b4489c96fba7043e56058ec9baf020b2d79c93 /spec
parent4592bfd59cd5d4795069798a14b483e16c98c1ff (diff)
(MODULES-660) Correct detached HEAD on latest
Previously vcsrepo detached HEAD on checkout which caused further branch revisions to fail. This corrects the behavior, and works on git 1.7, 1.8, 1.9, and 2.0
Diffstat (limited to 'spec')
-rw-r--r--spec/acceptance/modules_660_spec.rb89
-rw-r--r--spec/spec_helper_acceptance.rb2
-rw-r--r--spec/unit/puppet/provider/vcsrepo/git_spec.rb94
3 files changed, 110 insertions, 75 deletions
diff --git a/spec/acceptance/modules_660_spec.rb b/spec/acceptance/modules_660_spec.rb
new file mode 100644
index 0000000..c45aa28
--- /dev/null
+++ b/spec/acceptance/modules_660_spec.rb
@@ -0,0 +1,89 @@
+require 'spec_helper_acceptance'
+
+tmpdir = default.tmpdir('vcsrepo')
+
+describe 'MODULES-660' do
+ before(:all) do
+ # Create testrepo.git
+ my_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
+ shell("mkdir -p #{tmpdir}") # win test
+ scp_to(default, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
+ shell("cd #{tmpdir} && ./create_git_repo.sh")
+
+ # Configure testrepo.git as upstream of testrepo
+ pp = <<-EOS
+ vcsrepo { "#{tmpdir}/testrepo":
+ ensure => present,
+ provider => git,
+ revision => 'a_branch',
+ source => "file://#{tmpdir}/testrepo.git",
+ }
+ EOS
+ apply_manifest(pp, :catch_failures => true)
+ end
+
+ after(:all) do
+ shell("rm -rf #{tmpdir}/testrepo.git")
+ end
+
+ shared_examples 'switch to branch/tag/sha' do
+ it 'pulls the new branch commits' do
+ pp = <<-EOS
+ vcsrepo { "#{tmpdir}/testrepo":
+ ensure => latest,
+ provider => git,
+ revision => 'a_branch',
+ source => "file://#{tmpdir}/testrepo.git",
+ }
+ EOS
+ apply_manifest(pp, :expect_changes => true)
+ apply_manifest(pp, :catch_changes => true)
+ end
+ it 'checks out the tag' do
+ pp = <<-EOS
+ vcsrepo { "#{tmpdir}/testrepo":
+ ensure => latest,
+ provider => git,
+ revision => '0.0.3',
+ source => "file://#{tmpdir}/testrepo.git",
+ }
+ EOS
+ apply_manifest(pp, :expect_changes => true)
+ apply_manifest(pp, :catch_changes => true)
+ end
+ it 'checks out the sha' do
+ sha = shell("cd #{tmpdir}/testrepo && git rev-parse origin/master").stdout.chomp
+ pp = <<-EOS
+ vcsrepo { "#{tmpdir}/testrepo":
+ ensure => latest,
+ provider => git,
+ revision => '#{sha}',
+ source => "file://#{tmpdir}/testrepo.git",
+ }
+ EOS
+ apply_manifest(pp, :expect_changes => true)
+ apply_manifest(pp, :catch_changes => true)
+ end
+ end
+
+ context 'on branch' do
+ before :each do
+ shell("cd #{tmpdir}/testrepo && git checkout a_branch")
+ shell("cd #{tmpdir}/testrepo && git reset --hard 0.0.2")
+ end
+ it_behaves_like 'switch to branch/tag/sha'
+ end
+ context 'on tag' do
+ before :each do
+ shell("cd #{tmpdir}/testrepo && git checkout 0.0.1")
+ end
+ it_behaves_like 'switch to branch/tag/sha'
+ end
+ context 'on detached head' do
+ before :each do
+ shell("cd #{tmpdir}/testrepo && git checkout 0.0.2")
+ shell("cd #{tmpdir}/testrepo && git checkout HEAD~1")
+ end
+ it_behaves_like 'switch to branch/tag/sha'
+ end
+end
diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb
index e566a12..d37c169 100644
--- a/spec/spec_helper_acceptance.rb
+++ b/spec/spec_helper_acceptance.rb
@@ -1,6 +1,6 @@
require 'beaker-rspec'
-unless ENV['RS_PROVISION'] == 'no'
+unless ENV['RS_PROVISION'] == 'no' or ENV['BEAKER_provision'] == 'no'
hosts.each do |host|
# Install Puppet
if host.is_pe?
diff --git a/spec/unit/puppet/provider/vcsrepo/git_spec.rb b/spec/unit/puppet/provider/vcsrepo/git_spec.rb
index 2fd63f0..3f81cc8 100644
--- a/spec/unit/puppet/provider/vcsrepo/git_spec.rb
+++ b/spec/unit/puppet/provider/vcsrepo/git_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'
describe Puppet::Type.type(:vcsrepo).provider(:git_provider) do
- def branch_a_list(include_branch)
+ def branch_a_list(include_branch = nil?)
<<branches
end
#{"* master" unless include_branch.nil?}
@@ -222,51 +222,41 @@ branches
expects_chdir('/tmp/test')
resource[:revision] = 'currentsha'
resource.delete(:source)
- provider.expects(:git).with('rev-parse', 'HEAD').returns('currentsha')
+ provider.stubs(:git).with('config', 'remote.origin.url').returns('')
+ provider.stubs(:git).with('fetch', 'origin') # FIXME
+ provider.stubs(:git).with('fetch', '--tags', 'origin')
+ provider.stubs(:git).with('rev-parse', 'HEAD').returns('currentsha')
+ provider.stubs(:git).with('branch', '-a').returns(branch_a_list(resource.value(:revision)))
+ provider.stubs(:git).with('tag', '-l').returns("Hello")
end
context "when its SHA is not different than the current SHA" do
it "should return the ref" do
- provider.expects(:git).with('config', 'remote.origin.url').returns('')
- provider.expects(:git).with('fetch', 'origin') # FIXME
- provider.expects(:git).with('fetch', '--tags', 'origin')
- provider.expects(:git).with('rev-parse', '--revs-only', resource.value(:revision)).returns('currentsha')
- provider.expects(:git).with('tag', '-l').returns("Hello")
+ provider.expects(:git).with('rev-parse', resource.value(:revision)).returns('currentsha')
provider.revision.should == resource.value(:revision)
end
end
context "when its SHA is different than the current SHA" do
it "should return the current SHA" do
- provider.expects(:git).with('config', 'remote.origin.url').returns('')
- provider.expects(:git).with('fetch', 'origin') # FIXME
- provider.expects(:git).with('fetch', '--tags', 'origin')
- provider.expects(:git).with('rev-parse', '--revs-only', resource.value(:revision)).returns('othersha')
- provider.expects(:git).with('tag', '-l').returns("Hello")
- provider.revision.should == 'currentsha'
+ provider.expects(:git).with('rev-parse', resource.value(:revision)).returns('othersha')
+ provider.revision.should == resource.value(:revision)
end
end
context "when its a ref to a remote head" do
it "should return the revision" do
- provider.expects(:git).with('config', 'remote.origin.url').returns('')
- provider.expects(:git).with('fetch', 'origin') # FIXME
- provider.expects(:git).with('fetch', '--tags', 'origin')
- provider.expects(:git).with('tag', '-l').returns("Hello")
- provider.expects(:git).with('rev-parse', '--revs-only', resource.value(:revision)).returns('')
- provider.expects(:git).with('ls-remote', '--heads', '--tags', 'origin', resource.value(:revision)).returns("newsha refs/heads/#{resource.value(:revision)}")
- provider.revision.should == 'currentsha'
+ provider.stubs(:git).with('branch', '-a').returns(" remotes/origin/#{resource.value(:revision)}")
+ provider.expects(:git).with('rev-parse', "origin/#{resource.value(:revision)}").returns("newsha")
+ provider.revision.should == resource.value(:revision)
end
end
context "when its a ref to non existant remote head" do
it "should fail" do
- provider.expects(:git).with('config', 'remote.origin.url').returns('')
- provider.expects(:git).with('fetch', 'origin') # FIXME
- provider.expects(:git).with('fetch', '--tags', 'origin')
- provider.expects(:git).with('tag', '-l').returns("Hello")
+ provider.expects(:git).with('branch', '-a').returns(branch_a_list)
provider.expects(:git).with('rev-parse', '--revs-only', resource.value(:revision)).returns('')
- provider.expects(:git).with('ls-remote', '--heads', '--tags', 'origin', resource.value(:revision)).returns('')
+
expect { provider.revision }.to raise_error(Puppet::Error, /not a local or remote ref$/)
end
end
@@ -276,10 +266,7 @@ branches
resource[:source] = 'git://git@foo.com/bar.git'
provider.expects(:git).with('config', 'remote.origin.url').returns('old')
provider.expects(:git).with('config', 'remote.origin.url', 'git://git@foo.com/bar.git')
- provider.expects(:git).with('fetch', 'origin') # FIXME
- provider.expects(:git).with('fetch', '--tags', 'origin')
- provider.expects(:git).with('rev-parse', '--revs-only', resource.value(:revision)).returns('currentsha')
- provider.expects(:git).with('tag', '-l').returns("Hello")
+ provider.expects(:git).with('rev-parse', resource.value(:revision)).returns('currentsha')
provider.revision.should == resource.value(:revision)
end
end
@@ -295,7 +282,7 @@ branches
provider.expects(:update_submodules)
provider.expects(:git).with('branch', '-a').at_least_once.returns(branch_a_list(resource.value(:revision)))
provider.expects(:git).with('checkout', '--force', resource.value(:revision))
- provider.expects(:git).with('reset', '--hard', "origin/#{resource.value(:revision)}")
+ provider.expects(:git).with('reset', '--hard', "origin/#{resource.value(:revision)}")
provider.revision = resource.value(:revision)
end
end
@@ -305,7 +292,7 @@ branches
provider.expects(:update_submodules)
provider.expects(:git).with('branch', '-a').at_least_once.returns(resource.value(:revision))
provider.expects(:git).with('checkout', '--force', resource.value(:revision))
- provider.expects(:git).with('reset', '--hard', "origin/#{resource.value(:revision)}")
+ provider.expects(:git).with('reset', '--hard', "origin/#{resource.value(:revision)}")
provider.revision = resource.value(:revision)
end
end
@@ -368,64 +355,23 @@ branches
end
end
- context "retrieving the current revision" do
- before do
- expects_chdir
- provider.expects(:git).with('branch','-a').returns("* foo")
- end
-
- it "will strip trailing newlines" do
- provider.expects(:get_revision).with('origin/foo')
- provider.latest
- end
- end
-
describe 'latest?' do
- before do
- expects_chdir('/tmp/test')
- end
context 'when true' do
it do
provider.expects(:revision).returns('testrev')
- provider.expects(:latest).returns('testrev')
+ provider.expects(:latest_revision).returns('testrev')
provider.latest?.should be_true
end
end
context 'when false' do
it do
provider.expects(:revision).returns('master')
- provider.expects(:latest).returns('testrev')
+ provider.expects(:latest_revision).returns('testrev')
provider.latest?.should be_false
end
end
end
- describe 'latest' do
- before do
- provider.expects(:get_revision).returns('master')
- expects_chdir
- end
- context 'on master' do
- it do
- provider.expects(:git).with('branch','-a').returns("* master")
- provider.latest.should == 'master'
- end
- end
- context 'no branch' do
- it do
- provider.expects(:git).with('branch','-a').returns("* master")
-
- provider.latest.should == 'master'
- end
- end
- context 'feature/bar' do
- it do
- provider.expects(:git).with('branch','-a').returns("* master")
- provider.latest.should == 'master'
- end
- end
- end
-
describe 'convert_working_copy_to_bare' do
it do
FileUtils.expects(:mv).returns(true)