]>
Commit | Line | Data |
---|---|---|
87c86dd1 AS |
1 | #!/bin/sh |
2 | ||
3 | # An example hook script to verify what is about to be pushed. Called by "git | |
4 | # push" after it has checked the remote status, but before anything has been | |
5 | # pushed. If this script exits with a non-zero status nothing will be pushed. | |
6 | # | |
7 | # This hook is called with the following parameters: | |
8 | # | |
9 | # $1 -- Name of the remote to which the push is being done | |
10 | # $2 -- URL to which the push is being done | |
11 | # | |
12 | # If pushing without using a named remote those arguments will be equal. | |
13 | # | |
14 | # Information about the commits which are being pushed is supplied as lines to | |
15 | # the standard input in the form: | |
16 | # | |
6a117da6 | 17 | # <local ref> <local oid> <remote ref> <remote oid> |
87c86dd1 AS |
18 | # |
19 | # This sample shows how to prevent push of commits where the log message starts | |
20 | # with "WIP" (work in progress). | |
21 | ||
22 | remote="$1" | |
23 | url="$2" | |
24 | ||
8c7e5059 | 25 | zero=$(git hash-object --stdin </dev/null | tr '[0-9a-f]' '0') |
87c86dd1 | 26 | |
6a117da6 | 27 | while read local_ref local_oid remote_ref remote_oid |
87c86dd1 | 28 | do |
8c7e5059 | 29 | if test "$local_oid" = "$zero" |
87c86dd1 AS |
30 | then |
31 | # Handle delete | |
6897a64b | 32 | : |
87c86dd1 | 33 | else |
8c7e5059 | 34 | if test "$remote_oid" = "$zero" |
87c86dd1 AS |
35 | then |
36 | # New branch, examine all commits | |
6a117da6 | 37 | range="$local_oid" |
87c86dd1 AS |
38 | else |
39 | # Update to existing branch, examine new commits | |
6a117da6 | 40 | range="$remote_oid..$local_oid" |
87c86dd1 AS |
41 | fi |
42 | ||
43 | # Check for WIP commit | |
6a117da6 DL |
44 | commit=$(git rev-list -n 1 --grep '^WIP' "$range") |
45 | if test -n "$commit" | |
87c86dd1 | 46 | then |
1a947ba3 | 47 | echo >&2 "Found WIP commit in $local_ref, not pushing" |
87c86dd1 AS |
48 | exit 1 |
49 | fi | |
50 | fi | |
51 | done | |
52 | ||
53 | exit 0 |