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
This commit is contained in:
Junio C Hamano 2020-09-29 14:01:21 -07:00
commit 9f489ac6bb
2 changed files with 10 additions and 10 deletions

View File

@ -14,7 +14,7 @@
# Information about the commits which are being pushed is supplied as lines to
# the standard input in the form:
#
# <local ref> <local sha1> <remote ref> <remote sha1>
# <local ref> <local oid> <remote ref> <remote oid>
#
# This sample shows how to prevent push of commits where the log message starts
# with "WIP" (work in progress).
@ -22,27 +22,27 @@
remote="$1"
url="$2"
z40=0000000000000000000000000000000000000000
zero=$(git hash-object --stdin </dev/null | tr '[0-9a-f]' '0')
while read local_ref local_sha remote_ref remote_sha
while read local_ref local_oid remote_ref remote_oid
do
if [ "$local_sha" = $z40 ]
if test "$local_oid" = "$zero"
then
# Handle delete
:
else
if [ "$remote_sha" = $z40 ]
if test "$remote_oid" = "$zero"
then
# New branch, examine all commits
range="$local_sha"
range="$local_oid"
else
# Update to existing branch, examine new commits
range="$remote_sha..$local_sha"
range="$remote_oid..$local_oid"
fi
# Check for WIP commit
commit=`git rev-list -n 1 --grep '^WIP' "$range"`
if [ -n "$commit" ]
commit=$(git rev-list -n 1 --grep '^WIP' "$range")
if test -n "$commit"
then
echo >&2 "Found WIP commit in $local_ref, not pushing"
exit 1

View File

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