You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.3 KiB

2 years ago
  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 oid> <remote ref> <remote oid>
  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. zero=$(git hash-object --stdin </dev/null | tr '[0-9a-f]' '0')
  23. while read local_ref local_oid remote_ref remote_oid
  24. do
  25. if test "$local_oid" = "$zero"
  26. then
  27. # Handle delete
  28. :
  29. else
  30. if test "$remote_oid" = "$zero"
  31. then
  32. # New branch, examine all commits
  33. range="$local_oid"
  34. else
  35. # Update to existing branch, examine new commits
  36. range="$remote_oid..$local_oid"
  37. fi
  38. # Check for WIP commit
  39. commit=$(git rev-list -n 1 --grep '^WIP' "$range")
  40. if test -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