GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — add check on pre-push stage: exit if staged files not committed yet by aless10 · Pull Request #3113 · pre-commit/pre-commit

Conversation

@aless10

@aless10 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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
asottile
asottile reviewed Feb 25, 2024
View reviewed changes
Comment thread tests/commands/run_test.py
Comment on lines +1227 to +1252
def test_pre_push_fails_if_staged_files(
cap_out, store, repo_with_passing_hook,
):

@asottile asottile Feb 25, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

aless10 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
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()
):

@asottile asottile Feb 25, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

the extra parens here do nothing

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

aless10 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread pre_commit/commands/run.py Outdated
Comment on lines +377 to +379
logger.error(
'Staged files found. Please commit before pushing',
)

@asottile asottile Feb 25, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

this easily fits on one line

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

aless10 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread .gitignore Outdated
/.tox
/dist
.vscode/
.idea

@asottile asottile Feb 25, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@aless10 aless10 Feb 26, 2024

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Sorry about that. Removed

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@aless10
aless10 force-pushed the 2486-prepush-staged-files branch from 4868d89 to 506480f Compare February 26, 2024 15:04
@aless10
aless10 requested a review from asottile February 27, 2024 13:29
aless10 added 3 commits September 6, 2025 14:56
@aless10 @asottile
add check on pre-push stage: exit if staged files not committed yet
80e6149
@aless10 @asottile
fix failing tests
e36cdc2
@aless10 @asottile
improvements/fixes after code review
f6c6b6c
@asottile
asottile force-pushed the 2486-prepush-staged-files branch from 506480f to f6c6b6c Compare September 6, 2025 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@asottile asottile Awaiting requested review from asottile

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

pre-push should forbid unrelated staged changes while pushing

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@aless10 @asottile
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.