3 test_description
='git p4 tests'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10 test_expect_success
'start p4d' '
14 test_expect_success
'add p4 files' '
19 p4 submit -d "file1" &&
26 test_expect_success
'basic git p4 clone' '
27 git p4 clone --dest="$git" //depot &&
28 test_when_finished cleanup_git &&
31 git log --oneline >lines &&
32 test_line_count = 1 lines
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
41 test_expect_success
'git p4 clone @all' '
42 git p4 clone --dest="$git" //depot@all &&
43 test_when_finished cleanup_git &&
46 git log --oneline >lines &&
47 test_line_count = 2 lines
51 test_expect_success
'git p4 sync uninitialized repo' '
52 test_create_repo "$git" &&
53 test_when_finished cleanup_git &&
56 test_must_fail git p4 sync 2>errs &&
57 test_i18ngrep "Perhaps you never did" errs
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.
65 test_expect_success
'git p4 sync new branch' '
66 test_create_repo "$git" &&
67 test_when_finished cleanup_git &&
71 git p4 sync --branch=refs/remotes/p4/depot //depot@all &&
72 git log --oneline p4/depot >lines &&
73 test_line_count = 2 lines
77 test_expect_success
'clone two dirs' '
81 echo sub1/f1 >sub1/f1 &&
82 echo sub2/f2 >sub2/f2 &&
84 p4 submit -d "sub1/f1" &&
86 p4 submit -d "sub2/f2"
88 git p4 clone --dest="$git" //depot/sub1 //depot/sub2 &&
89 test_when_finished cleanup_git &&
92 git ls-files >lines &&
93 test_line_count = 2 lines &&
94 git log --oneline p4/master >lines &&
95 test_line_count = 1 lines
99 test_expect_success
'clone two dirs, @all' '
102 echo sub1/f3 >sub1/f3 &&
104 p4 submit -d "sub1/f3"
106 git p4 clone --dest="$git" //depot/sub1@all //depot/sub2@all &&
107 test_when_finished cleanup_git &&
110 git ls-files >lines &&
111 test_line_count = 3 lines &&
112 git log --oneline p4/master >lines &&
113 test_line_count = 3 lines
117 test_expect_success
'clone two dirs, @all, conflicting files' '
120 echo sub2/f3 >sub2/f3 &&
122 p4 submit -d "sub2/f3"
124 git p4 clone --dest="$git" //depot/sub1@all //depot/sub2@all &&
125 test_when_finished cleanup_git &&
128 git ls-files >lines &&
129 test_line_count = 3 lines &&
130 git log --oneline p4/master >lines &&
131 test_line_count = 4 lines &&
132 echo sub2/f3 >expected &&
137 test_expect_success
'clone two dirs, each edited by submit, single git commit' '
140 echo sub1/f4 >sub1/f4 &&
142 echo sub2/f4 >sub2/f4 &&
144 p4 submit -d "sub1/f4 and sub2/f4"
146 git p4 clone --dest="$git" //depot/sub1@all //depot/sub2@all &&
147 test_when_finished cleanup_git &&
150 git ls-files >lines &&
151 test_line_count = 4 lines &&
152 git log --oneline p4/master >lines &&
153 test_line_count = 5 lines
157 revision_ranges
="2000/01/01,#head \
159 2000/01/01,2080/01/01 \
163 test_expect_success
'clone using non-numeric revision ranges' '
164 test_when_finished cleanup_git &&
165 for r in $revision_ranges
169 git p4 clone --dest="$git" //depot@$r &&
172 git ls-files >lines &&
173 test_line_count = 8 lines
178 test_expect_success
'clone with date range, excluding some changes' '
179 test_when_finished cleanup_git &&
180 before=$(date +%Y/%m/%d:%H:%M:%S) &&
185 p4 add date_range_test &&
186 p4 submit -d "Adding file"
188 git p4 clone --dest="$git" //depot@1,$before &&
191 test_path_is_missing date_range_test
195 test_expect_success
'exit when p4 fails to produce marshaled output' '
197 test_when_finished "rm badp4dir/p4 && rmdir badp4dir" &&
198 cat >badp4dir/p4 <<-EOF &&
202 chmod 755 badp4dir/p4 &&
204 PATH="$TRASH_DIRECTORY/badp4dir:$PATH" &&
206 test_expect_code 1 git p4 clone --dest="$git" //depot >errs 2>&1
208 test_i18ngrep ! Traceback errs
211 # Hide a file from p4d, make sure we catch its complaint. This won't fail in
212 # p4 changes, files, or describe; just in p4 print. If P4CLIENT is unset, the
213 # message will include "Librarian checkout".
214 test_expect_success
'exit gracefully for p4 server errors' '
215 test_when_finished "mv \"$db\"/depot/file1,v,hidden \"$db\"/depot/file1,v" &&
216 mv "$db"/depot/file1,v "$db"/depot/file1,v,hidden &&
217 test_when_finished cleanup_git &&
218 test_expect_code 1 git p4 clone --dest="$git" //depot@1 >out 2>err &&
219 test_i18ngrep "Error from p4 print" err
222 test_expect_success
'clone --bare should make a bare repository' '
224 git p4 clone --dest="$git" --bare //depot &&
225 test_when_finished cleanup_git &&
228 test_path_is_missing .git &&
229 git config --get --bool core.bare true &&
230 git rev-parse --verify refs/remotes/p4/master &&
231 git rev-parse --verify refs/remotes/p4/HEAD &&
232 git rev-parse --verify refs/heads/main &&
233 git rev-parse --verify HEAD
237 # Sleep a bit so that the top-most p4 change did not happen "now". Then
238 # import the repo and make sure that the initial import has the same time
239 # as the top-most change.
240 test_expect_success
'initial import time from top change time' '
241 p4change=$(p4 -G changes -m 1 //depot/... | marshal_dump change) &&
242 p4time=$(p4 -G changes -m 1 //depot/... | marshal_dump time) &&
244 git p4 clone --dest="$git" //depot &&
245 test_when_finished cleanup_git &&
248 gittime=$(git show -s --raw --pretty=format:%at HEAD) &&
249 echo $p4time $gittime &&
250 test $p4time = $gittime
254 test_expect_success
'unresolvable host in P4PORT should display error' '
255 test_when_finished cleanup_git &&
256 git p4 clone --dest="$git" //depot &&
259 P4PORT=nosuchhost:65537 &&
261 test_expect_code 1 git p4 sync >out 2>err &&
262 grep "connect to nosuchhost" err
266 # Test following scenarios:
267 # - Without ".git/hooks/p4-pre-submit" , submit should continue
268 # - With the hook returning 0, submit should continue
269 # - With the hook returning 1, submit should abort
270 test_expect_success
'run hook p4-pre-submit before submit' '
271 test_when_finished cleanup_git &&
272 git p4 clone --dest="$git" //depot &&
275 echo "hello world" >hello.txt &&
277 git commit -m "add hello.txt" &&
278 git config git-p4.skipSubmitEdit true &&
279 git p4 submit --dry-run >out &&
280 grep "Would apply" out &&
281 mkdir -p .git/hooks &&
282 write_script .git/hooks/p4-pre-submit <<-\EOF &&
285 git p4 submit --dry-run >out &&
286 grep "Would apply" out &&
287 write_script .git/hooks/p4-pre-submit <<-\EOF &&
290 test_must_fail git p4 submit --dry-run >errs 2>&1 &&
291 ! grep "Would apply" errs
295 test_expect_success
'submit from detached head' '
296 test_when_finished cleanup_git &&
297 git p4 clone --dest="$git" //depot &&
300 git checkout p4/master &&
301 >detached_head_test &&
302 git add detached_head_test &&
303 git commit -m "add detached_head" &&
304 git config git-p4.skipSubmitEdit true &&
307 git log p4/master | grep detached_head
311 test_expect_success
'submit from worktree' '
312 test_when_finished cleanup_git &&
313 git p4 clone --dest="$git" //depot &&
316 git worktree add ../worktree-test
319 cd "$git/../worktree-test" &&
320 test_commit "worktree-commit" &&
321 git config git-p4.skipSubmitEdit true &&
327 test_path_is_file worktree-commit.t