From 6a117da6e523a82115733682f4d3f59755897d5a Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 23 Sep 2020 02:38:43 -0700 Subject: [PATCH 1/3] hooks--pre-push.sample: modernize script The preferred form for a command substitution is $() over ``. Use this form for the command substitution in the sample hook. The preferred form for conditional tests is to use `test` over []. Replace [] with `test`. Finally, replace all instances of "sha" with "oid". Signed-off-by: Denton Liu Signed-off-by: Junio C Hamano --- templates/hooks--pre-push.sample | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/templates/hooks--pre-push.sample b/templates/hooks--pre-push.sample index 6187dbf439..d0f30190ac 100755 --- a/templates/hooks--pre-push.sample +++ b/templates/hooks--pre-push.sample @@ -14,7 +14,7 @@ # Information about the commits which are being pushed is supplied as lines to # the standard input in the form: # -# +# # # This sample shows how to prevent push of commits where the log message starts # with "WIP" (work in progress). @@ -24,25 +24,25 @@ url="$2" z40=0000000000000000000000000000000000000000 -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" = $z40 then # Handle delete : else - if [ "$remote_sha" = $z40 ] + if test "$remote_oid" = $z40 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 From 8c7e5059506c6840bfbd4dd8d1730784a5689719 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 23 Sep 2020 02:38:44 -0700 Subject: [PATCH 2/3] hooks--pre-push.sample: use hash-agnostic zero OID 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 Signed-off-by: Junio C Hamano --- templates/hooks--pre-push.sample | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/hooks--pre-push.sample b/templates/hooks--pre-push.sample index d0f30190ac..4ce688d32b 100755 --- a/templates/hooks--pre-push.sample +++ b/templates/hooks--pre-push.sample @@ -22,16 +22,16 @@ remote="$1" url="$2" -z40=0000000000000000000000000000000000000000 +zero=$(git hash-object --stdin Date: Wed, 23 Sep 2020 02:38:45 -0700 Subject: [PATCH 3/3] hooks--update.sample: use hash-agnostic zero OID The update 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 Signed-off-by: Junio C Hamano --- templates/hooks--update.sample | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/hooks--update.sample b/templates/hooks--update.sample index 5014c4b31c..c4d426bc6e 100755 --- a/templates/hooks--update.sample +++ b/templates/hooks--update.sample @@ -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