git-p4 tests: refactor and cleanup

Introduce a library for functions that are common to multiple git-p4 test files. Be a bit more clever about starting and stopping p4d. Specify a unique port number for each test, so that tests can run in parallel. Start p4d not in daemon mode, and save the pid, to be able to kill it cleanly later. Never kill p4d at startup; always shutdown cleanly. Handle directory changes better. Always chdir inside a subshell, and remove any post-test directory changes. Clean up whitespace, and use test_cmp and test_must_fail more consistently. Separate the tests related to detecting p4 branches into their own file, and add a few more. Acked-by: Luke Diamand <luke@diamand.org> Signed-off-by: Pete Wyckoff <pw@padd.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Pete Wyckoff committed Aug 22, 2011 at 22:20 UTC fc002330718c2d939b4a1d0603db1a1ae623aa47
3 files changed +559 -324
t/lib-git-p4.sh new
+74
@@ -0,0 +1,74 @@
1 +#
2 +# Library code for git-p4 tests
3 +#
4 +
5 +. ./test-lib.sh
6 +
7 +if ! test_have_prereq PYTHON; then
8 + skip_all='skipping git-p4 tests; python not available'
9 + test_done
10 +fi
11 +( p4 -h && p4d -h ) >/dev/null 2>&1 || {
12 + skip_all='skipping git-p4 tests; no p4 or p4d'
13 + test_done
14 +}
15 +
16 +GITP4="$GIT_BUILD_DIR/contrib/fast-import/git-p4"
17 +
18 +# Try to pick a unique port: guess a large number, then hope
19 +# no more than one of each test is running.
20 +#
21 +# This does not handle the case where somebody else is running the
22 +# same tests and has chosen the same ports.
23 +testid=${this_test#t}
24 +git_p4_test_start=9800
25 +P4DPORT=$((10669 + ($testid - $git_p4_test_start)))
26 +
27 +export P4PORT=localhost:$P4DPORT
28 +export P4CLIENT=client
29 +
30 +db="$TRASH_DIRECTORY/db"
31 +cli="$TRASH_DIRECTORY/cli"
32 +git="$TRASH_DIRECTORY/git"
33 +pidfile="$TRASH_DIRECTORY/p4d.pid"
34 +
35 +start_p4d() {
36 + mkdir -p "$db" "$cli" "$git" &&
37 + (
38 + p4d -q -r "$db" -p $P4DPORT &
39 + echo $! >"$pidfile"
40 + ) &&
41 + for i in 1 2 3 4 5 ; do
42 + p4 info >/dev/null 2>&1 && break || true &&
43 + echo waiting for p4d to start &&
44 + sleep 1
45 + done &&
46 + # complain if it never started
47 + p4 info >/dev/null &&
48 + (
49 + cd "$cli" &&
50 + p4 client -i <<-EOF
51 + Client: client
52 + Description: client
53 + Root: $cli
54 + View: //depot/... //client/...
55 + EOF
56 + )
57 +}
58 +
59 +kill_p4d() {
60 + pid=$(cat "$pidfile")
61 + # it had better exist for the first kill
62 + kill $pid &&
63 + for i in 1 2 3 4 5 ; do
64 + kill $pid >/dev/null 2>&1 || break
65 + sleep 1
66 + done &&
67 + # complain if it would not die
68 + test_must_fail kill $pid >/dev/null 2>&1 &&
69 + rm -rf "$db" "$cli" "$pidfile"
70 +}
71 +
72 +cleanup_git() {
73 + rm -rf "$git"
74 +}
t/t9800-git-p4.sh
+252 -324
@@ -2,76 +2,51 @@
2
3 test_description='git-p4 tests'
4
5 -. ./test-lib.sh
5 +. ./lib-git-p4.sh
6
7 -( p4 -h && p4d -h ) >/dev/null 2>&1 || {
8 - skip_all='skipping git-p4 tests; no p4 or p4d'
9 - test_done
10 -}
11 -
12 -GITP4=$GIT_BUILD_DIR/contrib/fast-import/git-p4
13 -P4DPORT=10669
14 -
15 -export P4PORT=localhost:$P4DPORT
16 -
17 -db="$TRASH_DIRECTORY/db"
18 -cli="$TRASH_DIRECTORY/cli"
19 -git="$TRASH_DIRECTORY/git"
20 -
21 -test_debug 'echo p4d -q -d -r "$db" -p $P4DPORT'
22 -test_expect_success setup '
23 - mkdir -p "$db" &&
24 - p4d -q -d -r "$db" -p $P4DPORT &&
25 - mkdir -p "$cli" &&
26 - mkdir -p "$git" &&
27 - export P4PORT=localhost:$P4DPORT
7 +test_expect_success 'start p4d' '
8 + start_p4d
9 '
10
11 test_expect_success 'add p4 files' '
31 - cd "$cli" &&
32 - p4 client -i <<-EOF &&
33 - Client: client
34 - Description: client
35 - Root: $cli
36 - View: //depot/... //client/...
37 - EOF
38 - export P4CLIENT=client &&
39 - echo file1 >file1 &&
40 - p4 add file1 &&
41 - p4 submit -d "file1" &&
42 - echo file2 >file2 &&
43 - p4 add file2 &&
44 - p4 submit -d "file2" &&
45 - cd "$TRASH_DIRECTORY"
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 + )
21 '
22
48 -cleanup_git() {
49 - cd "$TRASH_DIRECTORY" &&
50 - rm -rf "$git" &&
51 - mkdir "$git"
52 -}
53 -
23 test_expect_success 'basic git-p4 clone' '
24 "$GITP4" clone --dest="$git" //depot &&
25 test_when_finished cleanup_git &&
57 - cd "$git" &&
58 - git log --oneline >lines &&
59 - test_line_count = 1 lines
26 + (
27 + cd "$git" &&
28 + git log --oneline >lines &&
29 + test_line_count = 1 lines
30 + )
31 '
32
33 test_expect_success 'git-p4 clone @all' '
34 "$GITP4" clone --dest="$git" //depot@all &&
35 test_when_finished cleanup_git &&
65 - cd "$git" &&
66 - git log --oneline >lines &&
67 - test_line_count = 2 lines
36 + (
37 + cd "$git" &&
38 + git log --oneline >lines &&
39 + test_line_count = 2 lines
40 + )
41 '
42
43 test_expect_success 'git-p4 sync uninitialized repo' '
44 test_create_repo "$git" &&
45 test_when_finished cleanup_git &&
73 - cd "$git" &&
74 - test_must_fail "$GITP4" sync
46 + (
47 + cd "$git" &&
48 + test_must_fail "$GITP4" sync
49 + )
50 '
51
52 #
@@ -81,17 +56,19 @@ test_expect_success 'git-p4 sync uninitialized repo' '
56 test_expect_success 'git-p4 sync new branch' '
57 test_create_repo "$git" &&
58 test_when_finished cleanup_git &&
84 - cd "$git" &&
85 - test_commit head &&
86 - "$GITP4" sync --branch=refs/remotes/p4/depot //depot@all &&
87 - git log --oneline p4/depot >lines &&
88 - test_line_count = 2 lines
59 + (
60 + cd "$git" &&
61 + test_commit head &&
62 + "$GITP4" sync --branch=refs/remotes/p4/depot //depot@all &&
63 + git log --oneline p4/depot >lines &&
64 + test_line_count = 2 lines
65 + )
66 '
67
68 test_expect_success 'exit when p4 fails to produce marshaled output' '
69 badp4dir="$TRASH_DIRECTORY/badp4dir" &&
93 - mkdir -p "$badp4dir" &&
94 - test_when_finished "rm -rf $badp4dir" &&
70 + mkdir "$badp4dir" &&
71 + test_when_finished "rm \"$badp4dir/p4\" && rmdir \"$badp4dir\"" &&
72 cat >"$badp4dir"/p4 <<-EOF &&
73 #!$SHELL_PATH
74 exit 1
@@ -103,61 +80,61 @@ test_expect_success 'exit when p4 fails to produce marshaled output' '
80 '
81
82 test_expect_success 'add p4 files with wildcards in the names' '
106 - cd "$cli" &&
107 - echo file-wild-hash >file-wild#hash &&
108 - echo file-wild-star >file-wild\*star &&
109 - echo file-wild-at >file-wild@at &&
110 - echo file-wild-percent >file-wild%percent &&
111 - p4 add -f file-wild* &&
112 - p4 submit -d "file wildcards"
83 + (
84 + cd "$cli" &&
85 + echo file-wild-hash >file-wild#hash &&
86 + echo file-wild-star >file-wild\*star &&
87 + echo file-wild-at >file-wild@at &&
88 + echo file-wild-percent >file-wild%percent &&
89 + p4 add -f file-wild* &&
90 + p4 submit -d "file wildcards"
91 + )
92 '
93
94 test_expect_success 'wildcard files git-p4 clone' '
95 "$GITP4" clone --dest="$git" //depot &&
96 test_when_finished cleanup_git &&
118 - cd "$git" &&
119 - test -f file-wild#hash &&
120 - test -f file-wild\*star &&
121 - test -f file-wild@at &&
122 - test -f file-wild%percent
97 + (
98 + cd "$git" &&
99 + test -f file-wild#hash &&
100 + test -f file-wild\*star &&
101 + test -f file-wild@at &&
102 + test -f file-wild%percent
103 + )
104 '
105
106 test_expect_success 'clone bare' '
107 "$GITP4" clone --dest="$git" --bare //depot &&
108 test_when_finished cleanup_git &&
128 - cd "$git" &&
129 - test ! -d .git &&
130 - bare=`git config --get core.bare` &&
131 - test "$bare" = true
109 + (
110 + cd "$git" &&
111 + test ! -d .git &&
112 + bare=`git config --get core.bare` &&
113 + test "$bare" = true
114 + )
115 '
116
117 p4_add_user() {
135 - name=$1
136 - fullname=$2
137 - p4 user -f -i <<EOF &&
138 -User: $name
139 -Email: $name@localhost
140 -FullName: $fullname
141 -EOF
142 - p4 passwd -P secret $name
118 + name=$1 fullname=$2 &&
119 + p4 user -f -i <<-EOF &&
120 + User: $name
121 + Email: $name@localhost
122 + FullName: $fullname
123 + EOF
124 + p4 passwd -P secret $name
125 }
126
127 p4_grant_admin() {
146 - name=$1
147 - p4 protect -o |\
148 - awk "{print}END{print \" admin user $name * //depot/...\"}" |\
149 - p4 protect -i
128 + name=$1 &&
129 + {
130 + p4 protect -o &&
131 + echo " admin user $name * //depot/..."
132 + } | p4 protect -i
133 }
134
135 p4_check_commit_author() {
153 - file=$1
154 - user=$2
155 - if p4 changes -m 1 //depot/$file | grep $user > /dev/null ; then
156 - return 0
157 - else
158 - echo "file $file not modified by user $user" 1>&2
159 - return 1
160 - fi
136 + file=$1 user=$2 &&
137 + p4 changes -m 1 //depot/$file | grep -q $user
138 }
139
140 make_change_by_user() {
@@ -174,15 +151,17 @@ test_expect_success 'preserve users' '
151 p4_grant_admin alice &&
152 "$GITP4" clone --dest="$git" //depot &&
153 test_when_finished cleanup_git &&
177 - cd "$git" &&
178 - echo "username: a change by alice" >> file1 &&
179 - echo "username: a change by bob" >> file2 &&
180 - git commit --author "Alice <alice@localhost>" -m "a change by alice" file1 &&
181 - git commit --author "Bob <bob@localhost>" -m "a change by bob" file2 &&
182 - git config git-p4.skipSubmitEditCheck true &&
183 - P4EDITOR=touch P4USER=alice P4PASSWD=secret "$GITP4" commit --preserve-user &&
184 - p4_check_commit_author file1 alice &&
185 - p4_check_commit_author file2 bob
154 + (
155 + cd "$git" &&
156 + echo "username: a change by alice" >>file1 &&
157 + echo "username: a change by bob" >>file2 &&
158 + git commit --author "Alice <alice@localhost>" -m "a change by alice" file1 &&
159 + git commit --author "Bob <bob@localhost>" -m "a change by bob" file2 &&
160 + git config git-p4.skipSubmitEditCheck true &&
161 + P4EDITOR=touch P4USER=alice P4PASSWD=secret "$GITP4" commit --preserve-user &&
162 + p4_check_commit_author file1 alice &&
163 + p4_check_commit_author file2 bob
164 + )
165 '
166
167 # Test username support, submitting as bob, who lacks admin rights. Should
@@ -190,32 +169,37 @@ test_expect_success 'preserve users' '
169 test_expect_success 'refuse to preserve users without perms' '
170 "$GITP4" clone --dest="$git" //depot &&
171 test_when_finished cleanup_git &&
193 - cd "$git" &&
194 - git config git-p4.skipSubmitEditCheck true &&
195 - echo "username-noperms: a change by alice" >> file1 &&
196 - git commit --author "Alice <alice@localhost>" -m "perms: a change by alice" file1 &&
197 - ! P4EDITOR=touch P4USER=bob P4PASSWD=secret "$GITP4" commit --preserve-user &&
198 - ! git diff --exit-code HEAD..p4/master > /dev/null
172 + (
173 + cd "$git" &&
174 + git config git-p4.skipSubmitEditCheck true &&
175 + echo "username-noperms: a change by alice" >>file1 &&
176 + git commit --author "Alice <alice@localhost>" -m "perms: a change by alice" file1 &&
177 + P4EDITOR=touch P4USER=bob P4PASSWD=secret test_must_fail "$GITP4" commit --preserve-user &&
178 + test_must_fail git diff --exit-code HEAD..p4/master
179 + )
180 '
181
182 # What happens with unknown author? Without allowMissingP4Users it should fail.
183 test_expect_success 'preserve user where author is unknown to p4' '
184 "$GITP4" clone --dest="$git" //depot &&
185 test_when_finished cleanup_git &&
205 - cd "$git" &&
206 - git config git-p4.skipSubmitEditCheck true &&
207 - echo "username-bob: a change by bob" >> file1 &&
208 - git commit --author "Bob <bob@localhost>" -m "preserve: a change by bob" file1 &&
209 - echo "username-unknown: a change by charlie" >> file1 &&
210 - git commit --author "Charlie <charlie@localhost>" -m "preserve: a change by charlie" file1 &&
211 - ! P4EDITOR=touch P4USER=alice P4PASSWD=secret "$GITP4" commit --preserve-user &&
212 - ! git diff --exit-code HEAD..p4/master > /dev/null &&
213 - echo "$0: repeat with allowMissingP4Users enabled" &&
214 - git config git-p4.allowMissingP4Users true &&
215 - git config git-p4.preserveUser true &&
216 - P4EDITOR=touch P4USER=alice P4PASSWD=secret "$GITP4" commit &&
217 - git diff --exit-code HEAD..p4/master > /dev/null &&
218 - p4_check_commit_author file1 alice
186 + (
187 + cd "$git" &&
188 + git config git-p4.skipSubmitEditCheck true &&
189 + echo "username-bob: a change by bob" >>file1 &&
190 + git commit --author "Bob <bob@localhost>" -m "preserve: a change by bob" file1 &&
191 + echo "username-unknown: a change by charlie" >>file1 &&
192 + git commit --author "Charlie <charlie@localhost>" -m "preserve: a change by charlie" file1 &&
193 + P4EDITOR=touch P4USER=alice P4PASSWD=secret test_must_fail "$GITP4" commit --preserve-user &&
194 + test_must_fail git diff --exit-code HEAD..p4/master &&
195 +
196 + echo "$0: repeat with allowMissingP4Users enabled" &&
197 + git config git-p4.allowMissingP4Users true &&
198 + git config git-p4.preserveUser true &&
199 + P4EDITOR=touch P4USER=alice P4PASSWD=secret "$GITP4" commit &&
200 + git diff --exit-code HEAD..p4/master &&
201 + p4_check_commit_author file1 alice
202 + )
203 '
204
205 # If we're *not* using --preserve-user, git-p4 should warn if we're submitting
@@ -225,33 +209,35 @@ test_expect_success 'preserve user where author is unknown to p4' '
209 test_expect_success 'not preserving user with mixed authorship' '
210 "$GITP4" clone --dest="$git" //depot &&
211 test_when_finished cleanup_git &&
228 - cd "$git" &&
229 - git config git-p4.skipSubmitEditCheck true &&
230 - p4_add_user derek Derek &&
231 -
232 - make_change_by_user usernamefile3 Derek derek@localhost &&
233 - P4EDITOR=cat P4USER=alice P4PASSWD=secret "$GITP4" commit >actual &&
234 - grep "git author derek@localhost does not match" actual &&
235 -
236 - make_change_by_user usernamefile3 Charlie charlie@localhost &&
237 - P4EDITOR=cat P4USER=alice P4PASSWD=secret "$GITP4" commit >actual &&
238 - grep "git author charlie@localhost does not match" actual &&
239 -
240 - make_change_by_user usernamefile3 alice alice@localhost &&
241 - P4EDITOR=cat P4USER=alice P4PASSWD=secret "$GITP4" commit >actual &&
242 - ! grep "git author.*does not match" actual &&
243 -
244 - git config git-p4.skipUserNameCheck true &&
245 - make_change_by_user usernamefile3 Charlie charlie@localhost &&
246 - P4EDITOR=cat P4USER=alice P4PASSWD=secret "$GITP4" commit >actual &&
247 - ! grep "git author.*does not match" actual &&
248 -
249 - p4_check_commit_author usernamefile3 alice
212 + (
213 + cd "$git" &&
214 + git config git-p4.skipSubmitEditCheck true &&
215 + p4_add_user derek Derek &&
216 +
217 + make_change_by_user usernamefile3 Derek derek@localhost &&
218 + P4EDITOR=cat P4USER=alice P4PASSWD=secret "$GITP4" commit |\
219 + grep "git author derek@localhost does not match" &&
220 +
221 + make_change_by_user usernamefile3 Charlie charlie@localhost &&
222 + P4EDITOR=cat P4USER=alice P4PASSWD=secret "$GITP4" commit |\
223 + grep "git author charlie@localhost does not match" &&
224 +
225 + make_change_by_user usernamefile3 alice alice@localhost &&
226 + P4EDITOR=cat P4USER=alice P4PASSWD=secret "$GITP4" |\
227 + test_must_fail grep "git author.*does not match" &&
228 +
229 + git config git-p4.skipUserNameCheck true &&
230 + make_change_by_user usernamefile3 Charlie charlie@localhost &&
231 + P4EDITOR=cat P4USER=alice P4PASSWD=secret "$GITP4" commit |\
232 + test_must_fail grep "git author.*does not match" &&
233 +
234 + p4_check_commit_author usernamefile3 alice
235 + )
236 '
237
238 marshal_dump() {
239 what=$1
254 - python -c 'import marshal, sys; d = marshal.load(sys.stdin); print d["'$what'"]'
240 + "$PYTHON_PATH" -c 'import marshal, sys; d = marshal.load(sys.stdin); print d["'$what'"]'
241 }
242
243 # Sleep a bit so that the top-most p4 change did not happen "now". Then
@@ -263,10 +249,12 @@ test_expect_success 'initial import time from top change time' '
249 sleep 3 &&
250 "$GITP4" clone --dest="$git" //depot &&
251 test_when_finished cleanup_git &&
266 - cd "$git" &&
267 - gittime=$(git show -s --raw --pretty=format:%at HEAD) &&
268 - echo $p4time $gittime &&
269 - test $p4time = $gittime
252 + (
253 + cd "$git" &&
254 + gittime=$(git show -s --raw --pretty=format:%at HEAD) &&
255 + echo $p4time $gittime &&
256 + test $p4time = $gittime
257 + )
258 '
259
260 # Rename a file and confirm that rename is not detected in P4.
@@ -279,47 +267,49 @@ test_expect_success 'initial import time from top change time' '
267 test_expect_success 'detect renames' '
268 "$GITP4" clone --dest="$git" //depot@all &&
269 test_when_finished cleanup_git &&
282 - cd "$git" &&
283 - git config git-p4.skipSubmitEditCheck true &&
284 -
285 - git mv file1 file4 &&
286 - git commit -a -m "Rename file1 to file4" &&
287 - git diff-tree -r -M HEAD &&
288 - "$GITP4" submit &&
289 - p4 filelog //depot/file4 &&
290 - ! p4 filelog //depot/file4 | grep -q "branch from" &&
291 -
292 - git mv file4 file5 &&
293 - git commit -a -m "Rename file4 to file5" &&
294 - git diff-tree -r -M HEAD &&
295 - git config git-p4.detectRenames true &&
296 - "$GITP4" submit &&
297 - p4 filelog //depot/file5 &&
298 - p4 filelog //depot/file5 | grep -q "branch from //depot/file4" &&
299 -
300 - git mv file5 file6 &&
301 - echo update >>file6 &&
302 - git add file6 &&
303 - git commit -a -m "Rename file5 to file6 with changes" &&
304 - git diff-tree -r -M HEAD &&
305 - level=$(git diff-tree -r -M HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/R0*//") &&
306 - test -n "$level" && test "$level" -gt 0 && test "$level" -lt 98 &&
307 - git config git-p4.detectRenames $((level + 2)) &&
308 - "$GITP4" submit &&
309 - p4 filelog //depot/file6 &&
310 - ! p4 filelog //depot/file6 | grep -q "branch from" &&
311 -
312 - git mv file6 file7 &&
313 - echo update >>file7 &&
314 - git add file7 &&
315 - git commit -a -m "Rename file6 to file7 with changes" &&
316 - git diff-tree -r -M HEAD &&
317 - level=$(git diff-tree -r -M HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/R0*//") &&
318 - test -n "$level" && test "$level" -gt 2 && test "$level" -lt 100 &&
319 - git config git-p4.detectRenames $((level - 2)) &&
320 - "$GITP4" submit &&
321 - p4 filelog //depot/file7 &&
322 - p4 filelog //depot/file7 | grep -q "branch from //depot/file6"
270 + (
271 + cd "$git" &&
272 + git config git-p4.skipSubmitEditCheck true &&
273 +
274 + git mv file1 file4 &&
275 + git commit -a -m "Rename file1 to file4" &&
276 + git diff-tree -r -M HEAD &&
277 + "$GITP4" submit &&
278 + p4 filelog //depot/file4 &&
279 + p4 filelog //depot/file4 | test_must_fail grep -q "branch from" &&
280 +
281 + git mv file4 file5 &&
282 + git commit -a -m "Rename file4 to file5" &&
283 + git diff-tree -r -M HEAD &&
284 + git config git-p4.detectRenames true &&
285 + "$GITP4" submit &&
286 + p4 filelog //depot/file5 &&
287 + p4 filelog //depot/file5 | grep -q "branch from //depot/file4" &&
288 +
289 + git mv file5 file6 &&
290 + echo update >>file6 &&
291 + git add file6 &&
292 + git commit -a -m "Rename file5 to file6 with changes" &&
293 + git diff-tree -r -M HEAD &&
294 + level=$(git diff-tree -r -M HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/R0*//") &&
295 + test -n "$level" && test "$level" -gt 0 && test "$level" -lt 98 &&
296 + git config git-p4.detectRenames $(($level + 2)) &&
297 + "$GITP4" submit &&
298 + p4 filelog //depot/file6 &&
299 + p4 filelog //depot/file6 | test_must_fail grep -q "branch from" &&
300 +
301 + git mv file6 file7 &&
302 + echo update >>file7 &&
303 + git add file7 &&
304 + git commit -a -m "Rename file6 to file7 with changes" &&
305 + git diff-tree -r -M HEAD &&
306 + level=$(git diff-tree -r -M HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/R0*//") &&
307 + test -n "$level" && test "$level" -gt 2 && test "$level" -lt 100 &&
308 + git config git-p4.detectRenames $(($level - 2)) &&
309 + "$GITP4" submit &&
310 + p4 filelog //depot/file7 &&
311 + p4 filelog //depot/file7 | grep -q "branch from //depot/file6"
312 + )
313 '
314
315 # Copy a file and confirm that copy is not detected in P4.
@@ -336,141 +326,79 @@ test_expect_success 'detect renames' '
326 test_expect_success 'detect copies' '
327 "$GITP4" clone --dest="$git" //depot@all &&
328 test_when_finished cleanup_git &&
339 - cd "$git" &&
340 - git config git-p4.skipSubmitEditCheck true &&
341 -
342 - cp file2 file8 &&
343 - git add file8 &&
344 - git commit -a -m "Copy file2 to file8" &&
345 - git diff-tree -r -C HEAD &&
346 - "$GITP4" submit &&
347 - p4 filelog //depot/file8 &&
348 - ! p4 filelog //depot/file8 | grep -q "branch from" &&
349 -
350 - cp file2 file9 &&
351 - git add file9 &&
352 - git commit -a -m "Copy file2 to file9" &&
353 - git diff-tree -r -C HEAD &&
354 - git config git-p4.detectCopies true &&
355 - "$GITP4" submit &&
356 - p4 filelog //depot/file9 &&
357 - ! p4 filelog //depot/file9 | grep -q "branch from" &&
358 -
359 - echo "file2" >>file2 &&
360 - cp file2 file10 &&
361 - git add file2 file10 &&
362 - git commit -a -m "Modify and copy file2 to file10" &&
363 - git diff-tree -r -C HEAD &&
364 - "$GITP4" submit &&
365 - p4 filelog //depot/file10 &&
366 - p4 filelog //depot/file10 | grep -q "branch from //depot/file" &&
367 -
368 - cp file2 file11 &&
369 - git add file11 &&
370 - git commit -a -m "Copy file2 to file11" &&
371 - git diff-tree -r -C --find-copies-harder HEAD &&
372 - src=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f2) &&
373 - test "$src" = file10 &&
374 - git config git-p4.detectCopiesHarder true &&
375 - "$GITP4" submit &&
376 - p4 filelog //depot/file11 &&
377 - p4 filelog //depot/file11 | grep -q "branch from //depot/file" &&
378 -
379 - cp file2 file12 &&
380 - echo "some text" >>file12 &&
381 - git add file12 &&
382 - git commit -a -m "Copy file2 to file12 with changes" &&
383 - git diff-tree -r -C --find-copies-harder HEAD &&
384 - level=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/C0*//") &&
385 - test -n "$level" && test "$level" -gt 0 && test "$level" -lt 98 &&
386 - src=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f2) &&
387 - test "$src" = file10 &&
388 - git config git-p4.detectCopies $((level + 2)) &&
389 - "$GITP4" submit &&
390 - p4 filelog //depot/file12 &&
391 - ! p4 filelog //depot/file12 | grep -q "branch from" &&
392 -
393 - cp file2 file13 &&
394 - echo "different text" >>file13 &&
395 - git add file13 &&
396 - git commit -a -m "Copy file2 to file13 with changes" &&
397 - git diff-tree -r -C --find-copies-harder HEAD &&
398 - level=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/C0*//") &&
399 - test -n "$level" && test "$level" -gt 2 && test "$level" -lt 100 &&
400 - src=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f2) &&
401 - test "$src" = file10 &&
402 - git config git-p4.detectCopies $((level - 2)) &&
403 - "$GITP4" submit &&
404 - p4 filelog //depot/file13 &&
405 - p4 filelog //depot/file13 | grep -q "branch from //depot/file"
406 -'
407 -
408 -# Create a simple branch structure in P4 depot to check if it is correctly
409 -# cloned.
410 -test_expect_success 'add simple p4 branches' '
411 - cd "$cli" &&
412 - mkdir branch1 &&
413 - cd branch1 &&
414 - echo file1 >file1 &&
415 - echo file2 >file2 &&
416 - p4 add file1 file2 &&
417 - p4 submit -d "branch1" &&
418 - p4 integrate //depot/branch1/... //depot/branch2/... &&
419 - p4 submit -d "branch2" &&
420 - echo file3 >file3 &&
421 - p4 add file3 &&
422 - p4 submit -d "add file3 in branch1" &&
423 - p4 open file2 &&
424 - echo update >>file2 &&
425 - p4 submit -d "update file2 in branch1" &&
426 - p4 integrate //depot/branch1/... //depot/branch3/... &&
427 - p4 submit -d "branch3" &&
428 - cd "$TRASH_DIRECTORY"
429 -'
430 -
431 -# Configure branches through git-config and clone them.
432 -# All files are tested to make sure branches were cloned correctly.
433 -# Finally, make an update to branch1 on P4 side to check if it is imported
434 -# correctly by git-p4.
435 -test_expect_success 'git-p4 clone simple branches' '
436 - test_when_finished cleanup_git &&
437 - test_create_repo "$git" &&
438 - cd "$git" &&
439 - git config git-p4.branchList branch1:branch2 &&
440 - git config --add git-p4.branchList branch1:branch3 &&
441 - "$GITP4" clone --dest=. --detect-branches //depot@all &&
442 - git log --all --graph --decorate --stat &&
443 - git reset --hard p4/depot/branch1 &&
444 - test -f file1 &&
445 - test -f file2 &&
446 - test -f file3 &&
447 - grep -q update file2 &&
448 - git reset --hard p4/depot/branch2 &&
449 - test -f file1 &&
450 - test -f file2 &&
451 - test ! -f file3 &&
452 - ! grep -q update file2 &&
453 - git reset --hard p4/depot/branch3 &&
454 - test -f file1 &&
455 - test -f file2 &&
456 - test -f file3 &&
457 - grep -q update file2 &&
458 - cd "$cli" &&
459 - cd branch1 &&
460 - p4 edit file2 &&
461 - echo file2_ >>file2 &&
462 - p4 submit -d "update file2 in branch1" &&
463 - cd "$git" &&
464 - git reset --hard p4/depot/branch1 &&
465 - "$GITP4" rebase &&
466 - grep -q file2_ file2
329 + (
330 + cd "$git" &&
331 + git config git-p4.skipSubmitEditCheck true &&
332 +
333 + cp file2 file8 &&
334 + git add file8 &&
335 + git commit -a -m "Copy file2 to file8" &&
336 + git diff-tree -r -C HEAD &&
337 + "$GITP4" submit &&
338 + p4 filelog //depot/file8 &&
339 + p4 filelog //depot/file8 | test_must_fail grep -q "branch from" &&
340 +
341 + cp file2 file9 &&
342 + git add file9 &&
343 + git commit -a -m "Copy file2 to file9" &&
344 + git diff-tree -r -C HEAD &&
345 + git config git-p4.detectCopies true &&
346 + "$GITP4" submit &&
347 + p4 filelog //depot/file9 &&
348 + p4 filelog //depot/file9 | test_must_fail grep -q "branch from" &&
349 +
350 + echo "file2" >>file2 &&
351 + cp file2 file10 &&
352 + git add file2 file10 &&
353 + git commit -a -m "Modify and copy file2 to file10" &&
354 + git diff-tree -r -C HEAD &&
355 + "$GITP4" submit &&
356 + p4 filelog //depot/file10 &&
357 + p4 filelog //depot/file10 | grep -q "branch from //depot/file" &&
358 +
359 + cp file2 file11 &&
360 + git add file11 &&
361 + git commit -a -m "Copy file2 to file11" &&
362 + git diff-tree -r -C --find-copies-harder HEAD &&
363 + src=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f2) &&
364 + test "$src" = file10 &&
365 + git config git-p4.detectCopiesHarder true &&
366 + "$GITP4" submit &&
367 + p4 filelog //depot/file11 &&
368 + p4 filelog //depot/file11 | grep -q "branch from //depot/file" &&
369 +
370 + cp file2 file12 &&
371 + echo "some text" >>file12 &&
372 + git add file12 &&
373 + git commit -a -m "Copy file2 to file12 with changes" &&
374 + git diff-tree -r -C --find-copies-harder HEAD &&
375 + level=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/C0*//") &&
376 + test -n "$level" && test "$level" -gt 0 && test "$level" -lt 98 &&
377 + src=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f2) &&
378 + test "$src" = file10 &&
379 + git config git-p4.detectCopies $(($level + 2)) &&
380 + "$GITP4" submit &&
381 + p4 filelog //depot/file12 &&
382 + p4 filelog //depot/file12 | test_must_fail grep -q "branch from" &&
383 +
384 + cp file2 file13 &&
385 + echo "different text" >>file13 &&
386 + git add file13 &&
387 + git commit -a -m "Copy file2 to file13 with changes" &&
388 + git diff-tree -r -C --find-copies-harder HEAD &&
389 + level=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/C0*//") &&
390 + test -n "$level" && test "$level" -gt 2 && test "$level" -lt 100 &&
391 + src=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f2) &&
392 + test "$src" = file10 &&
393 + git config git-p4.detectCopies $(($level - 2)) &&
394 + "$GITP4" submit &&
395 + p4 filelog //depot/file13 &&
396 + p4 filelog //depot/file13 | grep -q "branch from //depot/file"
397 + )
398 '
399
469 -test_expect_success 'shutdown' '
470 - pid=`pgrep -f p4d` &&
471 - test -n "$pid" &&
472 - test_debug "ps wl `echo $pid`" &&
473 - kill $pid
400 +test_expect_success 'kill p4d' '
401 + kill_p4d
402 '
403
404 test_done
t/t9801-git-p4-branch.sh new
+233
@@ -0,0 +1,233 @@
1 +#!/bin/sh
2 +
3 +test_description='git-p4 p4 branching tests'
4 +
5 +. ./lib-git-p4.sh
6 +
7 +test_expect_success 'start p4d' '
8 + start_p4d
9 +'
10 +
11 +#
12 +# 1: //depot/main/f1
13 +# 2: //depot/main/f2
14 +# 3: integrate //depot/main/... -> //depot/branch1/...
15 +# 4: //depot/main/f4
16 +# 5: //depot/branch1/f5
17 +# .: named branch branch2
18 +# 6: integrate -b branch2
19 +# 7: //depot/branch2/f7
20 +# 8: //depot/main/f8
21 +#
22 +test_expect_success 'basic p4 branches' '
23 + (
24 + cd "$cli" &&
25 + mkdir -p main &&
26 +
27 + echo f1 >main/f1 &&
28 + p4 add main/f1 &&
29 + p4 submit -d "main/f1" &&
30 +
31 + echo f2 >main/f2 &&
32 + p4 add main/f2 &&
33 + p4 submit -d "main/f2" &&
34 +
35 + p4 integrate //depot/main/... //depot/branch1/... &&
36 + p4 submit -d "integrate main to branch1" &&
37 +
38 + echo f4 >main/f4 &&
39 + p4 add main/f4 &&
40 + p4 submit -d "main/f4" &&
41 +
42 + echo f5 >branch1/f5 &&
43 + p4 add branch1/f5 &&
44 + p4 submit -d "branch1/f5" &&
45 +
46 + p4 branch -i <<-EOF &&
47 + Branch: branch2
48 + View: //depot/main/... //depot/branch2/...
49 + EOF
50 +
51 + p4 integrate -b branch2 &&
52 + p4 submit -d "integrate main to branch2" &&
53 +
54 + echo f7 >branch2/f7 &&
55 + p4 add branch2/f7 &&
56 + p4 submit -d "branch2/f7" &&
57 +
58 + echo f8 >main/f8 &&
59 + p4 add main/f8 &&
60 + p4 submit -d "main/f8"
61 + )
62 +'
63 +
64 +test_expect_success 'import main, no branch detection' '
65 + test_when_finished cleanup_git &&
66 + "$GITP4" clone --dest="$git" //depot/main@all &&
67 + (
68 + cd "$git" &&
69 + git log --oneline --graph --decorate --all &&
70 + git rev-list master >wc &&
71 + test_line_count = 4 wc
72 + )
73 +'
74 +
75 +test_expect_success 'import branch1, no branch detection' '
76 + test_when_finished cleanup_git &&
77 + "$GITP4" clone --dest="$git" //depot/branch1@all &&
78 + (
79 + cd "$git" &&
80 + git log --oneline --graph --decorate --all &&
81 + git rev-list master >wc &&
82 + test_line_count = 2 wc
83 + )
84 +'
85 +
86 +test_expect_success 'import branch2, no branch detection' '
87 + test_when_finished cleanup_git &&
88 + "$GITP4" clone --dest="$git" //depot/branch2@all &&
89 + (
90 + cd "$git" &&
91 + git log --oneline --graph --decorate --all &&
92 + git rev-list master >wc &&
93 + test_line_count = 2 wc
94 + )
95 +'
96 +
97 +test_expect_success 'import depot, no branch detection' '
98 + test_when_finished cleanup_git &&
99 + "$GITP4" clone --dest="$git" //depot@all &&
100 + (
101 + cd "$git" &&
102 + git log --oneline --graph --decorate --all &&
103 + git rev-list master >wc &&
104 + test_line_count = 8 wc
105 + )
106 +'
107 +
108 +test_expect_success 'import depot, branch detection' '
109 + test_when_finished cleanup_git &&
110 + "$GITP4" clone --dest="$git" --detect-branches //depot@all &&
111 + (
112 + cd "$git" &&
113 +
114 + git log --oneline --graph --decorate --all &&
115 +
116 + # 4 main commits
117 + git rev-list master >wc &&
118 + test_line_count = 4 wc &&
119 +
120 + # 3 main, 1 integrate, 1 on branch2
121 + git rev-list p4/depot/branch2 >wc &&
122 + test_line_count = 5 wc &&
123 +
124 + # no branch1, since no p4 branch created for it
125 + test_must_fail git show-ref p4/depot/branch1
126 + )
127 +'
128 +
129 +test_expect_success 'import depot, branch detection, branchList branch definition' '
130 + test_when_finished cleanup_git &&
131 + test_create_repo "$git" &&
132 + (
133 + cd "$git" &&
134 + git config git-p4.branchList main:branch1 &&
135 + "$GITP4" clone --dest=. --detect-branches //depot@all &&
136 +
137 + git log --oneline --graph --decorate --all &&
138 +
139 + # 4 main commits
140 + git rev-list master >wc &&
141 + test_line_count = 4 wc &&
142 +
143 + # 3 main, 1 integrate, 1 on branch2
144 + git rev-list p4/depot/branch2 >wc &&
145 + test_line_count = 5 wc &&
146 +
147 + # 2 main, 1 integrate, 1 on branch1
148 + git rev-list p4/depot/branch1 >wc &&
149 + test_line_count = 4 wc
150 + )
151 +'
152 +
153 +test_expect_success 'restart p4d' '
154 + kill_p4d &&
155 + start_p4d
156 +'
157 +
158 +#
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/...
165 +#
166 +## Create a simple branch structure in P4 depot.
167 +test_expect_success 'add simple p4 branches' '
168 + (
169 + cd "$cli" &&
170 + mkdir branch1 &&
171 + cd branch1 &&
172 + echo file1 >file1 &&
173 + echo file2 >file2 &&
174 + p4 add file1 file2 &&
175 + p4 submit -d "branch1" &&
176 + p4 integrate //depot/branch1/... //depot/branch2/... &&
177 + p4 submit -d "branch2" &&
178 + echo file3 >file3 &&
179 + p4 add file3 &&
180 + p4 submit -d "add file3 in branch1" &&
181 + p4 open file2 &&
182 + echo update >>file2 &&
183 + p4 submit -d "update file2 in branch1" &&
184 + p4 integrate //depot/branch1/... //depot/branch3/... &&
185 + p4 submit -d "branch3"
186 + )
187 +'
188 +
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" &&
196 + (
197 + cd "$git" &&
198 + git config git-p4.branchList branch1:branch2 &&
199 + git config --add git-p4.branchList branch1:branch3 &&
200 + "$GITP4" clone --dest=. --detect-branches //depot@all &&
201 + git log --all --graph --decorate --stat &&
202 + git reset --hard p4/depot/branch1 &&
203 + test -f file1 &&
204 + test -f file2 &&
205 + test -f file3 &&
206 + grep -q update file2 &&
207 + git reset --hard p4/depot/branch2 &&
208 + test -f file1 &&
209 + test -f file2 &&
210 + test ! -f file3 &&
211 + test_must_fail grep -q update file2 &&
212 + git reset --hard p4/depot/branch3 &&
213 + test -f file1 &&
214 + test -f file2 &&
215 + test -f file3 &&
216 + grep -q update file2 &&
217 + cd "$cli" &&
218 + cd branch1 &&
219 + p4 edit file2 &&
220 + echo file2_ >>file2 &&
221 + p4 submit -d "update file2 in branch3" &&
222 + cd "$git" &&
223 + git reset --hard p4/depot/branch1 &&
224 + "$GITP4" rebase &&
225 + grep -q file2_ file2
226 + )
227 +'
228 +
229 +test_expect_success 'kill p4d' '
230 + kill_p4d
231 +'
232 +
233 +test_done