git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/1] branch: advise the user to checkout a different branch before deleting

From
Heba Waly <heba.waly@gmail.com>
Date
Jan 6, 2020, 00:42 UTC
Message-ID
<CACg5j25bNcy66R3bCwwc1NQ1F1rEoc=QOPBteyux0Xr6xwHLSQ@mail.gmail.com>
In-Reply-To
<CAPig+cS39vcy6yT3Dg2HfGVCyg2U+7t7Xj85ayM7LaAk3zTjrg@mail.gmail.com>
On Thu, Jan 2, 2020 at 9:18 PM Eric Sunshine <sunshine@sunshineco.com> wrote:
Show 23 quoted lines
>
> On Wed, Jan 1, 2020 at 9:50 PM Heba Waly via GitGitGadget
> <gitgitgadget@gmail.com> wrote:
> > Display a hint to the user when attempting to delete a checked out
> > branch saying "Checkout another branch before deleting this one:
> > git checkout <branch_name>".
> >
> > Currently the user gets an error message saying: "error: Cannot delete
> > branch <branch_name> checked out at <path>". The hint will be displayed
> > after the error message.
> >
> > Signed-off-by: Heba Waly <heba.waly@gmail.com>
> > ---
> > diff --git a/builtin/branch.c b/builtin/branch.c
> > @@ -240,6 +240,8 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
> >                                 error(_("Cannot delete branch '%s' "
> >                                         "checked out at '%s'"),
> >                                       bname.buf, wt->path);
> > +                               advise(_("Checkout another branch before deleting this "
> > +                                                "one: git checkout <branch_name>"));
>
> s/another/a different/ would make the meaning clearer.
>
Ok.
> Let's try to avoid underscores in placeholders. <branch-name> would be
> better, however, git-checkout documentation just calls this <branch>,
> so that's probably a good choice.
>
Yes.
> However, these days, I think we're promoting git-switch rather than
> git-checkout, so perhaps this advice should follow suit.
>
I didn't know that, will change it.
Show 22 quoted lines
> Finally, is this advice sufficient for newcomers when the branch the
> user is trying to delete is in fact checked out in a worktree other
> than the worktree in which the git-branch command is being invoked?
> That is:
>
>     $ pwd
>     /home/me/foo
>     $ git branch -D bip
>     Cannot delete  branch 'bip' checked out at '/home/me/bar'
>     hint: Checkout another branch before deleting this one:
>     hint: git checkout <branch>
>     $ git checkout master # user follows advice
>     $ git branch -D bip
>     Cannot delete  branch 'bip' checked out at '/home/me/foo'
>     hint: Checkout another branch before deleting this one:
>     hint: git checkout <branch>
>     $
>
> And the user is left scratching his or her head wondering why
> git-branch is still showing the error despite following the
> instructions in the hint.
>
Understood.
Show 12 quoted lines
> > diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
> > @@ -808,7 +808,8 @@ test_expect_success 'test deleting branch without config' '
> >  test_expect_success 'deleting currently checked out branch fails' '
> >         git worktree add -b my7 my7 &&
> >         test_must_fail git -C my7 branch -d my7 &&
> > -       test_must_fail git branch -d my7 &&
> > +       test_must_fail git branch -d my7 >actual.out 2>actual.err &&
> > +       test_i18ngrep "hint: Checkout another branch" actual.err &&
>
> Why does this capture standard output into 'actual.out' if that file
> is never consulted?
>
Correct, I missed this one.
> >         rm -r my7 &&
> >         git worktree prune
> >  '
Thanks Eric, will submit an updated version soon.
Heba
Previous: Eric SunshineNext: Heba Waly via GitGitGadget
Message 4 of 18 in “[Outreachy] [RFC] branch: advise the user to checkout a different branch before deleting”
  1. 0/1 [Outreachy] [RFC] branch: advise the user to checkout a different branch before deletingHeba Waly via GitGitGadget, Jan 2, 2020
  2. 1/1 branch: advise the user to checkout a different branch before deletingHeba Waly via GitGitGadget, Jan 2, 2020
  3. Eric SunshineJan 2, 2020
  4. Heba WalyJan 6, 2020
  5. 0/1 [Outreachy] [RFC] branch: advise the user to checkout a different branch before deletingHeba Waly via GitGitGadget, Jan 7, 2020
  6. 1/1 branch: advise the user to checkout a different branch before deletingHeba Waly via GitGitGadget, Jan 7, 2020
  7. Eric SunshineJan 7, 2020
  8. Junio C HamanoJan 7, 2020
  9. Emily ShafferJan 8, 2020
  10. Eric SunshineJan 8, 2020
  11. Heba WalyJan 8, 2020
  12. Eric SunshineJan 8, 2020
  13. Heba WalyJan 8, 2020
  14. Johannes SchindelinJan 8, 2020
  15. Junio C HamanoJan 8, 2020
  16. Heba WalyJan 10, 2020
  17. Junio C HamanoJan 8, 2020
  18. Heba WalyJan 10, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.