]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'rj/branch-edit-description-with-nth-checkout'
authorJunio C Hamano <gitster@pobox.com>
Fri, 21 Oct 2022 18:37:29 +0000 (11:37 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 21 Oct 2022 18:37:29 +0000 (11:37 -0700)
"git branch --edit-description @{-1}" is now a way to edit branch
description of the branch you were on before switching to the
current branch.

* rj/branch-edit-description-with-nth-checkout:
  branch: support for shortcuts like @{-1}, completed

1  2 
builtin/branch.c

index e0e0af432024bb6db1802dec92fe48bab9da3157,658c9f87414b61acf2072d75684f952f8565ff10..407517ba68447322b0e9a4ccaff2df5fc83186e9
@@@ -805,26 -798,26 +807,26 @@@ int cmd_branch(int argc, const char **a
                        if (filter.detached)
                                die(_("Cannot give description to detached HEAD"));
                        branch_name = head;
-               } else if (argc == 1)
-                       branch_name = argv[0];
-               else
+               } else if (argc == 1) {
+                       strbuf_branchname(&buf, argv[0], INTERPRET_BRANCH_LOCAL);
+                       branch_name = buf.buf;
+               } else {
                        die(_("cannot edit description of more than one branch"));
+               }
  
                strbuf_addf(&branch_ref, "refs/heads/%s", branch_name);
-               if (!ref_exists(branch_ref.buf)) {
-                       strbuf_release(&branch_ref);
-                       if (!argc || !strcmp(head, branch_name))
-                               return error(_("No commit on branch '%s' yet."),
-                                            branch_name);
-                       else
-                               return error(_("No branch named '%s'."),
-                                            branch_name);
-               }
+               if (!ref_exists(branch_ref.buf))
 -                      ret = error(!argc
++                      ret = error((!argc || !strcmp(head, branch_name))
+                             ? _("No commit on branch '%s' yet.")
+                             : _("No branch named '%s'."),
+                             branch_name);
+               else if (!edit_branch_description(branch_name))
+                       ret = 0; /* happy */
                strbuf_release(&branch_ref);
+               strbuf_release(&buf);
  
-               if (edit_branch_description(branch_name))
-                       return 1;
+               return ret;
        } else if (copy) {
                if (!argc)
                        die(_("branch name required"));