Skip to content

Commit e73893e

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 34b04ff + 87d4cfb commit e73893e

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

compat/mingw.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1141,11 +1141,19 @@ unsigned int sleep (unsigned int seconds)
11411141
char *mingw_mktemp(char *template)
11421142
{
11431143
wchar_t wtemplate[MAX_PATH];
1144+
int offset = 0;
1145+
11441146
if (xutftowcs_path(wtemplate, template) < 0)
11451147
return NULL;
1148+
1149+
if (is_dir_sep(template[0]) && !is_dir_sep(template[1]) &&
1150+
iswalpha(wtemplate[0]) && wtemplate[1] == L':') {
1151+
/* We have an absolute path missing the drive prefix */
1152+
offset = 2;
1153+
}
11461154
if (!_wmktemp(wtemplate))
11471155
return NULL;
1148-
if (xwcstoutf(template, wtemplate, strlen(template) + 1) < 0)
1156+
if (xwcstoutf(template, wtemplate + offset, strlen(template) + 1) < 0)
11491157
return NULL;
11501158
return template;
11511159
}

t/t5580-unc-paths.sh

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,30 @@ fi
2020
UNCPATH="$(winpwd)"
2121
case "$UNCPATH" in
2222
[A-Z]:*)
23+
WITHOUTDRIVE="${UNCPATH#?:}"
2324
# Use administrative share e.g. \\localhost\C$\git-sdk-64\usr\src\git
2425
# (we use forward slashes here because MSYS2 and Git accept them, and
2526
# they are easier on the eyes)
26-
UNCPATH="//localhost/${UNCPATH%%:*}\$/${UNCPATH#?:}"
27-
test -d "$UNCPATH" || {
28-
skip_all='could not access administrative share; skipping'
29-
test_done
30-
}
27+
UNCPATH="//localhost/${UNCPATH%%:*}\$$WITHOUTDRIVE"
3128
;;
3229
*)
3330
skip_all='skipping UNC path tests, cannot determine current path as UNC'
3431
test_done
3532
;;
3633
esac
3734

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

0 commit comments

Comments
 (0)