Skip to content

Commit 36fbfaf

Browse files
committed
Merge branch 'unc-path-w-backslashes'
Merging this topic branch because it would otherwise conflict with the next commit. Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 9647bab + e1558b6 commit 36fbfaf

File tree

3 files changed

+77
-1
lines changed

3 files changed

+77
-1
lines changed

compat/mingw.c

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,7 @@ char *mingw_getcwd(char *pointer, int len)
10141014
* See http://msdn2.microsoft.com/en-us/library/17w5ykft(vs.71).aspx
10151015
* (Parsing C++ Command-Line Arguments)
10161016
*/
1017-
static const char *quote_arg(const char *arg)
1017+
static const char *quote_arg_msvc(const char *arg)
10181018
{
10191019
/* count chars to quote */
10201020
int len = 0, n = 0;
@@ -1069,6 +1069,37 @@ static const char *quote_arg(const char *arg)
10691069
return q;
10701070
}
10711071

1072+
#include "quote.h"
1073+
1074+
static const char *quote_arg_msys2(const char *arg)
1075+
{
1076+
struct strbuf buf = STRBUF_INIT;
1077+
const char *p2 = arg, *p;
1078+
1079+
for (p = arg; *p; p++) {
1080+
int ws = isspace(*p);
1081+
if (!ws && *p != '\\' && *p != '"' && *p != '{')
1082+
continue;
1083+
if (!buf.len)
1084+
strbuf_addch(&buf, '"');
1085+
if (p != p2)
1086+
strbuf_add(&buf, p2, p - p2);
1087+
if (!ws && *p != '{')
1088+
strbuf_addch(&buf, '\\');
1089+
p2 = p;
1090+
}
1091+
1092+
if (p == arg)
1093+
strbuf_addch(&buf, '"');
1094+
else if (!buf.len)
1095+
return arg;
1096+
else
1097+
strbuf_add(&buf, p2, p - p2),
1098+
1099+
strbuf_addch(&buf, '"');
1100+
return strbuf_detach(&buf, 0);
1101+
}
1102+
10721103
static const char *parse_interpreter(const char *cmd)
10731104
{
10741105
static char buf[100];
@@ -1300,6 +1331,34 @@ struct pinfo_t {
13001331
static struct pinfo_t *pinfo = NULL;
13011332
CRITICAL_SECTION pinfo_cs;
13021333

1334+
static int is_msys2_sh(const char *cmd)
1335+
{
1336+
if (cmd && !strcmp(cmd, "sh")) {
1337+
static int ret = -1;
1338+
char *p;
1339+
1340+
if (ret >= 0)
1341+
return ret;
1342+
1343+
p = path_lookup(cmd, 0);
1344+
if (!p)
1345+
ret = 0;
1346+
else {
1347+
size_t len = strlen(p);
1348+
ret = len > 15 &&
1349+
is_dir_sep(p[len - 15]) &&
1350+
!strncasecmp(p + len - 14, "usr", 3) &&
1351+
is_dir_sep(p[len - 11]) &&
1352+
!strncasecmp(p + len - 10, "bin", 3) &&
1353+
is_dir_sep(p[len - 7]) &&
1354+
!strcasecmp(p + len - 6, "sh.exe");
1355+
free(p);
1356+
}
1357+
return ret;
1358+
}
1359+
return 0;
1360+
}
1361+
13031362
static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaenv,
13041363
const char *dir,
13051364
int prepend_cmd, int fhin, int fhout, int fherr)
@@ -1311,6 +1370,8 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
13111370
unsigned flags = CREATE_UNICODE_ENVIRONMENT;
13121371
BOOL ret;
13131372
HANDLE cons;
1373+
const char *(*quote_arg)(const char *arg) =
1374+
is_msys2_sh(*argv) ? quote_arg_msys2 : quote_arg_msvc;
13141375

13151376
do_unset_environment_variables();
13161377

t/t0061-run-command.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,14 @@ test_expect_success 'GIT_TRACE with environment variables' '
177177
)
178178
'
179179

180+
test_expect_success MINGW 'verify curlies are quoted properly' '
181+
: force the rev-parse through the MSYS2 Bash &&
182+
git -c alias.r="!git rev-parse" r -- a{b}c >actual &&
183+
cat >expect <<-\EOF &&
184+
--
185+
a{b}c
186+
EOF
187+
test_cmp expect actual
188+
'
189+
180190
test_done

t/t5580-clone-push-unc.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ test_expect_success clone '
4949
git clone "file://$UNCPATH" clone
5050
'
5151

52+
test_expect_success 'clone with backslashed path' '
53+
BACKSLASHED="$(echo "$UNCPATH" | tr / \\\\)" &&
54+
git clone "$BACKSLASHED" backslashed
55+
'
56+
5257
test_expect_success push '
5358
(
5459
cd clone &&

0 commit comments

Comments
 (0)