Repository navigation
Commit b83fcb8
fix(config): match
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>~/ gitdir includes on Windows1 parent ccc4811 commit b83fcb8
2 files changed
Lines changed: 22 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
730 | 730 | | |
731 | 731 | | |
732 | 732 | | |
733 | | - | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
734 | 739 | | |
735 | 740 | | |
736 | 741 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
989 | 989 | | |
990 | 990 | | |
991 | 991 | | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
992 | 1008 | | |
993 | 1009 | | |
994 | 1010 | | |
| |||
0 commit comments