summaryrefslogtreecommitdiff
path: root/lorry
diff options
context:
space:
mode:
authorBen Hutchings <ben.hutchings@codethink.co.uk>2020-09-16 21:30:08 +0100
committerBen Hutchings <ben.hutchings@codethink.co.uk>2020-09-17 14:11:31 +0100
commit6d5fb6dbde1781fd74c0f7313024871003a5312b (patch)
treefcb367793cdeb557df5bd4436076272dedcef3d4 /lorry
parent4c7424821d8eb9d97a147e650e588aafbded753c (diff)
downloadlorry-6d5fb6dbde1781fd74c0f7313024871003a5312b.tar.gz
lorry: Use a working tree in gitify_cvs
Sadly, git cvsimport requires a working tree for most operations, and only an initial import can be done successfully with the '-i' option. Rather than adding back general support for non-bare repositories: * When creating a mirror, let git cvsimport create it non-bare and then convert it to be bare * When updating a mirror, add a temporary working tree with "git worktree add"
Diffstat (limited to 'lorry')
-rwxr-xr-xlorry63
1 files changed, 55 insertions, 8 deletions
diff --git a/lorry b/lorry
index a3b42e0..81fdeb3 100755
--- a/lorry
+++ b/lorry
@@ -676,21 +676,68 @@ class Lorry(cliapp.Application):
self.run_program(['git', 'svn', 'fetch'], cwd=gitdir)
def gitify_cvs(self, project_name, dirname, gitdir, spec):
+ # git cvsimport requires a working tree for some operations;
+ # keep this separate from the repository
+ worktree = os.path.join(dirname, 'git-cvs-worktree')
+
+ if os.path.exists(gitdir):
+ if os.path.exists(worktree):
+ shutil.rmtree(worktree)
+ self.run_program(['git', 'worktree', 'prune'],
+ cwd=gitdir)
+ self.run_program(['git', 'worktree', 'add', worktree, 'master'],
+ cwd=gitdir)
+
+ # git cvsimport insists on $GIT_DIR or .git being a
+ # directory, but .git will be a file. Set $GIT_DIR to
+ # the subdirectory of gitdir created for this worktree.
+ cvsimp_gitdir = self.runcmd(['git', 'rev-parse', '--git-dir'],
+ cwd=worktree) \
+ .decode('utf-8') \
+ .rstrip('\n')
+
+ # cvsps should find its cache under gitdir, not the
+ # temporary worktree
+ cvsps_home = gitdir
+ else:
+ # We must let git cvsimport create the repository
+ cvsimp_gitdir = os.path.join(worktree, '.git')
+
+ # cvsps should create its cache there, and it will be
+ # moved to gitdir later
+ cvsps_home = cvsimp_gitdir
+
self.needs_aggressive = True
env = dict(os.environ)
env['CVS_RSH'] = 'lorry-ssh-wrapper'
- env['GIT_DIR'] = gitdir
- env['HOME'] = gitdir # make cvsps store cache under git dir
+ env['GIT_DIR'] = cvsimp_gitdir
+ env['HOME'] = cvsps_home
self.run_program(
['git', 'cvsimport', '-a', '-d', spec['url'],
- '-i', spec['module']],
+ '-C', worktree, 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
+ if not os.path.exists(gitdir):
+ # git cvsimport created a non-bare repository; convert it
+ # to bare
+ os.rename(cvsimp_gitdir, gitdir)
+ self.run_program(['git', 'config', 'core.bare', 'true'],
+ cwd=gitdir)
+ self.run_program(['git', 'config', 'core.logallrefupdates',
+ 'false'],
+ cwd=gitdir)
+ try:
+ os.remove(os.path.join(gitdir, 'index'))
+ except FileNotFoundError:
+ pass
+ try:
+ shutil.rmtree(os.path.join(gitdir, 'logs'))
+ except FileNotFoundError:
+ pass
+
+ shutil.rmtree(worktree)
+ self.run_program(['git', 'worktree', 'prune'],
+ cwd=gitdir)
def gitify_hg(self, project_name, dirname, gitdir, spec):
cert_options = []