You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When trying to grep from the input COMMIT_EDITMSG ($1) file in the prepare-commit-msg hook makes it fail without any relevant trace nor error message.
The version of terminal is zsh 5.9 on a Mac
Husky version 9.0.11
Try to grep from the $1 input variable in the aforementioned hook. It doesn't execute the hook as it fails on that line.
You have the following code I am currently using on my prepare-commit-msg. It executes correctly until it reaches line COMMIT_TYPE_PRESENT_IN_MESSAGE=$(echo $COMMIT_MESSAGE | grep -Eo "^(${COMMIT_TYPE_LITERALS}):").
I have correctly extract the contents of the $1 file with cat, but as soon as I try to grep anything from it, the hook fails.
#!/bin/sh
COMMIT_TYPE_LITERALS='feat|fix|docs|style|refactor|test|chore|perf|test|build|ci|chore|revert'
BRANCH_NAME=$(git symbolic-ref --short HEAD)
TICKET_ID=$(echo $BRANCH_NAME | grep -Eo 'CU-.{9}')
COMMIT_TYPE=$(echo $BRANCH_NAME | grep -Eo "^(${COMMIT_TYPE_LITERALS})")
COMMIT_MESSAGE=$(cat $1)
COMMIT_TYPE_PRESENT_IN_MESSAGE=$(echo $COMMIT_MESSAGE | grep -Eo "^(${COMMIT_TYPE_LITERALS}):")
if [ $COMMIT_TYPE_PRESENT_IN_MESSAGE ];
then
CLEAN_COMMIT_MESSAGE=$(echo $COMMIT_MESSAGE | grep -E "^(${COMMIT_TYPE_LITERALS}):" | sed 's/^.*:https://')
sed -i.bak -e "s/.*:/$COMMIT_TYPE_PRESENT_IN_MESSAGE $TICKET_ID | /" $1
else
sed -i.bak -e "1s~^~$COMMIT_TYPE: $TICKET_ID | ~" $1
fi
The text was updated successfully, but these errors were encountered:
Context
When trying to grep from the input
COMMIT_EDITMSG ($1)
file in theprepare-commit-msg
hook makes it fail without any relevant trace nor error message.You have the following code I am currently using on my prepare-commit-msg. It executes correctly until it reaches line
COMMIT_TYPE_PRESENT_IN_MESSAGE=$(echo $COMMIT_MESSAGE | grep -Eo "^(${COMMIT_TYPE_LITERALS}):")
.I have correctly extract the contents of the $1 file with cat, but as soon as I try to grep anything from it, the hook fails.
The text was updated successfully, but these errors were encountered: