1

Is there a way for github to completely reject a commit if DOS newline characters are in any of the files?

(I know the github interface has a setting to make sure the DOS newline characters are not committed, but in the case that this setting isn't turned on, I'd like some insurance.)

hlin117
  • 20,764
  • 31
  • 72
  • 93
  • This could also be extended to reject any commits containing tab characters in lieu of spaces also. – hlin117 Aug 20 '15 at 06:33
  • *Is there a way for github to completely reject a commit [...]* Do you mean at commit time, or at push time? In the first case, a `pre-commit` [hook](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks) is probably what you need. – jub0bs Aug 20 '15 at 06:43
  • a hook able to deny a GitHub push? Not sure: http://stackoverflow.com/q/31334040/6309 – VonC Aug 20 '15 at 06:44
  • @Jubobs: Either would work honestly. But I was thinking of push time. – hlin117 Aug 20 '15 at 06:55

1 Answers1

2

Is there a way for github to completely reject a commit

That sounds like a server-side hook. That isn't possible: a GitHub webhook can register a push event, not reject a push.

That leaves you with a client side hook (which needs to be deployed on all client, and can be bypassed anyway)

A pre-commit hook is more sensible in that case (no need to wait for the push to discover a commit with a wrong content).

You also have then option of .gitattributes (see "Mind the End of Your Line") in order to instruct git to always replace CRLF by LF (*.txt eol=lf): see .gitattributes End-of-line conversion.
That is more robust than a client-side hook.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250