{"thread":{"id":"41797","subject":"[PATCH] add option -n (--no-checkout) to git-worktree add","startedAt":"2016-03-23T15:08:59Z","lastAt":"2016-03-30T17:59:27Z","messageCount":29,"participants":["Ray Zhang","Eric Sunshine","Junio C Hamano","Duy Nguyen","Zhang Lei","Mike Rappazzo","John Keeping"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"281583","messageId":"01020153a40588f3-5401ea3e-ece8-435c-a046-a5c1c1f92cd6-000000@eu-west-1.amazonses.com","threadId":"41797","inReplyTo":null,"subject":"[PATCH] add option -n (--no-checkout) to git-worktree add","fromName":"Ray Zhang","fromEmail":"zhanglei002@gmail.com","sentAt":"2016-03-23T15:08:59Z","receivedAt":"2016-03-23T15:08:59Z","isPatch":true,"sender":{"key":"zhanglei002@gmail.com","avatar":"https://avatars.githubusercontent.com/u/4970552?v=4"},"body":"By adding option -n, we can make some customizations before checkout, like sparse checkout, etc.\n\nSigned-off-by: Ray Zhang <zhanglei002@gmail.com>\n---\n builtin/worktree.c | 14 +++++++++-----\n 1 file changed, 9 insertions(+), 5 deletions(-)\n\ndiff --git a/builtin/worktree.c b/builtin/worktree.c\nindex 38b5609..14ca3d9 100644\n--- a/builtin/worktree.c\n+++ b/builtin/worktree.c\n@@ -21,6 +21,7 @@ static const char * const worktree_usage[] = {\n struct add_opts {\n \tint force;\n \tint detach;\n+\tint no_checkout;\n \tconst char *new_branch;\n \tint force_new_branch;\n };\n@@ -284,11 +285,13 @@ static int add_worktree(const char *path, const char *refname,\n \tif (ret)\n \t\tgoto done;\n \n-\tcp.argv = NULL;\n-\targv_array_clear(&cp.args);\n-\targv_array_pushl(&cp.args, \"reset\", \"--hard\", NULL);\n-\tcp.env = child_env.argv;\n-\tret = run_command(&cp);\n+\tif (!opts->no_checkout) {\n+\t\tcp.argv = NULL;\n+\t\targv_array_clear(&cp.args);\n+\t\targv_array_pushl(&cp.args, \"reset\", \"--hard\", NULL);\n+\t\tcp.env = child_env.argv;\n+\t\tret = run_command(&cp);\n+\t}\n \tif (!ret) {\n \t\tis_junk = 0;\n \t\tfree(junk_work_tree);\n@@ -320,6 +323,7 @@ static int add(int ac, const char **av, const char *prefix)\n \t\tOPT_STRING('B', NULL, &new_branch_force, N_(\"branch\"),\n \t\t\t   N_(\"create or reset a branch\")),\n \t\tOPT_BOOL(0, \"detach\", &opts.detach, N_(\"detach HEAD at named commit\")),\n+\t\tOPT_BOOL('n', \"no-checkout\", &opts.no_checkout, N_(\"don't create a checkout\")),\n \t\tOPT_END()\n \t};\n \n\n--\nhttps://github.com/git/git/pull/217\n"},{"id":"281585","messageId":"CAPig+cR3gQyqaVUeCN0OUAHDOmjYsDQ4LM3O0wj2f3jotchsDg@mail.gmail.com","threadId":"41797","inReplyTo":"01020153a40588f3-5401ea3e-ece8-435c-a046-a5c1c1f92cd6-000000@eu-west-1.amazonses.com","subject":"Re: [PATCH] add option -n (--no-checkout) to git-worktree add","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2016-03-23T15:49:33Z","receivedAt":"2016-03-23T15:49:33Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Wed, Mar 23, 2016 at 11:08 AM, Ray Zhang <zhanglei002@gmail.com> wrote:\n> add option -n (--no-checkout) to git-worktree add\n\nAlternate:\n\n    worktree: add: introduce --no-checkout option\n\n> By adding option -n, we can make some customizations before checkout, like sparse checkout, etc.\n\nThis parallels git-clone's --no-checkout. Okay.\n\nTypically, one would not squat on a short option (-n) when first\nintroducing a feature and would only add the short equivalent after\nthe option proved popular, however, in this case, as git-clone\nsupports -n, I suppose finger muscle-memory is a consideration.\n\nBy the way, please wrap the commit message at 70-72 characters or so.\n\n> Signed-off-by: Ray Zhang <zhanglei002@gmail.com>\n> ---\n>  builtin/worktree.c | 14 +++++++++-----\n>  1 file changed, 9 insertions(+), 5 deletions(-)\n\nThis change needs corresponding documentation\n(Documentation/git-worktree.txt) and test (t/t2025-worktree-add.sh)\nupdates.\n\nThanks.\n\n> diff --git a/builtin/worktree.c b/builtin/worktree.c\n> index 38b5609..14ca3d9 100644\n> --- a/builtin/worktree.c\n> +++ b/builtin/worktree.c\n> @@ -21,6 +21,7 @@ static const char * const worktree_usage[] = {\n>  struct add_opts {\n>         int force;\n>         int detach;\n> +       int no_checkout;\n>         const char *new_branch;\n>         int force_new_branch;\n>  };\n> @@ -284,11 +285,13 @@ static int add_worktree(const char *path, const char *refname,\n>         if (ret)\n>                 goto done;\n>\n> -       cp.argv = NULL;\n> -       argv_array_clear(&cp.args);\n> -       argv_array_pushl(&cp.args, \"reset\", \"--hard\", NULL);\n> -       cp.env = child_env.argv;\n> -       ret = run_command(&cp);\n> +       if (!opts->no_checkout) {\n> +               cp.argv = NULL;\n> +               argv_array_clear(&cp.args);\n> +               argv_array_pushl(&cp.args, \"reset\", \"--hard\", NULL);\n> +               cp.env = child_env.argv;\n> +               ret = run_command(&cp);\n> +       }\n>         if (!ret) {\n>                 is_junk = 0;\n>                 free(junk_work_tree);\n> @@ -320,6 +323,7 @@ static int add(int ac, const char **av, const char *prefix)\n>                 OPT_STRING('B', NULL, &new_branch_force, N_(\"branch\"),\n>                            N_(\"create or reset a branch\")),\n>                 OPT_BOOL(0, \"detach\", &opts.detach, N_(\"detach HEAD at named commit\")),\n> +               OPT_BOOL('n', \"no-checkout\", &opts.no_checkout, N_(\"don't create a checkout\")),\n>                 OPT_END()\n>         };\n"},{"id":"281586","messageId":"xmqq7fgtdwgb.fsf@gitster.mtv.corp.google.com","threadId":"41797","inReplyTo":"01020153a40588f3-5401ea3e-ece8-435c-a046-a5c1c1f92cd6-000000@eu-west-1.amazonses.com","subject":"Re: [PATCH] add option -n (--no-checkout) to git-worktree add","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-03-23T15:51:16Z","receivedAt":"2016-03-23T15:51:16Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ray Zhang <zhanglei002@gmail.com> writes:\n\n> @@ -320,6 +323,7 @@ static int add(int ac, const char **av, const char *prefix)\n>  \t\tOPT_STRING('B', NULL, &new_branch_force, N_(\"branch\"),\n>  \t\t\t   N_(\"create or reset a branch\")),\n>  \t\tOPT_BOOL(0, \"detach\", &opts.detach, N_(\"detach HEAD at named commit\")),\n> +\t\tOPT_BOOL('n', \"no-checkout\", &opts.no_checkout, N_(\"don't create a checkout\")),\n\nThis would allow --no-no-checkout, which is idiotic, wouldn't it?\n\nHow about\n\n    OPT_BOOL(0, \"checkout\", &opts.checkout, N_(\"populate the new working tree\"))\n\nand set opts.checkout to true when initializing?\n"},{"id":"281595","messageId":"CAPig+cTRa5YmbHdbXFNKNPN3GKpGOBUdVk774u9446J1qnYpfA@mail.gmail.com","threadId":"41797","inReplyTo":"xmqq7fgtdwgb.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH] add option -n (--no-checkout) to git-worktree add","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2016-03-23T17:43:13Z","receivedAt":"2016-03-23T17:43:13Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Wed, Mar 23, 2016 at 11:51 AM, Junio C Hamano <gitster@pobox.com> wrote:\n> Ray Zhang <zhanglei002@gmail.com> writes:\n>\n>> @@ -320,6 +323,7 @@ static int add(int ac, const char **av, const char *prefix)\n>>               OPT_STRING('B', NULL, &new_branch_force, N_(\"branch\"),\n>>                          N_(\"create or reset a branch\")),\n>>               OPT_BOOL(0, \"detach\", &opts.detach, N_(\"detach HEAD at named commit\")),\n>> +             OPT_BOOL('n', \"no-checkout\", &opts.no_checkout, N_(\"don't create a checkout\")),\n>\n> This would allow --no-no-checkout, which is idiotic, wouldn't it?\n>\n> How about\n>\n>     OPT_BOOL(0, \"checkout\", &opts.checkout, N_(\"populate the new working tree\"))\n>\n> and set opts.checkout to true when initializing?\n\nI think this code was copied verbatim from builtin/clone.c, and, as a\nnewcomer to the project, it's understandable that Ray Zhang imitated\nexisting code, but I agree that it would be better to avoid repeating\nthe misbehavior.\n"},{"id":"281637","messageId":"01020153a73bbb70-11a8482f-1a90-49e4-a56c-b311e12a85a2-000000@eu-west-1.amazonses.com","threadId":"41797","inReplyTo":"01020153a40588f3-5401ea3e-ece8-435c-a046-a5c1c1f92cd6-000000@eu-west-1.amazonses.com","subject":"[PATCH v2] worktree: add: introduce --checkout option","fromName":"Ray Zhang","fromEmail":"zhanglei002@gmail.com","sentAt":"2016-03-24T06:07:03Z","receivedAt":"2016-03-24T06:07:03Z","isPatch":true,"sender":{"key":"zhanglei002@gmail.com","avatar":"https://avatars.githubusercontent.com/u/4970552?v=4"},"body":"By adding this option which defaults to true, we can use the\ncorresponding --no-checkout to make some customizations before\nthe checkout, like sparse checkout, etc.\n\nSigned-off-by: Ray Zhang <zhanglei002@gmail.com>\n---\n Documentation/git-worktree.txt |  6 +++++-\n builtin/worktree.c             | 15 ++++++++++-----\n t/t2025-worktree-add.sh        |  5 +++++\n 3 files changed, 20 insertions(+), 6 deletions(-)\n\ndiff --git a/Documentation/git-worktree.txt b/Documentation/git-worktree.txt\nindex 62c76c1..e96fe0f 100644\n--- a/Documentation/git-worktree.txt\n+++ b/Documentation/git-worktree.txt\n@@ -9,7 +9,7 @@ git-worktree - Manage multiple working trees\n SYNOPSIS\n --------\n [verse]\n-'git worktree add' [-f] [--detach] [-b <new-branch>] <path> [<branch>]\n+'git worktree add' [-f] [--detach] [--checkout] [-b <new-branch>] <path> [<branch>]\n 'git worktree prune' [-n] [-v] [--expire <expire>]\n 'git worktree list' [--porcelain]\n \n@@ -87,6 +87,10 @@ OPTIONS\n \tWith `add`, detach HEAD in the new working tree. See \"DETACHED HEAD\"\n \tin linkgit:git-checkout[1].\n \n+--checkout::\n+\tDefault option with `add`, populate the new working tree. Use\n+\t`--no-checkout` to skip the checkout.\n+\n -n::\n --dry-run::\n \tWith `prune`, do not remove anything; just report what it would\ndiff --git a/builtin/worktree.c b/builtin/worktree.c\nindex 38b5609..e677cd7 100644\n--- a/builtin/worktree.c\n+++ b/builtin/worktree.c\n@@ -21,6 +21,7 @@ static const char * const worktree_usage[] = {\n struct add_opts {\n \tint force;\n \tint detach;\n+\tint checkout;\n \tconst char *new_branch;\n \tint force_new_branch;\n };\n@@ -284,11 +285,13 @@ static int add_worktree(const char *path, const char *refname,\n \tif (ret)\n \t\tgoto done;\n \n-\tcp.argv = NULL;\n-\targv_array_clear(&cp.args);\n-\targv_array_pushl(&cp.args, \"reset\", \"--hard\", NULL);\n-\tcp.env = child_env.argv;\n-\tret = run_command(&cp);\n+\tif (opts->checkout) {\n+\t\tcp.argv = NULL;\n+\t\targv_array_clear(&cp.args);\n+\t\targv_array_pushl(&cp.args, \"reset\", \"--hard\", NULL);\n+\t\tcp.env = child_env.argv;\n+\t\tret = run_command(&cp);\n+\t}\n \tif (!ret) {\n \t\tis_junk = 0;\n \t\tfree(junk_work_tree);\n@@ -320,10 +323,12 @@ static int add(int ac, const char **av, const char *prefix)\n \t\tOPT_STRING('B', NULL, &new_branch_force, N_(\"branch\"),\n \t\t\t   N_(\"create or reset a branch\")),\n \t\tOPT_BOOL(0, \"detach\", &opts.detach, N_(\"detach HEAD at named commit\")),\n+\t\tOPT_BOOL(0, \"checkout\", &opts.checkout, N_(\"populate the new working tree\")),\n \t\tOPT_END()\n \t};\n \n \tmemset(&opts, 0, sizeof(opts));\n+\topts.checkout = 1;\n \tac = parse_options(ac, av, prefix, options, worktree_usage, 0);\n \tif (!!opts.detach + !!opts.new_branch + !!new_branch_force > 1)\n \t\tdie(_(\"-b, -B, and --detach are mutually exclusive\"));\ndiff --git a/t/t2025-worktree-add.sh b/t/t2025-worktree-add.sh\nindex cbfa41e..601f963 100755\n--- a/t/t2025-worktree-add.sh\n+++ b/t/t2025-worktree-add.sh\n@@ -213,4 +213,9 @@ test_expect_success 'local clone from linked checkout' '\n \t( cd here-clone && git fsck )\n '\n \n+test_expect_success '\"add\" worktree without a checkout' '\n+\tgit worktree add --no-checkout -b swamp swamp &&\n+\t( cd swamp && git reset --hard && git fsck)\n+'\n+\n test_done\n\n--\nhttps://github.com/git/git/pull/217\n"},{"id":"281651","messageId":"CACsJy8DxcqYKrRi7_ERS3xLWfbbq3bNx-u2NWiXYoNw4yD+0dg@mail.gmail.com","threadId":"41797","inReplyTo":"01020153a73bbb70-11a8482f-1a90-49e4-a56c-b311e12a85a2-000000@eu-west-1.amazonses.com","subject":"Re: [PATCH v2] worktree: add: introduce --checkout option","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2016-03-24T09:16:36Z","receivedAt":"2016-03-24T09:16:36Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Thu, Mar 24, 2016 at 1:07 PM, Ray Zhang <zhanglei002@gmail.com> wrote:\n> By adding this option which defaults to true, we can use the\n> corresponding --no-checkout to make some customizations before\n> the checkout, like sparse checkout, etc.\n\nI think we can follow git-clone and use '-n' for this. But if it's\nsparse checkout that's you're after, be warned that it's not fully\nsupported (you either enable sparse chekcuot for all worktrees, or\nnone).\n-- \nDuy\n"},{"id":"281653","messageId":"CABEEbiBM-CTJdmOukLjfrmnmsSTwNzx+ELfO=BtgApT__QZu-g@mail.gmail.com","threadId":"41797","inReplyTo":"CACsJy8DxcqYKrRi7_ERS3xLWfbbq3bNx-u2NWiXYoNw4yD+0dg@mail.gmail.com","subject":"Re: [PATCH v2] worktree: add: introduce --checkout option","fromName":"Zhang Lei","fromEmail":"zhanglei002@gmail.com","sentAt":"2016-03-24T09:52:58Z","receivedAt":"2016-03-24T09:52:58Z","isPatch":true,"sender":{"key":"zhanglei002@gmail.com","avatar":"https://avatars.githubusercontent.com/u/4970552?v=4"},"body":"hi Duy,\nMy PATCH v1 did follow git-clone -n, however, Junio C Hamano and Eric Sunshine\nsuggested that we should avoid doing so , as --no-no-checkout could be\nconfusing.\n\nYes, core.sparsecheckout is the global switch for all worktrees, but\nevery worktree\ncan have its own info/sparse-checkout.\n\n2016-03-24 17:16 GMT+08:00 Duy Nguyen <pclouds@gmail.com>:\n>\n> On Thu, Mar 24, 2016 at 1:07 PM, Ray Zhang <zhanglei002@gmail.com> wrote:\n> > By adding this option which defaults to true, we can use the\n> > corresponding --no-checkout to make some customizations before\n> > the checkout, like sparse checkout, etc.\n>\n> I think we can follow git-clone and use '-n' for this. But if it's\n> sparse checkout that's you're after, be warned that it's not fully\n> supported (you either enable sparse chekcuot for all worktrees, or\n> none).\n> --\n> Duy\n"},{"id":"281764","messageId":"CAPig+cQGTcX+1nKM-zzGrJXgKsa6aaZxAHwD=z1M8-s+ugJRFg@mail.gmail.com","threadId":"41797","inReplyTo":"01020153a73bbb70-11a8482f-1a90-49e4-a56c-b311e12a85a2-000000@eu-west-1.amazonses.com","subject":"Re: [PATCH v2] worktree: add: introduce --checkout option","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2016-03-25T01:18:41Z","receivedAt":"2016-03-25T01:18:41Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Thu, Mar 24, 2016 at 2:07 AM, Ray Zhang <zhanglei002@gmail.com> wrote:\n> By adding this option which defaults to true, we can use the\n> corresponding --no-checkout to make some customizations before\n> the checkout, like sparse checkout, etc.\n\nThis version of the patch looks better. Thanks. A few comments below...\n\n> Signed-off-by: Ray Zhang <zhanglei002@gmail.com>\n> ---\n\nHere, below the \"---\" line is a good place to explain to reviewers\nwhat changed since the previous version of the patch. It's also\nhelpful to provide a link to the previous version, like this[1].\n\n[1]: http://thread.gmane.org/gmane.comp.version-control.git/289659\n\n> diff --git a/Documentation/git-worktree.txt b/Documentation/git-worktree.txt\n> @@ -87,6 +87,10 @@ OPTIONS\n>         With `add`, detach HEAD in the new working tree. See \"DETACHED HEAD\"\n>         in linkgit:git-checkout[1].\n>\n> +--checkout::\n\nWe can make it more clear that this is a boolean option by formatting\nit either like this:\n\n    --[no-]checkout::\n\nor this:\n\n    --checkout::\n    --no-checkout::\n\nI don't have a strong preference, and existing documentation uses either form.\n\n> +       Default option with `add`, populate the new working tree. Use\n> +       `--no-checkout` to skip the checkout.\n\nIt's subjective, but \"Default option with `add`\" doesn't quite convey\nto me that this is the default behavior of \"add\". Also, readers would\nlikely benefit from some explanation of why they might ever want to\nuse this option. Perhaps it could be rewritten something like this:\n\n    By default, `add` checks out HEAD, however, `--no-checkout` can\n    be used to suppress checkout in order to make customizations,\n    such as configuring sparse-checkout (see ...).\n\n> diff --git a/t/t2025-worktree-add.sh b/t/t2025-worktree-add.sh\n> @@ -213,4 +213,9 @@ test_expect_success 'local clone from linked checkout' '\n>         ( cd here-clone && git fsck )\n>  '\n>\n> +test_expect_success '\"add\" worktree without a checkout' '\n> +       git worktree add --no-checkout -b swamp swamp &&\n> +       ( cd swamp && git reset --hard && git fsck)\n\nTo match the style of the test immediately above this one, you'd want\na space before the closing ')'.\n\nHowever, I'm not convinced that reset+fsck is is really telling you\nmuch, as fsck is about checking the object database (which was already\nthe subject of earlier tests in the script) and doesn't say anything\nabout the working directory which is the point of --no-checkout. Much\nmore interesting would be to verify that no files were checked out.\nThere are many ways to do so; here's one:\n\n    git worktree add --no-checkout -b swamp swamp &&\n    ls swamp >actual &&\n    test_line_count = 0 actual\n\n> +'\n\nFinally, it wouldn't hurt to also add a test to verify that --checkout\nworks as expected (because the tests should check expected *behavior*,\nnot *implementation*).\n"},{"id":"281765","messageId":"CAPig+cTtRgMz_6oEXmBN2MHG65arq51JsoBL9QeWBFNLgFnCmw@mail.gmail.com","threadId":"41797","inReplyTo":"CABEEbiBM-CTJdmOukLjfrmnmsSTwNzx+ELfO=BtgApT__QZu-g@mail.gmail.com","subject":"Re: [PATCH v2] worktree: add: introduce --checkout option","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2016-03-25T01:22:33Z","receivedAt":"2016-03-25T01:22:33Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"[please respond inline rather than top-posting]\n\nOn Thu, Mar 24, 2016 at 5:52 AM, Zhang Lei <zhanglei002@gmail.com> wrote:\n> 2016-03-24 17:16 GMT+08:00 Duy Nguyen <pclouds@gmail.com>:\n>> I think we can follow git-clone and use '-n' for this. [...]\n>\n> My PATCH v1 did follow git-clone -n, however, Junio C Hamano and Eric Sunshine\n> suggested that we should avoid doing so , as --no-no-checkout could be\n> confusing.\n\nMy impression was that Duy was suggesting only that -n be recognized\nas shorthand for --no-checkout, however, git-worktree already\nrecognizes -n as shorthand for --dry-run (as a consequence of using\nOPT__DRY_RUN), so -n as shorthand for --no-checkout is a no-go.\n"},{"id":"281766","messageId":"CAPig+cS2qMZyUkf9Nekp+QaVkjc1oHXb4QF3wFDnBdF3WMU3iQ@mail.gmail.com","threadId":"41797","inReplyTo":"CAPig+cTtRgMz_6oEXmBN2MHG65arq51JsoBL9QeWBFNLgFnCmw@mail.gmail.com","subject":"Re: [PATCH v2] worktree: add: introduce --checkout option","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2016-03-25T01:29:31Z","receivedAt":"2016-03-25T01:29:31Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Thu, Mar 24, 2016 at 9:22 PM, Eric Sunshine <sunshine@sunshineco.com> wrote:\n> On Thu, Mar 24, 2016 at 5:52 AM, Zhang Lei <zhanglei002@gmail.com> wrote:\n>> 2016-03-24 17:16 GMT+08:00 Duy Nguyen <pclouds@gmail.com>:\n>>> I think we can follow git-clone and use '-n' for this. [...]\n>>\n>> My PATCH v1 did follow git-clone -n, however, Junio C Hamano and Eric Sunshine\n>> suggested that we should avoid doing so , as --no-no-checkout could be\n>> confusing.\n>\n> My impression was that Duy was suggesting only that -n be recognized\n> as shorthand for --no-checkout, however, git-worktree already\n> recognizes -n as shorthand for --dry-run (as a consequence of using\n> OPT__DRY_RUN), so -n as shorthand for --no-checkout is a no-go.\n\nIgnore this. It's only 'prune' which recognizes -n, so it's possible\nthat 'add' could recognize it for an alternate meaning (though the\ndocumentation would want to make this very clear).\n"},{"id":"281767","messageId":"CACsJy8Bs0WFJxGnVOBUnzipZYty-K4D9NkAQdODYqPUw2VAAiw@mail.gmail.com","threadId":"41797","inReplyTo":"CAPig+cS2qMZyUkf9Nekp+QaVkjc1oHXb4QF3wFDnBdF3WMU3iQ@mail.gmail.com","subject":"Re: [PATCH v2] worktree: add: introduce --checkout option","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2016-03-25T01:49:29Z","receivedAt":"2016-03-25T01:49:29Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Fri, Mar 25, 2016 at 8:29 AM, Eric Sunshine <sunshine@sunshineco.com> wrote:\n> On Thu, Mar 24, 2016 at 9:22 PM, Eric Sunshine <sunshine@sunshineco.com> wrote:\n>> On Thu, Mar 24, 2016 at 5:52 AM, Zhang Lei <zhanglei002@gmail.com> wrote:\n>>> 2016-03-24 17:16 GMT+08:00 Duy Nguyen <pclouds@gmail.com>:\n>>>> I think we can follow git-clone and use '-n' for this. [...]\n>>>\n>>> My PATCH v1 did follow git-clone -n, however, Junio C Hamano and Eric Sunshine\n>>> suggested that we should avoid doing so , as --no-no-checkout could be\n>>> confusing.\n>>\n>> My impression was that Duy was suggesting only that -n be recognized\n>> as shorthand for --no-checkout, however, git-worktree already\n>> recognizes -n as shorthand for --dry-run (as a consequence of using\n>> OPT__DRY_RUN), so -n as shorthand for --no-checkout is a no-go.\n>\n> Ignore this. It's only 'prune' which recognizes -n, so it's possible\n> that 'add' could recognize it for an alternate meaning (though the\n> documentation would want to make this very clear).\n\nTo make it clear, I don't feel strongly about '-n'. Yes muscle memory\nmay count. But if '-n' may become a new confusion source in\ngit-worktree then perhaps we should avoid it and go with\n--[no-]checkout\n-- \nDuy\n"},{"id":"281801","messageId":"01020153ad85c135-8ca8cff0-9e6f-48ea-89f3-4036814feeca-000000@eu-west-1.amazonses.com","threadId":"41797","inReplyTo":"01020153a73bbb70-11a8482f-1a90-49e4-a56c-b311e12a85a2-000000@eu-west-1.amazonses.com","subject":"[PATCH v3] worktree: add: introduce --checkout option","fromName":"Ray Zhang","fromEmail":"zhanglei002@gmail.com","sentAt":"2016-03-25T11:25:37Z","receivedAt":"2016-03-25T11:25:37Z","isPatch":true,"sender":{"key":"zhanglei002@gmail.com","avatar":"https://avatars.githubusercontent.com/u/4970552?v=4"},"body":"By adding this option which defaults to true, we can use the\ncorresponding --no-checkout to make some customizations before\nthe checkout, like sparse checkout, etc.\n\nSigned-off-by: Ray Zhang <zhanglei002@gmail.com>\n---\n1. reword on `--no-checkout` in Documentation/git-worktree.txt\n2. update the test for `--no-checkout`\n3. add a test for `--checkout`\nPrevious version of this patch:[v2]\n\n[v2]: http://article.gmane.org/gmane.comp.version-control.git/289713\n---\n Documentation/git-worktree.txt |  8 +++++++-\n builtin/worktree.c             | 15 ++++++++++-----\n t/t2025-worktree-add.sh        | 14 ++++++++++++++\n 3 files changed, 31 insertions(+), 6 deletions(-)\n\ndiff --git a/Documentation/git-worktree.txt b/Documentation/git-worktree.txt\nindex 62c76c1..c2796bb 100644\n--- a/Documentation/git-worktree.txt\n+++ b/Documentation/git-worktree.txt\n@@ -9,7 +9,7 @@ git-worktree - Manage multiple working trees\n SYNOPSIS\n --------\n [verse]\n-'git worktree add' [-f] [--detach] [-b <new-branch>] <path> [<branch>]\n+'git worktree add' [-f] [--detach] [--checkout] [-b <new-branch>] <path> [<branch>]\n 'git worktree prune' [-n] [-v] [--expire <expire>]\n 'git worktree list' [--porcelain]\n \n@@ -87,6 +87,12 @@ OPTIONS\n \tWith `add`, detach HEAD in the new working tree. See \"DETACHED HEAD\"\n \tin linkgit:git-checkout[1].\n \n+--[no-]checkout::\n+\tBy default, `add` checks out HEAD, however, `--no-checkout` can\n+\tbe used to suppress checkout in order to make customizations,\n+\tsuch as configuring sparse-checkout. See \"Sparse checkout\"\n+\tin linkgit:git-read-tree[1].\n+\n -n::\n --dry-run::\n \tWith `prune`, do not remove anything; just report what it would\ndiff --git a/builtin/worktree.c b/builtin/worktree.c\nindex 38b5609..e677cd7 100644\n--- a/builtin/worktree.c\n+++ b/builtin/worktree.c\n@@ -21,6 +21,7 @@ static const char * const worktree_usage[] = {\n struct add_opts {\n \tint force;\n \tint detach;\n+\tint checkout;\n \tconst char *new_branch;\n \tint force_new_branch;\n };\n@@ -284,11 +285,13 @@ static int add_worktree(const char *path, const char *refname,\n \tif (ret)\n \t\tgoto done;\n \n-\tcp.argv = NULL;\n-\targv_array_clear(&cp.args);\n-\targv_array_pushl(&cp.args, \"reset\", \"--hard\", NULL);\n-\tcp.env = child_env.argv;\n-\tret = run_command(&cp);\n+\tif (opts->checkout) {\n+\t\tcp.argv = NULL;\n+\t\targv_array_clear(&cp.args);\n+\t\targv_array_pushl(&cp.args, \"reset\", \"--hard\", NULL);\n+\t\tcp.env = child_env.argv;\n+\t\tret = run_command(&cp);\n+\t}\n \tif (!ret) {\n \t\tis_junk = 0;\n \t\tfree(junk_work_tree);\n@@ -320,10 +323,12 @@ static int add(int ac, const char **av, const char *prefix)\n \t\tOPT_STRING('B', NULL, &new_branch_force, N_(\"branch\"),\n \t\t\t   N_(\"create or reset a branch\")),\n \t\tOPT_BOOL(0, \"detach\", &opts.detach, N_(\"detach HEAD at named commit\")),\n+\t\tOPT_BOOL(0, \"checkout\", &opts.checkout, N_(\"populate the new working tree\")),\n \t\tOPT_END()\n \t};\n \n \tmemset(&opts, 0, sizeof(opts));\n+\topts.checkout = 1;\n \tac = parse_options(ac, av, prefix, options, worktree_usage, 0);\n \tif (!!opts.detach + !!opts.new_branch + !!new_branch_force > 1)\n \t\tdie(_(\"-b, -B, and --detach are mutually exclusive\"));\ndiff --git a/t/t2025-worktree-add.sh b/t/t2025-worktree-add.sh\nindex cbfa41e..1ff96af 100755\n--- a/t/t2025-worktree-add.sh\n+++ b/t/t2025-worktree-add.sh\n@@ -213,4 +213,18 @@ test_expect_success 'local clone from linked checkout' '\n \t( cd here-clone && git fsck )\n '\n \n+test_expect_success '\"add\" worktree with --no-checkout' '\n+\tgit worktree add --no-checkout -b swamp swamp &&\n+\tls swamp >actual && test_line_count = 0 actual &&\n+\t(\n+\t\tcd swamp && git reset --hard &&\n+\t\ttest_cmp ../init.t init.t\n+\t)\n+'\n+\n+test_expect_success '\"add\" worktree with --checkout' '\n+\tgit worktree add --checkout -b swmap2 swamp2 &&\n+\t( cd swamp2 && test_cmp ../init.t init.t )\n+'\n+\n test_done\n\n--\nhttps://github.com/git/git/pull/217\n"},{"id":"281799","messageId":"CABEEbiDRPsL6XJrnyFv43u26hXNbBVmMhbJeZmp+zjS+-jNZ=w@mail.gmail.com","threadId":"41797","inReplyTo":"CACsJy8Bs0WFJxGnVOBUnzipZYty-K4D9NkAQdODYqPUw2VAAiw@mail.gmail.com","subject":"Re: [PATCH v2] worktree: add: introduce --checkout option","fromName":"Zhang Lei","fromEmail":"zhanglei002@gmail.com","sentAt":"2016-03-25T11:31:02Z","receivedAt":"2016-03-25T11:31:02Z","isPatch":true,"sender":{"key":"zhanglei002@gmail.com","avatar":"https://avatars.githubusercontent.com/u/4970552?v=4"},"body":"Thanks for the clarification.\nBy the way, Duy, another unrelated question: why worktree name under\n.git/worktrees is being named\nafter the working tree path basename? I think branch name is more\nreasonable since we don't allow checking out\nthe same branch twice.\n\n2016-03-25 9:49 GMT+08:00 Duy Nguyen <pclouds@gmail.com>:\n> On Fri, Mar 25, 2016 at 8:29 AM, Eric Sunshine <sunshine@sunshineco.com> wrote:\n>> On Thu, Mar 24, 2016 at 9:22 PM, Eric Sunshine <sunshine@sunshineco.com> wrote:\n>>> On Thu, Mar 24, 2016 at 5:52 AM, Zhang Lei <zhanglei002@gmail.com> wrote:\n>>>> 2016-03-24 17:16 GMT+08:00 Duy Nguyen <pclouds@gmail.com>:\n>>>>> I think we can follow git-clone and use '-n' for this. [...]\n>>>>\n>>>> My PATCH v1 did follow git-clone -n, however, Junio C Hamano and Eric Sunshine\n>>>> suggested that we should avoid doing so , as --no-no-checkout could be\n>>>> confusing.\n>>>\n>>> My impression was that Duy was suggesting only that -n be recognized\n>>> as shorthand for --no-checkout, however, git-worktree already\n>>> recognizes -n as shorthand for --dry-run (as a consequence of using\n>>> OPT__DRY_RUN), so -n as shorthand for --no-checkout is a no-go.\n>>\n>> Ignore this. It's only 'prune' which recognizes -n, so it's possible\n>> that 'add' could recognize it for an alternate meaning (though the\n>> documentation would want to make this very clear).\n>\n> To make it clear, I don't feel strongly about '-n'. Yes muscle memory\n> may count. But if '-n' may become a new confusion source in\n> git-worktree then perhaps we should avoid it and go with\n> --[no-]checkout\n> --\n> Duy\n"},{"id":"281803","messageId":"CACsJy8AyMUn_AAF-DNGvjS8D+qdFLNuVBYvAjide6wA-ZnHJ5w@mail.gmail.com","threadId":"41797","inReplyTo":"CABEEbiDRPsL6XJrnyFv43u26hXNbBVmMhbJeZmp+zjS+-jNZ=w@mail.gmail.com","subject":"Re: [PATCH v2] worktree: add: introduce --checkout option","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2016-03-25T11:41:42Z","receivedAt":"2016-03-25T11:41:42Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Fri, Mar 25, 2016 at 6:31 PM, Zhang Lei <zhanglei002@gmail.com> wrote:\n> By the way, Duy, another unrelated question: why worktree name under\n> .git/worktrees is being named\n> after the working tree path basename? I think branch name is more\n> reasonable since we don't allow checking out\n> the same branch twice.\n\nBecause branch name is not always available (e.g. detached HEAD) and\ncheckout branch can be switched later on. And normally you'll get\nbranch name there anyway with \"git worktree add something\" because the\nbranch \"something\" is automatically created. I've been wondering if\nit's worth supporting \"git worktree -b abc ./\" where we create\nworktree \"./abc\" based on branch name too.\n-- \nDuy\n"},{"id":"281807","messageId":"CABEEbiAeMZ=PSScFJ98DkqyDBGTC1OBvTb8bLAn=whLjXJvdzA@mail.gmail.com","threadId":"41797","inReplyTo":"CACsJy8AyMUn_AAF-DNGvjS8D+qdFLNuVBYvAjide6wA-ZnHJ5w@mail.gmail.com","subject":"Re: [PATCH v2] worktree: add: introduce --checkout option","fromName":"Zhang Lei","fromEmail":"zhanglei002@gmail.com","sentAt":"2016-03-25T12:06:51Z","receivedAt":"2016-03-25T12:06:51Z","isPatch":true,"sender":{"key":"zhanglei002@gmail.com","avatar":"https://avatars.githubusercontent.com/u/4970552?v=4"},"body":"Yes, path basename makes sense.\nI am asking this question because we have some legacy code requires\nthat working tree\ncalled something like 'src', as a result, multiple branch would have\nsrc1 src2 src3 under .git/worktrees\nwhich could not be easy to maintain.\nI agreed with you, we should give users such option.\n\n\n2016-03-25 19:41 GMT+08:00 Duy Nguyen <pclouds@gmail.com>:\n> On Fri, Mar 25, 2016 at 6:31 PM, Zhang Lei <zhanglei002@gmail.com> wrote:\n>> By the way, Duy, another unrelated question: why worktree name under\n>> .git/worktrees is being named\n>> after the working tree path basename? I think branch name is more\n>> reasonable since we don't allow checking out\n>> the same branch twice.\n>\n> Because branch name is not always available (e.g. detached HEAD) and\n> checkout branch can be switched later on. And normally you'll get\n> branch name there anyway with \"git worktree add something\" because the\n> branch \"something\" is automatically created. I've been wondering if\n> it's worth supporting \"git worktree -b abc ./\" where we create\n> worktree \"./abc\" based on branch name too.\n> --\n> Duy\n"},{"id":"281808","messageId":"CACsJy8BhFjS=t1cjJ2D5UzNk6avd8LknL1xg5admeu--YWjyew@mail.gmail.com","threadId":"41797","inReplyTo":"CABEEbiAeMZ=PSScFJ98DkqyDBGTC1OBvTb8bLAn=whLjXJvdzA@mail.gmail.com","subject":"Re: [PATCH v2] worktree: add: introduce --checkout option","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2016-03-25T12:15:54Z","receivedAt":"2016-03-25T12:15:54Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Please don't top-post.\n\nOn Fri, Mar 25, 2016 at 7:06 PM, Zhang Lei <zhanglei002@gmail.com> wrote:\n> Yes, path basename makes sense.\n> I am asking this question because we have some legacy code requires\n> that working tree\n> called something like 'src', as a result, multiple branch would have\n> src1 src2 src3 under .git/worktrees\n> which could not be easy to maintain.\n\nIf you really need to care about these names, I think a new option to\nlet you control the naming explicitly would be better.\n\n> I agreed with you, we should give users such option.\n>\n>\n> 2016-03-25 19:41 GMT+08:00 Duy Nguyen <pclouds@gmail.com>:\n>> On Fri, Mar 25, 2016 at 6:31 PM, Zhang Lei <zhanglei002@gmail.com> wrote:\n>>> By the way, Duy, another unrelated question: why worktree name under\n>>> .git/worktrees is being named\n>>> after the working tree path basename? I think branch name is more\n>>> reasonable since we don't allow checking out\n>>> the same branch twice.\n>>\n>> Because branch name is not always available (e.g. detached HEAD) and\n>> checkout branch can be switched later on. And normally you'll get\n>> branch name there anyway with \"git worktree add something\" because the\n>> branch \"something\" is automatically created. I've been wondering if\n>> it's worth supporting \"git worktree -b abc ./\" where we create\n>> worktree \"./abc\" based on branch name too.\n>> --\n>> Duy\n\n\n\n-- \nDuy\n"},{"id":"281810","messageId":"CANoM8SXF2=+tObJaSAziGa_9W2CcwLMTW_mWoueq7Chm-yRqqw@mail.gmail.com","threadId":"41797","inReplyTo":"CACsJy8AyMUn_AAF-DNGvjS8D+qdFLNuVBYvAjide6wA-ZnHJ5w@mail.gmail.com","subject":"Re: [PATCH v2] worktree: add: introduce --checkout option","fromName":"Mike Rappazzo","fromEmail":"rappazzo@gmail.com","sentAt":"2016-03-25T13:02:11Z","receivedAt":"2016-03-25T13:02:11Z","isPatch":true,"sender":{"key":"rappazzo@gmail.com","avatar":"https://avatars.githubusercontent.com/u/525287?v=4"},"body":"On Fri, Mar 25, 2016 at 7:41 AM, Duy Nguyen <pclouds@gmail.com> wrote:\n> On Fri, Mar 25, 2016 at 6:31 PM, Zhang Lei <zhanglei002@gmail.com> wrote:\n>> By the way, Duy, another unrelated question: why worktree name under\n>> .git/worktrees is being named\n>> after the working tree path basename? I think branch name is more\n>> reasonable since we don't allow checking out\n>> the same branch twice.\n>\n> Because branch name is not always available (e.g. detached HEAD) and\n> checkout branch can be switched later on. And normally you'll get\n> branch name there anyway with \"git worktree add something\" because the\n> branch \"something\" is automatically created. I've been wondering if\n> it's worth supporting \"git worktree -b abc ./\" where we create\n> worktree \"./abc\" based on branch name too.\n\nYou can switch to any other branch in a worktree.  Consider that you\ncould switch branches in\nworktrees such that you could eventually end up having the branches\nswapped from original\nworktree setup.\n"},{"id":"281944","messageId":"20160327194948.GA9295@flurp.local","threadId":"41797","inReplyTo":"01020153ad85c135-8ca8cff0-9e6f-48ea-89f3-4036814feeca-000000@eu-west-1.amazonses.com","subject":"Re: [PATCH v3] worktree: add: introduce --checkout option","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2016-03-27T19:49:48Z","receivedAt":"2016-03-27T19:49:48Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Fri, Mar 25, 2016 at 11:25:37AM +0000, Ray Zhang wrote:\n> By adding this option which defaults to true, we can use the\n> corresponding --no-checkout to make some customizations before\n> the checkout, like sparse checkout, etc.\n> \n> Signed-off-by: Ray Zhang <zhanglei002@gmail.com>\n> ---\n> 1. reword on `--no-checkout` in Documentation/git-worktree.txt\n> 2. update the test for `--no-checkout`\n> 3. add a test for `--checkout`\n\nThanks, this version of the patch looks good and is:\n\n    Reviewed-by: Eric Sunshine <sunshine@sunshineco.com>\n\nwith or without the minor suggestions below. (If you do re-roll, feel\nfree to add my Reviewed-by: if you include these suggestions but not\nif you make other major changes.)\n\n> ---\n> diff --git a/Documentation/git-worktree.txt b/Documentation/git-worktree.txt\n> @@ -87,6 +87,12 @@ OPTIONS\n> +--[no-]checkout::\n> +\tBy default, `add` checks out HEAD, however, `--no-checkout` can\n\nI realize that this description is just a verbatim copy of what I\nsuggested during review[1], but in retrospect, I think\ns/HEAD/`<branch>`/ would be clearer and more consistent:\n\n    By default, `add` checks out `<branch>`, however, ...\n\n[1]: http://article.gmane.org/gmane.comp.version-control.git/289840\n\n> +\tbe used to suppress checkout in order to make customizations,\n> +\tsuch as configuring sparse-checkout. See \"Sparse checkout\"\n> +\tin linkgit:git-read-tree[1].\n> diff --git a/t/t2025-worktree-add.sh b/t/t2025-worktree-add.sh\n> @@ -213,4 +213,18 @@ test_expect_success 'local clone from linked checkout' '\n> +test_expect_success '\"add\" worktree with --no-checkout' '\n> +\tgit worktree add --no-checkout -b swamp swamp &&\n> +\tls swamp >actual && test_line_count = 0 actual &&\n\nStyle: One statement per line, so this should be split over two\nlines.\n\n> +\t(\n> +\t\tcd swamp && git reset --hard &&\n> +\t\ttest_cmp ../init.t init.t\n> +\t)\n\nNo need for the subshell. This can be written more simply as:\n\n    git -C swamp reset --hard &&\n    test_cmp init.t swamp/init.t\n\n> +'\n> +\n> +test_expect_success '\"add\" worktree with --checkout' '\n> +\tgit worktree add --checkout -b swmap2 swamp2 &&\n> +\t( cd swamp2 && test_cmp ../init.t init.t )\n\nLikewise, you can drop the subshell:\n\n    test_cmp init.t swamp2/init.t\n\n> +'\n> +\n>  test_done\n\nFor convenience, the above suggestions would look like this (applied\natop your patch). Feel free to fold them in if you re-roll.\n\n--- 8< ---\ndiff --git a/Documentation/git-worktree.txt b/Documentation/git-worktree.txt\nindex c2796bb..c622345 100644\n--- a/Documentation/git-worktree.txt\n+++ b/Documentation/git-worktree.txt\n@@ -88,7 +88,7 @@ OPTIONS\n \tin linkgit:git-checkout[1].\n \n --[no-]checkout::\n-\tBy default, `add` checks out HEAD, however, `--no-checkout` can\n+\tBy default, `add` checks out `<branch>`, however, `--no-checkout` can\n \tbe used to suppress checkout in order to make customizations,\n \tsuch as configuring sparse-checkout. See \"Sparse checkout\"\n \tin linkgit:git-read-tree[1].\ndiff --git a/t/t2025-worktree-add.sh b/t/t2025-worktree-add.sh\nindex 1ff96af..472b811 100755\n--- a/t/t2025-worktree-add.sh\n+++ b/t/t2025-worktree-add.sh\n@@ -215,16 +215,15 @@ test_expect_success 'local clone from linked checkout' '\n \n test_expect_success '\"add\" worktree with --no-checkout' '\n \tgit worktree add --no-checkout -b swamp swamp &&\n-\tls swamp >actual && test_line_count = 0 actual &&\n-\t(\n-\t\tcd swamp && git reset --hard &&\n-\t\ttest_cmp ../init.t init.t\n-\t)\n+\tls swamp >actual &&\n+\ttest_line_count = 0 actual &&\n+\tgit -C swamp reset --hard &&\n+\ttest_cmp init.t swamp/init.t\n '\n \n test_expect_success '\"add\" worktree with --checkout' '\n \tgit worktree add --checkout -b swmap2 swamp2 &&\n-\t( cd swamp2 && test_cmp ../init.t init.t )\n+\ttest_cmp init.t swamp2/init.t\n '\n \n test_done\n--- 8< ---\n"},{"id":"281953","messageId":"01020153bcda5e6c-2bae9b68-6669-4f29-a512-136c42722001-000000@eu-west-1.amazonses.com","threadId":"41797","inReplyTo":"01020153ad85c135-8ca8cff0-9e6f-48ea-89f3-4036814feeca-000000@eu-west-1.amazonses.com","subject":"[PATCH v4] worktree: add: introduce --checkout option","fromName":"Ray Zhang","fromEmail":"zhanglei002@gmail.com","sentAt":"2016-03-28T10:52:21Z","receivedAt":"2016-03-28T10:52:21Z","isPatch":true,"sender":{"key":"zhanglei002@gmail.com","avatar":"https://avatars.githubusercontent.com/u/4970552?v=4"},"body":"By adding this option which defaults to true, we can use the\ncorresponding --no-checkout to make some customizations before\nthe checkout, like sparse checkout, etc.\n\nHelped-by: Eric Sunshine <sunshine@sunshineco.com>\nHelped-by: Junio C Hamano <gitster@pobox.com>\nReviewed-by: Eric Sunshine <sunshine@sunshineco.com>\nSigned-off-by: Ray Zhang <zhanglei002@gmail.com>\n---\nChanges since last version of this patch[v3]:\n\tDocumentation/git-worktree.txt: HEAD --> `<branch>`\n\tt/t2025-worktree-add.sh: fix style\n\n[v3]: http://article.gmane.org/gmane.comp.version-control.git/289877\n[v2]: http://article.gmane.org/gmane.comp.version-control.git/289713\n[v1]: http://article.gmane.org/gmane.comp.version-control.git/289659\n---\n Documentation/git-worktree.txt |  8 +++++++-\n builtin/worktree.c             | 15 ++++++++++-----\n t/t2025-worktree-add.sh        | 13 +++++++++++++\n 3 files changed, 30 insertions(+), 6 deletions(-)\n\ndiff --git a/Documentation/git-worktree.txt b/Documentation/git-worktree.txt\nindex 62c76c1..c622345 100644\n--- a/Documentation/git-worktree.txt\n+++ b/Documentation/git-worktree.txt\n@@ -9,7 +9,7 @@ git-worktree - Manage multiple working trees\n SYNOPSIS\n --------\n [verse]\n-'git worktree add' [-f] [--detach] [-b <new-branch>] <path> [<branch>]\n+'git worktree add' [-f] [--detach] [--checkout] [-b <new-branch>] <path> [<branch>]\n 'git worktree prune' [-n] [-v] [--expire <expire>]\n 'git worktree list' [--porcelain]\n \n@@ -87,6 +87,12 @@ OPTIONS\n \tWith `add`, detach HEAD in the new working tree. See \"DETACHED HEAD\"\n \tin linkgit:git-checkout[1].\n \n+--[no-]checkout::\n+\tBy default, `add` checks out `<branch>`, however, `--no-checkout` can\n+\tbe used to suppress checkout in order to make customizations,\n+\tsuch as configuring sparse-checkout. See \"Sparse checkout\"\n+\tin linkgit:git-read-tree[1].\n+\n -n::\n --dry-run::\n \tWith `prune`, do not remove anything; just report what it would\ndiff --git a/builtin/worktree.c b/builtin/worktree.c\nindex 38b5609..e677cd7 100644\n--- a/builtin/worktree.c\n+++ b/builtin/worktree.c\n@@ -21,6 +21,7 @@ static const char * const worktree_usage[] = {\n struct add_opts {\n \tint force;\n \tint detach;\n+\tint checkout;\n \tconst char *new_branch;\n \tint force_new_branch;\n };\n@@ -284,11 +285,13 @@ static int add_worktree(const char *path, const char *refname,\n \tif (ret)\n \t\tgoto done;\n \n-\tcp.argv = NULL;\n-\targv_array_clear(&cp.args);\n-\targv_array_pushl(&cp.args, \"reset\", \"--hard\", NULL);\n-\tcp.env = child_env.argv;\n-\tret = run_command(&cp);\n+\tif (opts->checkout) {\n+\t\tcp.argv = NULL;\n+\t\targv_array_clear(&cp.args);\n+\t\targv_array_pushl(&cp.args, \"reset\", \"--hard\", NULL);\n+\t\tcp.env = child_env.argv;\n+\t\tret = run_command(&cp);\n+\t}\n \tif (!ret) {\n \t\tis_junk = 0;\n \t\tfree(junk_work_tree);\n@@ -320,10 +323,12 @@ static int add(int ac, const char **av, const char *prefix)\n \t\tOPT_STRING('B', NULL, &new_branch_force, N_(\"branch\"),\n \t\t\t   N_(\"create or reset a branch\")),\n \t\tOPT_BOOL(0, \"detach\", &opts.detach, N_(\"detach HEAD at named commit\")),\n+\t\tOPT_BOOL(0, \"checkout\", &opts.checkout, N_(\"populate the new working tree\")),\n \t\tOPT_END()\n \t};\n \n \tmemset(&opts, 0, sizeof(opts));\n+\topts.checkout = 1;\n \tac = parse_options(ac, av, prefix, options, worktree_usage, 0);\n \tif (!!opts.detach + !!opts.new_branch + !!new_branch_force > 1)\n \t\tdie(_(\"-b, -B, and --detach are mutually exclusive\"));\ndiff --git a/t/t2025-worktree-add.sh b/t/t2025-worktree-add.sh\nindex cbfa41e..472b811 100755\n--- a/t/t2025-worktree-add.sh\n+++ b/t/t2025-worktree-add.sh\n@@ -213,4 +213,17 @@ test_expect_success 'local clone from linked checkout' '\n \t( cd here-clone && git fsck )\n '\n \n+test_expect_success '\"add\" worktree with --no-checkout' '\n+\tgit worktree add --no-checkout -b swamp swamp &&\n+\tls swamp >actual &&\n+\ttest_line_count = 0 actual &&\n+\tgit -C swamp reset --hard &&\n+\ttest_cmp init.t swamp/init.t\n+'\n+\n+test_expect_success '\"add\" worktree with --checkout' '\n+\tgit worktree add --checkout -b swmap2 swamp2 &&\n+\ttest_cmp init.t swamp2/init.t\n+'\n+\n test_done\n\n--\nhttps://github.com/git/git/pull/217\n"},{"id":"281973","messageId":"xmqq8u12zejf.fsf@gitster.mtv.corp.google.com","threadId":"41797","inReplyTo":"01020153bcda5e6c-2bae9b68-6669-4f29-a512-136c42722001-000000@eu-west-1.amazonses.com","subject":"Re: [PATCH v4] worktree: add: introduce --checkout option","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-03-28T17:40:52Z","receivedAt":"2016-03-28T17:40:52Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ray Zhang <zhanglei002@gmail.com> writes:\n\n> By adding this option which defaults to true, we can use the\n> corresponding --no-checkout to make some customizations before\n> the checkout, like sparse checkout, etc.\n>\n> Helped-by: Eric Sunshine <sunshine@sunshineco.com>\n> Helped-by: Junio C Hamano <gitster@pobox.com>\n> Reviewed-by: Eric Sunshine <sunshine@sunshineco.com>\n> Signed-off-by: Ray Zhang <zhanglei002@gmail.com>\n> ---\n\nThanks.  Will queue.\n\n> diff --git a/t/t2025-worktree-add.sh b/t/t2025-worktree-add.sh\n> index cbfa41e..472b811 100755\n> --- a/t/t2025-worktree-add.sh\n> +++ b/t/t2025-worktree-add.sh\n> @@ -213,4 +213,17 @@ test_expect_success 'local clone from linked checkout' '\n>  \t( cd here-clone && git fsck )\n>  '\n>  \n> +test_expect_success '\"add\" worktree with --no-checkout' '\n> +\tgit worktree add --no-checkout -b swamp swamp &&\n> +\tls swamp >actual &&\n> +\ttest_line_count = 0 actual &&\n\nThe remainder of the test (both existing and added parts)\nseems to only care about init.t; running \"ls swamp\" feels\nsomewhat inconsistent.  We could replace the two lines with\n\n\t! test -e swamp/init.t\n\nto address this, but I do not think it is worth a patch churn.\n\n> +\tgit -C swamp reset --hard &&\n> +\ttest_cmp init.t swamp/init.t\n> +'\n> +test_expect_success '\"add\" worktree with --checkout' '\n> +\tgit worktree add --checkout -b swmap2 swamp2 &&\n> +\ttest_cmp init.t swamp2/init.t\n> +'\n> +\n>  test_done\n"},{"id":"282035","messageId":"01020153c1dae323-b918e73f-f116-4760-9747-9aa8cafb2db5-000000@eu-west-1.amazonses.com","threadId":"41797","inReplyTo":"01020153bcda5e6c-2bae9b68-6669-4f29-a512-136c42722001-000000@eu-west-1.amazonses.com","subject":"[PATCH v5] worktree: add: introduce --checkout option","fromName":"Ray Zhang","fromEmail":"zhanglei002@gmail.com","sentAt":"2016-03-29T10:11:01Z","receivedAt":"2016-03-29T10:11:01Z","isPatch":true,"sender":{"key":"zhanglei002@gmail.com","avatar":"https://avatars.githubusercontent.com/u/4970552?v=4"},"body":"By adding this option which defaults to true, we can use the\ncorresponding --no-checkout to make some customizations before\nthe checkout, like sparse checkout, etc.\n\nHelped-by: Eric Sunshine <sunshine@sunshineco.com>\nHelped-by: Junio C Hamano <gitster@pobox.com>\nReviewed-by: Eric Sunshine <sunshine@sunshineco.com>\nSigned-off-by: Ray Zhang <zhanglei002@gmail.com>\n---\nChanges since last version of this patch[v4]:\n\tt/t2025-worktree-add.sh: use test -e to test file existence.\n\tbuiltin/worktree.c: refactor the code a little bit.\n\n[v4]: http://article.gmane.org/gmane.comp.version-control.git/290030\n[v3]: http://article.gmane.org/gmane.comp.version-control.git/289877\n[v2]: http://article.gmane.org/gmane.comp.version-control.git/289713\n[v1]: http://article.gmane.org/gmane.comp.version-control.git/289659\n---\n Documentation/git-worktree.txt |  8 +++++++-\n builtin/worktree.c             | 29 ++++++++++++++++++-----------\n t/t2025-worktree-add.sh        | 12 ++++++++++++\n 3 files changed, 37 insertions(+), 12 deletions(-)\n\ndiff --git a/Documentation/git-worktree.txt b/Documentation/git-worktree.txt\nindex 62c76c1..c622345 100644\n--- a/Documentation/git-worktree.txt\n+++ b/Documentation/git-worktree.txt\n@@ -9,7 +9,7 @@ git-worktree - Manage multiple working trees\n SYNOPSIS\n --------\n [verse]\n-'git worktree add' [-f] [--detach] [-b <new-branch>] <path> [<branch>]\n+'git worktree add' [-f] [--detach] [--checkout] [-b <new-branch>] <path> [<branch>]\n 'git worktree prune' [-n] [-v] [--expire <expire>]\n 'git worktree list' [--porcelain]\n \n@@ -87,6 +87,12 @@ OPTIONS\n \tWith `add`, detach HEAD in the new working tree. See \"DETACHED HEAD\"\n \tin linkgit:git-checkout[1].\n \n+--[no-]checkout::\n+\tBy default, `add` checks out `<branch>`, however, `--no-checkout` can\n+\tbe used to suppress checkout in order to make customizations,\n+\tsuch as configuring sparse-checkout. See \"Sparse checkout\"\n+\tin linkgit:git-read-tree[1].\n+\n -n::\n --dry-run::\n \tWith `prune`, do not remove anything; just report what it would\ndiff --git a/builtin/worktree.c b/builtin/worktree.c\nindex 38b5609..d8e3795 100644\n--- a/builtin/worktree.c\n+++ b/builtin/worktree.c\n@@ -21,6 +21,7 @@ static const char * const worktree_usage[] = {\n struct add_opts {\n \tint force;\n \tint detach;\n+\tint checkout;\n \tconst char *new_branch;\n \tint force_new_branch;\n };\n@@ -284,18 +285,22 @@ static int add_worktree(const char *path, const char *refname,\n \tif (ret)\n \t\tgoto done;\n \n-\tcp.argv = NULL;\n-\targv_array_clear(&cp.args);\n-\targv_array_pushl(&cp.args, \"reset\", \"--hard\", NULL);\n-\tcp.env = child_env.argv;\n-\tret = run_command(&cp);\n-\tif (!ret) {\n-\t\tis_junk = 0;\n-\t\tfree(junk_work_tree);\n-\t\tfree(junk_git_dir);\n-\t\tjunk_work_tree = NULL;\n-\t\tjunk_git_dir = NULL;\n+\tif (opts->checkout) {\n+\t\tcp.argv = NULL;\n+\t\targv_array_clear(&cp.args);\n+\t\targv_array_pushl(&cp.args, \"reset\", \"--hard\", NULL);\n+\t\tcp.env = child_env.argv;\n+\t\tret = run_command(&cp);\n+\t\tif (ret)\n+\t\t\tgoto done;\n \t}\n+\n+\tis_junk = 0;\n+\tfree(junk_work_tree);\n+\tfree(junk_git_dir);\n+\tjunk_work_tree = NULL;\n+\tjunk_git_dir = NULL;\n+\n done:\n \tstrbuf_reset(&sb);\n \tstrbuf_addf(&sb, \"%s/locked\", sb_repo.buf);\n@@ -320,10 +325,12 @@ static int add(int ac, const char **av, const char *prefix)\n \t\tOPT_STRING('B', NULL, &new_branch_force, N_(\"branch\"),\n \t\t\t   N_(\"create or reset a branch\")),\n \t\tOPT_BOOL(0, \"detach\", &opts.detach, N_(\"detach HEAD at named commit\")),\n+\t\tOPT_BOOL(0, \"checkout\", &opts.checkout, N_(\"populate the new working tree\")),\n \t\tOPT_END()\n \t};\n \n \tmemset(&opts, 0, sizeof(opts));\n+\topts.checkout = 1;\n \tac = parse_options(ac, av, prefix, options, worktree_usage, 0);\n \tif (!!opts.detach + !!opts.new_branch + !!new_branch_force > 1)\n \t\tdie(_(\"-b, -B, and --detach are mutually exclusive\"));\ndiff --git a/t/t2025-worktree-add.sh b/t/t2025-worktree-add.sh\nindex cbfa41e..3acb992 100755\n--- a/t/t2025-worktree-add.sh\n+++ b/t/t2025-worktree-add.sh\n@@ -213,4 +213,16 @@ test_expect_success 'local clone from linked checkout' '\n \t( cd here-clone && git fsck )\n '\n \n+test_expect_success '\"add\" worktree with --no-checkout' '\n+\tgit worktree add --no-checkout -b swamp swamp &&\n+\t! test -e swamp/init.t &&\n+\tgit -C swamp reset --hard &&\n+\ttest_cmp init.t swamp/init.t\n+'\n+\n+test_expect_success '\"add\" worktree with --checkout' '\n+\tgit worktree add --checkout -b swmap2 swamp2 &&\n+\ttest_cmp init.t swamp2/init.t\n+'\n+\n test_done\n\n--\nhttps://github.com/git/git/pull/217\n"},{"id":"282039","messageId":"20160329105402.GB1578@serenity.lan","threadId":"41797","inReplyTo":"01020153c1dae323-b918e73f-f116-4760-9747-9aa8cafb2db5-000000@eu-west-1.amazonses.com","subject":"Re: [PATCH v5] worktree: add: introduce --checkout option","fromName":"John Keeping","fromEmail":"john@keeping.me.uk","sentAt":"2016-03-29T10:54:02Z","receivedAt":"2016-03-29T10:54:02Z","isPatch":true,"sender":{"key":"john@keeping.me.uk","avatar":"https://avatars.githubusercontent.com/u/1702081?v=4"},"body":"On Tue, Mar 29, 2016 at 10:11:01AM +0000, Ray Zhang wrote:\n> By adding this option which defaults to true, we can use the\n> corresponding --no-checkout to make some customizations before\n> the checkout, like sparse checkout, etc.\n> \n> Helped-by: Eric Sunshine <sunshine@sunshineco.com>\n> Helped-by: Junio C Hamano <gitster@pobox.com>\n> Reviewed-by: Eric Sunshine <sunshine@sunshineco.com>\n> Signed-off-by: Ray Zhang <zhanglei002@gmail.com>\n> ---\n> Changes since last version of this patch[v4]:\n> \tt/t2025-worktree-add.sh: use test -e to test file existence.\n> \tbuiltin/worktree.c: refactor the code a little bit.\n> \n> [v4]: http://article.gmane.org/gmane.comp.version-control.git/290030\n> [v3]: http://article.gmane.org/gmane.comp.version-control.git/289877\n> [v2]: http://article.gmane.org/gmane.comp.version-control.git/289713\n> [v1]: http://article.gmane.org/gmane.comp.version-control.git/289659\n> ---\n>  Documentation/git-worktree.txt |  8 +++++++-\n>  builtin/worktree.c             | 29 ++++++++++++++++++-----------\n>  t/t2025-worktree-add.sh        | 12 ++++++++++++\n>  3 files changed, 37 insertions(+), 12 deletions(-)\n> \n> diff --git a/Documentation/git-worktree.txt b/Documentation/git-worktree.txt\n> index 62c76c1..c622345 100644\n> --- a/Documentation/git-worktree.txt\n> +++ b/Documentation/git-worktree.txt\n> @@ -9,7 +9,7 @@ git-worktree - Manage multiple working trees\n>  SYNOPSIS\n>  --------\n>  [verse]\n> -'git worktree add' [-f] [--detach] [-b <new-branch>] <path> [<branch>]\n> +'git worktree add' [-f] [--detach] [--checkout] [-b <new-branch>] <path> [<branch>]\n>  'git worktree prune' [-n] [-v] [--expire <expire>]\n>  'git worktree list' [--porcelain]\n>  \n> @@ -87,6 +87,12 @@ OPTIONS\n>  \tWith `add`, detach HEAD in the new working tree. See \"DETACHED HEAD\"\n>  \tin linkgit:git-checkout[1].\n>  \n> +--[no-]checkout::\n\nThis should be:\n\n--checkout::\n--no-checkout::\n\n(see for example --progress in Documentation/merge-options.txt).\n\n> +\tBy default, `add` checks out `<branch>`, however, `--no-checkout` can\n> +\tbe used to suppress checkout in order to make customizations,\n> +\tsuch as configuring sparse-checkout. See \"Sparse checkout\"\n> +\tin linkgit:git-read-tree[1].\n> +\n>  -n::\n>  --dry-run::\n>  \tWith `prune`, do not remove anything; just report what it would\n> diff --git a/builtin/worktree.c b/builtin/worktree.c\n> index 38b5609..d8e3795 100644\n> --- a/builtin/worktree.c\n> +++ b/builtin/worktree.c\n> @@ -21,6 +21,7 @@ static const char * const worktree_usage[] = {\n>  struct add_opts {\n>  \tint force;\n>  \tint detach;\n> +\tint checkout;\n>  \tconst char *new_branch;\n>  \tint force_new_branch;\n>  };\n> @@ -284,18 +285,22 @@ static int add_worktree(const char *path, const char *refname,\n>  \tif (ret)\n>  \t\tgoto done;\n>  \n> -\tcp.argv = NULL;\n> -\targv_array_clear(&cp.args);\n> -\targv_array_pushl(&cp.args, \"reset\", \"--hard\", NULL);\n> -\tcp.env = child_env.argv;\n> -\tret = run_command(&cp);\n> -\tif (!ret) {\n> -\t\tis_junk = 0;\n> -\t\tfree(junk_work_tree);\n> -\t\tfree(junk_git_dir);\n> -\t\tjunk_work_tree = NULL;\n> -\t\tjunk_git_dir = NULL;\n> +\tif (opts->checkout) {\n> +\t\tcp.argv = NULL;\n> +\t\targv_array_clear(&cp.args);\n> +\t\targv_array_pushl(&cp.args, \"reset\", \"--hard\", NULL);\n> +\t\tcp.env = child_env.argv;\n> +\t\tret = run_command(&cp);\n> +\t\tif (ret)\n> +\t\t\tgoto done;\n>  \t}\n> +\n> +\tis_junk = 0;\n> +\tfree(junk_work_tree);\n> +\tfree(junk_git_dir);\n> +\tjunk_work_tree = NULL;\n> +\tjunk_git_dir = NULL;\n> +\n>  done:\n>  \tstrbuf_reset(&sb);\n>  \tstrbuf_addf(&sb, \"%s/locked\", sb_repo.buf);\n> @@ -320,10 +325,12 @@ static int add(int ac, const char **av, const char *prefix)\n>  \t\tOPT_STRING('B', NULL, &new_branch_force, N_(\"branch\"),\n>  \t\t\t   N_(\"create or reset a branch\")),\n>  \t\tOPT_BOOL(0, \"detach\", &opts.detach, N_(\"detach HEAD at named commit\")),\n> +\t\tOPT_BOOL(0, \"checkout\", &opts.checkout, N_(\"populate the new working tree\")),\n>  \t\tOPT_END()\n>  \t};\n>  \n>  \tmemset(&opts, 0, sizeof(opts));\n> +\topts.checkout = 1;\n>  \tac = parse_options(ac, av, prefix, options, worktree_usage, 0);\n>  \tif (!!opts.detach + !!opts.new_branch + !!new_branch_force > 1)\n>  \t\tdie(_(\"-b, -B, and --detach are mutually exclusive\"));\n> diff --git a/t/t2025-worktree-add.sh b/t/t2025-worktree-add.sh\n> index cbfa41e..3acb992 100755\n> --- a/t/t2025-worktree-add.sh\n> +++ b/t/t2025-worktree-add.sh\n> @@ -213,4 +213,16 @@ test_expect_success 'local clone from linked checkout' '\n>  \t( cd here-clone && git fsck )\n>  '\n>  \n> +test_expect_success '\"add\" worktree with --no-checkout' '\n> +\tgit worktree add --no-checkout -b swamp swamp &&\n> +\t! test -e swamp/init.t &&\n> +\tgit -C swamp reset --hard &&\n> +\ttest_cmp init.t swamp/init.t\n> +'\n> +\n> +test_expect_success '\"add\" worktree with --checkout' '\n> +\tgit worktree add --checkout -b swmap2 swamp2 &&\n> +\ttest_cmp init.t swamp2/init.t\n> +'\n> +\n>  test_done\n> \n> --\n> https://github.com/git/git/pull/217\n> --\n> To unsubscribe from this list: send the line \"unsubscribe git\" in\n> the body of a message to majordomo@vger.kernel.org\n> More majordomo info at  http://vger.kernel.org/majordomo-info.html\n"},{"id":"282076","messageId":"CAPig+cSUr1FK68qhHOf+M_tHqELW_ocJFU4-4kpjGVFV0R+F2g@mail.gmail.com","threadId":"41797","inReplyTo":"20160329105402.GB1578@serenity.lan","subject":"Re: [PATCH v5] worktree: add: introduce --checkout option","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2016-03-29T18:04:38Z","receivedAt":"2016-03-29T18:04:38Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Tue, Mar 29, 2016 at 6:54 AM, John Keeping <john@keeping.me.uk> wrote:\n> On Tue, Mar 29, 2016 at 10:11:01AM +0000, Ray Zhang wrote:\n>>       With `add`, detach HEAD in the new working tree. See \"DETACHED HEAD\"\n>>       in linkgit:git-checkout[1].\n>>\n>> +--[no-]checkout::\n>\n> This should be:\n>\n> --checkout::\n> --no-checkout::\n>\n> (see for example --progress in Documentation/merge-options.txt).\n\n[1] suggested either form without stating a preference since existing\nGit documentation uses a mixture of the two. See, for instance,\ngit-format-patch.txt. However, I see now that --[no-]-option is the\nminority.\n\n[1]: http://article.gmane.org/gmane.comp.version-control.git/289840\n"},{"id":"282081","messageId":"CAPig+cSgTK3M7UTssiTB_Kc-UgywcbotToD64E6wUWFGDUm1mg@mail.gmail.com","threadId":"41797","inReplyTo":"CAPig+cSkE-xoaXnXHZHB4xz=ehCR973PaKbZJRyiTvHWn0AyoA@mail.gmail.com","subject":"Re: [PATCH v4] worktree: add: introduce --checkout option","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2016-03-29T18:43:30Z","receivedAt":"2016-03-29T18:43:30Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"[re-sending this to the list since it's relevant, and I somehow\naccidentally dropped the list]\n\nOn Mon, Mar 28, 2016 at 1:13 PM, Eric Sunshine <sunshine@sunshineco.com> wrote:\n> On Mon, Mar 28, 2016 at 6:52 AM, Ray Zhang <zhanglei002@gmail.com> wrote:\n>> By adding this option which defaults to true, we can use the\n>> corresponding --no-checkout to make some customizations before\n>> the checkout, like sparse checkout, etc.\n>>\n>> Reviewed-by: Eric Sunshine <sunshine@sunshineco.com>\n>> Signed-off-by: Ray Zhang <zhanglei002@gmail.com>\n>> ---\n>> Changes since last version of this patch[v3]:\n>>         Documentation/git-worktree.txt: HEAD --> `<branch>`\n>>         t/t2025-worktree-add.sh: fix style\n>\n> Thanks, this version addresses the minor issues raised with the previous one.\n>\n> One observation below...\n>\n>> diff --git a/builtin/worktree.c b/builtin/worktree.c\n>> @@ -284,11 +285,13 @@ static int add_worktree(const char *path, const char *refname,\n>>         if (ret)\n>>                 goto done;\n>>\n>> -       cp.argv = NULL;\n>> -       argv_array_clear(&cp.args);\n>> -       argv_array_pushl(&cp.args, \"reset\", \"--hard\", NULL);\n>> -       cp.env = child_env.argv;\n>> -       ret = run_command(&cp);\n>> +       if (opts->checkout) {\n>> +               cp.argv = NULL;\n>> +               argv_array_clear(&cp.args);\n>> +               argv_array_pushl(&cp.args, \"reset\", \"--hard\", NULL);\n>> +               cp.env = child_env.argv;\n>> +               ret = run_command(&cp);\n>> +       }\n>>         if (!ret) {\n>>                 is_junk = 0;\n>>                 free(junk_work_tree);\n>\n> In the no-checkout case, this code effectively becomes:\n>\n>     ret = run_command(\"update-ref\"/\"symbolic-ref\");\n>     if (ret)\n>         goto done;\n>     ...\n>     if (!ret)\n>         ...free stuff...\n>     done:\n>         ...\n>\n> 'ret' does not change value, so it's a bit odd to have an 'if (ret)'\n> conditional immediately followed by an 'if (!ret)'.\n>\n> It might be cleaner to re-organize the code slightly so that 'if\n> (ret)' is used after all run_command()s, and then outdent the \"...free\n> stuff...\" code, like this:\n>\n>     ret = run_command(...);\n>     if (ret)\n>         goto done;\n>     if (checkout) {\n>         ret = run_command(...)\n>         if (ret)\n>             goto done;\n>     }\n>     ...free stuff...\n>     done:\n>         ...\n>\n> This is a very minor issue, and I'm not even convinced that the code\n> is any clearer this way, so it's not something which should hold up\n> this patch. If you try it and find it nicer, then it could be done as\n> a follow-on cleanup patch (or a preparatory cleanup patch if you want\n> to re-roll, but that's probably not necessary).\n>\n> I should have mentioned this earlier since I specifically looked for\n> it with a previous version of the patch, but unfortunately didn't\n> quite spot it. This time I did spot it.\n"},{"id":"282090","messageId":"CAPig+cRimDGFDk7A2p2rKpJ2GR27_R=BJdpyPK4xeyDU1TruWQ@mail.gmail.com","threadId":"41797","inReplyTo":"01020153c1dae323-b918e73f-f116-4760-9747-9aa8cafb2db5-000000@eu-west-1.amazonses.com","subject":"Re: [PATCH v5] worktree: add: introduce --checkout option","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2016-03-29T19:20:47Z","receivedAt":"2016-03-29T19:20:47Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Tue, Mar 29, 2016 at 6:11 AM, Ray Zhang <zhanglei002@gmail.com> wrote:\n> By adding this option which defaults to true, we can use the\n> corresponding --no-checkout to make some customizations before\n> the checkout, like sparse checkout, etc.\n>\n> Reviewed-by: Eric Sunshine <sunshine@sunshineco.com>\n> Signed-off-by: Ray Zhang <zhanglei002@gmail.com>\n> ---\n> Changes since last version of this patch[v4]:\n>         t/t2025-worktree-add.sh: use test -e to test file existence.\n>         builtin/worktree.c: refactor the code a little bit.\n\nThanks, this version is still:\n\n    Reviewed-by: Eric Sunshine <sunshine@sunshineco.com>\n\nA couple comments below...\n\n> ---\n> diff --git a/builtin/worktree.c b/builtin/worktree.c\n> @@ -284,18 +285,22 @@ static int add_worktree(const char *path, const char *refname,\n>         if (ret)\n>                 goto done;\n>\n> -       cp.argv = NULL;\n> -       argv_array_clear(&cp.args);\n> -       argv_array_pushl(&cp.args, \"reset\", \"--hard\", NULL);\n> -       cp.env = child_env.argv;\n> -       ret = run_command(&cp);\n> -       if (!ret) {\n> -               is_junk = 0;\n> -               free(junk_work_tree);\n> -               free(junk_git_dir);\n> -               junk_work_tree = NULL;\n> -               junk_git_dir = NULL;\n> +       if (opts->checkout) {\n> +               cp.argv = NULL;\n> +               argv_array_clear(&cp.args);\n> +               argv_array_pushl(&cp.args, \"reset\", \"--hard\", NULL);\n> +               cp.env = child_env.argv;\n> +               ret = run_command(&cp);\n> +               if (ret)\n> +                       goto done;\n>         }\n> +\n> +       is_junk = 0;\n> +       free(junk_work_tree);\n> +       free(junk_git_dir);\n> +       junk_work_tree = NULL;\n> +       junk_git_dir = NULL;\n\nDoing the goto-dance and outdenting the \"freeing\" code as suggested as\na possible improvement by [1] probably should have been done as a\nseparate preparatory patch since the result in this patch is fairly\nnoisy and more difficult to review. However, it's probably not worth\nthe patch churn to do so now.\n\n>  done:\n>         strbuf_reset(&sb);\n>         strbuf_addf(&sb, \"%s/locked\", sb_repo.buf);\n> diff --git a/t/t2025-worktree-add.sh b/t/t2025-worktree-add.sh\n> +test_expect_success '\"add\" worktree with --no-checkout' '\n> +       git worktree add --no-checkout -b swamp swamp &&\n> +       ! test -e swamp/init.t &&\n\nI realize that this was suggested by [2], however, a more modern way\nto state this would be:\n\n    test_path_is_missing swamp/init.t &&\n\nbut, as also mentioned in [2], it's probably not worth the patch churn\nto change it now.\n\n> +       git -C swamp reset --hard &&\n> +       test_cmp init.t swamp/init.t\n> +'\n> +\n> +test_expect_success '\"add\" worktree with --checkout' '\n> +       git worktree add --checkout -b swmap2 swamp2 &&\n> +       test_cmp init.t swamp2/init.t\n> +'\n> +\n>  test_done\n\n[1]: http://git.661346.n2.nabble.com/PATCH-add-option-n-no-checkout-to-git-worktree-add-tp7651385p7651884.html\n\n[2]: http://article.gmane.org/gmane.comp.version-control.git/290050\n"},{"id":"282105","messageId":"20160329201501.GE1578@serenity.lan","threadId":"41797","inReplyTo":"CAPig+cSUr1FK68qhHOf+M_tHqELW_ocJFU4-4kpjGVFV0R+F2g@mail.gmail.com","subject":"Re: [PATCH v5] worktree: add: introduce --checkout option","fromName":"John Keeping","fromEmail":"john@keeping.me.uk","sentAt":"2016-03-29T20:15:01Z","receivedAt":"2016-03-29T20:15:01Z","isPatch":true,"sender":{"key":"john@keeping.me.uk","avatar":"https://avatars.githubusercontent.com/u/1702081?v=4"},"body":"On Tue, Mar 29, 2016 at 02:04:38PM -0400, Eric Sunshine wrote:\n> On Tue, Mar 29, 2016 at 6:54 AM, John Keeping <john@keeping.me.uk> wrote:\n> > On Tue, Mar 29, 2016 at 10:11:01AM +0000, Ray Zhang wrote:\n> >>       With `add`, detach HEAD in the new working tree. See \"DETACHED HEAD\"\n> >>       in linkgit:git-checkout[1].\n> >>\n> >> +--[no-]checkout::\n> >\n> > This should be:\n> >\n> > --checkout::\n> > --no-checkout::\n> >\n> > (see for example --progress in Documentation/merge-options.txt).\n> \n> [1] suggested either form without stating a preference since existing\n> Git documentation uses a mixture of the two. See, for instance,\n> git-format-patch.txt. However, I see now that --[no-]-option is the\n> minority.\n> \n> [1]: http://article.gmane.org/gmane.comp.version-control.git/289840\n\nI tend to skim the mailing list so I didn't register that at the time.\n\nHaving gone looking, I can't find a reference but I for some reason I\nwas convinced the separate version was preferred in the option\ndescriptions.  Note that AsciiDoc does handle this specially, at least\nwhen outputting troff (HTML seems to show both on separate lines).\n"},{"id":"282113","messageId":"xmqqegatvxk4.fsf@gitster.mtv.corp.google.com","threadId":"41797","inReplyTo":"20160329201501.GE1578@serenity.lan","subject":"Re: [PATCH v5] worktree: add: introduce --checkout option","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-03-29T20:28:11Z","receivedAt":"2016-03-29T20:28:11Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"John Keeping <john@keeping.me.uk> writes:\n\n> Having gone looking, I can't find a reference but I for some reason I\n> was convinced the separate version was preferred in the option\n> descriptions. \n\nThe one that is similar that came back to my mind while reading your\nresponse was that we used to have these:\n\n\t--foo, --bar::\n\t\tDescription...\n\nand corrected them to:\n\n\t--foo::\n        --bar::\n\t\tDescription...\n"},{"id":"282187","messageId":"CABEEbiArWe+Tq2CYMw+54PkeOAnHqU+tw6iLDW2wRuGHJ964EQ@mail.gmail.com","threadId":"41797","inReplyTo":"CAPig+cRimDGFDk7A2p2rKpJ2GR27_R=BJdpyPK4xeyDU1TruWQ@mail.gmail.com","subject":"Re: [PATCH v5] worktree: add: introduce --checkout option","fromName":"Zhang Lei","fromEmail":"zhanglei002@gmail.com","sentAt":"2016-03-30T03:11:07Z","receivedAt":"2016-03-30T03:11:07Z","isPatch":true,"sender":{"key":"zhanglei002@gmail.com","avatar":"https://avatars.githubusercontent.com/u/4970552?v=4"},"body":"Thanks for the review.\nSorry for the patch churn, I wasn't quite familiar with working with\nmailing list.\n\n2016-03-30 3:20 GMT+08:00 Eric Sunshine <sunshine@sunshineco.com>:\n> On Tue, Mar 29, 2016 at 6:11 AM, Ray Zhang <zhanglei002@gmail.com> wrote:\n>> By adding this option which defaults to true, we can use the\n>> corresponding --no-checkout to make some customizations before\n>> the checkout, like sparse checkout, etc.\n>>\n>> Reviewed-by: Eric Sunshine <sunshine@sunshineco.com>\n>> Signed-off-by: Ray Zhang <zhanglei002@gmail.com>\n>> ---\n>> Changes since last version of this patch[v4]:\n>>         t/t2025-worktree-add.sh: use test -e to test file existence.\n>>         builtin/worktree.c: refactor the code a little bit.\n>\n> Thanks, this version is still:\n>\n>     Reviewed-by: Eric Sunshine <sunshine@sunshineco.com>\n>\n> A couple comments below...\n>\n>> ---\n>> diff --git a/builtin/worktree.c b/builtin/worktree.c\n>> @@ -284,18 +285,22 @@ static int add_worktree(const char *path, const char *refname,\n>>         if (ret)\n>>                 goto done;\n>>\n>> -       cp.argv = NULL;\n>> -       argv_array_clear(&cp.args);\n>> -       argv_array_pushl(&cp.args, \"reset\", \"--hard\", NULL);\n>> -       cp.env = child_env.argv;\n>> -       ret = run_command(&cp);\n>> -       if (!ret) {\n>> -               is_junk = 0;\n>> -               free(junk_work_tree);\n>> -               free(junk_git_dir);\n>> -               junk_work_tree = NULL;\n>> -               junk_git_dir = NULL;\n>> +       if (opts->checkout) {\n>> +               cp.argv = NULL;\n>> +               argv_array_clear(&cp.args);\n>> +               argv_array_pushl(&cp.args, \"reset\", \"--hard\", NULL);\n>> +               cp.env = child_env.argv;\n>> +               ret = run_command(&cp);\n>> +               if (ret)\n>> +                       goto done;\n>>         }\n>> +\n>> +       is_junk = 0;\n>> +       free(junk_work_tree);\n>> +       free(junk_git_dir);\n>> +       junk_work_tree = NULL;\n>> +       junk_git_dir = NULL;\n>\n> Doing the goto-dance and outdenting the \"freeing\" code as suggested as\n> a possible improvement by [1] probably should have been done as a\n> separate preparatory patch since the result in this patch is fairly\n> noisy and more difficult to review. However, it's probably not worth\n> the patch churn to do so now.\n>\n>>  done:\n>>         strbuf_reset(&sb);\n>>         strbuf_addf(&sb, \"%s/locked\", sb_repo.buf);\n>> diff --git a/t/t2025-worktree-add.sh b/t/t2025-worktree-add.sh\n>> +test_expect_success '\"add\" worktree with --no-checkout' '\n>> +       git worktree add --no-checkout -b swamp swamp &&\n>> +       ! test -e swamp/init.t &&\n>\n> I realize that this was suggested by [2], however, a more modern way\n> to state this would be:\n>\n>     test_path_is_missing swamp/init.t &&\n>\n> but, as also mentioned in [2], it's probably not worth the patch churn\n> to change it now.\n>\n>> +       git -C swamp reset --hard &&\n>> +       test_cmp init.t swamp/init.t\n>> +'\n>> +\n>> +test_expect_success '\"add\" worktree with --checkout' '\n>> +       git worktree add --checkout -b swmap2 swamp2 &&\n>> +       test_cmp init.t swamp2/init.t\n>> +'\n>> +\n>>  test_done\n>\n> [1]: http://git.661346.n2.nabble.com/PATCH-add-option-n-no-checkout-to-git-worktree-add-tp7651385p7651884.html\n>\n> [2]: http://article.gmane.org/gmane.comp.version-control.git/290050\n"},{"id":"282256","messageId":"CAPig+cR6pNwrpABHX_4TNtKUSUR8gqACm4=a6gCphjQRkL8XDQ@mail.gmail.com","threadId":"41797","inReplyTo":"CABEEbiArWe+Tq2CYMw+54PkeOAnHqU+tw6iLDW2wRuGHJ964EQ@mail.gmail.com","subject":"Re: [PATCH v5] worktree: add: introduce --checkout option","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2016-03-30T17:59:27Z","receivedAt":"2016-03-30T17:59:27Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"[please don't top-post]\n\nOn Tue, Mar 29, 2016 at 11:11 PM, Zhang Lei <zhanglei002@gmail.com> wrote:\n> Thanks for the review.\n> Sorry for the patch churn, I wasn't quite familiar with working with\n> mailing list.\n\nNo need to apologize. Reviewers understand what it is like being a\nnewcomer and provide additional review comments to help get up to\nspeed. Thanks for working on this enhancement.\n"}]}