3 # Copyright (c) 2005 Junio C Hamano
6 test_description
='Two way merge with read-tree -m $H $M
8 This test tries two-way merge (aka fast forward with carry forward).
10 There is the head (called H) and another commit (called M), which is
11 simply ahead of H. The index and the work tree contains a state that
12 is derived from H, but may also have local changes. This test checks
13 all the combinations described in the two-tree merge "carry forward"
14 rules, found in <Documentation/git-rev-tree.txt>.
16 In the test, these paths are used:
17 bozbar - in H, stays in M, modified from bozbar to gnusto
18 frotz - not in H added in M
19 nitfol - in H, stays in M unmodified
20 rezrov - in H, deleted in M
21 yomin - not in H nor M
25 _x40
='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
26 _x40
="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
29 -e '/^--- /d; /^+++ /d; /^@@ /d;' \
30 -e 's/^\(.[0-7][0-7][0-7][0-7][0-7][0-7]\) '"$_x40"' /\1 X /' "$1"
31 diff -u expected current
35 clean_if_empty
=`git-diff-files "$1"`
36 case "$clean_if_empty" in
37 '') echo "$1: clean" ;;
38 ?
*) echo "$1: dirty" ;;
40 case "$2,$clean_if_empty" in
51 echo nitfol >nitfol &&
52 echo bozbar >bozbar &&
53 echo rezrov >rezrov &&
55 git-update-cache --add nitfol bozbar rezrov &&
56 treeH=`git-write-tree` &&
60 echo gnusto >bozbar &&
61 git-update-cache --add frotz bozbar --force-remove rezrov &&
62 git-ls-files --stage >M.out &&
63 treeM=`git-write-tree` &&
66 git-diff-tree $treeH $treeM'
69 '1, 2, 3 - no carry forward' \
71 git-read-tree -m $treeH $treeM &&
72 git-ls-files --stage >1-3.out &&
74 check_cache_at bozbar dirty &&
75 check_cache_at frotz dirty &&
76 check_cache_at nitfol dirty'
78 echo '+100644 X 0 yomin' >expected
81 '4 - carry forward local addition.' \
83 git-update-cache --add yomin &&
84 git-read-tree -m $treeH $treeM &&
85 git-ls-files --stage >4.out || exit
86 diff --unified=0 M.out 4.out >4diff.out
87 compare_change 4diff.out expected &&
88 check_cache_at yomin clean'
91 '5 - carry forward local addition.' \
94 git-update-cache --add yomin &&
95 echo yomin yomin >yomin &&
96 git-read-tree -m $treeH $treeM &&
97 git-ls-files --stage >5.out || exit
98 diff --unified=0 M.out 5.out >5diff.out
99 compare_change 5diff.out expected &&
100 check_cache_at yomin dirty'
102 test_expect_success \
103 '6 - local addition already has the same.' \
105 git-update-cache --add frotz &&
106 git-read-tree -m $treeH $treeM &&
107 git-ls-files --stage >6.out &&
108 diff --unified=0 M.out 6.out &&
109 check_cache_at frotz clean'
111 test_expect_success \
112 '7 - local addition already has the same.' \
115 git-update-cache --add frotz &&
116 echo frotz frotz >frotz &&
117 git-read-tree -m $treeH $treeM &&
118 git-ls-files --stage >7.out &&
119 diff --unified=0 M.out 7.out &&
120 check_cache_at frotz dirty'
122 test_expect_success \
123 '8 - conflicting addition.' \
125 echo frotz frotz >frotz &&
126 git-update-cache --add frotz &&
127 if git-read-tree -m $treeH $treeM; then false; else :; fi'
129 test_expect_success \
130 '9 - conflicting addition.' \
132 echo frotz frotz >frotz &&
133 git-update-cache --add frotz &&
135 if git-read-tree -m $treeH $treeM; then false; else :; fi'
137 test_expect_success \
138 '10 - path removed.' \
140 echo rezrov >rezrov &&
141 git-update-cache --add rezrov &&
142 git-read-tree -m $treeH $treeM &&
143 git-ls-files --stage >10.out &&
146 test_expect_success \
147 '11 - dirty path removed.' \
149 echo rezrov >rezrov &&
150 git-update-cache --add rezrov &&
151 echo rezrov rezrov >rezrov &&
152 if git-read-tree -m $treeH $treeM; then false; else :; fi'
154 test_expect_success \
155 '12 - unmatching local changes being removed.' \
157 echo rezrov rezrov >rezrov &&
158 git-update-cache --add rezrov &&
159 if git-read-tree -m $treeH $treeM; then false; else :; fi'
161 test_expect_success \
162 '13 - unmatching local changes being removed.' \
164 echo rezrov rezrov >rezrov &&
165 git-update-cache --add rezrov &&
166 echo rezrov >rezrov &&
167 if git-read-tree -m $treeH $treeM; then false; else :; fi'
174 test_expect_success \
175 '14 - unchanged in two heads.' \
177 echo nitfol nitfol >nitfol &&
178 git-update-cache --add nitfol &&
179 git-read-tree -m $treeH $treeM &&
180 git-ls-files --stage >14.out || exit
181 diff --unified=0 M.out 14.out >14diff.out
182 compare_change 14diff.out expected &&
183 check_cache_at nitfol clean'
185 test_expect_success \
186 '15 - unchanged in two heads.' \
188 echo nitfol nitfol >nitfol &&
189 git-update-cache --add nitfol &&
190 echo nitfol nitfol nitfol >nitfol &&
191 git-read-tree -m $treeH $treeM &&
192 git-ls-files --stage >15.out || exit
193 diff --unified=0 M.out 15.out >15diff.out
194 compare_change 15diff.out expected &&
195 check_cache_at nitfol dirty'
197 test_expect_success \
198 '16 - conflicting local change.' \
200 echo bozbar bozbar >bozbar &&
201 git-update-cache --add bozbar &&
202 if git-read-tree -m $treeH $treeM; then false; else :; fi'
204 test_expect_success \
205 '17 - conflicting local change.' \
207 echo bozbar bozbar >bozbar &&
208 git-update-cache --add bozbar &&
209 echo bozbar bozbar bozbar >bozbar &&
210 if git-read-tree -m $treeH $treeM; then false; else :; fi'
212 test_expect_success \
213 '18 - local change already having a good result.' \
215 echo gnusto >bozbar &&
216 git-update-cache --add bozbar &&
217 git-read-tree -m $treeH $treeM &&
218 git-ls-files --stage >18.out &&
219 diff --unified=0 M.out 18.out &&
220 check_cache_at bozbar clean'
222 test_expect_success \
223 '19 - local change already having a good result, further modified.' \
225 echo gnusto >bozbar &&
226 git-update-cache --add bozbar &&
227 echo gnusto gnusto >bozbar &&
228 git-read-tree -m $treeH $treeM &&
229 git-ls-files --stage >19.out &&
230 diff --unified=0 M.out 19.out &&
231 check_cache_at bozbar dirty'
233 test_expect_success \
234 '20 - no local change, use new tree.' \
236 echo bozbar >bozbar &&
237 git-update-cache --add bozbar &&
238 git-read-tree -m $treeH $treeM &&
239 git-ls-files --stage >20.out &&
240 diff --unified=0 M.out 20.out &&
241 check_cache_at bozbar dirty'
243 test_expect_success \
244 '21 - no local change, dirty cache.' \
246 echo bozbar >bozbar &&
247 git-update-cache --add bozbar &&
248 echo gnusto gnusto >bozbar &&
249 if git-read-tree -m $treeH $treeM; then false; else :; fi'
251 # Also make sure we did not break DF vs DF/DF case.
252 test_expect_success \
253 'DF vs DF/DF case setup.' \
256 git-update-cache --add DF &&
257 treeDF=`git-write-tree` &&
258 echo treeDF $treeDF &&
259 git-ls-tree $treeDF &&
264 git-update-cache --add --remove DF DF/DF &&
265 treeDFDF=`git-write-tree` &&
266 echo treeDFDF $treeDFDF &&
267 git-ls-tree $treeDFDF &&
268 git-ls-files --stage >DFDF.out'
270 test_expect_success \
271 'DF vs DF/DF case test.' \
275 git-update-cache --add DF &&
276 git-read-tree -m $treeDF $treeDFDF &&
277 git-ls-files --stage >DFDFcheck.out &&
278 diff --unified=0 DFDF.out DFDFcheck.out &&
279 check_cache_at DF/DF dirty'