config: teach git_config_rename_section a file argument
[git/mjg.git] / t / t9809-git-p4-client-view.sh
blobc9471d562ddf8e793453f0404db8553f0ec24754
1 #!/bin/sh
3 test_description='git-p4 client view'
5 . ./lib-git-p4.sh
7 test_expect_success 'start p4d' '
8 start_p4d
12 # Construct a client with this list of View lines
14 client_view() {
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
29 # Verify these files exist, exactly. Caller creates
30 # a list of files in file "files".
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
44 # Sync up the p4 client, make sure the given files (and only
45 # those) exist.
47 client_verify() {
49 cd "$cli" &&
50 p4 sync &&
51 find . -type f ! -name files >files &&
52 check_files_exist "$@"
57 # Make sure the named files, exactly, exist.
59 git_verify() {
61 cd "$git" &&
62 git ls-files >files &&
63 check_files_exist "$@"
67 # //depot
68 # - dir1
69 # - file11
70 # - file12
71 # - dir2
72 # - file21
73 # - file22
74 test_expect_success 'init depot' '
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
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
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
104 test_expect_success 'wildcard ... only supported at end of spec' '
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
110 test_expect_success 'basic map' '
111 client_view "//depot/dir1/... //client/cli1/..." &&
112 files="cli1/file11 cli1/file12" &&
113 client_verify $files &&
114 test_when_finished cleanup_git &&
115 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
116 git_verify $files
119 test_expect_success 'client view with no mappings' '
120 client_view &&
121 client_verify &&
122 test_when_finished cleanup_git &&
123 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
124 git_verify
127 test_expect_success 'single file map' '
128 client_view "//depot/dir1/file11 //client/file11" &&
129 files="file11" &&
130 client_verify $files &&
131 test_when_finished cleanup_git &&
132 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
133 git_verify $files
136 test_expect_success 'later mapping takes precedence (entire repo)' '
137 client_view "//depot/dir1/... //client/cli1/..." \
138 "//depot/... //client/cli2/..." &&
139 files="cli2/dir1/file11 cli2/dir1/file12
140 cli2/dir2/file21 cli2/dir2/file22" &&
141 client_verify $files &&
142 test_when_finished cleanup_git &&
143 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
144 git_verify $files
147 test_expect_success 'later mapping takes precedence (partial repo)' '
148 client_view "//depot/dir1/... //client/..." \
149 "//depot/dir2/... //client/..." &&
150 files="file21 file22" &&
151 client_verify $files &&
152 test_when_finished cleanup_git &&
153 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
154 git_verify $files
157 # Reading the view backwards,
158 # dir2 goes to cli12
159 # dir1 cannot go to cli12 since it was filled by dir2
160 # dir1 also does not go to cli3, since the second rule
161 # noticed that it matched, but was already filled
162 test_expect_success 'depot path matching rejected client path' '
163 client_view "//depot/dir1/... //client/cli3/..." \
164 "//depot/dir1/... //client/cli12/..." \
165 "//depot/dir2/... //client/cli12/..." &&
166 files="cli12/file21 cli12/file22" &&
167 client_verify $files &&
168 test_when_finished cleanup_git &&
169 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
170 git_verify $files
173 # since both have the same //client/..., the exclusion
174 # rule keeps everything out
175 test_expect_success 'exclusion wildcard, client rhs same (odd)' '
176 client_view "//depot/... //client/..." \
177 "-//depot/dir2/... //client/..." &&
178 client_verify &&
179 test_when_finished cleanup_git &&
180 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
181 git_verify
184 test_expect_success 'exclusion wildcard, client rhs different (normal)' '
185 client_view "//depot/... //client/..." \
186 "-//depot/dir2/... //client/dir2/..." &&
187 files="dir1/file11 dir1/file12" &&
188 client_verify $files &&
189 test_when_finished cleanup_git &&
190 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
191 git_verify $files
194 test_expect_success 'exclusion single file' '
195 client_view "//depot/... //client/..." \
196 "-//depot/dir2/file22 //client/file22" &&
197 files="dir1/file11 dir1/file12 dir2/file21" &&
198 client_verify $files &&
199 test_when_finished cleanup_git &&
200 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
201 git_verify $files
204 test_expect_success 'overlay wildcard' '
205 client_view "//depot/dir1/... //client/cli/..." \
206 "+//depot/dir2/... //client/cli/...\n" &&
207 files="cli/file11 cli/file12 cli/file21 cli/file22" &&
208 client_verify $files &&
209 test_when_finished cleanup_git &&
210 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
211 git_verify $files
214 test_expect_success 'overlay single file' '
215 client_view "//depot/dir1/... //client/cli/..." \
216 "+//depot/dir2/file21 //client/cli/file21" &&
217 files="cli/file11 cli/file12 cli/file21" &&
218 client_verify $files &&
219 test_when_finished cleanup_git &&
220 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
221 git_verify $files
224 test_expect_success 'exclusion with later inclusion' '
225 client_view "//depot/... //client/..." \
226 "-//depot/dir2/... //client/dir2/..." \
227 "//depot/dir2/... //client/dir2incl/..." &&
228 files="dir1/file11 dir1/file12 dir2incl/file21 dir2incl/file22" &&
229 client_verify $files &&
230 test_when_finished cleanup_git &&
231 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
232 git_verify $files
235 test_expect_success 'quotes on rhs only' '
236 client_view "//depot/dir1/... \"//client/cdir 1/...\"" &&
237 client_verify "cdir 1/file11" "cdir 1/file12" &&
238 test_when_finished cleanup_git &&
239 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
240 git_verify "cdir 1/file11" "cdir 1/file12"
244 # Rename directories to test quoting in depot-side mappings
245 # //depot
246 # - "dir 1"
247 # - file11
248 # - file12
249 # - "dir 2"
250 # - file21
251 # - file22
253 test_expect_success 'rename files to introduce spaces' '
254 client_view "//depot/... //client/..." &&
255 client_verify dir1/file11 dir1/file12 \
256 dir2/file21 dir2/file22 &&
258 cd "$cli" &&
259 p4 open dir1/... &&
260 p4 move dir1/... "dir 1"/... &&
261 p4 open dir2/... &&
262 p4 move dir2/... "dir 2"/... &&
263 p4 submit -d "rename with spaces"
264 ) &&
265 client_verify "dir 1/file11" "dir 1/file12" \
266 "dir 2/file21" "dir 2/file22"
269 test_expect_success 'quotes on lhs only' '
270 client_view "\"//depot/dir 1/...\" //client/cdir1/..." &&
271 files="cdir1/file11 cdir1/file12" &&
272 client_verify $files &&
273 test_when_finished cleanup_git &&
274 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
275 client_verify $files
278 test_expect_success 'quotes on both sides' '
279 client_view "\"//depot/dir 1/...\" \"//client/cdir 1/...\"" &&
280 client_verify "cdir 1/file11" "cdir 1/file12" &&
281 test_when_finished cleanup_git &&
282 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
283 git_verify "cdir 1/file11" "cdir 1/file12"
286 test_expect_success 'kill p4d' '
287 kill_p4d
290 test_done