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

Re: [PATCH] git-apply: allow empty patch text

From
EWEric Wong <e@80x24.org>
Date
Apr 27, 2021, 05:46 UTC
Message-ID
<20210427054632.GA31347@dcvr>
In-Reply-To
<20210427011246.28054-1-jerry@skydio.com>
Jerry Zhang <jerry@skydio.com> wrote:
Show 8 quoted lines
> "git diff" produces no patch text if
> there is no diff, but "git apply" exits
> with code 128 if the patch text is empty.
> 
> Since every valid "git diff" should
> result in a successful patch application
> when applied to the same preimage as
> the diff,
Should it result in successful patch application? (Why?)

I fear this change can cause errors in pipelines to go undetected (since "set -o pipefail" is not POSIX). In my experience, zero-byte files is also a common failure mode for some filesystems, even after fsck marked them as clean.

Perhaps guarding this behavior with --allow-empty (as commit and cherry-pick do) is safer.

Show 14 quoted lines
> diff --git a/t/t4126-apply-empty.sh b/t/t4126-apply-empty.sh
> index ceb6a79fe0..37351be609 100755
> --- a/t/t4126-apply-empty.sh
> +++ b/t/t4126-apply-empty.sh
> @@ -31,6 +31,13 @@ test_expect_success 'apply empty' '
>  	test_cmp expect empty
>  '
>  
> +test_expect_success 'apply empty diff' '
> +	git reset --hard &&
> +	git diff >empty.patch &&
> +	git apply empty.patch &&
> +	git diff | git apply -
> +'

It shouldn't be necessary to use "git diff" to generate empty output. Tests are too slow for me on Linux, even. Something like:

	>empty.patch &&
	git apply empty.patch &&
	git apply - <empty.patch

...ought to be realistic enough, but /dev/null in place of empty.patch is probably portable enough, too. Thanks.

Previous: Jerry ZhangNext: Junio C Hamano
Message 2 of 13 in “git-apply: allow empty patch text”
  1. git-apply: allow empty patch textJerry Zhang, Apr 27, 2021
  2. Eric WongApr 27, 2021
  3. Junio C HamanoApr 27, 2021
  4. git-apply: add --allow-empty flagJerry Zhang, Apr 27, 2021
  5. Junio C HamanoApr 28, 2021
  6. Jerry ZhangApr 28, 2021
  7. Ævar Arnfjörð BjarmasonApr 29, 2021
  8. git-apply: add --allow-empty flagJerry Zhang, Dec 11, 2021
  9. Bagas SanjayaDec 11, 2021
  10. git-apply: add --allow-empty flagJerry Zhang, Dec 13, 2021
  11. Junio C HamanoDec 13, 2021
  12. Jerry ZhangDec 13, 2021
  13. Junio C HamanoDec 13, 2021

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.