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

Re: [PATCH] add option -n (--no-checkout) to git-worktree add

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Mar 23, 2016, 15:49 UTC
Message-ID
<CAPig+cR3gQyqaVUeCN0OUAHDOmjYsDQ4LM3O0wj2f3jotchsDg@mail.gmail.com>
In-Reply-To
<01020153a40588f3-5401ea3e-ece8-435c-a046-a5c1c1f92cd6-000000@eu-west-1.amazonses.com>
On Wed, Mar 23, 2016 at 11:08 AM, Ray Zhang <zhanglei002@gmail.com> wrote:
> add option -n (--no-checkout) to git-worktree add
Alternate:
    worktree: add: introduce --no-checkout option
> By adding option -n, we can make some customizations before checkout, like sparse checkout, etc.
This parallels git-clone's --no-checkout. Okay.

Typically, one would not squat on a short option (-n) when first introducing a feature and would only add the short equivalent after the option proved popular, however, in this case, as git-clone supports -n, I suppose finger muscle-memory is a consideration.

By the way, please wrap the commit message at 70-72 characters or so.
> Signed-off-by: Ray Zhang <zhanglei002@gmail.com>
> ---
>  builtin/worktree.c | 14 +++++++++-----
>  1 file changed, 9 insertions(+), 5 deletions(-)

This change needs corresponding documentation (Documentation/git-worktree.txt) and test (t/t2025-worktree-add.sh) updates.

Thanks.
Show 38 quoted lines
> diff --git a/builtin/worktree.c b/builtin/worktree.c
> index 38b5609..14ca3d9 100644
> --- a/builtin/worktree.c
> +++ b/builtin/worktree.c
> @@ -21,6 +21,7 @@ static const char * const worktree_usage[] = {
>  struct add_opts {
>         int force;
>         int detach;
> +       int no_checkout;
>         const char *new_branch;
>         int force_new_branch;
>  };
> @@ -284,11 +285,13 @@ static int add_worktree(const char *path, const char *refname,
>         if (ret)
>                 goto done;
>
> -       cp.argv = NULL;
> -       argv_array_clear(&cp.args);
> -       argv_array_pushl(&cp.args, "reset", "--hard", NULL);
> -       cp.env = child_env.argv;
> -       ret = run_command(&cp);
> +       if (!opts->no_checkout) {
> +               cp.argv = NULL;
> +               argv_array_clear(&cp.args);
> +               argv_array_pushl(&cp.args, "reset", "--hard", NULL);
> +               cp.env = child_env.argv;
> +               ret = run_command(&cp);
> +       }
>         if (!ret) {
>                 is_junk = 0;
>                 free(junk_work_tree);
> @@ -320,6 +323,7 @@ static int add(int ac, const char **av, const char *prefix)
>                 OPT_STRING('B', NULL, &new_branch_force, N_("branch"),
>                            N_("create or reset a branch")),
>                 OPT_BOOL(0, "detach", &opts.detach, N_("detach HEAD at named commit")),
> +               OPT_BOOL('n', "no-checkout", &opts.no_checkout, N_("don't create a checkout")),
>                 OPT_END()
>         };
Previous: Ray ZhangNext: Junio C Hamano
Message 2 of 29 in “add option -n (--no-checkout) to git-worktree add”
  1. add option -n (--no-checkout) to git-worktree addRay Zhang, Mar 23, 2016
  2. Eric SunshineMar 23, 2016
  3. Junio C HamanoMar 23, 2016
  4. Eric SunshineMar 23, 2016
  5. worktree: add: introduce --checkout optionRay Zhang, Mar 24, 2016
  6. Duy NguyenMar 24, 2016
  7. Zhang LeiMar 24, 2016
  8. Eric SunshineMar 25, 2016
  9. Eric SunshineMar 25, 2016
  10. Duy NguyenMar 25, 2016
  11. Zhang LeiMar 25, 2016
  12. Duy NguyenMar 25, 2016
  13. Zhang LeiMar 25, 2016
  14. Duy NguyenMar 25, 2016
  15. Mike RappazzoMar 25, 2016
  16. Eric SunshineMar 25, 2016
  17. worktree: add: introduce --checkout optionRay Zhang, Mar 25, 2016
  18. Eric SunshineMar 27, 2016
  19. worktree: add: introduce --checkout optionRay Zhang, Mar 28, 2016
  20. Junio C HamanoMar 28, 2016
  21. worktree: add: introduce --checkout optionRay Zhang, Mar 29, 2016
  22. John KeepingMar 29, 2016
  23. Eric SunshineMar 29, 2016
  24. John KeepingMar 29, 2016
  25. Junio C HamanoMar 29, 2016
  26. Eric SunshineMar 29, 2016
  27. Zhang LeiMar 30, 2016
  28. Eric SunshineMar 30, 2016
  29. Eric SunshineMar 29, 2016

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.