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

Use configparser to parse the .git/config #65

Closed
wants to merge 1 commit into from

Conversation

Fryguy
Copy link

@Fryguy Fryguy commented Mar 27, 2018

This allows for a more accurate parsing of the file since we know the
sections, and values within those sections.

Fixes #62


I took a crack at using configparser to parse the .git/config file, but I'm leaving this PR as WIP because it actually blows up on some .git/config files I have where there are duplicate sections with the same name (though the duplicate sections are empty). I'm not sure how to force my .git/config into being like that, so if I figure it out, I'll put it here. If configparser can't be used, it might be better to just build a simple, custom, parser or find a way around how configparser deals with duplicate but empty sections.

The two regexes on lines 72 and 86 can probably be smashed together to make the code simpler, but I didn't want to mess with them in this PR, mostly reusing the original ones.

This is my first time writing Python, so if what I've written is not Pythonic, please let me know and I can fix it up. Are there tests I should be writing somewhere? I didn't see any tests, so I wasn't sure.

@Fryguy Fryguy force-pushed the use_config_parser branch from 883d733 to 933e6c2 Compare March 27, 2018 17:38
This allows for a more accurate parsing of the file since we know the
sections, and values within those sections.

Fixes ehamiter#62
@Fryguy Fryguy force-pushed the use_config_parser branch from 933e6c2 to aea66a7 Compare March 27, 2018 19:47
@Fryguy Fryguy changed the title [WIP] Use configparser to parse the .git/config Use configparser to parse the .git/config Mar 27, 2018
@Fryguy
Copy link
Author

Fryguy commented Mar 27, 2018

I found that passing strict=False to the ConfigParser allows it to process .git/config files with multiple duplicate sections by merging their keys together. Since I've only seen empty sections, this results in a no-op which works perfectly. Even if the sections aren't empty (i.e. they have duplicate keys as well), it is ok, as the last one wins.

This should be good to go.

Review is a little easier with whitespace disabled: https://github.com/ehamiter/GitHubinator/pull/65/files?w=1

@Fryguy
Copy link
Author

Fryguy commented Mar 27, 2018

I also figured out where the "blank" section in the config file come from. If you remove a remote it will empty out any branch section that refers to that remote. If you then point that branch to a different remote, it will create a new section near the end of the file instead of reusing the section. This feels like a bug in git.

@Fryguy Fryguy closed this Jan 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

multiple, different, remotes can break detection
1 participant