aboutsummaryrefslogtreecommitdiff
path: root/contrib/prepare-commit-msg
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2020-05-22 18:40:35 -0400
committerMartin Liska <mliska@suse.cz>2020-05-26 08:38:24 +0200
commit757dbb59c1f2cd88c84a6dc7dc038e4da750b035 (patch)
treeb23b29e0cb81510b99e04b750ae88adb70a0a4e0 /contrib/prepare-commit-msg
parentb8e5f22671e900d9c7757f6289cc10d0c4fd0f03 (diff)
downloadgcc-757dbb59c1f2cd88c84a6dc7dc038e4da750b035.zip
gcc-757dbb59c1f2cd88c84a6dc7dc038e4da750b035.tar.gz
gcc-757dbb59c1f2cd88c84a6dc7dc038e4da750b035.tar.bz2
gcc-git: Add prepare-commit-msg hook.
This patch introduces a prepare-commit-msg hook that appends a ChangeLog skeleton to a commit message when the GCC_FORCE_MKLOG environment variable is set, and a 'git commit-mklog' command set that variable while running 'git commit'. contrib/ChangeLog: * prepare-commit-msg: New file. * gcc-git-customization.sh: Install it. Add commit-mklog alias. * mklog.py: Add new option -c which appends to a ChangeLog file.
Diffstat (limited to 'contrib/prepare-commit-msg')
-rwxr-xr-xcontrib/prepare-commit-msg57
1 files changed, 57 insertions, 0 deletions
diff --git a/contrib/prepare-commit-msg b/contrib/prepare-commit-msg
new file mode 100755
index 0000000..820dacc
--- /dev/null
+++ b/contrib/prepare-commit-msg
@@ -0,0 +1,57 @@
+#!/bin/sh
+
+# Copyright (C) 2020 Free Software Foundation, Inc.
+#
+# This file is part of GCC.
+#
+# GCC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GCC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING. If not, write to
+# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+
+COMMIT_MSG_FILE=$1
+COMMIT_SOURCE=$2
+SHA1=$3
+
+# Can't do anything if $COMMIT_MSG_FILE isn't a file.
+if ! [ -f "$COMMIT_MSG_FILE" ]; then exit 0; fi
+
+# Don't do anything unless requested to.
+if [ -z "$GCC_FORCE_MKLOG" ]; then exit 0; fi
+
+if [ -z "$COMMIT_SOURCE" ] || [ $COMMIT_SOURCE = template ]; then
+ # No source or "template" means new commit.
+ cmd="diff --cached"
+
+elif [ $COMMIT_SOURCE = message ]; then
+ # "message" means -m; assume a new commit if there are any changes staged.
+ if ! git diff --cached --quiet; then
+ cmd="diff --cached"
+ else
+ cmd="diff --cached HEAD^"
+ fi
+
+elif [ $COMMIT_SOURCE = commit ]; then
+ # The message of an existing commit. If it's HEAD, assume --amend;
+ # otherwise, assume a new commit with -C.
+ if [ $SHA1 = HEAD ]; then
+ cmd="diff --cached HEAD^"
+ else
+ cmd="diff --cached"
+ fi
+else
+ # Do nothing for merge or squash.
+ exit 0
+fi
+
+git $cmd | git gcc-mklog -c "$COMMIT_MSG_FILE"