Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit b7756d4

Browse files
pcloudsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7bbc4e8 commit b7756d4

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

builtin/reset.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
320320
if (reset_type == NONE)
321321
reset_type = MIXED; /* by default */
322322

323-
if (reset_type != SOFT && reset_type != MIXED)
323+
if (reset_type != SOFT && (reset_type != MIXED || get_git_work_tree()))
324324
setup_work_tree();
325325

326326
if (reset_type == MIXED && is_bare_repository())
@@ -340,8 +340,9 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
340340
int flags = quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN;
341341
if (read_from_tree(&pathspec, sha1))
342342
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:"));
345346
} else {
346347
int err = reset_index(sha1, reset_type, quiet);
347348
if (reset_type == KEEP && !err)

t/t7102-reset.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,4 +535,15 @@ test_expect_success 'reset with paths accepts tree' '
535535
git diff HEAD --exit-code
536536
'
537537

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+
538549
test_done

0 commit comments

Comments
 (0)