tags:

views:

731

answers:

4

What business is it of whatever VCS I'm using to worry about what I put in my files? I don't get what the point here is. Is git version control or syntax checker?

+11  A: 

Git doesn't care at all. The example pre-commit hook does a whitespace check as a demonstration of how to write a hook, but it's not enabled by default; you have to make it executable for it to do anything.

hobbs
+3  A: 

As hobbs wrote, the sample pre-commit hook may be doing a check for trailing whitespace. To disable it, look in .git/hooks and make sure the files there are not executable.

One possible way that the hooks may have gotten enabled is that the executable bit may have gotten set if you were moving your repo around on a FAT-formatted flash drive.

Phil
That is why in newer releases sample hooks are using '.sample' suffix rather than not having executable permissions.
Jakub Narębski
+3  A: 

Why? Because trailing whitespace is easily lost, leading to spurious changes and to not applied patches (because of whitespace change). It is a matter of conforming to programming style.

That said it is a question of pre-commit hook: you can edit it, or disable it, or configure trailing whitespace (perhaps for some kinds of files only) to be not considered an error.


The pre-commit hook should be disabled by default, but older versions (pre 1.6.0) used to install them turned off by having executable permissions turned off, which might not work on non-UNIX filesystems like FAT; from 1.6.0 they are installed turned off (disabled) by having '.sample' suffix appended.

Jakub Narębski
Yeah well I don't need some git developer telling me what she or he thinks is good programming style I need to conform to. If I want something like jslint, I'll get something like jslint. I don't want my VCS to do it, that's stupid. If it git has a problem with spurious changes, and not applied patches, then that is a problem with GIT, not my code.
apphacker
It **IS NOT ENABLED BY DEFAULT**.
hobbs
@apphacker: The checks used by default pre-commit hook is about *sending patches via email*, not so much about programming style.
Jakub Narębski
Got it, thank you. Sorry for being mean again.
apphacker
+8  A: 

It is because one of the very common uses for Git is sending patch series via email. Trailing spaces cause trouble in email, and are thus usually stripped out, which means any trailing spaces will be lost in the process of sending the patch via email and applying it. This in turn means that if there are trailing spaces on lines in the repo, but not in the patch being applied, you may get spurious conflicts, or extra changes that weren't intended, when applying a patch.

This pre-commit hook used to be enabled by default, but is no longer. It seems I have misremembered; it was never deliberately enabled by default. As others have pointed out, this has always been a sample pre-commit hook; it used to be disabled by not giving it the execute bit, but that's something that can get screwed up fairly easily (for instance, running under Cygwin on Windows), so in newer versions of Git (since over a year ago) the samples have been disabled by being named pre-commit.sample. You can delete or move your .git/hooks/pre-commit to prevent this hook from executing if you don't like the behavior. You should also update your Git to something more recent, as this has been fixed for quite a while.

Brian Campbell
That is just stupid this was enabled by default. Idiotic really.
apphacker
It **IS NOT ENABLED BY DEFAULT**.
hobbs
My apologies; I was mistaken by the fact that I was bitten by this many times, but I realize now that it was always under Cygwin.
Brian Campbell
@Brian: I was being snippy at apphacker, not you. In fact, I would guess that apphacker has the same thing going on re: Cygwin, but his tone is... well... not pleasant. :)
hobbs
Yeah, I figured that was the case, but I wanted to make sure I clarified as I looked through the Git history and realized that I had been incorrect.
Brian Campbell
Ah, I'm sorry for being mean then. :(
apphacker