.git/hooks/prepare-commit-msg.sample
author Pascal Volk <user@localhost.localdomain.org>
Sun, 21 Nov 2021 22:04:40 +0000
changeset 762 0147c0a9ce2b
permissions -rwxr-xr-x
Added a README and the files of the empty vmm.git Simply `git pull` it.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
762
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
     1
#!/bin/sh
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
     2
#
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
     3
# An example hook script to prepare the commit log message.
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
     4
# Called by "git commit" with the name of the file that has the
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
     5
# commit message, followed by the description of the commit
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
     6
# message's source.  The hook's purpose is to edit the commit
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
     7
# message file.  If the hook fails with a non-zero status,
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
     8
# the commit is aborted.
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
     9
#
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    10
# To enable this hook, rename this file to "prepare-commit-msg".
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    11
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    12
# This hook includes three examples. The first one removes the
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    13
# "# Please enter the commit message..." help message.
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    14
#
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    15
# The second includes the output of "git diff --name-status -r"
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    16
# into the message, just before the "git status" output.  It is
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    17
# commented because it doesn't cope with --amend or with squashed
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    18
# commits.
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    19
#
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    20
# The third example adds a Signed-off-by line to the message, that can
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    21
# still be edited.  This is rarely a good idea.
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    22
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    23
COMMIT_MSG_FILE=$1
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    24
COMMIT_SOURCE=$2
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    25
SHA1=$3
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    26
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    27
/usr/bin/perl -i.bak -ne 'print unless(m/^. Please enter the commit message/..m/^#$/)' "$COMMIT_MSG_FILE"
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    28
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    29
# case "$COMMIT_SOURCE,$SHA1" in
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    30
#  ,|template,)
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    31
#    /usr/bin/perl -i.bak -pe '
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    32
#       print "\n" . `git diff --cached --name-status -r`
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    33
# 	 if /^#/ && $first++ == 0' "$COMMIT_MSG_FILE" ;;
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    34
#  *) ;;
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    35
# esac
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    36
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    37
# SOB=$(git var GIT_COMMITTER_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    38
# git interpret-trailers --in-place --trailer "$SOB" "$COMMIT_MSG_FILE"
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    39
# if test -z "$COMMIT_SOURCE"
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    40
# then
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    41
#   /usr/bin/perl -i.bak -pe 'print "\n" if !$first_line++' "$COMMIT_MSG_FILE"
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    42
# fi