From 94c70b2a9df151ed409b549614c5bdf019791e5f Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Mon, 8 Oct 2012 13:22:09 +0100 Subject: 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. --- lorry | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/lorry b/lorry index b52a193..e1d2cf4 100755 --- a/lorry +++ b/lorry @@ -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') -- cgit v1.2.1