add check on pre-push stage: exit if staged files not committed yet#3113
Open
aless10 wants to merge 3 commits intopre-commit:mainfrom
Open
add check on pre-push stage: exit if staged files not committed yet#3113aless10 wants to merge 3 commits intopre-commit:mainfrom
aless10 wants to merge 3 commits intopre-commit:mainfrom
Conversation
asottile
reviewed
Feb 25, 2024
Comment on lines
+1227
to
+1252
| def test_pre_push_fails_if_staged_files( | ||
| cap_out, store, repo_with_passing_hook, | ||
| ): |
Member
There was a problem hiding this comment.
this test is probably sufficient -- then you don't need the additional one above
pre_commit/commands/run.py
Outdated
Comment on lines
374
to
376
| if ( | ||
| args.hook_stage == 'pre-push' and git.get_staged_files() | ||
| ): |
Member
There was a problem hiding this comment.
the extra parens here do nothing
pre_commit/commands/run.py
Outdated
Comment on lines
377
to
379
| logger.error( | ||
| 'Staged files found. Please commit before pushing', | ||
| ) |
.gitignore
Outdated
| /.tox | ||
| /dist | ||
| .vscode/ | ||
| .idea |
Member
There was a problem hiding this comment.
please don't touch gitignore files in projects you don't own -- please rebase this out thanks!
4868d89 to
506480f
Compare
506480f to
f6c6b6c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR aims to solve the issue #2486. The idea is to follow the same solution used for #1418 and add the check on the hook name and if there are staged files not committed yet.
About the error message
I did not want to print the list of the staged files, because it can too long and not very useful. I used
logger.errorto print the message, following what is done in the other checks above.Alternatives:
git.get_staged_files, we can just check for the number of staged files and fail if it is > 0, something likegit diff --cached --numstat | wc -lfixes #2486