git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] diff: ignore unmerged paths outside prefix with --relative --cached

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 24, 2026, 21:30 UTC
Message-ID
<xmqqo6fw3wki.fsf@gitster.g>
In-Reply-To
<20260715060523.GA517940@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 13 quoted lines
> 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;

OK, so if diff_unmerge() gives a NULL for a path outside out area of interest, we of course do not fill the filepair and return. We won't do any further processing, like showing the entry or recursing into it, and diff_queued_diff hasn't been told about this path (as diff_unmerge() returns NULL before queuing the pair), so it is the end of story for this path here.

Looks good to me.
Show 18 quoted lines
> 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
Previous: Junio C Hamano
Message 12 of 12 in “diff: ignore unmerged paths outside prefix with --relative --cached”
  1. diff: ignore unmerged paths outside prefix with --relative --cachedJeff King, Jul 15, 2026
  2. Junio C HamanoJul 15, 2026
  3. 0/2 diff-lib relative-path cleanupsJeff King, Jul 26, 2026
  4. 1/2 diff-lib: drop stale comment about advancing o->posJeff King, Jul 26, 2026
  5. 2/2 diff-lib: skip paths outside prefix in oneway_diff()Jeff King, Jul 26, 2026
  6. Jeff KingJul 27, 2026
  7. Junio C HamanoJul 28, 2026
  8. diff-lib: add idx/tree sanity check to oneway_diffJeff King, Jul 28, 2026
  9. Junio C HamanoJul 28, 2026
  10. Jeff KingJul 28, 2026
  11. Junio C HamanoJul 26, 2026
  12. Junio C HamanoJul 24, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.