observing / pre-commit

Automatically installs a git pre-commit script in your git repository which runs your `npm test` on pre-commit
MIT License
1.88k stars 152 forks source link

can't uninstall #106

Open eviazmensky opened 7 years ago

eviazmensky commented 7 years ago

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

3rd-Eden commented 7 years ago

How did you remove the dependency?

eviazmensky commented 7 years ago

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

3rd-Eden commented 7 years ago

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

przhkv commented 7 years ago

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

evannieuwburg commented 6 years ago

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.

avdeev commented 6 years ago

Solution - remove all previous hooks

rm .git/hooks/pre-commit

Tatsujinichi commented 6 years ago

+1

AndrewSouthpaw commented 6 years ago

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).

WillGibson commented 6 years ago

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.

devinrhode2 commented 2 years ago

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",
keval-r-7span commented 4 months ago

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