simple-git-hooks icon indicating copy to clipboard operation
simple-git-hooks copied to clipboard

[Question] run npx simple-git-hooks every time you change a command

Open pustovalov opened this issue 3 years ago • 12 comments

Is this a good idea to do something like this?

"simple-git-hooks": {
  "pre-commit": "npx simple-git-hooks && npx lint-staged"
}

so that people don't need to run npx simple-git-hooks command when the config change

pustovalov avatar Mar 18 '21 16:03 pustovalov

This shouldn't break things :) Gonna try it tomorrow, if this solution doesnt affect performance and works well, then gonna add it to the docs

Thanks for the idea!

toplenboren avatar Mar 20 '21 16:03 toplenboren

Couldn't this be done internally, before each command is run?

Check the hash and/or file modification time of the package.json or configuration file, and if it has changed, re-run setup?

Another idea: Install a post-merge hook that checks for updates to configuration, and if necessary, re-runs setup.

glen-84 avatar Mar 22 '21 14:03 glen-84

Definitely a fan of automatically keeping this synced as well! If a package updates a hooks' command, consumers' hooks should be updated without manual work of their own.

Thanks for the library, toplenboren!

JonKrone avatar Mar 23 '21 02:03 JonKrone

Also, what about initial hooks install? For example, if I'll replace husky with simple-git-hooks in my project, I need to say all project members to run npx simple-git-hooks. Doesn't seem nice to me.

Djaler avatar Mar 24 '21 16:03 Djaler

@Djaler Is that not handled by the postinstall script?

glen-84 avatar Mar 24 '21 17:03 glen-84

Hmm, looks like yes. I just didn't see this in readme

Djaler avatar Mar 24 '21 17:03 Djaler

Can someone confirm that the post-merge "auto-updating" of hooks work? It's the only thing holding me back from migrating/fleeing from husky@4

JaneJeon avatar Apr 13 '21 03:04 JaneJeon

@JaneJeon It hasn't been implemented, as far as I know.

glen-84 avatar Apr 13 '21 06:04 glen-84

@glen-84 sorry, I didn’t mean if that feature was “built-in” to this library, but rather whether it was possible to get the husky-like functionality by just prepending a npx simple-git-hooks to the post-merge hook.

JaneJeon avatar Apr 13 '21 14:04 JaneJeon

@JaneJeon Oh I see. I haven't tried it yet, TBH. 🙂

glen-84 avatar Apr 13 '21 18:04 glen-84

You may not need npx, you can also do simple-git-hooks as script after npm i simple-git-hooks --save-dev, that you can add to the prepare script in your package.json.

DanielRuf avatar Jul 20 '21 10:07 DanielRuf

I am using this:

"prepare": "is-ci || npx simple-git-hooks"

https://www.npmjs.com/package/is-ci

peschee avatar Feb 15 '22 07:02 peschee