]> git.ipfire.org Git - thirdparty/git.git/commitdiff
hooks--pre-push.sample: use hash-agnostic zero OID
authorDenton Liu <liu.denton@gmail.com>
Wed, 23 Sep 2020 09:38:44 +0000 (02:38 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 23 Sep 2020 16:31:45 +0000 (09:31 -0700)
The pre-push sample hook has the zero OID hardcoded as 40 zeros.
However, with the introduction of SHA-256 support, this assumption no
longer holds true. Replace the hardcoded $z40 with a call to

git hash-object --stdin </dev/null | tr '[0-9a-f]' '0'

so the sample hook becomes hash-agnostic.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
templates/hooks--pre-push.sample

index d0f30190acf4037982d1b07ca6f1b964e369782e..4ce688d32b7532862767345f2b991ae856f7d4a8 100755 (executable)
 remote="$1"
 url="$2"
 
-z40=0000000000000000000000000000000000000000
+zero=$(git hash-object --stdin </dev/null | tr '[0-9a-f]' '0')
 
 while read local_ref local_oid remote_ref remote_oid
 do
-       if test "$local_oid" = $z40
+       if test "$local_oid" = "$zero"
        then
                # Handle delete
                :
        else
-               if test "$remote_oid" = $z40
+               if test "$remote_oid" = "$zero"
                then
                        # New branch, examine all commits
                        range="$local_oid"