observing/pre-commit

can't uninstall

eviazmensky opened this issue ยท 11 comments

I attempted to uninstall this from a project I'm working on (we're over 100 tests and switching branches became a process). Once uninstalled, I started seeing this in my commit message:
.git/hooks/pre-commit: line 2: ./node_modules/pre-commit/hook: No such file or directory
I had to re-install the package and add this to my package.json to get the project functional again:

  "pre-commit": {
    "silent": true,
    "run": []
  }

I fully accept that the problem could be me, but if anyone else has experienced this I'd love to see a better solution

How did you remove the dependency?

I ran npm uninstall pre-commit --save-dev

In that case, i'm guessing that our uninstall script needs to updated for proper un-installation. Thanks for the heads up.

Had the same issue. In my case probably yarn install somehow skipped uninstall script ๐Ÿ˜•
To cancel old hook I manually replaced .git/hooks/pre-commit with .git/hooks/pre-commit.old

npm uninstall removes the node modules, but doesn't uninstall the git hooks in you '.git/hooks' folder, so that hook keeps referencing the already removed node module. It would be nice of this module had a 'reset-hooks' method or something.

Solution - remove all previous hooks

rm .git/hooks/pre-commit

For whatever reason mine got messed up as well. You can rm .git/hooks/pre-commit, but I just did

yarn add pre-commit
yarn remove pre-commit

and that got it back to working condition (and restored my old hooks, which the previous solution does not do).

I ran into trouble here when we decided to change from pre-commit to pre-push.

I might be wrong, but I think the issue might be that the uninstall removes the pre-commit hook on the machine of the person doing the uninstalling, but not other people who may already have the code checkout out with the hook in place, but now referencing a module which no longer exists.

It's mildly annoying to have to leave pre-commit installed to avoid this problem, but the original poster's suggestion seems to be the least workflow disrupting solution for now.

This could be added to the readme:

#!/usr/bin/env sh

[[ -f .git/hooks/pre-commit ]] && {
  echo 'De-activating old git hook (.git/hooks/pre-commit), by renaming to `.git/hooks/pre-husky-pre-commit-hook`'
  echo 'The old hook does not work, because `node_modules/pre-commit` has been replaced with husky'
  echo 'If you want to run eslint pre-commit, simply `yarn run activate-git-hooks`'
  echo 'Feel free to add other scripts to .husky/pre-commit under an opt-in flag.'
  echo 'You can also keep husky deactivated, and simply put anything you want in your `.git/hooks/pre-commit` file'
  echo 'Activating/deactivating husky does not modify .git/hooks directory.'
  echo 'It modifies .git/config core.hooksPath to point to .husky/ directory instead of using .git/hooks directory.'
  mv .git/hooks/pre-commit .git/hooks/pre-husky-pre-commit-hook
}

You can run this in a postinstall hook.

Name the file something like ./scripts/cleanup-old-pre-commit-hook.sh and call this in your postinstall script:

"posinstall": "./scripts/cleanup-old-pre-commit-hook.sh",

go to .git folder and remove hook folder and then solve your issue