Skip to content

Commit 31e10da

Browse files
committed
Merge branch 'drive-prefix'
This topic branch allows us to specify absolute paths without the drive prefix e.g. when cloning. Example: C:\Users\me> git clone https://github.com/git/git \upstream-git This will clone into a new directory C:\upstream-git, in line with how Windows interprets absolute paths. Signed-off-by: Johannes Schindelin <[email protected]>
2 parents a8dbfc4 + df05ba3 commit 31e10da

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

compat/mingw.c

+9-1
Original file line numberDiff line numberDiff line change
@@ -950,12 +950,20 @@ unsigned int sleep (unsigned int seconds)
950950
char *mingw_mktemp(char *template)
951951
{
952952
wchar_t wtemplate[MAX_PATH];
953+
int offset = 0;
954+
953955
/* we need to return the path, thus no long paths here! */
954956
if (xutftowcs_path(wtemplate, template) < 0)
955957
return NULL;
958+
959+
if (is_dir_sep(template[0]) && !is_dir_sep(template[1]) &&
960+
iswalpha(wtemplate[0]) && wtemplate[1] == L':') {
961+
/* We have an absolute path missing the drive prefix */
962+
offset = 2;
963+
}
956964
if (!_wmktemp(wtemplate))
957965
return NULL;
958-
if (xwcstoutf(template, wtemplate, strlen(template) + 1) < 0)
966+
if (xwcstoutf(template, wtemplate + offset, strlen(template) + 1) < 0)
959967
return NULL;
960968
return template;
961969
}

t/t5580-clone-push-unc.sh

+14-5
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,30 @@ fi
1111
UNCPATH="$(pwd)"
1212
case "$UNCPATH" in
1313
[A-Z]:*)
14+
WITHOUTDRIVE="${UNCPATH#?:}"
1415
# Use administrative share e.g. \\localhost\C$\git-sdk-64\usr\src\git
1516
# (we use forward slashes here because MSYS2 and Git accept them, and
1617
# they are easier on the eyes)
17-
UNCPATH="//localhost/${UNCPATH%%:*}\$/${UNCPATH#?:}"
18-
test -d "$UNCPATH" || {
19-
skip_all='could not access administrative share; skipping'
20-
test_done
21-
}
18+
UNCPATH="//localhost/${UNCPATH%%:*}\$$WITHOUTDRIVE"
2219
;;
2320
*)
2421
skip_all='skipping UNC path tests, cannot determine current path as UNC'
2522
test_done
2623
;;
2724
esac
2825

26+
test_expect_success 'clone into absolute path lacking a drive prefix' '
27+
USINGBACKSLASHES="$(echo "$WITHOUTDRIVE"/without-drive-prefix |
28+
tr / \\)" &&
29+
git clone . "$USINGBACKSLASHES" &&
30+
test -f without-drive-prefix/.git/HEAD
31+
'
32+
33+
test -d "$UNCPATH" || {
34+
skip_all='could not access administrative share; skipping'
35+
test_done
36+
}
37+
2938
test_expect_success setup '
3039
test_commit initial
3140
'

0 commit comments

Comments
 (0)