Skip to content

pre-push should forbid unrelated staged changes while pushing #2486

@bnchou

Description

@bnchou

search tried in the issue tracker

yes

describe your issue

I configured dotnet format as push hook in my .pre-commit-config.yaml
I installed them using

pre-commit install --install-hooks --hook-type pre-commit --hook-type pre-push

I committed a modification with dotnet format not following correct rules, it passes
I try to push, it is rejected with error

 error: failed to push some refs to

And it corrects my file after dotnet format
When I try to push again, I have the same error.

When I add the file in staged changes without commit it, I can push.
I expect to be rejected even if I put the correct file in staged changes.

pre-commit --version

pre-commit 2.20.0

.pre-commit-config.yaml

default_stages: [commit]
repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.1.0
    hooks:
      - id: check-added-large-files
      - id: check-case-conflict
  - repo: local
    hooks:
    - id: dotnet-format
      name: dotnet-format
      language: system
      entry: dotnet format --include
      types_or: ["c#"]
      stages : [push]

~/.cache/pre-commit/pre-commit.log (if present)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions