tarmolov / git-hooks-js

A tool to manage and run project git hooks
167 stars 30 forks source link

Install git-hooks globally #18

Closed jeremyalan closed 8 years ago

jeremyalan commented 8 years ago

Is it possible to install git-hooks globally?

$ npm install -g git-hooks

The primary purpose is to support repositories that do not contain Node.js modules. We want the ability to check our shared commit-hooks into source control, but if I install the library globally, and run git-hooks --install on a newly cloned repo, I get the following message:

git-hooks already installed

It appears that the git-hooks working directory is the location of the executable, which is in /usr/local/bin, rather than the node_modules/ folder of the current repo.

tarmolov commented 8 years ago

It's possible with process.cwd() but git-hooks uses the relative paths to support cases like this:

.git
.githooks
www
    node_modules <-- git-hooks here

I can support global installation but there will be an issue with moving project from one location to another.

Let me describe the problem in details.

npm install -g git-hooks@1.0.3-global
cd /path/to-my-project
git-hooks install # works!
git commit -m "test commit" # also works!
mv /path/to-my-project /yet/another/path
git commit -m "test commit2"
[GIT-HOOKS ERROR] Cannot find module '../../../../../../usr/local/lib/node_modules/git-hooks/lib/git-hooks'

You must run git-hooks uninstall + git-hooks install after moving your project to another place.

Does it suitable for you?

jeremyalan commented 8 years ago

I understand the concern, it is sort of a weird edge case. It would work fine for us, I don't normally move repos around without just re-cloning them, and doing the re-install wouldn't be a big deal if I ever needed to.

A few thoughts...

Perhaps there's a way to determine whether process.cwd() is a parent directory of the git-hooks executable, and branch the logic to use absolute paths instead of relative paths in that case?

If not, it might also be helpful to provide a more helpful error message if the call to require('%s/git-hooks') fails, hinting to the user that they may need to re-install git-hooks for this to work properly?

jeremyalan commented 8 years ago

By the way, I installed 1.0.3-global on my machine, and tried to install the git-hooks from a global install, and it appears to be working as expected!

tarmolov commented 8 years ago

Published 1.1.0 with supporting global installation and showing an extra message for MODULE_NOT_FOUND error.

jeremyalan commented 8 years ago

You rock, thanks!