3 # Copyright (c) 2007 Johannes E. Schindelin
6 test_description
='git rebase interactive
8 This test runs git rebase "interactively", by faking an edit, and verifies
9 that the result still makes sense.
13 # set up two branches like this:
21 # where B, D and G touch the same file.
23 test_expect_success
'setup' '
31 git commit -m B file1 &&
38 git commit -m D file1 &&
43 git checkout -b branch1 A &&
51 git commit -m G file1 &&
56 git checkout -b branch2 F &&
64 cat > fake-editor.sh
<< EOF
66 test "\$1" = .git/COMMIT_EDITMSG && {
67 test -z "\$FAKE_COMMIT_MESSAGE" || echo "\$FAKE_COMMIT_MESSAGE" > "\$1"
68 test -z "\$FAKE_COMMIT_AMEND" || echo "\$FAKE_COMMIT_AMEND" >> "\$1"
71 test -z "\$FAKE_LINES" && exit
72 grep -v "^#" < "\$1" > "\$1".tmp
76 for line in \$FAKE_LINES; do
81 echo sed -n "\${line}s/^pick/\$action/p"
82 sed -n "\${line}p" < "\$1".tmp
83 sed -n "\${line}s/^pick/\$action/p" < "\$1".tmp >> "\$1"
89 chmod a
+x fake-editor.sh
90 VISUAL
="$(pwd)/fake-editor.sh"
93 test_expect_success
'no changes are a nop' '
95 test $(git rev-parse I) = $(git rev-parse HEAD)
98 test_expect_success
'rebase on top of a non-conflicting commit' '
99 git checkout branch1 &&
100 git tag original-branch1 &&
101 git rebase -i branch2 &&
102 test file6 = $(git diff --name-only original-branch1) &&
103 test $(git rev-parse I) = $(git rev-parse HEAD~2)
106 test_expect_success
'reflog for the branch shows state before rebase' '
107 test $(git rev-parse branch1@{1}) = $(git rev-parse original-branch1)
110 test_expect_success
'exchange two commits' '
111 FAKE_LINES="2 1" git rebase -i HEAD~2 &&
112 test H = $(git cat-file commit HEAD^ | tail -n 1) &&
113 test G = $(git cat-file commit HEAD | tail -n 1)
117 diff --git a/file1 b/file1
118 index e69de29..00750ed 100644
130 >>>>>>> b7ca976... G:file1
133 test_expect_success
'stop on conflicting pick' '
134 git tag new-branch1 &&
135 ! git rebase -i master &&
136 diff -u expect .git/.dotest-merge/patch &&
137 diff -u expect2 file1 &&
138 test 4 = $(grep -v "^#" < .git/.dotest-merge/done | wc -l) &&
139 test 0 = $(grep -v "^#" < .git/.dotest-merge/todo | wc -l)
142 test_expect_success
'abort' '
143 git rebase --abort &&
144 test $(git rev-parse new-branch1) = $(git rev-parse HEAD) &&
145 ! test -d .git/.dotest-merge
148 test_expect_success
'retain authorship' '
152 GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
154 git rebase -i --onto master HEAD^ &&
155 git show HEAD | grep "^Author: Twerp Snog"
158 test_expect_success
'squash' '
159 git reset --hard twerp &&
162 GIT_AUTHOR_NAME="Nitfol" git commit -m "nitfol" file7 &&
163 echo "******************************" &&
164 FAKE_LINES="1 squash 2" git rebase -i --onto master HEAD~2 &&
165 test B = $(cat file7) &&
166 test $(git rev-parse HEAD^) = $(git rev-parse master)
169 test_expect_success
'retain authorship when squashing' '
170 git show HEAD | grep "^Author: Nitfol"
173 test_expect_success
'preserve merges with -p' '
174 git checkout -b to-be-preserved master^ &&
175 : > unrelated-file &&
176 git add unrelated-file &&
178 git commit -m "unrelated" &&
179 git checkout -b to-be-rebased master &&
182 git commit -m J file1 &&
184 git merge to-be-preserved &&
187 git commit -m K file1 &&
189 git rebase -i -p --onto branch1 master &&
190 test $(git rev-parse HEAD^^2) = $(git rev-parse to-be-preserved) &&
191 test $(git rev-parse HEAD~3) = $(git rev-parse branch1) &&
192 test $(git show HEAD:file1) = C &&
193 test $(git show HEAD~2:file1) = B
196 test_expect_success
'--continue tries to commit' '
198 ! git rebase -i --onto new-branch1 HEAD^ &&
199 echo resolved > file1 &&
201 FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue &&
202 test $(git rev-parse HEAD^) = $(git rev-parse new-branch1) &&
203 git show HEAD | grep chouette
206 test_expect_success
'verbose flag is heeded, even after --continue' '
207 git reset --hard HEAD@{1} &&
209 ! git rebase -v -i --onto new-branch1 HEAD^ &&
210 echo resolved > file1 &&
212 git rebase --continue > output &&
213 grep "^ file1 | 2 +-$" output
216 test_expect_success
'multi-squash only fires up editor once' '
217 base=$(git rev-parse HEAD~4) &&
218 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 squash 2 squash 3 squash 4" \
219 git rebase -i $base &&
220 test $base = $(git rev-parse HEAD^) &&
221 test 1 = $(git show | grep ONCE | wc -l)