Skip to content

git.cmd.Git.execute(..): fix with_stdout=False#2126

Open
ngie-eign wants to merge 2 commits intogitpython-developers:mainfrom
ngie-eign:fix-execute-with_stdout-no-issues
Open

git.cmd.Git.execute(..): fix with_stdout=False#2126
ngie-eign wants to merge 2 commits intogitpython-developers:mainfrom
ngie-eign:fix-execute-with_stdout-no-issues

Conversation

@ngie-eign
Copy link
Copy Markdown

In the event the end-user called one of the APIs with with_stdout=False, i.e., they didn't want to capture stdout, the code would crash with an AttributeError or ValueError when trying to dereference the stdout/stderr streams attached to Popen(..) objects.

Be more defensive by checking the streams first to make sure they're not None before trying to access their corresponding attributes.

Add myself to AUTHORS and add corresponding regression tests for the change.

In the event the end-user called one of the APIs with
`with_stdout=False`, i.e., they didn't want to capture stdout, the code
would crash with an AttributeError or ValueError when trying to
dereference the stdout/stderr streams attached to `Popen(..)` objects.

Be more defensive by checking the streams first to make sure they're not
`None` before trying to access their corresponding attributes.

Add myself to AUTHORS and add corresponding regression tests for the
change.

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
@ngie-eign ngie-eign force-pushed the fix-execute-with_stdout-no-issues branch 3 times, most recently from d3d587c to a64bde9 Compare April 17, 2026 17:04
@Byron Byron requested a review from Copilot April 18, 2026 02:53
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.

Thanks a lot. This looks good to me.

If the machine doesn't find anything horrendous, we can merge this.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes Git.execute(..., with_stdout=False) crashing when stdout/stderr streams are None, and adds regression coverage to prevent future regressions.

Changes:

  • Make Git.execute() defensive against None stdout/stderr streams when stripping newlines, copying output, and closing handles.
  • Add regression tests for with_stdout=False scenarios (with and without output_stream).
  • Add contributor entry to AUTHORS and improve test cleanup robustness in rmtree tests.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
git/cmd.py Adds None checks around stdout/stderr usage to avoid crashes when stdout isn’t piped.
test/test_git.py Adds regression tests covering with_stdout=False behavior.
test/test_util.py Adds a pytest finalizer to ensure temp directories are cleaned up on platforms with stricter permissions.
AUTHORS Adds a new contributor entry.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/test_util.py Outdated
Comment thread git/cmd.py
Comment thread git/cmd.py
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.

Needs auto-review comments to be addressed.

@ngie-eign ngie-eign force-pushed the fix-execute-with_stdout-no-issues branch 2 times, most recently from 0ae13c9 to 335989f Compare April 18, 2026 16:44
@ngie-eign
Copy link
Copy Markdown
Author

@Byron : I tried dealing with the type hinting issues, but it turned into a lot of onion peeling... I would prefer to delay this for another PR (my WIP branch can be found here: https://github.com/ngie-eign/GitPython/tree/type-checking-rabbit-hole ).

Prior to this the test would fail [silently] on my macOS host during the
test and then pytest would complain loudly about it being an issue
post-session (regardless of whether or not the test was being run).

Squash the unwritable directory to mute noise complaints from pytest.

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
@ngie-eign ngie-eign force-pushed the fix-execute-with_stdout-no-issues branch from 335989f to 6fc4742 Compare April 18, 2026 16:49
@ngie-eign ngie-eign requested a review from Byron April 18, 2026 18:07
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.

3 participants