pre-push revision 43147a9abaa1254235b853e643514cf1c7b150d7
43147a9abaa1254235b853e643514cf1c7b150d7Jakub Hrozek# A git pre-push hook that declines commits that don't contain a Reviewed-By:
43147a9abaa1254235b853e643514cf1c7b150d7Jakub Hrozek# tag. The tag must be present on the beginning of the line. To activate, copy
43147a9abaa1254235b853e643514cf1c7b150d7Jakub Hrozek# to $GIT_DIR/hooks/pre-push and make sure the executable flag is on.
43147a9abaa1254235b853e643514cf1c7b150d7Jakub Hrozek# The commit message should also be based on .git-commit-template, although
43147a9abaa1254235b853e643514cf1c7b150d7Jakub Hrozek# that is just best practice and not enforced
43147a9abaa1254235b853e643514cf1c7b150d7Jakub Hrozek args = ['git', 'rev-list', '{:s}..{:s}'.format(ref_from, ref_to)]
43147a9abaa1254235b853e643514cf1c7b150d7Jakub Hrozek p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
43147a9abaa1254235b853e643514cf1c7b150d7Jakub Hrozek return [commit.strip() for commit in out.split('\n') if commit != '']
43147a9abaa1254235b853e643514cf1c7b150d7Jakub Hrozek args = ['git', 'cat-file', 'commit', commit_hash]
43147a9abaa1254235b853e643514cf1c7b150d7Jakub Hrozek p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
43147a9abaa1254235b853e643514cf1c7b150d7Jakub Hrozek print("Commit {:s} does not have Reviewed-By!".format(commit_hash))
43147a9abaa1254235b853e643514cf1c7b150d7Jakub Hrozek print("{:s}".format(commit_message(commit_hash)))
43147a9abaa1254235b853e643514cf1c7b150d7Jakub Hrozek# man 5 githooks says:
43147a9abaa1254235b853e643514cf1c7b150d7Jakub Hrozek# Information about what is to be pushed is provided on the hook's
43147a9abaa1254235b853e643514cf1c7b150d7Jakub Hrozek# standard input with lines of the form:
43147a9abaa1254235b853e643514cf1c7b150d7Jakub Hrozek# <local ref> SP <local sha1> SP <remote ref> SP <remote sha1> LF
43147a9abaa1254235b853e643514cf1c7b150d7Jakub Hrozek commit_list = get_all_commits(ref_from, ref_to)
43147a9abaa1254235b853e643514cf1c7b150d7Jakub Hrozek# Don't warn when pushing to personal repositories, only origin