[sysadmin-bin] Use git push --mirror if default branch in GitLab is mainline



commit 5ce654e58c093bdc222786135bf73fd59d67e2a6
Author: Bartłomiej Piotrowski <bpiotrowski gnome org>
Date:   Mon Oct 28 15:33:45 2019 +0100

    Use git push --mirror if default branch in GitLab is mainline

 git/post-receive-mirror-github | 55 +++++++++++++++++++++++++++++-------------
 1 file changed, 38 insertions(+), 17 deletions(-)
---
diff --git a/git/post-receive-mirror-github b/git/post-receive-mirror-github
index ff54ba6..01f3f5c 100755
--- a/git/post-receive-mirror-github
+++ b/git/post-receive-mirror-github
@@ -203,32 +203,53 @@ def main():
         gh.create_github_repo(settings["name"], settings["description"], settings["homepage"])
         default_branch = settings["default_branch"]
 
-    for organization in [gh.organization] + ADDITIONAL_ORGANIZATIONS.get(repo_name, []):
-        if refs:
-            try:
-                command = 'git push --force git github com:{}/{} {}:mainline {}'.format(organization, 
github_name, settings['default_branch'], " ".join(refs))
-                out = tempfile.NamedTemporaryFile(prefix="github",suffix="std")
-                err = tempfile.NamedTemporaryFile(prefix="github",suffix="err")
-                subprocess.check_call(shlex.split(command), stderr=err, stdout=out)
-                out.close()
-                err.close()
-            except subprocess.CalledProcessError:
-                out = open(out.name, "r")
-                err = open(err.name, "r")
-                error_msg = """
+    if default_branch != 'mainline':
+        for organization in [gh.organization] + ADDITIONAL_ORGANIZATIONS.get(repo_name, []):
+            if refs:
+                try:
+                    command = 'git push --force git github com:{}/{} {}:mainline {}'.format(organization, 
github_name, settings['default_branch'], " ".join(refs))
+                    out = tempfile.NamedTemporaryFile(prefix="github",suffix="std")
+                    err = tempfile.NamedTemporaryFile(prefix="github",suffix="err")
+                    subprocess.check_call(shlex.split(command), stderr=err, stdout=out)
+                    out.close()
+                    err.close()
+                except subprocess.CalledProcessError:
+                    out = open(out.name, "r")
+                    err = open(err.name, "r")
+                    error_msg = """
 Error trying to push repo {}/{}
+Command: {}
 STDOUT: {}
 STDERR: {}
-
-Command: {}
 """.format(organization, repo_name, out.read(), err.read(), command)
-                raise Exception(error_msg)
+                    raise Exception(error_msg)
 
-    if default_branch != 'mainline':
         _, _, _, branches = gh.fetch_github_repo(github_name)
         if "mainline" in branches:
             gh.update_github_repo(github_name, 'default_branch', 'mainline')
 
+    if default_branch == 'mainline':
+        for organization in [gh.organization] + ADDITIONAL_ORGANIZATIONS.get(repo_name, []):
+            if refs:
+                try:
+                    command = 'git push --mirror git github com:{}/{} {}:mainline {}'.format(organization, 
github_name)
+                    out = tempfile.NamedTemporaryFile(prefix="github",suffix="std")
+                    err = tempfile.NamedTemporaryFile(prefix="github",suffix="err")
+                    subprocess.check_call(shlex.split(command), stderr=err, stdout=out)
+                    out.close()
+                    err.close()
+                except subprocess.CalledProcessError:
+                    out = open(out.name, "r")
+                    err = open(err.name, "r")
+                    error_msg = """
+Error trying to push repo {}/{}
+Command: {}
+STDOUT: {}
+STDERR: {}
+""".format(organization, repo_name, out.read(), err.read(), command)
+                    raise Exception(error_msg)
+
+
     # Drop master branch in separate loop as GitHub API disallows to drop the
     # default branch and also expects new default branch to exists
     for organization in [gh.organization] + ADDITIONAL_ORGANIZATIONS.get(repo_name, []):


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]