packfile: convert has_packed_and_bad() to object_id
[git/debian.git] / t / t3418-rebase-continue.sh
blob738fbae9b291b38f7129ec6321819c70cdc5aeae
1 #!/bin/sh
3 test_description='git rebase --continue tests'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 . ./test-lib.sh
10 . "$TEST_DIRECTORY"/lib-rebase.sh
12 set_fake_editor
14 test_expect_success 'setup' '
15 test_commit "commit-new-file-F1" F1 1 &&
16 test_commit "commit-new-file-F2" F2 2 &&
18 git checkout -b topic HEAD^ &&
19 test_commit "commit-new-file-F2-on-topic-branch" F2 22 &&
21 git checkout main
24 test_expect_success 'merge based rebase --continue with works with touched file' '
25 rm -fr .git/rebase-* &&
26 git reset --hard &&
27 git checkout main &&
29 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
30 test-tool chmtime =-60 F1 &&
31 git rebase --continue
34 test_expect_success 'merge based rebase --continue removes .git/MERGE_MSG' '
35 git checkout -f --detach topic &&
37 test_must_fail git rebase --onto main HEAD^ &&
38 git read-tree --reset -u HEAD &&
39 test_path_is_file .git/MERGE_MSG &&
40 git rebase --continue &&
41 test_path_is_missing .git/MERGE_MSG
44 test_expect_success 'apply based rebase --continue works with touched file' '
45 rm -fr .git/rebase-* &&
46 git reset --hard &&
47 git checkout main &&
49 test_must_fail git rebase --apply --onto main main topic &&
50 echo "Resolved" >F2 &&
51 git add F2 &&
52 test-tool chmtime =-60 F1 &&
53 git rebase --continue
56 test_expect_success 'rebase --continue can not be used with other options' '
57 test_must_fail git rebase -v --continue &&
58 test_must_fail git rebase --continue -v
61 test_expect_success 'rebase --continue remembers merge strategy and options' '
62 rm -fr .git/rebase-* &&
63 git reset --hard commit-new-file-F2-on-topic-branch &&
64 test_commit "commit-new-file-F3-on-topic-branch" F3 32 &&
65 test_when_finished "rm -fr test-bin funny.was.run" &&
66 mkdir test-bin &&
67 cat >test-bin/git-merge-funny <<-EOF &&
68 #!$SHELL_PATH
69 case "\$1" in --opt) ;; *) exit 2 ;; esac
70 shift &&
71 >funny.was.run &&
72 exec git merge-recursive "\$@"
73 EOF
74 chmod +x test-bin/git-merge-funny &&
76 PATH=./test-bin:$PATH &&
77 test_must_fail git rebase -s funny -Xopt main topic
78 ) &&
79 test -f funny.was.run &&
80 rm funny.was.run &&
81 echo "Resolved" >F2 &&
82 git add F2 &&
84 PATH=./test-bin:$PATH &&
85 git rebase --continue
86 ) &&
87 test -f funny.was.run
90 test_expect_success 'rebase -i --continue handles merge strategy and options' '
91 rm -fr .git/rebase-* &&
92 git reset --hard commit-new-file-F2-on-topic-branch &&
93 test_commit "commit-new-file-F3-on-topic-branch-for-dash-i" F3 32 &&
94 test_when_finished "rm -fr test-bin funny.was.run funny.args" &&
95 mkdir test-bin &&
96 cat >test-bin/git-merge-funny <<-EOF &&
97 #!$SHELL_PATH
98 echo "\$@" >>funny.args
99 case "\$1" in --opt) ;; *) exit 2 ;; esac
100 case "\$2" in --foo) ;; *) exit 2 ;; esac
101 case "\$4" in --) ;; *) exit 2 ;; esac
102 shift 2 &&
103 >funny.was.run &&
104 exec git merge-recursive "\$@"
106 chmod +x test-bin/git-merge-funny &&
108 PATH=./test-bin:$PATH &&
109 test_must_fail git rebase -i -s funny -Xopt -Xfoo main topic
110 ) &&
111 test -f funny.was.run &&
112 rm funny.was.run &&
113 echo "Resolved" >F2 &&
114 git add F2 &&
116 PATH=./test-bin:$PATH &&
117 git rebase --continue
118 ) &&
119 test -f funny.was.run
122 test_expect_success REBASE_P 'rebase passes merge strategy options correctly' '
123 rm -fr .git/rebase-* &&
124 git reset --hard commit-new-file-F3-on-topic-branch &&
125 test_commit theirs-to-merge &&
126 git reset --hard HEAD^ &&
127 test_commit some-commit &&
128 test_tick &&
129 git merge --no-ff theirs-to-merge &&
130 FAKE_LINES="1 edit 2 3" git rebase -i -f -p -m \
131 -s recursive --strategy-option=theirs HEAD~2 &&
132 test_commit force-change &&
133 git rebase --continue
136 test_expect_success 'rebase -r passes merge strategy options correctly' '
137 rm -fr .git/rebase-* &&
138 git reset --hard commit-new-file-F3-on-topic-branch &&
139 test_commit merge-theirs &&
140 git reset --hard HEAD^ &&
141 test_commit some-other-commit &&
142 test_tick &&
143 git merge --no-ff merge-theirs &&
144 FAKE_LINES="1 3 edit 4 5 7 8 9" git rebase -i -f -r -m \
145 -s recursive --strategy-option=theirs HEAD~2 &&
146 test_commit force-change-ours &&
147 git rebase --continue
150 test_expect_success '--skip after failed fixup cleans commit message' '
151 test_when_finished "test_might_fail git rebase --abort" &&
152 git checkout -b with-conflicting-fixup &&
153 test_commit wants-fixup &&
154 test_commit "fixup! wants-fixup" wants-fixup.t 1 wants-fixup-1 &&
155 test_commit "fixup! wants-fixup" wants-fixup.t 2 wants-fixup-2 &&
156 test_commit "fixup! wants-fixup" wants-fixup.t 3 wants-fixup-3 &&
157 test_must_fail env FAKE_LINES="1 fixup 2 squash 4" \
158 git rebase -i HEAD~4 &&
160 : now there is a conflict, and comments in the commit message &&
161 git show HEAD >out &&
162 grep "fixup! wants-fixup" out &&
164 : skip and continue &&
165 echo "cp \"\$1\" .git/copy.txt" | write_script copy-editor.sh &&
166 (test_set_editor "$PWD/copy-editor.sh" && git rebase --skip) &&
168 : the user should not have had to edit the commit message &&
169 test_path_is_missing .git/copy.txt &&
171 : now the comments in the commit message should have been cleaned up &&
172 git show HEAD >out &&
173 ! grep "fixup! wants-fixup" out &&
175 : now, let us ensure that "squash" is handled correctly &&
176 git reset --hard wants-fixup-3 &&
177 test_must_fail env FAKE_LINES="1 squash 4 squash 2 squash 4" \
178 git rebase -i HEAD~4 &&
180 : the first squash failed, but there are two more in the chain &&
181 (test_set_editor "$PWD/copy-editor.sh" &&
182 test_must_fail git rebase --skip) &&
184 : not the final squash, no need to edit the commit message &&
185 test_path_is_missing .git/copy.txt &&
187 : The first squash was skipped, therefore: &&
188 git show HEAD >out &&
189 test_i18ngrep "# This is a combination of 2 commits" out &&
190 test_i18ngrep "# This is the commit message #2:" out &&
192 (test_set_editor "$PWD/copy-editor.sh" && git rebase --skip) &&
193 git show HEAD >out &&
194 test_i18ngrep ! "# This is a combination" out &&
196 : Final squash failed, but there was still a squash &&
197 test_i18ngrep "# This is a combination of 2 commits" .git/copy.txt &&
198 test_i18ngrep "# This is the commit message #2:" .git/copy.txt
201 test_expect_success 'setup rerere database' '
202 rm -fr .git/rebase-* &&
203 git reset --hard commit-new-file-F3-on-topic-branch &&
204 git checkout main &&
205 test_commit "commit-new-file-F3" F3 3 &&
206 test_config rerere.enabled true &&
207 git update-ref refs/heads/topic commit-new-file-F3-on-topic-branch &&
208 test_must_fail git rebase -m main topic &&
209 echo "Resolved" >F2 &&
210 cp F2 expected-F2 &&
211 git add F2 &&
212 test_must_fail git rebase --continue &&
213 echo "Resolved" >F3 &&
214 cp F3 expected-F3 &&
215 git add F3 &&
216 git rebase --continue &&
217 git reset --hard topic@{1}
220 prepare () {
221 rm -fr .git/rebase-* &&
222 git reset --hard commit-new-file-F3-on-topic-branch &&
223 git checkout main &&
224 test_config rerere.enabled true
227 test_rerere_autoupdate () {
228 action=$1 &&
229 test_expect_success "rebase $action --continue remembers --rerere-autoupdate" '
230 prepare &&
231 test_must_fail git rebase $action --rerere-autoupdate main topic &&
232 test_cmp expected-F2 F2 &&
233 git diff-files --quiet &&
234 test_must_fail git rebase --continue &&
235 test_cmp expected-F3 F3 &&
236 git diff-files --quiet &&
237 git rebase --continue
240 test_expect_success "rebase $action --continue honors rerere.autoUpdate" '
241 prepare &&
242 test_config rerere.autoupdate true &&
243 test_must_fail git rebase $action main topic &&
244 test_cmp expected-F2 F2 &&
245 git diff-files --quiet &&
246 test_must_fail git rebase --continue &&
247 test_cmp expected-F3 F3 &&
248 git diff-files --quiet &&
249 git rebase --continue
252 test_expect_success "rebase $action --continue remembers --no-rerere-autoupdate" '
253 prepare &&
254 test_config rerere.autoupdate true &&
255 test_must_fail git rebase $action --no-rerere-autoupdate main topic &&
256 test_cmp expected-F2 F2 &&
257 test_must_fail git diff-files --quiet &&
258 git add F2 &&
259 test_must_fail git rebase --continue &&
260 test_cmp expected-F3 F3 &&
261 test_must_fail git diff-files --quiet &&
262 git add F3 &&
263 git rebase --continue
267 test_rerere_autoupdate --apply
268 test_rerere_autoupdate -m
269 GIT_SEQUENCE_EDITOR=: && export GIT_SEQUENCE_EDITOR
270 test_rerere_autoupdate -i
271 test_have_prereq !REBASE_P || test_rerere_autoupdate --preserve-merges
272 unset GIT_SEQUENCE_EDITOR
274 test_expect_success 'the todo command "break" works' '
275 rm -f execed &&
276 FAKE_LINES="break b exec_>execed" git rebase -i HEAD &&
277 test_path_is_missing execed &&
278 git rebase --continue &&
279 test_path_is_missing execed &&
280 git rebase --continue &&
281 test_path_is_file execed
284 test_expect_success '--reschedule-failed-exec' '
285 test_when_finished "git rebase --abort" &&
286 test_must_fail git rebase -x false --reschedule-failed-exec HEAD^ &&
287 grep "^exec false" .git/rebase-merge/git-rebase-todo &&
288 git rebase --abort &&
289 test_must_fail git -c rebase.rescheduleFailedExec=true \
290 rebase -x false HEAD^ 2>err &&
291 grep "^exec false" .git/rebase-merge/git-rebase-todo &&
292 test_i18ngrep "has been rescheduled" err
295 test_expect_success 'rebase.rescheduleFailedExec only affects `rebase -i`' '
296 test_config rebase.rescheduleFailedExec true &&
297 test_must_fail git rebase -x false HEAD^ &&
298 grep "^exec false" .git/rebase-merge/git-rebase-todo &&
299 git rebase --abort &&
300 git rebase HEAD^
303 test_expect_success 'rebase.rescheduleFailedExec=true & --no-reschedule-failed-exec' '
304 test_when_finished "git rebase --abort" &&
305 test_config rebase.rescheduleFailedExec true &&
306 test_must_fail git rebase -x false --no-reschedule-failed-exec HEAD~2 &&
307 test_must_fail git rebase --continue 2>err &&
308 ! grep "has been rescheduled" err
311 test_expect_success 'new rebase.rescheduleFailedExec=true setting in an ongoing rebase is ignored' '
312 test_when_finished "git rebase --abort" &&
313 test_must_fail git rebase -x false HEAD~2 &&
314 test_config rebase.rescheduleFailedExec true &&
315 test_must_fail git rebase --continue 2>err &&
316 ! grep "has been rescheduled" err
319 test_expect_success 'there is no --no-reschedule-failed-exec in an ongoing rebase' '
320 test_when_finished "git rebase --abort" &&
321 test_must_fail git rebase -x false HEAD~2 &&
322 test_expect_code 129 git rebase --continue --no-reschedule-failed-exec &&
323 test_expect_code 129 git rebase --edit-todo --no-reschedule-failed-exec
326 test_done