Skip to content

Duplicate files when doing pre-commit run --all-files during git conflict #3706

Description

@RomanValov

search you tried in the issue tracker

merge / conflict / duplicate

describe your issue

Hello,

First of all, thank you for your work. The tool helps to organize development workflows a lot. Here is an issue I have encountered:

I'm using pre-commit manually to run lints and checks over my code during development workflow. In particular running it during rebases when conflicts arisen. I found pre-commit to duplicate file names if they are in conflicted state. Some tools misbehaves in case.

Here is a minimal reproducible scenario using git stash conflict:

$ git init .
$ touch README.md
$ git add README.md 
$ git commit -am "initial state"
[master (root-commit) 53eaf48] initial state
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 README.md
$ pre-commit run --all-files --verbose
echo.....................................................................Passed
- hook id: echo
- duration: 0s

README.md

$ echo 'right' > ./README.md 
$ git stash
Saved working directory and index state WIP on master: 53eaf48 initial state
$ echo 'left' > ./README.md 
$ git add README.md 
$ git stash pop
Auto-merging README.md
CONFLICT (content): Merge conflict in README.md
Recorded preimage for 'README.md'
On branch master
Unmerged paths:
  (use "git restore --staged <file>..." to unstage)
  (use "git add <file>..." to mark resolution)
	both modified:   README.md

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	.pre-commit-config.yaml

no changes added to commit (use "git add" and/or "git commit -a")
The stash entry is kept in case you need it again.
$ pre-commit run --all-files --verbose
echo.....................................................................Passed
- hook id: echo
- duration: 0s

README.md README.md README.md

It would be nice if pre-commit could de-duplicate file list prior to feeding it to tools being invoked. Workarounds are welcome.

pre-commit --version

pre-commit 4.6.0

.pre-commit-config.yaml

repos:
  - repo: local
    hooks:
    - id: echo
      name: echo
      entry: echo
      language: system

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions