Skip to content

Commit 11cc3f4

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 68e6cb4 + 9bedff0 commit 11cc3f4

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

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)