3 # Copyright (c) 2018 Johannes E. Schindelin
6 test_description
='git rebase -i --rebase-merges
8 This test runs git rebase "interactively", retaining the branch structure by
9 recreating merge commits.
15 A - C - D - E - H (master)
20 .
"$TEST_DIRECTORY"/lib-rebase.sh
24 git log
--graph --boundary --format=%s
"$@" >output
&&
25 sed "s/ *$//" <output
>output.trimmed
&&
26 test_cmp expect output.trimmed
29 test_expect_success
'setup' '
30 write_script replace-editor.sh <<-\EOF &&
31 mv "$1" "$(git rev-parse --git-path ORIGINAL-TODO)"
32 cp script-from-scratch "$1"
36 git checkout -b first &&
38 git checkout master &&
41 git merge --no-commit B &&
45 git checkout -b second C &&
48 git checkout master &&
49 git merge --no-commit G &&
55 test_expect_success
'create completely different structure' '
56 cat >script-from-scratch <<-\EOF &&
71 merge onebranch # Merge the topic branch '\''onebranch'\''
73 test_config sequence.editor \""$PWD"/replace-editor.sh\" &&
76 test_cmp_graph <<-\EOF
77 * Merge the topic branch '\''onebranch'\''
91 test_expect_success
'generate correct todo list' '
92 cat >expect <<-\EOF &&
106 reset branch-point # C
108 merge -C 2051b56 E # E
109 merge -C 233d48a H # H
113 grep -v "^#" <.git/ORIGINAL-TODO >output &&
114 test_cmp expect output
117 test_expect_success
'`reset` refuses to overwrite untracked files' '
118 git checkout -b refuse-to-reset &&
119 test_commit dont-overwrite-untracked &&
120 git checkout @{-1} &&
121 : >dont-overwrite-untracked.t &&
122 echo "reset refs/tags/dont-overwrite-untracked" >script-from-scratch &&
123 test_config sequence.editor \""$PWD"/replace-editor.sh\" &&
124 test_must_fail git rebase -r HEAD &&
128 test_expect_success
'failed `merge` writes patch (may be rescheduled, too)' '
129 test_when_finished "test_might_fail git rebase --abort" &&
130 git checkout -b conflicting-merge A &&
132 : fail because of conflicting untracked file &&
134 echo "merge -C H G" >script-from-scratch &&
135 test_config sequence.editor \""$PWD"/replace-editor.sh\" &&
137 test_must_fail git rebase -ir HEAD &&
138 grep "^merge -C .* G$" .git/rebase-merge/done &&
139 grep "^merge -C .* G$" .git/rebase-merge/git-rebase-todo &&
140 test_path_is_file .git/rebase-merge/patch &&
142 : fail because of merge conflict &&
143 rm G.t .git/rebase-merge/patch &&
145 test_commit conflicting-G G.t not-G conflicting-G &&
146 test_must_fail git rebase --continue &&
147 ! grep "^merge -C .* G$" .git/rebase-merge/git-rebase-todo &&
148 test_path_is_file .git/rebase-merge/patch
151 test_expect_success
'with a branch tip that was cherry-picked already' '
152 git checkout -b already-upstream master &&
153 base="$(git rev-parse --verify HEAD)" &&
157 git reset --hard $base &&
160 git merge -m "Merge branch A" A2 &&
162 git checkout -b upstream-with-a2 $base &&
164 git cherry-pick A2 &&
166 git checkout already-upstream &&
168 git rebase -i -r upstream-with-a2 &&
169 test_cmp_graph upstream-with-a2.. <<-\EOF
179 test_expect_success
'refs/rewritten/* is worktree-local' '
180 git worktree add wt &&
181 cat >wt/script-from-scratch <<-\EOF &&
183 exec GIT_DIR=../.git git rev-parse --verify refs/rewritten/xyz >a || :
184 exec git rev-parse --verify refs/rewritten/xyz >b
187 test_config -C wt sequence.editor \""$PWD"/replace-editor.sh\" &&
188 git -C wt rebase -i HEAD &&
189 test_must_be_empty wt/a &&
190 test_cmp_rev HEAD "$(cat wt/b)"
193 test_expect_success
'post-rewrite hook and fixups work for merges' '
194 git checkout -b post-rewrite &&
196 git reset --hard HEAD^ &&
198 git merge -m "to fix up" same1 &&
199 echo same old same old >same2.t &&
201 git commit --fixup HEAD same2.t &&
202 fixup="$(git rev-parse HEAD)" &&
204 mkdir -p .git/hooks &&
205 test_when_finished "rm .git/hooks/post-rewrite" &&
206 echo "cat >actual" | write_script .git/hooks/post-rewrite &&
209 git rebase -i --autosquash -r HEAD^^^ &&
210 printf "%s %s\n%s %s\n%s %s\n%s %s\n" >expect $(git rev-parse \
215 test_cmp expect actual