awslabs / git-secrets

Prevents you from committing secrets and credentials into git repositories
Apache License 2.0
12.36k stars 1.17k forks source link

"git commit --amend" scans entire working directory if no files are staged #129

Open steadmon opened 5 years ago

steadmon commented 5 years ago

When "git commit --amend" is used when no files are staged (for example, to reword a commit message), git-secrets --pre_commit_hook scans the entire working tree. This is because the scan() function is called with an empty file list.

For large repos, this causes a bad user experience; the user expects their editor to open immediately, but instead the pre-commit hook runs for multiple seconds (9 seconds in the linux kernel on my workstation), with no progress indication. If the repo contains any previously committed files that match git-secrets patterns, the editor never opens, and git-secrets' error message is displayed.

We can make the pre_commit_hook() function return immediately if there are no changed files, which should match user expectations.

ujihisa commented 3 years ago

Looks like the same thing happens when you are removing files using git rm filename but not adding files.