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/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:782fc597-11a6-854c-7a34-73f05f228969 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | B4FC:1D1048:5D950F:828EA0:6969023C |
| html-safe-nonce | e20aed752901c954b679823880f488efa00d1a04a3ae8eb69e4a0766e4a38a19 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNEZDOjFEMTA0ODo1RDk1MEY6ODI4RUEwOjY5NjkwMjNDIiwidmlzaXRvcl9pZCI6Ijc4NjM5MDg5NTcxMDI0MTM0MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | f648a16355c566a147895ee59d8f9462bac97d8c51eb52a636b5d264cfeff2a8 |
| hovercard-subject-tag | pull_request:1503608819 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,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/files |
| 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 |
| diff-view | unified |
| 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 |
| disable-turbo | true |
| 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