0

I've made a githook for my current project, it works for me locally, now I'm trying to share it with my team. We are using Windows. Our team is volatile and distributed, people work on many different projects at the same time and can't be expected to perform additional manual configuration of repositories, so, I need the hook to just start working for them with next pull. I've found several tutorials, but all of them suggest additional configuration on recipient side. I need to avoid that.

P.S. Ideally, I'd expect to just add .git/hooks folder to the repo, but that seems to not be possible in GIT.

Ivan Koshelev
  • 3,830
  • 2
  • 30
  • 50
  • https://stackoverflow.com/search?q=%5Bgithooks%5D+share – phd Feb 12 '19 at 23:17
  • Expecting to install code that runs by surprise on other people's machines has had a bad reputation for quite a while now. Your repo is yours, a corollary of that is, their repo is theirs. They control what happens in it. You don't get to make checkout and push and commit and the rest run arbitrary code in their repos. They get to do that. – jthill Feb 13 '19 at 01:43

1 Answers1

3

Note: this is really more of a comment than an answer (but is too big to be a comment). See the linked duplicate for actual answers.

Some kind of configuring is required, because if it were not, I could make your computer do bad things by the simple act of you cloning a repository I control. Hooks can run arbitrary commands, after all.1

That said, if your users have configured at least one hook, that one hook can use Git to obtain and install more hooks. So, pick a hook that will be run, have your users configure it, and then have them run a Git operation that runs that one hook. That one hook can then do everything else.

Which hook should you use? That's up to you; the githooks documentation tells you which ones Git runs, when. The most obvious candidates are the post-checkout, post-merge, and pre-commit hooks.

Beyond this point, it's just a small matter of programming.


1There was a dreadful bug in old versions of Git: they would allow people to store files named, e.g., .GIT/hooks/post-checkout and .gIt/hooks/post-merge. This had no harmful effect on Linux systems, but caused problems on MacOS and Windows. Modern Git checks for, and rejects, such files, both on the way into a repository and on the way out (in case of Evil Wizards making bad repositories by stealth and/or trickery).

torek
  • 448,244
  • 59
  • 642
  • 775