Merge branch 'master' of github.com:Softcatala/git-po
[git/debian.git] / t / t3418-rebase-continue.sh
blob0838f4e798a5ef8bd3b99caba2be5364c1d9685f
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 'interactive rebase --continue 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 'non-interactive rebase --continue works with touched file' '
35 rm -fr .git/rebase-* &&
36 git reset --hard &&
37 git checkout main &&
39 test_must_fail git rebase --onto main main topic &&
40 echo "Resolved" >F2 &&
41 git add F2 &&
42 test-tool chmtime =-60 F1 &&
43 git rebase --continue
46 test_expect_success 'rebase --continue can not be used with other options' '
47 test_must_fail git rebase -v --continue &&
48 test_must_fail git rebase --continue -v
51 test_expect_success 'rebase --continue remembers merge strategy and options' '
52 rm -fr .git/rebase-* &&
53 git reset --hard commit-new-file-F2-on-topic-branch &&
54 test_commit "commit-new-file-F3-on-topic-branch" F3 32 &&
55 test_when_finished "rm -fr test-bin funny.was.run" &&
56 mkdir test-bin &&
57 cat >test-bin/git-merge-funny <<-EOF &&
58 #!$SHELL_PATH
59 case "\$1" in --opt) ;; *) exit 2 ;; esac
60 shift &&
61 >funny.was.run &&
62 exec git merge-recursive "\$@"
63 EOF
64 chmod +x test-bin/git-merge-funny &&
66 PATH=./test-bin:$PATH &&
67 test_must_fail git rebase -s funny -Xopt main topic
68 ) &&
69 test -f funny.was.run &&
70 rm funny.was.run &&
71 echo "Resolved" >F2 &&
72 git add F2 &&
74 PATH=./test-bin:$PATH &&
75 git rebase --continue
76 ) &&
77 test -f funny.was.run
80 test_expect_success 'rebase -i --continue handles merge strategy and options' '
81 rm -fr .git/rebase-* &&
82 git reset --hard commit-new-file-F2-on-topic-branch &&
83 test_commit "commit-new-file-F3-on-topic-branch-for-dash-i" F3 32 &&
84 test_when_finished "rm -fr test-bin funny.was.run funny.args" &&
85 mkdir test-bin &&
86 cat >test-bin/git-merge-funny <<-EOF &&
87 #!$SHELL_PATH
88 echo "\$@" >>funny.args
89 case "\$1" in --opt) ;; *) exit 2 ;; esac
90 case "\$2" in --foo) ;; *) exit 2 ;; esac
91 case "\$4" in --) ;; *) exit 2 ;; esac
92 shift 2 &&
93 >funny.was.run &&
94 exec git merge-recursive "\$@"
95 EOF
96 chmod +x test-bin/git-merge-funny &&
98 PATH=./test-bin:$PATH &&
99 test_must_fail git rebase -i -s funny -Xopt -Xfoo main topic
100 ) &&
101 test -f funny.was.run &&
102 rm funny.was.run &&
103 echo "Resolved" >F2 &&
104 git add F2 &&
106 PATH=./test-bin:$PATH &&
107 git rebase --continue
108 ) &&
109 test -f funny.was.run
112 test_expect_success REBASE_P 'rebase passes merge strategy options correctly' '
113 rm -fr .git/rebase-* &&
114 git reset --hard commit-new-file-F3-on-topic-branch &&
115 test_commit theirs-to-merge &&
116 git reset --hard HEAD^ &&
117 test_commit some-commit &&
118 test_tick &&
119 git merge --no-ff theirs-to-merge &&
120 FAKE_LINES="1 edit 2 3" git rebase -i -f -p -m \
121 -s recursive --strategy-option=theirs HEAD~2 &&
122 test_commit force-change &&
123 git rebase --continue
126 test_expect_success 'rebase -r passes merge strategy options correctly' '
127 rm -fr .git/rebase-* &&
128 git reset --hard commit-new-file-F3-on-topic-branch &&
129 test_commit merge-theirs &&
130 git reset --hard HEAD^ &&
131 test_commit some-other-commit &&
132 test_tick &&
133 git merge --no-ff merge-theirs &&
134 FAKE_LINES="1 3 edit 4 5 7 8 9" git rebase -i -f -r -m \
135 -s recursive --strategy-option=theirs HEAD~2 &&
136 test_commit force-change-ours &&
137 git rebase --continue
140 test_expect_success '--skip after failed fixup cleans commit message' '
141 test_when_finished "test_might_fail git rebase --abort" &&
142 git checkout -b with-conflicting-fixup &&
143 test_commit wants-fixup &&
144 test_commit "fixup! wants-fixup" wants-fixup.t 1 wants-fixup-1 &&
145 test_commit "fixup! wants-fixup" wants-fixup.t 2 wants-fixup-2 &&
146 test_commit "fixup! wants-fixup" wants-fixup.t 3 wants-fixup-3 &&
147 test_must_fail env FAKE_LINES="1 fixup 2 squash 4" \
148 git rebase -i HEAD~4 &&
150 : now there is a conflict, and comments in the commit message &&
151 git show HEAD >out &&
152 grep "fixup! wants-fixup" out &&
154 : skip and continue &&
155 echo "cp \"\$1\" .git/copy.txt" | write_script copy-editor.sh &&
156 (test_set_editor "$PWD/copy-editor.sh" && git rebase --skip) &&
158 : the user should not have had to edit the commit message &&
159 test_path_is_missing .git/copy.txt &&
161 : now the comments in the commit message should have been cleaned up &&
162 git show HEAD >out &&
163 ! grep "fixup! wants-fixup" out &&
165 : now, let us ensure that "squash" is handled correctly &&
166 git reset --hard wants-fixup-3 &&
167 test_must_fail env FAKE_LINES="1 squash 4 squash 2 squash 4" \
168 git rebase -i HEAD~4 &&
170 : the first squash failed, but there are two more in the chain &&
171 (test_set_editor "$PWD/copy-editor.sh" &&
172 test_must_fail git rebase --skip) &&
174 : not the final squash, no need to edit the commit message &&
175 test_path_is_missing .git/copy.txt &&
177 : The first squash was skipped, therefore: &&
178 git show HEAD >out &&
179 test_i18ngrep "# This is a combination of 2 commits" out &&
180 test_i18ngrep "# This is the commit message #2:" out &&
182 (test_set_editor "$PWD/copy-editor.sh" && git rebase --skip) &&
183 git show HEAD >out &&
184 test_i18ngrep ! "# This is a combination" out &&
186 : Final squash failed, but there was still a squash &&
187 test_i18ngrep "# This is a combination of 2 commits" .git/copy.txt &&
188 test_i18ngrep "# This is the commit message #2:" .git/copy.txt
191 test_expect_success 'setup rerere database' '
192 rm -fr .git/rebase-* &&
193 git reset --hard commit-new-file-F3-on-topic-branch &&
194 git checkout main &&
195 test_commit "commit-new-file-F3" F3 3 &&
196 test_config rerere.enabled true &&
197 git update-ref refs/heads/topic commit-new-file-F3-on-topic-branch &&
198 test_must_fail git rebase -m main topic &&
199 echo "Resolved" >F2 &&
200 cp F2 expected-F2 &&
201 git add F2 &&
202 test_must_fail git rebase --continue &&
203 echo "Resolved" >F3 &&
204 cp F3 expected-F3 &&
205 git add F3 &&
206 git rebase --continue &&
207 git reset --hard topic@{1}
210 prepare () {
211 rm -fr .git/rebase-* &&
212 git reset --hard commit-new-file-F3-on-topic-branch &&
213 git checkout main &&
214 test_config rerere.enabled true
217 test_rerere_autoupdate () {
218 action=$1 &&
219 test_expect_success "rebase $action --continue remembers --rerere-autoupdate" '
220 prepare &&
221 test_must_fail git rebase $action --rerere-autoupdate main topic &&
222 test_cmp expected-F2 F2 &&
223 git diff-files --quiet &&
224 test_must_fail git rebase --continue &&
225 test_cmp expected-F3 F3 &&
226 git diff-files --quiet &&
227 git rebase --continue
230 test_expect_success "rebase $action --continue honors rerere.autoUpdate" '
231 prepare &&
232 test_config rerere.autoupdate true &&
233 test_must_fail git rebase $action main topic &&
234 test_cmp expected-F2 F2 &&
235 git diff-files --quiet &&
236 test_must_fail git rebase --continue &&
237 test_cmp expected-F3 F3 &&
238 git diff-files --quiet &&
239 git rebase --continue
242 test_expect_success "rebase $action --continue remembers --no-rerere-autoupdate" '
243 prepare &&
244 test_config rerere.autoupdate true &&
245 test_must_fail git rebase $action --no-rerere-autoupdate main topic &&
246 test_cmp expected-F2 F2 &&
247 test_must_fail git diff-files --quiet &&
248 git add F2 &&
249 test_must_fail git rebase --continue &&
250 test_cmp expected-F3 F3 &&
251 test_must_fail git diff-files --quiet &&
252 git add F3 &&
253 git rebase --continue
257 test_rerere_autoupdate
258 test_rerere_autoupdate -m
259 GIT_SEQUENCE_EDITOR=: && export GIT_SEQUENCE_EDITOR
260 test_rerere_autoupdate -i
261 test_have_prereq !REBASE_P || test_rerere_autoupdate --preserve-merges
262 unset GIT_SEQUENCE_EDITOR
264 test_expect_success 'the todo command "break" works' '
265 rm -f execed &&
266 FAKE_LINES="break b exec_>execed" git rebase -i HEAD &&
267 test_path_is_missing execed &&
268 git rebase --continue &&
269 test_path_is_missing execed &&
270 git rebase --continue &&
271 test_path_is_file execed
274 test_expect_success '--reschedule-failed-exec' '
275 test_when_finished "git rebase --abort" &&
276 test_must_fail git rebase -x false --reschedule-failed-exec HEAD^ &&
277 grep "^exec false" .git/rebase-merge/git-rebase-todo &&
278 git rebase --abort &&
279 test_must_fail git -c rebase.rescheduleFailedExec=true \
280 rebase -x false HEAD^ 2>err &&
281 grep "^exec false" .git/rebase-merge/git-rebase-todo &&
282 test_i18ngrep "has been rescheduled" err
285 test_expect_success 'rebase.reschedulefailedexec only affects `rebase -i`' '
286 test_config rebase.reschedulefailedexec true &&
287 test_must_fail git rebase -x false HEAD^ &&
288 grep "^exec false" .git/rebase-merge/git-rebase-todo &&
289 git rebase --abort &&
290 git rebase HEAD^
293 test_done