René's URL Explorer Experiment


Title: Git.refresh GitCommandNotFound indicates "git" even for other commands · Issue #1809 · gitpython-developers/GitPython · GitHub

Open Graph Title: Git.refresh GitCommandNotFound indicates "git" even for other commands · Issue #1809 · gitpython-developers/GitPython

X Title: Git.refresh GitCommandNotFound indicates "git" even for other commands · Issue #1809 · gitpython-developers/GitPython

Description: The bug Even when the Git command that Git.refresh runs and checks is not git, its command line is reported as git in the GitCommandNotFound exception, when such an exception is raised: GitPython/git/cmd.py Lines 483 to 485 in d28c20b # ...

Open Graph Description: The bug Even when the Git command that Git.refresh runs and checks is not git, its command line is reported as git in the GitCommandNotFound exception, when such an exception is raised: GitPython/g...

X Description: The bug Even when the Git command that Git.refresh runs and checks is not git, its command line is reported as git in the GitCommandNotFound exception, when such an exception is raised: GitPython/g...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Git.refresh GitCommandNotFound indicates \"git\" even for other commands","articleBody":"### The bug\r\n\r\nEven when the Git command that `Git.refresh` runs and checks is not `git`, its command line is reported as `git` in the `GitCommandNotFound` exception, when such an exception is raised:\r\n\r\nhttps://github.com/gitpython-developers/GitPython/blob/d28c20b1dbf18dc60a2b1859e818801bd8d742f2/git/cmd.py#L483-L485\r\n\r\n### Steps to reproduce\r\n\r\nThe effect happens when the exception is raised due to a subsequent call to `Git.refresh`, since that is when `Git.refresh` raises `GitCommandNotFound` rather than `ImportError`. The `command` attribute is directly part of the traceback message, presented as `cmdline`. This can be produced by running a shell one-liner:\r\n\r\n```text\r\n$ GIT_PYTHON_GIT_EXECUTABLE=git-2.43 GIT_PYTHON_REFRESH=quiet python -c 'import git; git.refresh()'\r\nTraceback (most recent call last):\r\n  File \"\u003cstring\u003e\", line 1, in \u003cmodule\u003e\r\n  File \"/home/ek/repos-wsl/GitPython/git/__init__.py\", line 127, in refresh\r\n    if not Git.refresh(path=path):\r\n           ^^^^^^^^^^^^^^^^^^^^^^\r\n  File \"/home/ek/repos-wsl/GitPython/git/cmd.py\", line 485, in refresh\r\n    raise GitCommandNotFound(\"git\", err)\r\ngit.exc.GitCommandNotFound: Cmd('git') not found due to: 'Bad git executable.\r\nThe git executable must be specified in one of the following ways:\r\n    - be included in your $PATH\r\n    - be set via $GIT_PYTHON_GIT_EXECUTABLE\r\n    - explicitly set via git.refresh()\r\n'\r\n  cmdline: git\r\n```\r\n\r\nAlthough often a custom Git command may be a full path whose last component is exactly `git` (or sometimes `git.exe` on Windows), the above shows a realistic scenario in which even that may not be the case. I do not have a command named `git-2.43` installed, so it is correct that I get an error, but the error should not state the name of the command as `git`.\r\n\r\n### Verification\r\n\r\nVerbose debugging confirms that the command given in `GIT_PYTHON_GIT_EXECUTABLE` really is running, and that the only problem is that the hard-coded command name `git` is printed instead:\r\n\r\n```text\r\n$ GIT_PYTHON_GIT_EXECUTABLE=git-2.43 GIT_PYTHON_REFRESH=quiet GIT_PYTHON_TRACE=full python -c 'import logging; logging.basicConfig(level=logging.DEBUG); import git; git.refresh()'\r\nDEBUG:git.cmd:Popen(['git-2.43', 'version'], cwd=/home/ek/repos-wsl/GitPython, stdin=None, shell=False, universal_newlines=False)\r\nDEBUG:git.cmd:Popen(['git-2.43', 'version'], cwd=/home/ek/repos-wsl/GitPython, stdin=None, shell=False, universal_newlines=False)\r\nTraceback (most recent call last):\r\n  ...\r\n  cmdline: git\r\n```\r\n\r\nCapturing the `subprocess.Popen` [audit event](https://docs.python.org/3/library/audit_events.html) verifies that no other logging bug in GitPython is confusing the analysis:\r\n\r\n```text\r\n$ GIT_PYTHON_GIT_EXECUTABLE=git-2.43 GIT_PYTHON_REFRESH=quiet python -c 'import sys, git; sys.addaudithook(lambda event, args: event == \"subprocess.Popen\" and print(args[:2])); git.refresh()'\r\n('git-2.43', ['git-2.43', 'version'])\r\nTraceback (most recent call last):\r\n  ...\r\n  cmdline: git\r\n```\r\n\r\n(For both the above runs, I replaced most of the traceback with `...`.)\r\n\r\n### Why this is a bug\r\n\r\nSince it's possible, however unlikely, that someone has come to rely on the exception object's `command` attribute having the exact value `\"git\"` in this situation, it should *arguably* only be changed if it really is a bug for it to hold that value.\r\n\r\nI believe it is a bug, for three reasons:\r\n\r\n#### 1. It is presented as the command line\r\n\r\nWhen users see this in the `GitCommandNotFound` exception message, I believe they will assume it is the command that was run:\r\n\r\n```text\r\n  cmdline: git\r\n```\r\n\r\n#### 2. It differs from any other `GitCommandNotFound`\r\n\r\nIn other situations that raise `GitCommandNotFound`, it comes from `Git.execute`, and the exception is constructed with the actual command line as `command` (except that redactions are performed, such as for passwords):\r\n\r\nhttps://github.com/gitpython-developers/GitPython/blob/d28c20b1dbf18dc60a2b1859e818801bd8d742f2/git/cmd.py#L1065-L1079\r\n\r\n#### 3. The superclass documents the `command` argument\r\n\r\n`GitCommandNotFound` inherits its `command` attribute from its `CommandError` superclass. Although `CommandError` does not document the `command` attribute directly, it does document the `command` argument from which the value of that attribute is derived:\r\n\r\nhttps://github.com/gitpython-developers/GitPython/blob/d28c20b1dbf18dc60a2b1859e818801bd8d742f2/git/exc.py#L83-L88\r\n\r\nThis does not really guarantee the specific meaning of the `command` *attribute*. (Likskov substitutability is usually a goal for objects that have already been constructed/initialized; subclass `__new__` and `__init__` are not expected to treat arguments the same ways as the superclass.) But it is a further reason to consider the current behavior in `Git.refresh` unexpected.\r\n\r\n### Possible fixes\r\n\r\nThis could be fixed by having `Git.refresh` construct the `GitCommandNotFoundError` with the same command line that its `cls().version()` call causes `Git.execute` to use, which is given by `GIT_PYTHON_GIT_EXECUTABLE`.\r\n\r\nAnother approach, though, would be to keep a reference to the `GitCommandNotFound` exception that occurred occurred due to running `cls().version()`:\r\n\r\nhttps://github.com/gitpython-developers/GitPython/blob/d28c20b1dbf18dc60a2b1859e818801bd8d742f2/git/cmd.py#L381-L385\r\n\r\nThen that same exception object, with its original information, could be reraised instead of constructing and raising a new `GitCommandNotFound` object.\r\n\r\nIf this is to be done, then some refactoring may be in order, and a decision about whether that `GitCommandNotFound` object should be used as the `cause` of an `ImportError` in the case that is raised should probably also be made:\r\n\r\nhttps://github.com/gitpython-developers/GitPython/blob/d28c20b1dbf18dc60a2b1859e818801bd8d742f2/git/cmd.py#L476\r\n\r\nThus, in addition to the other changes, that statement could be changed to the `raise ... from ...` form.\r\n\r\nThere may be reasons to avoid this approach, in whole or in part, that I am not aware of.","author":{"url":"https://github.com/EliahKagan","@type":"Person","name":"EliahKagan"},"datePublished":"2024-01-24T03:25:48.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/1809/GitPython/issues/1809"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:db6cf206-aaff-fcd5-11fc-ab40b5e162cd
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idDA64:1F7343:475A1C:637398:6968B8E1
html-safe-nonce0e21656ba216cddf8886062d23993e1d5dbde4d5c442de79abeb3df9865b315c
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQTY0OjFGNzM0Mzo0NzVBMUM6NjM3Mzk4OjY5NjhCOEUxIiwidmlzaXRvcl9pZCI6IjU5NzM5NzM5NjkxNjMzMDMxMzciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmaca5fc495312a4d1c298cd66091d64675569d9aaae062effd484c2b287f47c7d0c
hovercard-subject-tagissue:2097348917
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/1809/issue_layout
twitter:imagehttps://opengraph.githubassets.com/ffcbaf7269d4782b60b5e4d93ff8628ff7b2bd0938ac1035d796b2c69fc76d30/gitpython-developers/GitPython/issues/1809
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/ffcbaf7269d4782b60b5e4d93ff8628ff7b2bd0938ac1035d796b2c69fc76d30/gitpython-developers/GitPython/issues/1809
og:image:altThe bug Even when the Git command that Git.refresh runs and checks is not git, its command line is reported as git in the GitCommandNotFound exception, when such an exception is raised: GitPython/g...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameEliahKagan
hostnamegithub.com
expected-hostnamegithub.com
Nonefdc7c66bd36a6c12eb8e771e806db863266e573fc299e77f27505a768d4f8a98
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
release3223a6503d318917691422cdadfbe16cd8fb21e5
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/gitpython-developers/GitPython/issues/1809#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgitpython-developers%2FGitPython%2Fissues%2F1809
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%2F1809
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/1809
Reloadhttps://github.com/gitpython-developers/GitPython/issues/1809
Reloadhttps://github.com/gitpython-developers/GitPython/issues/1809
gitpython-developers https://github.com/gitpython-developers
GitPythonhttps://github.com/gitpython-developers/GitPython
Please reload this pagehttps://github.com/gitpython-developers/GitPython/issues/1809
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/1809
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/1809
New issuehttps://github.com/login?return_to=https://github.com/gitpython-developers/GitPython/issues/1809
#1812https://github.com/gitpython-developers/GitPython/pull/1812
Git.refresh GitCommandNotFound indicates "git" even for other commandshttps://github.com/gitpython-developers/GitPython/issues/1809#top
#1812https://github.com/gitpython-developers/GitPython/pull/1812
acknowledgedhttps://github.com/gitpython-developers/GitPython/issues?q=state%3Aopen%20label%3A%22acknowledged%22
help wantedhttps://github.com/gitpython-developers/GitPython/issues?q=state%3Aopen%20label%3A%22help%20wanted%22
https://github.com/EliahKagan
https://github.com/EliahKagan
EliahKaganhttps://github.com/EliahKagan
on Jan 24, 2024https://github.com/gitpython-developers/GitPython/issues/1809#issue-2097348917
GitPython/git/cmd.pyhttps://github.com/gitpython-developers/GitPython/blob/d28c20b1dbf18dc60a2b1859e818801bd8d742f2/git/cmd.py#L483-L485
d28c20bhttps://github.com/gitpython-developers/GitPython/commit/d28c20b1dbf18dc60a2b1859e818801bd8d742f2
audit eventhttps://docs.python.org/3/library/audit_events.html
GitPython/git/cmd.pyhttps://github.com/gitpython-developers/GitPython/blob/d28c20b1dbf18dc60a2b1859e818801bd8d742f2/git/cmd.py#L1065-L1079
d28c20bhttps://github.com/gitpython-developers/GitPython/commit/d28c20b1dbf18dc60a2b1859e818801bd8d742f2
GitPython/git/exc.pyhttps://github.com/gitpython-developers/GitPython/blob/d28c20b1dbf18dc60a2b1859e818801bd8d742f2/git/exc.py#L83-L88
d28c20bhttps://github.com/gitpython-developers/GitPython/commit/d28c20b1dbf18dc60a2b1859e818801bd8d742f2
GitPython/git/cmd.pyhttps://github.com/gitpython-developers/GitPython/blob/d28c20b1dbf18dc60a2b1859e818801bd8d742f2/git/cmd.py#L381-L385
d28c20bhttps://github.com/gitpython-developers/GitPython/commit/d28c20b1dbf18dc60a2b1859e818801bd8d742f2
GitPython/git/cmd.pyhttps://github.com/gitpython-developers/GitPython/blob/d28c20b1dbf18dc60a2b1859e818801bd8d742f2/git/cmd.py#L476
d28c20bhttps://github.com/gitpython-developers/GitPython/commit/d28c20b1dbf18dc60a2b1859e818801bd8d742f2
acknowledgedhttps://github.com/gitpython-developers/GitPython/issues?q=state%3Aopen%20label%3A%22acknowledged%22
help wantedhttps://github.com/gitpython-developers/GitPython/issues?q=state%3Aopen%20label%3A%22help%20wanted%22
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.