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

Re: [PATCH v2] worktree add: shouldn't dwim if -b or -B is given

From
Yoichi Nakayama <yoichi.nakayama@gmail.com>
Date
Aug 19, 2026, 22:01 UTC
Message-ID
<CAF5D8-tbUqLyxhj7pqDmsHJqnN_Pg4QV0C2CcGL6XEqay_BG-A@mail.gmail.com>
In-Reply-To
<pull.2192.v2.git.1785932208004.gitgitgadget@gmail.com>

On Wed, Aug 5, 2026 at 9:16 PM Yoichi NAKAYAMA via GitGitGadget <gitgitgadget@gmail.com> wrote:

Show 32 quoted lines
> diff --git a/builtin/worktree.c b/builtin/worktree.c
> index 654d27c3e1..cc46c1b415 100644
> --- a/builtin/worktree.c
> +++ b/builtin/worktree.c
> @@ -898,16 +898,18 @@ static int add(int ac, const char **av, const char *prefix,
>                 /* DWIM: Infer --orphan when repo has no refs. */
>                 opts.orphan = (!s) && dwim_orphan(&opts, !!opt_track, 1);
>         } else if (ac == 2) {
> -               struct object_id oid;
> -               struct commit *commit;
> -               char *remote;
> -
> -               commit = lookup_commit_reference_by_name(branch);
> -               if (!commit) {
> -                       remote = unique_tracking_name(branch, &oid, NULL);
> -                       if (remote) {
> -                               new_branch = branch;
> -                               branch = new_branch_to_free = remote;
> +               if (!new_branch) {
> +                       struct object_id oid;
> +                       struct commit *commit;
> +                       char *remote;
> +
> +                       commit = lookup_commit_reference_by_name(branch);
> +                       if (!commit) {
> +                               remote = unique_tracking_name(branch, &oid, NULL);
> +                               if (remote) {
> +                                       new_branch = branch;
> +                                       branch = new_branch_to_free = remote;
> +                               }
>                         }
>                 }

To reduce nesting and match the style of the preceding conditions, I'd like to revise this part as follows: (I'll use the commit message modified by Junio with 'log --pretty=reference')

Show 9 quoted lines
> } else if (ac < 2 && new_branch) {
>     ...
> } else if (ac < 2) {
>     ...
> } else if (ac == 2 && new_branch) {
>     if (!strcmp(branch, "HEAD"))
>         can_use_local_refs(&opts);
> } else if (ac = 2) {
>     ...
Thanks,
-- 
Yoichi NAKAYAMA
Previous: Yoichi NakayamaNext: Yoichi NAKAYAMA via GitGitGadget
Message 6 of 10 in “worktree add: shouldn't dwim if -b or -B is given”
  1. worktree add: shouldn't dwim if -b or -B is givenYoichi NAKAYAMA via GitGitGadget, Aug 4, 2026
  2. Junio C HamanoAug 4, 2026
  3. Yoichi NakayamaAug 5, 2026
  4. worktree add: shouldn't dwim if -b or -B is givenYoichi NAKAYAMA via GitGitGadget, Aug 5, 2026
  5. Yoichi NakayamaAug 5, 2026
  6. Yoichi NakayamaAug 19, 2026
  7. worktree add: shouldn't dwim if -b or -B is givenYoichi NAKAYAMA via GitGitGadget, Aug 5, 2026
  8. Junio C HamanoAug 5, 2026
  9. worktree add: shouldn't dwim if -b or -B is givenYoichi NAKAYAMA via GitGitGadget, Aug 20, 2026
  10. Junio C HamanoAug 20, 2026

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.