Skip to content

'FatalError: pre-commit failed to diff -- perhaps due to permissions?' after fixing line endings during a merge. #2839

@th3w1zard1

Description

@th3w1zard1

search you tried in the issue tracker

"FatalError: pre-commit failed to diff" including exact phrase on google and stackoverflow

describe your issue

The only close issue I could find is #823.

I use GitHub Desktop. Whenever there's a merge conflict, and I fix them, github will ask to continue the merge now that conflicts are resolved. Ok. So I click 'continue', pre-commit does its thing, telling me its fixed mixed line endings like it normally does.

This is when this annoying bug starts. I'll press 'continue' after pre-commit did its thing and this will pop up:

An error has occurred: FatalError: pre-commit failed to diff -- perhaps due to permissions?

command: ('git', 'diff-index', '--ignore-submodules', '--binary', '--exit-code', '--no-color', '--no-ext-diff', 'c6b8adb03e2bdfec027d94f7f7e3865343d7e6f5', '--')
return code: 1
stdout: (none)
stderr:
    warning: in the working copy of 'custom_components/adaptive_lighting/switch.py', LF will be replaced by CRLF the next time Git touches it
    warning: in the working copy of 'tests/test_switch.py', LF will be replaced by CRLF the next time Git touches it
Check the log at C:\Users\boden\.cache\pre-commit\pre-commit.log

The only workaround is to commit a new commit instead of pressing 'continue'. This is ridiculously annoying because I have to not only title my commit but tell my fellow contributors what I squashed/merged with in the description by hand.

Is there any way to turn the 'failed to diff' off? I just want it to continue when there's no diff. Thanks!

It's worth pointing out that when there is no merge happening and I'm just committing (a basic one step process) pre-commit works fine. It's when GitHub desktop is dealing with the complicated multi-step 'oh you can't commit yet you have conflicts' stuff that pre-commit gets confused and starts outputting this error.

pre-commit --version

pre-commit 3.2.1

.pre-commit-config.yaml

repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.4.0
    hooks:
      - id: check-added-large-files
      - id: trailing-whitespace
      - id: end-of-file-fixer
      - id: mixed-line-ending
        args: ["--fix=lf"]
  - repo: https://github.com/pycqa/flake8
    rev: 6.0.0
    hooks:
      - id: flake8
  - repo: https://github.com/psf/black
    rev: 23.3.0
    hooks:
      - id: black
  - repo: https://github.com/asottile/pyupgrade
    rev: v3.3.1
    hooks:
      - id: pyupgrade
        args: ["--py39-plus"]
  - repo: https://github.com/PyCQA/isort
    rev: 5.12.0
    hooks:
      - id: isort

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

No response

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