From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.180 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796399106; b=xORieWyQbj8IP1Yu/p0s8P1tKaUV3Fr2CV6uyZQN0JJ8pscjVMYCVGzQ1BwqvgD+9SNt iXwsp88np50pbj8n4IgKgU8k2bFcw5dsRKsveKD35vheBcXlubDImfIE2kSHubVHS0yWR O4Y4tu7IEiwEABRAOf1zKk6RB9GLtXnWg68lwx1t2O1ZGXN5vgVrRKjTR4/f+qehpnTzK ux+AuxJl/YCXyTDled3ygfb3+ykPVku1RdzQHEjCoExJjs70h+yEMhv2wBo4ta2dw2BHI nnaFpyx69SA4Iy8NnoA3x91z0VyZVq998zuHD9ciyGrN4K9Mn7om5alDOY1WzfOLFdA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796399106; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:Message-Id:In-Reply-To: References:From:Date:Subject:Fcc:Content-Type: Content-Transfer-Encoding:MIME-Version:To:Cc; bh=jp/P2cIHf1PEd7b0QwWkpunHxqyVre4zGko9kSYpO84=; b=AJaXzLoAX2RnQyceOSd69w6gNf3Qd0UViNCRns9DUUi9op1eAAoNhjZp8w9nppgsnV5O JCZcH7H9Pa0DZfIg8X+uBYp8agmNkKrGm/SdY5bzmo1UXgyHMxS7SAqm9Z8XphwO+JD0q PZtp/HoK9CRaGnScyP7MfjnYETVvXTV98CL5lVZOQ1AsTbp0sjyeJo++iUZKgmBeZE4+4 VhUbSr4GX50FTl6mQtqBaVmZzn/nmCqdeNwKK27wU76Oeo9iLZNKb4fd1gzZBnUhpsRgm PvgC8Y2uLdqLXWUoY/JD2Bq8Wytc3RrVb6SVJ18/Le7SsKL1W2Ir8/fkjN3arNWxjow== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=bKAdaT0Q; arc=none smtp.remote-ip=209.85.167.180 Received: from mail-oi1-f180.google.com (mail-oi1-f180.google.com [209.85.167.180]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D6FCA606A32F for ; Fri, 4 Dec 2026 15:45:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D6FCA606A32F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=bKAdaT0Q Received: by mail-oi1-f180.google.com with SMTP id 5614622812f47-4b28d7c729fso850925b6e.0 for ; Fri, 04 Dec 2026 07:45:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796399105; x=1797003905; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:content-type:fcc :subject:date:from:references:in-reply-to:message-id:from:to:cc :subject:date:message-id:reply-to:content-type; bh=jp/P2cIHf1PEd7b0QwWkpunHxqyVre4zGko9kSYpO84=; b=bKAdaT0Qw4al1XXugAdh3IvWnYPCTpFQTwjqOSvEHbqZPV4Wh+/QYaoiEmYnOkdvkU H2S+UTi36ccI3y9eyq6mcJUJ+F7r7LWz36ja2aG4OdNdnr6QmfdnptFtdwvaSRVb5LWU NRE4JjafvrrT3YNCAJV7Z1VViZv+IiTsTUuOyOdy2TOGjAMh/ULBaN+RdmJqTAz/9pxC bwzgp5TewbSO3fangY50fUIQ1ORB0fi3FSbI5/nW+gMt87mDMJcLjlr6OyFWJZhEZA32 djGgYWZX5Q/kUz5YVGn57iFeSgF8tgcssKZj2fTMRtSY66RTWlu3+/wIidJ/oLHUwJ80 QAPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796399105; x=1797003905; h=cc:to:mime-version:content-transfer-encoding:content-type:fcc :subject:date:from:references:in-reply-to:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=jp/P2cIHf1PEd7b0QwWkpunHxqyVre4zGko9kSYpO84=; b=Jfocf814QGbrfPNdGOwRDhZcVUae4ZsVeKgz9AnwHcdN6gqrMjVE7LEx717haeas9/ RG7K8TqOHB7t3y0r4NWXLzUy3geqrzI6VaOjyXL47Jgb46O36I3lxUOOUBw0gR3biLWb 0SmWmW1dfpNaFr8mLoQUIXE+DunALNbgoy6Aj5h3RK/5XOiG+Ib7WnzT45MG963lTTYZ MOja1WNFyCD2NuA2yX0F3Qzzmx2aT+l4NpN4uiAA49ogwphfPDDBh0N2PwVTfPQ7lJZK xEtkLoMMiaxbMjGVCTHirbpWuP0N9cQN5LDIs1+NcH0X0C2mnq0P08hF5O0DOn0kBSV9 U3Cg== X-Gm-Message-State: APuU4Z869tKmHbYomVOkMFO5/jyHqSoHgVyzECqgqVHk4OWfhN+n01mm MCjw/yKT2Z1hCrSOV9axQpvvX6ujuXM2cXWSQMTcSBC8dA+AalrOLUXOoWAT+dSsvCc= X-Gm-Gg: AZFdTZcmmAT+Ze36n2bv92M5ZLuh0rnXc2bxBqnlCpW0IzmodrBQaED+9n+dp2ZKZO+ oBc5BI0xeDSDUuiG7tsq0Es921Wt0ck3jz0ndbFDolNLSgoiD2s/A17XI+vBF5lh5T83IK9njNb nwG20D0LLhSKaRqGZi99fwL3WFgm66HLP+5uB2/7Q4+/WH2Bfj/gmcsSo+VfANUNFtucO9ndEEh diOvZi1MypsyYGYW62pOnk1C3oDrXaKw4a7xONCi1irG4cfG6Y5atWiBG4uZzC+RkjsfbvQnYlE tghA+R/M9VL0Mk3eqedh3HCNGD1rI6mLN1QYgw7+jg1aeKRXDgOX/N1kvHJ+0Smn91U+p3/ohki JnYx/cBY+moyj62cJaHerCb3dMNRzcB0iUNsztDDTz7M1Wy2OnfPS6/3V9pEo+B2HrsSiiC3ElL b1o1+iV5ZjAG3tb0vhuGHy/RN0R7EZ+B2IWrX2ZVUZqQ2ne77jpi7Fy3b/SMllWFgLebp2gqkyl STggPresDksQYJHK6RNHY6xC2s+4h5+miICS1L/PlmqH4+MANuNttOr525OjQoEYY1toHMWMmwh WZV4384RPsuuYivQumnMy0fXMqi7g6gg+w== X-Received: by 2002:a05:6820:4008:b0:702:f7c2:1937 with SMTP id 006d021491bc7-71bf22d0250mr1615968eaf.83.1796399104436; Fri, 04 Dec 2026 07:45:04 -0800 (PST) Received: from [127.0.0.1] ([52.240.173.186]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-71bef100282sm2720657eaf.7.2026.12.04.07.45.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 07:45:03 -0800 (PST) Message-Id: In-Reply-To: References: From: "Nahid Hasan via GitGitGadget" Date: Fri, 04 Dec 2026 15:45:03 +0000 Subject: [PATCH v3] push: shell-quote names in suggested push commands Fcc: Sent Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Mailing-List: git@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 To: git@vger.kernel.org Cc: Patrick Steinhardt , Nahid Hasan , MD Nahid Hasan Sagor From: MD Nahid Hasan Sagor Branch and remote names in Git may contain shell metacharacters such as '&', ';', and '$'. When 'git push' fails and prints a suggested command to copy and paste, those names are formatted without shell quoting. Copying that suggestion into a POSIX shell splits the line; for example: git push --set-upstream origin feat-&-test backgrounds 'git push --set-upstream origin feat-' and tries to run '-test' as a separate command. Format the remote, branch, and ref names in the suggested 'git push' commands in 'builtin/push.c' with 'sq_quote_buf_pretty()' so names that need quoting are wrapped in single quotes while plain names stay bare. A 'HEAD:' refspec is quoted as one shell word, and the detached-HEAD hint in 'setup_default_push_refspecs()' quotes the remote name as well. Signed-off-by: MD Nahid Hasan Sagor --- push: shell-quote names in suggested push commands Changes since v2: * Replaced backticks with single quotes in the commit message. * Shortened the quoting comment in die_push_simple() to a one-liner, while keeping the comment in get_upstream_ref() explaining why the surrounding prose stays unquoted. * Kept the separate 'refspec' buffer in die_push_simple(): when no quoting is needed, sq_quote_buf_pretty() falls back to strbuf_addstr(), which would duplicate plain refspecs (e.g., "HEAD:mainHEAD:main") if source and destination shared the same buffer. * Trimmed t/t5529-push-errors.sh down to a single concise test covering a remote and ref with shell metacharacters. Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2336%2Fnahidhasan141400%2Ffix-push-upstream-quoting-v3 Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2336/nahidhasan141400/fix-push-upstream-quoting-v3 Pull-Request: https://github.com/gitgitgadget/git/pull/2336 Range-diff vs v2: 1: dad0b1673d ! 1: a74b54f926 push: shell-quote names in suggested push commands @@ Commit message push: shell-quote names in suggested push commands Branch and remote names in Git may contain shell metacharacters such - as '&', ';', and '$'. When `git push` fails and prints a suggested + as '&', ';', and '$'. When 'git push' fails and prints a suggested command to copy and paste, those names are formatted without shell quoting. Copying that suggestion into a POSIX shell splits the line; for example: git push --set-upstream origin feat-&-test - backgrounds `git push --set-upstream origin feat-` and tries to run - `-test` as a separate command. + backgrounds 'git push --set-upstream origin feat-' and tries to run + '-test' as a separate command. - Format the remote, branch, and ref names in the suggested `git push` - commands in `builtin/push.c` with `sq_quote_buf_pretty()` so names + Format the remote, branch, and ref names in the suggested 'git push' + commands in 'builtin/push.c' with 'sq_quote_buf_pretty()' so names that need quoting are wrapped in single quotes while plain names stay - bare. A HEAD: refspec is quoted as one shell word, and the - detached-HEAD hint in setup_default_push_refspecs() quotes the remote + bare. A 'HEAD:' refspec is quoted as one shell word, and the + detached-HEAD hint in 'setup_default_push_refspecs()' quotes the remote name as well. Signed-off-by: MD Nahid Hasan Sagor @@ builtin/push.c: static NORETURN void die_push_simple(struct branch *branch, "'simple' of branch.autoSetupMerge\n" "in 'git help config'.\n"); + -+ /* -+ * Quote for copy-paste into a POSIX shell. Ordinary names stay -+ * bare; metacharacters are wrapped in single quotes. -+ */ ++ /* Quote for copy-paste into a POSIX shell. */ + strbuf_addf(&refspec, "HEAD:%s", short_upstream); + sq_quote_buf_pretty("ed_remote, remote->name); + sq_quote_buf_pretty("ed_refspec, refspec.buf); @@ t/t5529-push-errors.sh: test_expect_success 'detect ambiguous refs early' ' test_cmp expect rp-ran ' -+# How a POSIX shell splits a copy-paste command line. -+shell_split () { -+ line=$1 -+ eval "set -- $line" -+ printf "%s\n" "$#" "$@" -+} -+ -+test_expect_success 'no-upstream advice leaves ordinary names unquoted' ' -+ test_must_fail git -c push.default=simple push origin 2>stderr && -+ test_grep -F "The current branch main has no upstream branch." stderr && -+ test_grep -F " git push --set-upstream origin main" stderr && -+ test_grep ! -F "git push --set-upstream ${SQ}origin${SQ}" stderr && -+ test_grep ! -F "git push --set-upstream origin ${SQ}main${SQ}" stderr -+' -+ -+test_expect_success 'simple push mismatch leaves ordinary names unquoted' ' -+ test_config branch.main.remote origin && -+ test_config branch.main.merge refs/heads/other-name && -+ test_must_fail git -c push.default=simple push origin 2>stderr && -+ printf "%s\n" \ -+ "git push origin HEAD:other-name" \ -+ "git push origin HEAD" >expect && -+ sed -n "/^ git push /s/^ //p" stderr >actual && -+ test_cmp expect actual -+' -+ -+test_expect_success 'no-upstream advice quotes metacharacters only in the command' ' -+ git remote add "weird&remote" remote.git && -+ test_when_finished "git remote remove \"weird&remote\"" && -+ test_when_finished "git branch -D ${SQ}feat-&;\$name${SQ}" && -+ test_when_finished "git checkout main" && -+ git checkout -b "feat-&;\$name" && -+ test_config "branch.feat-&;\$name.remote" "weird&remote" && -+ test_must_fail git -c push.default=simple push "weird&remote" 2>stderr && -+ test_grep -F "The current branch feat-&;\$name has no upstream branch." stderr && -+ test_grep ! -F "The current branch ${SQ}feat-&;\$name${SQ} has no upstream" stderr && -+ printf "%s\n" \ -+ "git push --set-upstream ${SQ}weird&remote${SQ} ${SQ}feat-&;\$name${SQ}" >expect && -+ sed -n "/^ git push /s/^ //p" stderr >actual && -+ test_cmp expect actual && -+ shell_split "$(cat actual)" >actual-split && -+ printf "%s\n" 5 git push --set-upstream "weird&remote" "feat-&;\$name" >expect-split && -+ test_cmp expect-split actual-split -+' -+ -+test_expect_success 'simple push mismatch quotes remote and upstream names' ' -+ git checkout main && -+ git remote add "weird&remote" remote.git && -+ test_when_finished "git remote remove \"weird&remote\"" && -+ test_config branch.main.remote "weird&remote" && -+ test_config branch.main.merge "refs/heads/feat-&;\$name" && -+ test_must_fail git -c push.default=simple push "weird&remote" 2>stderr && -+ printf "%s\n" \ -+ "git push ${SQ}weird&remote${SQ} ${SQ}HEAD:feat-&;\$name${SQ}" \ -+ "git push ${SQ}weird&remote${SQ} HEAD" >expect && -+ sed -n "/^ git push /s/^ //p" stderr >actual && -+ test_cmp expect actual && -+ { -+ while IFS= read -r line -+ do -+ shell_split "$line" || return 1 -+ done actual-split && -+ printf "%s\n" \ -+ 4 git push "weird&remote" "HEAD:feat-&;\$name" \ -+ 4 git push "weird&remote" HEAD >expect-split && -+ test_cmp expect-split actual-split -+' -+ +test_expect_success 'slash-slip advice quotes remote and ref metacharacters' ' + git remote add "weird&remote" remote.git && + test_when_finished "git remote remove \"weird&remote\"" && -+ + test_must_fail git push "weird&remote/feat-&-test" 2>stderr && -+ test_grep -F "hint: Did you mean to use: git push ${SQ}weird&remote${SQ} ${SQ}feat-&-test${SQ}?" stderr && -+ hint=$(sed -n "s/.*Did you mean to use: //p" stderr) && -+ hint=${hint%?} && -+ shell_split "$hint" >actual-split && -+ printf "%s\n" 4 git push "weird&remote" "feat-&-test" >expect-split && -+ test_cmp expect-split actual-split && -+ -+ test_must_fail git push "origin/feat;id" 2>stderr && -+ test_grep -F "hint: Did you mean to use: git push origin ${SQ}feat;id${SQ}?" stderr && -+ -+ test_must_fail git push "origin/feat\$name" 2>stderr && -+ test_grep -F "hint: Did you mean to use: git push origin ${SQ}feat\$name${SQ}?" stderr && -+ -+ test_must_fail git push "origin/feat & test" 2>stderr && -+ test_grep -F "hint: Did you mean to use: git push origin ${SQ}feat & test${SQ}?" stderr && -+ hint=$(sed -n "s/.*Did you mean to use: //p" stderr) && -+ hint=${hint%?} && -+ shell_split "$hint" >actual-split && -+ printf "%s\n" 4 git push origin "feat & test" >expect-split && -+ test_cmp expect-split actual-split && -+ -+ test_must_fail git push "origin/feat${SQ}test" 2>stderr && -+ test_grep -F "hint: Did you mean to use: git push origin ${SQ}feat${SQ}\\${SQ}${SQ}test${SQ}?" stderr ++ test_grep -F "hint: Did you mean to use: git push ${SQ}weird&remote${SQ} ${SQ}feat-&-test${SQ}?" stderr +' + test_done builtin/push.c | 45 +++++++++++++++++++++++++++++++++------- t/t5523-push-upstream.sh | 8 +++++++ t/t5528-push-default.sh | 17 +++++++++++++++ t/t5529-push-errors.sh | 7 +++++++ 4 files changed, 69 insertions(+), 8 deletions(-) diff --git a/builtin/push.c b/builtin/push.c index 2377b5af55..83359f1408 100644 --- a/builtin/push.c +++ b/builtin/push.c @@ -18,6 +18,7 @@ #include "transport.h" #include "parse-options.h" #include "pkt-line.h" +#include "quote.h" #include "submodule.h" #include "submodule-config.h" #include "send-pack.h" @@ -155,6 +156,9 @@ static NORETURN void die_push_simple(struct branch *branch, const char *advice_automergesimple_maybe = ""; const char *short_upstream = branch->merge[0]->src; struct repo_config_values *cfg = repo_config_values(the_repository); + struct strbuf quoted_remote = STRBUF_INIT; + struct strbuf refspec = STRBUF_INIT; + struct strbuf quoted_refspec = STRBUF_INIT; skip_prefix(short_upstream, "refs/heads/", &short_upstream); @@ -173,18 +177,23 @@ static NORETURN void die_push_simple(struct branch *branch, "won't match the local branch, see option " "'simple' of branch.autoSetupMerge\n" "in 'git help config'.\n"); + + /* Quote for copy-paste into a POSIX shell. */ + strbuf_addf(&refspec, "HEAD:%s", short_upstream); + sq_quote_buf_pretty("ed_remote, remote->name); + sq_quote_buf_pretty("ed_refspec, refspec.buf); die(_("The upstream branch of your current branch does not match\n" "the name of your current branch. To push to the upstream branch\n" "on the remote, use\n" "\n" - " git push %s HEAD:%s\n" + " git push %s %s\n" "\n" "To push to the branch of the same name on the remote, use\n" "\n" " git push %s HEAD\n" "%s%s"), - remote->name, short_upstream, - remote->name, advice_pushdefault_maybe, + quoted_remote.buf, quoted_refspec.buf, + quoted_remote.buf, advice_pushdefault_maybe, advice_automergesimple_maybe); } @@ -204,6 +213,9 @@ static const char *get_upstream_ref(int flags, struct branch *branch, const char if (!branch->merge_nr || !branch->merge || !branch->remote_name) { const char *advice_autosetup_maybe = ""; + struct strbuf quoted_remote = STRBUF_INIT; + struct strbuf quoted_branch = STRBUF_INIT; + if (!(flags & TRANSPORT_PUSH_AUTO_UPSTREAM)) { advice_autosetup_maybe = _("\n" "To have this happen automatically for " @@ -211,14 +223,20 @@ static const char *get_upstream_ref(int flags, struct branch *branch, const char "upstream, see 'push.autoSetupRemote' " "in 'git help config'.\n"); } + /* + * The prose keeps the raw branch name. Only the + * copy-pasteable command is shell-quoted. + */ + sq_quote_buf_pretty("ed_remote, remote_name); + sq_quote_buf_pretty("ed_branch, branch->name); die(_("The current branch %s has no upstream branch.\n" "To push the current branch and set the remote as upstream, use\n" "\n" " git push --set-upstream %s %s\n" "%s"), branch->name, - remote_name, - branch->name, + quoted_remote.buf, + quoted_branch.buf, advice_autosetup_maybe); } if (branch->merge_nr != 1) @@ -249,8 +267,12 @@ static void setup_default_push_refspecs(int *flags, struct remote *remote) } branch = branch_get(NULL); - if (!branch) - die(_(message_detached_head_die), remote->name); + if (!branch) { + struct strbuf quoted_remote = STRBUF_INIT; + + sq_quote_buf_pretty("ed_remote, remote->name); + die(_(message_detached_head_die), quoted_remote.buf); + } dst = branch->refname; same_remote = !strcmp(remote->name, remote_for_branch(branch, NULL)); @@ -669,6 +691,8 @@ static void die_if_repo_looks_like_ref(const char *repo) { const char *slash = strchr(repo, '/'); struct strbuf name = STRBUF_INIT; + struct strbuf quoted_remote = STRBUF_INIT; + struct strbuf quoted_ref = STRBUF_INIT; int code; if (!slash || !slash[1] || file_exists(repo)) @@ -680,11 +704,16 @@ static void die_if_repo_looks_like_ref(const char *repo) return; } + sq_quote_buf_pretty("ed_remote, name.buf); + sq_quote_buf_pretty("ed_ref, slash + 1); + code = die_message(_("'%s' is not a valid push target"), repo); advise_if_enabled(ADVICE_PUSH_REPO_LOOKS_LIKE_REF, _("Did you mean to use: git push %s %s?"), - name.buf, slash + 1); + quoted_remote.buf, quoted_ref.buf); strbuf_release(&name); + strbuf_release("ed_remote); + strbuf_release("ed_ref); exit(code); } diff --git a/t/t5523-push-upstream.sh b/t/t5523-push-upstream.sh index 22d3e1162c..23b20b0419 100755 --- a/t/t5523-push-upstream.sh +++ b/t/t5523-push-upstream.sh @@ -134,4 +134,12 @@ test_expect_success TTY 'quiet push -u' ' test_must_be_empty output ' +test_expect_success 'no-upstream advice quotes a branch name with metacharacters' ' + test_when_finished "git branch -D \"branch&name\"" && + test_when_finished "git checkout main" && + git checkout -b "branch&name" && + test_must_fail git push upstream 2>stderr && + test_grep "git push --set-upstream upstream ${SQ}branch&name${SQ}" stderr +' + test_done diff --git a/t/t5528-push-default.sh b/t/t5528-push-default.sh index 2bd8759a68..0c009f3543 100755 --- a/t/t5528-push-default.sh +++ b/t/t5528-push-default.sh @@ -294,4 +294,21 @@ test_expect_success 'default triangular behavior acts like "current"' ' test_push_success "" main repo2 ' +test_expect_success 'simple push quotes an upstream branch name with metacharacters' ' + test_config branch.main.remote parent1 && + test_config branch.main.merge "refs/heads/upstream&name" && + git checkout main && + test_must_fail git -c push.default=simple push parent1 2>stderr && + test_grep "git push parent1 ${SQ}HEAD:upstream&name${SQ}" stderr +' + +test_expect_success 'detached HEAD advice quotes a remote name with metacharacters' ' + git remote add "weird&remote" repo1 && + test_when_finished "git remote remove \"weird&remote\"" && + test_when_finished "git checkout main" && + git checkout --detach && + test_must_fail git push "weird&remote" 2>stderr && + test_grep " git push ${SQ}weird&remote${SQ} HEAD:" stderr +' + test_done diff --git a/t/t5529-push-errors.sh b/t/t5529-push-errors.sh index 5f8aa1ed19..85ec11165c 100755 --- a/t/t5529-push-errors.sh +++ b/t/t5529-push-errors.sh @@ -94,4 +94,11 @@ test_expect_success 'detect ambiguous refs early' ' test_cmp expect rp-ran ' +test_expect_success 'slash-slip advice quotes remote and ref metacharacters' ' + git remote add "weird&remote" remote.git && + test_when_finished "git remote remove \"weird&remote\"" && + test_must_fail git push "weird&remote/feat-&-test" 2>stderr && + test_grep -F "hint: Did you mean to use: git push ${SQ}weird&remote${SQ} ${SQ}feat-&-test${SQ}?" stderr +' + test_done base-commit: 566b6997dd4710b625c0882cf10a7443bf52d183 -- gitgitgadget