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