JonasPammer / cookiecutter-ansible-role

An awesome CookieCutter for my ansible roles.
MIT License
1 stars 3 forks source link

pre-commit fails in devcontainer #91

Closed JonasPammer closed 1 year ago

JonasPammer commented 1 year ago

solution: add the following line at top of postCreateCommand.sh (or at least before call to pre-commit):

git config --global --add safe.directory /workspaces/*

very nice content of /home/vscode/.cache/pre-commit/pre-commit.log:

version information

pre-commit version: 3.2.2
git --version: git version 2.40.0
sys.version:
    3.11.3 (main, Apr 25 2023, 09:37:07) [GCC 11.3.0]
sys.executable: /usr/local/python/current/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/python/current/lib/python3.11/site-packages/pre_commit/git.py", line 58, in get_root
    cmd_output('git', 'rev-parse', '--show-cdup')[1].strip(),
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/python/current/lib/python3.11/site-packages/pre_commit/util.py", line 116, in cmd_output
    returncode, stdout_b, stderr_b = cmd_output_b(*cmd, **kwargs)
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/python/current/lib/python3.11/site-packages/pre_commit/util.py", line 110, in cmd_output_b
    raise CalledProcessError(returncode, cmd, stdout_b, stderr_b)
pre_commit.util.CalledProcessError: command: ('/usr/local/bin/git', 'rev-parse', '--show-cdup')
return code: 128
stdout: (none)
stderr:
    fatal: detected dubious ownership in repository at '/workspaces/ansible-role-bootstrap'
    To add an exception for this directory, call:

        git config --global --add safe.directory /workspaces/ansible-role-bootstrap

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/python/current/lib/python3.11/site-packages/pre_commit/error_handler.py", line 73, in error_handler
    yield
  File "/usr/local/python/current/lib/python3.11/site-packages/pre_commit/main.py", line 366, in main
    _adjust_args_and_chdir(args)
  File "/usr/local/python/current/lib/python3.11/site-packages/pre_commit/main.py", line 180, in _adjust_args_and_chdir
    toplevel = git.get_root()
               ^^^^^^^^^^^^^^
  File "/usr/local/python/current/lib/python3.11/site-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?
JonasPammer commented 1 year ago

just for information: Host OS is a Windows 11 with newest VSCode (1.77.3) and the git clone of project was done through SSH

JonasPammer commented 1 year ago

note: doesn't happen my windows 11 at home, but that has other git/wsl weirdness... still, implement fix from issue nontheless