Skip to content

Instantly share code, notes, and snippets.

@arempe93
Last active October 1, 2019 19:17
Show Gist options
  • Save arempe93/749225f9d28d21d8d9154f6166b8e38d to your computer and use it in GitHub Desktop.
Save arempe93/749225f9d28d21d8d9154f6166b8e38d to your computer and use it in GitHub Desktop.
Automatic commit msg prefix for Clubhouse
#!/bin/bash
BRANCH_NAME=$(git symbolic-ref --short HEAD)
BRANCH_ADDED=$(grep -c "\[$BRANCH_NAME\]" $1)
## if branch was not manually added and BRANCH_NAME is not empty + starts with "ch"
if ! [[ $BRANCH_ADDED -ge 1 ]] && [ -n $BRANCH_NAME ] && [[ $BRANCH_NAME =~ ^ch.* ]]; then
# remove everything after - or / (ch122/my-branch => ch122)
BRANCH_NAME="${BRANCH_NAME%%[-/]*}"
sed -i.bak -e "1s/^/[$BRANCH_NAME] /" $1
fi
@arempe93
Copy link
Author

arempe93 commented Oct 1, 2019

Install:

  • navigate to project root
  • open ./.git/hooks/prepare-commit-msg.sample in editor
  • replace contents and save
  • mv ./.git/hooks/prepare-commit-msg.sample ./.git/hooks/prepare-commit-msg
  • chmod +x ./.git/hooks/prepare-commit-msg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment