pre-push.sample 1.3 KB

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