summaryrefslogtreecommitdiff
path: root/lorry
diff options
context:
space:
mode:
authorBen Brown <ben.brown@codethink.co.uk>2020-09-17 17:20:22 +0000
committerBen Brown <ben.brown@codethink.co.uk>2020-09-17 17:20:22 +0000
commit641ebd75f9868753ba472e780062a7f2aed5abbb (patch)
treefcb367793cdeb557df5bd4436076272dedcef3d4 /lorry
parentc356e375704e3951a6fa7db1097cef6182383047 (diff)
parent6d5fb6dbde1781fd74c0f7313024871003a5312b (diff)
downloadlorry-641ebd75f9868753ba472e780062a7f2aed5abbb.tar.gz
Merge branch 'bwh/cvs-use-worktree' into 'master'
Use a working tree in gitify_cvs Closes #12 See merge request CodethinkLabs/lorry/lorry!19
Diffstat (limited to 'lorry')
-rwxr-xr-xlorry62
1 files changed, 55 insertions, 7 deletions
diff --git a/lorry b/lorry
index 524ed2c..81fdeb3 100755
--- a/lorry
+++ b/lorry
@@ -676,20 +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['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 = []