Git development
 help / color / mirror / Atom feed
From: Phillip Wood <phillip.wood123@gmail.com>
To: Tanga Joris <tangajoris@gmail.com>, git@vger.kernel.org
Cc: gitster@pobox.com, jackrawlings2011@gmail.com,
	christian.couder@gmail.com, siddharthasthana31@gmail.com,
	kaartic.sivaraam@gmail.com, usmanakinyemi202@gmail.com
Subject: Re: [Outreachy PATCH 1/2] apply: do not keep names from an unused "diff --git" line
Date: Mon, 9 Nov 2026 10:52:28 +0000	[thread overview]
Message-ID: <7bd3360a-fb96-4631-8670-dde0d281532c@gmail.com> (raw)
In-Reply-To: <20261107195429.96842-1-tangajoris@gmail.com>

Hi Tanga

On 07/11/2026 19:54, Tanga Joris wrote:
> When a "diff --git" line is followed by a line that is not a git
> header line, such as a blank line or an indented "new file mode"
> line,

These sound like corrupt patches which we should be rejecting with a 
better error message, rather than applying.

> +test_expect_success 'apply new file with a blank line after "diff --git"' '
> +	test_when_finished "rm -f f" &&
> +	cat >blank_line.diff <<-\EOF &&
> +	diff --git a/f b/f
> +
> +	new file mode 100644
> +	index 0000000..d00491f
> +	--- /dev/null
> +	+++ b/f
> +	@@ -0,0 +1 @@
> +	+1
> +	EOF

To me this looks like a corrupt patch because we have a blank line after 
the "diff --git" header followed by valid extended diff headers. Now 
that we accept this do we respect the file mode?

> +test_expect_success 'apply new file with an indented "new file mode" line' '
> +	test_when_finished "rm -f f" &&
> +	cat >indented_mode.diff <<-\EOF &&
> +	diff --git a/f b/f
> +	 new file mode 100644

This looks like a corrupt patch as well where a space has been 
accidentally introduced at the start of the line.

> +test_expect_success 'ignore an empty "diff --git" section' '
> +	test_when_finished "rm -f g" &&
> +	echo 1 >g &&
> +	cat >empty_section.diff <<-\EOF &&
> +	diff --git a/f b/f
> +	diff --git a/g b/g
> +	index d00491f..0cfbf08 100644
> +	--- a/g
> +	+++ b/g
> +	@@ -1 +1 @@
> +	-1
> +	+2
> +	EOF

This is the only one that I think it is reasonable to accept - we have 
an empty patch for "f" followed by a valid patch for "g"

Thanks

Phillip


  parent reply	other threads:[~2026-11-09 10:52 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-17 15:17 Git crashed on `git apply --check` Gingrspacecadet
2026-10-24  6:10 ` Tanga Joris
     [not found]   ` <CALdwsC11JHUBBTt3e_RFixLYSF0VU1C+mG7bQsO0vV=a68XHNw@mail.gmail.com>
2026-10-25 22:56     ` Tanga Joris
2026-11-07 19:54 ` [Outreachy PATCH 1/2] apply: do not keep names from an unused "diff --git" line Tanga Joris
2026-11-07 19:54   ` [Outreachy PATCH 2/2] apply: reject new and deleted files that have both names Tanga Joris
2026-11-09 10:52   ` Phillip Wood [this message]
2026-11-09 13:13     ` [Outreachy PATCH 1/2] apply: do not keep names from an unused "diff --git" line Tanga Joris
2026-11-09 14:31       ` Phillip Wood
2026-11-09 20:54         ` Tanga Joris
2026-11-09 21:06           ` Junio C Hamano
2026-11-09 23:03             ` Tanga Joris
2026-11-09 19:56     ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7bd3360a-fb96-4631-8670-dde0d281532c@gmail.com \
    --to=phillip.wood123@gmail.com \
    --cc=christian.couder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jackrawlings2011@gmail.com \
    --cc=kaartic.sivaraam@gmail.com \
    --cc=phillip.wood@dunelm.org.uk \
    --cc=siddharthasthana31@gmail.com \
    --cc=tangajoris@gmail.com \
    --cc=usmanakinyemi202@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox