pull: don't warn if pull.ff has been set
[git/debian.git] / t / t3402-rebase-merge.sh
blob6e032716a687a3cd64b37683c67d3a476f06287f
1 #!/bin/sh
3 # Copyright (c) 2006 Junio C Hamano
6 test_description='git rebase --merge test'
8 . ./test-lib.sh
10 T="A quick brown fox
11 jumps over the lazy dog."
12 for i in 1 2 3 4 5 6 7 8 9 10
14 echo "$i $T"
15 done >original
17 test_expect_success setup '
18 git add original &&
19 git commit -m"initial" &&
20 git branch side &&
21 echo "11 $T" >>original &&
22 git commit -a -m"master updates a bit." &&
24 echo "12 $T" >>original &&
25 git commit -a -m"master updates a bit more." &&
27 git checkout side &&
28 (echo "0 $T" && cat original) >renamed &&
29 git add renamed &&
30 git update-index --force-remove original &&
31 git commit -a -m"side renames and edits." &&
33 tr "[a-z]" "[A-Z]" <original >newfile &&
34 git add newfile &&
35 git commit -a -m"side edits further." &&
36 git branch second-side &&
38 tr "[a-m]" "[A-M]" <original >newfile &&
39 rm -f original &&
40 git commit -a -m"side edits once again." &&
42 git branch test-rebase side &&
43 git branch test-rebase-pick side &&
44 git branch test-reference-pick side &&
45 git branch test-conflicts side &&
46 git checkout -b test-merge side
49 test_expect_success 'reference merge' '
50 git merge -s recursive -m "reference merge" master
53 PRE_REBASE=$(git rev-parse test-rebase)
54 test_expect_success rebase '
55 git checkout test-rebase &&
56 GIT_TRACE=1 git rebase --merge master
59 test_expect_success 'test-rebase@{1} is pre rebase' '
60 test $PRE_REBASE = $(git rev-parse test-rebase@{1})
63 test_expect_success 'merge and rebase should match' '
64 git diff-tree -r test-rebase test-merge >difference &&
65 if test -s difference
66 then
67 cat difference
68 (exit 1)
69 else
70 echo happy
74 test_expect_success 'rebase the other way' '
75 git reset --hard master &&
76 git rebase --merge side
79 test_expect_success 'rebase -Xtheirs' '
80 git checkout -b conflicting master~2 &&
81 echo "AB $T" >> original &&
82 git commit -mconflicting original &&
83 git rebase -Xtheirs master &&
84 grep AB original &&
85 ! grep 11 original
88 test_expect_success 'rebase -Xtheirs from orphan' '
89 git checkout --orphan orphan-conflicting master~2 &&
90 echo "AB $T" >> original &&
91 git commit -morphan-conflicting original &&
92 git rebase -Xtheirs master &&
93 grep AB original &&
94 ! grep 11 original
97 test_expect_success 'merge and rebase should match' '
98 git diff-tree -r test-rebase test-merge >difference &&
99 if test -s difference
100 then
101 cat difference
102 (exit 1)
103 else
104 echo happy
108 test_expect_success 'picking rebase' '
109 git reset --hard side &&
110 git rebase --merge --onto master side^^ &&
111 mb=$(git merge-base master HEAD) &&
112 if test "$mb" = "$(git rev-parse master)"
113 then
114 echo happy
115 else
116 git show-branch
117 (exit 1)
118 fi &&
119 f=$(git diff-tree --name-only HEAD^ HEAD) &&
120 g=$(git diff-tree --name-only HEAD^^ HEAD^) &&
121 case "$f,$g" in
122 newfile,newfile)
123 echo happy ;;
125 echo "$f"
126 echo "$g"
127 (exit 1)
128 esac
131 test_expect_success 'rebase -s funny -Xopt' '
132 test_when_finished "rm -fr test-bin funny.was.run" &&
133 mkdir test-bin &&
134 cat >test-bin/git-merge-funny <<-EOF &&
135 #!$SHELL_PATH
136 case "\$1" in --opt) ;; *) exit 2 ;; esac
137 shift &&
138 >funny.was.run &&
139 exec git merge-recursive "\$@"
141 chmod +x test-bin/git-merge-funny &&
142 git reset --hard &&
143 git checkout -b test-funny master^ &&
144 test_commit funny &&
146 PATH=./test-bin:$PATH &&
147 git rebase -s funny -Xopt master
148 ) &&
149 test -f funny.was.run
152 test_expect_success 'rebase --skip works with two conflicts in a row' '
153 git checkout second-side &&
154 tr "[A-Z]" "[a-z]" <newfile >tmp &&
155 mv tmp newfile &&
156 git commit -a -m"edit conflicting with side" &&
157 tr "[d-f]" "[D-F]" <newfile >tmp &&
158 mv tmp newfile &&
159 git commit -a -m"another edit conflicting with side" &&
160 test_must_fail git rebase --merge test-conflicts &&
161 test_must_fail git rebase --skip &&
162 git rebase --skip
165 test_expect_success '--reapply-cherry-picks' '
166 git init repo &&
168 # O(1-10) -- O(1-11) -- O(0-10) master
170 # -- O(1-11) -- O(1-12) otherbranch
172 printf "Line %d\n" $(test_seq 1 10) >repo/file.txt &&
173 git -C repo add file.txt &&
174 git -C repo commit -m "base commit" &&
176 printf "Line %d\n" $(test_seq 1 11) >repo/file.txt &&
177 git -C repo commit -a -m "add 11" &&
179 printf "Line %d\n" $(test_seq 0 10) >repo/file.txt &&
180 git -C repo commit -a -m "add 0 delete 11" &&
182 git -C repo checkout -b otherbranch HEAD^^ &&
183 printf "Line %d\n" $(test_seq 1 11) >repo/file.txt &&
184 git -C repo commit -a -m "add 11 in another branch" &&
186 printf "Line %d\n" $(test_seq 1 12) >repo/file.txt &&
187 git -C repo commit -a -m "add 12 in another branch" &&
189 # Regular rebase fails, because the 1-11 commit is deduplicated
190 test_must_fail git -C repo rebase --merge master 2> err &&
191 test_i18ngrep "error: could not apply.*add 12 in another branch" err &&
192 git -C repo rebase --abort &&
194 # With --reapply-cherry-picks, it works
195 git -C repo rebase --merge --reapply-cherry-picks master
198 test_expect_success '--reapply-cherry-picks refrains from reading unneeded blobs' '
199 git init server &&
201 # O(1-10) -- O(1-11) -- O(1-12) master
203 # -- O(0-10) otherbranch
205 printf "Line %d\n" $(test_seq 1 10) >server/file.txt &&
206 git -C server add file.txt &&
207 git -C server commit -m "merge base" &&
209 printf "Line %d\n" $(test_seq 1 11) >server/file.txt &&
210 git -C server commit -a -m "add 11" &&
212 printf "Line %d\n" $(test_seq 1 12) >server/file.txt &&
213 git -C server commit -a -m "add 12" &&
215 git -C server checkout -b otherbranch HEAD^^ &&
216 printf "Line %d\n" $(test_seq 0 10) >server/file.txt &&
217 git -C server commit -a -m "add 0" &&
219 test_config -C server uploadpack.allowfilter 1 &&
220 test_config -C server uploadpack.allowanysha1inwant 1 &&
222 git clone --filter=blob:none "file://$(pwd)/server" client &&
223 git -C client checkout origin/master &&
224 git -C client checkout origin/otherbranch &&
226 # Sanity check to ensure that the blobs from the merge base and "add
227 # 11" are missing
228 git -C client rev-list --objects --all --missing=print >missing_list &&
229 MERGE_BASE_BLOB=$(git -C server rev-parse master^^:file.txt) &&
230 ADD_11_BLOB=$(git -C server rev-parse master^:file.txt) &&
231 grep "[?]$MERGE_BASE_BLOB" missing_list &&
232 grep "[?]$ADD_11_BLOB" missing_list &&
234 git -C client rebase --merge --reapply-cherry-picks origin/master &&
236 # The blob from the merge base had to be fetched, but not "add 11"
237 git -C client rev-list --objects --all --missing=print >missing_list &&
238 ! grep "[?]$MERGE_BASE_BLOB" missing_list &&
239 grep "[?]$ADD_11_BLOB" missing_list
242 test_done