am --rebasing: get patch body from commit, not from mailbox

Rebasing a commit that contains a diff in the commit message results in a failure with output such as First, rewinding head to replay your work on top of it... Applying: My cool patch. fatal: sha1 information is lacking or useless (app/controllers/settings_controller.rb). Repository lacks necessary blobs to fall back on 3-way merge. Cannot fall back to three-way merge. Patch failed at 0001 My cool patch. The reason is that 'git rebase' without -p/-i/-m internally calls 'git format-patch' and pipes the output to 'git am --rebasing', which has no way of knowing what is a real patch and what is a commit message that contains a patch. Make 'git am' while in --rebasing mode get the patch body from the commit object instead of extracting it from the mailbox. Patch by Junio, test case and commit log message by Martin. Reported-by: anikey <arty.anikey@gmail.com> Helped-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Martin von Zweigbergk committed Jun 26, 2012 at 07:51 UTC a230949409f4a650c6a1a9a5879e2a8b993ba695
2 files changed +29 -4
git-am.sh
+1
@@ -683,6 +683,7 @@ To restore the original branch and stop patching run \"\$cmdline --abort\"."
683 sed -e '1,/^$/d' >"$dotest/msg-clean"
684 echo "$commit" > "$dotest/original-commit"
685 get_author_ident_from_commit "$commit" > "$dotest/author-script"
686 + git diff-tree --root --binary "$commit" >"$dotest/patch"
687 else
688 {
689 sed -n '/^Subject/ s/Subject: //p' "$dotest/info"
t/t3405-rebase-malformed.sh
+28 -4
@@ -1,6 +1,6 @@
1 #!/bin/sh
2
3 -test_description='rebase should not insist on git message convention'
3 +test_description='rebase should handle arbitrary git message'
4
5 . ./test-lib.sh
6
@@ -12,6 +12,11 @@ It has two paragraphs, but its first paragraph is not friendly
12 to oneline summary format.
13 EOF
14
15 +cat >G <<\EOF
16 +commit log message containing a diff
17 +EOF
18 +
19 +
20 test_expect_success setup '
21
22 >file1 &&
@@ -19,8 +24,9 @@ test_expect_success setup '
24 git add file1 file2 &&
25 test_tick &&
26 git commit -m "Initial commit" &&
27 + git branch diff-in-message
28
23 - git checkout -b side &&
29 + git checkout -b multi-line-subject &&
30 cat F >file2 &&
31 git add file2 &&
32 test_tick &&
@@ -28,6 +34,17 @@ test_expect_success setup '
34
35 git cat-file commit HEAD | sed -e "1,/^\$/d" >F0 &&
36
37 + git checkout diff-in-message &&
38 + echo "commit log message containing a diff" >G &&
39 + echo "" >>G
40 + cat G >file2 &&
41 + git add file2 &&
42 + git diff --cached >>G &&
43 + test_tick &&
44 + git commit -F G &&
45 +
46 + git cat-file commit HEAD | sed -e "1,/^\$/d" >G0 &&
47 +
48 git checkout master &&
49
50 echo One >file1 &&
@@ -36,13 +53,20 @@ test_expect_success setup '
53 git commit -m "Second commit"
54 '
55
39 -test_expect_success rebase '
56 +test_expect_success 'rebase commit with multi-line subject' '
57
41 - git rebase master side &&
58 + git rebase master multi-line-subject &&
59 git cat-file commit HEAD | sed -e "1,/^\$/d" >F1 &&
60
61 test_cmp F0 F1 &&
62 test_cmp F F0
63 '
64
65 +test_expect_success 'rebase commit with diff in message' '
66 + git rebase master diff-in-message &&
67 + git cat-file commit HEAD | sed -e "1,/^$/d" >G1 &&
68 + test_cmp G0 G1 &&
69 + test_cmp G G0
70 +'
71 +
72 test_done