question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pre-commit install-hooks should run without git tree

See original GitHub issue

search tried in the issue tracker

install-hooks

describe your issue

I want to build a docker container in which pre-commit hooks are already installed but running pre-commit install-hooks -c .pre-commit-config.yaml fails: An error has occurred: FatalError: git failed. Is it installed, and are you in a Git repository directory?

There are various workarounds such as copying the .git directory inside the container or creating a temporary git repo but I think it’s useful to just allow install-hooks to work with just a config file

pre-commit --version

pre-commit 2.19.0

.pre-commit-config.yaml

# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.2.0
    hooks:
      - id: trailing-whitespace
      - id: end-of-file-fixer
      - id: check-yaml
      - id: check-added-large-files

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

An error has occurred: FatalError: git failed. Is it installed, and are you in a Git repository directory? Check the log at /root/.cache/pre-commit/pre-commit.log

version information

pre-commit version: 2.19.0
git --version: git version 2.34.1
sys.version:
    3.10.4 (main, Apr  2 2022, 09:04:19) [GCC 11.2.0]
sys.executable: /usr/bin/python3
os.name: posix
sys.platform: linux

error information

An error has occurred: FatalError: git failed. Is it installed, and are you in a Git repository directory?
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/pre_commit/git.py", line 58, in get_root
    cmd_output('git', 'rev-parse', '--show-cdup')[1].strip(),
  File "/usr/local/lib/python3.10/dist-packages/pre_commit/util.py", line 152, in cmd_output
    returncode, stdout_b, stderr_b = cmd_output_b(*cmd, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/pre_commit/util.py", line 146, in cmd_output_b
    raise CalledProcessError(returncode, cmd, retcode, stdout_b, stderr_b)
pre_commit.util.CalledProcessError: command: ('/usr/bin/git', 'rev-parse', '--show-cdup')
return code: 128
expected return code: 0
stdout: (none)
stderr:
    fatal: not a git repository (or any of the parent directories): .git


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/pre_commit/error_handler.py", line 73, in error_handler
    yield
  File "/usr/local/lib/python3.10/dist-packages/pre_commit/main.py", line 344, in main
    _adjust_args_and_chdir(args)
  File "/usr/local/lib/python3.10/dist-packages/pre_commit/main.py", line 147, in _adjust_args_and_chdir
    toplevel = git.get_root()
  File "/usr/local/lib/python3.10/dist-packages/pre_commit/git.py", line 64, in get_root
    raise FatalError(
pre_commit.errors.FatalError: git failed. Is it installed, and are you in a Git repository directory?

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
asottilecommented, May 8, 2022

no thanks, I have no intention to carry such complexity

0reactions
cdleonardcommented, May 9, 2022

Fair enough, I’ll use temporary git repos.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Supported hooks - pre-commit
prospector - This hook runs Prospector: https://github.com/landscapeio/prospector ... script-must-not-have-extension - Executable shell script omits the ...
Read more >
How can I manually run a Git pre-commit hook, without ...
Just run the pre-commit script through the shell: bash .git/hooks/pre-commit.
Read more >
How to use git pre-commit hooks, the hard way and the easy ...
The hook runs before a commit is accepted to git, and if the hook script fails (ie if it returns a non-zero exit...
Read more >
Git Hooks - Git SCM
The first four hooks have to do with the committing process. The pre-commit hook is run first, before you even type in a...
Read more >
Hooks not installed in the right hooks directory for worktrees
When on a git worktree, the hooks are not installed on the right hook dir: ❯ pre-commit install pre-commit installed at ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found