1

Everyone knows you cannot commit anything in .git/hooks because it's not a git repository.

So I wrote a script to symlink all hooks in .git/hooks to point to all of my hooks located in my_repo/hooks/driver. Now I can track and commit my hooks, as I please. This was recommended by several stack overflow users across many threads (see link below).

Putting git hooks into repository

The problem is I don't want other developers (who work on the same repository) to manually run my script, it should just run automatically run when they pull or init the repository (assuming they did not run it once already).

Anyone have any ideas? Tons of threads on tracking git hooks, none on automating it once the script is written (i.e. like I have). :(

Community
  • 1
  • 1
MrPickles
  • 1,255
  • 1
  • 16
  • 31

2 Answers2

1

Git has no facility for automatically running a script on your local system when you first clone a repository. This would present a substantial security issue.

Your best course of action is probably to provide a set-up-hooks command of some sort that will install the necessary symlinks into a local repository, and include instructions for running this script in your README or equivalent documentation for new developers.

larsks
  • 277,717
  • 41
  • 399
  • 399
1

Depending on the technology you are using, there might be ways to hook this into a build or dependency management tool.

In the Node.js world, some thing people use are

  • npm's install/postinstall script (https://docs.npmjs.com/misc/scripts): You would add your script command in the package.json file as

    "scripts": { 
        "install": "link-my-git-hooks"
    }
    

    This would ensure that your script is run anytime someone runs npm install locally.

  • Grunt: If you're using Grunt (or a similar build tool), you could use something along the lines of https://www.npmjs.com/package/grunt-githooks, which will install the hooks as part of the build process. When someone runs grunt locally to build the project, your Git-Hooks would be installed/verified/updated.

So the general idea here is that you should integrate the process of installing the hooks with something that developers run on a regular basis anyway. I completely agree that it shouldn't be an additional step that people usually forget about - add it to something that they're already using every day.

The above examples are just ideas - there are probably similar tools/approaches for other technologies.

nwinkler
  • 52,665
  • 21
  • 154
  • 168