Skip to content

Commit a8a2491

Browse files
committed
Merge branch 'dl/stash-show-untracked-fixup'
The code to handle options recently added to "git stash show" around untracked part of the stash segfaulted when these options were used on a stash entry that does not record untracked part. * dl/stash-show-untracked-fixup: stash show: fix segfault with --{include,only}-untracked t3905: correct test title
2 parents 16f9145 + 1ff595d commit a8a2491

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

builtin/stash.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -902,10 +902,14 @@ static int show_stash(int argc, const char **argv, const char *prefix)
902902
diff_tree_oid(&info.b_commit, &info.w_commit, "", &rev.diffopt);
903903
break;
904904
case UNTRACKED_ONLY:
905-
diff_root_tree_oid(&info.u_tree, "", &rev.diffopt);
905+
if (info.has_u)
906+
diff_root_tree_oid(&info.u_tree, "", &rev.diffopt);
906907
break;
907908
case UNTRACKED_INCLUDE:
908-
diff_include_untracked(&info, &rev.diffopt);
909+
if (info.has_u)
910+
diff_include_untracked(&info, &rev.diffopt);
911+
else
912+
diff_tree_oid(&info.b_commit, &info.w_commit, "", &rev.diffopt);
909913
break;
910914
}
911915
log_tree_diff_flush(&rev);

t/t3905-stash-include-untracked.sh

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ test_expect_success 'stash show --only-untracked only shows untracked files' '
367367
test_cmp expect actual
368368
'
369369

370-
test_expect_success 'stash show --no-include-untracked cancels --{include,show}-untracked' '
370+
test_expect_success 'stash show --no-include-untracked cancels --{include,only}-untracked' '
371371
git reset --hard &&
372372
git clean -xf &&
373373
>untracked &&
@@ -405,4 +405,19 @@ test_expect_success 'stash show --include-untracked errors on duplicate files' '
405405
test_i18ngrep "worktree and untracked commit have duplicate entries: tracked" err
406406
'
407407

408+
test_expect_success 'stash show --{include,only}-untracked on stashes without untracked entries' '
409+
git reset --hard &&
410+
git clean -xf &&
411+
>tracked &&
412+
git add tracked &&
413+
git stash &&
414+
415+
git stash show >expect &&
416+
git stash show --include-untracked >actual &&
417+
test_cmp expect actual &&
418+
419+
git stash show --only-untracked >actual &&
420+
test_must_be_empty actual
421+
'
422+
408423
test_done

0 commit comments

Comments
 (0)