Skip to content

Commit f316fc4

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 37176bc + 70718c9 commit f316fc4

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
@@ -980,11 +980,19 @@ unsigned int sleep (unsigned int seconds)
980980
char *mingw_mktemp(char *template)
981981
{
982982
wchar_t wtemplate[MAX_PATH];
983+
int offset = 0;
984+
983985
if (xutftowcs_path(wtemplate, template) < 0)
984986
return NULL;
987+
988+
if (is_dir_sep(template[0]) && !is_dir_sep(template[1]) &&
989+
iswalpha(wtemplate[0]) && wtemplate[1] == L':') {
990+
/* We have an absolute path missing the drive prefix */
991+
offset = 2;
992+
}
985993
if (!_wmktemp(wtemplate))
986994
return NULL;
987-
if (xwcstoutf(template, wtemplate, strlen(template) + 1) < 0)
995+
if (xwcstoutf(template, wtemplate + offset, strlen(template) + 1) < 0)
988996
return NULL;
989997
return template;
990998
}

t/t5580-unc-paths.sh

Lines changed: 14 additions & 5 deletions
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)