]> git.ipfire.org Git - thirdparty/git.git/commitdiff
remote-curl: make --force-with-lease work with non-ASCII ref names
authorbrian m. carlson <sandals@crustytoothpaste.net>
Tue, 21 Jul 2020 01:15:11 +0000 (01:15 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 21 Jul 2020 04:05:16 +0000 (21:05 -0700)
When we invoke a remote transport helper and pass an option with an
argument, we quote the argument as a C-style string if necessary.  This
is the case for the cas option, which implements the --force-with-lease
command-line flag, when we're passing a non-ASCII refname.

However, the remote curl helper isn't designed to parse such an
argument, meaning that if we try to use --force-with-lease with an HTTP
push and a non-ASCII refname, we get an error like this:

  error: cannot parse expected object name '0000000000000000000000000000000000000000"'

Note the double quote, which get_oid has reminded us is not valid in an
hex object ID.

Even if we had been able to parse it, we would send the wrong data to
the server: we'd send an escaped ref, which would not behave as the user
wanted and might accidentally result in updating or deleting a ref we
hadn't intended.

Since we need to expect a quoted C-style string here, just check if the
first argument is a double quote, and if so, unquote it.  Note that if
the refname contains a double quote, then we will have double-quoted it
already, so there is no ambiguity.

We test for this case only in the smart protocol, since the DAV-based
protocol is not capable of handling this capability.  We use UTF-8
because this is nicer in our tests and friendlier to Windows, but the
code should work for all non-ASCII refs.

While we're at it, since the name of the option is now well established
and isn't going to change, let's inline it instead of using the #define
constant.

Reported-by: Frej Bjon <frej.bjon@nemit.fi>
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
remote-curl.c
t/t5541-http-push-smart.sh

index e4cd3218447ff385d31d621eb70f67f295f3f92a..0b331faa72bcc5f79a861a782c5b44bba0c5e1ee 100644 (file)
@@ -119,7 +119,11 @@ static int set_option(const char *name, const char *value)
        }
        else if (!strcmp(name, "cas")) {
                struct strbuf val = STRBUF_INIT;
-               strbuf_addf(&val, "--" CAS_OPT_NAME "=%s", value);
+               strbuf_addstr(&val, "--force-with-lease=");
+               if (*value != '"')
+                       strbuf_addstr(&val, value);
+               else if (unquote_c_style(&val, value, NULL))
+                       return -1;
                string_list_append(&cas_options, val.buf);
                strbuf_release(&val);
                return 0;
index 23be8ce92d67824166156cf0c5ca380022b79efc..26c28cec5423f78512d0b784fc14652e2182a5d1 100755 (executable)
@@ -456,6 +456,21 @@ test_expect_success 'push status output scrubs password' '
        grep "^To $HTTPD_URL/smart/test_repo.git" status
 '
 
+test_expect_success 'Non-ASCII branch name can be used with --force-with-lease' '
+       cd "$ROOT_PATH" &&
+       git clone "$HTTPD_URL_USER_PASS/smart/test_repo.git" non-ascii &&
+       cd non-ascii &&
+       git checkout -b rama-de-árbol &&
+       test_commit F &&
+       git push --force-with-lease origin rama-de-árbol &&
+       git ls-remote origin refs/heads/rama-de-árbol >actual &&
+       git ls-remote . refs/heads/rama-de-árbol >expect &&
+       test_cmp expect actual &&
+       git push --delete --force-with-lease origin rama-de-árbol &&
+       git ls-remote origin refs/heads/rama-de-árbol >actual &&
+       test_must_be_empty actual
+'
+
 test_expect_success 'colorize errors/hints' '
        cd "$ROOT_PATH"/test_repo_clone &&
        test_must_fail git -c color.transport=always -c color.advice=always \