Skip to content

Conversation

bvanelli
Copy link
Contributor

@bvanelli bvanelli commented Oct 7, 2025

Support adding custom paths for the following git config:

# Anonymous user override
[includeIf "hasconfig:remote.*.url:**/**github.com*/**"]
	path = ~/.personal.gitconfig

According to the documentation:

As for the naming of this keyword, it is for forwards compatibility with a naming scheme that supports more variable-based include conditions, but currently Git only supports the exact keyword described above.

So I have matched the condition exactly word to word with hasconfig:remote.*.url. I then go over the list of remotes and find using fnmatchcase the correct remote (not sure if fnmatch.

Maybe a list of open points here:

  • I'm not sure if the wildcard format and the fnmatch function are equivalent. Is it necessary to match these two 100%? Maybe a maintainer would have more experience with
  • Should I write more test cases?
  • Write a couple of cases which are handled by both git binary and gitpython and compare the two.

Closes #2017

Copy link
Member

@Byron Byron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for contributing this capability!

I really like the implementation, and love that there are tests as well.
To my mind these tests cover the most important cases.

Good to merge!


elif keyword == "hasconfig:remote.*.url":
for remote in self._repo.remotes:
if fnmatch.fnmatchcase(remote.url, value):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a case-sensitive search is correct here, Git does the same.


# Ensure that config with hasconfig and incorrect url is incorrect.
with open(path1, "w") as stream:
stream.write(template.format("incorrect", path2))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that "incorrect" fails to communicate that this is a URL that simply doesn't match.
Maybe something for a follow-up.

@Byron Byron merged commit 0c2bfac into gitpython-developers:main Oct 8, 2025
27 checks passed
@bvanelli bvanelli deleted the 2017-support-hasconfig-remote-url branch October 8, 2025 05:35
@bvanelli
Copy link
Contributor Author

bvanelli commented Oct 8, 2025

Oh, such speed, thanks for the quick response!

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

hasconfig:remote.*.url not supported by includeIf

2 participants