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

Commit 1f56977

Browse files
committed
Merge branch 'nd/reset-setup-worktree' into maint
"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 a8b3131 + b7756d4 commit 1f56977

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)