Message ID | 20221104010242.11555-3-jacobabel@nullpo.dev (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | worktree: Support `--orphan` when creating new worktrees | expand |
On Fri, Nov 04 2022, Jacob Abel wrote: > Updates the function to call `git checkout` instead of > `git reset --hard` to simplify adding orphan support. > > Signed-off-by: Jacob Abel <jacobabel@nullpo.dev> > --- > builtin/worktree.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/builtin/worktree.c b/builtin/worktree.c > index b3373fbbd6..d40f771848 100644 > --- a/builtin/worktree.c > +++ b/builtin/worktree.c > @@ -357,7 +357,7 @@ static int checkout_worktree(const struct add_opts *opts, > { > struct child_process cp = CHILD_PROCESS_INIT; > cp.git_cmd = 1; > - strvec_pushl(&cp.args, "reset", "--hard", "--no-recurse-submodules", NULL); > + strvec_pushl(&cp.args, "checkout", "--no-recurse-submodules", NULL); > if (opts->quiet) > strvec_push(&cp.args, "--quiet"); > strvec_pushv(&cp.env, child_env->v); Won't we now start to run the post-checkout when doing this, and is that intended?
On 22/11/04 02:32AM, Ævar Arnfjörð Bjarmason wrote: > > Won't we now start to run the post-checkout when doing this, and is that > intended? It appears it will. `git worktree add` runs the hook manually later after the `done` label so I can suppress the initial hook run in v2. Is there a sanctioned way to do this beyond `-c core.hooksPath=/dev/null`? This seems hacky to put it lightly. Alternatively would `git symbolic-ref HEAD "refs/heads/${new_branch_name}"` work instead (along with reverting the change from reset to checkout) when creating an orphan branch? It appears to work based on my quick tests but there's something I might be missing.
On Fri, Nov 04, 2022 at 02:32:11AM +0100, Ævar Arnfjörð Bjarmason wrote: > > @@ -357,7 +357,7 @@ static int checkout_worktree(const struct add_opts *opts, > > { > > struct child_process cp = CHILD_PROCESS_INIT; > > cp.git_cmd = 1; > > - strvec_pushl(&cp.args, "reset", "--hard", "--no-recurse-submodules", NULL); > > + strvec_pushl(&cp.args, "checkout", "--no-recurse-submodules", NULL); > > if (opts->quiet) > > strvec_push(&cp.args, "--quiet"); > > strvec_pushv(&cp.env, child_env->v); > > Won't we now start to run the post-checkout when doing this, and is that > intended? Beyond that, does the change between `reset --hard` and `checkout`'s treatment of modified files in the working copy matter? I don't know enough about the worktree code off-hand to know if this function will ever run in an already-populated worktree that may be carrying its own modifications. Thanks, Taylor
diff --git a/builtin/worktree.c b/builtin/worktree.c index b3373fbbd6..d40f771848 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -357,7 +357,7 @@ static int checkout_worktree(const struct add_opts *opts, { struct child_process cp = CHILD_PROCESS_INIT; cp.git_cmd = 1; - strvec_pushl(&cp.args, "reset", "--hard", "--no-recurse-submodules", NULL); + strvec_pushl(&cp.args, "checkout", "--no-recurse-submodules", NULL); if (opts->quiet) strvec_push(&cp.args, "--quiet"); strvec_pushv(&cp.env, child_env->v);
Updates the function to call `git checkout` instead of `git reset --hard` to simplify adding orphan support. Signed-off-by: Jacob Abel <jacobabel@nullpo.dev> --- builtin/worktree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.37.4