Merge branch 'nd/reset-setup-worktree'
authorJunio C Hamano <gitster@pobox.com>
Fri, 14 Mar 2014 21:25:02 +0000 (14:25 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 14 Mar 2014 21:25:03 +0000 (14:25 -0700)
"git reset" needs to refresh the index when working in a working
tree (it can also be used to match the index to the HEAD in an
otherwise bare repository), but it failed to set up the working
tree properly, causing GIT_WORK_TREE to be ignored.

* nd/reset-setup-worktree:
reset: optionally setup worktree and refresh index on --mixed

1  2 
builtin/reset.c
t/t7102-reset.sh
diff --cc builtin/reset.c
index 4fd1c6c51d3ce5af60f2978f3839c0e595d3fece,a9913443580846b7c401c8c4517890ad91fe8ded..f4e087596b6337d2306af4cf45119752b4a049ea
@@@ -354,10 -338,11 +354,11 @@@ int cmd_reset(int argc, const char **ar
                int newfd = hold_locked_index(lock, 1);
                if (reset_type == MIXED) {
                        int flags = quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN;
 -                      if (read_from_tree(&pathspec, sha1))
 +                      if (read_from_tree(&pathspec, sha1, intent_to_add))
                                return 1;
-                       refresh_index(&the_index, flags, NULL, NULL,
-                                     _("Unstaged changes after reset:"));
+                       if (get_git_work_tree())
+                               refresh_index(&the_index, flags, NULL, NULL,
+                                             _("Unstaged changes after reset:"));
                } else {
                        int err = reset_index(sha1, reset_type, quiet);
                        if (reset_type == KEEP && !err)
index bc0846f4356e548cc72d3cf0c18ef00c21ede87d,ee117e2e727d2bcdc87053684f0c32486452a65e..450529404c686469ed5ba5ad465cf8b3ef651ef9
@@@ -535,19 -535,15 +535,30 @@@ test_expect_success 'reset with paths a
        git diff HEAD --exit-code
  '
  
 +test_expect_success 'reset -N keeps removed files as intent-to-add' '
 +      echo new-file >new-file &&
 +      git add new-file &&
 +      git reset -N HEAD &&
 +
 +      tree=$(git write-tree) &&
 +      git ls-tree $tree new-file >actual &&
 +      >expect &&
 +      test_cmp expect actual &&
 +
 +      git diff --name-only >actual &&
 +      echo new-file >expect &&
 +      test_cmp expect actual
 +'
 +
+ test_expect_success 'reset --mixed sets up work tree' '
+       git init mixed_worktree &&
+       (
+               cd mixed_worktree &&
+               test_commit dummy
+       ) &&
+       : >expect &&
+       git --git-dir=mixed_worktree/.git --work-tree=mixed_worktree reset >actual &&
+       test_cmp expect actual
+ '
  test_done