chiark / gitweb /
server: smooth out btlog transfer for offline signing setups
authorHans-Christoph Steiner <hans@eds.org>
Fri, 7 Jul 2017 15:52:53 +0000 (17:52 +0200)
committerHans-Christoph Steiner <hans@eds.org>
Mon, 17 Jul 2017 09:38:15 +0000 (11:38 +0200)
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.

fdroidserver/server.py
tests/run-tests

index 7ca6009a69abd0ad584b5ed322418f4088a4bd27..ebfea3a37876d311cb24e03291422649577dffad 100644 (file)
@@ -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():
index eef54ee4bfa215fef9c6453ecd92be8999c00c7b..2cfdc55aca866095eda78ed274e74c442412a5cd 100755 (executable)
@@ -1051,24 +1051,20 @@ test `grep '<mirror>' 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 '<application id=' $LOCAL_COPY_DIR/repo/index.xml > /dev/null
-    cd $ONLINE_ROOT
-    echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> 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 '<application id=' $LOCAL_COPY_DIR/repo/index.xml > /dev/null
+cd $ONLINE_ROOT
+echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> 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" ]
 
 
 #------------------------------------------------------------------------------#