]>
Commit | Line | Data |
---|---|---|
c3fb0e35 JH |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2006 Junio C Hamano | |
4 | # | |
5 | ||
6 | test_description='git rebase --merge test' | |
7 | ||
d1c02d93 | 8 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
9 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
10 | ||
b571fb98 | 11 | TEST_PASSES_SANITIZE_LEAK=true |
c3fb0e35 JH |
12 | . ./test-lib.sh |
13 | ||
14 | T="A quick brown fox | |
15 | jumps over the lazy dog." | |
16 | for i in 1 2 3 4 5 6 7 8 9 10 | |
17 | do | |
18 | echo "$i $T" | |
19 | done >original | |
20 | ||
21 | test_expect_success setup ' | |
22 | git add original && | |
23 | git commit -m"initial" && | |
24 | git branch side && | |
25 | echo "11 $T" >>original && | |
d1c02d93 | 26 | git commit -a -m"main updates a bit." && |
c3fb0e35 JH |
27 | |
28 | echo "12 $T" >>original && | |
d1c02d93 | 29 | git commit -a -m"main updates a bit more." && |
c3fb0e35 JH |
30 | |
31 | git checkout side && | |
3ea67379 | 32 | (echo "0 $T" && cat original) >renamed && |
c3fb0e35 JH |
33 | git add renamed && |
34 | git update-index --force-remove original && | |
35 | git commit -a -m"side renames and edits." && | |
36 | ||
37 | tr "[a-z]" "[A-Z]" <original >newfile && | |
38 | git add newfile && | |
39 | git commit -a -m"side edits further." && | |
95104c7e | 40 | git branch second-side && |
c3fb0e35 JH |
41 | |
42 | tr "[a-m]" "[A-M]" <original >newfile && | |
43 | rm -f original && | |
44 | git commit -a -m"side edits once again." && | |
45 | ||
46 | git branch test-rebase side && | |
47 | git branch test-rebase-pick side && | |
48 | git branch test-reference-pick side && | |
95104c7e | 49 | git branch test-conflicts side && |
c3fb0e35 JH |
50 | git checkout -b test-merge side |
51 | ' | |
52 | ||
53 | test_expect_success 'reference merge' ' | |
d1c02d93 | 54 | git merge -s recursive -m "reference merge" main |
c3fb0e35 JH |
55 | ' |
56 | ||
6fd2f5e6 | 57 | PRE_REBASE=$(git rev-parse test-rebase) |
c3fb0e35 JH |
58 | test_expect_success rebase ' |
59 | git checkout test-rebase && | |
d1c02d93 | 60 | GIT_TRACE=1 git rebase --merge main |
6fd2f5e6 JS |
61 | ' |
62 | ||
63 | test_expect_success 'test-rebase@{1} is pre rebase' ' | |
64 | test $PRE_REBASE = $(git rev-parse test-rebase@{1}) | |
c3fb0e35 JH |
65 | ' |
66 | ||
67 | test_expect_success 'merge and rebase should match' ' | |
68 | git diff-tree -r test-rebase test-merge >difference && | |
69 | if test -s difference | |
70 | then | |
71 | cat difference | |
77b1d9f3 | 72 | false |
c3fb0e35 JH |
73 | else |
74 | echo happy | |
75 | fi | |
76 | ' | |
77 | ||
78 | test_expect_success 'rebase the other way' ' | |
d1c02d93 | 79 | git reset --hard main && |
c3fb0e35 JH |
80 | git rebase --merge side |
81 | ' | |
82 | ||
93ce190c | 83 | test_expect_success 'rebase -Xtheirs' ' |
d1c02d93 | 84 | git checkout -b conflicting main~2 && |
93ce190c ML |
85 | echo "AB $T" >> original && |
86 | git commit -mconflicting original && | |
d1c02d93 | 87 | git rebase -Xtheirs main && |
93ce190c ML |
88 | grep AB original && |
89 | ! grep 11 original | |
90 | ' | |
91 | ||
79f43447 | 92 | test_expect_success 'rebase -Xtheirs from orphan' ' |
d1c02d93 | 93 | git checkout --orphan orphan-conflicting main~2 && |
79f43447 BW |
94 | echo "AB $T" >> original && |
95 | git commit -morphan-conflicting original && | |
d1c02d93 | 96 | git rebase -Xtheirs main && |
79f43447 BW |
97 | grep AB original && |
98 | ! grep 11 original | |
99 | ' | |
100 | ||
c3fb0e35 JH |
101 | test_expect_success 'merge and rebase should match' ' |
102 | git diff-tree -r test-rebase test-merge >difference && | |
103 | if test -s difference | |
104 | then | |
105 | cat difference | |
77b1d9f3 | 106 | false |
c3fb0e35 JH |
107 | else |
108 | echo happy | |
109 | fi | |
110 | ' | |
111 | ||
112 | test_expect_success 'picking rebase' ' | |
113 | git reset --hard side && | |
d1c02d93 JS |
114 | git rebase --merge --onto main side^^ && |
115 | mb=$(git merge-base main HEAD) && | |
116 | if test "$mb" = "$(git rev-parse main)" | |
c3fb0e35 JH |
117 | then |
118 | echo happy | |
119 | else | |
120 | git show-branch | |
77b1d9f3 | 121 | false |
c3fb0e35 JH |
122 | fi && |
123 | f=$(git diff-tree --name-only HEAD^ HEAD) && | |
124 | g=$(git diff-tree --name-only HEAD^^ HEAD^) && | |
125 | case "$f,$g" in | |
126 | newfile,newfile) | |
127 | echo happy ;; | |
128 | *) | |
129 | echo "$f" | |
130 | echo "$g" | |
77b1d9f3 | 131 | false |
c3fb0e35 JH |
132 | esac |
133 | ' | |
134 | ||
95104c7e | 135 | test_expect_success 'rebase --skip works with two conflicts in a row' ' |
136 | git checkout second-side && | |
137 | tr "[A-Z]" "[a-z]" <newfile >tmp && | |
138 | mv tmp newfile && | |
139 | git commit -a -m"edit conflicting with side" && | |
140 | tr "[d-f]" "[D-F]" <newfile >tmp && | |
141 | mv tmp newfile && | |
142 | git commit -a -m"another edit conflicting with side" && | |
143 | test_must_fail git rebase --merge test-conflicts && | |
144 | test_must_fail git rebase --skip && | |
145 | git rebase --skip | |
146 | ' | |
147 | ||
0fcb4f6b JT |
148 | test_expect_success '--reapply-cherry-picks' ' |
149 | git init repo && | |
150 | ||
d1c02d93 | 151 | # O(1-10) -- O(1-11) -- O(0-10) main |
0fcb4f6b JT |
152 | # \ |
153 | # -- O(1-11) -- O(1-12) otherbranch | |
154 | ||
155 | printf "Line %d\n" $(test_seq 1 10) >repo/file.txt && | |
156 | git -C repo add file.txt && | |
157 | git -C repo commit -m "base commit" && | |
158 | ||
159 | printf "Line %d\n" $(test_seq 1 11) >repo/file.txt && | |
160 | git -C repo commit -a -m "add 11" && | |
161 | ||
162 | printf "Line %d\n" $(test_seq 0 10) >repo/file.txt && | |
163 | git -C repo commit -a -m "add 0 delete 11" && | |
164 | ||
165 | git -C repo checkout -b otherbranch HEAD^^ && | |
166 | printf "Line %d\n" $(test_seq 1 11) >repo/file.txt && | |
167 | git -C repo commit -a -m "add 11 in another branch" && | |
168 | ||
169 | printf "Line %d\n" $(test_seq 1 12) >repo/file.txt && | |
170 | git -C repo commit -a -m "add 12 in another branch" && | |
171 | ||
172 | # Regular rebase fails, because the 1-11 commit is deduplicated | |
d1c02d93 | 173 | test_must_fail git -C repo rebase --merge main 2> err && |
6789275d | 174 | test_grep "error: could not apply.*add 12 in another branch" err && |
0fcb4f6b JT |
175 | git -C repo rebase --abort && |
176 | ||
177 | # With --reapply-cherry-picks, it works | |
d1c02d93 | 178 | git -C repo rebase --merge --reapply-cherry-picks main |
0fcb4f6b JT |
179 | ' |
180 | ||
181 | test_expect_success '--reapply-cherry-picks refrains from reading unneeded blobs' ' | |
182 | git init server && | |
183 | ||
d1c02d93 | 184 | # O(1-10) -- O(1-11) -- O(1-12) main |
0fcb4f6b JT |
185 | # \ |
186 | # -- O(0-10) otherbranch | |
187 | ||
188 | printf "Line %d\n" $(test_seq 1 10) >server/file.txt && | |
189 | git -C server add file.txt && | |
190 | git -C server commit -m "merge base" && | |
191 | ||
192 | printf "Line %d\n" $(test_seq 1 11) >server/file.txt && | |
193 | git -C server commit -a -m "add 11" && | |
194 | ||
195 | printf "Line %d\n" $(test_seq 1 12) >server/file.txt && | |
196 | git -C server commit -a -m "add 12" && | |
197 | ||
198 | git -C server checkout -b otherbranch HEAD^^ && | |
199 | printf "Line %d\n" $(test_seq 0 10) >server/file.txt && | |
200 | git -C server commit -a -m "add 0" && | |
201 | ||
202 | test_config -C server uploadpack.allowfilter 1 && | |
203 | test_config -C server uploadpack.allowanysha1inwant 1 && | |
204 | ||
205 | git clone --filter=blob:none "file://$(pwd)/server" client && | |
d1c02d93 | 206 | git -C client checkout origin/main && |
0fcb4f6b JT |
207 | git -C client checkout origin/otherbranch && |
208 | ||
209 | # Sanity check to ensure that the blobs from the merge base and "add | |
210 | # 11" are missing | |
211 | git -C client rev-list --objects --all --missing=print >missing_list && | |
d1c02d93 JS |
212 | MERGE_BASE_BLOB=$(git -C server rev-parse main^^:file.txt) && |
213 | ADD_11_BLOB=$(git -C server rev-parse main^:file.txt) && | |
0fcb4f6b JT |
214 | grep "[?]$MERGE_BASE_BLOB" missing_list && |
215 | grep "[?]$ADD_11_BLOB" missing_list && | |
216 | ||
d1c02d93 | 217 | git -C client rebase --merge --reapply-cherry-picks origin/main && |
0fcb4f6b JT |
218 | |
219 | # The blob from the merge base had to be fetched, but not "add 11" | |
220 | git -C client rev-list --objects --all --missing=print >missing_list && | |
221 | ! grep "[?]$MERGE_BASE_BLOB" missing_list && | |
222 | grep "[?]$ADD_11_BLOB" missing_list | |
223 | ' | |
224 | ||
c3fb0e35 | 225 | test_done |