jumanjihouse / pre-commit-hooks

git pre-commit hooks that work with http://pre-commit.com/
MIT License
113 stars 52 forks source link

git-check checks all files, not just changed? #40

Open dsedivec opened 5 years ago

dsedivec commented 5 years ago

Thanks for writing the git-check plug-in! I was surprised, though, to find that it checks my whole tree, not just staged changes against the prior commit (if any).

Should it be calling git diff-index with --cached, and preferring HEAD, when it exists, to ${EMPTY_COMMIT}?

jumanjiman commented 5 years ago

Hi @dsedivec

There are two use cases:

Since the second use case covers the first (and then some, admittedly), I lazily implemented the second use case. I'm certainly open to support both individually.

Do you know if there's a way to detect if pre-commit is invoked with --all-files?

dsedivec commented 5 years ago

Hi @jumanjiman!

There are two use cases:

  • Check only the files that are part of the current commit as a pre-commit hook
  • Check the entire tree in case of pre-commit run --all-files

Since the second use case covers the first (and then some, admittedly), I lazily implemented the second use case. I'm certainly open to support both individually.

Do you know if there's a way to detect if pre-commit is invoked with --all-files?

OK, I didn't think of --all-files, good point. Can you set pass_filenames: True in the hook's definition, and then just pass all of the file names on the command line into git diff-index?

jumanjiman commented 4 years ago

OK, I didn't think of --all-files, good point. Can you set pass_filenames: True in the hook's definition, and then just pass all of the file names on the command line into git diff-index?

That's a nifty thought to try.

i'll have to play with it and see if I can somehow also support the exclude* options.

zaufi commented 1 year ago

I also hit this issue ;-(

Having a repo with so many files and adopting changes in the pre-commit hooks I run it w/ -a and see that this hook forks a lot of git diff-index --check some-hash processes w/ the same hash (meaning that it ignores all that 100500 files given as parameters and performs the same command 100500 times!)

PS It's running for 30 minutes already and still not finished ;-()