system-manager-wakasu
 1#!/bin/sh
 2
 3# Based on https://gist.github.com/Quintok/815396509ff79d886656b2855e1a8a46
 4
 5# A pre-push hook based on the git template. This will verify that no WIP or
 6# autosquash commits are present. If such a commit is present, pushing will not
 7# be possible.
 8
 9# This hook is called with the following parameters:
10#
11# $1 -- Name of the remote to which the push is being done
12# $2 -- URL to which the push is being done
13#
14# If pushing without using a named remote those arguments will be equal.
15#
16# Information about the commits which are being pushed is supplied as lines to
17# the standard input in the form:
18#
19#   <local ref> <local sha1> <remote ref> <remote sha1>
20
21z40=0000000000000000000000000000000000000000
22
23IFS=' '
24while read -r local_ref local_sha remote_ref remote_sha
25do
26  echo "$remote_ref" > /dev/null
27
28  if [ "$local_sha" = $z40 ]
29  then
30    # Ignore delete
31    :
32  else
33    if [ "$remote_sha" = $z40 ]
34    then
35      # New branch, examine all commits since master
36      range="$(git merge-base $local_sha master)..$local_sha"
37    else
38      # Update to existing branch, examine new commits
39      range="$remote_sha..$local_sha"
40    fi
41
42    # Check for WIP commits
43    commit=$(git rev-list -n 1 --grep '^WIP' "$range")
44    if [ "${local_ref}" = refs/heads/master ] && [ -n "$commit" ]
45    then
46      printf "\nPush rejected: WIP commit detected\n\n"
47      exit 1
48    fi
49
50    # Check for autosquash commits
51    commit=$(git rev-list -n 1 --grep '^\(fixup\|squash\)!' "$range")
52    if [ -n "$commit" ]
53    then
54      printf "\nPush rejected: autosquash commit detected\n\n"
55      exit 1
56    fi
57  fi
58done
59
60# Local Variables:
61# sh-basic-offset: 2
62# End: