From d358630fc69421fc44123672ff5ae3b724c00317 Mon Sep 17 00:00:00 2001 From: Bruce Williams Date: Sat, 13 Mar 2010 01:28:40 -0800 Subject: Handle special case when converting an empty bare repository to a working copy repository --- lib/puppet/provider/vcsrepo/git.rb | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'lib/puppet/provider/vcsrepo/git.rb') diff --git a/lib/puppet/provider/vcsrepo/git.rb b/lib/puppet/provider/vcsrepo/git.rb index ec58515..2ea146f 100644 --- a/lib/puppet/provider/vcsrepo/git.rb +++ b/lib/puppet/provider/vcsrepo/git.rb @@ -97,9 +97,10 @@ Puppet::Type.type(:vcsrepo).provide(:git) do # to: # / def convert_working_copy_to_bare + notice "Converting working copy repository to bare repository" FileUtils.mv(File.join(@resource.value(:path), '.git'), tempdir) FileUtils.rm_rf(@resource.value(:path)) - FileUtils.cp_r(tempdir, @resource.value(:path)) + FileUtils.mv(tempdir, @resource.value(:path)) end # Convert bare to working copy @@ -109,27 +110,34 @@ Puppet::Type.type(:vcsrepo).provide(:git) do # to: # /.git def convert_bare_to_working_copy + notice "Converting bare repository to working copy repository" FileUtils.mv(@resource.value(:path), tempdir) FileUtils.mkdir(@resource.value(:path)) - FileUtils.cp_r(tempdir, File.join(@resource.value(:path), '.git')) - reset('HEAD') - git('checkout', '-f') + FileUtils.mv(tempdir, File.join(@resource.value(:path), '.git')) + if commits_in?(File.join(@resource.value(:path), '.git')) + reset('HEAD') + git('checkout', '-f') + end end def normal_init FileUtils.mkdir(@resource.value(:path)) args = ['init'] if @resource.value(:ensure) == :bare - notice "Creating a bare repository" args << '--bare' - else - notice "Creating a working copy repository (#{@resource.value(:ensure).inspect})" end at_path do git(*args) end end + def commits_in?(dot_git) + Dir.glob(File.join(dot_git, 'objects/info/*'), File::FNM_DOTMATCH) do |e| + return true unless %w(. ..).include?(File::basename(e)) + end + false + end + def reset(desired) at_path do git('reset', '--hard', desired) -- cgit v1.2.3