Merge branch 'ps/maintenance-detach-fix-more' into next
[alt-git.git] / t / t9816-git-p4-locked.sh
blobe687fbc25f60f5f4e8d4e540f99e072370d9d209
1 #!/bin/sh
3 test_description='git p4 locked file behavior'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./lib-git-p4.sh
8 test_expect_success 'start p4d' '
9 start_p4d
12 # See
13 # https://web.archive.org/web/20150602090517/http://www.perforce.com/perforce/doc.current/manuals/p4sag/chapter.superuser.html#superuser.basic.typemap_locking
14 # for suggestions on how to configure "sitewide pessimistic locking"
15 # where only one person can have a file open for edit at a time.
16 test_expect_success 'init depot' '
18 cd "$cli" &&
19 echo "TypeMap: +l //depot/..." | p4 typemap -i &&
20 echo file1 >file1 &&
21 p4 add file1 &&
22 p4 submit -d "add file1"
26 test_expect_success 'edit with lock not taken' '
27 test_when_finished cleanup_git &&
28 git p4 clone --dest="$git" //depot &&
30 cd "$git" &&
31 echo line2 >>file1 &&
32 git add file1 &&
33 git commit -m "line2 in file1" &&
34 git config git-p4.skipSubmitEdit true &&
35 git p4 submit
39 test_expect_success 'add with lock not taken' '
40 test_when_finished cleanup_git &&
41 git p4 clone --dest="$git" //depot &&
43 cd "$git" &&
44 echo line1 >>add-lock-not-taken &&
45 git add add-lock-not-taken &&
46 git commit -m "add add-lock-not-taken" &&
47 git config git-p4.skipSubmitEdit true &&
48 git p4 submit --verbose
52 lock_in_another_client() {
53 # build a different client
54 cli2="$TRASH_DIRECTORY/cli2" &&
55 mkdir -p "$cli2" &&
56 test_when_finished "p4 client -f -d client2 && rm -rf \"$cli2\"" &&
58 cd "$cli2" &&
59 P4CLIENT=client2 &&
60 cli="$cli2" &&
61 client_view "//depot/... //client2/..." &&
62 p4 sync &&
63 p4 open file1
67 test_expect_failure 'edit with lock taken' '
68 lock_in_another_client &&
69 test_when_finished cleanup_git &&
70 test_when_finished "cd \"$cli\" && p4 sync -f file1" &&
71 git p4 clone --dest="$git" //depot &&
73 cd "$git" &&
74 echo line3 >>file1 &&
75 git add file1 &&
76 git commit -m "line3 in file1" &&
77 git config git-p4.skipSubmitEdit true &&
78 git p4 submit --verbose
82 test_expect_failure 'delete with lock taken' '
83 lock_in_another_client &&
84 test_when_finished cleanup_git &&
85 test_when_finished "cd \"$cli\" && p4 sync -f file1" &&
86 git p4 clone --dest="$git" //depot &&
88 cd "$git" &&
89 git rm file1 &&
90 git commit -m "delete file1" &&
91 git config git-p4.skipSubmitEdit true &&
92 git p4 submit --verbose
96 test_expect_failure 'chmod with lock taken' '
97 lock_in_another_client &&
98 test_when_finished cleanup_git &&
99 test_when_finished "cd \"$cli\" && p4 sync -f file1" &&
100 git p4 clone --dest="$git" //depot &&
102 cd "$git" &&
103 chmod +x file1 &&
104 git add file1 &&
105 git commit -m "chmod +x file1" &&
106 git config git-p4.skipSubmitEdit true &&
107 git p4 submit --verbose
111 test_expect_success 'copy with lock taken' '
112 lock_in_another_client &&
113 test_when_finished cleanup_git &&
114 test_when_finished "cd \"$cli\" && p4 revert file2 && rm -f file2" &&
115 git p4 clone --dest="$git" //depot &&
117 cd "$git" &&
118 cp file1 file2 &&
119 git add file2 &&
120 git commit -m "cp file1 to file2" &&
121 git config git-p4.skipSubmitEdit true &&
122 git config git-p4.detectCopies true &&
123 git p4 submit --verbose
127 test_expect_failure 'move with lock taken' '
128 lock_in_another_client &&
129 test_when_finished cleanup_git &&
130 test_when_finished "cd \"$cli\" && p4 sync file1 && rm -f file2" &&
131 git p4 clone --dest="$git" //depot &&
133 cd "$git" &&
134 git mv file1 file3 &&
135 git commit -m "mv file1 to file3" &&
136 git config git-p4.skipSubmitEdit true &&
137 git config git-p4.detectRenames true &&
138 git p4 submit --verbose
142 test_done