prepare-commit-msg.sample 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/bin/sh
  2. #
  3. # An example hook script to prepare the commit log message.
  4. # Called by "git commit" with the name of the file that has the
  5. # commit message, followed by the description of the commit
  6. # message's source. The hook's purpose is to edit the commit
  7. # message file. If the hook fails with a non-zero status,
  8. # the commit is aborted.
  9. #
  10. # To enable this hook, rename this file to "prepare-commit-msg".
  11. # This hook includes three examples. The first one removes the
  12. # "# Please enter the commit message..." help message.
  13. #
  14. # The second includes the output of "git diff --name-status -r"
  15. # into the message, just before the "git status" output. It is
  16. # commented because it doesn't cope with --amend or with squashed
  17. # commits.
  18. #
  19. # The third example adds a Signed-off-by line to the message, that can
  20. # still be edited. This is rarely a good idea.
  21. COMMIT_MSG_FILE=$1
  22. COMMIT_SOURCE=$2
  23. SHA1=$3
  24. /usr/bin/perl -i.bak -ne 'print unless(m/^. Please enter the commit message/..m/^#$/)' "$COMMIT_MSG_FILE"
  25. # case "$COMMIT_SOURCE,$SHA1" in
  26. # ,|template,)
  27. # /usr/bin/perl -i.bak -pe '
  28. # print "\n" . `git diff --cached --name-status -r`
  29. # if /^#/ && $first++ == 0' "$COMMIT_MSG_FILE" ;;
  30. # *) ;;
  31. # esac
  32. # SOB=$(git var GIT_COMMITTER_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
  33. # git interpret-trailers --in-place --trailer "$SOB" "$COMMIT_MSG_FILE"
  34. # if test -z "$COMMIT_SOURCE"
  35. # then
  36. # /usr/bin/perl -i.bak -pe 'print "\n" if !$first_line++' "$COMMIT_MSG_FILE"
  37. # fi