pre-git
pre-git copied to clipboard
prepare-commit-msg hook?
Hi,
Is it possible to trigger the prepare-commit-msg hook using this configuration in package.json?
"config": {
"pre-git": {
"prepare-commit-msg": [
"path/to/prepare-commit-msg"
]
}
}
Best,
Hi, not sure what this git hook does, can you explain?
I use this hook to populate the commit message with some useful infos like the name of the branch you are currently on. Here's the link to the doc.
For what it's worth, you'll find below the script I use to insert text like this: [feature name] (branch name)
:
#!/bin/sh
# Put this file in .git/hooks/prepare-commit-msg
# (don't forget to check permissions on the file, it must be executable)
# This script prepares the commit message by inserting
# [PROJECT_NAME] (BRANCH) at the top of the message.
# PROJECT_NAME is your own environment variable,
# you can set it like this:
# $ export PROJECT_NAME=MY_PROJECT_NAME
# or don't set it, you'll just have empty brackets.
# Then you just have to write the commit message.
current_branch()
{
ref=$(git rev-parse --abbrev-ref HEAD 2> /dev/null) \
|| return
echo $ref
}
# If $2 is empty, prepare the commit message.
# See what are the values of $2 there:
# http://git-scm.com/docs/githooks#_prepare_commit_msg
# Useful for leaving the commit message untouched on a merge.
if [ -z "$2" ]
then
BRANCH=$(current_branch)
TIME=$(date +%s)
TEMPORARY_COMMIT_FILE="/tmp/temporary_commit_file.$TIME"
echo "[$PROJECT_NAME] ($BRANCH)" | cat - "$1" > $TEMPORARY_COMMIT_FILE
mv $TEMPORARY_COMMIT_FILE "$1"
fi
that's a cool feature, I should probably do this.
I am thinking out loud... how about to execute commit-wizard on this step and then use the result, instead of using npm run commit
this could be just git commit
? Could it be possible?
I am going to try it . I will hack a bit using this https://github.com/linxiaowu66/prepare-commit-msg-angular/blob/master/index.js