puppetlabs/puppetlabs-vcsrepo — pull request #54 by riseuplabs (2013-02-21 20:38:34+00:00)
Title: Enhance force=>true to check for a valid repository

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.