[sysadmin-bin] Push refs only if there are any locally



commit b1d39b12b313400bf69d15b51bcaea452d2a6264
Author: Bartłomiej Piotrowski <bpiotrowski gnome org>
Date:   Tue Oct 15 19:57:15 2019 +0200

    Push refs only if there are any locally

 git/post-receive-mirror-github | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)
---
diff --git a/git/post-receive-mirror-github b/git/post-receive-mirror-github
index b7b80a5..d53fbcd 100755
--- a/git/post-receive-mirror-github
+++ b/git/post-receive-mirror-github
@@ -185,7 +185,7 @@ def main():
     if repo_name.endswith('.wiki'):
         sys.exit(1)
 
-    settings = get_repo_settings(repo_name)
+   settings = get_repo_settings(repo_name)
     repo_exists = gh.check_if_repo_exists(repo_name)
 
     # Avoid master here as we will later push it under different name
@@ -204,17 +204,18 @@ def main():
         default_branch = settings["default_branch"]
 
     for organization in [gh.organization] + ADDITIONAL_ORGANIZATIONS.get(repo_name, []):
-        try:
-            command = 'git push --force git github com:{}/{} {}:mainline {}'.format(organization, 
github_name, 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")
-            raise Exception("Error trying to push repo %s/%s\nSTDOUT:\n%s\nSTDERR\n%s" % (organization, 
repo_name, out.read(), err.read()))
+        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")
+                raise Exception("Error trying to push repo %s/%s\nSTDOUT:\n%s\nSTDERR\n%s" % (organization, 
repo_name, out.read(), err.read()))
 
     if default_branch != 'mainline':
         gh.update_github_repo(github_name, 'default_branch', 'mainline')


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