# Applying a patch with a diff header in its commit message

5 messages from 2021-06-28 to 2021-07-06. Participants: Pratyush Yadav, Felipe Contreras, Ævar Arnfjörð Bjarmason.
Thread: https://gitlist.dev/t/56021

## Pratyush Yadav, 2021-06-28 18:30

Subject: Applying a patch with a diff header in its commit message
Message-ID: <20210628183004.flxirucfv2celll3@yadavpratyush.com>
URL: https://gitlist.dev/e/20210628183004.flxirucfv2celll3%40yadavpratyush.com

```
Hi,

I have a patch at $DAYJOB that contains a diff header ("diff --git 
a/...") in its commit message, and unfortunately it is not indented. So 
naturally, git-am trips up and thinks it is the start of the main diff 
and tries to apply the diff starting there. It does not apply and the 
patch is rejected as being corrupt.

I know one option for me is to manually edit the patch and indent the 
diff header. But I would like to avoid that if possible. Is there any 
way to apply that patch as-is? Is it possible to tell git-am where to 
start looking for the diff?

-- 
Regards,
Pratyush Yadav

```

## Felipe Contreras, 2021-06-28 23:44

Subject: RE: Applying a patch with a diff header in its commit message
Message-ID: <60da5ed21ec8c_1f78f2082a@natae.notmuch>
URL: https://gitlist.dev/e/60da5ed21ec8c_1f78f2082a%40natae.notmuch
In-Reply-To: <20210628183004.flxirucfv2celll3@yadavpratyush.com>

```
Pratyush Yadav wrote:
> I have a patch at $DAYJOB that contains a diff header ("diff --git 
> a/...") in its commit message, and unfortunately it is not indented. So 
> naturally, git-am trips up and thinks it is the start of the main diff 
> and tries to apply the diff starting there. It does not apply and the 
> patch is rejected as being corrupt.
> 
> I know one option for me is to manually edit the patch and indent the 
> diff header. But I would like to avoid that if possible. Is there any 
> way to apply that patch as-is? Is it possible to tell git-am where to 
> start looking for the diff?

git apply?

-- 
Felipe Contreras

```

## Pratyush Yadav, 2021-07-06 08:17

Subject: Re: Applying a patch with a diff header in its commit message
Message-ID: <20210706081738.5th24lypiicnbckv@yadavpratyush.com>
URL: https://gitlist.dev/e/20210706081738.5th24lypiicnbckv%40yadavpratyush.com
In-Reply-To: <60da5ed21ec8c_1f78f2082a@natae.notmuch>

```
On 28/06/21 06:44PM, Felipe Contreras wrote:
> Pratyush Yadav wrote:
> > I have a patch at $DAYJOB that contains a diff header ("diff --git 
> > a/...") in its commit message, and unfortunately it is not indented. So 
> > naturally, git-am trips up and thinks it is the start of the main diff 
> > and tries to apply the diff starting there. It does not apply and the 
> > patch is rejected as being corrupt.
> > 
> > I know one option for me is to manually edit the patch and indent the 
> > diff header. But I would like to avoid that if possible. Is there any 
> > way to apply that patch as-is? Is it possible to tell git-am where to 
> > start looking for the diff?
> 
> git apply?

Sure, that is an option. But then I would have to copy/paste the commit 
message and add the author information manually. Is there any way to do 
this automatically? What if I have 100 commits like this?

This is a valid Git commit. It would be nice if the Git email tooling 
could handle it cleanly.

-- 
Regards,
Pratyush Yadav

```

## Ævar Arnfjörð Bjarmason, 2021-07-06 14:37

Subject: Re: Applying a patch with a diff header in its commit message
Message-ID: <87pmvv5ww8.fsf@evledraar.gmail.com>
URL: https://gitlist.dev/e/87pmvv5ww8.fsf%40evledraar.gmail.com
In-Reply-To: <20210706081738.5th24lypiicnbckv@yadavpratyush.com>

```

On Tue, Jul 06 2021, Pratyush Yadav wrote:

> On 28/06/21 06:44PM, Felipe Contreras wrote:
>> Pratyush Yadav wrote:
>> > I have a patch at $DAYJOB that contains a diff header ("diff --git 
>> > a/...") in its commit message, and unfortunately it is not indented. So 
>> > naturally, git-am trips up and thinks it is the start of the main diff 
>> > and tries to apply the diff starting there. It does not apply and the 
>> > patch is rejected as being corrupt.
>> > 
>> > I know one option for me is to manually edit the patch and indent the 
>> > diff header. But I would like to avoid that if possible. Is there any 
>> > way to apply that patch as-is? Is it possible to tell git-am where to 
>> > start looking for the diff?
>> 
>> git apply?
>
> Sure, that is an option. But then I would have to copy/paste the commit 
> message and add the author information manually. Is there any way to do 
> this automatically? What if I have 100 commits like this?
>
> This is a valid Git commit. It would be nice if the Git email tooling 
> could handle it cleanly.

I don't think there is, but it could be fixed.

I had this happen to me the other day and ended up reading the relevant
parsing code, I think if it were a bit smarter we could handle the
common case, i.e. when we find "diff --git" or whatever it is keep
looking and see if we find another one, or perhaps have a "looks like
I'm at the diffstat" heuristic where we'll prefer the "diff --git" that
follows a "---" line, if there' two of them (that's also going to be
ambiguous, but both of them are less likely to happen to the same
commit).

```

## Felipe Contreras, 2021-07-06 22:17

Subject: Re: Applying a patch with a diff header in its commit message
Message-ID: <60e4d686cb59d_1c428120810@natae.notmuch>
URL: https://gitlist.dev/e/60e4d686cb59d_1c428120810%40natae.notmuch
In-Reply-To: <20210706081738.5th24lypiicnbckv@yadavpratyush.com>

```
Pratyush Yadav wrote:
> On 28/06/21 06:44PM, Felipe Contreras wrote:
> > Pratyush Yadav wrote:
> > > I have a patch at $DAYJOB that contains a diff header ("diff --git 
> > > a/...") in its commit message, and unfortunately it is not indented. So 
> > > naturally, git-am trips up and thinks it is the start of the main diff 
> > > and tries to apply the diff starting there. It does not apply and the 
> > > patch is rejected as being corrupt.
> > > 
> > > I know one option for me is to manually edit the patch and indent the 
> > > diff header. But I would like to avoid that if possible. Is there any 
> > > way to apply that patch as-is? Is it possible to tell git-am where to 
> > > start looking for the diff?
> > 
> > git apply?
> 
> Sure, that is an option. But then I would have to copy/paste the commit 
> message and add the author information manually. Is there any way to do 
> this automatically? What if I have 100 commits like this?

Ahh, I misread your full question.

> This is a valid Git commit. It would be nice if the Git email tooling 
> could handle it cleanly.

Yes it would, that's definitely a bug.

-- 
Felipe Contreras

```
