Merge branch 'da/difftool-git-files'
[git/gitweb.git] / templates / hooks--pre-push.sample
blob1f3bcebfd76ae1b37e1542631a87e5a5e3e6b1eb
1 #!/bin/sh
3 # An example hook script to verify what is about to be pushed. Called by "git
4 # push" after it has checked the remote status, but before anything has been
5 # pushed. If this script exits with a non-zero status nothing will be pushed.
7 # This hook is called with the following parameters:
9 # $1 -- Name of the remote to which the push is being done
10 # $2 -- URL to which the push is being done
12 # If pushing without using a named remote those arguments will be equal.
14 # Information about the commits which are being pushed is supplied as lines to
15 # the standard input in the form:
17 # <local ref> <local sha1> <remote ref> <remote sha1>
19 # This sample shows how to prevent push of commits where the log message starts
20 # with "WIP" (work in progress).
22 remote="$1"
23 url="$2"
25 z40=0000000000000000000000000000000000000000
27 IFS=' '
28 while read local_ref local_sha remote_ref remote_sha
30 if [ "$local_sha" = $z40 ]
31 then
32 # Handle delete
34 else
35 if [ "$remote_sha" = $z40 ]
36 then
37 # New branch, examine all commits
38 range="$local_sha"
39 else
40 # Update to existing branch, examine new commits
41 range="$remote_sha..$local_sha"
44 # Check for WIP commit
45 commit=`git rev-list -n 1 --grep '^WIP' "$range"`
46 if [ -n "$commit" ]
47 then
48 echo "Found WIP commit in $local_ref, not pushing"
49 exit 1
52 done
54 exit 0