Handle special case when converting an empty bare repository to a working copy repository

This commit is contained in:
Bruce Williams 2010-03-13 01:28:40 -08:00
parent 0a306f288e
commit d358630fc6

View File

@ -97,9 +97,10 @@ Puppet::Type.type(:vcsrepo).provide(:git) do
# to: # to:
# <path>/ # <path>/
def convert_working_copy_to_bare def convert_working_copy_to_bare
notice "Converting working copy repository to bare repository"
FileUtils.mv(File.join(@resource.value(:path), '.git'), tempdir) FileUtils.mv(File.join(@resource.value(:path), '.git'), tempdir)
FileUtils.rm_rf(@resource.value(:path)) FileUtils.rm_rf(@resource.value(:path))
FileUtils.cp_r(tempdir, @resource.value(:path)) FileUtils.mv(tempdir, @resource.value(:path))
end end
# Convert bare to working copy # Convert bare to working copy
@ -109,27 +110,34 @@ Puppet::Type.type(:vcsrepo).provide(:git) do
# to: # to:
# <path>/.git # <path>/.git
def convert_bare_to_working_copy def convert_bare_to_working_copy
notice "Converting bare repository to working copy repository"
FileUtils.mv(@resource.value(:path), tempdir) FileUtils.mv(@resource.value(:path), tempdir)
FileUtils.mkdir(@resource.value(:path)) FileUtils.mkdir(@resource.value(:path))
FileUtils.cp_r(tempdir, File.join(@resource.value(:path), '.git')) FileUtils.mv(tempdir, File.join(@resource.value(:path), '.git'))
reset('HEAD') if commits_in?(File.join(@resource.value(:path), '.git'))
git('checkout', '-f') reset('HEAD')
git('checkout', '-f')
end
end end
def normal_init def normal_init
FileUtils.mkdir(@resource.value(:path)) FileUtils.mkdir(@resource.value(:path))
args = ['init'] args = ['init']
if @resource.value(:ensure) == :bare if @resource.value(:ensure) == :bare
notice "Creating a bare repository"
args << '--bare' args << '--bare'
else
notice "Creating a working copy repository (#{@resource.value(:ensure).inspect})"
end end
at_path do at_path do
git(*args) git(*args)
end end
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) def reset(desired)
at_path do at_path do
git('reset', '--hard', desired) git('reset', '--hard', desired)