From: Hans-Christoph Steiner Date: Fri, 7 Jul 2017 15:52:53 +0000 (+0200) Subject: server: smooth out btlog transfer for offline signing setups X-Git-Tag: 0.8~9^2~13 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=523b5f4777d0ea7422fead1544de58fd870afa21;p=fdroidserver.git server: smooth out btlog transfer for offline signing setups It turns out it is error prone to `git push` to a non-bare git repo. For the offline signing machine, the git remote needs to be a regular git repo in a directory on a thumbdrive so that once the thumbdrive is plugged into an online machine, that git repo can be transferred to the online machine. --- diff --git a/fdroidserver/server.py b/fdroidserver/server.py index 7ca6009a..ebfea3a3 100644 --- a/fdroidserver/server.py +++ b/fdroidserver/server.py @@ -507,7 +507,8 @@ def push_binary_transparency(git_repo_path, git_remote): If the remote is a local directory, make sure it exists, and is a git repo. This is used to move this git repo from an offline - machine onto a flash drive, then onto the online machine. + machine onto a flash drive, then onto the online machine. Also, + this pulls because pushing to a non-bare git repo is error prone. This is also used in offline signing setups, where it then also creates a "local copy dir" git repo that serves to shuttle the git @@ -518,24 +519,36 @@ def push_binary_transparency(git_repo_path, git_remote): ''' import git - if os.path.isdir(os.path.dirname(git_remote)) \ - and not os.path.isdir(os.path.join(git_remote, '.git')): - os.makedirs(git_remote, exist_ok=True) - repo = git.Repo.init(git_remote) - config = repo.config_writer() - config.set_value('receive', 'denyCurrentBranch', 'updateInstead') - config.release() - logging.info('Pushing binary transparency log to ' + git_remote) - gitrepo = git.Repo(git_repo_path) - origin = git.remote.Remote(gitrepo, 'origin') - if origin in gitrepo.remotes: - origin = gitrepo.remote('origin') - if 'set_url' in dir(origin): # added in GitPython 2.x - origin.set_url(git_remote) + + if os.path.isdir(os.path.dirname(git_remote)): + # from offline machine to thumbdrive + remote_path = os.path.abspath(git_repo_path) + if not os.path.isdir(os.path.join(git_remote, '.git')): + os.makedirs(git_remote, exist_ok=True) + thumbdriverepo = git.Repo.init(git_remote) + local = thumbdriverepo.create_remote('local', remote_path) + else: + thumbdriverepo = git.Repo(git_remote) + local = git.remote.Remote(thumbdriverepo, 'local') + if local in thumbdriverepo.remotes: + local = thumbdriverepo.remote('local') + if 'set_url' in dir(local): # force remote URL if using GitPython 2.x + local.set_url(remote_path) + else: + local = thumbdriverepo.create_remote('local', remote_path) + local.pull('master') else: - origin = gitrepo.create_remote('origin', git_remote) - origin.push('master') + # from online machine to remote on a server on the internet + gitrepo = git.Repo(git_repo_path) + origin = git.remote.Remote(gitrepo, 'origin') + if origin in gitrepo.remotes: + origin = gitrepo.remote('origin') + if 'set_url' in dir(origin): # added in GitPython 2.x + origin.set_url(git_remote) + else: + origin = gitrepo.create_remote('origin', git_remote) + origin.push('master') def main(): diff --git a/tests/run-tests b/tests/run-tests index eef54ee4..2cfdc55a 100755 --- a/tests/run-tests +++ b/tests/run-tests @@ -1051,24 +1051,20 @@ test `grep '' archive/index.xml | wc -l` -eq 2 cd binary_transparency [ `git rev-list --count HEAD` == "1" ] cd .. -if have_git_2_3; then - $fdroid server update --verbose - grep -F '> config.py - echo "sync_from_local_copy_dir = True" >> config.py - echo "serverwebroots = '$SERVERWEBROOT'" >> config.py - echo "servergitmirrors = '$SERVER_GIT_MIRROR'" >> config.py - echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py - echo "binary_transparency_remote = '$BINARY_TRANSPARENCY_REMOTE'" >> config.py - $fdroid server update --verbose - cd $BINARY_TRANSPARENCY_REMOTE - [ `git rev-list --count HEAD` == "1" ] - cd $SERVER_GIT_MIRROR - [ `git rev-list --count HEAD` == "1" ] -else - echo "Skipping test, `git --version` older than 2.3" -fi +$fdroid server update --verbose +grep -F '> config.py +echo "sync_from_local_copy_dir = True" >> config.py +echo "serverwebroots = '$SERVERWEBROOT'" >> config.py +echo "servergitmirrors = '$SERVER_GIT_MIRROR'" >> config.py +echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py +echo "binary_transparency_remote = '$BINARY_TRANSPARENCY_REMOTE'" >> config.py +$fdroid server update --verbose +cd $BINARY_TRANSPARENCY_REMOTE +[ `git rev-list --count HEAD` == "1" ] +cd $SERVER_GIT_MIRROR +[ `git rev-list --count HEAD` == "1" ] #------------------------------------------------------------------------------#