Skip to content

Commit

Permalink
reset: optionally setup worktree and refresh index on --mixed
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Nguyễn Thái Ngọc Duy authored and Junio C Hamano committed Feb 18, 2014
1 parent 7bbc4e8 commit b7756d4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 4 additions & 3 deletions builtin/reset.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
if (reset_type == NONE)
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();

if (reset_type == MIXED && is_bare_repository())
Expand All @@ -340,8 +340,9 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
int flags = quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN;
if (read_from_tree(&pathspec, sha1))
return 1;
refresh_index(&the_index, flags, NULL, NULL,
_("Unstaged changes after reset:"));
if (get_git_work_tree())
refresh_index(&the_index, flags, NULL, NULL,
_("Unstaged changes after reset:"));
} else {
int err = reset_index(sha1, reset_type, quiet);
if (reset_type == KEEP && !err)
Expand Down
11 changes: 11 additions & 0 deletions t/t7102-reset.sh
Original file line number Diff line number Diff line change
Expand Up @@ -535,4 +535,15 @@ test_expect_success 'reset with paths accepts tree' '
git diff HEAD --exit-code
'

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

0 comments on commit b7756d4

Please sign in to comment.