]> git.ipfire.org Git - thirdparty/git.git/blobdiff - templates/hooks--pre-push.sample
Merge branch 'jk/stop-pack-objects-when-push-is-killed'
[thirdparty/git.git] / templates / hooks--pre-push.sample
index 6187dbf4390fc6e28445dd3d988aefb9d1111988..4ce688d32b7532862767345f2b991ae856f7d4a8 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).
 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