{"thread":{"id":"35869","subject":"git-reset does not seem to respect GIT_WORK_TREE","startedAt":"2014-02-14T18:57:36Z","lastAt":"2014-02-16T18:19:18Z","messageCount":6,"participants":["Patrick Palka","Nguyễn Thái Ngọc Duy","Duy Nguyen","Eric Sunshine"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"234784","messageId":"CA+C-WL_x=+OPn4Ec-6Y13w1+dd5G5v8W6=i15WH47pyP3ggjuw@mail.gmail.com","threadId":"35869","inReplyTo":null,"subject":"git-reset does not seem to respect GIT_WORK_TREE","fromName":"Patrick Palka","fromEmail":"patrick@parcs.ath.cx","sentAt":"2014-02-14T18:57:36Z","receivedAt":"2014-02-14T18:57:36Z","isPatch":false,"sender":{"key":"patrick@parcs.ath.cx","avatar":"https://avatars.githubusercontent.com/u/320253206?v=4"},"body":"Hi everyone,\n\nI noticed that git-reset does not seem to respect GIT_WORK_TREE.  Here\nis a simplified test case:\n\n$ mkdir src_dir && cd src_dir\n$ git init\n$ touch A && git add A && git commit -m \"Dummy commit.\"\n$ mkdir ../build_dir && cd ../build_dir\n$ export GIT_WORK_TREE=../src_dir\n$ export GIT_DIR=../src_dir/.git\n$ git reset\nUnstaged changes after reset:\nD       A\n\nThe final command \"git reset\" erroneously suggests that the file \"A\"\ndoes not exist in the working tree.  Does anybody know why git-reset\nbehaves this way?\n\nThanks,\nPatrick\n"},{"id":"234847","messageId":"1392455661-20665-1-git-send-email-pclouds@gmail.com","threadId":"35869","inReplyTo":"CA+C-WL_x=+OPn4Ec-6Y13w1+dd5G5v8W6=i15WH47pyP3ggjuw@mail.gmail.com","subject":"[PATCH] reset: setup worktree on --mixed","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2014-02-15T09:14:21Z","receivedAt":"2014-02-15T09:14:21Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"--mixed does mainly two things: read_from_tree(), which does not\nrequire a worktree, and refresh_index(), which does.\n\nReported-by: Patrick Palka <patrick@parcs.ath.cx>\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin/reset.c  |  2 +-\n t/t7102-reset.sh | 11 +++++++++++\n 2 files changed, 12 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/reset.c b/builtin/reset.c\nindex 6004803..9928c28 100644\n--- a/builtin/reset.c\n+++ b/builtin/reset.c\n@@ -320,7 +320,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)\n \tif (reset_type == NONE)\n \t\treset_type = MIXED; /* by default */\n \n-\tif (reset_type != SOFT && reset_type != MIXED)\n+\tif (reset_type != SOFT)\n \t\tsetup_work_tree();\n \n \tif (reset_type == MIXED && is_bare_repository())\ndiff --git a/t/t7102-reset.sh b/t/t7102-reset.sh\nindex 8d4b50d..ee117e2 100755\n--- a/t/t7102-reset.sh\n+++ b/t/t7102-reset.sh\n@@ -535,4 +535,15 @@ test_expect_success 'reset with paths accepts tree' '\n \tgit diff HEAD --exit-code\n '\n \n+test_expect_success 'reset --mixed sets up work tree' '\n+\tgit init mixed_worktree &&\n+\t(\n+\t\tcd mixed_worktree &&\n+\t\ttest_commit dummy\n+\t) &&\n+\t: >expect &&\n+\tgit --git-dir=mixed_worktree/.git --work-tree=mixed_worktree reset >actual &&\n+\ttest_cmp expect actual\n+'\n+\n test_done\n-- \n1.8.5.2.240.g8478abd\n"},{"id":"234848","messageId":"CACsJy8AChRw30Vb1ivn7HR2+MDgH5ZcGLgzugSrjaJhE=mHqXQ@mail.gmail.com","threadId":"35869","inReplyTo":"1392455661-20665-1-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH] reset: setup worktree on --mixed","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2014-02-15T09:38:49Z","receivedAt":"2014-02-15T09:38:49Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Sat, Feb 15, 2014 at 4:14 PM, Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:\n> --mixed does mainly two things: read_from_tree(), which does not\n> require a worktree, and refresh_index(), which does.\n\n.. and I should have run the entire test suite before sending this. It\nbreaks t7103.5 (reset --mixed in bare repository). That test seems\nwrong though, in my opinon..\n\n>\n> Reported-by: Patrick Palka <patrick@parcs.ath.cx>\n> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n> ---\n>  builtin/reset.c  |  2 +-\n>  t/t7102-reset.sh | 11 +++++++++++\n>  2 files changed, 12 insertions(+), 1 deletion(-)\n>\n> diff --git a/builtin/reset.c b/builtin/reset.c\n> index 6004803..9928c28 100644\n> --- a/builtin/reset.c\n> +++ b/builtin/reset.c\n> @@ -320,7 +320,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)\n>         if (reset_type == NONE)\n>                 reset_type = MIXED; /* by default */\n>\n> -       if (reset_type != SOFT && reset_type != MIXED)\n> +       if (reset_type != SOFT)\n>                 setup_work_tree();\n>\n>         if (reset_type == MIXED && is_bare_repository())\n> diff --git a/t/t7102-reset.sh b/t/t7102-reset.sh\n> index 8d4b50d..ee117e2 100755\n> --- a/t/t7102-reset.sh\n> +++ b/t/t7102-reset.sh\n> @@ -535,4 +535,15 @@ test_expect_success 'reset with paths accepts tree' '\n>         git diff HEAD --exit-code\n>  '\n>\n> +test_expect_success 'reset --mixed sets up work tree' '\n> +       git init mixed_worktree &&\n> +       (\n> +               cd mixed_worktree &&\n> +               test_commit dummy\n> +       ) &&\n> +       : >expect &&\n> +       git --git-dir=mixed_worktree/.git --work-tree=mixed_worktree reset >actual &&\n> +       test_cmp expect actual\n> +'\n> +\n>  test_done\n> --\n> 1.8.5.2.240.g8478abd\n>\n\n\n\n-- \nDuy\n"},{"id":"234871","messageId":"1392517683-29518-1-git-send-email-pclouds@gmail.com","threadId":"35869","inReplyTo":"1392455661-20665-1-git-send-email-pclouds@gmail.com","subject":"[PATCH v2] reset: optionally setup worktree and refresh index on --mixed","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2014-02-16T02:28:03Z","receivedAt":"2014-02-16T02:28:03Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Refreshing index requires work tree. So we have to options: always set\nup work tree (and refuse to reset if failing to do so), or make\nrefreshing index optional.\n\nAs refreshing index is not the main task, it makes more sense to make\nit optional.\n\nReported-by: Patrick Palka <patrick@parcs.ath.cx>\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin/reset.c  |  7 ++++---\n t/t7102-reset.sh | 11 +++++++++++\n 2 files changed, 15 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/reset.c b/builtin/reset.c\nindex 6004803..a991344 100644\n--- a/builtin/reset.c\n+++ b/builtin/reset.c\n@@ -320,7 +320,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)\n \tif (reset_type == NONE)\n \t\treset_type = MIXED; /* by default */\n \n-\tif (reset_type != SOFT && reset_type != MIXED)\n+\tif (reset_type != SOFT && (reset_type != MIXED || get_git_work_tree()))\n \t\tsetup_work_tree();\n \n \tif (reset_type == MIXED && is_bare_repository())\n@@ -340,8 +340,9 @@ int cmd_reset(int argc, const char **argv, const char *prefix)\n \t\t\tint flags = quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN;\n \t\t\tif (read_from_tree(&pathspec, sha1))\n \t\t\t\treturn 1;\n-\t\t\trefresh_index(&the_index, flags, NULL, NULL,\n-\t\t\t\t      _(\"Unstaged changes after reset:\"));\n+\t\t\tif (get_git_work_tree())\n+\t\t\t\trefresh_index(&the_index, flags, NULL, NULL,\n+\t\t\t\t\t      _(\"Unstaged changes after reset:\"));\n \t\t} else {\n \t\t\tint err = reset_index(sha1, reset_type, quiet);\n \t\t\tif (reset_type == KEEP && !err)\ndiff --git a/t/t7102-reset.sh b/t/t7102-reset.sh\nindex 8d4b50d..ee117e2 100755\n--- a/t/t7102-reset.sh\n+++ b/t/t7102-reset.sh\n@@ -535,4 +535,15 @@ test_expect_success 'reset with paths accepts tree' '\n \tgit diff HEAD --exit-code\n '\n \n+test_expect_success 'reset --mixed sets up work tree' '\n+\tgit init mixed_worktree &&\n+\t(\n+\t\tcd mixed_worktree &&\n+\t\ttest_commit dummy\n+\t) &&\n+\t: >expect &&\n+\tgit --git-dir=mixed_worktree/.git --work-tree=mixed_worktree reset >actual &&\n+\ttest_cmp expect actual\n+'\n+\n test_done\n-- \n1.8.5.2.240.g8478abd\n"},{"id":"234872","messageId":"CAPig+cTFxwnAA807rAaRfU6HZWthZFxUKzaKoLmPBVs+v4pMSQ@mail.gmail.com","threadId":"35869","inReplyTo":"1392517683-29518-1-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH v2] reset: optionally setup worktree and refresh index on --mixed","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2014-02-16T02:29:32Z","receivedAt":"2014-02-16T02:29:32Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Sat, Feb 15, 2014 at 9:28 PM, Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:\n> Refreshing index requires work tree. So we have to options: always set\n\ns/to/two/\n\n> up work tree (and refuse to reset if failing to do so), or make\n> refreshing index optional.\n>\n> As refreshing index is not the main task, it makes more sense to make\n> it optional.\n>\n> Reported-by: Patrick Palka <patrick@parcs.ath.cx>\n> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n> ---\n>  builtin/reset.c  |  7 ++++---\n>  t/t7102-reset.sh | 11 +++++++++++\n>  2 files changed, 15 insertions(+), 3 deletions(-)\n>\n> diff --git a/builtin/reset.c b/builtin/reset.c\n> index 6004803..a991344 100644\n> --- a/builtin/reset.c\n> +++ b/builtin/reset.c\n> @@ -320,7 +320,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)\n>         if (reset_type == NONE)\n>                 reset_type = MIXED; /* by default */\n>\n> -       if (reset_type != SOFT && reset_type != MIXED)\n> +       if (reset_type != SOFT && (reset_type != MIXED || get_git_work_tree()))\n>                 setup_work_tree();\n>\n>         if (reset_type == MIXED && is_bare_repository())\n> @@ -340,8 +340,9 @@ int cmd_reset(int argc, const char **argv, const char *prefix)\n>                         int flags = quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN;\n>                         if (read_from_tree(&pathspec, sha1))\n>                                 return 1;\n> -                       refresh_index(&the_index, flags, NULL, NULL,\n> -                                     _(\"Unstaged changes after reset:\"));\n> +                       if (get_git_work_tree())\n> +                               refresh_index(&the_index, flags, NULL, NULL,\n> +                                             _(\"Unstaged changes after reset:\"));\n>                 } else {\n>                         int err = reset_index(sha1, reset_type, quiet);\n>                         if (reset_type == KEEP && !err)\n> diff --git a/t/t7102-reset.sh b/t/t7102-reset.sh\n> index 8d4b50d..ee117e2 100755\n> --- a/t/t7102-reset.sh\n> +++ b/t/t7102-reset.sh\n> @@ -535,4 +535,15 @@ test_expect_success 'reset with paths accepts tree' '\n>         git diff HEAD --exit-code\n>  '\n>\n> +test_expect_success 'reset --mixed sets up work tree' '\n> +       git init mixed_worktree &&\n> +       (\n> +               cd mixed_worktree &&\n> +               test_commit dummy\n> +       ) &&\n> +       : >expect &&\n> +       git --git-dir=mixed_worktree/.git --work-tree=mixed_worktree reset >actual &&\n> +       test_cmp expect actual\n> +'\n> +\n>  test_done\n> --\n> 1.8.5.2.240.g8478abd\n>\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":"234905","messageId":"CA+C-WL9_WC7TVGJ7yhRM6T6zJ5Q+YGhPODU-vJsu53SOSs2cRg@mail.gmail.com","threadId":"35869","inReplyTo":"1392517683-29518-1-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH v2] reset: optionally setup worktree and refresh index on --mixed","fromName":"Patrick Palka","fromEmail":"patrick@parcs.ath.cx","sentAt":"2014-02-16T18:19:18Z","receivedAt":"2014-02-16T18:19:18Z","isPatch":true,"sender":{"key":"patrick@parcs.ath.cx","avatar":"https://avatars.githubusercontent.com/u/320253206?v=4"},"body":"On Sat, Feb 15, 2014 at 9:28 PM, Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:\n> Refreshing index requires work tree. So we have to options: always set\n> up work tree (and refuse to reset if failing to do so), or make\n> refreshing index optional.\n>\n> As refreshing index is not the main task, it makes more sense to make\n> it optional.\n>\n> Reported-by: Patrick Palka <patrick@parcs.ath.cx>\n> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n\nThanks!  I can confirm that this change fixes my use case.\n"}]}