Skip to content
Permalink
Browse files

Merge branch 'unc-path-w-backslashes'

This topic branch addresses a problem identified in
#439: while
cloning/fetching/pushing from "POSIX-ified UNC paths" (i.e. UNC paths
whose backslashes have been converted to forward slashes) works for some
time now, true UNC paths (with backslashes left intact) were handled
incorrectly. Example:

	git clone //myserver/folder/repo.git

works, but

	git clone \\myserver\folder\repo.git

(in CMD; in Git Bash, the backslashes would need to be doubled) used to
fail. The reason was an unexpected difference in command-line handling
between Win32 executables and MSYS2 ones (such as the shell that is used
by git-clone.exe to spawn git-upload-pack.exe).

This topic branch features a workaround *just* for the case where Git
passes stuff through sh.exe (which covers quite a few use cases,
though).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information...
dscho committed Jun 26, 2017
2 parents 5e149ce + dcca30f commit 914b84c9d949b14a135ab50c8b881cdee9be116c
Showing with 40 additions and 2 deletions.
  1. +34 −1 compat/mingw.c
  2. +6 −1 t/t5580-clone-push-unc.sh
@@ -1066,7 +1066,7 @@ char *mingw_getcwd(char *pointer, int len)
* See http://msdn2.microsoft.com/en-us/library/17w5ykft(vs.71).aspx
* (Parsing C++ Command-Line Arguments)
*/
static const char *quote_arg(const char *arg)
static const char *quote_arg_msvc(const char *arg)
{
/* count chars to quote */
int len = 0, n = 0;
@@ -1121,6 +1121,37 @@ static const char *quote_arg(const char *arg)
return q;
}

#include "quote.h"

static const char *quote_arg_sh(const char *arg)
{
struct strbuf buf = STRBUF_INIT;
const char *p2 = arg, *p;

for (p = arg; *p; p++) {
int ws = isspace(*p);
if (!ws && *p != '\\' && *p != '"')
continue;
if (!buf.len)
strbuf_addch(&buf, '"');
if (p != p2)
strbuf_add(&buf, p2, p - p2);
if (!ws)
strbuf_addch(&buf, '\\');
p2 = p;
}

if (p == arg)
strbuf_addch(&buf, '"');
else if (!buf.len)
return arg;
else
strbuf_add(&buf, p2, p - p2),

strbuf_addch(&buf, '"');
return strbuf_detach(&buf, 0);
}

static const char *parse_interpreter(const char *cmd)
{
static char buf[100];
@@ -1547,6 +1578,8 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
BOOL ret;
HANDLE cons;
const char *strace_env;
const char *(*quote_arg)(const char *arg) =
*argv && !strcmp("sh", *argv) ? quote_arg_sh : quote_arg_msvc;

if (!atexit_handler_initialized) {
atexit_handler_initialized = 1;
@@ -25,7 +25,7 @@ esac

test_expect_success 'clone into absolute path lacking a drive prefix' '
USINGBACKSLASHES="$(echo "$WITHOUTDRIVE"/without-drive-prefix |
tr / \\)" &&
tr / \\\\)" &&
git clone . "$USINGBACKSLASHES" &&
test -f without-drive-prefix/.git/HEAD
'
@@ -43,6 +43,11 @@ test_expect_success clone '
git clone "file://$UNCPATH" clone
'

test_expect_success 'clone with backslashed path' '
BACKSLASHED="$(echo "$UNCPATH" | tr / \\\\)" &&
git clone "$BACKSLASHED" backslashed
'

test_expect_success push '
(
cd clone &&

0 comments on commit 914b84c

Please sign in to comment.
You can’t perform that action at this time.