Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stashed changes conflicted with hook auto-fixes... Rolling back fixes... #1787

Closed
pantelis-karamolegkos opened this issue Feb 6, 2021 · 4 comments
Labels

Comments

@pantelis-karamolegkos
Copy link

Using

▶ pre-commit --version
pre-commit 2.10.0

on MacOS Catalina.

I have a directory full of (not only, but mostly) terraform files as also terragrunt hcl config.

Using this pre-commit config

▶ cat .pre-commit-config.yaml
repos:
  - repo: git://github.com/antonbabenko/pre-commit-terraform
    rev: v1.45.0
    hooks:
      - id: terraform_fmt
      - id: terraform_tflint
      - id: terraform_docs
      - id: terraform_tfsec
      - id: terragrunt_fmt

The following error comes up when running pre-commit

[WARNING] Stashed changes conflicted with hook auto-fixes... Rolling back fixes...
An unexpected error has occurred: CalledProcessError: command: ('/usr/bin/git', '-c', 'core.autocrlf=false', 'apply', '--whitespace=nowarn', '/Users/pantelis/.cache/pre-commit/patch1612618048')
return code: 128
expected return code: 0
stdout: (none)
stderr:
    error: unrecognized input

Check the log at /Users/pantelis/.cache/pre-commit/pre-commit.log

and the log

### version information

pre-commit version: 2.10.0
sys.version:
    3.9.0 (default, Dec  6 2020, 18:02:34)
    [Clang 12.0.0 (clang-1200.0.32.27)]
sys.executable: /usr/local/opt/python@3.9/bin/python3.9
os.name: posix
sys.platform: darwin

### error information

An unexpected error has occurred: CalledProcessError: command: ('/usr/bin/git', '-c', 'core.autocrlf=false', 'apply', '--whitespace=nowarn', '/Users/pantelis/.cache/pre-commit/patch1612618267')
return code: 128
expected return code: 0
stdout: (none)
stderr:
    error: unrecognized input


Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/pre_commit/staged_files_only.py", line 20, in _git_apply
    cmd_output_b('git', *args)
  File "/usr/local/lib/python3.9/site-packages/pre_commit/util.py", line 154, in cmd_output_b
    raise CalledProcessError(returncode, cmd, retcode, stdout_b, stderr_b)
pre_commit.util.CalledProcessError: command: ('/usr/bin/git', 'apply', '--whitespace=nowarn', '/Users/pantelis/.cache/pre-commit/patch1612618267')
return code: 128
expected return code: 0
stdout: (none)
stderr:
    error: unrecognized input


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/pre_commit/staged_files_only.py", line 68, in _unstaged_changes_cleared
    _git_apply(patch_filename)
  File "/usr/local/lib/python3.9/site-packages/pre_commit/staged_files_only.py", line 23, in _git_apply
    cmd_output_b('git', '-c', 'core.autocrlf=false', *args)
  File "/usr/local/lib/python3.9/site-packages/pre_commit/util.py", line 154, in cmd_output_b
    raise CalledProcessError(returncode, cmd, retcode, stdout_b, stderr_b)
pre_commit.util.CalledProcessError: command: ('/usr/bin/git', '-c', 'core.autocrlf=false', 'apply', '--whitespace=nowarn', '/Users/pantelis/.cache/pre-commit/patch1612618267')
return code: 128
expected return code: 0
stdout: (none)
stderr:
    error: unrecognized input


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/pre_commit/staged_files_only.py", line 20, in _git_apply
    cmd_output_b('git', *args)
  File "/usr/local/lib/python3.9/site-packages/pre_commit/util.py", line 154, in cmd_output_b
    raise CalledProcessError(returncode, cmd, retcode, stdout_b, stderr_b)
pre_commit.util.CalledProcessError: command: ('/usr/bin/git', 'apply', '--whitespace=nowarn', '/Users/pantelis/.cache/pre-commit/patch1612618267')
return code: 128
expected return code: 0
stdout: (none)
stderr:
    error: unrecognized input


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/pre_commit/error_handler.py", line 65, in error_handler
    yield
  File "/usr/local/lib/python3.9/site-packages/pre_commit/main.py", line 378, in main
    return run(args.config, store, args)
  File "/usr/local/lib/python3.9/site-packages/pre_commit/commands/run.py", line 405, in run
    return _run_hooks(config, hooks, args, environ)
  File "/usr/local/Cellar/python@3.9/3.9.0_5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/contextlib.py", line 513, in __exit__
    raise exc_details[1]
  File "/usr/local/Cellar/python@3.9/3.9.0_5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/contextlib.py", line 498, in __exit__
    if cb(*exc_details):
  File "/usr/local/Cellar/python@3.9/3.9.0_5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/contextlib.py", line 124, in __exit__
    next(self.gen)
  File "/usr/local/lib/python3.9/site-packages/pre_commit/staged_files_only.py", line 93, in staged_files_only
    yield
  File "/usr/local/Cellar/python@3.9/3.9.0_5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/contextlib.py", line 124, in __exit__
    next(self.gen)
  File "/usr/local/lib/python3.9/site-packages/pre_commit/staged_files_only.py", line 78, in _unstaged_changes_cleared
    _git_apply(patch_filename)
  File "/usr/local/lib/python3.9/site-packages/pre_commit/staged_files_only.py", line 23, in _git_apply
    cmd_output_b('git', '-c', 'core.autocrlf=false', *args)
  File "/usr/local/lib/python3.9/site-packages/pre_commit/util.py", line 154, in cmd_output_b
    raise CalledProcessError(returncode, cmd, retcode, stdout_b, stderr_b)
pre_commit.util.CalledProcessError: command: ('/usr/bin/git', '-c', 'core.autocrlf=false', 'apply', '--whitespace=nowarn', '/Users/pantelis/.cache/pre-commit/patch1612618267')
return code: 128
expected return code: 0
stdout: (none)
stderr:
    error: unrecognized input
@asottile
Copy link
Member

asottile commented Feb 6, 2021

can you show the contents of the patch file it mentions?

can you also share your .gitattributes -- this may be another case of #776 which I believe is a bug in git itself and I haven't gotten any traction on the mailing list

@asottile asottile added the bug label Feb 6, 2021
@pantelis-karamolegkos
Copy link
Author

pantelis-karamolegkos commented Feb 6, 2021

Actually I am using git-crypt to encrypt secrets.auto.tfvars so the patch file contains sensitive info

▶ cat .gitattributes
secrets.auto.tfvars filter=git-crypt diff=git-crypt

Could this be the issue?

Can I instruct pre-commit to ignore these files?

@asottile
Copy link
Member

asottile commented Feb 6, 2021

this is a dupe of #776 then

@asottile asottile closed this as completed Feb 6, 2021
@yuklia
Copy link

yuklia commented Mar 23, 2021

hi, @pantelis-karamolegkos !
how did you manage to solve this issue?

thanks in advance!

@pre-commit pre-commit locked as resolved and limited conversation to collaborators Mar 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

3 participants