3 # Copyright (c) 2017 Johannes E. Schindelin
6 test_description='git rebase -i --recreate-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
22 test_expect_success 'setup' '
23 write_script replace-editor.sh <<-\EOF &&
24 mv "$1" "$(git rev-parse --git-path ORIGINAL-TODO)"
25 cp script-from-scratch "$1"
29 git checkout -b first &&
31 git checkout master &&
34 git merge --no-commit B &&
38 git checkout -b second C &&
41 git checkout master &&
42 git merge --no-commit G &&
48 cat >script-from-scratch <<\EOF
63 merge onebranch # Merge the topic branch 'onebranch'
68 git log --graph --boundary --format=%s "$@" >output &&
69 sed "s/ *$//" <output >output.trimmed &&
70 test_cmp expect output.trimmed
73 test_expect_success 'create completely different structure' '
74 test_config sequence.editor \""$PWD"/replace-editor.sh\" &&
76 git rebase -i --recreate-merges A &&
77 test_cmp_graph <<-\EOF
78 * Merge the topic branch '\''onebranch'\''
92 test_expect_success 'generate correct todo list' '
93 cat >expect <<-\EOF &&
107 reset branch-point # C
109 merge -C 2051b56 E # E
110 merge -C 233d48a H # H
114 grep -v "^#" <.git/ORIGINAL-TODO >output &&
115 test_cmp expect output
118 test_expect_success 'with a branch tip that was cherry-picked already' '
119 git checkout -b already-upstream master &&
120 base="$(git rev-parse --verify HEAD)" &&
124 git reset --hard $base &&
127 git merge -m "Merge branch A" A2 &&
129 git checkout -b upstream-with-a2 $base &&
131 git cherry-pick A2 &&
133 git checkout already-upstream &&
135 git rebase -i --recreate-merges upstream-with-a2 &&
136 test_cmp_graph upstream-with-a2.. <<-\EOF
146 test_expect_success 'refs/rewritten/* is worktree-local' '
147 git worktree add wt &&
148 cat >wt/script-from-scratch <<-\EOF &&
150 exec GIT_DIR=../.git git rev-parse --verify refs/rewritten/xyz >a || :
151 exec git rev-parse --verify refs/rewritten/xyz >b
154 test_config -C wt sequence.editor \""$PWD"/replace-editor.sh\" &&
155 git -C wt rebase -i HEAD &&
156 test_must_be_empty wt/a &&
157 test_cmp_rev HEAD "$(cat wt/b)"