summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCody Herriges <c.a.herriges@gmail.com>2011-05-24 21:24:26 +1200
committerCody Herriges <c.a.herriges@gmail.com>2011-06-06 10:42:24 -0700
commit8e51aebd4cf77c7d68eee70dfa0e16909aa114c5 (patch)
tree7a86ce210825fb461d57c6b5c95b3fc2021a9955
parentf31853d1c3ccb4d84ae7e417bc25e14260d7e969 (diff)
(#7797) Makes git tags actually work.
Fixes a number of issues with the git provider. remote_branch_revision? method was always returning true because it would always at least return something, even if that something was a zero length array. You normally don't desire a tag to become a branch since it creates ambiguity so I removed that. latest method had no concept of (no branch) and so would fail if you switched to a remote branch or a tag. Then finally revision sha1 returned by 'git rev-parse' for tags is not the revision of the commit the tag represents. We have to use 'git show' and do some text parsing to actually figure out which commit goes with which tag.
-rw-r--r--lib/puppet/provider/vcsrepo/git.rb22
1 files changed, 16 insertions, 6 deletions
diff --git a/lib/puppet/provider/vcsrepo/git.rb b/lib/puppet/provider/vcsrepo/git.rb
index fa7e492..8de1313 100644
--- a/lib/puppet/provider/vcsrepo/git.rb
+++ b/lib/puppet/provider/vcsrepo/git.rb
@@ -41,15 +41,22 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo)
branch = on_branch?
if branch == 'master'
return get_revision('origin/HEAD')
+ elsif branch == '(no branch)'
+ return get_revision('HEAD')
else
- return get_revision('origin/%s' % branch)
+ return get_revision('origin/%s' % branch)
end
end
def revision
update_references
- current = at_path { git('rev-parse', 'HEAD') }
- canonical = at_path { git('rev-parse', @resource.value(:revision)) }
+ current = at_path { git('rev-parse', 'HEAD').chomp }
+ if tag_revision?(@resource.value(:revision))
+ canonical = at_path { git('show', @resource.value(:revision)).scan(/commit (.*)/).to_s }
+ else
+ canonical = at_path { git('rev-parse', @resource.value(:revision)).chomp }
+ end
+
if current == canonical
@resource.value(:revision)
else
@@ -179,10 +186,10 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo)
end
def checkout_or_reset(revision = @resource.value(:revision))
- if local_branch_revision?
+ if local_branch_revision?
reset(revision)
elsif tag_revision?
- at_path { git('checkout', '-b', revision) }
+ at_path { git('checkout', revision) }
elsif remote_branch_revision?
at_path { git('checkout', '-b', revision, '--track', "origin/#{revision}") }
end
@@ -206,7 +213,10 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo)
def remote_branch_revision?(revision = @resource.value(:revision))
# git < 1.6 returns 'origin/#{revision}'
# git 1.6+ returns 'remotes/origin/#{revision}'
- at_path { branches.grep /(remotes\/)?origin\/#{revision}/ }
+ branch = at_path { branches.grep /(remotes\/)?origin\/#{revision}/ }
+ if branch.length > 0
+ return branch
+ end
end
def local_branch_revision?(revision = @resource.value(:revision))