aboutsummaryrefslogtreecommitdiff
path: root/git
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2019-05-29 18:42:07 +1200
committerTom Ryder <tom@sanctum.geek.nz>2019-05-29 18:44:07 +1200
commitd424be71f3df78f29239fc3e7ab3680146bb0f4c (patch)
tree566561c2cb037b8755d9142a36228ea24ceaa4b9 /git
parentExclude files with extension from Git hooks (diff)
downloaddotfiles-d424be71f3df78f29239fc3e7ab3680146bb0f4c.tar.gz
dotfiles-d424be71f3df78f29239fc3e7ab3680146bb0f4c.zip
Adjust prepare-commit-msg hook to arguments
<https://git-scm.com/docs/githooks#_prepare_commit_msg> > It takes one to three parameters. The first is the name of the file > that contains the commit log message. The second is the source of the > commit message, and can be: ... merge (if the commit is a merge or a > .git/MERGE_MSG file exists) ...
Diffstat (limited to 'git')
-rwxr-xr-x[-rw-r--r--]git/template/hooks/prepare-commit-msg.awk32
1 files changed, 15 insertions, 17 deletions
diff --git a/git/template/hooks/prepare-commit-msg.awk b/git/template/hooks/prepare-commit-msg.awk
index d1c08c56..800e2220 100644..100755
--- a/git/template/hooks/prepare-commit-msg.awk
+++ b/git/template/hooks/prepare-commit-msg.awk
@@ -1,39 +1,37 @@
# Filter to clean up a merge commit; still experimental on tejr's part.
-# If the first word of the subject line of the commit message is 'Merge', we
-# know we need to rewrite this; otherwise we can just bail out directly
-NR == 1 {
- if (!(rewrite = ($1 == "Merge")))
+# If the second argument to this script is "merge", this is a merge commit, and
+# we know we need to filter it; otherwise we can just bail out directly
+BEGIN {
+ if (ARGV[2] != "merge")
exit(0)
+ message = ARGV[1]
}
-# We're starting a new branch; save the whole line into a variable and skip to
-# the next line
+# This line starts with an asterisk, so we're starting the commit listings for
+# a new branch; save the whole line into a variable and skip to the next line
/^\* / {
branch = $0
next
}
-# Skip this commit, it's just a version number bump
-# Other patterns to skip go HERE; be as precise as you can
-/^ Bump VERSION$/ { next }
+# Commit message subject patterns to skip go here; be as precise as you can
+$0 == " Bump VERSION" { next } # Skip version number bumps
# If we got past this point, we have an actual commit line to include, so if
# there's a branch heading yet to print, we should do so now; add it to the
# line buffer
-length(branch) {
+branch {
lines[++l] = branch
- branch = ""
+ branch = 0
}
# Add the current line to the line buffer
{ lines[++l] = $0 }
-# When we get to the end of the file, we need to decide whether we're going to
-# rewrite the whole thing; note that the exit(0) call above still ends up down
-# here, so we have to check and set a flag
+# If we set the message filename in BEGIN due to this being a merge commit,
+# write our filtered message back to that file, and we're done
END {
- if (rewrite)
- for (i = 1; i <= l; i++)
- print lines[i] > ARGV[1]
+ for (i = 1; message && i <= l; i++)
+ print lines[i] > message
}