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. Similar
13 to the "fixup" command that works with "fixup!", "fixup -C" works with
14 "amend!" upon --autosquash.
17 TEST_PASSES_SANITIZE_LEAK
=true
20 .
"$TEST_DIRECTORY"/lib-rebase.sh
24 # test_commit_message <rev> -m <msg>
25 # test_commit_message <rev> <path>
26 # Verify that the commit message of <rev> matches
27 # <msg> or the content of <path>.
28 test_commit_message
() {
29 git show
--no-patch --pretty=format
:%B
"$1" >actual
&&
33 test_cmp expect actual
;;
35 test_cmp
"$2" actual
;;
41 git log
-1 --pretty=format
:"%an %ae %at" "$rev"
44 test_expect_success
'setup' '
45 cat >message <<-EOF &&
54 test_commit initial &&
57 get_author HEAD >expected-author &&
58 ORIG_AUTHOR_NAME="$GIT_AUTHOR_NAME" &&
59 ORIG_AUTHOR_EMAIL="$GIT_AUTHOR_EMAIL" &&
60 GIT_AUTHOR_NAME="Amend Author" &&
61 GIT_AUTHOR_EMAIL="amend@example.com" &&
62 test_commit "$(cat message)" A A1 A1 &&
65 GIT_AUTHOR_NAME="$ORIG_AUTHOR_NAME" &&
66 GIT_AUTHOR_EMAIL="$ORIG_AUTHOR_EMAIL" &&
67 git checkout -b conflicts-branch A &&
68 test_commit conflicts A &&
71 git checkout -b branch B &&
74 git commit --fixup=HEAD -a &&
77 FAKE_COMMIT_AMEND="edited 1" git commit --fixup=reword:B &&
79 FAKE_COMMIT_AMEND="edited 2" git commit --fixup=reword:HEAD &&
82 FAKE_COMMIT_AMEND="edited squash" git commit --squash=HEAD -a &&
86 FAKE_COMMIT_AMEND="edited 3" git commit -a --fixup=amend:HEAD^ &&
89 GIT_AUTHOR_NAME="Rebase Author" &&
90 GIT_AUTHOR_EMAIL="rebase.author@example.com" &&
91 GIT_COMMITTER_NAME="Rebase Committer" &&
92 GIT_COMMITTER_EMAIL="rebase.committer@example.com"
95 test_expect_success
'simple fixup -C works' '
96 test_when_finished "test_might_fail git rebase --abort" &&
97 git checkout --detach A2 &&
98 FAKE_LINES="1 fixup_-C 2" git rebase -i B &&
99 test_cmp_rev HEAD^ B &&
100 test_cmp_rev HEAD^{tree} A2^{tree} &&
101 test_commit_message HEAD -m "A2"
104 test_expect_success
'simple fixup -c works' '
105 test_when_finished "test_might_fail git rebase --abort" &&
106 git checkout --detach A2 &&
107 git log -1 --pretty=format:%B >expected-fixup-message &&
108 test_write_lines "" "Modified A2" >>expected-fixup-message &&
109 FAKE_LINES="1 fixup_-c 2" \
110 FAKE_COMMIT_AMEND="Modified A2" \
112 test_cmp_rev HEAD^ B &&
113 test_cmp_rev HEAD^{tree} A2^{tree} &&
114 test_commit_message HEAD expected-fixup-message
117 test_expect_success
'fixup -C removes amend! from message' '
118 test_when_finished "test_might_fail git rebase --abort" &&
119 git checkout --detach A1 &&
120 git log -1 --pretty=format:%b >expected-message &&
121 FAKE_LINES="1 fixup_-C 2" git rebase -i A &&
122 test_cmp_rev HEAD^ A &&
123 test_cmp_rev HEAD^{tree} A1^{tree} &&
124 test_commit_message HEAD expected-message &&
125 get_author HEAD >actual-author &&
126 test_cmp expected-author actual-author
129 test_expect_success
'fixup -C with conflicts gives correct message' '
130 test_when_finished "test_might_fail git rebase --abort" &&
131 git checkout --detach A1 &&
132 git log -1 --pretty=format:%b >expected-message &&
133 test_write_lines "" "edited" >>expected-message &&
134 test_must_fail env FAKE_LINES="1 fixup_-C 2" git rebase -i conflicts &&
135 git checkout --theirs -- A &&
137 FAKE_COMMIT_AMEND=edited git rebase --continue &&
138 test_cmp_rev HEAD^ conflicts &&
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
'skipping fixup -C after fixup gives correct message' '
146 test_when_finished "test_might_fail git rebase --abort" &&
147 git checkout --detach A3 &&
148 test_must_fail env FAKE_LINES="1 fixup 2 fixup_-C 4" git rebase -i A &&
150 FAKE_COMMIT_AMEND=edited git rebase --continue &&
151 test_commit_message HEAD -m "B"
154 test_expect_success
'sequence of fixup, fixup -C & squash --signoff works' '
155 git checkout --detach B3 &&
156 FAKE_LINES="1 fixup 2 fixup_-C 3 fixup_-C 4 squash 5 fixup_-C 6" \
157 FAKE_COMMIT_AMEND=squashed \
158 FAKE_MESSAGE_COPY=actual-squash-message \
159 git -c commit.status=false rebase -ik --signoff A &&
160 git diff-tree --exit-code --patch HEAD B3 -- &&
161 test_cmp_rev HEAD^ A &&
162 test_cmp "$TEST_DIRECTORY/t3437/expected-squash-message" \
163 actual-squash-message
166 test_expect_success
'first fixup -C commented out in sequence fixup fixup -C fixup -C' '
167 test_when_finished "test_might_fail git rebase --abort" &&
168 git checkout --detach B2~ &&
169 git log -1 --pretty=format:%b >expected-message &&
170 FAKE_LINES="1 fixup 2 fixup_-C 3 fixup_-C 4" git rebase -i A &&
171 test_cmp_rev HEAD^ A &&
172 test_commit_message HEAD expected-message
175 test_expect_success
'multiple fixup -c opens editor once' '
176 test_when_finished "test_might_fail git rebase --abort" &&
177 git checkout --detach A3 &&
178 git log -1 --pretty=format:%B >expected-message &&
179 test_write_lines "" "Modified-A3" >>expected-message &&
180 FAKE_COMMIT_AMEND="Modified-A3" \
181 FAKE_LINES="1 fixup_-C 2 fixup_-c 3 fixup_-c 4" \
182 EXPECT_HEADER_COUNT=4 \
184 test_cmp_rev HEAD^ A &&
185 get_author HEAD >actual-author &&
186 test_cmp expected-author actual-author &&
187 test_commit_message HEAD expected-message
190 test_expect_success
'sequence squash, fixup & fixup -c gives combined message' '
191 test_when_finished "test_might_fail git rebase --abort" &&
192 git checkout --detach A3 &&
193 FAKE_LINES="1 squash 2 fixup 3 fixup_-c 4" \
194 FAKE_MESSAGE_COPY=actual-combined-message \
195 git -c commit.status=false rebase -i A &&
196 test_cmp "$TEST_DIRECTORY/t3437/expected-combined-message" \
197 actual-combined-message &&
201 test_expect_success
'fixup -C works upon --autosquash with amend!' '
202 git checkout --detach B3 &&
203 FAKE_COMMIT_AMEND=squashed \
204 FAKE_MESSAGE_COPY=actual-squash-message \
205 git -c commit.status=false rebase -ik --autosquash \
207 git diff-tree --exit-code --patch HEAD B3 -- &&
208 test_cmp_rev HEAD^ A &&
209 test_cmp "$TEST_DIRECTORY/t3437/expected-squash-message" \
210 actual-squash-message
213 test_expect_success
'fixup -[Cc]<commit> works' '
214 test_when_finished "test_might_fail git rebase --abort" &&
222 set_replace_editor todo &&
223 FAKE_COMMIT_MESSAGE="edited and fixed up" \
224 git rebase -i initial initial
226 git log --pretty=format:%B initial.. >actual &&
227 cat >expect <<-EOF &&
235 test_cmp expect actual