summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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)