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

bug? illegal text in commit log

From
MTMichael S. Tsirkin <mst@redhat.com>
Date
Feb 4, 2020, 06:14 UTC
Message-ID
<20200204010524-mutt-send-email-mst@kernel.org>

It seems that it's not too hard to make commits such that the standard way of git format-patch -> email -> git am fails.

For example:
[mst@tuck ~]$ mkdir gittest
[mst@tuck ~]$ cd gittest/
[mst@tuck gittest]$ git init
Initialized empty Git repository in /home/mst/gittest/.git/
[mst@tuck gittest]$ echo AA > a.txt
[mst@tuck gittest]$ git add a.txt
[mst@tuck gittest]$ git commit
[master (root-commit) 46e2cd1] original
 1 file changed, 1 insertion(+)
 create mode 100644 a.txt
[mst@tuck gittest]$ echo AA > b.txt
[mst@tuck gittest]$ echo BB > c.txt
[mst@tuck gittest]$ diff -u b.txt c.txt > bc.diff
[mst@tuck gittest]$ echo "this change" > commitlog.txt
[mst@tuck gittest]$ echo >> commitlog.txt
[mst@tuck gittest]$ cat bc.diff >> commitlog.txt
[mst@tuck gittest]$ echo BB >> a.txt
[mst@tuck gittest]$ git commit -a -F commitlog.txt 
[master c5f40b2] this change
 1 file changed, 1 insertion(+)
[mst@tuck gittest]$ git format-patch HEAD~1..
0001-this-change.patch
[mst@tuck gittest]$ git reset --hard HEAD~1
HEAD is now at 46e2cd1 original
[mst@tuck gittest]$ git am 0001-this-change.patch
Applying: this change
error: sha1 information is lacking or useless (c.txt).
error: could not build fake ancestor
Patch failed at 0001 this change
hint: Use 'git am --show-current-patch' to see the failed patch
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".

A work around is "don't do it" - avoid putting anything that looks like a unified diff in the commit log.

However:
- Users don't know what other restrictions exist
- User sending the patch has no way to detect failure,
  it's only visible to user receiving the patch
Ideas:
- validate commit log and warn users?
- find a way to escape text in git format-patch, and unescape in git am?
Thanks,
-- 
MST
Next: René Scharfe
Message 1 of 14 in “bug? illegal text in commit log”
  1. Michael S. TsirkinFeb 4, 2020
  2. René ScharfeFeb 4, 2020
  3. Junio C HamanoFeb 4, 2020
  4. Michael S. TsirkinFeb 6, 2020
  5. Junio C HamanoFeb 6, 2020
  6. Junio C HamanoFeb 6, 2020
  7. René ScharfeFeb 6, 2020
  8. Junio C HamanoFeb 7, 2020
  9. René ScharfeFeb 7, 2020
  10. Jeff KingFeb 12, 2020
  11. Michael S. TsirkinFeb 6, 2020
  12. Pratyush YadavFeb 7, 2020
  13. René ScharfeFeb 7, 2020
  14. Junio C HamanoFeb 7, 2020

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.