Last active
October 26, 2017 13:57
-
-
Save goodevilgenius/f0c8d3f8469f89a7ee0f to your computer and use it in GitHub Desktop.
[git commit message] This git hook can be used to enforce a format for git commits, according to this suggestion on StackExchange: http://programmers.stackexchange.com/a/112710 #development #git
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This requires the commit summary to start like this: | |
# [XXX]: message | |
# * Add | |
# * Mod(ify) | |
# * Ref(actor) | |
# * Fix | |
# * Rem(ove) | |
# * Rea(dability) | |
# Save to .git/hooks/commit-msg and chmod +x it. | |
# Save gitmessage.txt to ~/.gitmessage and run: | |
# git config --global commit.template ~/.gitmessage | |
# This will remind you to use the correct format when committing | |
totallines=$(wc -l "$1" | awk '{print $1}') | |
let l=1 | |
summary="$(sed -n '/^[^#]/{p;q}' "$1")" | |
echo "$summary" | egrep -i '^\[(Add|Mod|Ref|Fix|Rem|Rea)\]' >/dev/null | |
if [ $? -ne 0 ] | |
then | |
echo "Status line must start with [XXX] where XXX is a valid commit type" >&2 | |
echo "Commit aborted. Try again" >&2 | |
exit 1 | |
fi | |
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[XXX]: summary | |
More details | |
* Step 1 | |
* Step 2 | |
# Use one of the following in [XXX]: | |
# * Add | |
# * Mod(ify) | |
# * Ref(actor) | |
# * Fix | |
# * Rem(ove) | |
# * Rea(dability) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment