3 test_description
='git p4 tests'
7 test_expect_success
'start p4d' '
11 test_expect_success
'add p4 files' '
16 p4 submit -d "file1" &&
23 test_expect_success
'basic git p4 clone' '
24 git p4 clone --dest="$git" //depot &&
25 test_when_finished cleanup_git &&
28 git log --oneline >lines &&
29 test_line_count = 1 lines
33 test_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
38 test_expect_success
'git p4 clone @all' '
39 git p4 clone --dest="$git" //depot@all &&
40 test_when_finished cleanup_git &&
43 git log --oneline >lines &&
44 test_line_count = 2 lines
48 test_expect_success
'git p4 sync uninitialized repo' '
49 test_create_repo "$git" &&
50 test_when_finished cleanup_git &&
53 test_must_fail git p4 sync 2>errs &&
54 test_i18ngrep "Perhaps you never did" errs
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.
62 test_expect_success
'git p4 sync new branch' '
63 test_create_repo "$git" &&
64 test_when_finished cleanup_git &&
68 git p4 sync --branch=refs/remotes/p4/depot //depot@all &&
69 git log --oneline p4/depot >lines &&
70 test_line_count = 2 lines
74 test_expect_success
'clone two dirs' '
78 echo sub1/f1 >sub1/f1 &&
79 echo sub2/f2 >sub2/f2 &&
81 p4 submit -d "sub1/f1" &&
83 p4 submit -d "sub2/f2"
85 git p4 clone --dest="$git" //depot/sub1 //depot/sub2 &&
86 test_when_finished cleanup_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
96 test_expect_success
'clone two dirs, @all' '
99 echo sub1/f3 >sub1/f3 &&
101 p4 submit -d "sub1/f3"
103 git p4 clone --dest="$git" //depot/sub1@all //depot/sub2@all &&
104 test_when_finished cleanup_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
114 test_expect_success
'clone two dirs, @all, conflicting files' '
117 echo sub2/f3 >sub2/f3 &&
119 p4 submit -d "sub2/f3"
121 git p4 clone --dest="$git" //depot/sub1@all //depot/sub2@all &&
122 test_when_finished cleanup_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 &&
134 test_expect_success
'clone two dirs, each edited by submit, single git commit' '
137 echo sub1/f4 >sub1/f4 &&
139 echo sub2/f4 >sub2/f4 &&
141 p4 submit -d "sub1/f4 and sub2/f4"
143 git p4 clone --dest="$git" //depot/sub1@all //depot/sub2@all &&
144 test_when_finished cleanup_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
154 revision_ranges
="2000/01/01,#head \
156 2000/01/01,2080/01/01 \
160 test_expect_success
'clone using non-numeric revision ranges' '
161 test_when_finished cleanup_git &&
162 for r in $revision_ranges
166 git p4 clone --dest="$git" //depot@$r &&
169 git ls-files >lines &&
170 test_line_count = 8 lines
175 test_expect_success
'clone with date range, excluding some changes' '
176 test_when_finished cleanup_git &&
177 before=$(date +%Y/%m/%d:%H:%M:%S) &&
182 p4 add date_range_test &&
183 p4 submit -d "Adding file"
185 git p4 clone --dest="$git" //depot@1,$before &&
188 test_path_is_missing date_range_test
192 test_expect_success
'exit when p4 fails to produce marshaled output' '
194 test_when_finished "rm badp4dir/p4 && rmdir badp4dir" &&
195 cat >badp4dir/p4 <<-EOF &&
199 chmod 755 badp4dir/p4 &&
201 PATH="$TRASH_DIRECTORY/badp4dir:$PATH" &&
203 test_expect_code 1 git p4 clone --dest="$git" //depot >errs 2>&1
205 test_i18ngrep ! Traceback errs
208 # Hide a file from p4d, make sure we catch its complaint. This won't fail in
209 # p4 changes, files, or describe; just in p4 print. If P4CLIENT is unset, the
210 # message will include "Librarian checkout".
211 test_expect_success
'exit gracefully for p4 server errors' '
212 test_when_finished "mv \"$db\"/depot/file1,v,hidden \"$db\"/depot/file1,v" &&
213 mv "$db"/depot/file1,v "$db"/depot/file1,v,hidden &&
214 test_when_finished cleanup_git &&
215 test_expect_code 1 git p4 clone --dest="$git" //depot@1 >out 2>err &&
216 test_i18ngrep "Error from p4 print" err
219 test_expect_success
'clone --bare should make a bare repository' '
221 git p4 clone --dest="$git" --bare //depot &&
222 test_when_finished cleanup_git &&
225 test_path_is_missing .git &&
226 git config --get --bool core.bare true &&
227 git rev-parse --verify refs/remotes/p4/master &&
228 git rev-parse --verify refs/remotes/p4/HEAD &&
229 git rev-parse --verify refs/heads/master &&
230 git rev-parse --verify HEAD
234 # Sleep a bit so that the top-most p4 change did not happen "now". Then
235 # import the repo and make sure that the initial import has the same time
236 # as the top-most change.
237 test_expect_success
'initial import time from top change time' '
238 p4change=$(p4 -G changes -m 1 //depot/... | marshal_dump change) &&
239 p4time=$(p4 -G changes -m 1 //depot/... | marshal_dump time) &&
241 git p4 clone --dest="$git" //depot &&
242 test_when_finished cleanup_git &&
245 gittime=$(git show -s --raw --pretty=format:%at HEAD) &&
246 echo $p4time $gittime &&
247 test $p4time = $gittime
251 test_expect_success
'unresolvable host in P4PORT should display error' '
252 test_when_finished cleanup_git &&
253 git p4 clone --dest="$git" //depot &&
256 P4PORT=nosuchhost:65537 &&
258 test_expect_code 1 git p4 sync >out 2>err &&
259 grep "connect to nosuchhost" err
263 # Test following scenarios:
264 # - Without ".git/hooks/p4-pre-submit" , submit should continue
265 # - With the hook returning 0, submit should continue
266 # - With the hook returning 1, submit should abort
267 test_expect_success
'run hook p4-pre-submit before submit' '
268 test_when_finished cleanup_git &&
269 git p4 clone --dest="$git" //depot &&
272 echo "hello world" >hello.txt &&
274 git commit -m "add hello.txt" &&
275 git config git-p4.skipSubmitEdit true &&
276 git p4 submit --dry-run >out &&
277 grep "Would apply" out &&
278 mkdir -p .git/hooks &&
279 write_script .git/hooks/p4-pre-submit <<-\EOF &&
282 git p4 submit --dry-run >out &&
283 grep "Would apply" out &&
284 write_script .git/hooks/p4-pre-submit <<-\EOF &&
287 test_must_fail git p4 submit --dry-run >errs 2>&1 &&
288 ! grep "Would apply" errs
292 test_expect_success
'submit from detached head' '
293 test_when_finished cleanup_git &&
294 git p4 clone --dest="$git" //depot &&
297 git checkout p4/master &&
298 >detached_head_test &&
299 git add detached_head_test &&
300 git commit -m "add detached_head" &&
301 git config git-p4.skipSubmitEdit true &&
304 git log p4/master | grep detached_head
308 test_expect_success
'submit from worktree' '
309 test_when_finished cleanup_git &&
310 git p4 clone --dest="$git" //depot &&
313 git worktree add ../worktree-test
316 cd "$git/../worktree-test" &&
317 test_commit "worktree-commit" &&
318 git config git-p4.skipSubmitEdit true &&
324 test_path_is_file worktree-commit.t