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

When looking at potentially long paths: leave drive-less absolute paths intact #4592

Merged
merged 1 commit into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion compat/mingw.c
Original file line number Diff line number Diff line change
Expand Up @@ -3851,7 +3851,12 @@ int handle_long_path(wchar_t *path, int len, int max_path, int expand)
* "cwd + path" doesn't due to '..' components)
*/
if (result < max_path) {
wcscpy(path, buf);
/* Be careful not to add a drive prefix if there was none */
if (is_wdir_sep(path[0]) &&
!is_wdir_sep(buf[0]) && buf[1] == L':' && is_wdir_sep(buf[2]))
wcscpy(path, buf + 2);
else
wcscpy(path, buf);
return result;
}

Expand Down
9 changes: 9 additions & 0 deletions t/t2031-checkout-long-paths.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,13 @@ test_expect_success SHORTABSPATH 'clean up path close to MAX_PATH' '
test ! -d "$subdir1"
'

test_expect_success SYMLINKS_WINDOWS 'leave drive-less, short paths intact' '
printf "/Program Files" >symlink-target &&
symlink_target_oid="$(git hash-object -w --stdin <symlink-target)" &&
git update-index --add --cacheinfo 120000,$symlink_target_oid,PF &&
git -c core.symlinks=true checkout -- PF &&
cmd //c dir >actual &&
grep "<SYMLINKD\\?> *PF *\\[\\\\Program Files\\]" actual
'

test_done
Loading