git-am with mailbox patch fails when it contains a cover letter
Asked Answered
H

1

6

When running git-am to apply a patch series I had saved into an mbox file from a mailing list, if the mbox also contains the cover letter (otherwise known as PATCH [0/N]), it complains as follows:

128 git … am --3way ~/patches/sample.mbox
Patch is empty.
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

It is true the cover letter is an empty patch as there isn't a patch delimiter contained within, but I would've thought git am would be smart enough to notice it and skip it altogether. This is not a major nuisance as I can skip adding this patch into the mbox from mutt without trouble, but sometimes a patch series arrives to the mailing list somewhat scrambled, and I can't just copy the entire thread into the same mbox. Alternatively I can manually skip the patch and it will apply smoothly.

Is there any way I can instruct git am to skip patch number 0 when it is indeed a cover letter?

Haymaker answered 20/4, 2020 at 12:22 Comment(0)
B
1

With Git 2.35 (Q1 2022), "git am"(man) learns --empty=(stop|drop|keep)" and --allow-empty options to tweak what is done to a piece of e-mail without a patch in it.

So try again (Git 2.35+) with:

git … am --empty=keep --allow-empty --3way ~/patches/sample.mbox

See commit 9e7e41b, commit 7c096b8, commit 552038e (09 Dec 2021) by 徐沛文 (Aleen) (aleen42).
(Merged by Junio C Hamano -- gitster -- in commit ead6767, 05 Jan 2022)

am: support --empty=<option> to handle empty patches

Signed-off-by: 徐沛文 (Aleen)

Since that the command 'git-format-patch' can include patches of commits that emit no changes, the 'git-am' command should also support an option, named as '--empty', to specify how to handle those empty patches.

In this commit, we have implemented three valid options ('stop', 'drop' and 'keep').

git am now includes in its man page:

--empty=(stop|drop|keep)

By default, or when the option is set to 'stop', the command errors out on an input e-mail message lacking a patch and stops into the middle of the current am session.

When this option is set to 'drop', skip such an e-mail message instead.

When this option is set to 'keep', create an empty commit, recording the contents of the e-mail message as its log.

Bushel answered 6/1, 2022 at 22:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.