Skip to content

Instantly share code, notes, and snippets.

View Laurentyb's full-sized avatar

Laurent Brickell Laurentyb

View GitHub Profile
@Laurentyb
Laurentyb / pre-commit.sh
Created December 16, 2022 13:13
Git hook for validating branch names before commiting
#!/bin/sh
BRANCH=$(git rev-parse --abbrev-ref HEAD)
REGEX="^(develop|master|production|staging|uat|main|release|((feature|devops|bugfix|hotfix)\/[A-Z]+-[0-9]+_[A-Z]+_.+))$"
if ! [[ $BRANCH =~ $REGEX ]]; then
echo "Your commit was rejected due to branching name"
echo "Please rename your branch with $REGEX syntax"
exit 1
fi
@Laurentyb
Laurentyb / prepare-commit-msg.sh
Created December 14, 2022 15:45
Git hook for preparing JIRA commit messages
#!/bin/sh
#
# git prepare-commit-msg hook for automatically prepending an issue key
# from the start of the current branch name to commit messages.
# check if commit is merge commit or a commit ammend
if [ $2 = "merge" ] || [ $2 = "commit" ]; then
exit
fi
ISSUE_KEY=`git branch | grep -o "\* \(.*/\)*[A-Z]\{2,\}-[0-9]\+" | grep -o "[A-Z]\{2,\}-[0-9]\+"`