Repository navigation
Conversation
On Windows, `GitConfigParser` never applied an
`[includeIf "gitdir:~/..."]` section, although `git config` does.
`os.path.expanduser` returns the home directory with backslashes, so
`gitdir:~/work/` became the pattern `C:\Users\me/work/**`. GitPython
compares gitdir patterns with the repository's `git_dir` written with
forward slashes, and in a gitdir pattern a backslash escapes the next
character instead of separating path components, so the pattern could
never match.
Git converts the home directory to forward slashes when it expands `~`
on Windows (`interpolate_path()` in `path.c`, which
`prepare_include_condition_pattern()` in `config.c` uses for gitdir
conditions). A usual setup such as
[includeIf "gitdir:~/work/"]
path = ~/.gitconfig-work
therefore made GitPython read `user.email` and other settings for a
repository under `~/work` from the global configuration only, while Git
read them from the included file.
On Windows, a pattern that is `~` or starts with `~/` now gets the home
directory with forward slashes. The rest of the pattern is unchanged, so
a backslash written in the pattern still escapes the next character, as
`test_conditional_includes_do_not_treat_backslashes_as_separators`
expects. Other platforms and `~user` patterns keep the previous
`os.path.expanduser` call.
`test_conditional_includes_expand_home_in_git_dir_pattern` points the
home directory at a temporary directory and checks that
`gitdir:~/target/` matches a repository below it. On Windows it fails
without this change and passes with it. On other platforms it passes
either way.
Validated on Windows 11 with Git for Windows 2.51.2 and Python 3.11.9:
`test/test_config.py` passes (55 passed, 3 skipped); `ruff check`,
`ruff format --check`, `mypy` and `basedpyright --warnings` report no
issues. For a repository whose `.git/config` includes a file through
`gitdir:~/...`, `git config --get user.email` returns the included value,
and `Repo.config_reader("repository").get_value("user", "email")` now
returns it too instead of finding no value.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On Windows,
GitConfigParsernever applies an[includeIf "gitdir:~/..."]section, whilegit configdoes.os.path.expanduserreturns the home directory with backslashes, sogitdir:~/work/becomesC:\Users\me/work/**. GitPython compares gitdir patterns withgit_dirwritten with forward slashes, and a backslash in a gitdir pattern escapes the next character, so the pattern never matches. Git converts the home directory to forward slashes when it expands~on Windows (interpolate_path()inpath.c, used byprepare_include_condition_pattern()inconfig.c).So with the usual setup
GitPython reads
user.emailetc. for a repository under~/workfrom the global config only.Repro on Windows, in a repository under the home directory whose
.git/configincludes a file that setsuser.email = work@example.comthroughgitdir:~/<path to repo>/:Change
On Windows, a pattern that is
~or starts with~/gets the home directory with forward slashes. The rest of the pattern is unchanged, so backslashes written in the pattern are still escapes (test_conditional_includes_do_not_treat_backslashes_as_separatorsstill passes). Other platforms and~userpatterns keep the previousos.path.expandusercall.Tests
test_conditional_includes_expand_home_in_git_dir_patternpoints the home directory at a temporary directory and checks thatgitdir:~/target/matches a repository below it. On Windows it fails without the change and passes with it; on other platforms it passes either way.Validation
Run by the agent on Windows 11, Git for Windows 2.51.2, Python 3.11.9:
test/test_config.py: 55 passed, 3 skippedruff check,ruff format --check,mypy,basedpyright --warnings: no issuesWinError 1314) intest_submodule.pyplustest/performance/test_commit.pywork@example.comafter the changeThis change and description were written by Claude Code (an AI agent) and opened through @b84330808's account.