Re: [PATCH v2] worktree add: shouldn't dwim if -b or -B is given
Yoichi Nakayama <[email protected]>
| Newsgroups | org.kernel.vger.git |
|---|---|
| Message-ID | <CAF5D8-tbUqLyxhj7pqDmsHJqnN_Pg4QV0C2CcGL6XEqay_BG-A@mail.gmail.com> |
On Wed, Aug 5, 2026 at 9:16 PM Yoichi NAKAYAMA via GitGitGadget <[email protected]> wrote: > 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') > } 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