Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

configparser.NoOptionError if submodule's URL key name is Url rather than url in .gitmodules #1601

Open
frezcirno opened this issue Jun 28, 2023 · 1 comment

Comments

@frezcirno
Copy link

Hi, thanks for your effort in this excellent library.

Recently, I'm mining many OSS repositories using GitPython, it's a handy tool and helps me a lot. And I encountered a weird error when processing this repository.

The minimal code to reproduce the error is:

import git

# git clone https://github.com/zoneminder/zoneminder.git zoneminder
repo = git.Repo("zoneminder")

repo.submodules  # <--- This line causes the error

And the exception is:

Traceback (most recent call last):
  File "/home/frezcirno/test.py", line 6, in <module>
    gitrepo.submodules  # <-- this line causes the error
    ^^^^^^^^^^^^^^^^^^
  File "/home/frezcirno/miniconda3/envs/work/lib/python3.11/site-packages/git/repo/base.py", line 422, in submodules
    return Submodule.list_items(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/frezcirno/miniconda3/envs/work/lib/python3.11/site-packages/git/util.py", line 1189, in list_items
    out_list.extend(cls.iter_items(repo, *args, **kwargs))
  File "/home/frezcirno/miniconda3/envs/work/lib/python3.11/site-packages/git/objects/submodule/base.py", line 1382, in iter_items
    u = parser.get(sms, "url")
        ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/frezcirno/miniconda3/envs/work/lib/python3.11/site-packages/git/config.py", line 122, in assure_data_present
    return func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/frezcirno/miniconda3/envs/work/lib/python3.11/configparser.py", line 808, in get
    raise NoOptionError(option, section)
configparser.NoOptionError: No option 'url' in section: 'submodule "web/api/app/Plugin/CakePHP-Enum-Behavior"'

It seems that the root cause is the .gitmodule file in this repository contains a Url instead of url key, which interferes GitPython's parsing process. As a result, commit diff is also unusable.

As the .gitmodule with Url can be correctly recognized by git, would this be a small bug?

@Byron
Copy link
Member

Byron commented Jun 29, 2023

Thanks for reporting. The submodules implementation is definitely not according to specification and it's more a matter of luck if it works. Maybe issues like these that seem to be about capitalization can be fixed though, and I invite contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants