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
This commit is contained in:
commit
6eb593a764
@ -333,7 +333,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
|
|||||||
if (reset_type == NONE)
|
if (reset_type == NONE)
|
||||||
reset_type = MIXED; /* by default */
|
reset_type = MIXED; /* by default */
|
||||||
|
|
||||||
if (reset_type != SOFT && reset_type != MIXED)
|
if (reset_type != SOFT && (reset_type != MIXED || get_git_work_tree()))
|
||||||
setup_work_tree();
|
setup_work_tree();
|
||||||
|
|
||||||
if (reset_type == MIXED && is_bare_repository())
|
if (reset_type == MIXED && is_bare_repository())
|
||||||
@ -356,6 +356,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
|
|||||||
int flags = quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN;
|
int flags = quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN;
|
||||||
if (read_from_tree(&pathspec, sha1, intent_to_add))
|
if (read_from_tree(&pathspec, sha1, intent_to_add))
|
||||||
return 1;
|
return 1;
|
||||||
|
if (get_git_work_tree())
|
||||||
refresh_index(&the_index, flags, NULL, NULL,
|
refresh_index(&the_index, flags, NULL, NULL,
|
||||||
_("Unstaged changes after reset:"));
|
_("Unstaged changes after reset:"));
|
||||||
} else {
|
} else {
|
||||||
|
@ -550,4 +550,15 @@ test_expect_success 'reset -N keeps removed files as intent-to-add' '
|
|||||||
test_cmp expect actual
|
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
|
test_done
|
||||||
|
Loading…
Reference in New Issue
Block a user