Skip to content

Commit 3408d10

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 9318a60 + 58acc72 commit 3408d10

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
@@ -951,12 +951,20 @@ unsigned int sleep (unsigned int seconds)
951951
char *mingw_mktemp(char *template)
952952
{
953953
wchar_t wtemplate[MAX_PATH];
954+
int offset = 0;
955+
954956
/* we need to return the path, thus no long paths here! */
955957
if (xutftowcs_path(wtemplate, template) < 0)
956958
return NULL;
959+
960+
if (is_dir_sep(template[0]) && !is_dir_sep(template[1]) &&
961+
iswalpha(wtemplate[0]) && wtemplate[1] == L':') {
962+
/* We have an absolute path missing the drive prefix */
963+
offset = 2;
964+
}
957965
if (!_wmktemp(wtemplate))
958966
return NULL;
959-
if (xwcstoutf(template, wtemplate, strlen(template) + 1) < 0)
967+
if (xwcstoutf(template, wtemplate + offset, strlen(template) + 1) < 0)
960968
return NULL;
961969
return template;
962970
}

t/t5580-clone-push-unc.sh

+14-5
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,30 @@ fi
1717
UNCPATH="$(winpwd)"
1818
case "$UNCPATH" in
1919
[A-Z]:*)
20+
WITHOUTDRIVE="${UNCPATH#?:}"
2021
# Use administrative share e.g. \\localhost\C$\git-sdk-64\usr\src\git
2122
# (we use forward slashes here because MSYS2 and Git accept them, and
2223
# they are easier on the eyes)
23-
UNCPATH="//localhost/${UNCPATH%%:*}\$/${UNCPATH#?:}"
24-
test -d "$UNCPATH" || {
25-
skip_all='could not access administrative share; skipping'
26-
test_done
27-
}
24+
UNCPATH="//localhost/${UNCPATH%%:*}\$$WITHOUTDRIVE"
2825
;;
2926
*)
3027
skip_all='skipping UNC path tests, cannot determine current path as UNC'
3128
test_done
3229
;;
3330
esac
3431

32+
test_expect_success 'clone into absolute path lacking a drive prefix' '
33+
USINGBACKSLASHES="$(echo "$WITHOUTDRIVE"/without-drive-prefix |
34+
tr / \\)" &&
35+
git clone . "$USINGBACKSLASHES" &&
36+
test -f without-drive-prefix/.git/HEAD
37+
'
38+
39+
test -d "$UNCPATH" || {
40+
skip_all='could not access administrative share; skipping'
41+
test_done
42+
}
43+
3544
test_expect_success setup '
3645
test_commit initial
3746
'

0 commit comments

Comments
 (0)