René's URL Explorer Experiment


Title: Commit_ish is much broader than commit-ish · Issue #1858 · gitpython-developers/GitPython · GitHub

Open Graph Title: Commit_ish is much broader than commit-ish · Issue #1858 · gitpython-developers/GitPython

X Title: Commit_ish is much broader than commit-ish · Issue #1858 · gitpython-developers/GitPython

Description: In git, if I understand correctly, a commit-ish is a git object from which a commit can be reached by dereferencing it zero or more times, which is to say that all commits are commit-ish, some tag objects are commit-ish--those that, thro...

Open Graph Description: In git, if I understand correctly, a commit-ish is a git object from which a commit can be reached by dereferencing it zero or more times, which is to say that all commits are commit-ish, some tag ...

X Description: In git, if I understand correctly, a commit-ish is a git object from which a commit can be reached by dereferencing it zero or more times, which is to say that all commits are commit-ish, some tag ...

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

X: @github

direct link

Domain: redirect.github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Commit_ish is much broader than commit-ish","articleBody":"In git, if I understand correctly, a *commit-ish* is a git object from which a commit can be reached by dereferencing it zero or more times, which is to say that all commits are commit-ish, some tag objects are commit-ish--those that, through (possibly repeated) dereferencing, eventually reach a commit--and no other types of git objects are ever commit-ish.\r\n\r\nAs [gitglossary(7) says](https://git-scm.com/docs/gitglossary#def_commit-ish):\r\n\r\n\u003e #### commit-ish (also committish)\r\n\u003e\r\n\u003e A [commit object](https://git-scm.com/docs/gitglossary#def_commit_object) or an [object](https://git-scm.com/docs/gitglossary#def_object) that can be recursively [dereferenced](https://git-scm.com/docs/gitglossary#def_dereference) to a commit object. The following are all commit-ishes: a commit object, a [tag object](https://git-scm.com/docs/gitglossary#def_tag_object) that points to a commit object, a tag object that points to a tag object that points to a commit object, etc.\r\n\r\nTherefore, *all* instances of GitPython's `Commit` class, and *some* instances of GitPython's `TagObject` class, encapsulate git objects that are actually commit-ish.\r\n\r\nBut GitPython has a `Commit_ish` union type in the `git.types` module, and that `Commit_ish` type is considerably broader:\r\n\r\nhttps://github.com/gitpython-developers/GitPython/blob/b2c3d8b72301dc4723e83de676fd7086d5c3c381/git/types.py#L53\r\n\r\nThese four classes are the GitPython classes whose instances encapsulate any of the [four types of git objects](https://git-scm.com/docs/gitglossary#def_object_type) (of which blobs and trees are never actually commit-ish):\r\n\r\n\u003e #### object type\r\n\u003e\r\n\u003e One of the identifiers \"[commit](https://git-scm.com/docs/gitglossary#def_commit_object)\", \"[tree](https://git-scm.com/docs/gitglossary#def_tree_object)\", \"[tag](https://git-scm.com/docs/gitglossary#def_tag_object)\" or \"[blob](https://git-scm.com/docs/gitglossary#def_blob_object)\" describing the type of an [object](https://git-scm.com/docs/gitglossary#def_object).\r\n\r\nGitPython uses its `Commit_ish` type in accordance with this much broader concept, at least some of the time and possibly always. For example, `Commit_ish` is given as the return type of `Object.new`:\r\n\r\nhttps://github.com/gitpython-developers/GitPython/blob/b2c3d8b72301dc4723e83de676fd7086d5c3c381/git/objects/base.py#L77-L78\r\n\r\n`Commit_ish` cannot simply be replaced by `Object` because GitPython's `Object` class is also, through `IndexObject`, a superclass of `Submodule` (and the `RootModule` subclass of `Submodule`):\r\n\r\nhttps://github.com/gitpython-developers/GitPython/blob/b2c3d8b72301dc4723e83de676fd7086d5c3c381/git/objects/submodule/base.py#L82\r\n\r\nhttps://github.com/gitpython-developers/GitPython/blob/b2c3d8b72301dc4723e83de676fd7086d5c3c381/git/objects/submodule/base.py#L87-L88\r\n\r\nhttps://github.com/gitpython-developers/GitPython/blob/b2c3d8b72301dc4723e83de676fd7086d5c3c381/git/objects/submodule/base.py#L100-L101\r\n\r\nHowever, elsewhere in GitPython, `Commit_ish` is used where it seems only a commit is intended to be allowed, though it is unclear if this is unintentional, intentional but only to allow type checkers to allow some code that can only reasonably be checked at runtime, or intentional for some other reason. For example, the `Repo.commit` method, when called with one argument, looks up a commit in the repository it represents from a `Commit_ish` or string, and returns the commit it finds as a `Commit`:\r\n\r\nhttps://github.com/gitpython-developers/GitPython/blob/b2c3d8b72301dc4723e83de676fd7086d5c3c381/git/repo/base.py#L698\r\n\r\nThis leads to a situation where one can write code that type checkers allow and that may appear intended to work, but that always fails, and in a way that may be unclear to users less familiar with git concepts:\r\n\r\n```text\r\n\u003e\u003e\u003e import git\r\n\u003e\u003e\u003e repo = git.Repo()\r\n\u003e\u003e\u003e tree = repo.tree()\r\n\u003e\u003e\u003e repo.commit(tree)\r\nTraceback (most recent call last):\r\n  File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\r\n  File \"C:\\Users\\ek\\source\\repos\\GitPython\\git\\repo\\base.py\", line 709, in commit\r\n    return self.rev_parse(str(rev) + \"^0\")\r\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n  File \"C:\\Users\\ek\\source\\repos\\GitPython\\git\\repo\\fun.py\", line 379, in rev_parse\r\n    obj = to_commit(obj)\r\n          ^^^^^^^^^^^^^^\r\n  File \"C:\\Users\\ek\\source\\repos\\GitPython\\git\\repo\\fun.py\", line 221, in to_commit\r\n    raise ValueError(\"Cannot convert object %r to type commit\" % obj)\r\nValueError: Cannot convert object \u003cgit.Tree \"d5538cc6cc8839ccb0168baf9f98aebcedfd9c2c\"\u003e to type commit\r\n```\r\n\r\nAn argument that this specific situation with `Repo.commit` is not a typing bug is that this operation is fundamentally one that can only be checked at runtime in some cases. After all, an argument of type `str` is also allowed and it cannot known until runtime what object a string happens to name. Even so, the method docstring should possibly be expanded to clarify this issue. Or perhaps if the situation with `Commit_ish` is improved, then the potential for confusion will go away.\r\n\r\nOne way to improve this situation is to clearly document it in a docstring for the `Commit_ish` type. But if possible it seems to me that more should be done:\r\n\r\n- If known, the reason for the current situation should be stated there.\r\n- Its relationship to other types should be clarified where otherwise confusing. For example, `Object` may benefit from greater clarity about what it ideally represents (git objects) versus the entirety of what it represents (that an `Object` can also be a `Submodule`), and the way that `Tree_ish` is narrower than all tree-ish git objects while `Commit_ish` is broader than all commit-ish git objects can be noted in one of their docstrings.\r\n- Maybe `Commit_ish` should be deprecated and one or more new types introduced, replacing all uses of it in GitPython.\r\n\r\nIf I am making a fundamental mistake about git concepts here, and GitPython's `Commit_ish` has a closer and more intuitive relationship to commit-ish git objects than I think it does, then I apologize.\r\n\r\nI have not figured out very much from GitPython's revision history what the reason for defining `Commit_ish` as it is currently defined is, or alternatively why this union of all four actual git object types was introduced with the narrower-seeming name `Commit_ish`. However, the `Commit_ish` type was introduced in 82b131c (#1282), where the annotations it was used to replace had listed all four types `Commit`, `TagObject`, `Tree`, and `Blob` as explicit alternatives.","author":{"url":"https://github.com/EliahKagan","@type":"Person","name":"EliahKagan"},"datePublished":"2024-03-04T21:16:42.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/1858/GitPython/issues/1858"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:6fff2df1-62fa-7aab-1c18-f4389bf7ebbd
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idA1AE:B510C:2C20E98:3DC9E76:69692BDA
html-safe-nonce07b53bcd33f0b6556c85db6c13a802845a969f1cd8b10ae55b9aac323cfeace0
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMUFFOkI1MTBDOjJDMjBFOTg6M0RDOUU3Njo2OTY5MkJEQSIsInZpc2l0b3JfaWQiOiIxNDI3MTI1NjYxNzk5NjIzNjQyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac17e6d9770cd37ee1bbde64aae4a9e130b94bb9966c1d2dc870f51a52e67a4bd8
hovercard-subject-tagissue:2167774773
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/1858/issue_layout
twitter:imagehttps://opengraph.githubassets.com/6fc52ff322099ca13ec495e2c0347e89047fb209efa2ef93742c9ba77645a6e7/gitpython-developers/GitPython/issues/1858
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/6fc52ff322099ca13ec495e2c0347e89047fb209efa2ef93742c9ba77645a6e7/gitpython-developers/GitPython/issues/1858
og:image:altIn git, if I understand correctly, a commit-ish is a git object from which a commit can be reached by dereferencing it zero or more times, which is to say that all commits are commit-ish, some tag ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameEliahKagan
hostnamegithub.com
expected-hostnamegithub.com
None54182691a21263b584d2e600b758e081b0ff1d10ffc0d2eefa51cf754b43b51d
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
released69ac0477df0f87da03b8b06cebd187012d7a930
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://redirect.github.com/gitpython-developers/GitPython/issues/1858#start-of-content
https://redirect.github.com/
Sign in https://redirect.github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgitpython-developers%2FGitPython%2Fissues%2F1858
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://redirect.github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgitpython-developers%2FGitPython%2Fissues%2F1858
Sign up https://redirect.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://redirect.github.com/gitpython-developers/GitPython/issues/1858
Reloadhttps://redirect.github.com/gitpython-developers/GitPython/issues/1858
Reloadhttps://redirect.github.com/gitpython-developers/GitPython/issues/1858
gitpython-developers https://redirect.github.com/gitpython-developers
GitPythonhttps://redirect.github.com/gitpython-developers/GitPython
Please reload this pagehttps://redirect.github.com/gitpython-developers/GitPython/issues/1858
Notifications https://redirect.github.com/login?return_to=%2Fgitpython-developers%2FGitPython
Fork 964 https://redirect.github.com/login?return_to=%2Fgitpython-developers%2FGitPython
Star 5k https://redirect.github.com/login?return_to=%2Fgitpython-developers%2FGitPython
Code https://redirect.github.com/gitpython-developers/GitPython
Issues 169 https://redirect.github.com/gitpython-developers/GitPython/issues
Pull requests 8 https://redirect.github.com/gitpython-developers/GitPython/pulls
Discussions https://redirect.github.com/gitpython-developers/GitPython/discussions
Actions https://redirect.github.com/gitpython-developers/GitPython/actions
Security Uh oh! There was an error while loading. Please reload this page. https://redirect.github.com/gitpython-developers/GitPython/security
Please reload this pagehttps://redirect.github.com/gitpython-developers/GitPython/issues/1858
Insights https://redirect.github.com/gitpython-developers/GitPython/pulse
Code https://redirect.github.com/gitpython-developers/GitPython
Issues https://redirect.github.com/gitpython-developers/GitPython/issues
Pull requests https://redirect.github.com/gitpython-developers/GitPython/pulls
Discussions https://redirect.github.com/gitpython-developers/GitPython/discussions
Actions https://redirect.github.com/gitpython-developers/GitPython/actions
Security https://redirect.github.com/gitpython-developers/GitPython/security
Insights https://redirect.github.com/gitpython-developers/GitPython/pulse
New issuehttps://redirect.github.com/login?return_to=https://github.com/gitpython-developers/GitPython/issues/1858
New issuehttps://redirect.github.com/login?return_to=https://github.com/gitpython-developers/GitPython/issues/1858
#1859https://github.com/gitpython-developers/GitPython/pull/1859
Commit_ish is much broader than commit-ishhttps://redirect.github.com/gitpython-developers/GitPython/issues/1858#top
#1859https://github.com/gitpython-developers/GitPython/pull/1859
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 Mar 4, 2024https://github.com/gitpython-developers/GitPython/issues/1858#issue-2167774773
gitglossary(7) sayshttps://git-scm.com/docs/gitglossary#def_commit-ish
commit objecthttps://git-scm.com/docs/gitglossary#def_commit_object
objecthttps://git-scm.com/docs/gitglossary#def_object
dereferencedhttps://git-scm.com/docs/gitglossary#def_dereference
tag objecthttps://git-scm.com/docs/gitglossary#def_tag_object
GitPython/git/types.pyhttps://github.com/gitpython-developers/GitPython/blob/b2c3d8b72301dc4723e83de676fd7086d5c3c381/git/types.py#L53
b2c3d8bhttps://redirect.github.com/gitpython-developers/GitPython/commit/b2c3d8b72301dc4723e83de676fd7086d5c3c381
four types of git objectshttps://git-scm.com/docs/gitglossary#def_object_type
commithttps://git-scm.com/docs/gitglossary#def_commit_object
treehttps://git-scm.com/docs/gitglossary#def_tree_object
taghttps://git-scm.com/docs/gitglossary#def_tag_object
blobhttps://git-scm.com/docs/gitglossary#def_blob_object
objecthttps://git-scm.com/docs/gitglossary#def_object
GitPython/git/objects/base.pyhttps://github.com/gitpython-developers/GitPython/blob/b2c3d8b72301dc4723e83de676fd7086d5c3c381/git/objects/base.py#L77-L78
b2c3d8bhttps://redirect.github.com/gitpython-developers/GitPython/commit/b2c3d8b72301dc4723e83de676fd7086d5c3c381
GitPython/git/objects/submodule/base.pyhttps://github.com/gitpython-developers/GitPython/blob/b2c3d8b72301dc4723e83de676fd7086d5c3c381/git/objects/submodule/base.py#L82
b2c3d8bhttps://redirect.github.com/gitpython-developers/GitPython/commit/b2c3d8b72301dc4723e83de676fd7086d5c3c381
GitPython/git/objects/submodule/base.pyhttps://github.com/gitpython-developers/GitPython/blob/b2c3d8b72301dc4723e83de676fd7086d5c3c381/git/objects/submodule/base.py#L87-L88
b2c3d8bhttps://redirect.github.com/gitpython-developers/GitPython/commit/b2c3d8b72301dc4723e83de676fd7086d5c3c381
GitPython/git/objects/submodule/base.pyhttps://github.com/gitpython-developers/GitPython/blob/b2c3d8b72301dc4723e83de676fd7086d5c3c381/git/objects/submodule/base.py#L100-L101
b2c3d8bhttps://redirect.github.com/gitpython-developers/GitPython/commit/b2c3d8b72301dc4723e83de676fd7086d5c3c381
GitPython/git/repo/base.pyhttps://github.com/gitpython-developers/GitPython/blob/b2c3d8b72301dc4723e83de676fd7086d5c3c381/git/repo/base.py#L698
b2c3d8bhttps://redirect.github.com/gitpython-developers/GitPython/commit/b2c3d8b72301dc4723e83de676fd7086d5c3c381
82b131chttps://github.com/gitpython-developers/GitPython/commit/82b131cf2afebbed3723df5b5dfd5cd820716f97
#1282https://github.com/gitpython-developers/GitPython/pull/1282
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.