Thanks for the report! could you provide some more information (if possible) for me?
it appears from the output that you committed with an unstaged change, to which file was that and if possible could you share the patch file mentioned?
I suspect the diff=git-crypt is somehow throwing off the way we generate and then reapply patches and will need to be worked around.
+ git commit -m test
[WARNING] Unstaged files detected.
[INFO] Stashing unstaged files to /home/asottile/.cache/pre-commit/patch1530539647.
Trim Trailing Whitespace.................................................Passed
[WARNING] Stashed changes conflicted with hook auto-fixes... Rolling back fixes...
An unexpected error has occurred: CalledProcessError: Command: ('/usr/lib/git-core/git', '-c', 'core.autocrlf=false', 'apply', '--whitespace=nowarn', '/home/asottile/.cache/pre-commit/patch1530539647')
Return code: 1
Expected return code: 0
Output: (none)
Errors:
error: binary patch to 'f' creates incorrect result (expecting 9dc8b7b3fd7e85892019cbf77d888ce9d9f37b15, got e69de29bb2d1d6434b8b29ae775ad8c2e48c5391)
error: f: patch does not apply
Check the log at /home/asottile/.cache/pre-commit/pre-commit.log
Almost certainly due to the smudge filter though I'm not exactly sure what the correct approach is here -- for now you can work around this by making sure you stage the encrypted files before committing.
I encountered a similar issue as well, here's the log. This is reproduced in some repos that have implemented some clean filters, with some test cases files intentionally committed uncleaned for testing.
Wondering if there was an update on this issue? If there are any hints on what the issue might be, I'd be keen to offer help fixing - it's something we run into frequently
I started looking into this from the git side but never got a definitive response -- it comes down to unstaged things in a smudge filter generating bogus git diff that cannot be later git applyd
the current known workaround is to make sure such files are git added before committing, but isn't ideal
I'm not sure what it would take to fix this, I suspect a fix from git is necessary (or some workaround where pre-commit identifies smudge-filter files and handles them separately)
as it turned out there were a couple of empty files. I took a look inside /Users/yulia/.cache/pre-commit/pre-commit.log and noticed that 1 commit ago I committed 2 totally empty secrets files. So I filled them in.
then
0 git add .
1 pre-commit install
2 git commit -m 'Your commit msg'
Everything works as expected :))
Terraform fmt............................................................Passed
Terraform docs.......................................(no files to check)Skipped
Terraform validate.......................................................Passed
Check for merge conflicts................................................Passed
git-crypt-check-status...................................................Passed
I can confirm that this issue was resolved for me by making sure I wasn't staging empty files that matched my .gitattributes git-crypt smudge/filter settings.
Reacted by anthony sottile, Paulo Koch and Marco Pfatschbacher
interestingly, adding --textconv to the git diff command makes (at least) my reproduction above succeed. it certainly seems like the wrong thing to do but maybe that's ok?
I can confirm that this issue was resolved for me by making sure I wasn't staging empty files that matched my .gitattributes git-crypt smudge/filter settings.
Activity
asottile commented on Jul 2, 2018
Thanks for the report! could you provide some more information (if possible) for me?
it appears from the output that you committed with an unstaged change, to which file was that and if possible could you share the patch file mentioned?
I suspect the diff=git-crypt is somehow throwing off the way we generate and then reapply patches and will need to be worked around.
ranimufid commented on Jul 2, 2018
thanks for your prompt response @asottile.
Context:
I'm trying to encrypt some ansible secrets using git-crypt. I'm also doing ansible-lint as a pre-commit hook.
The change which triggered the error is creating an empty file /hosts/testing/secret-vars.yml with a corresponding entry in .gitattributes
.gitattributes
The patch file corresponding to the above change
Do let me know if you need further info
asottile commented on Jul 2, 2018
ok, I have a reproduction:
which ends with:
+ git commit -m test [WARNING] Unstaged files detected. [INFO] Stashing unstaged files to /home/asottile/.cache/pre-commit/patch1530539647. Trim Trailing Whitespace.................................................Passed [WARNING] Stashed changes conflicted with hook auto-fixes... Rolling back fixes... An unexpected error has occurred: CalledProcessError: Command: ('/usr/lib/git-core/git', '-c', 'core.autocrlf=false', 'apply', '--whitespace=nowarn', '/home/asottile/.cache/pre-commit/patch1530539647') Return code: 1 Expected return code: 0 Output: (none) Errors: error: binary patch to 'f' creates incorrect result (expecting 9dc8b7b3fd7e85892019cbf77d888ce9d9f37b15, got e69de29bb2d1d6434b8b29ae775ad8c2e48c5391) error: f: patch does not apply Check the log at /home/asottile/.cache/pre-commit/pre-commit.logAlmost certainly due to the smudge filter though I'm not exactly sure what the correct approach is here -- for now you can work around this by making sure you stage the encrypted files before committing.
ranimufid commented on Jul 2, 2018
This is how i've worked around it for the time being:
asottile commented on Jul 2, 2018
hmm, my crash is actually different from yours -- I wonder there's two issues here :S
brlin-tw commented on Aug 14, 2018
I encountered a similar issue as well, here's the log. This is reproduced in some repos that have implemented some clean filters, with some test cases files intentionally committed uncleaned for testing.
marcjay commented on Aug 20, 2019
Wondering if there was an update on this issue? If there are any hints on what the issue might be, I'd be keen to offer help fixing - it's something we run into frequently
asottile commented on Aug 20, 2019
I started looking into this from the git side but never got a definitive response -- it comes down to unstaged things in a smudge filter generating bogus git diff that cannot be later git applyd
the current known workaround is to make sure such files are git added before committing, but isn't ideal
I'm not sure what it would take to fix this, I suspect a fix from git is necessary (or some workaround where pre-commit identifies smudge-filter files and handles them separately)
marcjay commented on Aug 20, 2019
Many thanks @asottile, that all sounds very non-trivial
asottile commented on Aug 20, 2019
yeah :'( that's why I haven't dug into it yet beyond the repro above
yuklia commented on Mar 23, 2021
Hi! I've got the same issue:
pre-commit run --show-diff-on-failure terraform_validate [WARNING] Unstaged files detected. [INFO] Stashing unstaged files to /Users/yulia/.cache/pre-commit/patch1616497389. Terraform validate.......................................................Passed [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/yulia/.cache/pre-commit/patch1616497389') return code: 128 expected return code: 0 stdout: (none) stderr: error: unrecognized input.pre-commit-config.yml
repos: - repo: git://github.com/antonbabenko/pre-commit-terraform rev: v1.46.0 hooks: - id: terraform_fmt - id: terraform_docs # - id: terraform_tflint # args: # - '--args=--only=terraform_deprecated_interpolation' # - '--args=--only=terraform_deprecated_index' # - '--args=--only=terraform_unused_declarations' # - '--args=--only=terraform_comment_syntax' # - '--args=--only=terraform_documented_outputs' # - '--args=--only=terraform_documented_variables' # - '--args=--only=terraform_typed_variables' # - '--args=--only=terraform_module_pinned_source' # - '--args=--only=terraform_naming_convention' # - '--args=--only=terraform_required_version' # - '--args=--only=terraform_required_providers' # - '--args=--only=terraform_standard_module_structure' # - '--args=--only=terraform_workspace_remote' - repo: git://github.com/pre-commit/pre-commit-hooks rev: v3.4.0 hooks: - id: check-merge-conflict - repo: git://github.com/gruntwork-io/pre-commit rev: v0.1.12 hooks: - id: terraform-validateyuklia commented on Mar 23, 2021
it solved for me
as it turned out there were a couple of empty files. I took a look inside /Users/yulia/.cache/pre-commit/pre-commit.log and noticed that 1 commit ago I committed 2 totally empty secrets files. So I filled them in.
then
philipsd6 commented on Aug 15, 2021
I can confirm that this issue was resolved for me by making sure I wasn't staging empty files that matched my .gitattributes git-crypt smudge/filter settings.
asottile commented on Nov 1, 2022
interestingly, adding --textconv to the git diff command makes (at least) my reproduction above succeed. it certainly seems like the wrong thing to do but maybe that's ok?
asottile commented on Nov 1, 2022
I submitted a more thorough investigation to the git mailing list -- https://marc.info/?l=git&m=166733577332408&w=2
mpfz0r commented on Feb 14, 2025
Thank you! This was the reason for me as well.