-
-
Save wingleung/1b6efce388b81f5554ca to your computer and use it in GitHub Desktop.
#!/bin/sh | |
# | |
# Automatically adds Jira key to commit message | |
# | |
if [ -z "$BRANCHES_TO_SKIP" ]; then | |
BRANCHES_TO_SKIP=(master develop) | |
fi | |
BRANCH_NAME=$(git symbolic-ref --short HEAD) | |
BRANCH_NAME="${BRANCH_NAME##*/}" | |
BRANCH_EXCLUDED=$(printf "%s\n" "${BRANCHES_TO_SKIP[@]}" | grep -c "^$BRANCH_NAME$") | |
BRANCH_JIRA_KEY=$(echo $BRANCH_NAME | grep -E -o '^([A-Z]+-[0-9]+)') | |
if ! [[ $BRANCH_EXCLUDED -eq 1 ]] && ! [[ $(cat "$1") == "$BRANCH_JIRA_KEY"* ]] && ! [ -z "$BRANCH_JIRA_KEY" ]; then | |
echo "$BRANCH_JIRA_KEY $(cat "${1}")" > "$1" | |
fi |
Hi, new job requires JIRA ticket in every single commit, and this is working great, thank you so much.
I do have a question, is it expected for some prompts to open up, about 3 or 4 times, when I commit now? I'm on Windows 7 with git version 2.17.1.
I've never had to use git hooks before and I setup this locally for a single project.
Thanks,
P.
@pnmcosta not really. What editor are you using?
Also, can you upgrade off Win7?
VS2017, and a locked down Win7 too, I wish I could upgrade but it's a firmwide setup! I've begged, no result yet 😂
Windows 7 is EOL and unsupported, which means it's full of security holes, which might be leverage to get it updated: https://support.microsoft.com/en-us/help/4057281/windows-7-support-ended-on-january-14-2020
I might also suggest a lighter-weight editor for commit messages - the lightest, actually: vim
or vi
is great for the quick stuff needed for them. It's a bit of a learning curve but the few commands you really need to know are easily memorized.
Unfortunately we're one of the firms that extended the support 😿
Ok then, let's work with what we have. What prompts are opening? Do you get to the editor eventually?
Command prompts flashes, can't really see what they are and/or doing. But don't worry, I can't really change editor, and it's probably related to the way git handles the hooks on my setup. So I'll have to live with it. Thanks anyway.
this is fantastic, thanks!