]> git.ipfire.org Git - thirdparty/git.git/commitdiff
hooks--pre-push.sample: modernize script
authorDenton Liu <liu.denton@gmail.com>
Wed, 23 Sep 2020 09:38:43 +0000 (02:38 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 23 Sep 2020 16:31:45 +0000 (09:31 -0700)
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 <liu.denton@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
templates/hooks--pre-push.sample

index 6187dbf4390fc6e28445dd3d988aefb9d1111988..d0f30190acf4037982d1b07ca6f1b964e369782e 100755 (executable)
@@ -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).
@@ -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