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

Empty .git/hooks/pre-commit.legacy File causes OSError #2448

Closed
BigTuna94 opened this issue Jul 8, 2022 · 7 comments
Closed

Empty .git/hooks/pre-commit.legacy File causes OSError #2448

BigTuna94 opened this issue Jul 8, 2022 · 7 comments

Comments

@BigTuna94
Copy link

search tried in the issue tracker

is:issue is:open OSError

describe your issue

In the latest version (2.19.0) pre-commit install appears to create an empty .git/hooks/pre-commit.legacy file. This causes an OSError when git (version 2.31.1) attempts to run the actual pre-commit hook.

Actual reported error:

$ git commit -m "dummy commit"
An unexpected error has occurred: OSError: [Errno 8] Exec format error: '/<repo path>/.git/hooks/pre-commit.legacy'

This appears to be the same core issue as: #1350
If I manually modify the empty file and add a shebang, the error subsides. However, the real solution is probably to avoid the creation of the empty file altogether.

pre-commit --version

pre-commit 2.19.0

.pre-commit-config.yaml

repos:
-   repo: local
    hooks:
    -   id: clang-format
        name: Enforce code style format
        language: system
        entry: make format-check-staged-silent

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

version information

pre-commit version: 2.19.0
git --version: git version 2.31.1
sys.version:
    3.9.7 (default, Sep 21 2021, 00:13:39) 
    [GCC 8.5.0 20210514 (Red Hat 8.5.0-3)]
sys.executable: /root/.local/pipx/venvs/pre-commit/bin/python
os.name: posix
sys.platform: linux

error information

An unexpected error has occurred: OSError: [Errno 8] Exec format error: '/<repo path>/.git/hooks/pre-commit.legacy'
Traceback (most recent call last):
  File "/root/.local/pipx/venvs/pre-commit/lib64/python3.9/site-packages/pre_commit/error_handler.py", line 73, in error_handler
    yield
  File "/root/.local/pipx/venvs/pre-commit/lib64/python3.9/site-packages/pre_commit/main.py", line 361, in main
    return hook_impl(
  File "/root/.local/pipx/venvs/pre-commit/lib64/python3.9/site-packages/pre_commit/commands/hook_impl.py", line 232, in hook_impl
    retv, stdin = _run_legacy(hook_type, hook_dir, args)
  File "/root/.local/pipx/venvs/pre-commit/lib64/python3.9/site-packages/pre_commit/commands/hook_impl.py", line 43, in _run_legacy
    return subprocess.run(cmd, input=stdin).returncode, stdin
  File "/usr/lib64/python3.9/subprocess.py", line 505, in run
    with Popen(*popenargs, **kwargs) as process:
  File "/usr/lib64/python3.9/subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib64/python3.9/subprocess.py", line 1821, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
OSError: [Errno 8] Exec format error: '/<repo path>/.git/hooks/pre-commit.legacy'
@asottile
Copy link
Member

asottile commented Jul 8, 2022

how did that file get there to begin with? do you have reproduction steps?

@BigTuna94
Copy link
Author

With the listed config file in place, all I did was pre-commit install, which created the file.

@asottile
Copy link
Member

asottile commented Jul 8, 2022

I can't reproduce -- the only way that would happen is if you already had created an (invalid) empty .git/hooks/pre-commit file

@BigTuna94
Copy link
Author

Hmmm now that I removed the empty file, I cannot reproduce myself... perhaps the empty file was created by an OS/NAS issue...

However, when the empty .git/hooks/pre-commit.legacy file did exist, I could avoid this issue by downgrading to pre-commit==2.18.0. Then when switching back to pre-commit==2.19.0, the issue returned.

@asottile
Copy link
Member

asottile commented Jul 8, 2022

I don't think that's accurate either -- nothing changed in hook-impl between those two versions that'd be relevant (and having that file present, empty and executable shows the same error in all those cases): https://github.com/pre-commit/pre-commit/compare/v2.18.0..v2.19.0#diff-c8d43e2e621a124c4518d87dd3a9e598261fcbb4947ea379d84f7f4eeada0238

either way -- this is a user error and not a pre-commit issue

@asottile asottile closed this as completed Jul 8, 2022
@jtlz2
Copy link

jtlz2 commented Mar 1, 2023

If this is a user error, does anyone have a solution? Thanks!

@asottile
Copy link
Member

asottile commented Mar 1, 2023

delete the empty file

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

No branches or pull requests

3 participants