diff options
author | Daniel Silverstone <daniel.silverstone@codethink.co.uk> | 2012-10-08 13:22:09 +0100 |
---|---|---|
committer | Daniel Silverstone <daniel.silverstone@codethink.co.uk> | 2012-10-08 13:22:09 +0100 |
commit | 94c70b2a9df151ed409b549614c5bdf019791e5f (patch) | |
tree | c3ab09a25e955e2f7f405651a67df7196c0bf725 | |
parent | 216fd8f6f477c074d42577809aefdf4633823992 (diff) | |
download | lorry-94c70b2a9df151ed409b549614c5bdf019791e5f.tar.gz |
Handle branch name kind changes more gracefully.
Scenario: a repository contains a ref: refs/heads/foo and we
have that in our repository cache.
Action: upstream deletes that ref and then pushes a new refs
at refs/heads/foo/bar.
Action: we attempt to update the git and the update fails because
git remote update cannot cope with the 'kind' change of
refs/heads/foo from ref to directory.
Remedy: If we get an exception from the remote update --prune we
try the less efficient but more resilient combination of
first pruning and then updating.
-rwxr-xr-x | lorry | 21 |
1 files changed, 19 insertions, 2 deletions
@@ -287,9 +287,26 @@ class Lorry(cliapp.Application): self.progress('.. initialising git dir') self.run_program(['git', 'init', '--bare', gitdir]) self.progress('.. updating existing clone') - self.run_program(['git', 'fetch', spec['url'], - '+refs/heads/*:refs/heads/*', + if 'remote.origin.fetch' in self.run_program(['git', 'config', '-l'], + cwd=gitdir): + self.run_program(['git', 'config', '--unset-all', + 'remote.origin.fetch'], cwd=gitdir) + self.run_program(['git', 'config', 'remote.origin.url', + spec['url']], cwd=gitdir) + self.run_program(['git', 'config', 'remote.origin.mirror', 'true'], + cwd=gitdir) + self.run_program(['git', 'config', '--add', 'remote.origin.fetch', + '+refs/heads/*:refs/heads/*'], cwd=gitdir) + self.run_program(['git', 'config', '--add', 'remote.origin.fetch', '+refs/tags/*:refs/tags/*'], cwd=gitdir) + try: + self.run_program(['git', 'remote', 'update', 'origin', '--prune'], + cwd=gitdir) + except: + self.run_program(['git', 'remote', 'prune', 'origin'], + cwd=gitdir) + self.run_program(['git', 'remote', 'update', 'origin', '--prune'], + cwd=gitdir) def gitify_bzr(self, project_name, dirname, gitdir, spec): bzrdir = os.path.join(dirname, 'bzr') |