From b931190b329979cd59b1ca721152ed0430296d0a Mon Sep 17 00:00:00 2001 From: Matt Robinson Date: Thu, 19 Jan 2012 14:40:49 -0800 Subject: [PATCH] (#11798) Fix git checkout of revisions The git provider had some problems checking out SHA1s - it couldn't. And what's worse, it lied about what it was doing saying that it did checkout the SHA1. There was also a bug where if you specified a different branch than you were on, it was doing a `reset --hard` to the specified branch. For example, if master was checked out, and you set "revision => stable", it would `git reset --hard stable` on the master branch instead of just checking out stable. Maybe the original author did this to get around being unable to checkout when you had local changes, but the --force flag to checkout will fix that. With this change, you should now be able to specify a branch, tag, or SHA1 in the revision attribute and have it work. --- lib/puppet/provider/vcsrepo/git.rb | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/puppet/provider/vcsrepo/git.rb b/lib/puppet/provider/vcsrepo/git.rb index 6cbda67..7fa755d 100644 --- a/lib/puppet/provider/vcsrepo/git.rb +++ b/lib/puppet/provider/vcsrepo/git.rb @@ -17,7 +17,7 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo) if @resource.value(:ensure) == :bare notice "Ignoring revision for bare repository" else - checkout_or_reset + checkout end end if @resource.value(:ensure) != :bare @@ -67,7 +67,7 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo) end def revision=(desired) - checkout_or_reset(desired) + checkout(desired) if local_branch_revision?(desired) # reset instead of pull to avoid merge conflicts. assuming remote is # authoritative. @@ -188,13 +188,11 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo) false end - def checkout_or_reset(revision = @resource.value(:revision)) - if local_branch_revision? - reset(revision) - elsif tag_revision? - at_path { git_with_identity('checkout', revision) } - elsif remote_branch_revision? + def checkout(revision = @resource.value(:revision)) + if !local_branch_revision? && remote_branch_revision? at_path { git_with_identity('checkout', '-b', revision, '--track', "origin/#{revision}") } + else + at_path { git_with_identity('checkout', '--force', revision) } end end