From 4d065accbb66272c2a3630372349cd4013efb664 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Caletka?= Date: Thu, 12 Jul 2018 15:55:33 +0200 Subject: [PATCH] Implement update hook --- dzonegit.py | 22 ++++++++++++++++++++++ setup.py | 1 + 2 files changed, 23 insertions(+) diff --git a/dzonegit.py b/dzonegit.py index b32892e..81e1932 100644 --- a/dzonegit.py +++ b/dzonegit.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 +import os import sys import subprocess import re @@ -243,11 +244,32 @@ def pre_commit(): raise SystemExit(1) +def update(): + if "GIT_DIR" not in os.environ: + raise SystemExit("Don't run this hook from command line") + if len(sys.argv) < 4: + raise SystemExit( + "Usage: {} ".format(sys.argv[0]), + ) + refname, against, revision = sys.argv[1:4] + + if refname != "refs/heads/master": + raise SystemExit("Nothing else except master branch is accepted here") + try: + check_whitespace_errors(against, revision) + check_updated_zones(against, revision) + except HookException as e: + print(e) + raise SystemExit(1) + + def main(): name = Path(sys.argv[0]).name print(name) if name == "pre-commit": pre_commit() + elif name == "update": + update() else: sys.exit("No valid command found") diff --git a/setup.py b/setup.py index 003cfdf..3bcfd3b 100644 --- a/setup.py +++ b/setup.py @@ -16,6 +16,7 @@ setup( "console_scripts": [ "dzonegit = dzonegit:main", "dzonegit-pre-commit = dzonegit:pre_commit", + "dzonegit-update = dzonegit:update", ], }, classifiers=[