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 && exit
67 test -z "\$FAKE_LINES" && exit
68 grep -v "^#" < "\$1" > "\$1".tmp
72 for line in \$FAKE_LINES; do
77 echo sed -n "\${line}s/^pick/\$action/p"
78 sed -n "\${line}p" < "\$1".tmp
79 sed -n "\${line}s/^pick/\$action/p" < "\$1".tmp >> "\$1"
85 chmod a
+x fake-editor.sh
86 VISUAL
="$(pwd)/fake-editor.sh"
89 test_expect_success
'no changes are a nop' '
91 test $(git rev-parse I) = $(git rev-parse HEAD)
94 test_expect_success
'rebase on top of a non-conflicting commit' '
95 git checkout branch1 &&
96 git tag original-branch1 &&
97 git rebase -i branch2 &&
98 test file6 = $(git diff --name-only original-branch1) &&
99 test $(git rev-parse I) = $(git rev-parse HEAD~2)
102 test_expect_success
'exchange two commits' '
103 FAKE_LINES="2 1" git rebase -i HEAD~2 &&
104 test H = $(git cat-file commit HEAD^ | tail -n 1) &&
105 test G = $(git cat-file commit HEAD | tail -n 1)
109 diff --git a/file1 b/file1
110 index e69de29..00750ed 100644
122 >>>>>>> b7ca976... G:file1
125 test_expect_success
'stop on conflicting pick' '
126 git tag new-branch1 &&
127 ! git rebase -i master &&
128 diff -u expect .git/.dotest-merge/patch &&
129 diff -u expect2 file1 &&
130 test 4 = $(grep -v "^#" < .git/.dotest-merge/done | wc -l) &&
131 test 0 = $(grep -v "^#" < .git/.dotest-merge/todo | wc -l)
134 test_expect_success
'abort' '
135 git rebase --abort &&
136 test $(git rev-parse new-branch1) = $(git rev-parse HEAD) &&
137 ! test -d .git/.dotest-merge
140 test_expect_success
'retain authorship' '
143 GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
145 git rebase -i --onto master HEAD^ &&
146 git show HEAD | grep "^Author: Twerp Snog"
149 test_expect_success
'squash' '
150 git reset --hard twerp &&
152 GIT_AUTHOR_NAME="Nitfol" git commit -m "nitfol" file7 &&
153 echo "******************************" &&
154 FAKE_LINES="1 squash 2" git rebase -i --onto master HEAD~2 &&
155 test B = $(cat file7) &&
156 test $(git rev-parse HEAD^) = $(git rev-parse master)
159 test_expect_success
'retain authorship when squashing' '
160 git show HEAD | grep "^Author: Nitfol"