summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAshley Penney <ashley.penney@puppetlabs.com>2014-05-19 08:09:13 -0700
committerAshley Penney <ashley.penney@puppetlabs.com>2014-05-19 08:09:13 -0700
commit059599691d4cf08ce012e4b057d0c82525ba163a (patch)
tree9587ade7c8b6caf7b8bcaba621ec059cdf1a9d87 /lib
parent4021245ebb54878c691d50efe3f9ce712734e4b6 (diff)
parent4613e93e35551271651bb7b1102d3b97a3f5b40d (diff)
Merge pull request #139 from cyberious/FM-1284
Fix detached head state
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/provider/vcsrepo/git.rb21
1 files changed, 18 insertions, 3 deletions
diff --git a/lib/puppet/provider/vcsrepo/git.rb b/lib/puppet/provider/vcsrepo/git.rb
index fafe4bf..61044e0 100644
--- a/lib/puppet/provider/vcsrepo/git.rb
+++ b/lib/puppet/provider/vcsrepo/git.rb
@@ -79,12 +79,18 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo)
def revision=(desired)
checkout(desired)
- if local_branch_revision?(desired)
+ if local_branch_revision?
# reset instead of pull to avoid merge conflicts. assuming remote is
# authoritative.
# might be worthwhile to have an allow_local_changes param to decide
# whether to reset or pull when we're ensuring latest.
- at_path { git_with_identity('reset', '--hard', "#{@resource.value(:remote)}/#{desired}") }
+ at_path {
+ git_with_identity('reset', '--hard', "#{@resource.value(:remote)}/#{desired}")
+ if detached?
+ git_with_identity('checkout', "#{@resource.value(:revision)}")
+ git_with_identity('pull')
+ end
+ }
end
if @resource.value(:ensure) != :bare
update_submodules
@@ -259,7 +265,16 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo)
end
def on_branch?
- at_path { git_with_identity('rev-parse', '--abbrev-ref', 'HEAD').chomp }
+ at_path {
+ matches = git_with_identity('branch', '-a').match /\*\s+(.*)/
+ matches[1] unless matches[1].match /detached/
+ }
+ end
+
+ def detached?
+ at_path {
+ git_with_identity('branch', '-a').match /\*\s+\(detached from.*\)/
+ }
end
def tags