Merge pull request #3 from damien-list/master
[git-mirror.git] / githook.py
index 47a87e95115ac0092e1948ea2fd428c0a500c5ad..fcfb392bc662984c1837f2d7bfe28d8be1f829e7 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/env python3
 # Copyright (c) 2015, Ralf Jung <post@ralfj.de>
 # All rights reserved.
 # 
@@ -35,17 +35,20 @@ if __name__ == "__main__":
         # find the repository we are dealing with
         reponame = find_repo_by_directory(repos, os.getcwd())
         if reponame is None or reponame not in repos:
-            raise Exception("Unknown repository.")
+            raise Exception("Unknown repository {}.".format(reponame))
         
         # now sync this repository
         repo = repos[reponame]
         # parse the information we get from stdin. we trust this information.
         for line in sys.stdin:
-            (oldsha, newsha, ref) = line.split()
+            line = line.split()
+            if len(line) == 0: continue
+            assert len(line) == 3
+            (oldsha, newsha, ref) = line
             repo.update_mirrors(ref, oldsha, newsha)
     except Exception as e:
         if repo is not None:
             repo.mail_owner("There was a problem running the git-mirror git hook:\n\n{}".format(traceback.format_exc()))
         # do not print all the details
-        sys.stderr.write("We have a problem:\n{}".format('\n'.join(traceback.format_exception_only(type(e), e))))
+        sys.stderr.write("git-mirror: We have a problem:\n{}".format('\n'.join(traceback.format_exception_only(type(e), e))))