]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3437-rebase-fixup-options.sh
The twentieth batch
[thirdparty/git.git] / t / t3437-rebase-fixup-options.sh
CommitLineData
1d410cd8
CM
1#!/bin/sh
2#
3# Copyright (c) 2018 Phillip Wood
4#
5
6test_description='git rebase interactive fixup options
7
8This test checks the "fixup [-C|-c]" command of rebase interactive.
9In addition to amending the contents of the commit, "fixup -C"
10replaces the original commit message with the message of the fixup
11commit. "fixup -c" also replaces the original message, but opens the
d8bd0806
CM
12editor to allow the user to edit the message before committing. Similar
13to the "fixup" command that works with "fixup!", "fixup -C" works with
14"amend!" upon --autosquash.
1d410cd8
CM
15'
16
9ff2f060 17TEST_PASSES_SANITIZE_LEAK=true
1d410cd8
CM
18. ./test-lib.sh
19
20. "$TEST_DIRECTORY"/lib-rebase.sh
21
22EMPTY=""
23
1d410cd8
CM
24get_author () {
25 rev="$1" &&
4755fed0 26 git log -1 --pretty=format:"%an %ae %at" "$rev"
1d410cd8
CM
27}
28
29test_expect_success 'setup' '
30 cat >message <<-EOF &&
17665167
CM
31 amend! B
32 $EMPTY
33 new subject
34 $EMPTY
35 new
36 body
37 EOF
1d410cd8 38
666b6e11 39 test_commit initial &&
1d410cd8
CM
40 test_commit A A &&
41 test_commit B B &&
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 &&
48 test_commit A2 A &&
49 test_commit A3 A &&
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 &&
54
55 set_fake_editor &&
56 git checkout -b branch B &&
57 echo B1 >B &&
58 test_tick &&
59 git commit --fixup=HEAD -a &&
9c7650c4 60 git tag B1 &&
1d410cd8 61 test_tick &&
8bedae45 62 FAKE_COMMIT_AMEND="edited 1" git commit --fixup=reword:B &&
1d410cd8 63 test_tick &&
8bedae45 64 FAKE_COMMIT_AMEND="edited 2" git commit --fixup=reword:HEAD &&
1d410cd8
CM
65 echo B2 >B &&
66 test_tick &&
67 FAKE_COMMIT_AMEND="edited squash" git commit --squash=HEAD -a &&
9c7650c4 68 git tag B2 &&
1d410cd8
CM
69 echo B3 >B &&
70 test_tick &&
8bedae45 71 FAKE_COMMIT_AMEND="edited 3" git commit -a --fixup=amend:HEAD^ &&
9c7650c4 72 git tag B3 &&
1d410cd8
CM
73
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"
78'
79
80test_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"
87'
88
89test_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" \
96 git rebase -i B &&
97 test_cmp_rev HEAD^ B &&
98 test_cmp_rev HEAD^{tree} A2^{tree} &&
99 test_commit_message HEAD expected-fixup-message
100'
101
102test_expect_success 'fixup -C removes amend! from message' '
103 test_when_finished "test_might_fail git rebase --abort" &&
104 git checkout --detach A1 &&
733ad2e1 105 git log -1 --pretty=format:%b >expected-message &&
1d410cd8
CM
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
112'
113
114test_expect_success 'fixup -C with conflicts gives correct message' '
115 test_when_finished "test_might_fail git rebase --abort" &&
116 git checkout --detach A1 &&
733ad2e1
CM
117 git log -1 --pretty=format:%b >expected-message &&
118 test_write_lines "" "edited" >>expected-message &&
1d410cd8
CM
119 test_must_fail env FAKE_LINES="1 fixup_-C 2" git rebase -i conflicts &&
120 git checkout --theirs -- A &&
121 git add A &&
122 FAKE_COMMIT_AMEND=edited git rebase --continue &&
123 test_cmp_rev HEAD^ conflicts &&
124 test_cmp_rev HEAD^{tree} A1^{tree} &&
1d410cd8
CM
125 test_commit_message HEAD expected-message &&
126 get_author HEAD >actual-author &&
127 test_cmp expected-author actual-author
128'
129
130test_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 &&
134 git reset --hard &&
135 FAKE_COMMIT_AMEND=edited git rebase --continue &&
136 test_commit_message HEAD -m "B"
137'
138
139test_expect_success 'sequence of fixup, fixup -C & squash --signoff works' '
9c7650c4 140 git checkout --detach B3 &&
1d410cd8
CM
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 &&
9c7650c4 145 git diff-tree --exit-code --patch HEAD B3 -- &&
1d410cd8 146 test_cmp_rev HEAD^ A &&
feeb03bc 147 test_cmp "$TEST_DIRECTORY/t3437/expected-squash-message" \
1d410cd8
CM
148 actual-squash-message
149'
150
151test_expect_success 'first fixup -C commented out in sequence fixup fixup -C fixup -C' '
152 test_when_finished "test_might_fail git rebase --abort" &&
9c7650c4 153 git checkout --detach B2~ &&
1d410cd8
CM
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
158'
159
160test_expect_success 'multiple fixup -c opens editor once' '
161 test_when_finished "test_might_fail git rebase --abort" &&
162 git checkout --detach A3 &&
9ff6b74b
CM
163 git log -1 --pretty=format:%B >expected-message &&
164 test_write_lines "" "Modified-A3" >>expected-message &&
165 FAKE_COMMIT_AMEND="Modified-A3" \
1d410cd8
CM
166 FAKE_LINES="1 fixup_-C 2 fixup_-c 3 fixup_-c 4" \
167 EXPECT_HEADER_COUNT=4 \
9c7650c4
CM
168 git rebase -i A &&
169 test_cmp_rev HEAD^ A &&
4755fed0
CM
170 get_author HEAD >actual-author &&
171 test_cmp expected-author actual-author &&
9ff6b74b 172 test_commit_message HEAD expected-message
1d410cd8
CM
173'
174
175test_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 &&
feeb03bc 181 test_cmp "$TEST_DIRECTORY/t3437/expected-combined-message" \
1d410cd8
CM
182 actual-combined-message &&
183 test_cmp_rev HEAD^ A
184'
185
bae5b4ae 186test_expect_success 'fixup -C works upon --autosquash with amend!' '
9c7650c4 187 git checkout --detach B3 &&
bae5b4ae
CM
188 FAKE_COMMIT_AMEND=squashed \
189 FAKE_MESSAGE_COPY=actual-squash-message \
190 git -c commit.status=false rebase -ik --autosquash \
191 --signoff A &&
9c7650c4 192 git diff-tree --exit-code --patch HEAD B3 -- &&
bae5b4ae 193 test_cmp_rev HEAD^ A &&
feeb03bc 194 test_cmp "$TEST_DIRECTORY/t3437/expected-squash-message" \
bae5b4ae
CM
195 actual-squash-message
196'
197
666b6e11
PW
198test_expect_success 'fixup -[Cc]<commit> works' '
199 test_when_finished "test_might_fail git rebase --abort" &&
200 cat >todo <<-\EOF &&
201 pick A
202 fixup -CA1
203 pick B
204 fixup -cA2
205 EOF
206 (
207 set_replace_editor todo &&
208 FAKE_COMMIT_MESSAGE="edited and fixed up" \
209 git rebase -i initial initial
210 ) &&
211 git log --pretty=format:%B initial.. >actual &&
212 cat >expect <<-EOF &&
213 edited and fixed up
214 $EMPTY
215 new subject
216 $EMPTY
217 new
218 body
219 EOF
220 test_cmp expect actual
221'
222
1d410cd8 223test_done