summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/puppet/provider/vcsrepo/git.rb15
-rw-r--r--spec/unit/puppet/provider/vcsrepo/git_spec.rb30
2 files changed, 41 insertions, 4 deletions
diff --git a/lib/puppet/provider/vcsrepo/git.rb b/lib/puppet/provider/vcsrepo/git.rb
index c298179..536f652 100644
--- a/lib/puppet/provider/vcsrepo/git.rb
+++ b/lib/puppet/provider/vcsrepo/git.rb
@@ -56,7 +56,20 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo)
if tag_revision?(@resource.value(:revision))
canonical = at_path { git_with_identity('show', @resource.value(:revision)).scan(/^commit (.*)/).to_s }
else
- canonical = at_path { git_with_identity('rev-parse', @resource.value(:revision)).chomp }
+ # if it's not a tag, look for it as a local ref
+ canonical = at_path { git_with_identity('rev-parse', '--revs-only', @resource.value(:revision)).chomp }
+ if canonical.empty?
+ # git rev-parse executed properly but didn't find the ref;
+ # look for it in the remote
+ remote_ref = at_path { git_with_identity('ls-remote', '--heads', '--tags', @resource.value(:remote), @resource.value(:revision)).chomp }
+ if remote_ref.empty?
+ fail("#{@resource.value(:revision)} is not a local or remote ref")
+ end
+
+ # $ git ls-remote --heads --tags origin feature/cvs
+ # 7d4244b35e72904e30130cad6d2258f901c16f1a refs/heads/feature/cvs
+ canonical = remote_ref.split.first
+ end
end
if current == canonical
diff --git a/spec/unit/puppet/provider/vcsrepo/git_spec.rb b/spec/unit/puppet/provider/vcsrepo/git_spec.rb
index cb6c0c6..e10fd1e 100644
--- a/spec/unit/puppet/provider/vcsrepo/git_spec.rb
+++ b/spec/unit/puppet/provider/vcsrepo/git_spec.rb
@@ -132,7 +132,7 @@ describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} 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', resource.value(:revision)).returns('currentsha')
+ provider.expects(:git).with('rev-parse', '--revs-only', resource.value(:revision)).returns('currentsha')
provider.expects(:git).with('tag', '-l').returns("Hello")
provider.revision.should == resource.value(:revision)
end
@@ -143,12 +143,36 @@ describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} 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', resource.value(:revision)).returns('othersha')
+ 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'
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'
+ 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('rev-parse', '--revs-only', resource.value(:revision)).returns('')
+ provider.expects(:git).with('ls-remote', '--heads', '--tags', 'origin', resource.value(:revision)).returns('')
+ expect { provider.revision }.should raise_error(Puppet::Error, /not a local or remote ref$/)
+ end
+ end
+
context "when the source is modified" do
resource_with :source => 'git://git@foo.com/bar.git' do
it "should update the origin url" do
@@ -156,7 +180,7 @@ describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do
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', resource.value(:revision)).returns('currentsha')
+ provider.expects(:git).with('rev-parse', '--revs-only', resource.value(:revision)).returns('currentsha')
provider.expects(:git).with('tag', '-l').returns("Hello")
provider.revision.should == resource.value(:revision)
end