Skip to content

Instantly share code, notes, and snippets.

@vitormil
Created May 10, 2023 09:33
Show Gist options
  • Save vitormil/a5e819fce89e455059eba00da3ede999 to your computer and use it in GitHub Desktop.
Save vitormil/a5e819fce89e455059eba00da3ede999 to your computer and use it in GitHub Desktop.
Git Hooks
#!/bin/sh
current_branch=`git rev-parse --abbrev-ref HEAD`
if [[ $current_branch =~ master|main ]]; then
message="Please don't commit directly to $current_branch."
echo "💥 \033[1;31mERROR: $message\033[0m";
exit 1
fi
#!/bin/sh
[ -f $GIT_DIR/MERGE_MSG ] && exit 0
COMMIT_MSG_FILE=$1
COMMIT_SOURCE=$2
SHA1=$3
quote1=$(ruby ~/vitor/quotes/quote.rb)
quote2=$(ruby ~/vitor/quotes/quote.rb --color)
# Only add custom message when there is no commit source
if [[ -z "$COMMIT_SOURCE" ]]
then
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [[ $CURRENT_BRANCH =~ ^(.+\/)?([A-Z]+-[0-9]*).* ]]
then
JIRA_ID="${BASH_REMATCH[2]}"
hint=$(cat "$COMMIT_MSG_FILE")
echo "[${JIRA_ID}] " > "$COMMIT_MSG_FILE"
echo "$hint" >> "$COMMIT_MSG_FILE"
echo "# Quote of the commit:\n#\t${quote1}" >> "$COMMIT_MSG_FILE"
echo "#\n#\n# Quote of the commit:\n#\n# ${quote2}\n#\n#\n"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment