-
Notifications
You must be signed in to change notification settings - Fork 76
Update Pre Commit Hook Script #89
base: master
Are you sure you want to change the base?
Conversation
Changes Unknown when pulling 5727349 on Marto32:mm/pre-commit-updates into ** on sk-:master**. |
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.
Thanks for the change. Could you update the PR, so that the change retains the same functionality as before.
scripts/pre-commit.git-lint.sh
Outdated
then | ||
exit 0; | ||
else | ||
git lint; |
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.
Note that this is not exactly the same as the original script. The original script was linting only files being commited.
Here it should read something like:
echo $DIFF_FILES | xargs -0 git lint
The same applies for the mercurial hook.
scripts/pre-commit.git-lint.sh
Outdated
@@ -14,8 +14,13 @@ | |||
# limitations under the License. | |||
|
|||
# First part return the files being commited, excluding deleted files. | |||
git diff-index -z --cached HEAD --name-only --diff-filter=ACMRTUXB | | |||
xargs --null --no-run-if-empty git lint; | |||
DIFF=$(git diff-index -z --cached HEAD --name-only --diff-filter=ACMRTUXB) |
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.
Could you rename to something like DIFF_FILES
.
Changes Unknown when pulling 7092839 on Marto32:mm/pre-commit-updates into ** on sk-:master**. |
@@ -14,8 +14,13 @@ | |||
# limitations under the License. | |||
|
|||
# First part return the files being commited, excluding deleted files. | |||
git diff-index -z --cached HEAD --name-only --diff-filter=ACMRTUXB | | |||
xargs --null --no-run-if-empty git lint; | |||
DIFF_FILES=$(git diff-index -z --cached HEAD --name-only --diff-filter=ACMRTUXB) |
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.
Bash does not store new lines nor \0
, so the above won't work. See http://stackoverflow.com/questions/6570531/assign-string-containing-null-character-0-to-a-variable-in-bash#answer-22985397
Apparently the only bullet proof solution is to save the result to a file, but that has the complications of deleting the temporary file even in case of errors.
Another alternative is to run the command twice. The first time to check whether the output is empty. And the second piped to xargs.
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.
Would it be possible to convert this to a python script and store those results as variables? Or does the hook have to be a shell script?
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.
@sk- I opted for the latter solution and used the variable to check if there is output, if there is, I reran the command and piped it into xargs. I tested the git script by running it manually line by line - works on OSX 10.11.6 (I did not test mercurial).
Changes Unknown when pulling 7d93f36 on Marto32:mm/pre-commit-updates into ** on sk-:master**. |
@sk- circling back on this |
Is this PR still going? This is a different change, but it seems to be working for me on OSX mojave. I think Let me know if you want me to send a PR.
|
This PR updates the pre-commit hook scripts:
pre-commit.git-lint.sh
pre-commit.hg-lint.sh
These changes are needed as the previous command to initialize
git lint
usedxargs
flags that were not available on OSX (namely--null
and--no-run-if-empty
). The updated scripts should perform the same functionality and will run on OSX.This is addressed in issue #88