Title: Fix 'Tree' object has no attribute '_name' when submodule path is normal path by CosmosAtlas · Pull Request #1645 · gitpython-developers/GitPython · GitHub
Open Graph Title: Fix 'Tree' object has no attribute '_name' when submodule path is normal path by CosmosAtlas · Pull Request #1645 · gitpython-developers/GitPython
X Title: Fix 'Tree' object has no attribute '_name' when submodule path is normal path by CosmosAtlas · Pull Request #1645 · gitpython-developers/GitPython
Description: When a repository have a .gitmodules file and the actual path defined in the git repository is not related to submodule, GitPython still assumes its a submodule. To replicate: # In a temp directory mkdir test cd test git init mkdir DbConnector touch DbConnector/readme.md touch .gitmodules # Put the context of the next segment in .gitmodules git add . git commit -m "test" [submodule "DbConnector"] path = DbConnector url = https://github.com/chaconinc/DbConnector Then in a python section from git.repo import Repo r = Repo('.') r.submodules the following error occurs In [3]: r.submodules --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) Cell In[3], line 1 ----> 1 r.submodules File ~/.local/share/virtualenvs/GitPython-yvdsleke/lib/python3.11/site-packages/git/repo/base.py:423, in Repo.submodules(self) 418 @property 419 def submodules(self) -> "IterableList[Submodule]": 420 """ 421 :return: git.IterableList(Submodule, ...) of direct submodules 422 available from the current head""" --> 423 return Submodule.list_items(self) File ~/.local/share/virtualenvs/GitPython-yvdsleke/lib/python3.11/site-packages/git/util.py:1184, in IterableObj.list_items(cls, repo, *args, **kwargs) 1175 """ 1176 Find all items of this type - subclasses can specify args and kwargs differently. 1177 If no args are given, subclasses are obliged to return all items if no additional (...) 1181 1182 :return: list(Item,...) list of item instances""" 1183 out_list: IterableList = IterableList(cls._id_attribute_) -> 1184 out_list.extend(cls.iter_items(repo, *args, **kwargs)) 1185 return out_list File ~/.local/share/virtualenvs/GitPython-yvdsleke/lib/python3.11/site-packages/git/objects/submodule/base.py:1406, in Submodule.iter_items(cls, repo, parent_commit, *Args, **kwargs) 1401 continue 1402 # END handle keyerror 1403 # END handle critical error 1404 1405 # fill in remaining info - saves time as it doesn't have to be parsed again -> 1406 sm._name = n 1407 if pc != repo.commit(): 1408 sm._parent_commit = pc AttributeError: 'Tree' object has no attribute '_name' Fixed by adding an additional check when determining whether the object is a submodule. Doing so makes sure only Submodule but not Blob or Tree instances of the IndexObjUnion is considered a submodule. PS: An example real project with this issue https://github.com/ChaoticOnyx/OnyxForum
Open Graph Description: When a repository have a .gitmodules file and the actual path defined in the git repository is not related to submodule, GitPython still assumes its a submodule. To replicate: # In a temp directory...
X Description: When a repository have a .gitmodules file and the actual path defined in the git repository is not related to submodule, GitPython still assumes its a submodule. To replicate: # In a temp directory...
Opengraph URL: https://github.com/gitpython-developers/GitPython/pull/1645
X: @github
Domain: togithub.com
| route-pattern | /:user_id/:repository/pull/:id/checks(.:format) |
| route-controller | pull_requests |
| route-action | checks |
| fetch-nonce | v2:16d819a6-506b-ebdc-dd03-61f9f5beb1e8 |
| current-catalog-service-hash | 87dc3bc62d9b466312751bfd5f889726f4f1337bdff4e8be7da7c93d6c00a25a |
| request-id | A512:1D1048:5C302F:809A0F:6969020A |
| html-safe-nonce | d6bd0d7add8400ae011860d46761738ab0b46c80c2d967c622a0736c7cc81f3b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNTEyOjFEMTA0ODo1QzMwMkY6ODA5QTBGOjY5NjkwMjBBIiwidmlzaXRvcl9pZCI6Ijg1OTI0NDQxNTkwNzU5NDc2MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 12ffdcb14354f5e8d15d00a2914d9bb32865de8bd6e386d2feabb43973004ab6 |
| hovercard-subject-tag | pull_request:1503608819 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,checks,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/gitpython-developers/GitPython/pull/1645/checks |
| twitter:image | https://avatars.githubusercontent.com/u/5738747?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/5738747?s=400&v=4 |
| og:image:alt | When a repository have a .gitmodules file and the actual path defined in the git repository is not related to submodule, GitPython still assumes its a submodule. To replicate: # In a temp directory... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | e6156bd4ef9f2dc8dadf4c49a8f7ed8532186388cef72eda3ccb9f0ab3b8cfca |
| turbo-cache-control | no-preview |
| go-import | github.com/gitpython-developers/GitPython git https://github.com/gitpython-developers/GitPython.git |
| octolytics-dimension-user_id | 503709 |
| octolytics-dimension-user_login | gitpython-developers |
| octolytics-dimension-repository_id | 1126087 |
| octolytics-dimension-repository_nwo | gitpython-developers/GitPython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1126087 |
| octolytics-dimension-repository_network_root_nwo | gitpython-developers/GitPython |
| turbo-body-classes | logged-out env-production page-responsive full-width full-width-p-0 |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | fd1938215b152e2c6a29cf56fec07fd9f91f1203 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width