Skip to content

bug: Griffe does not dump stderr in case there is an error in a git call #415

@mabdullahsoyturk

Description

@mabdullahsoyturk

Description of the bug

Griffe does bunch of git calls (via _git function). In case there is an error in one of those calls, it's impossible to see the stderr because _git function captures the output and only returns the stdout with GitError.

To Reproduce

Example:

git clone git@github.com:GAMS-dev/gamspy.git
cd gamspy
git checkout -b griffe-origin-master
python -m venv .venv
source venv/bin/activate
pip install griffe
griffe check --search src gamspy --verbose --against origin/master

Full traceback

Traceback (most recent call last):
  File "C:\Users\muhammet\anaconda3\envs\py313\Lib\site-packages\griffe\_internal\git.py", line 118, in _tmp_worktree
    _git("-C", str(repo), "worktree", "add", "-b", tmp_branch, location, ref)
    ~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\muhammet\anaconda3\envs\py313\Lib\site-packages\griffe\_internal\git.py", line 39, in _git
    raise GitError(process.stdout.strip())
griffe._internal.exceptions.GitError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\muhammet\anaconda3\envs\py313\Scripts\griffe.exe\__main__.py", line 7, in <module>
    sys.exit(main())
             ~~~~^^
  File "C:\Users\muhammet\anaconda3\envs\py313\Lib\site-packages\griffe\_internal\cli.py", line 572, in main
    return commands[subcommand](**opts_dict)
           ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
  File "C:\Users\muhammet\anaconda3\envs\py313\Lib\site-packages\griffe\_internal\cli.py", line 478, in check
    old_package = load_git(
        against_path,
    ...<7 lines>...
        resolve_external=None,
    )
  File "C:\Users\muhammet\anaconda3\envs\py313\Lib\site-packages\griffe\_internal\loader.py", line 903, in load_git
    with _tmp_worktree(repo, ref) as worktree:
         ~~~~~~~~~~~~~^^^^^^^^^^^
  File "C:\Users\muhammet\anaconda3\envs\py313\Lib\contextlib.py", line 141, in __enter__
    return next(self.gen)
  File "C:\Users\muhammet\anaconda3\envs\py313\Lib\site-packages\griffe\_internal\git.py", line 120, in _tmp_worktree
    raise RuntimeError(f"Could not create git worktree: {error}") from error
RuntimeError: Could not create git worktree:

Expected behavior

I would expect to see the stderr which says "fatal: a branch named 'griffe-origin-master' already exists". Without this information, the error message is not really useful.

Environment information

- __System__: Windows-11-10.0.26100-SP0
- __Python__: cpython 3.13.0 (C:\Users\muhammet\anaconda3\envs\py313\python.exe)
- __Environment variables__:
- __Installed packages__:
  - `griffe` v1.14.0

Metadata

Metadata

Assignees

Labels

unconfirmedThis bug was not reproduced yet

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions