run-if-changed icon indicating copy to clipboard operation
run-if-changed copied to clipboard

Mapping conditions to specific hook(s) only

Open brettz9 opened this issue 5 years ago • 1 comments

Hi,

This appears to be an extremely useful tool--should be built into npm!

One feature request if I may...

I'd like for some file change conditions to only apply for certain hooks.

For example, I have some pre-commit hooks to run to ensure repo-bundled build files get updated (they are bundled so that GitHub Pages will have access to them), but I don't want such time-consuming scripts running for everyone on the team upon a merge hook since their pulls should already receive the updated build files as they would already have been updated in the commit history.

However, I have other hooks I do want run on checkout since they are not repo-bundled, e.g., dev. documentation and npm dependencies.

(I thought of using lint-staged for the repo-bundled changes, but that passes on arguments to my scripts which I don't want to occur in these cases, e.g., for npm-run-all, which may give errors upon receiving extra arguments.)

If this is not already possible to implement, might you consider allowing more fine-grained control of which hook (or hooks) are run for which conditions?

brettz9 avatar Aug 05 '20 12:08 brettz9

I could implement this after Git introduces an environment variable for which hook ran a script. Depends on https://github.com/git/git/pull/1271

Husky also doesn't offer a way to see which hook ran.

I could add an option flag for this, but doesn't seem to be such a high necessity to warrant a new option for target. Instead, I'd prefer to keep to using the upcoming environment variable from Git itself and expanding the config with patterns.

hkdobrev avatar Dec 28 '24 22:12 hkdobrev