From: Junio C Hamano Date: Fri, 14 Mar 2014 21:25:02 +0000 (-0700) Subject: Merge branch 'nd/reset-setup-worktree' X-Git-Tag: v2.0.0-rc0~127 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/6eb593a764303c05c7ca4f0fd107c5118b9cf7fb 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 --- 6eb593a764303c05c7ca4f0fd107c5118b9cf7fb diff --cc builtin/reset.c index 4fd1c6c51d,a991344358..f4e087596b --- a/builtin/reset.c +++ b/builtin/reset.c @@@ -354,10 -338,11 +354,11 @@@ int cmd_reset(int argc, const char **ar int newfd = hold_locked_index(lock, 1); if (reset_type == MIXED) { int flags = quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN; - if (read_from_tree(&pathspec, sha1)) + if (read_from_tree(&pathspec, sha1, intent_to_add)) 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) diff --cc t/t7102-reset.sh index bc0846f435,ee117e2e72..450529404c --- a/t/t7102-reset.sh +++ b/t/t7102-reset.sh @@@ -535,19 -535,15 +535,30 @@@ test_expect_success 'reset with paths a git diff HEAD --exit-code ' +test_expect_success 'reset -N keeps removed files as intent-to-add' ' + echo new-file >new-file && + git add new-file && + git reset -N HEAD && + + tree=$(git write-tree) && + git ls-tree $tree new-file >actual && + >expect && + test_cmp expect actual && + + git diff --name-only >actual && + echo new-file >expect && + 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