Skip to content

Commit 9f489ac

Browse files
committed
Merge branch 'dl/zero-oid-in-hooks'
Adjust sample hooks for hash algorithm other than SHA-1. * dl/zero-oid-in-hooks: hooks--update.sample: use hash-agnostic zero OID hooks--pre-push.sample: use hash-agnostic zero OID hooks--pre-push.sample: modernize script
2 parents e76ae33 + d8d3d63 commit 9f489ac

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

templates/hooks--pre-push.sample

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,35 @@
1414
# Information about the commits which are being pushed is supplied as lines to
1515
# the standard input in the form:
1616
#
17-
# <local ref> <local sha1> <remote ref> <remote sha1>
17+
# <local ref> <local oid> <remote ref> <remote oid>
1818
#
1919
# This sample shows how to prevent push of commits where the log message starts
2020
# with "WIP" (work in progress).
2121

2222
remote="$1"
2323
url="$2"
2424

25-
z40=0000000000000000000000000000000000000000
25+
zero=$(git hash-object --stdin </dev/null | tr '[0-9a-f]' '0')
2626

27-
while read local_ref local_sha remote_ref remote_sha
27+
while read local_ref local_oid remote_ref remote_oid
2828
do
29-
if [ "$local_sha" = $z40 ]
29+
if test "$local_oid" = "$zero"
3030
then
3131
# Handle delete
3232
:
3333
else
34-
if [ "$remote_sha" = $z40 ]
34+
if test "$remote_oid" = "$zero"
3535
then
3636
# New branch, examine all commits
37-
range="$local_sha"
37+
range="$local_oid"
3838
else
3939
# Update to existing branch, examine new commits
40-
range="$remote_sha..$local_sha"
40+
range="$remote_oid..$local_oid"
4141
fi
4242

4343
# Check for WIP commit
44-
commit=`git rev-list -n 1 --grep '^WIP' "$range"`
45-
if [ -n "$commit" ]
44+
commit=$(git rev-list -n 1 --grep '^WIP' "$range")
45+
if test -n "$commit"
4646
then
4747
echo >&2 "Found WIP commit in $local_ref, not pushing"
4848
exit 1

templates/hooks--update.sample

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ esac
6060

6161
# --- Check types
6262
# if $newrev is 0000...0000, it's a commit to delete a ref.
63-
zero="0000000000000000000000000000000000000000"
63+
zero=$(git hash-object --stdin </dev/null | tr '[0-9a-f]' '0')
6464
if [ "$newrev" = "$zero" ]; then
6565
newrev_type=delete
6666
else

0 commit comments

Comments
 (0)