3 test_description
='git p4 tests for p4 branches'
7 test_expect_success
'start p4d' '
14 # 3: integrate //depot/main/... -> //depot/branch1/...
16 # 5: //depot/branch1/f5
17 # .: named branch branch2
18 # 6: integrate -b branch2
19 # 7: //depot/branch2/f7
22 test_expect_success
'basic p4 branches' '
29 p4 submit -d "main/f1" &&
33 p4 submit -d "main/f2" &&
35 p4 integrate //depot/main/... //depot/branch1/... &&
36 p4 submit -d "integrate main to branch1" &&
40 p4 submit -d "main/f4" &&
42 echo f5 >branch1/f5 &&
44 p4 submit -d "branch1/f5" &&
46 p4 branch -i <<-EOF &&
48 View: //depot/main/... //depot/branch2/...
51 p4 integrate -b branch2 &&
52 p4 submit -d "integrate main to branch2" &&
54 echo f7 >branch2/f7 &&
56 p4 submit -d "branch2/f7" &&
60 p4 submit -d "main/f8"
64 test_expect_success
'import main, no branch detection' '
65 test_when_finished cleanup_git &&
66 git p4 clone --dest="$git" //depot/main@all &&
69 git log --oneline --graph --decorate --all &&
70 git rev-list master >wc &&
71 test_line_count = 4 wc
75 test_expect_success
'import branch1, no branch detection' '
76 test_when_finished cleanup_git &&
77 git p4 clone --dest="$git" //depot/branch1@all &&
80 git log --oneline --graph --decorate --all &&
81 git rev-list master >wc &&
82 test_line_count = 2 wc
86 test_expect_success
'import branch2, no branch detection' '
87 test_when_finished cleanup_git &&
88 git p4 clone --dest="$git" //depot/branch2@all &&
91 git log --oneline --graph --decorate --all &&
92 git rev-list master >wc &&
93 test_line_count = 2 wc
97 test_expect_success
'import depot, no branch detection' '
98 test_when_finished cleanup_git &&
99 git p4 clone --dest="$git" //depot@all &&
102 git log --oneline --graph --decorate --all &&
103 git rev-list master >wc &&
104 test_line_count = 8 wc
108 test_expect_success
'import depot, branch detection' '
109 test_when_finished cleanup_git &&
110 git p4 clone --dest="$git" --detect-branches //depot@all &&
114 git log --oneline --graph --decorate --all &&
117 git rev-list master >wc &&
118 test_line_count = 4 wc &&
120 # 3 main, 1 integrate, 1 on branch2
121 git rev-list p4/depot/branch2 >wc &&
122 test_line_count = 5 wc &&
124 # no branch1, since no p4 branch created for it
125 test_must_fail git show-ref p4/depot/branch1
129 test_expect_success
'import depot, branch detection, branchList branch definition' '
130 test_when_finished cleanup_git &&
131 test_create_repo "$git" &&
134 git config git-p4.branchList main:branch1 &&
135 git p4 clone --dest=. --detect-branches //depot@all &&
137 git log --oneline --graph --decorate --all &&
140 git rev-list master >wc &&
141 test_line_count = 4 wc &&
143 # 3 main, 1 integrate, 1 on branch2
144 git rev-list p4/depot/branch2 >wc &&
145 test_line_count = 5 wc &&
147 # 2 main, 1 integrate, 1 on branch1
148 git rev-list p4/depot/branch1 >wc &&
149 test_line_count = 4 wc
153 test_expect_success
'restart p4d' '
159 # 1: //depot/branch1/file1
160 # //depot/branch1/file2
161 # 2: integrate //depot/branch1/... -> //depot/branch2/...
162 # 3: //depot/branch1/file3
163 # 4: //depot/branch1/file2 (edit)
164 # 5: integrate //depot/branch1/... -> //depot/branch3/...
166 ## Create a simple branch structure in P4 depot.
167 test_expect_success
'add simple p4 branches' '
174 p4 add file1 file2 &&
175 p4 submit -d "Create branch1" &&
176 p4 integrate //depot/branch1/... //depot/branch2/... &&
177 p4 submit -d "Integrate branch2 from branch1" &&
180 p4 submit -d "add file3 in branch1" &&
182 echo update >>file2 &&
183 p4 submit -d "update file2 in branch1" &&
184 p4 integrate //depot/branch1/... //depot/branch3/... &&
185 p4 submit -d "Integrate branch3 from branch1"
189 # Configure branches through git-config and clone them.
190 # All files are tested to make sure branches were cloned correctly.
191 # Finally, make an update to branch1 on P4 side to check if it is imported
192 # correctly by git p4.
193 test_expect_success
'git p4 clone simple branches' '
194 test_when_finished cleanup_git &&
195 test_create_repo "$git" &&
198 git config git-p4.branchList branch1:branch2 &&
199 git config --add git-p4.branchList branch1:branch3 &&
200 git p4 clone --dest=. --detect-branches //depot@all &&
201 git log --all --graph --decorate --stat &&
202 git reset --hard p4/depot/branch1 &&
207 git reset --hard p4/depot/branch2 &&
211 ! grep update file2 &&
212 git reset --hard p4/depot/branch3 &&
220 echo file2_ >>file2 &&
221 p4 submit -d "update file2 in branch1" &&
223 git reset --hard p4/depot/branch1 &&
229 # Create a complex branch structure in P4 depot to check if they are correctly
230 # cloned. The branches are created from older changelists to check if git p4 is
231 # able to correctly detect them.
232 # The final expected structure is:
235 # | `- file2 (updated)
242 # | `- file2 (updated)
251 test_expect_success
'git p4 add complex branches' '
254 changelist=$(p4 changes -m1 //depot/... | cut -d" " -f2) &&
255 changelist=$(($changelist - 5)) &&
256 p4 integrate //depot/branch1/...@$changelist //depot/branch4/... &&
257 p4 submit -d "Integrate branch4 from branch1@${changelist}" &&
258 changelist=$(($changelist + 2)) &&
259 p4 integrate //depot/branch1/...@$changelist //depot/branch5/... &&
260 p4 submit -d "Integrate branch5 from branch1@${changelist}"
264 # Configure branches through git-config and clone them. git p4 will only be able
265 # to clone the original structure if it is able to detect the origin changelist
267 test_expect_success
'git p4 clone complex branches' '
268 test_when_finished cleanup_git &&
269 test_create_repo "$git" &&
272 git config git-p4.branchList branch1:branch2 &&
273 git config --add git-p4.branchList branch1:branch3 &&
274 git config --add git-p4.branchList branch1:branch4 &&
275 git config --add git-p4.branchList branch1:branch5 &&
276 git p4 clone --dest=. --detect-branches //depot@all &&
277 git log --all --graph --decorate --stat &&
278 git reset --hard p4/depot/branch1 &&
279 test_path_is_file file1 &&
280 test_path_is_file file2 &&
281 test_path_is_file file3 &&
283 git reset --hard p4/depot/branch2 &&
284 test_path_is_file file1 &&
285 test_path_is_file file2 &&
286 test_path_is_missing file3 &&
287 ! grep update file2 &&
288 git reset --hard p4/depot/branch3 &&
289 test_path_is_file file1 &&
290 test_path_is_file file2 &&
291 test_path_is_file file3 &&
293 git reset --hard p4/depot/branch4 &&
294 test_path_is_file file1 &&
295 test_path_is_file file2 &&
296 test_path_is_missing file3 &&
297 ! grep update file2 &&
298 git reset --hard p4/depot/branch5 &&
299 test_path_is_file file1 &&
300 test_path_is_file file2 &&
301 test_path_is_file file3 &&
302 ! grep update file2 &&
303 test_path_is_missing .git/git-p4-tmp
307 # Move branch3/file3 to branch4/file3 in a single changelist
308 test_expect_success
'git p4 submit to two branches in a single changelist' '
311 p4 integrate //depot/branch3/file3 //depot/branch4/file3 &&
312 p4 delete //depot/branch3/file3 &&
313 p4 submit -d "Move branch3/file3 to branch4/file3"
317 # Confirm that changes to two branches done in a single changelist
318 # are correctly imported by git p4
319 test_expect_success
'git p4 sync changes to two branches in the same changelist' '
320 test_when_finished cleanup_git &&
321 test_create_repo "$git" &&
324 git config git-p4.branchList branch1:branch2 &&
325 git config --add git-p4.branchList branch1:branch3 &&
326 git config --add git-p4.branchList branch1:branch4 &&
327 git config --add git-p4.branchList branch1:branch5 &&
328 git p4 clone --dest=. --detect-branches //depot@all &&
329 git log --all --graph --decorate --stat &&
330 git reset --hard p4/depot/branch1 &&
331 test_path_is_file file1 &&
332 test_path_is_file file2 &&
333 test_path_is_file file3 &&
335 git reset --hard p4/depot/branch2 &&
336 test_path_is_file file1 &&
337 test_path_is_file file2 &&
338 test_path_is_missing file3 &&
339 ! grep update file2 &&
340 git reset --hard p4/depot/branch3 &&
341 test_path_is_file file1 &&
342 test_path_is_file file2 &&
343 test_path_is_missing file3 &&
345 git reset --hard p4/depot/branch4 &&
346 test_path_is_file file1 &&
347 test_path_is_file file2 &&
348 test_path_is_file file3 &&
349 ! grep update file2 &&
350 git reset --hard p4/depot/branch5 &&
351 test_path_is_file file1 &&
352 test_path_is_file file2 &&
353 test_path_is_file file3 &&
354 ! grep update file2 &&
355 test_path_is_missing .git/git-p4-tmp
359 # Create a branch by integrating a single file
360 test_expect_success
'git p4 file subset branch' '
363 p4 integrate //depot/branch1/file1 //depot/branch6/file1 &&
364 p4 submit -d "Integrate file1 alone from branch1 to branch6"
368 # Check if git p4 creates a new branch containing a single file,
369 # instead of keeping the old files from the original branch
370 test_expect_failure
'git p4 clone file subset branch' '
371 test_when_finished cleanup_git &&
372 test_create_repo "$git" &&
375 git config git-p4.branchList branch1:branch2 &&
376 git config --add git-p4.branchList branch1:branch3 &&
377 git config --add git-p4.branchList branch1:branch4 &&
378 git config --add git-p4.branchList branch1:branch5 &&
379 git config --add git-p4.branchList branch1:branch6 &&
380 git p4 clone --dest=. --detect-branches //depot@all &&
381 git log --all --graph --decorate --stat &&
382 git reset --hard p4/depot/branch1 &&
383 test_path_is_file file1 &&
384 test_path_is_file file2 &&
385 test_path_is_file file3 &&
387 git reset --hard p4/depot/branch2 &&
388 test_path_is_file file1 &&
389 test_path_is_file file2 &&
390 test_path_is_missing file3 &&
391 ! grep update file2 &&
392 git reset --hard p4/depot/branch3 &&
393 test_path_is_file file1 &&
394 test_path_is_file file2 &&
395 test_path_is_missing file3 &&
397 git reset --hard p4/depot/branch4 &&
398 test_path_is_file file1 &&
399 test_path_is_file file2 &&
400 test_path_is_file file3 &&
401 ! grep update file2 &&
402 git reset --hard p4/depot/branch5 &&
403 test_path_is_file file1 &&
404 test_path_is_file file2 &&
405 test_path_is_file file3 &&
406 ! grep update file2 &&
407 git reset --hard p4/depot/branch6 &&
408 test_path_is_file file1 &&
409 test_path_is_missing file2 &&
410 test_path_is_missing file3
413 test_expect_success
'kill p4d' '