docs(cmd): clarify Git.execute() string vs list command argument#2144
Merged
Byron merged 1 commit intogitpython-developers:mainfrom May 7, 2026
Merged
Conversation
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
Rewrites the
:param command:docstring onGit.execute()ingit/cmd.pyto 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: withshell=False(the default),subprocess.Popentreats the entire string as a single executable name, so"git log -n 1"looks for an executable literally named "git log -n 1" and raisesGitCommandNotFound.The new docstring:
["git", "log", "-n", "1"]) for the defaultshell=Falsecase.shell=False, with the exact failure mode users see in [Bug] GitCommandNotFound when executing repo.git.execute on macOS #2016.shlex.split(...)(sequence) orshell=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.Popensemantics 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.pyis clean. No tests were modified or broken.