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 &&
56 get_author HEAD >expected-author &&
57 ORIG_AUTHOR_NAME="$GIT_AUTHOR_NAME" &&
58 ORIG_AUTHOR_EMAIL="$GIT_AUTHOR_EMAIL" &&
59 GIT_AUTHOR_NAME="Amend Author" &&
60 GIT_AUTHOR_EMAIL="amend@example.com" &&
61 test_commit "$(cat message)" A A1 A1 &&
64 GIT_AUTHOR_NAME="$ORIG_AUTHOR_NAME" &&
65 GIT_AUTHOR_EMAIL="$ORIG_AUTHOR_EMAIL" &&
66 git checkout -b conflicts-branch A &&
67 test_commit conflicts A &&
70 git checkout -b branch B &&
73 git commit --fixup=HEAD -a &&
76 FAKE_COMMIT_AMEND="edited 1" git commit --fixup=reword:B &&
78 FAKE_COMMIT_AMEND="edited 2" git commit --fixup=reword:HEAD &&
81 FAKE_COMMIT_AMEND="edited squash" git commit --squash=HEAD -a &&
85 FAKE_COMMIT_AMEND="edited 3" git commit -a --fixup=amend:HEAD^ &&
88 GIT_AUTHOR_NAME="Rebase Author" &&
89 GIT_AUTHOR_EMAIL="rebase.author@example.com" &&
90 GIT_COMMITTER_NAME="Rebase Committer" &&
91 GIT_COMMITTER_EMAIL="rebase.committer@example.com"
94 test_expect_success
'simple fixup -C works' '
95 test_when_finished "test_might_fail git rebase --abort" &&
96 git checkout --detach A2 &&
97 FAKE_LINES="1 fixup_-C 2" git rebase -i B &&
98 test_cmp_rev HEAD^ B &&
99 test_cmp_rev HEAD^{tree} A2^{tree} &&
100 test_commit_message HEAD -m "A2"
103 test_expect_success
'simple fixup -c works' '
104 test_when_finished "test_might_fail git rebase --abort" &&
105 git checkout --detach A2 &&
106 git log -1 --pretty=format:%B >expected-fixup-message &&
107 test_write_lines "" "Modified A2" >>expected-fixup-message &&
108 FAKE_LINES="1 fixup_-c 2" \
109 FAKE_COMMIT_AMEND="Modified A2" \
111 test_cmp_rev HEAD^ B &&
112 test_cmp_rev HEAD^{tree} A2^{tree} &&
113 test_commit_message HEAD expected-fixup-message
116 test_expect_success
'fixup -C removes amend! from message' '
117 test_when_finished "test_might_fail git rebase --abort" &&
118 git checkout --detach A1 &&
119 git log -1 --pretty=format:%b >expected-message &&
120 FAKE_LINES="1 fixup_-C 2" git rebase -i A &&
121 test_cmp_rev HEAD^ A &&
122 test_cmp_rev HEAD^{tree} A1^{tree} &&
123 test_commit_message HEAD expected-message &&
124 get_author HEAD >actual-author &&
125 test_cmp expected-author actual-author
128 test_expect_success
'fixup -C with conflicts gives correct message' '
129 test_when_finished "test_might_fail git rebase --abort" &&
130 git checkout --detach A1 &&
131 git log -1 --pretty=format:%b >expected-message &&
132 test_write_lines "" "edited" >>expected-message &&
133 test_must_fail env FAKE_LINES="1 fixup_-C 2" git rebase -i conflicts &&
134 git checkout --theirs -- A &&
136 FAKE_COMMIT_AMEND=edited git rebase --continue &&
137 test_cmp_rev HEAD^ conflicts &&
138 test_cmp_rev HEAD^{tree} A1^{tree} &&
139 test_commit_message HEAD expected-message &&
140 get_author HEAD >actual-author &&
141 test_cmp expected-author actual-author
144 test_expect_success
'skipping fixup -C after fixup gives correct message' '
145 test_when_finished "test_might_fail git rebase --abort" &&
146 git checkout --detach A3 &&
147 test_must_fail env FAKE_LINES="1 fixup 2 fixup_-C 4" git rebase -i A &&
149 FAKE_COMMIT_AMEND=edited git rebase --continue &&
150 test_commit_message HEAD -m "B"
153 test_expect_success
'sequence of fixup, fixup -C & squash --signoff works' '
154 git checkout --detach B3 &&
155 FAKE_LINES="1 fixup 2 fixup_-C 3 fixup_-C 4 squash 5 fixup_-C 6" \
156 FAKE_COMMIT_AMEND=squashed \
157 FAKE_MESSAGE_COPY=actual-squash-message \
158 git -c commit.status=false rebase -ik --signoff A &&
159 git diff-tree --exit-code --patch HEAD B3 -- &&
160 test_cmp_rev HEAD^ A &&
161 test_cmp "$TEST_DIRECTORY/t3437/expected-squash-message" \
162 actual-squash-message
165 test_expect_success
'first fixup -C commented out in sequence fixup fixup -C fixup -C' '
166 test_when_finished "test_might_fail git rebase --abort" &&
167 git checkout --detach B2~ &&
168 git log -1 --pretty=format:%b >expected-message &&
169 FAKE_LINES="1 fixup 2 fixup_-C 3 fixup_-C 4" git rebase -i A &&
170 test_cmp_rev HEAD^ A &&
171 test_commit_message HEAD expected-message
174 test_expect_success
'multiple fixup -c opens editor once' '
175 test_when_finished "test_might_fail git rebase --abort" &&
176 git checkout --detach A3 &&
177 git log -1 --pretty=format:%B >expected-message &&
178 test_write_lines "" "Modified-A3" >>expected-message &&
179 FAKE_COMMIT_AMEND="Modified-A3" \
180 FAKE_LINES="1 fixup_-C 2 fixup_-c 3 fixup_-c 4" \
181 EXPECT_HEADER_COUNT=4 \
183 test_cmp_rev HEAD^ A &&
184 get_author HEAD >actual-author &&
185 test_cmp expected-author actual-author &&
186 test_commit_message HEAD expected-message
189 test_expect_success
'sequence squash, fixup & fixup -c gives combined message' '
190 test_when_finished "test_might_fail git rebase --abort" &&
191 git checkout --detach A3 &&
192 FAKE_LINES="1 squash 2 fixup 3 fixup_-c 4" \
193 FAKE_MESSAGE_COPY=actual-combined-message \
194 git -c commit.status=false rebase -i A &&
195 test_cmp "$TEST_DIRECTORY/t3437/expected-combined-message" \
196 actual-combined-message &&
200 test_expect_success
'fixup -C works upon --autosquash with amend!' '
201 git checkout --detach B3 &&
202 FAKE_COMMIT_AMEND=squashed \
203 FAKE_MESSAGE_COPY=actual-squash-message \
204 git -c commit.status=false rebase -ik --autosquash \
206 git diff-tree --exit-code --patch HEAD B3 -- &&
207 test_cmp_rev HEAD^ A &&
208 test_cmp "$TEST_DIRECTORY/t3437/expected-squash-message" \
209 actual-squash-message