]>
Commit | Line | Data |
---|---|---|
1b1dce4b JS |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2007 Johannes E. Schindelin | |
4 | # | |
5 | ||
6 | test_description='git rebase interactive | |
7 | ||
8 | This test runs git rebase "interactively", by faking an edit, and verifies | |
9 | that the result still makes sense. | |
10 | ' | |
11 | . ./test-lib.sh | |
12 | ||
13 | # set up two branches like this: | |
14 | # | |
15 | # A - B - C - D - E | |
16 | # \ | |
17 | # F - G - H | |
18 | # \ | |
19 | # I | |
20 | # | |
21 | # where B, D and G touch the same file. | |
22 | ||
23 | test_expect_success 'setup' ' | |
24 | : > file1 && | |
25 | git add file1 && | |
26 | test_tick && | |
27 | git commit -m A && | |
28 | git tag A && | |
29 | echo 1 > file1 && | |
30 | test_tick && | |
31 | git commit -m B file1 && | |
32 | : > file2 && | |
33 | git add file2 && | |
34 | test_tick && | |
35 | git commit -m C && | |
36 | echo 2 > file1 && | |
37 | test_tick && | |
38 | git commit -m D file1 && | |
39 | : > file3 && | |
40 | git add file3 && | |
41 | test_tick && | |
42 | git commit -m E && | |
43 | git checkout -b branch1 A && | |
44 | : > file4 && | |
45 | git add file4 && | |
46 | test_tick && | |
47 | git commit -m F && | |
48 | git tag F && | |
49 | echo 3 > file1 && | |
50 | test_tick && | |
51 | git commit -m G file1 && | |
52 | : > file5 && | |
53 | git add file5 && | |
54 | test_tick && | |
55 | git commit -m H && | |
56 | git checkout -b branch2 F && | |
57 | : > file6 && | |
58 | git add file6 && | |
59 | test_tick && | |
60 | git commit -m I && | |
61 | git tag I | |
62 | ' | |
63 | ||
64 | cat > fake-editor.sh << EOF | |
65 | #!/bin/sh | |
66 | test "\$1" = .git/COMMIT_EDITMSG && exit | |
67 | test -z "\$FAKE_LINES" && exit | |
68 | grep -v "^#" < "\$1" > "\$1".tmp | |
69 | rm "\$1" | |
70 | cat "\$1".tmp | |
71 | action=pick | |
72 | for line in \$FAKE_LINES; do | |
73 | case \$line in | |
74 | squash) | |
75 | action="\$line";; | |
76 | *) | |
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" | |
80 | action=pick;; | |
81 | esac | |
82 | done | |
83 | EOF | |
84 | ||
85 | chmod a+x fake-editor.sh | |
86 | VISUAL="$(pwd)/fake-editor.sh" | |
87 | export VISUAL | |
88 | ||
89 | test_expect_success 'no changes are a nop' ' | |
90 | git rebase -i F && | |
91 | test $(git rev-parse I) = $(git rev-parse HEAD) | |
92 | ' | |
93 | ||
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) | |
100 | ' | |
101 | ||
68a163c9 JS |
102 | test_expect_success 'reflog for the branch shows state before rebase' ' |
103 | test $(git rev-parse branch1@{1}) = $(git rev-parse original-branch1) | |
104 | ' | |
105 | ||
1b1dce4b JS |
106 | test_expect_success 'exchange two commits' ' |
107 | FAKE_LINES="2 1" git rebase -i HEAD~2 && | |
108 | test H = $(git cat-file commit HEAD^ | tail -n 1) && | |
109 | test G = $(git cat-file commit HEAD | tail -n 1) | |
110 | ' | |
111 | ||
112 | cat > expect << EOF | |
113 | diff --git a/file1 b/file1 | |
114 | index e69de29..00750ed 100644 | |
115 | --- a/file1 | |
116 | +++ b/file1 | |
117 | @@ -0,0 +1 @@ | |
118 | +3 | |
119 | EOF | |
120 | ||
121 | cat > expect2 << EOF | |
122 | <<<<<<< HEAD:file1 | |
123 | 2 | |
124 | ======= | |
125 | 3 | |
126 | >>>>>>> b7ca976... G:file1 | |
127 | EOF | |
128 | ||
129 | test_expect_success 'stop on conflicting pick' ' | |
130 | git tag new-branch1 && | |
131 | ! git rebase -i master && | |
132 | diff -u expect .git/.dotest-merge/patch && | |
133 | diff -u expect2 file1 && | |
134 | test 4 = $(grep -v "^#" < .git/.dotest-merge/done | wc -l) && | |
135 | test 0 = $(grep -v "^#" < .git/.dotest-merge/todo | wc -l) | |
136 | ' | |
137 | ||
138 | test_expect_success 'abort' ' | |
139 | git rebase --abort && | |
140 | test $(git rev-parse new-branch1) = $(git rev-parse HEAD) && | |
141 | ! test -d .git/.dotest-merge | |
142 | ' | |
143 | ||
144 | test_expect_success 'retain authorship' ' | |
145 | echo A > file7 && | |
146 | git add file7 && | |
c54b7817 | 147 | test_tick && |
1b1dce4b JS |
148 | GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" && |
149 | git tag twerp && | |
150 | git rebase -i --onto master HEAD^ && | |
151 | git show HEAD | grep "^Author: Twerp Snog" | |
152 | ' | |
153 | ||
154 | test_expect_success 'squash' ' | |
155 | git reset --hard twerp && | |
156 | echo B > file7 && | |
c54b7817 | 157 | test_tick && |
1b1dce4b JS |
158 | GIT_AUTHOR_NAME="Nitfol" git commit -m "nitfol" file7 && |
159 | echo "******************************" && | |
160 | FAKE_LINES="1 squash 2" git rebase -i --onto master HEAD~2 && | |
161 | test B = $(cat file7) && | |
162 | test $(git rev-parse HEAD^) = $(git rev-parse master) | |
163 | ' | |
164 | ||
165 | test_expect_success 'retain authorship when squashing' ' | |
166 | git show HEAD | grep "^Author: Nitfol" | |
167 | ' | |
168 | ||
f09c9b8c JS |
169 | test_expect_success 'preserve merges with -p' ' |
170 | git checkout -b to-be-preserved master^ && | |
171 | : > unrelated-file && | |
172 | git add unrelated-file && | |
173 | test_tick && | |
174 | git commit -m "unrelated" && | |
175 | git checkout -b to-be-rebased master && | |
176 | echo B > file1 && | |
177 | test_tick && | |
178 | git commit -m J file1 && | |
179 | test_tick && | |
180 | git merge to-be-preserved && | |
181 | echo C > file1 && | |
182 | test_tick && | |
183 | git commit -m K file1 && | |
184 | git rebase -i -p --onto branch1 master && | |
185 | test $(git rev-parse HEAD^^2) = $(git rev-parse to-be-preserved) && | |
186 | test $(git rev-parse HEAD~3) = $(git rev-parse branch1) && | |
187 | test $(git show HEAD:file1) = C && | |
188 | test $(git show HEAD~2:file1) = B | |
189 | ' | |
190 | ||
1b1dce4b | 191 | test_done |