reset: optionally setup worktree and refresh index on --mixed
Refreshing index requires work tree. So we have two options: always set up work tree (and refuse to reset if failing to do so), or make refreshing index optional. As refreshing index is not the main task, it makes more sense to make it optional. This allows us to still work in a bare repository to update what is in the index. Reported-by: Patrick Palka <patrick@parcs.ath.cx> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Feb 16, 2014 at 09:28 UTC
b7756d41dcc6720e6005b663bcb6f8b2f2a66763
2 files changed
+15
-3
builtin/reset.c
+4
-3
@@ -320,7 +320,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
320
if (reset_type == NONE)
321
reset_type = MIXED; /* by default */
322
323
- if (reset_type != SOFT && reset_type != MIXED)
323
+ if (reset_type != SOFT && (reset_type != MIXED || get_git_work_tree()))
324
setup_work_tree();
325
326
if (reset_type == MIXED && is_bare_repository())
@@ -340,8 +340,9 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
340
int flags = quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN;
341
if (read_from_tree(&pathspec, sha1))
342
return 1;
343
- refresh_index(&the_index, flags, NULL, NULL,
344
- _("Unstaged changes after reset:"));
343
+ if (get_git_work_tree())
344
+ refresh_index(&the_index, flags, NULL, NULL,
345
+ _("Unstaged changes after reset:"));
346
} else {
347
int err = reset_index(sha1, reset_type, quiet);
348
if (reset_type == KEEP && !err)
t/t7102-reset.sh
+11
@@ -535,4 +535,15 @@ test_expect_success 'reset with paths accepts tree' '
535
git diff HEAD --exit-code
536
'
537
538
+test_expect_success 'reset --mixed sets up work tree' '
539
+ git init mixed_worktree &&
540
+ (
541
+ cd mixed_worktree &&
542
+ test_commit dummy
543
+ ) &&
544
+ : >expect &&
545
+ git --git-dir=mixed_worktree/.git --work-tree=mixed_worktree reset >actual &&
546
+ test_cmp expect actual
547
+'
548
+
549
test_done