From: "Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Harald Nordgren <haraldnordgren@gmail.com>
Subject: [PATCH v3 0/2] branch/push: suggest intended form when remote/branch slip given
Date: Sat, 27 Jun 2026 18:02:23 +0000 [thread overview]
Message-ID: <pull.2331.v3.git.git.1782583345.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.2331.v2.git.git.1782338114.gitgitgadget@gmail.com>
When the repository or upstream argument is a slip like "origin/main" or
"origin main", suggest the intended "git push origin main" or "git branch
--set-upstream-to=origin/main" form instead of failing with an unrelated
error.
Changes in v3:
* Reworded the branch commit message to also show the second confusing
error (the requested upstream branch 'origin' does not exist) for when
the operated-on branch does exist.
* Converted the new t5529 tests from bare grep/! grep to test_grep to fix
the test-lint failures.
* Added a brief call-site comment explaining the up-front advice_enabled()
gate (skips the lookups when the hint is off, while advise_if_enabled()
still prints the disable-message footer).
Changes in v2:
* Rewrote both commit messages to lead with the intended command, the easy
slip, and the resulting error, instead of the terse original.
* Gated each suggestion on advice_enabled() up front, so a user who
silenced the hint pays no remote/ref lookups and falls through to the
original error. Extracted the detection logic into helpers
(die_if_repo_looks_like_ref, die_if_upstream_looks_like_remote) so each
call site reads as a single guarded line.
Harald Nordgren (2):
branch: suggest <remote>/<branch> on upstream slip
push: suggest <remote> <branch> for a slash slip
Documentation/config/advice.adoc | 5 +++++
advice.c | 1 +
advice.h | 1 +
builtin/branch.c | 32 +++++++++++++++++++++++++++
builtin/push.c | 37 ++++++++++++++++++++++++++++++-
t/t3200-branch.sh | 38 ++++++++++++++++++++++++++++++++
t/t5529-push-errors.sh | 31 ++++++++++++++++++++++++++
7 files changed, 144 insertions(+), 1 deletion(-)
base-commit: ab776a62a78576513ee121424adb19597fbb7613
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2331%2FHaraldNordgren%2Fsuggest-remote-branch-slips-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2331/HaraldNordgren/suggest-remote-branch-slips-v3
Pull-Request: https://github.com/git/git/pull/2331
Range-diff vs v2:
1: 11bcecebf4 ! 1: 9883c28482 branch: suggest <remote>/<branch> on upstream slip
@@ Commit message
fatal: branch 'main' does not exist
- pointing at a branch the user never meant to name.
+ pointing at a branch the user never meant to name. When 'main' does
+ exist, it instead dies with:
+
+ fatal: the requested upstream branch 'origin' does not exist
+
+ leaving the user equally puzzled.
When the operated-on branch is missing and '<remote>/<branch>' names
a real remote-tracking ref, suggest the intended form:
@@ builtin/branch.c: int cmd_branch(int argc,
if (!refs_ref_exists(get_main_ref_store(the_repository), branch->refname)) {
if (!argc || branch_checked_out(branch->refname))
die(_("no commit on branch '%s' yet"), branch->name);
++ /*
++ * Check the advice up front to avoid the ref
++ * lookups when the hint is off. The helper still
++ * calls advise_if_enabled() so the hint carries the
++ * standard "disable this message" instructions.
++ */
+ if (argc == 1 &&
+ advice_enabled(ADVICE_SET_UPSTREAM_FAILURE))
+ die_if_upstream_looks_like_remote(new_upstream, argv[0]);
2: 49de5a925d ! 2: dbe4dbc346 push: suggest <remote> <branch> for a slash slip
@@ builtin/push.c: int cmd_push(int argc,
if (!add_remote_or_group(repo, &remote_group)) {
+ struct remote *r;
+
++ /*
++ * Check the advice up front to avoid the remote
++ * lookup when the hint is off. The helper still
++ * calls advise_if_enabled() so the hint carries the
++ * standard "disable this message" instructions.
++ */
+ if (advice_enabled(ADVICE_PUSH_REPO_LOOKS_LIKE_REF))
+ die_if_repo_looks_like_ref(repo);
+
@@ t/t5529-push-errors.sh: test_expect_success 'detect empty remote with targeted r
+test_expect_success 'suggest <remote> <branch> for a <remote>/<branch> slip' '
+ test_must_fail git push origin/main 2>stderr &&
-+ grep "${SQ}origin/main${SQ} is not a valid push target" stderr &&
-+ grep "hint: Did you mean to use: git push origin main?" stderr &&
++ test_grep "${SQ}origin/main${SQ} is not a valid push target" stderr &&
++ test_grep "hint: Did you mean to use: git push origin main?" stderr &&
+ test_must_fail git -c advice.pushRepoLooksLikeRef=false push origin/main 2>stderr &&
-+ ! grep "Did you mean" stderr
++ test_grep ! "Did you mean" stderr
+'
+
+test_expect_success 'suggest <remote> <branch> when the branch has slashes' '
+ test_must_fail git push origin/feature/x 2>stderr &&
-+ grep "hint: Did you mean to use: git push origin feature/x?" stderr
++ test_grep "hint: Did you mean to use: git push origin feature/x?" stderr
+'
+
+test_expect_success 'no suggestion when prefix is not a configured remote' '
+ test_must_fail git push not-a-remote/main 2>stderr &&
-+ ! grep "Did you mean" stderr
++ test_grep ! "Did you mean" stderr
+'
+
+test_expect_success 'no suggestion for a trailing slash with no branch' '
+ test_must_fail git push origin/ 2>stderr &&
-+ ! grep "Did you mean" stderr
++ test_grep ! "Did you mean" stderr
+'
+
+test_expect_success 'no suggestion when the argument is an existing path' '
+ test_when_finished "rm -rf origin" &&
+ git init --bare origin/main &&
+ git push origin/main HEAD:refs/heads/pushed 2>stderr &&
-+ ! grep "Did you mean" stderr &&
++ test_grep ! "Did you mean" stderr &&
+ git -C origin/main rev-parse --verify refs/heads/pushed
+'
+
--
gitgitgadget
next prev parent reply other threads:[~2026-06-27 18:02 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-12 11:10 [PATCH 0/2] branch/push: suggest intended form when remote/branch slip given Harald Nordgren via GitGitGadget
2026-06-12 11:10 ` [PATCH 1/2] branch: suggest <remote>/<branch> on upstream slip Harald Nordgren via GitGitGadget
2026-06-22 19:56 ` Junio C Hamano
2026-06-22 21:35 ` Junio C Hamano
2026-06-24 12:35 ` Ben Knoble
2026-06-12 11:10 ` [PATCH 2/2] push: suggest <remote> <branch> for a slash slip Harald Nordgren via GitGitGadget
2026-06-22 20:40 ` Junio C Hamano
2026-06-22 8:41 ` [PATCH 0/2] branch/push: suggest intended form when remote/branch slip given Harald Nordgren
2026-06-22 8:59 ` Weijie Yuan
2026-06-22 21:16 ` Junio C Hamano
2026-06-23 7:35 ` Harald Nordgren
2026-06-24 21:55 ` [PATCH v2 " Harald Nordgren via GitGitGadget
2026-06-24 21:55 ` [PATCH v2 1/2] branch: suggest <remote>/<branch> on upstream slip Harald Nordgren via GitGitGadget
2026-06-24 22:33 ` Junio C Hamano
2026-06-25 7:44 ` Harald Nordgren
2026-06-25 21:16 ` Junio C Hamano
2026-06-24 21:55 ` [PATCH v2 2/2] push: suggest <remote> <branch> for a slash slip Harald Nordgren via GitGitGadget
2026-06-24 22:42 ` Junio C Hamano
2026-06-25 3:36 ` Junio C Hamano
2026-06-25 7:53 ` Harald Nordgren
2026-06-25 13:12 ` Junio C Hamano
2026-06-27 18:02 ` Harald Nordgren via GitGitGadget [this message]
2026-06-27 18:02 ` [PATCH v3 1/2] branch: suggest <remote>/<branch> on upstream slip Harald Nordgren via GitGitGadget
2026-06-27 18:02 ` [PATCH v3 2/2] push: suggest <remote> <branch> for a slash slip Harald Nordgren via GitGitGadget
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=pull.2331.v3.git.git.1782583345.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=git@vger.kernel.org \
--cc=haraldnordgren@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.