From: Junio C Hamano Date: Wed, 15 Jul 2026 15:17:06 GMT Subject: Re: [PATCH] diff: ignore unmerged paths outside prefix with --relative --cached Message-ID: In-Reply-To: <20260715060523.GA517940@coredump.intra.peff.net> Jeff King writes: > A diff using --relative ignores entries outside the current directory. > This results in a segfault when we try to process an unmerged entry > that's outside of our prefix, since we end up with a NULL diff_filepair > and use it without checking that it's valid. > ... > +cc Junio, as you may have some wisdom on that further exploration. Will take a look at the history myself, but I would probably not have much wisdom on a change from 2011. I often do not even remember what I ate for breakfast yesterday ;-). > diff-lib.c | 2 +- > t/t4045-diff-relative.sh | 9 +++++++++ > 2 files changed, 10 insertions(+), 1 deletion(-) > > diff --git a/diff-lib.c b/diff-lib.c > index ae91027a02..a23119b852 100644 > --- a/diff-lib.c > +++ b/diff-lib.c > @@ -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; > diff --git a/t/t4045-diff-relative.sh b/t/t4045-diff-relative.sh > index 2c8493fe66..167be0bdcc 100755 > --- a/t/t4045-diff-relative.sh > +++ b/t/t4045-diff-relative.sh > @@ -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