aboutsummaryrefslogtreecommitdiff
path: root/ssh-sync-repos.py
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2016-06-18 19:02:17 -0400
committerRob Austein <sra@hactrn.net>2016-06-18 19:02:17 -0400
commitef27539ad71977b06683bbc304760f366ed4199e (patch)
tree86e66ba6003fb1e88d879300a7c826fbd1722fa4 /ssh-sync-repos.py
parent6b1074775e5f62541a31240e8abf44b5cd95b700 (diff)
Add --prune to fetch commands; track (old) HTTPS configuration changes; general cleanup.
Diffstat (limited to 'ssh-sync-repos.py')
-rwxr-xr-xssh-sync-repos.py37
1 files changed, 20 insertions, 17 deletions
diff --git a/ssh-sync-repos.py b/ssh-sync-repos.py
index 5d585a3..fd418e4 100755
--- a/ssh-sync-repos.py
+++ b/ssh-sync-repos.py
@@ -3,26 +3,29 @@
# Synchronize Cryptech git repositories via SSH by asking gitolite for a JSON
# listing of repositories. Not useful unless you have an SSH account, sorry.
-import json, subprocess, os.path, sys
+from subprocess import check_call, check_output
+from os.path import isdir
+from json import loads
+from sys import exit
user = "git@git.cryptech.is"
-cmd = "ssh %s info -json -lc" % user
-info = json.loads(subprocess.check_output(cmd.split()))
+cmd = "ssh {} info -json -lc".format(user)
+info = loads(check_output(cmd.split()))
errs = 0
for repo in sorted(info["repos"]):
- try:
- if all(c not in repo for c in "*?[]"):
- print
- print repo
- pull = os.path.isdir(repo)
- if pull:
- subprocess.check_call(("git", "fetch", "--all"), cwd = repo)
- subprocess.check_call(("git", "pull"), cwd = repo)
- else:
- subprocess.check_call(("git", "clone", "%s:%s.git" % (user, repo), repo))
- except:
- print "** Error", "pulling" if pull else "cloning", repo
- errs += 1
+ try:
+ if all(c not in repo for c in "*?[]"):
+ print
+ print repo
+ pull = isdir(repo)
+ if pull:
+ check_call(("git", "fetch", "--all", "--prune"), cwd = repo)
+ check_call(("git", "pull"), cwd = repo)
+ else:
+ check_call(("git", "clone", "{}:{}.git".format(user, repo), repo))
+ except:
+ print "** Error", "pulling" if pull else "cloning", repo
+ errs += 1
-sys.exit(errs)
+exit(errs)