diff options
author | Junio C Hamano <gitster@pobox.com> | 2014-03-18 14:03:24 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-03-18 14:03:24 -0700 |
commit | 1f569775810be1655c284076082015168865d005 (patch) | |
tree | c773162fe6f354f2db976193410d107bff8acf45 | |
parent | Merge branch 'jc/check-attr-honor-working-tree' into maint (diff) | |
parent | reset: optionally setup worktree and refresh index on --mixed (diff) | |
download | tgif-1f569775810be1655c284076082015168865d005.tar.xz |
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
-rw-r--r-- | builtin/reset.c | 7 | ||||
-rwxr-xr-x | t/t7102-reset.sh | 11 |
2 files changed, 15 insertions, 3 deletions
diff --git a/builtin/reset.c b/builtin/reset.c index 60048030dd..a991344358 100644 --- a/builtin/reset.c +++ b/builtin/reset.c @@ -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()) @@ -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) diff --git a/t/t7102-reset.sh b/t/t7102-reset.sh index 8d4b50d1b5..ee117e2e72 100755 --- a/t/t7102-reset.sh +++ b/t/t7102-reset.sh @@ -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 |