Subject: Re: [PATCH] branch: description for non-existent branch errors

From: Junio C Hamano <[email-masked]>
Date: Tue, 27 Sep 2022 15:24:41 -0700

Rubén Justo <[email-masked]> writes:

> I pointed out in the first mail of this thread, there is already a patch in
> 'seen' that touches builtin/branch.c [1].  I would like to keep the patches
> separated, but I don't know how to proceed: make the change from 'seen', keep
> it from 'master'... Maybe you can give me some guidance in this.

I do not see much problem in keeping them separated.  My trial merge
of the result of applying this patch on top of 'master', with the
other topic that has the "branch description for nth prior checkout"
patch does show a minor textual conflict, but the resolution does
not look too bad.

Check near the topic branch of 'seen' after I push out today's
integration result in a few hours and see if they look reasonable.

Thanks.

diff --cc builtin/branch.c
index 5ca35064f3,13d1f028da..2b3884ce61
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@@ -810,19 -807,18 +814,18 @@@ int cmd_branch(int argc, const char **a
  
  		strbuf_addf(&branch_ref, "refs/heads/%s", branch_name);
  		if (!ref_exists(branch_ref.buf)) {
- 			strbuf_release(&branch_ref);
- 
 -			if (!argc)
 +			if (!argc || !strcmp(head, branch_name))
- 				return error(_("No commit on branch '%s' yet."),
+ 				ret = error(_("No commit on branch '%s' yet."),
  					     branch_name);
  			else
- 				return error(_("No branch named '%s'."),
+ 				ret = error(_("No branch named '%s'."),
  					     branch_name);
- 		}
- 		strbuf_release(&branch_ref);
+ 		} else
+ 			ret = edit_branch_description(branch_name);
  
- 		if (edit_branch_description(branch_name))
- 			return 1;
+ 		strbuf_release(&branch_ref);
+ 		strbuf_release(&buf);
+ 		return -ret;
  	} else if (copy) {
  		if (!argc)
  			die(_("branch name required"));