Skip to content

Commit 6eb593a

Browse files
committed
Merge branch 'nd/reset-setup-worktree'
"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
2 parents ed27751 + b7756d4 commit 6eb593a

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
@@ -333,7 +333,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
333333
if (reset_type == NONE)
334334
reset_type = MIXED; /* by default */
335335

336-
if (reset_type != SOFT && reset_type != MIXED)
336+
if (reset_type != SOFT && (reset_type != MIXED || get_git_work_tree()))
337337
setup_work_tree();
338338

339339
if (reset_type == MIXED && is_bare_repository())
@@ -356,8 +356,9 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
356356
int flags = quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN;
357357
if (read_from_tree(&pathspec, sha1, intent_to_add))
358358
return 1;
359-
refresh_index(&the_index, flags, NULL, NULL,
360-
_("Unstaged changes after reset:"));
359+
if (get_git_work_tree())
360+
refresh_index(&the_index, flags, NULL, NULL,
361+
_("Unstaged changes after reset:"));
361362
} else {
362363
int err = reset_index(sha1, reset_type, quiet);
363364
if (reset_type == KEEP && !err)

t/t7102-reset.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,4 +550,15 @@ test_expect_success 'reset -N keeps removed files as intent-to-add' '
550550
test_cmp expect actual
551551
'
552552

553+
test_expect_success 'reset --mixed sets up work tree' '
554+
git init mixed_worktree &&
555+
(
556+
cd mixed_worktree &&
557+
test_commit dummy
558+
) &&
559+
: >expect &&
560+
git --git-dir=mixed_worktree/.git --work-tree=mixed_worktree reset >actual &&
561+
test_cmp expect actual
562+
'
563+
553564
test_done

0 commit comments

Comments
 (0)