stash show: fix segfault with --{include,only}-untracked
When `git stash show --include-untracked` or `git stash show --only-untracked` is run on a stash that doesn't include an untracked entry, a segfault occurs. This happens because we do not check whether the untracked entry is actually present and just attempt to blindly dereference it. Ensure that the untracked entry is present before actually attempting to dereference it. Signed-off-by: Denton Liu <liu.denton@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
aa2b05d9f6
commit
1ff595d218
|
@ -900,10 +900,14 @@ static int show_stash(int argc, const char **argv, const char *prefix)
|
||||||
diff_tree_oid(&info.b_commit, &info.w_commit, "", &rev.diffopt);
|
diff_tree_oid(&info.b_commit, &info.w_commit, "", &rev.diffopt);
|
||||||
break;
|
break;
|
||||||
case UNTRACKED_ONLY:
|
case UNTRACKED_ONLY:
|
||||||
|
if (info.has_u)
|
||||||
diff_root_tree_oid(&info.u_tree, "", &rev.diffopt);
|
diff_root_tree_oid(&info.u_tree, "", &rev.diffopt);
|
||||||
break;
|
break;
|
||||||
case UNTRACKED_INCLUDE:
|
case UNTRACKED_INCLUDE:
|
||||||
|
if (info.has_u)
|
||||||
diff_include_untracked(&info, &rev.diffopt);
|
diff_include_untracked(&info, &rev.diffopt);
|
||||||
|
else
|
||||||
|
diff_tree_oid(&info.b_commit, &info.w_commit, "", &rev.diffopt);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
log_tree_diff_flush(&rev);
|
log_tree_diff_flush(&rev);
|
||||||
|
|
|
@ -405,4 +405,19 @@ test_expect_success 'stash show --include-untracked errors on duplicate files' '
|
||||||
test_i18ngrep "worktree and untracked commit have duplicate entries: tracked" err
|
test_i18ngrep "worktree and untracked commit have duplicate entries: tracked" err
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'stash show --{include,only}-untracked on stashes without untracked entries' '
|
||||||
|
git reset --hard &&
|
||||||
|
git clean -xf &&
|
||||||
|
>tracked &&
|
||||||
|
git add tracked &&
|
||||||
|
git stash &&
|
||||||
|
|
||||||
|
git stash show >expect &&
|
||||||
|
git stash show --include-untracked >actual &&
|
||||||
|
test_cmp expect actual &&
|
||||||
|
|
||||||
|
git stash show --only-untracked >actual &&
|
||||||
|
test_must_be_empty actual
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
|
Loading…
Reference in New Issue