Skip to content

Commit

Permalink
Merge branch 'dl/stash-show-untracked-fixup'
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gitster committed May 16, 2021
2 parents 16f9145 + 1ff595d commit a8a2491
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
8 changes: 6 additions & 2 deletions builtin/stash.c
Expand Up @@ -902,10 +902,14 @@ static int show_stash(int argc, const char **argv, const char *prefix)
diff_tree_oid(&info.b_commit, &info.w_commit, "", &rev.diffopt);
break;
case UNTRACKED_ONLY:
diff_root_tree_oid(&info.u_tree, "", &rev.diffopt);
if (info.has_u)
diff_root_tree_oid(&info.u_tree, "", &rev.diffopt);
break;
case UNTRACKED_INCLUDE:
diff_include_untracked(&info, &rev.diffopt);
if (info.has_u)
diff_include_untracked(&info, &rev.diffopt);
else
diff_tree_oid(&info.b_commit, &info.w_commit, "", &rev.diffopt);
break;
}
log_tree_diff_flush(&rev);
Expand Down
17 changes: 16 additions & 1 deletion t/t3905-stash-include-untracked.sh
Expand Up @@ -367,7 +367,7 @@ test_expect_success 'stash show --only-untracked only shows untracked files' '
test_cmp expect actual
'

test_expect_success 'stash show --no-include-untracked cancels --{include,show}-untracked' '
test_expect_success 'stash show --no-include-untracked cancels --{include,only}-untracked' '
git reset --hard &&
git clean -xf &&
>untracked &&
Expand Down Expand Up @@ -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_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

0 comments on commit a8a2491

Please sign in to comment.