git-p4: only a single ... wildcard is supported
[git] / t / t9809-git-p4-client-view.sh
1 #!/bin/sh
2
3 test_description='git-p4 client view'
4
5 . ./lib-git-p4.sh
6
7 test_expect_success 'start p4d' '
8         start_p4d
9 '
10
11 #
12 # Construct a client with this list of View lines
13 #
14 client_view() {
15         (
16                 cat <<-EOF &&
17                 Client: client
18                 Description: client
19                 Root: $cli
20                 View:
21                 EOF
22                 for arg ; do
23                         printf "\t$arg\n"
24                 done
25         ) | p4 client -i
26 }
27
28 #
29 # Verify these files exist, exactly.  Caller creates
30 # a list of files in file "files".
31 #
32 check_files_exist() {
33         ok=0 &&
34         num=${#@} &&
35         for arg ; do
36                 test_path_is_file "$arg" &&
37                 ok=$(($ok + 1))
38         done &&
39         test $ok -eq $num &&
40         test_line_count = $num files
41 }
42
43 #
44 # Sync up the p4 client, make sure the given files (and only
45 # those) exist.
46 #
47 client_verify() {
48         (
49                 cd "$cli" &&
50                 p4 sync &&
51                 find . -type f ! -name files >files &&
52                 check_files_exist "$@"
53         )
54 }
55
56 #
57 # Make sure the named files, exactly, exist.
58 #
59 git_verify() {
60         (
61                 cd "$git" &&
62                 git ls-files >files &&
63                 check_files_exist "$@"
64         )
65 }
66
67 # //depot
68 #   - dir1
69 #     - file11
70 #     - file12
71 #   - dir2
72 #     - file21
73 #     - file22
74 test_expect_success 'init depot' '
75         (
76                 cd "$cli" &&
77                 for d in 1 2 ; do
78                         mkdir -p dir$d &&
79                         for f in 1 2 ; do
80                                 echo dir$d/file$d$f >dir$d/file$d$f &&
81                                 p4 add dir$d/file$d$f &&
82                                 p4 submit -d "dir$d/file$d$f"
83                         done
84                 done &&
85                 find . -type f ! -name files >files &&
86                 check_files_exist dir1/file11 dir1/file12 \
87                                   dir2/file21 dir2/file22
88         )
89 '
90
91 # double % for printf
92 test_expect_success 'unsupported view wildcard %%n' '
93         client_view "//depot/%%%%1/sub/... //client/sub/%%%%1/..." &&
94         test_when_finished cleanup_git &&
95         test_must_fail "$GITP4" clone --use-client-spec --dest="$git" //depot
96 '
97
98 test_expect_success 'unsupported view wildcard *' '
99         client_view "//depot/*/bar/... //client/*/bar/..." &&
100         test_when_finished cleanup_git &&
101         test_must_fail "$GITP4" clone --use-client-spec --dest="$git" //depot
102 '
103
104 test_expect_success 'wildcard ... only supported at end of spec 1' '
105         client_view "//depot/.../file11 //client/.../file11" &&
106         test_when_finished cleanup_git &&
107         test_must_fail "$GITP4" clone --use-client-spec --dest="$git" //depot
108 '
109
110 test_expect_success 'wildcard ... only supported at end of spec 2' '
111         client_view "//depot/.../a/... //client/.../a/..." &&
112         test_when_finished cleanup_git &&
113         test_must_fail "$GITP4" clone --use-client-spec --dest="$git" //depot
114 '
115
116 test_expect_success 'basic map' '
117         client_view "//depot/dir1/... //client/cli1/..." &&
118         files="cli1/file11 cli1/file12" &&
119         client_verify $files &&
120         test_when_finished cleanup_git &&
121         "$GITP4" clone --use-client-spec --dest="$git" //depot &&
122         git_verify $files
123 '
124
125 test_expect_success 'client view with no mappings' '
126         client_view &&
127         client_verify &&
128         test_when_finished cleanup_git &&
129         "$GITP4" clone --use-client-spec --dest="$git" //depot &&
130         git_verify
131 '
132
133 test_expect_success 'single file map' '
134         client_view "//depot/dir1/file11 //client/file11" &&
135         files="file11" &&
136         client_verify $files &&
137         test_when_finished cleanup_git &&
138         "$GITP4" clone --use-client-spec --dest="$git" //depot &&
139         git_verify $files
140 '
141
142 test_expect_success 'later mapping takes precedence (entire repo)' '
143         client_view "//depot/dir1/... //client/cli1/..." \
144                     "//depot/... //client/cli2/..." &&
145         files="cli2/dir1/file11 cli2/dir1/file12
146                cli2/dir2/file21 cli2/dir2/file22" &&
147         client_verify $files &&
148         test_when_finished cleanup_git &&
149         "$GITP4" clone --use-client-spec --dest="$git" //depot &&
150         git_verify $files
151 '
152
153 test_expect_success 'later mapping takes precedence (partial repo)' '
154         client_view "//depot/dir1/... //client/..." \
155                     "//depot/dir2/... //client/..." &&
156         files="file21 file22" &&
157         client_verify $files &&
158         test_when_finished cleanup_git &&
159         "$GITP4" clone --use-client-spec --dest="$git" //depot &&
160         git_verify $files
161 '
162
163 # Reading the view backwards,
164 #   dir2 goes to cli12
165 #   dir1 cannot go to cli12 since it was filled by dir2
166 #   dir1 also does not go to cli3, since the second rule
167 #     noticed that it matched, but was already filled
168 test_expect_success 'depot path matching rejected client path' '
169         client_view "//depot/dir1/... //client/cli3/..." \
170                     "//depot/dir1/... //client/cli12/..." \
171                     "//depot/dir2/... //client/cli12/..." &&
172         files="cli12/file21 cli12/file22" &&
173         client_verify $files &&
174         test_when_finished cleanup_git &&
175         "$GITP4" clone --use-client-spec --dest="$git" //depot &&
176         git_verify $files
177 '
178
179 # since both have the same //client/..., the exclusion
180 # rule keeps everything out
181 test_expect_success 'exclusion wildcard, client rhs same (odd)' '
182         client_view "//depot/... //client/..." \
183                     "-//depot/dir2/... //client/..." &&
184         client_verify &&
185         test_when_finished cleanup_git &&
186         "$GITP4" clone --use-client-spec --dest="$git" //depot &&
187         git_verify
188 '
189
190 test_expect_success 'exclusion wildcard, client rhs different (normal)' '
191         client_view "//depot/... //client/..." \
192                     "-//depot/dir2/... //client/dir2/..." &&
193         files="dir1/file11 dir1/file12" &&
194         client_verify $files &&
195         test_when_finished cleanup_git &&
196         "$GITP4" clone --use-client-spec --dest="$git" //depot &&
197         git_verify $files
198 '
199
200 test_expect_success 'exclusion single file' '
201         client_view "//depot/... //client/..." \
202                     "-//depot/dir2/file22 //client/file22" &&
203         files="dir1/file11 dir1/file12 dir2/file21" &&
204         client_verify $files &&
205         test_when_finished cleanup_git &&
206         "$GITP4" clone --use-client-spec --dest="$git" //depot &&
207         git_verify $files
208 '
209
210 test_expect_success 'overlay wildcard' '
211         client_view "//depot/dir1/... //client/cli/..." \
212                     "+//depot/dir2/... //client/cli/...\n" &&
213         files="cli/file11 cli/file12 cli/file21 cli/file22" &&
214         client_verify $files &&
215         test_when_finished cleanup_git &&
216         "$GITP4" clone --use-client-spec --dest="$git" //depot &&
217         git_verify $files
218 '
219
220 test_expect_success 'overlay single file' '
221         client_view "//depot/dir1/... //client/cli/..." \
222                     "+//depot/dir2/file21 //client/cli/file21" &&
223         files="cli/file11 cli/file12 cli/file21" &&
224         client_verify $files &&
225         test_when_finished cleanup_git &&
226         "$GITP4" clone --use-client-spec --dest="$git" //depot &&
227         git_verify $files
228 '
229
230 test_expect_success 'exclusion with later inclusion' '
231         client_view "//depot/... //client/..." \
232                     "-//depot/dir2/... //client/dir2/..." \
233                     "//depot/dir2/... //client/dir2incl/..." &&
234         files="dir1/file11 dir1/file12 dir2incl/file21 dir2incl/file22" &&
235         client_verify $files &&
236         test_when_finished cleanup_git &&
237         "$GITP4" clone --use-client-spec --dest="$git" //depot &&
238         git_verify $files
239 '
240
241 test_expect_success 'quotes on rhs only' '
242         client_view "//depot/dir1/... \"//client/cdir 1/...\"" &&
243         client_verify "cdir 1/file11" "cdir 1/file12" &&
244         test_when_finished cleanup_git &&
245         "$GITP4" clone --use-client-spec --dest="$git" //depot &&
246         git_verify "cdir 1/file11" "cdir 1/file12"
247 '
248
249 #
250 # Rename directories to test quoting in depot-side mappings
251 # //depot
252 #    - "dir 1"
253 #       - file11
254 #       - file12
255 #    - "dir 2"
256 #       - file21
257 #       - file22
258 #
259 test_expect_success 'rename files to introduce spaces' '
260         client_view "//depot/... //client/..." &&
261         client_verify dir1/file11 dir1/file12 \
262                       dir2/file21 dir2/file22 &&
263         (
264                 cd "$cli" &&
265                 p4 open dir1/... &&
266                 p4 move dir1/... "dir 1"/... &&
267                 p4 open dir2/... &&
268                 p4 move dir2/... "dir 2"/... &&
269                 p4 submit -d "rename with spaces"
270         ) &&
271         client_verify "dir 1/file11" "dir 1/file12" \
272                       "dir 2/file21" "dir 2/file22"
273 '
274
275 test_expect_success 'quotes on lhs only' '
276         client_view "\"//depot/dir 1/...\" //client/cdir1/..." &&
277         files="cdir1/file11 cdir1/file12" &&
278         client_verify $files &&
279         test_when_finished cleanup_git &&
280         "$GITP4" clone --use-client-spec --dest="$git" //depot &&
281         client_verify $files
282 '
283
284 test_expect_success 'quotes on both sides' '
285         client_view "\"//depot/dir 1/...\" \"//client/cdir 1/...\"" &&
286         client_verify "cdir 1/file11" "cdir 1/file12" &&
287         test_when_finished cleanup_git &&
288         "$GITP4" clone --use-client-spec --dest="$git" //depot &&
289         git_verify "cdir 1/file11" "cdir 1/file12"
290 '
291
292 test_expect_success 'kill p4d' '
293         kill_p4d
294 '
295
296 test_done