@@ -9,7 +9,9 @@ This test checks the "fixup [-C|-c]" command of rebase interactive.
99In addition to amending the contents of the commit, "fixup -C"
1010replaces the original commit message with the message of the fixup
1111commit. "fixup -c" also replaces the original message, but opens the
12- editor to allow the user to edit the message before committing.
12+ editor to allow the user to edit the message before committing. Similar
13+ to the "fixup" command that works with "fixup!", "fixup -C" works with
14+ "amend!" upon --autosquash.
1315'
1416
1517. ./test-lib.sh
@@ -18,35 +20,35 @@ editor to allow the user to edit the message before committing.
1820
1921EMPTY=" "
2022
23+ # test_commit_message <rev> -m <msg>
24+ # test_commit_message <rev> <path>
25+ # Verify that the commit message of <rev> matches
26+ # <msg> or the content of <path>.
2127test_commit_message () {
22- rev=" $1 " && # commit or tag we want to test
23- file=" $2 " && # test against the content of a file
24- git show --no-patch --pretty=format:%B " $rev " > actual-message &&
25- if test " $2 " = -m
26- then
27- str=" $3 " && # test against a string
28- printf " %s\n" " $str " > tmp-expected-message &&
29- file=" tmp-expected-message"
30- fi
31- test_cmp " $file " actual-message
28+ git show --no-patch --pretty=format:%B " $1 " > actual &&
29+ case " $2 " in
30+ -m)
31+ echo " $3 " > expect &&
32+ test_cmp expect actual ;;
33+ * )
34+ test_cmp " $2 " actual ;;
35+ esac
3236}
3337
3438get_author () {
3539 rev=" $1 " &&
36- git log -1 --pretty=format:" %an %ae" " $rev "
40+ git log -1 --pretty=format:" %an %ae %at " " $rev "
3741}
3842
3943test_expect_success ' setup' '
4044 cat >message <<-EOF &&
41- amend! B
42- ${EMPTY}
43- new subject
44- ${EMPTY}
45- new
46- body
47- EOF
48-
49- sed "1,2d" message >expected-message &&
45+ amend! B
46+ $EMPTY
47+ new subject
48+ $EMPTY
49+ new
50+ body
51+ EOF
5052
5153 test_commit A A &&
5254 test_commit B B &&
@@ -68,40 +70,43 @@ test_expect_success 'setup' '
6870 echo B1 >B &&
6971 test_tick &&
7072 git commit --fixup=HEAD -a &&
73+ git tag B1 &&
7174 test_tick &&
7275 git commit --allow-empty -F - <<-EOF &&
73- amend! B
74- ${ EMPTY}
75- B
76- ${ EMPTY}
77- edited 1
78- EOF
76+ amend! B
77+ $ EMPTY
78+ B
79+ $ EMPTY
80+ edited 1
81+ EOF
7982 test_tick &&
8083 git commit --allow-empty -F - <<-EOF &&
81- amend! amend! B
82- ${ EMPTY}
83- B
84- ${ EMPTY}
85- edited 1
86- ${ EMPTY}
87- edited 2
88- EOF
84+ amend! amend! B
85+ $ EMPTY
86+ B
87+ $ EMPTY
88+ edited 1
89+ $ EMPTY
90+ edited 2
91+ EOF
8992 echo B2 >B &&
9093 test_tick &&
9194 FAKE_COMMIT_AMEND="edited squash" git commit --squash=HEAD -a &&
95+ git tag B2 &&
9296 echo B3 >B &&
9397 test_tick &&
9498 git commit -a -F - <<-EOF &&
95- amend! amend! amend! B
96- ${EMPTY}
97- B
98- ${EMPTY}
99- edited 1
100- ${EMPTY}
101- edited 2
102- ${EMPTY}
103- edited 3
104- EOF
99+ amend! amend! amend! B
100+ $EMPTY
101+ B
102+ $EMPTY
103+ edited 1
104+ $EMPTY
105+ edited 2
106+ $EMPTY
107+ edited 3
108+ EOF
109+ git tag B3 &&
105110
106111 GIT_AUTHOR_NAME="Rebase Author" &&
107112 GIT_AUTHOR_EMAIL="rebase.author@example.com" &&
@@ -134,6 +139,7 @@ test_expect_success 'simple fixup -c works' '
134139test_expect_success ' fixup -C removes amend! from message' '
135140 test_when_finished "test_might_fail git rebase --abort" &&
136141 git checkout --detach A1 &&
142+ git log -1 --pretty=format:%b >expected-message &&
137143 FAKE_LINES="1 fixup_-C 2" git rebase -i A &&
138144 test_cmp_rev HEAD^ A &&
139145 test_cmp_rev HEAD^{tree} A1^{tree} &&
@@ -145,13 +151,14 @@ test_expect_success 'fixup -C removes amend! from message' '
145151test_expect_success ' fixup -C with conflicts gives correct message' '
146152 test_when_finished "test_might_fail git rebase --abort" &&
147153 git checkout --detach A1 &&
154+ git log -1 --pretty=format:%b >expected-message &&
155+ test_write_lines "" "edited" >>expected-message &&
148156 test_must_fail env FAKE_LINES="1 fixup_-C 2" git rebase -i conflicts &&
149157 git checkout --theirs -- A &&
150158 git add A &&
151159 FAKE_COMMIT_AMEND=edited git rebase --continue &&
152160 test_cmp_rev HEAD^ conflicts &&
153161 test_cmp_rev HEAD^{tree} A1^{tree} &&
154- test_write_lines "" edited >>expected-message &&
155162 test_commit_message HEAD expected-message &&
156163 get_author HEAD >actual-author &&
157164 test_cmp expected-author actual-author
@@ -167,20 +174,20 @@ test_expect_success 'skipping fixup -C after fixup gives correct message' '
167174'
168175
169176test_expect_success ' sequence of fixup, fixup -C & squash --signoff works' '
170- git checkout --detach branch &&
177+ git checkout --detach B3 &&
171178 FAKE_LINES="1 fixup 2 fixup_-C 3 fixup_-C 4 squash 5 fixup_-C 6" \
172179 FAKE_COMMIT_AMEND=squashed \
173180 FAKE_MESSAGE_COPY=actual-squash-message \
174181 git -c commit.status=false rebase -ik --signoff A &&
175- git diff-tree --exit-code --patch HEAD branch -- &&
182+ git diff-tree --exit-code --patch HEAD B3 -- &&
176183 test_cmp_rev HEAD^ A &&
177184 test_i18ncmp "$TEST_DIRECTORY/t3437/expected-squash-message" \
178185 actual-squash-message
179186'
180187
181188test_expect_success ' first fixup -C commented out in sequence fixup fixup -C fixup -C' '
182189 test_when_finished "test_might_fail git rebase --abort" &&
183- git checkout branch && git checkout --detach branch~2 &&
190+ git checkout --detach B2~ &&
184191 git log -1 --pretty=format:%b >expected-message &&
185192 FAKE_LINES="1 fixup 2 fixup_-C 3 fixup_-C 4" git rebase -i A &&
186193 test_cmp_rev HEAD^ A &&
@@ -190,13 +197,16 @@ test_expect_success 'first fixup -C commented out in sequence fixup fixup -C fix
190197test_expect_success ' multiple fixup -c opens editor once' '
191198 test_when_finished "test_might_fail git rebase --abort" &&
192199 git checkout --detach A3 &&
193- base=$(git rev-parse HEAD~4) &&
194- FAKE_COMMIT_MESSAGE="Modified-A3" \
200+ git log -1 --pretty=format:%B >expected-message &&
201+ test_write_lines "" "Modified-A3" >>expected-message &&
202+ FAKE_COMMIT_AMEND="Modified-A3" \
195203 FAKE_LINES="1 fixup_-C 2 fixup_-c 3 fixup_-c 4" \
196204 EXPECT_HEADER_COUNT=4 \
197- git rebase -i $base &&
198- test_cmp_rev $base HEAD^ &&
199- test 1 = $(git show | grep Modified-A3 | wc -l)
205+ git rebase -i A &&
206+ test_cmp_rev HEAD^ A &&
207+ get_author HEAD >actual-author &&
208+ test_cmp expected-author actual-author &&
209+ test_commit_message HEAD expected-message
200210'
201211
202212test_expect_success ' sequence squash, fixup & fixup -c gives combined message' '
@@ -211,12 +221,12 @@ test_expect_success 'sequence squash, fixup & fixup -c gives combined message' '
211221'
212222
213223test_expect_success ' fixup -C works upon --autosquash with amend!' '
214- git checkout --detach branch &&
224+ git checkout --detach B3 &&
215225 FAKE_COMMIT_AMEND=squashed \
216226 FAKE_MESSAGE_COPY=actual-squash-message \
217227 git -c commit.status=false rebase -ik --autosquash \
218228 --signoff A &&
219- git diff-tree --exit-code --patch HEAD branch -- &&
229+ git diff-tree --exit-code --patch HEAD B3 -- &&
220230 test_cmp_rev HEAD^ A &&
221231 test_i18ncmp "$TEST_DIRECTORY/t3437/expected-squash-message" \
222232 actual-squash-message
0 commit comments