Skip to content

Instantly share code, notes, and snippets.

@afuna
Last active May 25, 2018 22:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afuna/ae9386b122d6a490eaf9 to your computer and use it in GitHub Desktop.
Save afuna/ae9386b122d6a490eaf9 to your computer and use it in GitHub Desktop.
.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