Skip to content

docs(cmd): clarify Git.execute() string vs list command argument#2144

Merged
Byron merged 1 commit intogitpython-developers:mainfrom
mvanhorn:osc/2016-clarify-execute-string-arg
May 7, 2026
Merged

docs(cmd): clarify Git.execute() string vs list command argument#2144
Byron merged 1 commit intogitpython-developers:mainfrom
mvanhorn:osc/2016-clarify-execute-string-arg

Conversation

@mvanhorn
Copy link
Copy Markdown
Contributor

@mvanhorn mvanhorn commented May 7, 2026

What changed

Rewrites the :param command: docstring on Git.execute() in git/cmd.py to clarify the string-vs-sequence semantics. The previous wording ("the program to execute is the first item in the args sequence or string") was misleading: with shell=False (the default), subprocess.Popen treats the entire string as a single executable name, so "git log -n 1" looks for an executable literally named "git log -n 1" and raises GitCommandNotFound.

The new docstring:

  • Recommends the sequence form (["git", "log", "-n", "1"]) for the default shell=False case.
  • Documents that a string is accepted but is passed as a single executable name when shell=False, with the exact failure mode users see in [Bug] GitCommandNotFound when executing repo.git.execute on macOS #2016.
  • Points users at shlex.split(...) (sequence) or shell=True (with the existing warning) for the case where they want a string that gets tokenised.

Closes #2016

Why

This is the third recurrence of this confusion that surfaces in issues — string commands look like the obvious shape for "run this git invocation", and the failure mode is opaque. The subprocess.Popen semantics are doing exactly what they always do; the GitPython docstring was the surface that misled users into expecting otherwise. Updating it costs ~10 lines and short-circuits the next round of issues.

I deliberately kept this docs-only. Auto-splitting a string when it contains spaces would be a behavior change that could break existing callers who do pass a single executable path with whitespace. The acknowledged label on the issue suggests maintainer interest without committing to a specific behavior fix; clarifying the docs is the smallest useful step.

Verification

python -c "import git; help(git.cmd.Git.execute)" renders the new param block cleanly. python -m py_compile git/cmd.py is clean. No tests were modified or broken.

Closes gitpython-developers#2016

Users routinely hit GitCommandNotFound by passing a single string with
spaces to repo.git.execute(...). With shell=False (default) subprocess
treats the entire string as the executable name and fails. Document the
recommended list form, the string-as-single-executable behavior, and the
two ways to coerce a string into argv tokens (shlex.split or shell=True).
Copy link
Copy Markdown
Member

@Byron Byron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@Byron Byron merged commit 7b83f7a into gitpython-developers:main May 7, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants