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
26 git log
-1 --pretty=format
:"%an %ae %at" "$rev"
29 test_expect_success
'setup' '
30 cat >message <<-EOF &&
39 test_commit initial &&
42 get_author HEAD >expected-author &&
43 ORIG_AUTHOR_NAME="$GIT_AUTHOR_NAME" &&
44 ORIG_AUTHOR_EMAIL="$GIT_AUTHOR_EMAIL" &&
45 GIT_AUTHOR_NAME="Amend Author" &&
46 GIT_AUTHOR_EMAIL="amend@example.com" &&
47 test_commit "$(cat message)" A A1 A1 &&
50 GIT_AUTHOR_NAME="$ORIG_AUTHOR_NAME" &&
51 GIT_AUTHOR_EMAIL="$ORIG_AUTHOR_EMAIL" &&
52 git checkout -b conflicts-branch A &&
53 test_commit conflicts A &&
56 git checkout -b branch B &&
59 git commit --fixup=HEAD -a &&
62 FAKE_COMMIT_AMEND="edited 1" git commit --fixup=reword:B &&
64 FAKE_COMMIT_AMEND="edited 2" git commit --fixup=reword:HEAD &&
67 FAKE_COMMIT_AMEND="edited squash" git commit --squash=HEAD -a &&
71 FAKE_COMMIT_AMEND="edited 3" git commit -a --fixup=amend:HEAD^ &&
74 GIT_AUTHOR_NAME="Rebase Author" &&
75 GIT_AUTHOR_EMAIL="rebase.author@example.com" &&
76 GIT_COMMITTER_NAME="Rebase Committer" &&
77 GIT_COMMITTER_EMAIL="rebase.committer@example.com"
80 test_expect_success
'simple fixup -C works' '
81 test_when_finished "test_might_fail git rebase --abort" &&
82 git checkout --detach A2 &&
83 FAKE_LINES="1 fixup_-C 2" git rebase -i B &&
84 test_cmp_rev HEAD^ B &&
85 test_cmp_rev HEAD^{tree} A2^{tree} &&
86 test_commit_message HEAD -m "A2"
89 test_expect_success
'simple fixup -c works' '
90 test_when_finished "test_might_fail git rebase --abort" &&
91 git checkout --detach A2 &&
92 git log -1 --pretty=format:%B >expected-fixup-message &&
93 test_write_lines "" "Modified A2" >>expected-fixup-message &&
94 FAKE_LINES="1 fixup_-c 2" \
95 FAKE_COMMIT_AMEND="Modified A2" \
97 test_cmp_rev HEAD^ B &&
98 test_cmp_rev HEAD^{tree} A2^{tree} &&
99 test_commit_message HEAD expected-fixup-message
102 test_expect_success
'fixup -C removes amend! from message' '
103 test_when_finished "test_might_fail git rebase --abort" &&
104 git checkout --detach A1 &&
105 git log -1 --pretty=format:%b >expected-message &&
106 FAKE_LINES="1 fixup_-C 2" git rebase -i A &&
107 test_cmp_rev HEAD^ A &&
108 test_cmp_rev HEAD^{tree} A1^{tree} &&
109 test_commit_message HEAD expected-message &&
110 get_author HEAD >actual-author &&
111 test_cmp expected-author actual-author
114 test_expect_success
'fixup -C with conflicts gives correct message' '
115 test_when_finished "test_might_fail git rebase --abort" &&
116 git checkout --detach A1 &&
117 git log -1 --pretty=format:%b >expected-message &&
118 test_write_lines "" "edited" >>expected-message &&
119 test_must_fail env FAKE_LINES="1 fixup_-C 2" git rebase -i conflicts &&
120 git checkout --theirs -- A &&
122 FAKE_COMMIT_AMEND=edited git rebase --continue &&
123 test_cmp_rev HEAD^ conflicts &&
124 test_cmp_rev HEAD^{tree} A1^{tree} &&
125 test_commit_message HEAD expected-message &&
126 get_author HEAD >actual-author &&
127 test_cmp expected-author actual-author
130 test_expect_success
'skipping fixup -C after fixup gives correct message' '
131 test_when_finished "test_might_fail git rebase --abort" &&
132 git checkout --detach A3 &&
133 test_must_fail env FAKE_LINES="1 fixup 2 fixup_-C 4" git rebase -i A &&
135 FAKE_COMMIT_AMEND=edited git rebase --continue &&
136 test_commit_message HEAD -m "B"
139 test_expect_success
'sequence of fixup, fixup -C & squash --signoff works' '
140 git checkout --detach B3 &&
141 FAKE_LINES="1 fixup 2 fixup_-C 3 fixup_-C 4 squash 5 fixup_-C 6" \
142 FAKE_COMMIT_AMEND=squashed \
143 FAKE_MESSAGE_COPY=actual-squash-message \
144 git -c commit.status=false rebase -ik --signoff A &&
145 git diff-tree --exit-code --patch HEAD B3 -- &&
146 test_cmp_rev HEAD^ A &&
147 test_cmp "$TEST_DIRECTORY/t3437/expected-squash-message" \
148 actual-squash-message
151 test_expect_success
'first fixup -C commented out in sequence fixup fixup -C fixup -C' '
152 test_when_finished "test_might_fail git rebase --abort" &&
153 git checkout --detach B2~ &&
154 git log -1 --pretty=format:%b >expected-message &&
155 FAKE_LINES="1 fixup 2 fixup_-C 3 fixup_-C 4" git rebase -i A &&
156 test_cmp_rev HEAD^ A &&
157 test_commit_message HEAD expected-message
160 test_expect_success
'multiple fixup -c opens editor once' '
161 test_when_finished "test_might_fail git rebase --abort" &&
162 git checkout --detach A3 &&
163 git log -1 --pretty=format:%B >expected-message &&
164 test_write_lines "" "Modified-A3" >>expected-message &&
165 FAKE_COMMIT_AMEND="Modified-A3" \
166 FAKE_LINES="1 fixup_-C 2 fixup_-c 3 fixup_-c 4" \
167 EXPECT_HEADER_COUNT=4 \
169 test_cmp_rev HEAD^ A &&
170 get_author HEAD >actual-author &&
171 test_cmp expected-author actual-author &&
172 test_commit_message HEAD expected-message
175 test_expect_success
'sequence squash, fixup & fixup -c gives combined message' '
176 test_when_finished "test_might_fail git rebase --abort" &&
177 git checkout --detach A3 &&
178 FAKE_LINES="1 squash 2 fixup 3 fixup_-c 4" \
179 FAKE_MESSAGE_COPY=actual-combined-message \
180 git -c commit.status=false rebase -i A &&
181 test_cmp "$TEST_DIRECTORY/t3437/expected-combined-message" \
182 actual-combined-message &&
186 test_expect_success
'fixup -C works upon --autosquash with amend!' '
187 git checkout --detach B3 &&
188 FAKE_COMMIT_AMEND=squashed \
189 FAKE_MESSAGE_COPY=actual-squash-message \
190 git -c commit.status=false rebase -ik --autosquash \
192 git diff-tree --exit-code --patch HEAD B3 -- &&
193 test_cmp_rev HEAD^ A &&
194 test_cmp "$TEST_DIRECTORY/t3437/expected-squash-message" \
195 actual-squash-message
198 test_expect_success
'fixup -[Cc]<commit> works' '
199 test_when_finished "test_might_fail git rebase --abort" &&
207 set_replace_editor todo &&
208 FAKE_COMMIT_MESSAGE="edited and fixed up" \
209 git rebase -i initial initial
211 git log --pretty=format:%B initial.. >actual &&
212 cat >expect <<-EOF &&
220 test_cmp expect actual