git-ssh-push/pull: usability improvements
[alt-git.git] / t / t1001-read-tree-m-2way.sh
blob33041f3cce275089f6b816e7052fe19fdcd41410
1 #!/bin/sh
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
23 . ./test-lib.sh
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"
27 compare_change () {
28 sed >current \
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
34 check_cache_at () {
35 clean_if_empty=`git-diff-files "$1"`
36 case "$clean_if_empty" in
37 '') echo "$1: clean" ;;
38 ?*) echo "$1: dirty" ;;
39 esac
40 case "$2,$clean_if_empty" in
41 clean,) : ;;
42 clean,?*) false ;;
43 dirty,) false ;;
44 dirty,?*) : ;;
45 esac
48 test_expect_success \
49 setup \
50 'echo frotz >frotz &&
51 echo nitfol >nitfol &&
52 echo bozbar >bozbar &&
53 echo rezrov >rezrov &&
54 echo yomin >yomin &&
55 git-update-cache --add nitfol bozbar rezrov &&
56 treeH=`git-write-tree` &&
57 echo treeH $treeH &&
58 git-ls-tree $treeH &&
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` &&
64 echo treeM $treeM &&
65 git-ls-tree $treeM &&
66 git-diff-tree $treeH $treeM'
68 test_expect_success \
69 '1, 2, 3 - no carry forward' \
70 'rm -f .git/index &&
71 git-read-tree -m $treeH $treeM &&
72 git-ls-files --stage >1-3.out &&
73 cmp M.out 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
80 test_expect_success \
81 '4 - carry forward local addition.' \
82 'rm -f .git/index &&
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'
90 test_expect_success \
91 '5 - carry forward local addition.' \
92 'rm -f .git/index &&
93 echo yomin >yomin &&
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.' \
104 'rm -f .git/index &&
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.' \
113 'rm -f .git/index &&
114 echo frotz >frotz &&
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.' \
124 'rm -f .git/index &&
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.' \
131 'rm -f .git/index &&
132 echo frotz frotz >frotz &&
133 git-update-cache --add frotz &&
134 echo frotz >frotz &&
135 if git-read-tree -m $treeH $treeM; then false; else :; fi'
137 test_expect_success \
138 '10 - path removed.' \
139 'rm -f .git/index &&
140 echo rezrov >rezrov &&
141 git-update-cache --add rezrov &&
142 git-read-tree -m $treeH $treeM &&
143 git-ls-files --stage >10.out &&
144 cmp M.out 10.out'
146 test_expect_success \
147 '11 - dirty path removed.' \
148 'rm -f .git/index &&
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.' \
156 'rm -f .git/index &&
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.' \
163 'rm -f .git/index &&
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'
169 cat >expected <<EOF
170 -100644 X 0 nitfol
171 +100644 X 0 nitfol
174 test_expect_success \
175 '14 - unchanged in two heads.' \
176 'rm -f .git/index &&
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.' \
187 'rm -f .git/index &&
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.' \
199 'rm -f .git/index &&
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.' \
206 'rm -f .git/index &&
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.' \
214 'rm -f .git/index &&
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.' \
224 'rm -f .git/index &&
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.' \
235 'rm -f .git/index &&
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.' \
245 'rm -f .git/index &&
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.' \
254 'rm -f .git/index &&
255 echo DF >DF &&
256 git-update-cache --add DF &&
257 treeDF=`git-write-tree` &&
258 echo treeDF $treeDF &&
259 git-ls-tree $treeDF &&
261 rm -f DF &&
262 mkdir DF &&
263 echo DF/DF >DF/DF &&
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.' \
272 'rm -f .git/index &&
273 rm -fr DF &&
274 echo DF >DF &&
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'
281 test_done