]>
Commit | Line | Data |
---|---|---|
d00d2ed1 PW |
1 | #!/bin/sh |
2 | ||
6ab1d76c | 3 | test_description='git p4 tests' |
d00d2ed1 | 4 | |
46a29020 | 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
7 | ||
fc002330 | 8 | . ./lib-git-p4.sh |
d00d2ed1 | 9 | |
fc002330 PW |
10 | test_expect_success 'start p4d' ' |
11 | start_p4d | |
d00d2ed1 PW |
12 | ' |
13 | ||
14 | test_expect_success 'add p4 files' ' | |
fc002330 PW |
15 | ( |
16 | cd "$cli" && | |
17 | echo file1 >file1 && | |
18 | p4 add file1 && | |
19 | p4 submit -d "file1" && | |
20 | echo file2 >file2 && | |
21 | p4 add file2 && | |
22 | p4 submit -d "file2" | |
23 | ) | |
d00d2ed1 PW |
24 | ' |
25 | ||
6ab1d76c PW |
26 | test_expect_success 'basic git p4 clone' ' |
27 | git p4 clone --dest="$git" //depot && | |
f40ae5ce | 28 | test_when_finished cleanup_git && |
fc002330 PW |
29 | ( |
30 | cd "$git" && | |
31 | git log --oneline >lines && | |
32 | test_line_count = 1 lines | |
33 | ) | |
f0c9fe05 PW |
34 | ' |
35 | ||
0f487d30 PW |
36 | test_expect_success 'depot typo error' ' |
37 | test_must_fail git p4 clone --dest="$git" /depot 2>errs && | |
38 | grep "Depot paths must start with" errs | |
39 | ' | |
40 | ||
6ab1d76c PW |
41 | test_expect_success 'git p4 clone @all' ' |
42 | git p4 clone --dest="$git" //depot@all && | |
f40ae5ce | 43 | test_when_finished cleanup_git && |
fc002330 PW |
44 | ( |
45 | cd "$git" && | |
46 | git log --oneline >lines && | |
47 | test_line_count = 2 lines | |
48 | ) | |
d00d2ed1 PW |
49 | ' |
50 | ||
6ab1d76c | 51 | test_expect_success 'git p4 sync uninitialized repo' ' |
27c6000b | 52 | test_create_repo "$git" && |
f40ae5ce | 53 | test_when_finished cleanup_git && |
fc002330 PW |
54 | ( |
55 | cd "$git" && | |
4256397a | 56 | test_must_fail git p4 sync 2>errs && |
6789275d | 57 | test_grep "Perhaps you never did" errs |
fc002330 | 58 | ) |
27c6000b PW |
59 | ' |
60 | ||
61 | # | |
62 | # Create a git repo by hand. Add a commit so that HEAD is valid. | |
63 | # Test imports a new p4 repository into a new git branch. | |
64 | # | |
6ab1d76c | 65 | test_expect_success 'git p4 sync new branch' ' |
27c6000b | 66 | test_create_repo "$git" && |
f40ae5ce | 67 | test_when_finished cleanup_git && |
fc002330 PW |
68 | ( |
69 | cd "$git" && | |
70 | test_commit head && | |
6ab1d76c | 71 | git p4 sync --branch=refs/remotes/p4/depot //depot@all && |
fc002330 PW |
72 | git log --oneline p4/depot >lines && |
73 | test_line_count = 2 lines | |
74 | ) | |
27c6000b PW |
75 | ' |
76 | ||
17f273ff TK |
77 | # |
78 | # Setup as before, and then explicitly sync imported branch, using a | |
79 | # different ref format. | |
80 | # | |
81 | test_expect_success 'git p4 sync existing branch without changes' ' | |
82 | test_create_repo "$git" && | |
83 | test_when_finished cleanup_git && | |
84 | ( | |
85 | cd "$git" && | |
86 | test_commit head && | |
87 | git p4 sync --branch=depot //depot@all && | |
88 | git p4 sync --branch=refs/remotes/p4/depot >out && | |
6789275d | 89 | test_grep "No changes to import!" out |
17f273ff TK |
90 | ) |
91 | ' | |
92 | ||
93 | # | |
94 | # Same as before, relative branch name. | |
95 | # | |
96 | test_expect_success 'git p4 sync existing branch with relative name' ' | |
97 | test_create_repo "$git" && | |
98 | test_when_finished cleanup_git && | |
99 | ( | |
100 | cd "$git" && | |
101 | test_commit head && | |
102 | git p4 sync --branch=branch1 //depot@all && | |
103 | git p4 sync --branch=p4/branch1 >out && | |
6789275d | 104 | test_grep "No changes to import!" out |
17f273ff TK |
105 | ) |
106 | ' | |
107 | ||
108 | # | |
109 | # Same as before, with a nested branch path, referenced different ways. | |
110 | # | |
111 | test_expect_success 'git p4 sync existing branch with nested path' ' | |
112 | test_create_repo "$git" && | |
113 | test_when_finished cleanup_git && | |
114 | ( | |
115 | cd "$git" && | |
116 | test_commit head && | |
117 | git p4 sync --branch=p4/some/path //depot@all && | |
118 | git p4 sync --branch=some/path >out && | |
6789275d | 119 | test_grep "No changes to import!" out |
17f273ff TK |
120 | ) |
121 | ' | |
122 | ||
123 | # | |
124 | # Same as before, with a full ref path outside the p4/* namespace. | |
125 | # | |
126 | test_expect_success 'git p4 sync branch explicit ref without p4 in path' ' | |
127 | test_create_repo "$git" && | |
128 | test_when_finished cleanup_git && | |
129 | ( | |
130 | cd "$git" && | |
131 | test_commit head && | |
132 | git p4 sync --branch=refs/remotes/someremote/depot //depot@all && | |
133 | git p4 sync --branch=refs/remotes/someremote/depot >out && | |
6789275d | 134 | test_grep "No changes to import!" out |
17f273ff TK |
135 | ) |
136 | ' | |
137 | ||
138 | test_expect_success 'git p4 sync nonexistent ref' ' | |
139 | test_create_repo "$git" && | |
140 | test_when_finished cleanup_git && | |
141 | ( | |
142 | cd "$git" && | |
143 | test_commit head && | |
144 | git p4 sync --branch=depot //depot@all && | |
145 | test_must_fail git p4 sync --branch=depot2 2>errs && | |
6789275d | 146 | test_grep "Perhaps you never did" errs |
17f273ff TK |
147 | ) |
148 | ' | |
149 | ||
150 | test_expect_success 'git p4 sync existing non-p4-imported ref' ' | |
151 | test_create_repo "$git" && | |
152 | test_when_finished cleanup_git && | |
153 | ( | |
154 | cd "$git" && | |
155 | test_commit head && | |
156 | git p4 sync --branch=depot //depot@all && | |
157 | test_must_fail git p4 sync --branch=refs/heads/master 2>errs && | |
6789275d | 158 | test_grep "Perhaps you never did" errs |
17f273ff TK |
159 | ) |
160 | ' | |
161 | ||
da191d15 PW |
162 | test_expect_success 'clone two dirs' ' |
163 | ( | |
164 | cd "$cli" && | |
165 | mkdir sub1 sub2 && | |
166 | echo sub1/f1 >sub1/f1 && | |
167 | echo sub2/f2 >sub2/f2 && | |
168 | p4 add sub1/f1 && | |
169 | p4 submit -d "sub1/f1" && | |
170 | p4 add sub2/f2 && | |
171 | p4 submit -d "sub2/f2" | |
172 | ) && | |
6ab1d76c | 173 | git p4 clone --dest="$git" //depot/sub1 //depot/sub2 && |
da191d15 PW |
174 | test_when_finished cleanup_git && |
175 | ( | |
176 | cd "$git" && | |
177 | git ls-files >lines && | |
178 | test_line_count = 2 lines && | |
179 | git log --oneline p4/master >lines && | |
180 | test_line_count = 1 lines | |
181 | ) | |
182 | ' | |
183 | ||
184 | test_expect_success 'clone two dirs, @all' ' | |
185 | ( | |
186 | cd "$cli" && | |
187 | echo sub1/f3 >sub1/f3 && | |
188 | p4 add sub1/f3 && | |
189 | p4 submit -d "sub1/f3" | |
190 | ) && | |
6ab1d76c | 191 | git p4 clone --dest="$git" //depot/sub1@all //depot/sub2@all && |
da191d15 PW |
192 | test_when_finished cleanup_git && |
193 | ( | |
194 | cd "$git" && | |
195 | git ls-files >lines && | |
196 | test_line_count = 3 lines && | |
197 | git log --oneline p4/master >lines && | |
198 | test_line_count = 3 lines | |
199 | ) | |
200 | ' | |
201 | ||
202 | test_expect_success 'clone two dirs, @all, conflicting files' ' | |
203 | ( | |
204 | cd "$cli" && | |
205 | echo sub2/f3 >sub2/f3 && | |
206 | p4 add sub2/f3 && | |
207 | p4 submit -d "sub2/f3" | |
208 | ) && | |
6ab1d76c | 209 | git p4 clone --dest="$git" //depot/sub1@all //depot/sub2@all && |
da191d15 PW |
210 | test_when_finished cleanup_git && |
211 | ( | |
212 | cd "$git" && | |
213 | git ls-files >lines && | |
214 | test_line_count = 3 lines && | |
215 | git log --oneline p4/master >lines && | |
216 | test_line_count = 4 lines && | |
217 | echo sub2/f3 >expected && | |
218 | test_cmp expected f3 | |
219 | ) | |
220 | ' | |
221 | ||
9943e5b9 GV |
222 | test_expect_success 'clone two dirs, each edited by submit, single git commit' ' |
223 | ( | |
224 | cd "$cli" && | |
225 | echo sub1/f4 >sub1/f4 && | |
226 | p4 add sub1/f4 && | |
227 | echo sub2/f4 >sub2/f4 && | |
228 | p4 add sub2/f4 && | |
229 | p4 submit -d "sub1/f4 and sub2/f4" | |
230 | ) && | |
231 | git p4 clone --dest="$git" //depot/sub1@all //depot/sub2@all && | |
232 | test_when_finished cleanup_git && | |
233 | ( | |
234 | cd "$git" && | |
235 | git ls-files >lines && | |
236 | test_line_count = 4 lines && | |
237 | git log --oneline p4/master >lines && | |
238 | test_line_count = 5 lines | |
239 | ) | |
240 | ' | |
241 | ||
eceafffb LD |
242 | revision_ranges="2000/01/01,#head \ |
243 | 1,2080/01/01 \ | |
244 | 2000/01/01,2080/01/01 \ | |
245 | 2000/01/01,1000 \ | |
246 | 1,1000" | |
247 | ||
248 | test_expect_success 'clone using non-numeric revision ranges' ' | |
249 | test_when_finished cleanup_git && | |
250 | for r in $revision_ranges | |
251 | do | |
252 | rm -fr "$git" && | |
253 | test ! -d "$git" && | |
254 | git p4 clone --dest="$git" //depot@$r && | |
255 | ( | |
256 | cd "$git" && | |
257 | git ls-files >lines && | |
9943e5b9 | 258 | test_line_count = 8 lines |
0c51d6b4 | 259 | ) || return 1 |
eceafffb LD |
260 | done |
261 | ' | |
262 | ||
263 | test_expect_success 'clone with date range, excluding some changes' ' | |
264 | test_when_finished cleanup_git && | |
265 | before=$(date +%Y/%m/%d:%H:%M:%S) && | |
266 | sleep 2 && | |
267 | ( | |
268 | cd "$cli" && | |
269 | :>date_range_test && | |
270 | p4 add date_range_test && | |
271 | p4 submit -d "Adding file" | |
272 | ) && | |
273 | git p4 clone --dest="$git" //depot@1,$before && | |
274 | ( | |
275 | cd "$git" && | |
276 | test_path_is_missing date_range_test | |
277 | ) | |
278 | ' | |
279 | ||
68b28593 | 280 | test_expect_success 'exit when p4 fails to produce marshaled output' ' |
08c5eb7a PW |
281 | mkdir badp4dir && |
282 | test_when_finished "rm badp4dir/p4 && rmdir badp4dir" && | |
283 | cat >badp4dir/p4 <<-EOF && | |
68b28593 PW |
284 | #!$SHELL_PATH |
285 | exit 1 | |
286 | EOF | |
08c5eb7a | 287 | chmod 755 badp4dir/p4 && |
a0327c0e PW |
288 | ( |
289 | PATH="$TRASH_DIRECTORY/badp4dir:$PATH" && | |
290 | export PATH && | |
291 | test_expect_code 1 git p4 clone --dest="$git" //depot >errs 2>&1 | |
292 | ) && | |
6789275d | 293 | test_grep ! Traceback errs |
68b28593 PW |
294 | ' |
295 | ||
78189bea PW |
296 | # Hide a file from p4d, make sure we catch its complaint. This won't fail in |
297 | # p4 changes, files, or describe; just in p4 print. If P4CLIENT is unset, the | |
298 | # message will include "Librarian checkout". | |
299 | test_expect_success 'exit gracefully for p4 server errors' ' | |
300 | test_when_finished "mv \"$db\"/depot/file1,v,hidden \"$db\"/depot/file1,v" && | |
301 | mv "$db"/depot/file1,v "$db"/depot/file1,v,hidden && | |
302 | test_when_finished cleanup_git && | |
303 | test_expect_code 1 git p4 clone --dest="$git" //depot@1 >out 2>err && | |
6789275d | 304 | test_grep "Error from p4 print" err |
78189bea PW |
305 | ' |
306 | ||
307 | test_expect_success 'clone --bare should make a bare repository' ' | |
23a2666c | 308 | rm -rf "$git" && |
6ab1d76c | 309 | git p4 clone --dest="$git" --bare //depot && |
f40ae5ce | 310 | test_when_finished cleanup_git && |
fc002330 PW |
311 | ( |
312 | cd "$git" && | |
695d6998 PW |
313 | test_path_is_missing .git && |
314 | git config --get --bool core.bare true && | |
315 | git rev-parse --verify refs/remotes/p4/master && | |
316 | git rev-parse --verify refs/remotes/p4/HEAD && | |
46a29020 | 317 | git rev-parse --verify refs/heads/main && |
695d6998 | 318 | git rev-parse --verify HEAD |
fc002330 | 319 | ) |
38200076 PW |
320 | ' |
321 | ||
4e2e6ce4 PW |
322 | # Sleep a bit so that the top-most p4 change did not happen "now". Then |
323 | # import the repo and make sure that the initial import has the same time | |
324 | # as the top-most change. | |
325 | test_expect_success 'initial import time from top change time' ' | |
326 | p4change=$(p4 -G changes -m 1 //depot/... | marshal_dump change) && | |
327 | p4time=$(p4 -G changes -m 1 //depot/... | marshal_dump time) && | |
328 | sleep 3 && | |
6ab1d76c | 329 | git p4 clone --dest="$git" //depot && |
4e2e6ce4 | 330 | test_when_finished cleanup_git && |
fc002330 PW |
331 | ( |
332 | cd "$git" && | |
b7cf25c8 | 333 | gittime=$(git show -s --pretty=format:%at HEAD) && |
fc002330 PW |
334 | echo $p4time $gittime && |
335 | test $p4time = $gittime | |
336 | ) | |
4e2e6ce4 | 337 | ' |
848de9c3 | 338 | |
e6777fde PW |
339 | test_expect_success 'unresolvable host in P4PORT should display error' ' |
340 | test_when_finished cleanup_git && | |
341 | git p4 clone --dest="$git" //depot && | |
342 | ( | |
343 | cd "$git" && | |
344 | P4PORT=nosuchhost:65537 && | |
345 | export P4PORT && | |
346 | test_expect_code 1 git p4 sync >out 2>err && | |
347 | grep "connect to nosuchhost" err | |
348 | ) | |
349 | ' | |
350 | ||
251c8c50 CB |
351 | # Test following scenarios: |
352 | # - Without ".git/hooks/p4-pre-submit" , submit should continue | |
353 | # - With the hook returning 0, submit should continue | |
354 | # - With the hook returning 1, submit should abort | |
355 | test_expect_success 'run hook p4-pre-submit before submit' ' | |
356 | test_when_finished cleanup_git && | |
357 | git p4 clone --dest="$git" //depot && | |
358 | ( | |
359 | cd "$git" && | |
360 | echo "hello world" >hello.txt && | |
361 | git add hello.txt && | |
362 | git commit -m "add hello.txt" && | |
363 | git config git-p4.skipSubmitEdit true && | |
364 | git p4 submit --dry-run >out && | |
d7ef0368 ÆAB |
365 | grep "Would apply" out |
366 | ) && | |
367 | test_hook -C "$git" p4-pre-submit <<-\EOF && | |
368 | exit 0 | |
369 | EOF | |
370 | ( | |
371 | cd "$git" && | |
251c8c50 | 372 | git p4 submit --dry-run >out && |
d7ef0368 ÆAB |
373 | grep "Would apply" out |
374 | ) && | |
375 | test_hook -C "$git" --clobber p4-pre-submit <<-\EOF && | |
376 | exit 1 | |
377 | EOF | |
378 | ( | |
379 | cd "$git" && | |
251c8c50 CB |
380 | test_must_fail git p4 submit --dry-run >errs 2>&1 && |
381 | ! grep "Would apply" errs | |
382 | ) | |
383 | ' | |
384 | ||
00ad6e31 | 385 | test_expect_success 'submit from detached head' ' |
74b6fe92 LD |
386 | test_when_finished cleanup_git && |
387 | git p4 clone --dest="$git" //depot && | |
388 | ( | |
389 | cd "$git" && | |
390 | git checkout p4/master && | |
391 | >detached_head_test && | |
392 | git add detached_head_test && | |
393 | git commit -m "add detached_head" && | |
394 | git config git-p4.skipSubmitEdit true && | |
395 | git p4 submit && | |
396 | git p4 rebase && | |
397 | git log p4/master | grep detached_head | |
398 | ) | |
399 | ' | |
400 | ||
378f7be1 LD |
401 | test_expect_success 'submit from worktree' ' |
402 | test_when_finished cleanup_git && | |
403 | git p4 clone --dest="$git" //depot && | |
404 | ( | |
405 | cd "$git" && | |
406 | git worktree add ../worktree-test | |
407 | ) && | |
408 | ( | |
409 | cd "$git/../worktree-test" && | |
410 | test_commit "worktree-commit" && | |
411 | git config git-p4.skipSubmitEdit true && | |
412 | git p4 submit | |
413 | ) && | |
414 | ( | |
415 | cd "$cli" && | |
416 | p4 sync && | |
417 | test_path_is_file worktree-commit.t | |
418 | ) | |
419 | ' | |
420 | ||
d00d2ed1 | 421 | test_done |