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