Last active
December 12, 2022 19:19
-
-
Save kalecser/5d4ae4c95a4ba1a1bfd89acaea5284b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo "Directory of git projects: ($(echo ~)/Projects)" | |
read projects_dir | |
projects_dir=${projects_dir:=$(echo ~)/Projects} | |
echo Projects dir root: $projects_dir | |
echo ---------------------------------- | |
echo | |
if [ ! $projects_dir/.git ] ; | |
then | |
echo "ERROR: File $projects_dir/.git not found." | |
exit 1 | |
fi | |
echo Create git template | |
echo --------------------------------- | |
echo | |
cat <<-ENDOFMESSAGE > /tmp/jira-git-hook-temp.sh | |
#!/usr/bin/env ruby | |
message_file = ARGV[0] | |
message = File.read(message_file) | |
\$regex = /\[[A-Z]+\-(\d+)\]/ | |
if !\$regex.match(message) | |
puts "[FIX] Please provide the Jira Issue key on your commit message. e.g. [BANKAOLL-42]" | |
exit 1 | |
end | |
ENDOFMESSAGE | |
git config --global init.templatedir '~/.git_template' | |
mkdir -p ~/.git_template/hooks | |
mv /tmp/jira-git-hook-temp.sh ~/.git_template/hooks/commit-msg | |
chmod +x ~/.git_template/hooks/commit-msg | |
echo Done! | |
echo | |
echo Apply hook to existing projects | |
echo -------------------------------- | |
echo | |
cd $projects_dir | |
find . -name ".git"|xargs -I{} cp -v ~/.git_template/hooks/commit-msg {}/hooks/commit-msg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment