Skip to content

Commit 66bf8f1

Browse files
committed
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
2 parents c232eba + 4c643fb commit 66bf8f1

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

builtin/branch.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,11 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
220220
struct string_list refs_to_delete = STRING_LIST_INIT_DUP;
221221
struct string_list_item *item;
222222
int branch_name_pos;
223+
const char *fmt_remotes = "refs/remotes/%s";
223224

224225
switch (kinds) {
225226
case FILTER_REFS_REMOTES:
226-
fmt = "refs/remotes/%s";
227+
fmt = fmt_remotes;
227228
/* For subsequent UI messages */
228229
remote_branch = 1;
229230
allowed_interpret = INTERPRET_BRANCH_REMOTE;
@@ -267,9 +268,25 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
267268
| RESOLVE_REF_ALLOW_BAD_NAME,
268269
&oid, &flags);
269270
if (!target) {
270-
error(remote_branch
271-
? _("remote-tracking branch '%s' not found.")
272-
: _("branch '%s' not found."), bname.buf);
271+
if (remote_branch) {
272+
error(_("remote-tracking branch '%s' not found."), bname.buf);
273+
} else {
274+
char *virtual_name = mkpathdup(fmt_remotes, bname.buf);
275+
char *virtual_target = resolve_refdup(virtual_name,
276+
RESOLVE_REF_READING
277+
| RESOLVE_REF_NO_RECURSE
278+
| RESOLVE_REF_ALLOW_BAD_NAME,
279+
&oid, &flags);
280+
FREE_AND_NULL(virtual_name);
281+
282+
if (virtual_target)
283+
error(_("branch '%s' not found.\n"
284+
"Did you forget --remote?"),
285+
bname.buf);
286+
else
287+
error(_("branch '%s' not found."), bname.buf);
288+
FREE_AND_NULL(virtual_target);
289+
}
273290
ret = 1;
274291
continue;
275292
}

0 commit comments

Comments
 (0)