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"
70 test -z "\$FAKE_LINES" && exit
71 grep -v "^#" < "\$1" > "\$1".tmp
75 for line in \$FAKE_LINES; do
80 echo sed -n "\${line}s/^pick/\$action/p"
81 sed -n "\${line}p" < "\$1".tmp
82 sed -n "\${line}s/^pick/\$action/p" < "\$1".tmp >> "\$1"
88 chmod a
+x fake-editor.sh
89 VISUAL
="$(pwd)/fake-editor.sh"
92 test_expect_success
'no changes are a nop' '
94 test $(git rev-parse I) = $(git rev-parse HEAD)
97 test_expect_success
'rebase on top of a non-conflicting commit' '
98 git checkout branch1 &&
99 git tag original-branch1 &&
100 git rebase -i branch2 &&
101 test file6 = $(git diff --name-only original-branch1) &&
102 test $(git rev-parse I) = $(git rev-parse HEAD~2)
105 test_expect_success
'reflog for the branch shows state before rebase' '
106 test $(git rev-parse branch1@{1}) = $(git rev-parse original-branch1)
109 test_expect_success
'exchange two commits' '
110 FAKE_LINES="2 1" git rebase -i HEAD~2 &&
111 test H = $(git cat-file commit HEAD^ | tail -n 1) &&
112 test G = $(git cat-file commit HEAD | tail -n 1)
116 diff --git a/file1 b/file1
117 index e69de29..00750ed 100644
129 >>>>>>> b7ca976... G:file1
132 test_expect_success
'stop on conflicting pick' '
133 git tag new-branch1 &&
134 ! git rebase -i master &&
135 diff -u expect .git/.dotest-merge/patch &&
136 diff -u expect2 file1 &&
137 test 4 = $(grep -v "^#" < .git/.dotest-merge/done | wc -l) &&
138 test 0 = $(grep -v "^#" < .git/.dotest-merge/todo | wc -l)
141 test_expect_success
'abort' '
142 git rebase --abort &&
143 test $(git rev-parse new-branch1) = $(git rev-parse HEAD) &&
144 ! test -d .git/.dotest-merge
147 test_expect_success
'retain authorship' '
151 GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
153 git rebase -i --onto master HEAD^ &&
154 git show HEAD | grep "^Author: Twerp Snog"
157 test_expect_success
'squash' '
158 git reset --hard twerp &&
161 GIT_AUTHOR_NAME="Nitfol" git commit -m "nitfol" file7 &&
162 echo "******************************" &&
163 FAKE_LINES="1 squash 2" git rebase -i --onto master HEAD~2 &&
164 test B = $(cat file7) &&
165 test $(git rev-parse HEAD^) = $(git rev-parse master)
168 test_expect_success
'retain authorship when squashing' '
169 git show HEAD | grep "^Author: Nitfol"
172 test_expect_success
'preserve merges with -p' '
173 git checkout -b to-be-preserved master^ &&
174 : > unrelated-file &&
175 git add unrelated-file &&
177 git commit -m "unrelated" &&
178 git checkout -b to-be-rebased master &&
181 git commit -m J file1 &&
183 git merge to-be-preserved &&
186 git commit -m K file1 &&
188 git rebase -i -p --onto branch1 master &&
189 test $(git rev-parse HEAD^^2) = $(git rev-parse to-be-preserved) &&
190 test $(git rev-parse HEAD~3) = $(git rev-parse branch1) &&
191 test $(git show HEAD:file1) = C &&
192 test $(git show HEAD~2:file1) = B
195 test_expect_success
'--continue tries to commit' '
197 ! git rebase -i --onto new-branch1 HEAD^ &&
198 echo resolved > file1 &&
200 FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue &&
201 test $(git rev-parse HEAD^) = $(git rev-parse new-branch1) &&
202 git show HEAD | grep chouette
205 test_expect_success
'verbose flag is heeded, even after --continue' '
206 git reset --hard HEAD@{1} &&
208 ! git rebase -v -i --onto new-branch1 HEAD^ &&
209 echo resolved > file1 &&
211 git rebase --continue > output &&
212 grep "^ file1 | 2 +-$" output