4

Lets say you have a Git repository, like on GitHub, and you have a lot of people contributing to the repository. Everyone uses their own standards for coding, so the code ends up being a mess without any standards applied.

I've read a bit about git hooks but I don't fully understand their concept or primary uses.

Is it possible to use hooks, when a pull request is sent to your repository, to send the code to some remote service, that then formats the code into whatever XYZ standard you want to use, and then returns the formatted code back in to the repo or into the pull request? Or does it not work like that?

Jake Wilson
  • 8,494
  • 29
  • 94
  • 121

1 Answers1

4

Sure, you could do something like that. However, I don't like the idea of a third-party service or daemon making changes to code that are committed by my engineers.

So instead of fixing this retroactively, Just check the code via the pre-receive hook and then reject the push if it fails to meet your code style standards. Your engineers really ought to be able to get over their own personal ideas of how code should be formatted and adhere to the organization's desires.

EEAA
  • 108,414
  • 18
  • 172
  • 242
  • More than that, suppose it automatically changed the pull request to have formatted code before pulling. You just generated a future merge conflict for that collaborator. Do it enough times and your collaborators will revolt. – Christopher Aug 10 '12 at 23:05
  • 3
    They aren't "my engineers". Just a group of random people collaborating on a project. If I sit there and reject people's code over and over cause of poor formatting then they are going to just stop contributing. – Jake Wilson Aug 12 '12 at 06:03