Skip to contentSkip to conversation

pre-commit hook to reject whitespace

DISCUSSION Neal Kreitzinger 3 participants 4 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

The reference manuals state in the hooks documentation that the pre-commit hook sample will reject whitespace only changes. However, the pre-commit.sample in the 1.7.1 and 1.7.5.4 downloads do not appear to do this (I'm new to linux scripts). The appear to only reject non-ascii filenames. Does someone have a pre-commit hook example I can use to reject whitespace-only changes? Thanks!

v/r,
neal

#1 lore raw
Quoted 7 lines · Neal Kreitzinger

The reference manuals state in the hooks documentation that the pre-commit hook sample will reject whitespace only changes. However, the pre-commit.sample in the 1.7.1 and 1.7.5.4 downloads do not appear to do this (I'm new to linux scripts). The appear to only reject non-ascii filenames. Does someone have a pre-commit hook example I can use to reject whitespace-only changes? Thanks!

As someone kindly pointed out, the documentation actually says:
"The default 'pre-commit' hook, when enabled, catches introduction of lines with trailing whitespaces and aborts the commit when such a line is found."

I'm not seeing this functionality in the pre-commit.sample for 1.7.1 or 1.7.5.4.

v/r,
neal

#2 lore raw
Quoted 10 lines · Neal Kreitzinger
Quoted 9 lines · Neal Kreitzinger

The reference manuals state in the hooks documentation that the pre-commit hook sample will reject whitespace only changes.  However, the pre-commit.sample in the 1.7.1 and 1.7.5.4 downloads do not appear to do this (I'm new to linux scripts).  The appear to only reject non-ascii filenames.  Does someone have a pre-commit hook example I can use to reject
whitespace-only changes?  Thanks!

Quoted 6 lines

As someone kindly pointed out, the documentation actually says:
"The default 'pre-commit' hook, when enabled, catches introduction of lines with trailing whitespaces and aborts the commit when such a line is found."

I'm not seeing this functionality in the pre-commit.sample for 1.7.1 or 1.7.5.4.

I've never tried that hook script myself, but it appears to be on the last line:
exec git diff-index --check --cached $against --

In particular, the --check option says:
Warn if changes introduce trailing whitespace or an indent that
uses a space before a tab. Exits with non-zero status if problems are found. Not compatible with --exit-code.

HTH!

-John

#3 lore raw
Quoted 18 lines · John Szakmeister
Quoted 10 lines · Neal Kreitzinger
Quoted 9 lines · Neal Kreitzinger

The reference manuals state in the hooks documentation that the pre-commit hook sample will reject whitespace only changes. However, the pre-commit.sample in the 1.7.1 and 1.7.5.4 downloads do not appear to do this (I'm new to linux scripts). The appear to only reject non-ascii filenames. Does someone have a pre-commit hook example I can use to reject
whitespace-only changes? Thanks!

Quoted 6 lines

As someone kindly pointed out, the documentation actually says:
"The default 'pre-commit' hook, when enabled, catches introduction of lines with trailing whitespaces and aborts the commit when such a line is found."

I'm not seeing this functionality in the pre-commit.sample for 1.7.1 or 1.7.5.4.

Quoted 8 lines

I've never tried that hook script myself, but it appears to be on the last line:

    exec git diff-index --check --cached $against --

In particular, the --check option says:
Warn if changes introduce trailing whitespace or an indent that
uses a space before a tab. Exits with non-zero status if problems are found. Not compatible with --exit-code.

Ah ha! Thanks!

v/r,
neal