summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2010-08-30 13:27:14 -0400
committerBrad King <brad.king@kitware.com>2010-08-30 13:27:14 -0400
commitcb038d0b57fa6d131089066b71a30ad284df3c3c (patch)
tree9954c0d2737c6d21ad64289dd422e60ef9e4a053
parent7cd9751649d0bb93bdc7b88f96b840877c202b11 (diff)
downloadcmake-cb038d0b57fa6d131089066b71a30ad284df3c3c.tar.gz
commit-msg: Invoke gerrit/commit-msg if hooks.GerritId=true
Add a Gerrit Change-Id header if hooks.GerritId is true. Print help if the option is not set and a remote URL looks like Gerrit.
-rwxr-xr-xcommit-msg42
1 files changed, 41 insertions, 1 deletions
diff --git a/commit-msg b/commit-msg
index 19d2d4cbe5..37fa32be5a 100755
--- a/commit-msg
+++ b/commit-msg
@@ -79,4 +79,44 @@ cat "$commit_msg" |
while IFS='' read line; do
msg_$state || break
done &&
-rm -f "$commit_msg"
+rm -f "$commit_msg" || exit 1
+
+#-----------------------------------------------------------------------------
+# Optionally run Gerrit's commit-msg hook to add a Change-Id line.
+
+gerrit_advice() {
+ gerrits=$(git config -l |grep '^remote\.[^=]\+url=.*review.*$')
+ test "x$gerrits" != "x" || return
+
+ echo 'Some config values look like Gerrit Code Review URLs:'
+ echo ''
+ echo "$gerrits" | sed 's/^/ /'
+ echo '
+This hook can automatically add a "Change-Id" footer to commit messages
+to make interaction with Gerrit easier. To enable this feature, run
+
+ git config hooks.GerritId true
+
+Then run "git commit --amend" to fix this commit. Otherwise, run
+
+ git config hooks.GerritId false
+
+to disable the feature and this message.'
+}
+
+gerrit_error() {
+ die 'non-bool config value hooks.GerritId = '"$hooks_GerritId"
+}
+
+gerrit_hook() {
+ "$GIT_DIR/hooks/gerrit/commit-msg" "$@" ||
+ die 'gerrit/commit-msg failed'
+}
+
+hooks_GerritId=$(git config --get hooks.GerritId)
+case "$hooks_GerritId" in
+ 'true') gerrit_hook "$@" ;;
+ 'false') ;;
+ '') gerrit_advice ;;
+ *) gerrit_error ;;
+esac