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

Parallel execution ran into "patch does not apply" #1880

Closed
adamchainz opened this issue Apr 16, 2021 · 0 comments · Fixed by #1881
Closed

Parallel execution ran into "patch does not apply" #1880

adamchainz opened this issue Apr 16, 2021 · 0 comments · Fixed by #1881

Comments

@adamchainz
Copy link
Contributor

I modified a bunch of repos using pre-commit in parallel and ran git commit at the same time, with unstaged changes. The pre-commit processes did [WARNING] Unstaged files detected., stashed the changes in a pach, ran, and then tried to reapply the patches.

Some repos failed with:

[WARNING] Stashed changes conflicted with hook auto-fixes... Rolling back fixes...
An unexpected error has occurred: CalledProcessError: command: ('/usr/local/Cellar/git/2.31.1/libexec/git-core/git', '-c', 'core.autocrlf=false', 'apply', '--whitespace=nowarn', '/Users/chainz/.cache/pre-commit/patch1618586253')
return code: 1
expected return code: 0
stdout: (none)
stderr:
    error: patch failed: .github/workflows/main.yml:21
    error: .github/workflows/main.yml: patch does not apply

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

It looks like this is due to use of the unix timestamp as the only differentiator in patch file paths, causing the parallely-created patches to clobber each other.

pre-commit.log says:

version information

pre-commit version: 2.12.0
sys.version:
    3.9.4 (default, Apr  5 2021, 01:49:30) 
    [Clang 12.0.0 (clang-1200.0.32.29)]
sys.executable: /usr/local/Cellar/pre-commit/2.12.0/libexec/bin/python3
os.name: posix
sys.platform: darwin

error information

An unexpected error has occurred: CalledProcessError: command: ('/usr/local/Cellar/git/2.31.1/libexec/git-core/git', '-c', 'core.autocrlf=false', 'apply', '--whitespace=nowarn', '/Users/chainz/.cache/pre-commit/patch1618586253')
return code: 1
expected return code: 0
stdout: (none)
stderr:
    error: patch failed: .github/workflows/main.yml:21
    error: .github/workflows/main.yml: patch does not apply
    
Traceback (most recent call last):
  File "/usr/local/Cellar/pre-commit/2.12.0/libexec/lib/python3.9/site-packages/pre_commit/staged_files_only.py", line 20, in _git_apply
    cmd_output_b('git', *args)
  File "/usr/local/Cellar/pre-commit/2.12.0/libexec/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/local/Cellar/git/2.31.1/libexec/git-core/git', 'apply', '--whitespace=nowarn', '/Users/chainz/.cache/pre-commit/patch1618586253')
return code: 1
expected return code: 0
stdout: (none)
stderr:
    error: patch failed: .github/workflows/main.yml:21
    error: .github/workflows/main.yml: patch does not apply
    

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/Cellar/pre-commit/2.12.0/libexec/lib/python3.9/site-packages/pre_commit/staged_files_only.py", line 68, in _unstaged_changes_cleared
    _git_apply(patch_filename)
  File "/usr/local/Cellar/pre-commit/2.12.0/libexec/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/Cellar/pre-commit/2.12.0/libexec/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/local/Cellar/git/2.31.1/libexec/git-core/git', '-c', 'core.autocrlf=false', 'apply', '--whitespace=nowarn', '/Users/chainz/.cache/pre-commit/patch1618586253')
return code: 1
expected return code: 0
stdout: (none)
stderr:
    error: patch failed: .github/workflows/main.yml:21
    error: .github/workflows/main.yml: patch does not apply
    

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/Cellar/pre-commit/2.12.0/libexec/lib/python3.9/site-packages/pre_commit/staged_files_only.py", line 20, in _git_apply
    cmd_output_b('git', *args)
  File "/usr/local/Cellar/pre-commit/2.12.0/libexec/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/local/Cellar/git/2.31.1/libexec/git-core/git', 'apply', '--whitespace=nowarn', '/Users/chainz/.cache/pre-commit/patch1618586253')
return code: 1
expected return code: 0
stdout: (none)
stderr:
    error: patch failed: .github/workflows/main.yml:21
    error: .github/workflows/main.yml: patch does not apply
    

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/Cellar/pre-commit/2.12.0/libexec/lib/python3.9/site-packages/pre_commit/error_handler.py", line 65, in error_handler
    yield
  File "/usr/local/Cellar/pre-commit/2.12.0/libexec/lib/python3.9/site-packages/pre_commit/main.py", line 357, in main
    return hook_impl(
  File "/usr/local/Cellar/pre-commit/2.12.0/libexec/lib/python3.9/site-packages/pre_commit/commands/hook_impl.py", line 227, in hook_impl
    return retv | run(config, store, ns)
  File "/usr/local/Cellar/pre-commit/2.12.0/libexec/lib/python3.9/site-packages/pre_commit/commands/run.py", line 408, in run
    return _run_hooks(config, hooks, args, environ)
  File "/usr/local/Cellar/python@3.9/3.9.4/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.4/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.4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/contextlib.py", line 124, in __exit__
    next(self.gen)
  File "/usr/local/Cellar/pre-commit/2.12.0/libexec/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.4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/contextlib.py", line 124, in __exit__
    next(self.gen)
  File "/usr/local/Cellar/pre-commit/2.12.0/libexec/lib/python3.9/site-packages/pre_commit/staged_files_only.py", line 78, in _unstaged_changes_cleared
    _git_apply(patch_filename)
  File "/usr/local/Cellar/pre-commit/2.12.0/libexec/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/Cellar/pre-commit/2.12.0/libexec/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/local/Cellar/git/2.31.1/libexec/git-core/git', '-c', 'core.autocrlf=false', 'apply', '--whitespace=nowarn', '/Users/chainz/.cache/pre-commit/patch1618586253')
return code: 1
expected return code: 0
stdout: (none)
stderr:
    error: patch failed: .github/workflows/main.yml:21
    error: .github/workflows/main.yml: patch does not apply
adamchainz added a commit to adamchainz/pre-commit that referenced this issue Apr 16, 2021
adamchainz added a commit to adamchainz/pre-commit that referenced this issue Apr 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants