3 # Copyright (c) 2018 Phillip Wood
6 test_description='git rebase interactive fixup options
8 This test checks the "fixup [-C|-c]" command of rebase interactive.
9 In addition to amending the contents of the commit, "fixup -C"
10 replaces the original commit message with the message of the fixup
11 commit. "fixup -c" also replaces the original message, but opens the
12 editor to allow the user to edit the message before committing.
17 . "$TEST_DIRECTORY"/lib-rebase.sh
21 test_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 &&
27 str="$3" && # test against a string
28 printf "%s\n" "$str" >tmp-expected-message &&
29 file="tmp-expected-message"
31 test_cmp "$file" actual-message
36 git log -1 --pretty=format:"%an %ae" "$rev"
39 test_expect_success 'setup' '
40 cat >message <<-EOF &&
49 sed "1,2d" message >expected-message &&
53 get_author HEAD >expected-author &&
54 ORIG_AUTHOR_NAME="$GIT_AUTHOR_NAME" &&
55 ORIG_AUTHOR_EMAIL="$GIT_AUTHOR_EMAIL" &&
56 GIT_AUTHOR_NAME="Amend Author" &&
57 GIT_AUTHOR_EMAIL="amend@example.com" &&
58 test_commit "$(cat message)" A A1 A1 &&
61 GIT_AUTHOR_NAME="$ORIG_AUTHOR_NAME" &&
62 GIT_AUTHOR_EMAIL="$ORIG_AUTHOR_EMAIL" &&
63 git checkout -b conflicts-branch A &&
64 test_commit conflicts A &&
67 git checkout -b branch B &&
70 git commit --fixup=HEAD -a &&
72 git commit --allow-empty -F - <<-EOF &&
80 git commit --allow-empty -F - <<-EOF &&
91 FAKE_COMMIT_AMEND="edited squash" git commit --squash=HEAD -a &&
94 git commit -a -F - <<-EOF &&
95 amend! amend! amend! B
106 GIT_AUTHOR_NAME="Rebase Author" &&
107 GIT_AUTHOR_EMAIL="rebase.author@example.com" &&
108 GIT_COMMITTER_NAME="Rebase Committer" &&
109 GIT_COMMITTER_EMAIL="rebase.committer@example.com"
112 test_expect_success 'simple fixup -C works' '
113 test_when_finished "test_might_fail git rebase --abort" &&
114 git checkout --detach A2 &&
115 FAKE_LINES="1 fixup_-C 2" git rebase -i B &&
116 test_cmp_rev HEAD^ B &&
117 test_cmp_rev HEAD^{tree} A2^{tree} &&
118 test_commit_message HEAD -m "A2"
121 test_expect_success 'simple fixup -c works' '
122 test_when_finished "test_might_fail git rebase --abort" &&
123 git checkout --detach A2 &&
124 git log -1 --pretty=format:%B >expected-fixup-message &&
125 test_write_lines "" "Modified A2" >>expected-fixup-message &&
126 FAKE_LINES="1 fixup_-c 2" \
127 FAKE_COMMIT_AMEND="Modified A2" \
129 test_cmp_rev HEAD^ B &&
130 test_cmp_rev HEAD^{tree} A2^{tree} &&
131 test_commit_message HEAD expected-fixup-message
134 test_expect_success 'fixup -C removes amend! from message' '
135 test_when_finished "test_might_fail git rebase --abort" &&
136 git checkout --detach A1 &&
137 FAKE_LINES="1 fixup_-C 2" git rebase -i A &&
138 test_cmp_rev HEAD^ A &&
139 test_cmp_rev HEAD^{tree} A1^{tree} &&
140 test_commit_message HEAD expected-message &&
141 get_author HEAD >actual-author &&
142 test_cmp expected-author actual-author
145 test_expect_success 'fixup -C with conflicts gives correct message' '
146 test_when_finished "test_might_fail git rebase --abort" &&
147 git checkout --detach A1 &&
148 test_must_fail env FAKE_LINES="1 fixup_-C 2" git rebase -i conflicts &&
149 git checkout --theirs -- A &&
151 FAKE_COMMIT_AMEND=edited git rebase --continue &&
152 test_cmp_rev HEAD^ conflicts &&
153 test_cmp_rev HEAD^{tree} A1^{tree} &&
154 test_write_lines "" edited >>expected-message &&
155 test_commit_message HEAD expected-message &&
156 get_author HEAD >actual-author &&
157 test_cmp expected-author actual-author
160 test_expect_success 'skipping fixup -C after fixup gives correct message' '
161 test_when_finished "test_might_fail git rebase --abort" &&
162 git checkout --detach A3 &&
163 test_must_fail env FAKE_LINES="1 fixup 2 fixup_-C 4" git rebase -i A &&
165 FAKE_COMMIT_AMEND=edited git rebase --continue &&
166 test_commit_message HEAD -m "B"
169 test_expect_success 'sequence of fixup, fixup -C & squash --signoff works' '
170 git checkout --detach branch &&
171 FAKE_LINES="1 fixup 2 fixup_-C 3 fixup_-C 4 squash 5 fixup_-C 6" \
172 FAKE_COMMIT_AMEND=squashed \
173 FAKE_MESSAGE_COPY=actual-squash-message \
174 git -c commit.status=false rebase -ik --signoff A &&
175 git diff-tree --exit-code --patch HEAD branch -- &&
176 test_cmp_rev HEAD^ A &&
177 test_i18ncmp "$TEST_DIRECTORY/t3437/expected-squash-message" \
178 actual-squash-message
181 test_expect_success 'first fixup -C commented out in sequence fixup fixup -C fixup -C' '
182 test_when_finished "test_might_fail git rebase --abort" &&
183 git checkout branch && git checkout --detach branch~2 &&
184 git log -1 --pretty=format:%b >expected-message &&
185 FAKE_LINES="1 fixup 2 fixup_-C 3 fixup_-C 4" git rebase -i A &&
186 test_cmp_rev HEAD^ A &&
187 test_commit_message HEAD expected-message
190 test_expect_success 'multiple fixup -c opens editor once' '
191 test_when_finished "test_might_fail git rebase --abort" &&
192 git checkout --detach A3 &&
193 base=$(git rev-parse HEAD~4) &&
194 FAKE_COMMIT_MESSAGE="Modified-A3" \
195 FAKE_LINES="1 fixup_-C 2 fixup_-c 3 fixup_-c 4" \
196 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)
202 test_expect_success 'sequence squash, fixup & fixup -c gives combined message' '
203 test_when_finished "test_might_fail git rebase --abort" &&
204 git checkout --detach A3 &&
205 FAKE_LINES="1 squash 2 fixup 3 fixup_-c 4" \
206 FAKE_MESSAGE_COPY=actual-combined-message \
207 git -c commit.status=false rebase -i A &&
208 test_i18ncmp "$TEST_DIRECTORY/t3437/expected-combined-message" \
209 actual-combined-message &&
213 test_expect_success 'fixup -C works upon --autosquash with amend!' '
214 git checkout --detach branch &&
215 FAKE_COMMIT_AMEND=squashed \
216 FAKE_MESSAGE_COPY=actual-squash-message \
217 git -c commit.status=false rebase -ik --autosquash \
219 git diff-tree --exit-code --patch HEAD branch -- &&
220 test_cmp_rev HEAD^ A &&
221 test_i18ncmp "$TEST_DIRECTORY/t3437/expected-squash-message" \
222 actual-squash-message