-
Notifications
You must be signed in to change notification settings - Fork 56
Simple prepare-commit-msg hook #170
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,14 @@ if [ ! -e "$DEV_LIB_PATH/check-diff.sh" ]; then | |
| exit 1 | ||
| fi | ||
|
|
||
| DEV_LIB_COMMIT_MESSAGE_FILE=".dev-lib-commit-message.$PPID" | ||
| DEV_LIB_COMMIT_MESSAGE='' | ||
| function add_commit_message { | ||
| label=$1 | ||
| value=$2 | ||
| DEV_LIB_COMMIT_MESSAGE+="\n$label: $value" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @marcin-lawrowski instead of appending to a variable, how about just appending it to the file? echo "$label: $value" >> $DEV_LIB_COMMIT_MESSAGE_FILE
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When pre-commit terminates with return code other than 0 the file should be cleaned as well. In this approach the file is created only if all tests passed.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, but I don't think that's so important now, since the file is getting stored in
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BTW, I wasn't aware that Bash supported the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The pleasure is all mine ;-)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Temporary files will be garbage-collected with the next reboot, but what about users that use this tool in some server environment which isn't rebooted often?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The files are super tiny, so I'm not so concerned about it, since this is going to be used on dev environments not servers. Also, there are a lot of other files being written to |
||
| } | ||
|
|
||
| source "$DEV_LIB_PATH/check-diff.sh" | ||
| set_environment_variables --diff-base ${DIFF_BASE:-HEAD} --diff-head ${DIFF_HEAD:-STAGE} | ||
| install_tools | ||
|
|
@@ -41,3 +49,5 @@ if [[ $SYNC_README_MD == 1 ]] && [ -e readme.txt ] && cat "$TEMP_DIRECTORY/paths | |
| git add $MARKDOWN_README_PATH | ||
| fi | ||
| fi | ||
|
|
||
| echo -e "$DEV_LIB_COMMIT_MESSAGE" > $DEV_LIB_COMMIT_MESSAGE_FILE | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| #!/bin/bash | ||
| # WordPress prepare-commit-msg hook | ||
|
|
||
| DEV_LIB_COMMIT_MESSAGE_FILE=".dev-lib-commit-message.$PPID" | ||
|
|
||
| if [ -f "$DEV_LIB_COMMIT_MESSAGE_FILE" ]; then | ||
| COMMIT_EDITMSG=$1 | ||
| cat "$DEV_LIB_COMMIT_MESSAGE_FILE" >> $COMMIT_EDITMSG | ||
| unlink "$DEV_LIB_COMMIT_MESSAGE_FILE" | ||
| 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.
@marcin-lawrowski I suggest storing this file in
/tmp