@matheusbsbs / matheus-bagliano / commits / 5e835cac86
Fork 0

rebase: do not munge commit log message

Traditionally git-rebase was implemented in terms of "format-patch" piped to "am -3", to strike balance between speed (because it avoids a rather expensive read-tree/merge-recursive machinery most of the time) and flexibility (the magic "-3" allows it to fall back to 3-way merge as necessary). However, this combination has one flaw when dealing with a nonstandard commit log message format that has more than one lines in the first paragraph. This teaches "git am --rebasing" to take advantage of the fact that the mbox message "git rebase" prepares for it records the original commit object name, to get the log message from the original commit object instead. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Apr 16, 2008 at 12:50 UTC 5e835cac8622373724235d299f1331ac4cf81ccf
2 files changed +55 -5
git-am.sh
+14 -5
@@ -327,11 +327,20 @@ do
327 echo "Patch is empty. Was it split wrong?"
328 stop_here $this
329 }
330 - SUBJECT="$(sed -n '/^Subject/ s/Subject: //p' "$dotest/info")"
331 - case "$keep_subject" in -k) SUBJECT="[PATCH] $SUBJECT" ;; esac
332 -
333 - (echo "$SUBJECT" ; echo ; cat "$dotest/msg") |
334 - git stripspace > "$dotest/msg-clean"
330 + if test -f "$dotest/rebasing" &&
331 + commit=$(sed -e 's/^From \([0-9a-f]*\) .*/\1/' \
332 + -e q "$dotest/$msgnum") &&
333 + test "$(git cat-file -t "$commit")" = commit
334 + then
335 + git cat-file commit "$commit" |
336 + sed -e '1,/^$/d' >"$dotest/msg-clean"
337 + else
338 + SUBJECT="$(sed -n '/^Subject/ s/Subject: //p' "$dotest/info")"
339 + case "$keep_subject" in -k) SUBJECT="[PATCH] $SUBJECT" ;; esac
340 +
341 + (echo "$SUBJECT" ; echo ; cat "$dotest/msg") |
342 + git stripspace > "$dotest/msg-clean"
343 + fi
344 ;;
345 esac
346
t/t3408-rebase-multi-line.sh new
+41
@@ -0,0 +1,41 @@
1 +#!/bin/sh
2 +
3 +test_description='rebasing a commit with multi-line first paragraph.'
4 +
5 +. ./test-lib.sh
6 +
7 +test_expect_success setup '
8 +
9 + >file &&
10 + git add file &&
11 + test_tick &&
12 + git commit -m initial &&
13 +
14 + echo hello >file &&
15 + test_tick &&
16 + git commit -a -m "A sample commit log message that has a long
17 +summary that spills over multiple lines.
18 +
19 +But otherwise with a sane description."
20 +
21 + git branch side &&
22 +
23 + git reset --hard HEAD^ &&
24 + >elif &&
25 + git add elif &&
26 + test_tick &&
27 + git commit -m second
28 +
29 +'
30 +
31 +test_expect_success rebase '
32 +
33 + git checkout side &&
34 + git rebase master &&
35 + git cat-file commit HEAD | sed -e "1,/^$/d" >actual &&
36 + git cat-file commit side@{1} | sed -e "1,/^$/d" >expect &&
37 + test_cmp expect actual
38 +
39 +'
40 +
41 +test_done