From f92d09226cfddb0c7e5e342dd199d8ea05b497cb Mon Sep 17 00:00:00 2001 From: Micah Anderson Date: Thu, 21 Feb 2013 15:30:52 -0500 Subject: Due to a network anomaly during a vcsrepo git clone you can get a 'non-repository' at the path. That can be even just an empty directory. This makes it so further puppet runs cannot ever complete properly, because of this error: change from absent to present failed: Could not create repository (non-repository at path) This requires manual intervention to resolve (ie. removing the directory). It is possible to pass the 'force => true' parameter to vcsrepo to handle this, however, all this will do is remove whatever is there, even if it is a valid repository. That means on every puppet run you get the tree removed and then a new clone is done. This is less than ideal for a number of reasons. So this commit adds a test to determine if the location contains a valid repository and then it is used when 'force => true' to determine if it should replace the existing content with a fresh clone. Note: the valid_repo? check is also added to the 'def bare_git_config_exists?' because the test that is done there is intended to look for a bare git repository by checking to see if there 'config' is in the directory. This isn't a particularly robust test because 'config' could be in a directory, when it isn't a bare git repository (such as is common in a rails app) causing vcsrepo to mistakenly think it was a proper bare repository, when it isn't. --- lib/puppet/provider/vcsrepo/git.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/puppet/provider/vcsrepo/git.rb b/lib/puppet/provider/vcsrepo/git.rb index 58330f6..8470ea8 100644 --- a/lib/puppet/provider/vcsrepo/git.rb +++ b/lib/puppet/provider/vcsrepo/git.rb @@ -126,8 +126,12 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo) private + def valid_repo? + Dir.chdir(@resource.value(:path)){ system('git rev-parse > /dev/null 2>&1')} + end + def bare_git_config_exists? - File.exist?(File.join(@resource.value(:path), 'config')) + File.exist?(File.join(@resource.value(:path), 'config')) && valid_repo? end def clone_repository(source, path) @@ -148,7 +152,7 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo) def check_force if path_exists? - if @resource.value(:force) + if @resource.value(:force) && !valid_repo? notice "Removing %s to replace with vcsrepo." % @resource.value(:path) destroy else -- cgit v1.2.3