Skip to content

[FR][bug?] pre-commit hook repo self-test #1258

@webknjaz

Description

@webknjaz

Given a repo with .pre-commit-hooks.yaml defined (like https://github.com/ansible/ansible-lint), I want to integrate testing of the hooks declared in it.

I can do pre-commit try-repo https://github.com/ansible/ansible-lint.git but this hits the remote which I want to avoid. I know that Git itself can work with local fs paths (like /path/to/.git) perfectly fine.

So I tried:

$ pre-commit try-repo .git -vvv
pre-commit try-repo .git -vvv
[WARNING] Creating temporary repo with uncommitted changes...
An unexpected error has occurred: CalledProcessError: Command: ('/usr/bin/git', 'add', '-u')
Return code: 128
Expected return code: 0
Output: (none)
Errors: 
    fatal: this operation must be run in a work tree
    

Check the log at ~/.cache/pre-commit/pre-commit.log

The log doesn't reveal anything more than the fact that the Git command failed.

$ cat ~/.cache/pre-commit/pre-commit.log
An unexpected error has occurred: CalledProcessError: Command: ('/usr/bin/git', 'add', '-u')
Return code: 128
Expected return code: 0
Output: (none)
Errors: 
    fatal: this operation must be run in a work tree
    

Traceback (most recent call last):
  File "~/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pre_commit/error_handler.py", line 46, in error_handler
    yield
  File "~/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pre_commit/main.py", line 296, in main
    return try_repo(args)
  File "~/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pre_commit/commands/try_repo.py", line 55, in try_repo
    repo, ref = _repo_ref(tempdir, args.repo, args.ref)
  File "~/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pre_commit/commands/try_repo.py", line 45, in _repo_ref
    cmd_output('git', 'add', '-u', cwd=repo, env=env)
  File "~/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pre_commit/util.py", line 153, in cmd_output
    returncode, cmd, retcode, output=(stdout, stderr),
pre_commit.util.CalledProcessError: Command: ('/usr/bin/git', 'add', '-u')
Return code: 128
Expected return code: 0
Output: (none)
Errors: 
    fatal: this operation must be run in a work tree

It must be pretty easy to fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions