git hooks: commit msg: allow to opt in for auto-sign-off
Just the subset when author and the committer is the same. Signed-off-by: Miklos Vajna <vmiklos@collabora.com> Change-Id: Icff594a6a82bd0395e31f8e46cb56cb0e046e638
This commit is contained in:
parent
bb30f7c346
commit
32517390e8
2 changed files with 28 additions and 6 deletions
11
.git-hooks/README
Normal file
11
.git-hooks/README
Normal file
|
@ -0,0 +1,11 @@
|
|||
commit-msg
|
||||
----------
|
||||
|
||||
This hooks supports the `commit.signOff` option.
|
||||
|
||||
This is a boolean value which lets you enable the -s/--signoff option of
|
||||
commit by default. Note: Adding the Signed-off-by: line to a commit should be
|
||||
a conscious act and means that you certify you have the rights to submit this
|
||||
work under the same open source license. Please see the README.CONTRIBUTING.md
|
||||
document for further discussion. The option is ignored if the author and the
|
||||
committer is not the same.
|
|
@ -28,9 +28,26 @@ if test ! -f "$1" ; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
# $RANDOM will be undefined if not using bash, so don't use set -u
|
||||
random=$( (whoami ; hostname ; date; cat $1 ; echo $RANDOM) | git hash-object --stdin)
|
||||
dest="$1.tmp.${random}"
|
||||
|
||||
trap 'rm -f "${dest}"' EXIT
|
||||
|
||||
GIT_AUTHOR="$(git var GIT_AUTHOR_IDENT | sed 's/^\(.*>\).*$/\1/')"
|
||||
GIT_COMMITTER="$(git var GIT_COMMITTER_IDENT | sed 's/^\(.*>\).*$/\1/')"
|
||||
git config --bool --get commit.signOff >/dev/null
|
||||
if [ $? = 0 -a "${GIT_AUTHOR}" = "${GIT_COMMITTER}" ]; then
|
||||
SOB="Signed-off-by: ${GIT_AUTHOR}"
|
||||
git -c trailer.ifexists=doNothing interpret-trailers \
|
||||
--trailer "${SOB}" < "$1" > "${dest}"
|
||||
mv "${dest}" "$1"
|
||||
fi
|
||||
|
||||
if ! grep -q "^Signed-off-by:" "$1"; then
|
||||
echo "Commit message is not signed off: $1"
|
||||
echo "Use 'git commit -s' to sign off the commit message."
|
||||
echo "Use 'git config commit.signOff true' to automatically sign off commits."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
@ -39,12 +56,6 @@ if test "false" = "`git config --bool --get gerrit.createChangeId`" ; then
|
|||
exit 0
|
||||
fi
|
||||
|
||||
# $RANDOM will be undefined if not using bash, so don't use set -u
|
||||
random=$( (whoami ; hostname ; date; cat $1 ; echo $RANDOM) | git hash-object --stdin)
|
||||
dest="$1.tmp.${random}"
|
||||
|
||||
trap 'rm -f "${dest}"' EXIT
|
||||
|
||||
if ! git stripspace --strip-comments < "$1" > "${dest}" ; then
|
||||
echo "cannot strip comments from $1"
|
||||
exit 1
|
||||
|
|
Loading…
Reference in a new issue