Code

Merge branch 'am/maint-push-doc'
[git.git] / t / t3412-rebase-root.sh
1 #!/bin/sh
3 test_description='git rebase --root
5 Tests if git rebase --root --onto <newparent> can rebase the root commit.
6 '
7 . ./test-lib.sh
9 # we always run the interactive rebases unchanged, so just disable the editor
10 GIT_EDITOR=:
11 export GIT_EDITOR
13 test_expect_success 'prepare repository' '
14         test_commit 1 A &&
15         test_commit 2 A &&
16         git symbolic-ref HEAD refs/heads/other &&
17         rm .git/index &&
18         test_commit 3 B &&
19         test_commit 1b A 1 &&
20         test_commit 4 B
21 '
23 test_expect_success 'rebase --root expects --onto' '
24         test_must_fail git rebase --root
25 '
27 test_expect_success 'setup pre-rebase hook' '
28         mkdir -p .git/hooks &&
29         cat >.git/hooks/pre-rebase <<EOF &&
30 #!$SHELL_PATH
31 echo "\$1,\$2" >.git/PRE-REBASE-INPUT
32 EOF
33         chmod +x .git/hooks/pre-rebase
34 '
35 cat > expect <<EOF
36 4
37 3
38 2
39 1
40 EOF
42 test_expect_success 'rebase --root --onto <newbase>' '
43         git checkout -b work &&
44         git rebase --root --onto master &&
45         git log --pretty=tformat:"%s" > rebased &&
46         test_cmp expect rebased
47 '
49 test_expect_success 'pre-rebase got correct input (1)' '
50         test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
51 '
53 test_expect_success 'rebase --root --onto <newbase> <branch>' '
54         git branch work2 other &&
55         git rebase --root --onto master work2 &&
56         git log --pretty=tformat:"%s" > rebased2 &&
57         test_cmp expect rebased2
58 '
60 test_expect_success 'pre-rebase got correct input (2)' '
61         test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,work2
62 '
64 test_expect_success 'rebase -i --root --onto <newbase>' '
65         git checkout -b work3 other &&
66         git rebase -i --root --onto master &&
67         git log --pretty=tformat:"%s" > rebased3 &&
68         test_cmp expect rebased3
69 '
71 test_expect_success 'pre-rebase got correct input (3)' '
72         test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
73 '
75 test_expect_success 'rebase -i --root --onto <newbase> <branch>' '
76         git branch work4 other &&
77         git rebase -i --root --onto master work4 &&
78         git log --pretty=tformat:"%s" > rebased4 &&
79         test_cmp expect rebased4
80 '
82 test_expect_success 'pre-rebase got correct input (4)' '
83         test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,work4
84 '
86 test_expect_success 'rebase -i -p with linear history' '
87         git checkout -b work5 other &&
88         git rebase -i -p --root --onto master &&
89         git log --pretty=tformat:"%s" > rebased5 &&
90         test_cmp expect rebased5
91 '
93 test_expect_success 'pre-rebase got correct input (5)' '
94         test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
95 '
97 test_expect_success 'set up merge history' '
98         git checkout other^ &&
99         git checkout -b side &&
100         test_commit 5 C &&
101         git checkout other &&
102         git merge side
105 sed 's/#/ /g' > expect-side <<'EOF'
106 *   Merge branch 'side' into other
107 |\##
108 | * 5
109 * | 4
110 |/##
111 * 3
112 * 2
113 * 1
114 EOF
116 test_expect_success 'rebase -i -p with merge' '
117         git checkout -b work6 other &&
118         git rebase -i -p --root --onto master &&
119         git log --graph --topo-order --pretty=tformat:"%s" > rebased6 &&
120         test_cmp expect-side rebased6
123 test_expect_success 'set up second root and merge' '
124         git symbolic-ref HEAD refs/heads/third &&
125         rm .git/index &&
126         rm A B C &&
127         test_commit 6 D &&
128         git checkout other &&
129         git merge third
132 sed 's/#/ /g' > expect-third <<'EOF'
133 *   Merge branch 'third' into other
134 |\##
135 | * 6
136 * |   Merge branch 'side' into other
137 |\ \##
138 | * | 5
139 * | | 4
140 |/ /##
141 * | 3
142 |/##
143 * 2
144 * 1
145 EOF
147 test_expect_success 'rebase -i -p with two roots' '
148         git checkout -b work7 other &&
149         git rebase -i -p --root --onto master &&
150         git log --graph --topo-order --pretty=tformat:"%s" > rebased7 &&
151         test_cmp expect-third rebased7
154 test_expect_success 'setup pre-rebase hook that fails' '
155         mkdir -p .git/hooks &&
156         cat >.git/hooks/pre-rebase <<EOF &&
157 #!$SHELL_PATH
158 false
159 EOF
160         chmod +x .git/hooks/pre-rebase
163 test_expect_success 'pre-rebase hook stops rebase' '
164         git checkout -b stops1 other &&
165         test_must_fail git rebase --root --onto master &&
166         test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops1
167         test 0 = $(git rev-list other...stops1 | wc -l)
170 test_expect_success 'pre-rebase hook stops rebase -i' '
171         git checkout -b stops2 other &&
172         test_must_fail git rebase --root --onto master &&
173         test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops2
174         test 0 = $(git rev-list other...stops2 | wc -l)
177 test_expect_success 'remove pre-rebase hook' '
178         rm -f .git/hooks/pre-rebase
181 test_expect_success 'set up a conflict' '
182         git checkout master &&
183         echo conflict > B &&
184         git add B &&
185         git commit -m conflict
188 test_expect_success 'rebase --root with conflict (first part)' '
189         git checkout -b conflict1 other &&
190         test_must_fail git rebase --root --onto master &&
191         git ls-files -u | grep "B$"
194 test_expect_success 'fix the conflict' '
195         echo 3 > B &&
196         git add B
199 cat > expect-conflict <<EOF
204 conflict
207 EOF
209 test_expect_success 'rebase --root with conflict (second part)' '
210         git rebase --continue &&
211         git log --pretty=tformat:"%s" > conflict1 &&
212         test_cmp expect-conflict conflict1
215 test_expect_success 'rebase -i --root with conflict (first part)' '
216         git checkout -b conflict2 other &&
217         test_must_fail git rebase -i --root --onto master &&
218         git ls-files -u | grep "B$"
221 test_expect_success 'fix the conflict' '
222         echo 3 > B &&
223         git add B
226 test_expect_success 'rebase -i --root with conflict (second part)' '
227         git rebase --continue &&
228         git log --pretty=tformat:"%s" > conflict2 &&
229         test_cmp expect-conflict conflict2
232 cat >expect-conflict-p <<\EOF
233 commit conflict3 conflict3~1 conflict3^2
234 Merge branch 'third' into other
235 commit conflict3^2 conflict3~4
237 commit conflict3~1 conflict3~2 conflict3~1^2
238 Merge branch 'side' into other
239 commit conflict3~1^2 conflict3~3
241 commit conflict3~2 conflict3~3
243 commit conflict3~3 conflict3~4
245 commit conflict3~4 conflict3~5
246 conflict
247 commit conflict3~5 conflict3~6
249 commit conflict3~6
251 EOF
253 test_expect_success 'rebase -i -p --root with conflict (first part)' '
254         git checkout -b conflict3 other &&
255         test_must_fail git rebase -i -p --root --onto master &&
256         git ls-files -u | grep "B$"
259 test_expect_success 'fix the conflict' '
260         echo 3 > B &&
261         git add B
264 test_expect_success 'rebase -i -p --root with conflict (second part)' '
265         git rebase --continue &&
266         git rev-list --topo-order --parents --pretty="tformat:%s" HEAD |
267         git name-rev --stdin --name-only --refs=refs/heads/conflict3 >out &&
268         test_cmp expect-conflict-p out
271 test_done