git-p4: fix typos
[git/gitster.git] / t / t3412-rebase-root.sh
blobe75b3d0e07cb13b5d8b4fd3b83b07c35eeddce49
1 #!/bin/sh
3 test_description='git rebase --root
5 Tests if git rebase --root --onto <newparent> can rebase the root commit.
7 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
8 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10 TEST_PASSES_SANITIZE_LEAK=true
11 . ./test-lib.sh
13 log_with_names () {
14 git rev-list --topo-order --parents --pretty="tformat:%s" HEAD |
15 git name-rev --annotate-stdin --name-only --refs=refs/heads/$1
19 test_expect_success 'prepare repository' '
20 test_commit 1 A &&
21 test_commit 2 A &&
22 git symbolic-ref HEAD refs/heads/other &&
23 rm .git/index &&
24 test_commit 3 B &&
25 test_commit 1b A 1 &&
26 test_commit 4 B
29 test_expect_success 'rebase --root fails with too many args' '
30 git checkout -B fail other &&
31 test_must_fail git rebase --onto main --root fail fail
34 test_expect_success 'setup pre-rebase hook' '
35 test_hook --setup pre-rebase <<-\EOF
36 echo "$1,$2" >.git/PRE-REBASE-INPUT
37 EOF
39 cat > expect <<EOF
44 EOF
46 test_expect_success 'rebase --root --onto <newbase>' '
47 git checkout -b work other &&
48 git rebase --root --onto main &&
49 git log --pretty=tformat:"%s" > rebased &&
50 test_cmp expect rebased
53 test_expect_success 'pre-rebase got correct input (1)' '
54 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
57 test_expect_success 'rebase --root --onto <newbase> <branch>' '
58 git branch work2 other &&
59 git rebase --root --onto main work2 &&
60 git log --pretty=tformat:"%s" > rebased2 &&
61 test_cmp expect rebased2
64 test_expect_success 'pre-rebase got correct input (2)' '
65 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,work2
68 test_expect_success 'rebase -i --root --onto <newbase>' '
69 git checkout -b work3 other &&
70 git rebase -i --root --onto main &&
71 git log --pretty=tformat:"%s" > rebased3 &&
72 test_cmp expect rebased3
75 test_expect_success 'pre-rebase got correct input (3)' '
76 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
79 test_expect_success 'rebase -i --root --onto <newbase> <branch>' '
80 git branch work4 other &&
81 git rebase -i --root --onto main work4 &&
82 git log --pretty=tformat:"%s" > rebased4 &&
83 test_cmp expect rebased4
86 test_expect_success 'pre-rebase got correct input (4)' '
87 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,work4
90 test_expect_success 'set up merge history' '
91 git checkout other^ &&
92 git checkout -b side &&
93 test_commit 5 C &&
94 git checkout other &&
95 git merge side
98 cat > expect-side <<'EOF'
99 commit work6 work6~1 work6^2
100 Merge branch 'side' into other
101 commit work6^2 work6~2
103 commit work6~1 work6~2
105 commit work6~2 work6~3
107 commit work6~3 work6~4
109 commit work6~4
113 test_expect_success 'set up second root and merge' '
114 git symbolic-ref HEAD refs/heads/third &&
115 rm .git/index &&
116 rm A B C &&
117 test_commit 6 D &&
118 git checkout other &&
119 git merge --allow-unrelated-histories third
122 cat > expect-third <<'EOF'
123 commit work7 work7~1 work7^2
124 Merge branch 'third' into other
125 commit work7^2 work7~4
127 commit work7~1 work7~2 work7~1^2
128 Merge branch 'side' into other
129 commit work7~1^2 work7~3
131 commit work7~2 work7~3
133 commit work7~3 work7~4
135 commit work7~4 work7~5
137 commit work7~5
141 test_expect_success 'setup pre-rebase hook that fails' '
142 test_hook --setup --clobber pre-rebase <<-\EOF
143 false
147 test_expect_success 'pre-rebase hook stops rebase' '
148 git checkout -b stops1 other &&
149 test_must_fail git rebase --root --onto main &&
150 test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops1 &&
151 test 0 = $(git rev-list other...stops1 | wc -l)
154 test_expect_success 'pre-rebase hook stops rebase -i' '
155 git checkout -b stops2 other &&
156 test_must_fail git rebase --root --onto main &&
157 test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops2 &&
158 test 0 = $(git rev-list other...stops2 | wc -l)
161 test_expect_success 'remove pre-rebase hook' '
162 rm -f .git/hooks/pre-rebase
165 test_expect_success 'set up a conflict' '
166 git checkout main &&
167 echo conflict > B &&
168 git add B &&
169 git commit -m conflict
172 test_expect_success 'rebase --root with conflict (first part)' '
173 git checkout -b conflict1 other &&
174 test_must_fail git rebase --root --onto main &&
175 git ls-files -u | grep "B$"
178 test_expect_success 'fix the conflict' '
179 echo 3 > B &&
180 git add B
183 cat > expect-conflict <<EOF
188 conflict
193 test_expect_success 'rebase --root with conflict (second part)' '
194 git rebase --continue &&
195 git log --pretty=tformat:"%s" > conflict1 &&
196 test_cmp expect-conflict conflict1
199 test_expect_success 'rebase -i --root with conflict (first part)' '
200 git checkout -b conflict2 other &&
201 test_must_fail git rebase -i --root --onto main &&
202 git ls-files -u | grep "B$"
205 test_expect_success 'fix the conflict' '
206 echo 3 > B &&
207 git add B
210 test_expect_success 'rebase -i --root with conflict (second part)' '
211 git rebase --continue &&
212 git log --pretty=tformat:"%s" > conflict2 &&
213 test_cmp expect-conflict conflict2
216 cat >expect-conflict-p <<\EOF
217 commit conflict3 conflict3~1 conflict3^2
218 Merge branch 'third' into other
219 commit conflict3^2 conflict3~4
221 commit conflict3~1 conflict3~2 conflict3~1^2
222 Merge branch 'side' into other
223 commit conflict3~1^2 conflict3~3
225 commit conflict3~2 conflict3~3
227 commit conflict3~3 conflict3~4
229 commit conflict3~4 conflict3~5
230 conflict
231 commit conflict3~5 conflict3~6
233 commit conflict3~6
237 test_expect_success 'fix the conflict' '
238 echo 3 > B &&
239 git add B
242 test_done