]> git.ipfire.org Git - thirdparty/git.git/blob - t/t3437-rebase-fixup-options.sh
test-lib: ignore uninteresting LSan output
[thirdparty/git.git] / t / t3437-rebase-fixup-options.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2018 Phillip Wood
4 #
5
6 test_description='git rebase interactive fixup options
7
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.
15 '
16
17 TEST_PASSES_SANITIZE_LEAK=true
18 . ./test-lib.sh
19
20 . "$TEST_DIRECTORY"/lib-rebase.sh
21
22 EMPTY=""
23
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 &&
30 case "$2" in
31 -m)
32 echo "$3" >expect &&
33 test_cmp expect actual ;;
34 *)
35 test_cmp "$2" actual ;;
36 esac
37 }
38
39 get_author () {
40 rev="$1" &&
41 git log -1 --pretty=format:"%an %ae %at" "$rev"
42 }
43
44 test_expect_success 'setup' '
45 cat >message <<-EOF &&
46 amend! B
47 $EMPTY
48 new subject
49 $EMPTY
50 new
51 body
52 EOF
53
54 test_commit initial &&
55 test_commit A A &&
56 test_commit B B &&
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 &&
63 test_commit A2 A &&
64 test_commit A3 A &&
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 &&
69
70 set_fake_editor &&
71 git checkout -b branch B &&
72 echo B1 >B &&
73 test_tick &&
74 git commit --fixup=HEAD -a &&
75 git tag B1 &&
76 test_tick &&
77 FAKE_COMMIT_AMEND="edited 1" git commit --fixup=reword:B &&
78 test_tick &&
79 FAKE_COMMIT_AMEND="edited 2" git commit --fixup=reword:HEAD &&
80 echo B2 >B &&
81 test_tick &&
82 FAKE_COMMIT_AMEND="edited squash" git commit --squash=HEAD -a &&
83 git tag B2 &&
84 echo B3 >B &&
85 test_tick &&
86 FAKE_COMMIT_AMEND="edited 3" git commit -a --fixup=amend:HEAD^ &&
87 git tag B3 &&
88
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"
93 '
94
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"
102 '
103
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" \
111 git rebase -i B &&
112 test_cmp_rev HEAD^ B &&
113 test_cmp_rev HEAD^{tree} A2^{tree} &&
114 test_commit_message HEAD expected-fixup-message
115 '
116
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
127 '
128
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 &&
136 git add 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
143 '
144
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 &&
149 git reset --hard &&
150 FAKE_COMMIT_AMEND=edited git rebase --continue &&
151 test_commit_message HEAD -m "B"
152 '
153
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
164 '
165
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
173 '
174
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 \
183 git rebase -i A &&
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
188 '
189
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 &&
198 test_cmp_rev HEAD^ A
199 '
200
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 \
206 --signoff A &&
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
211 '
212
213 test_expect_success 'fixup -[Cc]<commit> works' '
214 test_when_finished "test_might_fail git rebase --abort" &&
215 cat >todo <<-\EOF &&
216 pick A
217 fixup -CA1
218 pick B
219 fixup -cA2
220 EOF
221 (
222 set_replace_editor todo &&
223 FAKE_COMMIT_MESSAGE="edited and fixed up" \
224 git rebase -i initial initial
225 ) &&
226 git log --pretty=format:%B initial.. >actual &&
227 cat >expect <<-EOF &&
228 edited and fixed up
229 $EMPTY
230 new subject
231 $EMPTY
232 new
233 body
234 EOF
235 test_cmp expect actual
236 '
237
238 test_done