Skip to content

Commit 0b46e3d

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 c4b8bd1 + b4379e6 commit 0b46e3d

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
@@ -994,12 +994,20 @@ unsigned int sleep (unsigned int seconds)
994994
char *mingw_mktemp(char *template)
995995
{
996996
wchar_t wtemplate[MAX_PATH];
997+
int offset = 0;
998+
997999
/* we need to return the path, thus no long paths here! */
9981000
if (xutftowcs_path(wtemplate, template) < 0)
9991001
return NULL;
1002+
1003+
if (is_dir_sep(template[0]) && !is_dir_sep(template[1]) &&
1004+
iswalpha(wtemplate[0]) && wtemplate[1] == L':') {
1005+
/* We have an absolute path missing the drive prefix */
1006+
offset = 2;
1007+
}
10001008
if (!_wmktemp(wtemplate))
10011009
return NULL;
1002-
if (xwcstoutf(template, wtemplate, strlen(template) + 1) < 0)
1010+
if (xwcstoutf(template, wtemplate + offset, strlen(template) + 1) < 0)
10031011
return NULL;
10041012
return template;
10051013
}

t/t5580-clone-push-unc.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)