Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return from pre_commit_hook if no files changed. #130

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

steadmon
Copy link

@steadmon steadmon commented Jul 1, 2019

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.

Closes #129

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

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.

Closes awslabs#129
@rongutierrez
Copy link

Bump on this PR, any chance it can get reviewed?

@madchap
Copy link

madchap commented Apr 23, 2020

@mtdowling any chance to merge this? Thanks.

@aman-singh
Copy link

Bump, please review.

Copy link
Contributor

@sparr sparr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix is already in use at aws-lumberyard#1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"git commit --amend" scans entire working directory if no files are staged
6 participants