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