Merge branch 'ja/doc-synopsis-markup'
[git/gitster.git] / t / t3437-rebase-fixup-options.sh
blob7929e2e2e3a8fc1240af3991f85172c16dcbd2cf
1 #!/bin/sh
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
18 . ./test-lib.sh
20 . "$TEST_DIRECTORY"/lib-rebase.sh
22 EMPTY=""
24 get_author () {
25 rev="$1" &&
26 git log -1 --pretty=format:"%an %ae %at" "$rev"
29 test_expect_success 'setup' '
30 cat >message <<-EOF &&
31 amend! B
32 $EMPTY
33 new subject
34 $EMPTY
35 new
36 body
37 EOF
39 test_commit initial &&
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 &&
55 set_fake_editor &&
56 git checkout -b branch B &&
57 echo B1 >B &&
58 test_tick &&
59 git commit --fixup=HEAD -a &&
60 git tag B1 &&
61 test_tick &&
62 FAKE_COMMIT_AMEND="edited 1" git commit --fixup=reword:B &&
63 test_tick &&
64 FAKE_COMMIT_AMEND="edited 2" git commit --fixup=reword:HEAD &&
65 echo B2 >B &&
66 test_tick &&
67 FAKE_COMMIT_AMEND="edited squash" git commit --squash=HEAD -a &&
68 git tag B2 &&
69 echo B3 >B &&
70 test_tick &&
71 FAKE_COMMIT_AMEND="edited 3" git commit -a --fixup=amend:HEAD^ &&
72 git tag B3 &&
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" \
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
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 &&
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} &&
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 &&
134 git reset --hard &&
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 \
168 git rebase -i A &&
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 &&
183 test_cmp_rev HEAD^ A
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 \
191 --signoff A &&
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" &&
200 cat >todo <<-\EOF &&
201 pick A
202 fixup -CA1
203 pick B
204 fixup -cA2
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
218 body
220 test_cmp expect actual
223 test_done