Merge branch 'l10n/zh_TW/220113' of github.com:l10n-tw/git-po
[alt-git.git] / t / t3412-rebase-root.sh
blob19c6f4acbf6c8a2872da776e586b327639258901
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-lib.sh
12 log_with_names () {
13 git rev-list --topo-order --parents --pretty="tformat:%s" HEAD |
14 git name-rev --stdin --name-only --refs=refs/heads/$1
18 test_expect_success 'prepare repository' '
19 test_commit 1 A &&
20 test_commit 2 A &&
21 git symbolic-ref HEAD refs/heads/other &&
22 rm .git/index &&
23 test_commit 3 B &&
24 test_commit 1b A 1 &&
25 test_commit 4 B
28 test_expect_success 'rebase --root fails with too many args' '
29 git checkout -B fail other &&
30 test_must_fail git rebase --onto main --root fail fail
33 test_expect_success 'setup pre-rebase hook' '
34 mkdir -p .git/hooks &&
35 cat >.git/hooks/pre-rebase <<EOF &&
36 #!$SHELL_PATH
37 echo "\$1,\$2" >.git/PRE-REBASE-INPUT
38 EOF
39 chmod +x .git/hooks/pre-rebase
41 cat > expect <<EOF
46 EOF
48 test_expect_success 'rebase --root --onto <newbase>' '
49 git checkout -b work other &&
50 git rebase --root --onto main &&
51 git log --pretty=tformat:"%s" > rebased &&
52 test_cmp expect rebased
55 test_expect_success 'pre-rebase got correct input (1)' '
56 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
59 test_expect_success 'rebase --root --onto <newbase> <branch>' '
60 git branch work2 other &&
61 git rebase --root --onto main work2 &&
62 git log --pretty=tformat:"%s" > rebased2 &&
63 test_cmp expect rebased2
66 test_expect_success 'pre-rebase got correct input (2)' '
67 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,work2
70 test_expect_success 'rebase -i --root --onto <newbase>' '
71 git checkout -b work3 other &&
72 git rebase -i --root --onto main &&
73 git log --pretty=tformat:"%s" > rebased3 &&
74 test_cmp expect rebased3
77 test_expect_success 'pre-rebase got correct input (3)' '
78 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
81 test_expect_success 'rebase -i --root --onto <newbase> <branch>' '
82 git branch work4 other &&
83 git rebase -i --root --onto main work4 &&
84 git log --pretty=tformat:"%s" > rebased4 &&
85 test_cmp expect rebased4
88 test_expect_success 'pre-rebase got correct input (4)' '
89 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,work4
92 test_expect_success 'set up merge history' '
93 git checkout other^ &&
94 git checkout -b side &&
95 test_commit 5 C &&
96 git checkout other &&
97 git merge side
100 cat > expect-side <<'EOF'
101 commit work6 work6~1 work6^2
102 Merge branch 'side' into other
103 commit work6^2 work6~2
105 commit work6~1 work6~2
107 commit work6~2 work6~3
109 commit work6~3 work6~4
111 commit work6~4
115 test_expect_success 'set up second root and merge' '
116 git symbolic-ref HEAD refs/heads/third &&
117 rm .git/index &&
118 rm A B C &&
119 test_commit 6 D &&
120 git checkout other &&
121 git merge --allow-unrelated-histories third
124 cat > expect-third <<'EOF'
125 commit work7 work7~1 work7^2
126 Merge branch 'third' into other
127 commit work7^2 work7~4
129 commit work7~1 work7~2 work7~1^2
130 Merge branch 'side' into other
131 commit work7~1^2 work7~3
133 commit work7~2 work7~3
135 commit work7~3 work7~4
137 commit work7~4 work7~5
139 commit work7~5
143 test_expect_success 'setup pre-rebase hook that fails' '
144 mkdir -p .git/hooks &&
145 cat >.git/hooks/pre-rebase <<EOF &&
146 #!$SHELL_PATH
147 false
149 chmod +x .git/hooks/pre-rebase
152 test_expect_success 'pre-rebase hook stops rebase' '
153 git checkout -b stops1 other &&
154 test_must_fail git rebase --root --onto main &&
155 test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops1 &&
156 test 0 = $(git rev-list other...stops1 | wc -l)
159 test_expect_success 'pre-rebase hook stops rebase -i' '
160 git checkout -b stops2 other &&
161 test_must_fail git rebase --root --onto main &&
162 test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops2 &&
163 test 0 = $(git rev-list other...stops2 | wc -l)
166 test_expect_success 'remove pre-rebase hook' '
167 rm -f .git/hooks/pre-rebase
170 test_expect_success 'set up a conflict' '
171 git checkout main &&
172 echo conflict > B &&
173 git add B &&
174 git commit -m conflict
177 test_expect_success 'rebase --root with conflict (first part)' '
178 git checkout -b conflict1 other &&
179 test_must_fail git rebase --root --onto main &&
180 git ls-files -u | grep "B$"
183 test_expect_success 'fix the conflict' '
184 echo 3 > B &&
185 git add B
188 cat > expect-conflict <<EOF
193 conflict
198 test_expect_success 'rebase --root with conflict (second part)' '
199 git rebase --continue &&
200 git log --pretty=tformat:"%s" > conflict1 &&
201 test_cmp expect-conflict conflict1
204 test_expect_success 'rebase -i --root with conflict (first part)' '
205 git checkout -b conflict2 other &&
206 test_must_fail git rebase -i --root --onto main &&
207 git ls-files -u | grep "B$"
210 test_expect_success 'fix the conflict' '
211 echo 3 > B &&
212 git add B
215 test_expect_success 'rebase -i --root with conflict (second part)' '
216 git rebase --continue &&
217 git log --pretty=tformat:"%s" > conflict2 &&
218 test_cmp expect-conflict conflict2
221 cat >expect-conflict-p <<\EOF
222 commit conflict3 conflict3~1 conflict3^2
223 Merge branch 'third' into other
224 commit conflict3^2 conflict3~4
226 commit conflict3~1 conflict3~2 conflict3~1^2
227 Merge branch 'side' into other
228 commit conflict3~1^2 conflict3~3
230 commit conflict3~2 conflict3~3
232 commit conflict3~3 conflict3~4
234 commit conflict3~4 conflict3~5
235 conflict
236 commit conflict3~5 conflict3~6
238 commit conflict3~6
242 test_expect_success 'fix the conflict' '
243 echo 3 > B &&
244 git add B
247 test_done