Skip to content

Commit bef00e1

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 1b335d0 + 820dbe4 commit bef00e1

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
@@ -1059,11 +1059,19 @@ unsigned int sleep (unsigned int seconds)
10591059
char *mingw_mktemp(char *template)
10601060
{
10611061
wchar_t wtemplate[MAX_PATH];
1062+
int offset = 0;
1063+
10621064
if (xutftowcs_path(wtemplate, template) < 0)
10631065
return NULL;
1066+
1067+
if (is_dir_sep(template[0]) && !is_dir_sep(template[1]) &&
1068+
iswalpha(wtemplate[0]) && wtemplate[1] == L':') {
1069+
/* We have an absolute path missing the drive prefix */
1070+
offset = 2;
1071+
}
10641072
if (!_wmktemp(wtemplate))
10651073
return NULL;
1066-
if (xwcstoutf(template, wtemplate, strlen(template) + 1) < 0)
1074+
if (xwcstoutf(template, wtemplate + offset, strlen(template) + 1) < 0)
10671075
return NULL;
10681076
return template;
10691077
}

t/t5580-unc-paths.sh

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

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

0 commit comments

Comments
 (0)