#!/bin/sh global test_description := ''git p4 locked file behavior'' source ./lib-git-p4.sh test_expect_success 'start p4d' ' start_p4d ' # See # http://www.perforce.com/perforce/doc.current/manuals/p4sag/03_superuser.html#1088563 # for suggestions on how to configure "sitewide pessimistic locking" # where only one person can have a file open for edit at a time. test_expect_success 'init depot' ' ( cd "$cli" && echo "TypeMap: +l //depot/..." | p4 typemap -i && echo file1 >file1 && p4 add file1 && p4 submit -d "add file1" ) ' test_expect_success 'edit with lock not taken' ' test_when_finished cleanup_git && git p4 clone --dest="$git" //depot && ( cd "$git" && echo line2 >>file1 && git add file1 && git commit -m "line2 in file1" && git config git-p4.skipSubmitEdit true && git p4 submit ) ' test_expect_success 'add with lock not taken' ' test_when_finished cleanup_git && git p4 clone --dest="$git" //depot && ( cd "$git" && echo line1 >>add-lock-not-taken && git add add-lock-not-taken && git commit -m "add add-lock-not-taken" && git config git-p4.skipSubmitEdit true && git p4 submit --verbose ) ' proc lock_in_another_client { # build a different client global cli2 := ""$TRASH_DIRECTORY/cli2"" && mkdir -p $cli2 && test_when_finished "p4 client -f -d client2 && rm -rf \"$cli2\"" && shell { cd $cli2 && global P4CLIENT := 'client2' && global cli := $cli2 && client_view "//depot/... //client2/..." && p4 sync && p4 open file1 } } test_expect_failure 'edit with lock taken' ' lock_in_another_client && test_when_finished cleanup_git && test_when_finished "cd \"$cli\" && p4 sync -f file1" && git p4 clone --dest="$git" //depot && ( cd "$git" && echo line3 >>file1 && git add file1 && git commit -m "line3 in file1" && git config git-p4.skipSubmitEdit true && git p4 submit --verbose ) ' test_expect_failure 'delete with lock taken' ' lock_in_another_client && test_when_finished cleanup_git && test_when_finished "cd \"$cli\" && p4 sync -f file1" && git p4 clone --dest="$git" //depot && ( cd "$git" && git rm file1 && git commit -m "delete file1" && git config git-p4.skipSubmitEdit true && git p4 submit --verbose ) ' test_expect_failure 'chmod with lock taken' ' lock_in_another_client && test_when_finished cleanup_git && test_when_finished "cd \"$cli\" && p4 sync -f file1" && git p4 clone --dest="$git" //depot && ( cd "$git" && chmod +x file1 && git add file1 && git commit -m "chmod +x file1" && git config git-p4.skipSubmitEdit true && git p4 submit --verbose ) ' test_expect_success 'copy with lock taken' ' lock_in_another_client && test_when_finished cleanup_git && test_when_finished "cd \"$cli\" && p4 revert file2 && rm -f file2" && git p4 clone --dest="$git" //depot && ( cd "$git" && cp file1 file2 && git add file2 && git commit -m "cp file1 to file2" && git config git-p4.skipSubmitEdit true && git config git-p4.detectCopies true && git p4 submit --verbose ) ' test_expect_failure 'move with lock taken' ' lock_in_another_client && test_when_finished cleanup_git && test_when_finished "cd \"$cli\" && p4 sync file1 && rm -f file2" && git p4 clone --dest="$git" //depot && ( cd "$git" && git mv file1 file3 && git commit -m "mv file1 to file3" && git config git-p4.skipSubmitEdit true && git config git-p4.detectRenames true && git p4 submit --verbose ) ' test_expect_success 'kill p4d' ' kill_p4d ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"git p4 locked file behavior">)} spids: [4] ) ] spids: [4] ) (C {(.)} {(./lib-git-p4.sh)}) (C {(test_expect_success)} {(SQ <"start p4d">)} {(SQ <"\n"> <"\tstart_p4d\n">)}) (C {(test_expect_success)} {(SQ <"init depot">)} { (SQ <"\n"> <"\t(\n"> <"\t\tcd \"$cli\" &&\n"> <"\t\techo \"TypeMap: +l //depot/...\" | p4 typemap -i &&\n"> <"\t\techo file1 >file1 &&\n"> <"\t\tp4 add file1 &&\n"> <"\t\tp4 submit -d \"add file1\"\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"edit with lock not taken">)} { (SQ <"\n"> <"\ttest_when_finished cleanup_git &&\n"> <"\tgit p4 clone --dest=\"$git\" //depot &&\n"> <"\t(\n"> <"\t\tcd \"$git\" &&\n"> <"\t\techo line2 >>file1 &&\n"> <"\t\tgit add file1 &&\n"> <"\t\tgit commit -m \"line2 in file1\" &&\n"> <"\t\tgit config git-p4.skipSubmitEdit true &&\n"> <"\t\tgit p4 submit\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"add with lock not taken">)} { (SQ <"\n"> <"\ttest_when_finished cleanup_git &&\n"> <"\tgit p4 clone --dest=\"$git\" //depot &&\n"> <"\t(\n"> <"\t\tcd \"$git\" &&\n"> <"\t\techo line1 >>add-lock-not-taken &&\n"> <"\t\tgit add add-lock-not-taken &&\n"> <"\t\tgit commit -m \"add add-lock-not-taken\" &&\n"> <"\t\tgit config git-p4.skipSubmitEdit true &&\n"> <"\t\tgit p4 submit --verbose\n"> <"\t)\n"> ) } ) (FuncDef name: lock_in_another_client body: (BraceGroup children: [ (AndOr children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:cli2) op: Equal rhs: {(DQ ($ VSub_Name "$TRASH_DIRECTORY") (/cli2))} spids: [110] ) ] spids: [110] ) (AndOr children: [ (C {(mkdir)} {(-p)} {(DQ ($ VSub_Name "$cli2"))}) (AndOr children: [ (C {(test_when_finished)} { (DQ ("p4 client -f -d client2 && rm -rf ") (EscapedLiteralPart token: ) ($ VSub_Name "$cli2") (EscapedLiteralPart token:) ) } ) (Subshell child: (AndOr children: [ (C {(cd)} {(DQ ($ VSub_Name "$cli2"))}) (AndOr children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:P4CLIENT) op: Equal rhs: {(client2)} spids: [154] ) ] spids: [154] ) (AndOr children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:cli) op: Equal rhs: {(DQ ($ VSub_Name "$cli2"))} spids: [160] ) ] spids: [160] ) (AndOr children: [ (C {(client_view)} {(DQ ("//depot/... //client2/..."))}) (AndOr children: [ (C {(p4)} {(sync)}) (C {(p4)} {(open)} {(file1)}) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) spids: [142 191] ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] spids: [103] ) spids: [99 102] ) (C {(test_expect_failure)} {(SQ <"edit with lock taken">)} { (SQ <"\n"> <"\tlock_in_another_client &&\n"> <"\ttest_when_finished cleanup_git &&\n"> <"\ttest_when_finished \"cd \\\"$cli\\\" && p4 sync -f file1\" &&\n"> <"\tgit p4 clone --dest=\"$git\" //depot &&\n"> <"\t(\n"> <"\t\tcd \"$git\" &&\n"> <"\t\techo line3 >>file1 &&\n"> <"\t\tgit add file1 &&\n"> <"\t\tgit commit -m \"line3 in file1\" &&\n"> <"\t\tgit config git-p4.skipSubmitEdit true &&\n"> <"\t\tgit p4 submit --verbose\n"> <"\t)\n"> ) } ) (C {(test_expect_failure)} {(SQ <"delete with lock taken">)} { (SQ <"\n"> <"\tlock_in_another_client &&\n"> <"\ttest_when_finished cleanup_git &&\n"> <"\ttest_when_finished \"cd \\\"$cli\\\" && p4 sync -f file1\" &&\n"> <"\tgit p4 clone --dest=\"$git\" //depot &&\n"> <"\t(\n"> <"\t\tcd \"$git\" &&\n"> <"\t\tgit rm file1 &&\n"> <"\t\tgit commit -m \"delete file1\" &&\n"> <"\t\tgit config git-p4.skipSubmitEdit true &&\n"> <"\t\tgit p4 submit --verbose\n"> <"\t)\n"> ) } ) (C {(test_expect_failure)} {(SQ <"chmod with lock taken">)} { (SQ <"\n"> <"\tlock_in_another_client &&\n"> <"\ttest_when_finished cleanup_git &&\n"> <"\ttest_when_finished \"cd \\\"$cli\\\" && p4 sync -f file1\" &&\n"> <"\tgit p4 clone --dest=\"$git\" //depot &&\n"> <"\t(\n"> <"\t\tcd \"$git\" &&\n"> <"\t\tchmod +x file1 &&\n"> <"\t\tgit add file1 &&\n"> <"\t\tgit commit -m \"chmod +x file1\" &&\n"> <"\t\tgit config git-p4.skipSubmitEdit true &&\n"> <"\t\tgit p4 submit --verbose\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"copy with lock taken">)} { (SQ <"\n"> <"\tlock_in_another_client &&\n"> <"\ttest_when_finished cleanup_git &&\n"> <"\ttest_when_finished \"cd \\\"$cli\\\" && p4 revert file2 && rm -f file2\" &&\n"> <"\tgit p4 clone --dest=\"$git\" //depot &&\n"> <"\t(\n"> <"\t\tcd \"$git\" &&\n"> <"\t\tcp file1 file2 &&\n"> <"\t\tgit add file2 &&\n"> <"\t\tgit commit -m \"cp file1 to file2\" &&\n"> <"\t\tgit config git-p4.skipSubmitEdit true &&\n"> <"\t\tgit config git-p4.detectCopies true &&\n"> <"\t\tgit p4 submit --verbose\n"> <"\t)\n"> ) } ) (C {(test_expect_failure)} {(SQ <"move with lock taken">)} { (SQ <"\n"> <"\tlock_in_another_client &&\n"> <"\ttest_when_finished cleanup_git &&\n"> <"\ttest_when_finished \"cd \\\"$cli\\\" && p4 sync file1 && rm -f file2\" &&\n"> <"\tgit p4 clone --dest=\"$git\" //depot &&\n"> <"\t(\n"> <"\t\tcd \"$git\" &&\n"> <"\t\tgit mv file1 file3 &&\n"> <"\t\tgit commit -m \"mv file1 to file3\" &&\n"> <"\t\tgit config git-p4.skipSubmitEdit true &&\n"> <"\t\tgit config git-p4.detectRenames true &&\n"> <"\t\tgit p4 submit --verbose\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"kill p4d">)} {(SQ <"\n"> <"\tkill_p4d\n">)}) (C {(test_done)}) ] )