diff --git a/t/t2501-cwd-empty.sh b/t/t2501-cwd-empty.sh index 398908dfc9..5af1fec6fe 100755 --- a/t/t2501-cwd-empty.sh +++ b/t/t2501-cwd-empty.sh @@ -121,7 +121,7 @@ test_expect_success 'reset --hard does not clean cwd incidentally' ' ' test_expect_success 'reset --hard fails if cwd needs to be removed' ' - test_required_dir_removal failure git reset --hard fd_conflict + test_required_dir_removal success git reset --hard fd_conflict ' test_expect_success 'merge does not clean cwd incidentally' ' diff --git a/unpack-trees.c b/unpack-trees.c index 6bc16f3a71..5852807d2f 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -2261,10 +2261,19 @@ static int verify_absent_1(const struct cache_entry *ce, int len; struct stat st; - if (o->index_only || !o->update || - o->reset == UNPACK_RESET_OVERWRITE_UNTRACKED) + if (o->index_only || !o->update) return 0; + if (o->reset == UNPACK_RESET_OVERWRITE_UNTRACKED) { + /* Avoid nuking startup_info->original_cwd... */ + if (startup_info->original_cwd && + !strcmp(startup_info->original_cwd, ce->name)) + return add_rejected_path(o, ERROR_CWD_IN_THE_WAY, + ce->name); + /* ...but nuke anything else. */ + return 0; + } + len = check_leading_path(ce->name, ce_namelen(ce), 0); if (!len) return 0;