diff options
author | Junio C Hamano <gitster@pobox.com> | 2023-04-18 04:05:12 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2023-04-18 04:05:12 +0300 |
commit | 66bf8f19439556da7cf1c8852d07b87257f2a7d9 (patch) | |
tree | 9964ee59639b782a430f1c7c62725c1cd3541076 | |
parent | c232ebacb21829e5001361280b8dec7c30c3a057 (diff) | |
parent | 4c643fb321db00a9c79e2dcd1fd033681333584b (diff) |
Merge branch 'cm/branch-delete-error-message-update'
"git branch -d origin/master" would say "no such branch", but it is
likely a missed "-r" if refs/remotes/origin/master exists. The
command has been taught to give such a hint in its error message.
* cm/branch-delete-error-message-update:
branch: improve error log on branch not found by checking remotes refs
-rw-r--r-- | builtin/branch.c | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/builtin/branch.c b/builtin/branch.c index 6413a016c5..68964eef2d 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -220,10 +220,11 @@ static int delete_branches(int argc, const char **argv, int force, int kinds, struct string_list refs_to_delete = STRING_LIST_INIT_DUP; struct string_list_item *item; int branch_name_pos; + const char *fmt_remotes = "refs/remotes/%s"; switch (kinds) { case FILTER_REFS_REMOTES: - fmt = "refs/remotes/%s"; + fmt = fmt_remotes; /* For subsequent UI messages */ remote_branch = 1; allowed_interpret = INTERPRET_BRANCH_REMOTE; @@ -267,9 +268,25 @@ static int delete_branches(int argc, const char **argv, int force, int kinds, | RESOLVE_REF_ALLOW_BAD_NAME, &oid, &flags); if (!target) { - error(remote_branch - ? _("remote-tracking branch '%s' not found.") - : _("branch '%s' not found."), bname.buf); + if (remote_branch) { + error(_("remote-tracking branch '%s' not found."), bname.buf); + } else { + char *virtual_name = mkpathdup(fmt_remotes, bname.buf); + char *virtual_target = resolve_refdup(virtual_name, + RESOLVE_REF_READING + | RESOLVE_REF_NO_RECURSE + | RESOLVE_REF_ALLOW_BAD_NAME, + &oid, &flags); + FREE_AND_NULL(virtual_name); + + if (virtual_target) + error(_("branch '%s' not found.\n" + "Did you forget --remote?"), + bname.buf); + else + error(_("branch '%s' not found."), bname.buf); + FREE_AND_NULL(virtual_target); + } ret = 1; continue; } |