Skip to content

Commit

Permalink
mingw: allow absolute paths without drive prefix
Browse files Browse the repository at this point in the history
When specifying an absolute path without a drive prefix, we convert that
path internally. Let's make sure that we handle that case properly, too
;-)

This fixes the command

	git clone https://github.com/git-for-windows/git \G4W

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information
dscho committed Apr 28, 2023
1 parent 88cfe5b commit 927537b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion compat/mingw.c
Original file line number Diff line number Diff line change
Expand Up @@ -1058,11 +1058,19 @@ unsigned int sleep (unsigned int seconds)
char *mingw_mktemp(char *template)
{
wchar_t wtemplate[MAX_PATH];
int offset = 0;

if (xutftowcs_path(wtemplate, template) < 0)
return NULL;

if (is_dir_sep(template[0]) && !is_dir_sep(template[1]) &&
iswalpha(wtemplate[0]) && wtemplate[1] == L':') {
/* We have an absolute path missing the drive prefix */
offset = 2;
}
if (!_wmktemp(wtemplate))
return NULL;
if (xwcstoutf(template, wtemplate, strlen(template) + 1) < 0)
if (xwcstoutf(template, wtemplate + offset, strlen(template) + 1) < 0)
return NULL;
return template;
}
Expand Down
2 changes: 1 addition & 1 deletion t/t5580-unc-paths.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ case "$UNCPATH" in
;;
esac

test_expect_failure 'clone into absolute path lacking a drive prefix' '
test_expect_success 'clone into absolute path lacking a drive prefix' '
USINGBACKSLASHES="$(echo "$WITHOUTDRIVE"/without-drive-prefix |
tr / \\\\)" &&
git clone . "$USINGBACKSLASHES" &&
Expand Down

0 comments on commit 927537b

Please sign in to comment.