Create a gist now

Instantly share code, notes, and snippets.

@afuna /prepare-commit-hook Secret
Last active May 25, 2018

Embed
What would you like to do?
.git/hooks/prepare-commit-hook
#!/bin/sh
# This hook appends "Fixes #123." to the commit message
# when you're on a branch with "bug-###" in the branch name.e.g., post-by-email-bug123; bug123-post-by-email
# Note: I find it easier to do the first one because autocomplete is more useful that way.
branch=$(git rev-parse --abbrev-ref HEAD)
bug=$(echo $branch | sed -n 's/^.*bug-\([[:digit:]]*\).*/\1/ p')
original_commit=$(head -n 1 $1)
if [ -n "$bug" -a -z "$original_commit" ]
then
/usr/bin/perl -i.bak -npe "s/^/\n\nFixes #$bug./s if \$. == 1" "$1"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment