diff options
Diffstat (limited to 'lorry')
-rwxr-xr-x | lorry | 81 |
1 files changed, 48 insertions, 33 deletions
@@ -423,6 +423,13 @@ class Lorry(cliapp.Application): if not os.path.exists(old_gitdir): old_gitdir = old_repo + # Ensure that it's bare + self.run_program(['git', 'config', 'core.bare', 'true'], + cwd=old_gitdir) + self.run_program(['git', 'config', 'core.logallrefupdates', + 'false'], + cwd=old_gitdir) + self.write_update_count(old_gitdir, 1) # Move it to new name, and remove top-level directory if we @@ -471,6 +478,8 @@ class Lorry(cliapp.Application): shutil.rmtree(temp_repo) if active_count == 0: + # We can't create the repo here because "git cvsimport" + # insists on doing so itself return temp_repo, None, 1 self.copy_gitdir(active_repo, temp_repo) @@ -481,6 +490,17 @@ class Lorry(cliapp.Application): with open(count_name, 'w') as count_file: count_file.write('%d\n' % count) + def ensure_gitdir(self, gitdir): + # Create git directory if it doesn't exist. Return flag for + # whether we created it. + exists = os.path.exists(gitdir) + if not exists: + self.progress('.. creating git repo') + self.run_program(['git', 'init', '--bare', gitdir]) + else: + self.progress('.. updating existing clone') + return not exists + def copy_gitdir(self, source, dest): if not os.path.exists(source): return None @@ -516,10 +536,7 @@ class Lorry(cliapp.Application): env = dict(os.environ) env['GIT_SSL_NO_VERIFY'] = 'true' - if not os.path.exists(gitdir): - self.progress('.. initialising git dir') - self.run_program(['git', 'init', '--bare', gitdir]) - self.progress('.. updating existing clone') + self.ensure_gitdir(gitdir) argv = ['git', '-c', 'gc.autodetach=false', 'fetch', '--prune', spec['url'], '+refs/heads/*:refs/heads/*', '+refs/tags/*:refs/tags/*'] @@ -538,11 +555,7 @@ class Lorry(cliapp.Application): self.progress('.. creating bzr repository') self.run_program([bzr, 'init-repo', '--no-trees', bzrdir]) - if not os.path.exists(gitdir): - self.progress('.. creating git repo') - os.mkdir(gitdir) - self.run_program(['git', 'init', '--bare', gitdir]) - self.needs_aggressive = True + self.needs_aggressive = self.ensure_gitdir(gitdir) # branches are the listed branches, plus the branch specified in url if 'branches' in spec: @@ -608,24 +621,22 @@ class Lorry(cliapp.Application): layout = { "trunk": "trunk", "tags": "tags/*", "branches": "branches/*" } - if not os.path.exists(gitdir): - self.progress('.. doing initial clone') - self.needs_aggressive = True - self.run_program(['git', 'svn', 'init', spec['url'], gitdir + "-tmp", - '--svn-remote=svn', '--no-minimize-url']) - os.rename(os.path.join(gitdir + "-tmp", '.git'), gitdir) - os.rmdir(gitdir + "-tmp") - self.run_program(['git', 'config', 'core.bare', 'true'], - cwd=gitdir) - else: - self.progress('.. updating existing clone') - # Force URL to the one in the Lorry spec. This way, if the - # URL in the spec changes, Lorry accepts the change rather - # than using the original one. - self.run_program( - ['git', 'config', 'svn-remote.svn.url', spec['url']], - cwd=gitdir) + # We should not run "git svn init" which creates a non-bare + # repository. Instead, create the directory and extra config + # parameters that it would create. This also ensures that if + # the URL in the spec changes, Lorry accepts the change rather + # than using the original one. + self.needs_aggressive = self.ensure_gitdir(gitdir) + os.makedirs(os.path.join(gitdir, 'svn/refs/remotes/git-svn'), + exist_ok=True) + self.run_program( + ['git', 'config', 'svn-remote.svn.url', spec['url']], + cwd=gitdir) + self.run_program( + ['git', 'config', 'svn-remote.svn.fetch', ':refs/remotes/git-svn'], + cwd=gitdir) + # manually set the refspecs to fetch into local # git-svn can apparently provide better history tracking by # fetching the root of the repository @@ -668,11 +679,18 @@ class Lorry(cliapp.Application): self.needs_aggressive = True env = dict(os.environ) env['CVS_RSH'] = 'lorry-ssh-wrapper' + env['GIT_DIR'] = gitdir self.run_program( - ['git', 'cvsimport', '-a', '-d', spec['url'], - '-C', gitdir, spec['module']], + ['git', 'cvsimport', '-a', '-d', spec['url'], + '-i', spec['module']], env=env) + # git cvsimport may create an index even in a bare repo + try: + os.remove(os.path.join(gitdir, 'index')) + except FileNotFoundError: + pass + def gitify_hg(self, project_name, dirname, gitdir, spec): cert_options = [] if not self.should_check_certificates(spec): @@ -692,9 +710,7 @@ class Lorry(cliapp.Application): self.run_program(['hg', 'clone', '--quiet', *cert_options, spec['url'], hgdir]) - if not os.path.exists(gitdir): - self.needs_aggressive = True - self.run_program(['git', 'init', '--bare', gitdir]) + self.needs_aggressive = self.ensure_gitdir(gitdir) # Since there are marks files in existing deployments that # have broken references, fix up the marks file before rather @@ -737,8 +753,7 @@ class Lorry(cliapp.Application): else: self.progress('.. no need to run, nothing to do') return - if not os.path.exists(gitdir): - self.run_program(['git', 'init', '--bare', gitdir]) + self.ensure_gitdir(gitdir) cmdline = ["%s.%s-importer" % (lorry_path, archive_type), archive_dest] self.run_program(cmdline, cwd=gitdir) |