blob: c13578a635fbcf8b33c1cf912df69afa23e96885 [file] [log] [blame]
Junio C Hamanoed93b442006-10-08 22:48:06 -07001#!/bin/sh
2
3test_description='read-tree -m -u checks working tree files'
4
5. ./test-lib.sh
Jens Lehmannea5070c2011-05-25 22:10:41 +02006. "$TEST_DIRECTORY"/lib-read-tree.sh
Junio C Hamanoed93b442006-10-08 22:48:06 -07007
8# two-tree test
9
10test_expect_success 'two-way setup' '
11
Junio C Hamanof8a9d422006-12-04 16:00:46 -080012 mkdir subdir &&
Junio C Hamanoed93b442006-10-08 22:48:06 -070013 echo >file1 file one &&
14 echo >file2 file two &&
Junio C Hamanof8a9d422006-12-04 16:00:46 -080015 echo >subdir/file1 file one in subdirectory &&
16 echo >subdir/file2 file two in subdirectory &&
17 git update-index --add file1 file2 subdir/file1 subdir/file2 &&
Junio C Hamanoed93b442006-10-08 22:48:06 -070018 git commit -m initial &&
19
20 git branch side &&
21 git tag -f branch-point &&
22
23 echo file2 is not tracked on the master anymore &&
Junio C Hamanof8a9d422006-12-04 16:00:46 -080024 rm -f file2 subdir/file2 &&
25 git update-index --remove file2 subdir/file2 &&
26 git commit -a -m "master removes file2 and subdir/file2"
Junio C Hamanoed93b442006-10-08 22:48:06 -070027'
28
29test_expect_success 'two-way not clobbering' '
30
31 echo >file2 master creates untracked file2 &&
Junio C Hamanof8a9d422006-12-04 16:00:46 -080032 echo >subdir/file2 master creates untracked subdir/file2 &&
Elia Pinto77317c02014-04-28 05:57:35 -070033 if err=$(read_tree_u_must_succeed -m -u master side 2>&1)
Junio C Hamanoed93b442006-10-08 22:48:06 -070034 then
35 echo should have complained
36 false
37 else
38 echo "happy to see $err"
39 fi
40'
41
Junio C Hamanof8a9d422006-12-04 16:00:46 -080042echo file2 >.gitignore
43
44test_expect_success 'two-way with incorrect --exclude-per-directory (1)' '
45
Elia Pinto77317c02014-04-28 05:57:35 -070046 if err=$(read_tree_u_must_succeed -m --exclude-per-directory=.gitignore master side 2>&1)
Junio C Hamanof8a9d422006-12-04 16:00:46 -080047 then
48 echo should have complained
49 false
50 else
51 echo "happy to see $err"
52 fi
53'
54
55test_expect_success 'two-way with incorrect --exclude-per-directory (2)' '
56
Elia Pinto77317c02014-04-28 05:57:35 -070057 if err=$(read_tree_u_must_succeed -m -u --exclude-per-directory=foo --exclude-per-directory=.gitignore master side 2>&1)
Junio C Hamanof8a9d422006-12-04 16:00:46 -080058 then
59 echo should have complained
60 false
61 else
62 echo "happy to see $err"
63 fi
64'
65
66test_expect_success 'two-way clobbering a ignored file' '
67
Jens Lehmannea5070c2011-05-25 22:10:41 +020068 read_tree_u_must_succeed -m -u --exclude-per-directory=.gitignore master side
Junio C Hamanof8a9d422006-12-04 16:00:46 -080069'
70
71rm -f .gitignore
72
Junio C Hamanoed93b442006-10-08 22:48:06 -070073# three-tree test
74
Junio C Hamanof8a9d422006-12-04 16:00:46 -080075test_expect_success 'three-way not complaining on an untracked path in both' '
Junio C Hamanoed93b442006-10-08 22:48:06 -070076
Junio C Hamanof8a9d422006-12-04 16:00:46 -080077 rm -f file2 subdir/file2 &&
Junio C Hamanoed93b442006-10-08 22:48:06 -070078 git checkout side &&
79 echo >file3 file three &&
Junio C Hamanof8a9d422006-12-04 16:00:46 -080080 echo >subdir/file3 file three &&
81 git update-index --add file3 subdir/file3 &&
82 git commit -a -m "side adds file3 and removes file2" &&
Junio C Hamanoed93b442006-10-08 22:48:06 -070083
84 git checkout master &&
85 echo >file2 file two is untracked on the master side &&
Junio C Hamanof8a9d422006-12-04 16:00:46 -080086 echo >subdir/file2 file two is untracked on the master side &&
Junio C Hamanoed93b442006-10-08 22:48:06 -070087
Jens Lehmannea5070c2011-05-25 22:10:41 +020088 read_tree_u_must_succeed -m -u branch-point master side
Junio C Hamanoed93b442006-10-08 22:48:06 -070089'
90
Pavel Roskin3dff5372007-02-03 23:49:16 -050091test_expect_success 'three-way not clobbering a working tree file' '
Junio C Hamanof8a9d422006-12-04 16:00:46 -080092
93 git reset --hard &&
94 rm -f file2 subdir/file2 file3 subdir/file3 &&
95 git checkout master &&
96 echo >file3 file three created in master, untracked &&
97 echo >subdir/file3 file three created in master, untracked &&
Elia Pinto77317c02014-04-28 05:57:35 -070098 if err=$(read_tree_u_must_succeed -m -u branch-point master side 2>&1)
Junio C Hamanof8a9d422006-12-04 16:00:46 -080099 then
100 echo should have complained
101 false
102 else
103 echo "happy to see $err"
104 fi
105'
106
107echo >.gitignore file3
108
109test_expect_success 'three-way not complaining on an untracked file' '
110
111 git reset --hard &&
112 rm -f file2 subdir/file2 file3 subdir/file3 &&
113 git checkout master &&
114 echo >file3 file three created in master, untracked &&
115 echo >subdir/file3 file three created in master, untracked &&
116
Jens Lehmannea5070c2011-05-25 22:10:41 +0200117 read_tree_u_must_succeed -m -u --exclude-per-directory=.gitignore branch-point master side
Junio C Hamanof8a9d422006-12-04 16:00:46 -0800118'
119
Linus Torvalds7f8ab8d2008-03-16 11:42:50 -0700120test_expect_success '3-way not overwriting local changes (setup)' '
121
122 git reset --hard &&
123 git checkout -b side-a branch-point &&
124 echo >>file1 "new line to be kept in the merge result" &&
125 git commit -a -m "side-a changes file1" &&
126 git checkout -b side-b branch-point &&
127 echo >>file2 "new line to be kept in the merge result" &&
128 git commit -a -m "side-b changes file2" &&
129 git checkout side-a
130
131'
132
133test_expect_success '3-way not overwriting local changes (our side)' '
134
135 # At this point, file1 from side-a should be kept as side-b
136 # did not touch it.
137
138 git reset --hard &&
139
140 echo >>file1 "local changes" &&
Jens Lehmannea5070c2011-05-25 22:10:41 +0200141 read_tree_u_must_succeed -m -u branch-point side-a side-b &&
Linus Torvalds7f8ab8d2008-03-16 11:42:50 -0700142 grep "new line to be kept" file1 &&
143 grep "local changes" file1
144
145'
146
147test_expect_success '3-way not overwriting local changes (their side)' '
148
149 # At this point, file2 from side-b should be taken as side-a
150 # did not touch it.
151
152 git reset --hard &&
153
154 echo >>file2 "local changes" &&
Jens Lehmannea5070c2011-05-25 22:10:41 +0200155 read_tree_u_must_fail -m -u branch-point side-a side-b &&
Linus Torvalds7f8ab8d2008-03-16 11:42:50 -0700156 ! grep "new line to be kept" file2 &&
157 grep "local changes" file2
158
159'
160
Johannes Sixt889c6f02013-06-07 22:53:28 +0200161test_expect_success 'funny symlink in work tree' '
Junio C Hamano8a785dc2008-03-18 21:59:39 -0700162
163 git reset --hard &&
164 git checkout -b sym-b side-b &&
165 mkdir -p a &&
166 >a/b &&
167 git add a/b &&
168 git commit -m "side adds a/b" &&
169
170 rm -fr a &&
171 git checkout -b sym-a side-a &&
172 mkdir -p a &&
Johannes Sixt889c6f02013-06-07 22:53:28 +0200173 test_ln_s_add ../b a/b &&
Junio C Hamano8a785dc2008-03-18 21:59:39 -0700174 git commit -m "we add a/b" &&
175
Jens Lehmannea5070c2011-05-25 22:10:41 +0200176 read_tree_u_must_succeed -m -u sym-a sym-a sym-b
Junio C Hamano8a785dc2008-03-18 21:59:39 -0700177
178'
179
Johannes Sixt889c6f02013-06-07 22:53:28 +0200180test_expect_success SANITY 'funny symlink in work tree, un-unlink-able' '
Junio C Hamano8a785dc2008-03-18 21:59:39 -0700181
Junio C Hamano03771422018-06-15 11:13:39 -0700182 test_when_finished "chmod u+w a 2>/dev/null; rm -fr a b" &&
183
Junio C Hamano8a785dc2008-03-18 21:59:39 -0700184 rm -fr a b &&
185 git reset --hard &&
186
187 git checkout sym-a &&
188 chmod a-w a &&
189 test_must_fail git read-tree -m -u sym-a sym-a sym-b
190
191'
192
Junio C Hamano29dc1332008-03-17 16:47:18 -0700193test_expect_success 'D/F setup' '
194
195 git reset --hard &&
196
197 git checkout side-a &&
198 rm -f subdir/file2 &&
199 mkdir subdir/file2 &&
200 echo qfwfq >subdir/file2/another &&
201 git add subdir/file2/another &&
202 test_tick &&
203 git commit -m "side-a changes file2 to directory"
204
205'
206
207test_expect_success 'D/F' '
208
209 git checkout side-b &&
Jens Lehmannea5070c2011-05-25 22:10:41 +0200210 read_tree_u_must_succeed -m -u branch-point side-b side-a &&
Junio C Hamano29dc1332008-03-17 16:47:18 -0700211 git ls-files -u >actual &&
212 (
Eric Sunshinef2deabf2018-07-01 20:23:56 -0400213 a=$(git rev-parse branch-point:subdir/file2) &&
214 b=$(git rev-parse side-a:subdir/file2/another) &&
215 echo "100644 $a 1 subdir/file2" &&
216 echo "100644 $a 2 subdir/file2" &&
Junio C Hamano29dc1332008-03-17 16:47:18 -0700217 echo "100644 $b 3 subdir/file2/another"
218 ) >expect &&
Stefan Beller9c5b2fa2017-10-06 12:00:06 -0700219 test_cmp expect actual
Junio C Hamano29dc1332008-03-17 16:47:18 -0700220
221'
222
223test_expect_success 'D/F resolve' '
224
225 git reset --hard &&
226 git checkout side-b &&
227 git merge-resolve branch-point -- side-b side-a
228
229'
230
231test_expect_success 'D/F recursive' '
232
233 git reset --hard &&
234 git checkout side-b &&
235 git merge-recursive branch-point -- side-b side-a
236
237'
238
Junio C Hamanoed93b442006-10-08 22:48:06 -0700239test_done