Merge branch 'jk/diff-relative-cached-unmerged' into jch

'git diff --relative' running with '--cached' has been corrected to
avoid a segfault when encountering unmerged paths outside the
prefix.

* jk/diff-relative-cached-unmerged:
  diff: ignore unmerged paths outside prefix with --relative --cached
jch
Junio C Hamano 2026-07-24 14:40:40 -07:00
commit a557328866
2 changed files with 10 additions and 1 deletions

View File

@ -467,7 +467,7 @@ static void do_oneway_diff(struct unpack_trees_options *o,
if (cached && idx && ce_stage(idx)) {
struct diff_filepair *pair;
pair = diff_unmerge(&revs->diffopt, idx->name);
if (tree)
if (pair && tree)
fill_filespec(pair->one, &tree->oid, 1,
tree->ce_mode);
return;

View File

@ -245,4 +245,13 @@ test_expect_failure 'diff --relative with change in subdir' '
test_cmp expected out
'

test_expect_success 'diff --relative --cached with change in subdir' '
git switch br3 &&
test_when_finished "git merge --abort" &&
test_must_fail git merge sub1 &&
echo file0 >expected &&
git -C subdir diff --relative --name-only --cached >out &&
test_cmp expected out
'

test_done