Skip to content

Commit 44c3aac

Browse files
dschoGit for Windows Build Agent
authored andcommitted
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 cc61e72 + 72f2f0b commit 44c3aac

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
@@ -1164,11 +1164,19 @@ unsigned int sleep (unsigned int seconds)
11641164
char *mingw_mktemp(char *template)
11651165
{
11661166
wchar_t wtemplate[MAX_PATH];
1167+
int offset = 0;
1168+
11671169
if (xutftowcs_path(wtemplate, template) < 0)
11681170
return NULL;
1171+
1172+
if (is_dir_sep(template[0]) && !is_dir_sep(template[1]) &&
1173+
iswalpha(wtemplate[0]) && wtemplate[1] == L':') {
1174+
/* We have an absolute path missing the drive prefix */
1175+
offset = 2;
1176+
}
11691177
if (!_wmktemp(wtemplate))
11701178
return NULL;
1171-
if (xwcstoutf(template, wtemplate, strlen(template) + 1) < 0)
1179+
if (xwcstoutf(template, wtemplate + offset, strlen(template) + 1) < 0)
11721180
return NULL;
11731181
return template;
11741182
}

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)