Skip to content

Conversation

delilahw
Copy link

cc: Delilah Ashley Wu [email protected], Delilah Ashley Wu [email protected]
cc: Derrick Stolee [email protected]
cc: Johannes Schindelin [email protected]

Git prefers forward slashes as directory separators across all
platforms. On Windows, the backslash is the native directory separator,
but all Windows versions supported by Git also accept the forward slash
in all but rare circumstances. Our tests expect forward slashes. Git
generates relative paths using forward slashes. Forward slashes are more
convenient to use in shell scripts.

For these reasons, we enforced forward slashes in `interpolate_path()`
in 5ca6b7b (config --show-origin: report paths with forward slashes,
2016-03-23). However, other code paths may generate paths containing
backslashes. For example, `config --show-origin` prints the XDG config
path with backslashes on Windows:

$ git config --list --show-origin
file:C:/Program Files/Git/etc/gitconfig         system.foo=bar
file:"C:\\Users\\delilah/.config/git/config"    xdg.foo=bar
file:C:/Users/delilah/.gitconfig                home.foo=bar
file:.git/config                                local.foo=bar

Let's enforce forward slashes in all code paths that directly or
indirectly call `cleanup_path()` by modifying it to call
`convert_slashes()` on Windows. Since `convert_slashes()` modifies the
path in-place, change the argument and return type of `cleanup_path()`
from `const char *` to `char *`. All existing callers of
`cleanup_path()` pass `char *` anyways, so this change is compatible.

Suggested-by: Johannes Schindelin <[email protected]>
Signed-off-by: Delilah Ashley Wu <[email protected]>
@delilahw delilahw force-pushed the lilah/fix-xdg-path-slashes-windows/patchset branch from 89b6531 to bdd6252 Compare September 18, 2025 03:43
@delilahw delilahw changed the title path: use forward slashes for XDG path on windows cleanup_path: force forward slashes on Windows Sep 18, 2025
@delilahw
Copy link
Author

Feedback addressed in the new commit message, thanks @dscho! 😊

I should probably add some tests to check that the XDG path uses the correct slashes, in either t1300-config.sh:2123 or t1306-xdg-files.sh.

My other patch series, #1938, will exercise a similar scenario: config --list --global --show-origin. However, it's blocked by the current patch because the below test_cmp fails from mismatched slashes on Windows. I don't think it makes sense to place the current patch inside the #1938 series, because they solve related problems but are not part of the same issue. In these situations, should we finalise the current patch and submit #1938 later?

git/t/t1300-config.sh

Lines 2427 to 2432 in 5b253d6

cat >expect <<-EOF &&
global file:$HOME/.config/git/config xdg.config=true
global file:$HOME/.gitconfig home.config=true
EOF
git config ${mode_prefix}list --global --show-scope --show-origin >output &&
test_cmp expect output

@dscho
Copy link
Member

dscho commented Sep 18, 2025

@delilahw how about inserting the current patch as a first commit into #1938, mentioning in the commit message that the next patch adds a test case that validates the newly-adjusted logic anyway, therefore that first commit refrains from adding a redundant test case? Then you could go ahead and submit #1938.

@delilahw
Copy link
Author

Ohhhh yep that makes sense. Thanks so much for your guidance @dscho !!

@delilahw delilahw closed this Sep 18, 2025
@delilahw
Copy link
Author

Superseded by #1938.

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.

2 participants