FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

add check on pre-push stage: exit if staged files not committed yet by aless10 · Pull Request #3113 · pre-commit/pre-commit · GitHub

add check on pre-push stage: exit if staged files not committed yet - #3113

Open
aless10 wants to merge 3 commits into
pre-commit:mainfrom
aless10:2486-prepush-staged-files
Open

add check on pre-push stage: exit if staged files not committed yet#3113
aless10 wants to merge 3 commits into
pre-commit:mainfrom
aless10:2486-prepush-staged-files

Conversation

aless10 commented Jan 18, 2024

Copy link
Copy Markdown

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.error to print the message, following what is done in the other checks above.

Alternatives:

  • instead of using the function git.get_staged_files, we can just check for the number of staged files and fail if it is > 0, something like git diff --cached --numstat | wc -l

fixes #2486

Comment on lines +1227 to +1252
def test_pre_push_fails_if_staged_files(
cap_out, store, repo_with_passing_hook,
):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

this test is probably sufficient -- then you don't need the additional one above

Comment thread pre_commit/commands/run.py Outdated
Comment on lines +374 to +376
if (
args.hook_stage == 'pre-push' and git.get_staged_files()
):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

the extra parens here do nothing

Comment thread pre_commit/commands/run.py Outdated
Comment on lines +377 to +379
logger.error(
'Staged files found. Please commit before pushing',
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

this easily fits on one line

Comment thread .gitignore Outdated
/.tox
/dist
.vscode/
.idea

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

please don't touch gitignore files in projects you don't own -- please rebase this out thanks!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Sorry about that. Removed

aless10 force-pushed the 2486-prepush-staged-files branch from 4868d89 to 506480f Compare February 26, 2024 15:04
aless10 requested a review from asottile February 27, 2024 13:29
asottile force-pushed the 2486-prepush-staged-files branch from 506480f to f6c6b6c Compare September 6, 2025 18:56
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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

pre-push should forbid unrelated staged changes while pushing

2 participants


Back | FazBrowse Home | New Git URL