summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Williams <bruce@codefluency.com>2010-03-13 01:28:40 -0800
committerBruce Williams <bruce@codefluency.com>2010-03-13 01:28:40 -0800
commitd358630fc69421fc44123672ff5ae3b724c00317 (patch)
treec37091135d76f3e15ee7ff1d6cee10eed462a727
parent0a306f288e84bed857e4d82c695dcea0c6ceb37a (diff)
Handle special case when converting an empty bare repository to a working copy repository
-rw-r--r--lib/puppet/provider/vcsrepo/git.rb22
1 files changed, 15 insertions, 7 deletions
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:
# <path>/
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:
# <path>/.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)