3

I am team of 4 members, we have have git repo in azure devOps, I am given task to add git hook(scan code for indentation, unwanted spaces etc). I know git hook must be added to ./.git/hooks, I have scripts ready. But how do I ensure my other teammates receive my script in their local repo, so code check is done before they commit new files.

FYI, any changes made .git will remain only to local repo, but what is the easiest way that my git hook is passed onto all my team members?

karthik_personal
  • 369
  • 1
  • 3
  • 14

4 Answers4

3

The problem with such a hook is that it is a client-side hook, which involves a deployment to all user.
This differs from a server-side hook, which is modified once, and applied for every user git push to said server.

In my case, I ask my users to make a symlink from their .git/hooks/pre-commit file to a file managed in the repository.
That way, updating that file is easy and applied automatically.

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

I commit hooks in the repository and tell my team mates that they can use them by setting the core.hooksPath, e.g.

git config core.hooksPath './hooks'

Here is my example repository on github

René Link
  • 48,224
  • 13
  • 108
  • 140
0

You can set up git hooks in the dependency install stage(npm install, maven, cargo...), and read real commands from project source code.

Have a look at husky for example.

banyudu
  • 1,046
  • 9
  • 19
0

Yet another variation to @ReneLink's and @VonC's answers :

you can commit a script which sets up the hooks for any repo, and instruct the users to run it on their local clone.

For example, have a repo-setup.sh script with :

#!/bin/bash

# set the hooksPath config to point to a versioned directory :
git config core.hooksPath './hooks'

# or :
#!/bin/bash

# set a symlink for 'pre-commit' hook :
ln -nsf ../../pre-commit-hook.sh .git/hooks/pre-commit
LeGEC
  • 46,477
  • 5
  • 57
  • 104