Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions scripts/pre-commit.git-lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Owner

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.

Copy link
Author

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?

Copy link
Author

@Marto32 Marto32 Feb 14, 2017

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).

if [ -z "$DIFF_FILES" ]
then
exit 0;
else
echo $DIFF_FILES | xargs -0 git lint;
fi

if [ "$?" != "0" ]; then
echo "There are some problems with the modified files.";
Expand Down
9 changes: 7 additions & 2 deletions scripts/pre-commit.hg-lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ if [ "$NO_VERIFY" != "" ]; then
exit 0
fi

hg status --change $HG_NODE | cut -b 3- | tr '\n' '\0' |
xargs --null --no-run-if-empty git-lint;
DIFF_FILES=$(hg status --change $HG_NODE | cut -b 3- | tr '\n' '\0')
if [ -z "$DIFF_FILES" ]
then
exit 0;
else
echo $DIFF_FILES | xargs -0 git lint;
fi

if [ "$?" != "0" ]; then
echo "There are some problems with the modified files.";
Expand Down