3 test_description
='git-p4 client view'
7 test_expect_success
'start p4d' '
12 # Construct a client with this list of View lines
29 # Verify these files exist, exactly. Caller creates
30 # a list of files in file "files".
36 test_path_is_file
"$arg" &&
40 test_line_count
= $num files
44 # Sync up the p4 client, make sure the given files (and only
51 find .
-type f
! -name files
>files
&&
52 check_files_exist
"$@"
57 # Make sure the named files, exactly, exist.
62 git ls-files
>files
&&
63 check_files_exist
"$@"
78 echo dir
$d/file$d$f >dir
$d/file$d$f &&
79 p4 add dir
$d/file$d$f &&
80 p4 submit
-d "dir$d/file$d$f"
83 find .
-type f
! -name files
>files
&&
84 check_files_exist dir
1/file11 dir
1/file12 \
85 dir
2/file21 dir
2/file22
88 test_expect_success
'init depot' '
96 test_expect_success
'unsupported view wildcard %%n' '
97 client_view "//depot/%%%%1/sub/... //client/sub/%%%%1/..." &&
98 test_when_finished cleanup_git &&
99 test_must_fail "$GITP4" clone --use-client-spec --dest="$git" //depot
102 test_expect_success
'unsupported view wildcard *' '
103 client_view "//depot/*/bar/... //client/*/bar/..." &&
104 test_when_finished cleanup_git &&
105 test_must_fail "$GITP4" clone --use-client-spec --dest="$git" //depot
108 test_expect_success
'wildcard ... only supported at end of spec' '
109 client_view "//depot/.../file11 //client/.../file11" &&
110 test_when_finished cleanup_git &&
111 test_must_fail "$GITP4" clone --use-client-spec --dest="$git" //depot
114 test_expect_success
'basic map' '
115 client_view "//depot/dir1/... //client/cli1/..." &&
116 files="cli1/file11 cli1/file12" &&
117 client_verify $files &&
118 test_when_finished cleanup_git &&
119 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
123 test_expect_success
'client view with no mappings' '
126 test_when_finished cleanup_git &&
127 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
131 test_expect_success
'single file map' '
132 client_view "//depot/dir1/file11 //client/file11" &&
134 client_verify $files &&
135 test_when_finished cleanup_git &&
136 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
140 test_expect_success
'later mapping takes precedence (entire repo)' '
141 client_view "//depot/dir1/... //client/cli1/..." \
142 "//depot/... //client/cli2/..." &&
143 files="cli2/dir1/file11 cli2/dir1/file12
144 cli2/dir2/file21 cli2/dir2/file22" &&
145 client_verify $files &&
146 test_when_finished cleanup_git &&
147 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
151 test_expect_success
'later mapping takes precedence (partial repo)' '
152 client_view "//depot/dir1/... //client/..." \
153 "//depot/dir2/... //client/..." &&
154 files="file21 file22" &&
155 client_verify $files &&
156 test_when_finished cleanup_git &&
157 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
161 # Reading the view backwards,
163 # dir1 cannot go to cli12 since it was filled by dir2
164 # dir1 also does not go to cli3, since the second rule
165 # noticed that it matched, but was already filled
166 test_expect_success
'depot path matching rejected client path' '
167 client_view "//depot/dir1/... //client/cli3/..." \
168 "//depot/dir1/... //client/cli12/..." \
169 "//depot/dir2/... //client/cli12/..." &&
170 files="cli12/file21 cli12/file22" &&
171 client_verify $files &&
172 test_when_finished cleanup_git &&
173 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
177 # since both have the same //client/..., the exclusion
178 # rule keeps everything out
179 test_expect_success
'exclusion wildcard, client rhs same (odd)' '
180 client_view "//depot/... //client/..." \
181 "-//depot/dir2/... //client/..." &&
183 test_when_finished cleanup_git &&
184 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
188 test_expect_success
'exclusion wildcard, client rhs different (normal)' '
189 client_view "//depot/... //client/..." \
190 "-//depot/dir2/... //client/dir2/..." &&
191 files="dir1/file11 dir1/file12" &&
192 client_verify $files &&
193 test_when_finished cleanup_git &&
194 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
198 test_expect_success
'exclusion single file' '
199 client_view "//depot/... //client/..." \
200 "-//depot/dir2/file22 //client/file22" &&
201 files="dir1/file11 dir1/file12 dir2/file21" &&
202 client_verify $files &&
203 test_when_finished cleanup_git &&
204 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
208 test_expect_success
'overlay wildcard' '
209 client_view "//depot/dir1/... //client/cli/..." \
210 "+//depot/dir2/... //client/cli/...\n" &&
211 files="cli/file11 cli/file12 cli/file21 cli/file22" &&
212 client_verify $files &&
213 test_when_finished cleanup_git &&
214 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
218 test_expect_success
'overlay single file' '
219 client_view "//depot/dir1/... //client/cli/..." \
220 "+//depot/dir2/file21 //client/cli/file21" &&
221 files="cli/file11 cli/file12 cli/file21" &&
222 client_verify $files &&
223 test_when_finished cleanup_git &&
224 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
228 test_expect_success
'exclusion with later inclusion' '
229 client_view "//depot/... //client/..." \
230 "-//depot/dir2/... //client/dir2/..." \
231 "//depot/dir2/... //client/dir2incl/..." &&
232 files="dir1/file11 dir1/file12 dir2incl/file21 dir2incl/file22" &&
233 client_verify $files &&
234 test_when_finished cleanup_git &&
235 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
239 test_expect_success
'quotes on rhs only' '
240 client_view "//depot/dir1/... \"//client/cdir 1/...\"" &&
241 client_verify "cdir 1/file11" "cdir 1/file12" &&
242 test_when_finished cleanup_git &&
243 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
244 git_verify "cdir 1/file11" "cdir 1/file12"
251 # clone sets variable
252 test_expect_success
'clone --use-client-spec sets useClientSpec' '
253 client_view "//depot/... //client/..." &&
254 test_when_finished cleanup_git &&
255 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
258 git config --bool git-p4.useClientSpec >actual &&
264 # clone just a subdir of the client spec
265 test_expect_success
'subdir clone' '
266 client_view "//depot/... //client/..." &&
267 files="dir1/file11 dir1/file12 dir2/file21 dir2/file22" &&
268 client_verify $files &&
269 test_when_finished cleanup_git &&
270 "$GITP4" clone --use-client-spec --dest="$git" //depot/dir1 &&
271 git_verify dir1/file11 dir1/file12
275 # submit back, see what happens: five cases
277 test_expect_success
'subdir clone, submit modify' '
278 client_view "//depot/... //client/..." &&
279 test_when_finished cleanup_git &&
280 "$GITP4" clone --use-client-spec --dest="$git" //depot/dir1 &&
283 git config git-p4.skipSubmitEdit true &&
284 echo line >>dir1/file12 &&
285 git add dir1/file12 &&
286 git commit -m dir1/file12 &&
291 test_path_is_file dir1/file12 &&
292 test_line_count = 2 dir1/file12
296 test_expect_success
'subdir clone, submit add' '
297 client_view "//depot/... //client/..." &&
298 test_when_finished cleanup_git &&
299 "$GITP4" clone --use-client-spec --dest="$git" //depot/dir1 &&
302 git config git-p4.skipSubmitEdit true &&
303 echo file13 >dir1/file13 &&
304 git add dir1/file13 &&
305 git commit -m dir1/file13 &&
310 test_path_is_file dir1/file13
314 test_expect_success
'subdir clone, submit delete' '
315 client_view "//depot/... //client/..." &&
316 test_when_finished cleanup_git &&
317 "$GITP4" clone --use-client-spec --dest="$git" //depot/dir1 &&
320 git config git-p4.skipSubmitEdit true &&
321 git rm dir1/file12 &&
322 git commit -m "delete dir1/file12" &&
327 test_path_is_missing dir1/file12
331 test_expect_success
'subdir clone, submit copy' '
332 client_view "//depot/... //client/..." &&
333 test_when_finished cleanup_git &&
334 "$GITP4" clone --use-client-spec --dest="$git" //depot/dir1 &&
337 git config git-p4.skipSubmitEdit true &&
338 git config git-p4.detectCopies true &&
339 cp dir1/file11 dir1/file11a &&
340 git add dir1/file11a &&
341 git commit -m "copy to dir1/file11a" &&
346 test_path_is_file dir1/file11a
350 test_expect_success
'subdir clone, submit rename' '
351 client_view "//depot/... //client/..." &&
352 test_when_finished cleanup_git &&
353 "$GITP4" clone --use-client-spec --dest="$git" //depot/dir1 &&
356 git config git-p4.skipSubmitEdit true &&
357 git config git-p4.detectRenames true &&
358 git mv dir1/file13 dir1/file13a &&
359 git commit -m "rename dir1/file13 to dir1/file13a" &&
364 test_path_is_missing dir1/file13 &&
365 test_path_is_file dir1/file13a
369 test_expect_success
'reinit depot' '
375 p4 submit -d "delete all files" &&
381 # Rename directories to test quoting in depot-side mappings
390 test_expect_success
'rename files to introduce spaces' '
391 client_view "//depot/... //client/..." &&
392 client_verify dir1/file11 dir1/file12 \
393 dir2/file21 dir2/file22 &&
397 p4 move dir1/... "dir 1"/... &&
399 p4 move dir2/... "dir 2"/... &&
400 p4 submit -d "rename with spaces"
402 client_verify "dir 1/file11" "dir 1/file12" \
403 "dir 2/file21" "dir 2/file22"
406 test_expect_success
'quotes on lhs only' '
407 client_view "\"//depot/dir 1/...\" //client/cdir1/..." &&
408 files="cdir1/file11 cdir1/file12" &&
409 client_verify $files &&
410 test_when_finished cleanup_git &&
411 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
415 test_expect_success
'quotes on both sides' '
416 client_view "\"//depot/dir 1/...\" \"//client/cdir 1/...\"" &&
417 client_verify "cdir 1/file11" "cdir 1/file12" &&
418 test_when_finished cleanup_git &&
419 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
420 git_verify "cdir 1/file11" "cdir 1/file12"
423 test_expect_success
'kill p4d' '