René's URL Explorer Experiment


Title: Git.execute treats shell=False the same as shell=None · Issue #1685 · gitpython-developers/GitPython · GitHub

Open Graph Title: Git.execute treats shell=False the same as shell=None · Issue #1685 · gitpython-developers/GitPython

X Title: Git.execute treats shell=False the same as shell=None · Issue #1685 · gitpython-developers/GitPython

Description: Expected behavior The intention in git.cmd.Git.execute is that when a bool value, True or False, is passed for shell, that value determines whether a shell is used, and that only if this argument is omitted or passed as None is the class...

Open Graph Description: Expected behavior The intention in git.cmd.Git.execute is that when a bool value, True or False, is passed for shell, that value determines whether a shell is used, and that only if this argument i...

X Description: Expected behavior The intention in git.cmd.Git.execute is that when a bool value, True or False, is passed for shell, that value determines whether a shell is used, and that only if this argument i...

Opengraph URL: https://github.com/gitpython-developers/GitPython/issues/1685

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Git.execute treats shell=False the same as shell=None","articleBody":"### Expected behavior\r\n\r\nThe *intention* in [`git.cmd.Git.execute`](https://github.com/gitpython-developers/GitPython/blob/7d4f6c68c657586f27125f25b15f02c5a3d7f35c/git/cmd.py#L827) is that when a `bool` value, `True` or `False`, is passed for `shell`, that value determines whether a shell is used, and that only if this argument is omitted or passed as `None` is the class or object's `USE_SHELL` attribute consulted:\r\n\r\nhttps://github.com/gitpython-developers/GitPython/blob/7d4f6c68c657586f27125f25b15f02c5a3d7f35c/git/cmd.py#L839\r\n\r\nhttps://github.com/gitpython-developers/GitPython/blob/7d4f6c68c657586f27125f25b15f02c5a3d7f35c/git/cmd.py#L903-L905\r\n\r\n### The logic error\r\n\r\nThis is the code [in the `Popen` call](https://github.com/gitpython-developers/GitPython/blob/7d4f6c68c657586f27125f25b15f02c5a3d7f35c/git/cmd.py#L987) that is intended to implement that documented logic:\r\n\r\nhttps://github.com/gitpython-developers/GitPython/blob/7d4f6c68c657586f27125f25b15f02c5a3d7f35c/git/cmd.py#L995\r\n\r\n`shell is not None and shell or self.USE_SHELL` is intended to mean `self.USE_SHELL if shell is None else shell` (which could also be written `shell if shell is not None else self.USE_SHELL`). But it actually means `shell or self.USE_SHELL`:\r\n\r\n```python\r\n\u003e\u003e\u003e def ternary_truth_table(f):\r\n...     return {(p, q): f(p, q) for p in (True, False, None) for q in (True, False, None)}\r\n...\r\n\u003e\u003e\u003e table1 = ternary_truth_table(lambda p, q: p is not None and p or q)\r\n\u003e\u003e\u003e table2 = ternary_truth_table(lambda p, q: p or q)\r\n\u003e\u003e\u003e table1 == table2\r\nTrue\r\n\u003e\u003e\u003e table1\r\n{(True, True): True, (True, False): True, (True, None): True, (False, True): True, (False, False): False, (False, None): None, (None, True): True, (None, False): False, (None, None): None}\r\n```\r\n\r\n(This resembles the [`type(z)==types.ComplexType and z.real or z`](https://mail.python.org/pipermail/python-dev/2005-September/056510.html) problem that [led to the adoption of conditional expressions](https://peps.python.org/pep-0308/#id5).)\r\n\r\n### Possible fix\r\n\r\nI would *like* to fix this by doing:\r\n\r\n```diff\r\n-                    shell=shell is not None and shell or self.USE_SHELL,\r\n+                    shell=self.USE_SHELL if shell is None else shell,\r\n```\r\n\r\nOr, perhaps even more clearly:\r\n\r\n```diff\r\n+        if shell is None:\r\n+            shell = self.USE_SHELL\r\n...\r\n-                    shell=shell is not None and shell or self.USE_SHELL,\r\n+                    shell=shell,\r\n```\r\n\r\n### Could users be relying on the current (wrong) behavior?\r\n\r\nOn the surface that seems okay. The problem only happens when `USE_SHELL` is `True`. The class attribute `USE_SHELL` is set to `False` by default. It is named as a constant so, unless documented otherwise, it should really only be set during initialization, or by being monkey-patched inside GitPython's own tests. So it's tempting to think nobody should be relying on what happens if they change it.\r\n\r\nExcept... setting it from outside GitPython *is* documented. In the changelog entry for [0.3.7](https://github.com/gitpython-developers/GitPython/blob/7d4f6c68c657586f27125f25b15f02c5a3d7f35c/doc/source/changes.rst?plain=1#L669-L684):\r\n\r\nhttps://github.com/gitpython-developers/GitPython/blob/7d4f6c68c657586f27125f25b15f02c5a3d7f35c/doc/source/changes.rst?plain=1#L679-L682\r\n\r\nThis is [elaborated](https://github.com/gitpython-developers/GitPython/compare/0.3.6...0.3.7#diff-35a18a749eb4d6efad45e56e78a9554926be5526e2ba2159b44311e718450e88) at the `USE_SHELL` class attribute definition:\r\n\r\nhttps://github.com/gitpython-developers/GitPython/blob/7d4f6c68c657586f27125f25b15f02c5a3d7f35c/git/cmd.py#L282-L286\r\n\r\n### The `pythonw` use case\r\n\r\nIn #126, a default of `shell=True` had been introduced to fix a bug on Windows where console windows would flash on the screen for `git` commands, when using the `pythonw` interpreter executable (selected to open `.pyw` files on Windows):\r\n\r\n\u003e The GitPython module works great, but when called from a windowless script (.pyw) each command spawns a console window. Those windows are empty and last only a second, but I think they should not be there at all.\r\n\u003e\r\n\u003e I saw it was using `Popen` to call the `git` executable and added a `shell=True` parameter to avoid spawning those windows.\r\n\r\nI don't know if that is in practice ever still an issue or not. On my Windows 10 system, I created a Python 3.7.9 virtual environment (since 3.7 is the lowest version GitPython currently supports), installing GitPython in it, running IDLE in it using `pythonw -m idlelib.idle`, and in IDLE, running statements such as `import git` and `git.Git().execute(\"git version\")`. No console window was created. However, it may be that this particular manual test is flawed, as IDLE, being a REPL, must be handling standard streams in a way that most other `.pyw` applications aren't. Nonetheless, the unwanted window creation seems like it should only have happened due to a bug in Python or Windows. But I am not sure.\r\n\r\n### Impact of a fix?\r\n\r\nMy concern is that existing software may be inadvertently relying on `Git.USE_SHELL` taking precedence over the optional `shell` keyword argument to the `Git.execute` method or to any function that forwards that argument to that method.\r\n\r\nI believe this should be fixed, because applications that build on GitPython should be able to rely on documented claims about when shells are used to create subprocesses. But I am unsure if there is anything that should be documented or warned about, or taken account in deciding exactly how to fix this and how, if at all, the impact of the fix should be documented in the changelog or elsewhere.\r\n\r\nI've proposed a fix, along the lines of those I suggested above, in #1687. But I wanted to open an issue to explore this, in case that fix is unsatisfactory, requires refinements, or has obscure effects (perhaps even only in cases that GitPython is used incorrectly) that people might find this by searching about.","author":{"url":"https://github.com/EliahKagan","@type":"Person","name":"EliahKagan"},"datePublished":"2023-10-02T09:20:12.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/1685/GitPython/issues/1685"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:7221e3fb-2e3d-c6d1-4308-167031d0facb
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idA5F2:3E5583:1FCFF:2B2DB:696844B7
html-safe-noncedf7755628f80e4f285462737c11f040e867f2f634036fc8c05cd01e670e7489e
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNUYyOjNFNTU4MzoxRkNGRjoyQjJEQjo2OTY4NDRCNyIsInZpc2l0b3JfaWQiOiIyOTQxMDQwNDgxODk1MjA0MDIzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac3f3e603122ab68c924e7fbc4736534c1352416c20742c99d86272b470629e938
hovercard-subject-tagissue:1921546496
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/gitpython-developers/GitPython/1685/issue_layout
twitter:imagehttps://opengraph.githubassets.com/cdb45d358d805b67eef36380d8cd9d92d0f6c56a33fd12160bee230104e297bc/gitpython-developers/GitPython/issues/1685
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/cdb45d358d805b67eef36380d8cd9d92d0f6c56a33fd12160bee230104e297bc/gitpython-developers/GitPython/issues/1685
og:image:altExpected behavior The intention in git.cmd.Git.execute is that when a bool value, True or False, is passed for shell, that value determines whether a shell is used, and that only if this argument i...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameEliahKagan
hostnamegithub.com
expected-hostnamegithub.com
Nonef16c57f41ed243e5b4dfe9b9bcd6828bd83080b1b6dbb4ff239bbe9745f12e0c
turbo-cache-controlno-preview
go-importgithub.com/gitpython-developers/GitPython git https://github.com/gitpython-developers/GitPython.git
octolytics-dimension-user_id503709
octolytics-dimension-user_logingitpython-developers
octolytics-dimension-repository_id1126087
octolytics-dimension-repository_nwogitpython-developers/GitPython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id1126087
octolytics-dimension-repository_network_root_nwogitpython-developers/GitPython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasecfa7062cc6d4fe8fcb156bd33f4c97bd3b2470af
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/gitpython-developers/GitPython/issues/1685#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgitpython-developers%2FGitPython%2Fissues%2F1685
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgitpython-developers%2FGitPython%2Fissues%2F1685
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=gitpython-developers%2FGitPython
Reloadhttps://github.com/gitpython-developers/GitPython/issues/1685
Reloadhttps://github.com/gitpython-developers/GitPython/issues/1685
Reloadhttps://github.com/gitpython-developers/GitPython/issues/1685
gitpython-developers https://github.com/gitpython-developers
GitPythonhttps://github.com/gitpython-developers/GitPython
Please reload this pagehttps://github.com/gitpython-developers/GitPython/issues/1685
Notifications https://github.com/login?return_to=%2Fgitpython-developers%2FGitPython
Fork 964 https://github.com/login?return_to=%2Fgitpython-developers%2FGitPython
Star 5k https://github.com/login?return_to=%2Fgitpython-developers%2FGitPython
Code https://github.com/gitpython-developers/GitPython
Issues 169 https://github.com/gitpython-developers/GitPython/issues
Pull requests 8 https://github.com/gitpython-developers/GitPython/pulls
Discussions https://github.com/gitpython-developers/GitPython/discussions
Actions https://github.com/gitpython-developers/GitPython/actions
Security Uh oh! There was an error while loading. Please reload this page. https://github.com/gitpython-developers/GitPython/security
Please reload this pagehttps://github.com/gitpython-developers/GitPython/issues/1685
Insights https://github.com/gitpython-developers/GitPython/pulse
Code https://github.com/gitpython-developers/GitPython
Issues https://github.com/gitpython-developers/GitPython/issues
Pull requests https://github.com/gitpython-developers/GitPython/pulls
Discussions https://github.com/gitpython-developers/GitPython/discussions
Actions https://github.com/gitpython-developers/GitPython/actions
Security https://github.com/gitpython-developers/GitPython/security
Insights https://github.com/gitpython-developers/GitPython/pulse
New issuehttps://github.com/login?return_to=https://github.com/gitpython-developers/GitPython/issues/1685
New issuehttps://github.com/login?return_to=https://github.com/gitpython-developers/GitPython/issues/1685
#1687https://github.com/gitpython-developers/GitPython/pull/1687
Git.execute treats shell=False the same as shell=Nonehttps://github.com/gitpython-developers/GitPython/issues/1685#top
#1687https://github.com/gitpython-developers/GitPython/pull/1687
v3.1.38 - Bugfixeshttps://github.com/gitpython-developers/GitPython/milestone/68
https://github.com/EliahKagan
https://github.com/EliahKagan
EliahKaganhttps://github.com/EliahKagan
on Oct 2, 2023https://github.com/gitpython-developers/GitPython/issues/1685#issue-1921546496
git.cmd.Git.executehttps://github.com/gitpython-developers/GitPython/blob/7d4f6c68c657586f27125f25b15f02c5a3d7f35c/git/cmd.py#L827
GitPython/git/cmd.pyhttps://github.com/gitpython-developers/GitPython/blob/7d4f6c68c657586f27125f25b15f02c5a3d7f35c/git/cmd.py#L839
7d4f6c6https://github.com/gitpython-developers/GitPython/commit/7d4f6c68c657586f27125f25b15f02c5a3d7f35c
GitPython/git/cmd.pyhttps://github.com/gitpython-developers/GitPython/blob/7d4f6c68c657586f27125f25b15f02c5a3d7f35c/git/cmd.py#L903-L905
7d4f6c6https://github.com/gitpython-developers/GitPython/commit/7d4f6c68c657586f27125f25b15f02c5a3d7f35c
in the Popen callhttps://github.com/gitpython-developers/GitPython/blob/7d4f6c68c657586f27125f25b15f02c5a3d7f35c/git/cmd.py#L987
GitPython/git/cmd.pyhttps://github.com/gitpython-developers/GitPython/blob/7d4f6c68c657586f27125f25b15f02c5a3d7f35c/git/cmd.py#L995
7d4f6c6https://github.com/gitpython-developers/GitPython/commit/7d4f6c68c657586f27125f25b15f02c5a3d7f35c
type(z)==types.ComplexType and z.real or zhttps://mail.python.org/pipermail/python-dev/2005-September/056510.html
led to the adoption of conditional expressionshttps://peps.python.org/pep-0308/#id5
0.3.7https://github.com/gitpython-developers/GitPython/blob/7d4f6c68c657586f27125f25b15f02c5a3d7f35c/doc/source/changes.rst?plain=1#L669-L684
GitPython/doc/source/changes.rsthttps://github.com/gitpython-developers/GitPython/blob/7d4f6c68c657586f27125f25b15f02c5a3d7f35c/doc/source/changes.rst?plain=1#L679-L682
7d4f6c6https://github.com/gitpython-developers/GitPython/commit/7d4f6c68c657586f27125f25b15f02c5a3d7f35c
elaboratedhttps://github.com/gitpython-developers/GitPython/compare/0.3.6...0.3.7#diff-35a18a749eb4d6efad45e56e78a9554926be5526e2ba2159b44311e718450e88
GitPython/git/cmd.pyhttps://github.com/gitpython-developers/GitPython/blob/7d4f6c68c657586f27125f25b15f02c5a3d7f35c/git/cmd.py#L282-L286
7d4f6c6https://github.com/gitpython-developers/GitPython/commit/7d4f6c68c657586f27125f25b15f02c5a3d7f35c
#126https://github.com/gitpython-developers/GitPython/pull/126
#1687https://github.com/gitpython-developers/GitPython/pull/1687
v3.1.38 - Bugfixeshttps://github.com/gitpython-developers/GitPython/milestone/68
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.