diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2019-05-29 18:11:56 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2019-05-29 18:11:56 +1200 |
commit | f5952200fe81b2b5ffecef32030398ea3db0842c (patch) | |
tree | f4d0e6eae723334ca3b3d76a20e3da67e94b0c0b | |
parent | Add some nice comments to post-update Git hook (diff) | |
download | dotfiles-f5952200fe81b2b5ffecef32030398ea3db0842c.tar.gz dotfiles-f5952200fe81b2b5ffecef32030398ea3db0842c.zip |
Add an attempt at a commit merge message filter
The idea is to automatically strip out semver version number bumps from
commit merge logs, and maybe other nonsense later on. Let's see how
well this works.
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | git/template/hooks/applypatch-msg.awk | 39 |
3 files changed, 42 insertions, 1 deletions
@@ -170,6 +170,7 @@ /games/zs /git/gitconfig /git/gitconfig.m4 +/git/template/hooks/applypatch-msg /git/template/hooks/post-update /gnupg/gpg.conf /gnupg/gpg.conf.m4 @@ -263,7 +263,8 @@ GAMES = games/aaf \ games/xyzzy \ games/zs -GIT_TEMPLATE_HOOKS = git/template/hooks/post-update +GIT_TEMPLATE_HOOKS = git/template/hooks/applypatch-msg \ + git/template/hooks/post-update all: $(BINS) git/gitconfig $(GIT_TEMPLATE_HOOKS) gnupg/gpg.conf diff --git a/git/template/hooks/applypatch-msg.awk b/git/template/hooks/applypatch-msg.awk new file mode 100644 index 00000000..d1c08c56 --- /dev/null +++ b/git/template/hooks/applypatch-msg.awk @@ -0,0 +1,39 @@ +# 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"))) + exit(0) +} + +# We're starting 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 } + +# 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) { + lines[++l] = branch + branch = "" +} + +# 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 +END { + if (rewrite) + for (i = 1; i <= l; i++) + print lines[i] > ARGV[1] +} |