[Bug] GitCommandNotFound when executing repo.git.execute on macOS · Issue #2016 · gitpython-developers/GitPython · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content

[Bug] GitCommandNotFound when executing repo.git.execute on macOS #2016

Open
@cloudskytian

Description

@cloudskytian

Describe the bug
When executing repo.git.execute with string-type arguments on macOS, it throws a GitCommandNotFound exception:

Traceback (most recent call last):
  File "/Users/macuser/.pyenv/versions/3.12.2/lib/python3.12/site-packages/git/cmd.py", line 1262, in execute
    proc = safer_popen(
           ^^^^^^^^^^^^
  File "/Users/macuser/.pyenv/versions/3.12.2/lib/python3.12/subprocess.py", line 1026, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/Users/macuser/.pyenv/versions/3.12.2/lib/python3.12/subprocess.py", line 1953, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'git log -n 1'

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

Traceback (most recent call last):
  File "/Users/macuser/test.py", line 36, in <module>
    cmd = repo.git.execute("git log -n 1")
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/macuser/.pyenv/versions/3.12.2/lib/python3.12/site-packages/git/cmd.py", line 1275, in execute
    raise GitCommandNotFound(redacted_command, err) from err
git.exc.GitCommandNotFound: Cmd('g') not found due to: FileNotFoundError('[Errno 2] No such file or directory: 'git log -n 1'')

I have installed git and it works well on other commands, only repo.git.execute doesn't work'

The error only occurs when passing a string-type argument to repo.git.execute

Works correctly when using string array arguments

Works correctly when using shell=True argument

for example:

# Failing case (string argument)
repo.git.execute("git log -n 1")  # Throws exception

# Working case (array argument)
repo.git.execute(["git", "log", "-n", "1"])  # Executes successfully

# Working case (array argument)
repo.git.execute("git log -n 1", shell=True)  # Executes successfully

Environment

  • Python version: 3.12
  • GitPython version: 3.1.43
  • Operating System: macOS 14.3.1 (Sonoma)
  • Git version: 2.46.0
  • By the way, I'm using pyenv

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      TMZ Celebrity News – Breaking Stories, Videos & Gossip

      Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

      Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

      🎥 Watch TMZ Live

      TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.