GitPython icon indicating copy to clipboard operation
GitPython copied to clipboard

'user' section of config exists for sections() but not items methods

Open pushfoo opened this issue 2 years ago • 3 comments

This appears to work fine:

>>> reader = repo_instance.config_reader()
>>> reader.sections()
['filter "lfs"', 'core', 'user']

However, these do not:

>>> reader.items('user')
NoSectionError: "No section: 'user'"

>>> reader.items_all('user')
KeyError: 'user'

I've confirmed the section exists in the repo's local .git/config as follows:

[user]
        name = pushfoo
        email = [email protected]

If this is due to misuse on my part, please let me know how. I'd be willing to try to make a PR to do the following:

  1. Make the exceptions more consistent
  2. Update relevant doc to be clearer
  3. Fix underlying bugs

Depending on how far down into git's internals I need to go, the last option may require some guidance from project leads.

EDIT: Version info:

Detail Value Comments
Python Version 3.9.2 Stock for Debian 11
Git version 2.30.2 Stock for Debian 11
OS / version Debian 11 No major customization have been applied
GitPthon version 3.1.37 default for pip install
gitdb version 4.0.10 default installed by above

pushfoo avatar Oct 16 '23 10:10 pushfoo

Interesting! I'd also expect this to work particularly since its talking about section: 'user' not being present even though it is present.

I don't know what's expected though as it seems impossible to find items or items_all in the generated documentation, one would probably have to check in the source code or find tests for these. Thanks for considering to contribute!

Byron avatar Oct 16 '23 10:10 Byron

Thank you for the quick initial response! I've added some version info to the issue.

  1. Can you confirm it as broken on your system?

  2. one would probably have to check in the source code

    Are there any specific directions you'd suggest investigating?

The first things that come to mind for me are:

  • [x] Whether other repo-level sections work
  • [x] Whether it's this specific project's repo or all of them
  • [x] Whether changing git config values at other levels still gets picked up
  • [x] Whether ConfigReader is broken in general, or just when attached to a repo object
  • [ ] Did any assumptions change since the code was written?
    • [ ] default location / name of the config files
    • [ ] default git config format

I'll try to look into the items over the coming hours / days.

or find tests for these.

If you need new tests or doc improvement help, I'd be willing to try as time allows. :+1:

pushfoo avatar Oct 16 '23 11:10 pushfoo

I can't confirm it as I didn't try. If it doesn't work for you it's a reason to look into the matter.

I'd check for config.py and test_config.py for hints on how the API is supposed to work, or what's tested. Maybe add a test and see if it reproduces there as well.

Good luck (even though you probably won't need it)

Byron avatar Oct 16 '23 11:10 Byron