#!/bin/sh
COMMIT_FILE=$1
COMMIT_MSG=$(cat $1)
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
JIRA_ID=$(echo "$CURRENT_BRANCH" | grep -Eo "[A-Z0-9]{1,10}-?[A-Z0-9]+-\d+")
if [ ! -z "$JIRA_ID" ]; then
echo "$JIRA_ID $COMMIT_MSG" > $COMMIT_FILE
echo "JIRA ID '$JIRA_ID', matched in current branch name, prepended to commit message. (Use --no-verify to skip)"
fi
Last active
April 13, 2023 17:26
-
-
Save robatron/01b9a1061e1e8b35d270 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/sh | |
| COMMIT_FILE=$1 | |
| COMMIT_MSG=$(cat $1) | |
| CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) | |
| JIRA_ID=$(echo "$CURRENT_BRANCH" | grep -Eo "[A-Z0-9]{1,10}-?[A-Z0-9]+-\d+") | |
| if [ ! -z "$JIRA_ID" ]; then | |
| echo "$JIRA_ID $COMMIT_MSG" > $COMMIT_FILE | |
| echo "JIRA ID '$JIRA_ID', matched in current branch name, prepended to commit message. (Use --no-verify to skip)" | |
| fi |
@zack-snyder
I know this is old, but:
Have you tried echo -e "$COMMIT_MSG\n$JIRA_ID" > $COMMIT_FILE
-e flag enables interpretation of backslashes and the \n is a newline. No guarantees it will work on all systems, but it should give you an idea of what you need to try.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How can I append the issue number in the next line?
switching to :
echo "$COMMIT_MSG $JIRA_ID" > $COMMIT_FILEdoesn't work.