Conversation
|
Changes Unknown when pulling 5727349 on Marto32:mm/pre-commit-updates into ** on sk-:master**. |
sk-
left a comment
There was a problem hiding this comment.
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.
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
| # 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.
Could you rename to something like DIFF_FILES.
|
Changes Unknown when pulling 7092839 on Marto32:mm/pre-commit-updates into ** on sk-:master**. |
| # 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.
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.
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.
@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.shpre-commit.hg-lint.shThese changes are needed as the previous command to initialize
git lintusedxargsflags that were not available on OSX (namely--nulland--no-run-if-empty). The updated scripts should perform the same functionality and will run on OSX.This is addressed in issue #88