From 90f22c6cf30a6bba768f77117923edb022c7ef39 Mon Sep 17 00:00:00 2001 From: Ben Hutchings Date: Tue, 15 Sep 2020 16:37:26 +0100 Subject: lorry: Avoid creating non-bare repository in gitify_svn Our working repositories should always be initialised as bare, and this should be done in one place. gitify_svn currently uses "git svn init", which always creates a non-bare repository, and then modifies the repository to be bare (though still with core.logallrefupdates enabled). Thankfully "git svn init" does very little beyond "git init", so we can avoid this: 1. Call ensure_gitdir, like other gitify methods do 2. Create the directory svn/refs/remotes/git-svn 3. Set config parameters svn-remote.svn.url (which we already did) and svn-remote.svn.fetch --- lorry | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) (limited to 'lorry') diff --git a/lorry b/lorry index 59d8296..524ed2c 100755 --- a/lorry +++ b/lorry @@ -479,7 +479,7 @@ class Lorry(cliapp.Application): if active_count == 0: # We can't create the repo here because "git cvsimport" - # and "git svn init" insist on doing so themselves + # insists on doing so itself return temp_repo, None, 1 self.copy_gitdir(active_repo, temp_repo) @@ -621,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 -- cgit v1.2.1