I am running a pre-commit hook which potentially adds new files to the commit. However, although this technically works as expected, the git status
part of the commit message does not reflect this change.
For example, I am adding file x
in a commit, so my git status
beforehand gives the following:
repo>git status
On branch development
Your branch is up-to-date with 'origin/development'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: x
Now, suppose my git hook determines file y
also needs to be commited. Although afterwards I can see y
was indeed staged for the commit, my empty commit message (after the pre-commit hook has executed) gives the following:
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch development
# Your branch is up-to-date with 'origin/development'.
#
# Changes to be committed:
# new file: x
#
even though I am expecting
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch development
# Your branch is up-to-date with 'origin/development'.
#
# Changes to be committed:
# new file: x
# new file: y
#
Indeed, after aborting the commit I get the following git status
:
repo>git status
On branch development
Your branch is up-to-date with 'origin/development'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: x
new file: y
In other words, how do I 'refresh' the automatically generated part of my commit message in the pre-commit hook?
EDIT: My pre-commit hook currently looks as follows.
#!/bin/sh
gulp --production
vendor/bin/phpunit
rc=$?
if [[ $rc != 0 ]] ; then
echo "phpunit failed - commit denied"
exit $rc
fi
git add public
gulp
does things like compile SCSS and potentially move things to my public/ directory. If this happens I want to add those files to the commit, hence the git add public
directive at the end.
So even though these files do get added to the commit, the git status
part of the commit message does not reflect this.