summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJoshua Hoblitt <jhoblitt@cpan.org>2013-07-16 16:25:09 -0700
committerJoshua Hoblitt <jhoblitt@vm2.sdm.noao.edu>2013-07-17 13:39:29 -0700
commit8a58caef1fe6b2c301f321cd0d52e42cc58f5f6b (patch)
tree0dab4f77007f54dad1f29bc659bbeaafa4e4dde8 /lib
parent827cfaa7715c03589cbfda0fc7fe79239859b216 (diff)
downloadpuppet-vcsrepo-8a58caef1fe6b2c301f321cd0d52e42cc58f5f6b.tar.gz
puppet-vcsrepo-8a58caef1fe6b2c301f321cd0d52e42cc58f5f6b.tar.bz2
fix git provider checkout of a remote ref on an existing repo
Per discussion of https://github.com/puppetlabs/puppetlabs-vcsrepo/issues/51 in the git channel on freenode, EugeneKay <eugene@kashpureff.org> stated that `git rev-parse` is not capable of inspecting remote refs but that `git ls-remote` is. This patch makes a second attempt to resolve the ref with `ls-remote` if `rev-parse` fails. The git provider also appears to support several type features that are not tagged under `has_features`. It's not clear if this is the best way to resolve this issue or if the provider should be refactored to work with different type features. Demonstration of the problem with changing refs (branches and tags) $ git --version git version 1.7.1 $ cat master.pp branch.pp vcsrepo { '/tmp/vcsrepo': ensure => present, provider => git, source => 'https://github.com/puppetlabs/puppetlabs-vcsrepo.git', revision => 'master', } vcsrepo { '/tmp/vcsrepo': ensure => present, provider => git, source => 'https://github.com/puppetlabs/puppetlabs-vcsrepo.git', revision => 'feature/cvs', } $ puppet apply --modulepath=`pwd`/.. master.pp Notice: /Stage[main]//Vcsrepo[/tmp/vcsrepo]/ensure: Creating repository from present Notice: /Stage[main]//Vcsrepo[/tmp/vcsrepo]/ensure: created Notice: Finished catalog run in 2.19 seconds $ puppet apply --modulepath=`pwd`/.. branch.pp Error: /Stage[main]//Vcsrepo[/tmp/vcsrepo]: Could not evaluate: Execution of '/usr/bin/git rev-parse feature/cvs' returned 128: fatal: ambiguous argument 'feature/cvs': unknown revision or path not in the working tree. Use '--' to separate paths from revisions feature/cvs Notice: Finished catalog run in 1.69 seconds
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/provider/vcsrepo/git.rb15
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/puppet/provider/vcsrepo/git.rb b/lib/puppet/provider/vcsrepo/git.rb
index 76fa315..ac56ac5 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