Skip to content

Commit 6e22345

Browse files
committed
Merge branch 'en/stash-df-fix'
"git stash apply" forgot to attempt restoring untracked files when it failed to restore changes to tracked ones. * en/stash-df-fix: stash: do not return before restoring untracked files
2 parents 27a70fa + 71cade5 commit 6e22345

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

builtin/stash.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -561,18 +561,19 @@ static int do_apply_stash(const char *prefix, struct stash_info *info,
561561
if (index)
562562
fprintf_ln(stderr, _("Index was not unstashed."));
563563

564-
return ret;
564+
goto restore_untracked;
565565
}
566566

567567
if (has_index) {
568568
if (reset_tree(&index_tree, 0, 0))
569-
return -1;
569+
ret = -1;
570570
} else {
571571
unstage_changes_unless_new(&c_tree);
572572
}
573573

574+
restore_untracked:
574575
if (info->has_u && restore_untracked(&info->u_tree))
575-
return error(_("could not restore untracked files from stash"));
576+
ret = error(_("could not restore untracked files from stash"));
576577

577578
if (!quiet) {
578579
struct child_process cp = CHILD_PROCESS_INIT;
@@ -592,7 +593,7 @@ static int do_apply_stash(const char *prefix, struct stash_info *info,
592593
run_command(&cp);
593594
}
594595

595-
return 0;
596+
return ret;
596597
}
597598

598599
static int apply_stash(int argc, const char **argv, const char *prefix)

t/t3903-stash.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,4 +1395,28 @@ test_expect_success 'git stash can pop directory -> file saved changes' '
13951395
)
13961396
'
13971397

1398+
test_expect_success 'restore untracked files even when we hit conflicts' '
1399+
git init restore_untracked_after_conflict &&
1400+
(
1401+
cd restore_untracked_after_conflict &&
1402+
1403+
echo hi >a &&
1404+
echo there >b &&
1405+
git add . &&
1406+
git commit -m first &&
1407+
echo hello >a &&
1408+
echo something >c &&
1409+
1410+
git stash push --include-untracked &&
1411+
1412+
echo conflict >a &&
1413+
git add a &&
1414+
git commit -m second &&
1415+
1416+
test_must_fail git stash pop &&
1417+
1418+
test_path_is_file c
1419+
)
1420+
'
1421+
13981422
test_done

0 commit comments

Comments
 (0)