#!/bin/sh global test_description := ''git p4 tests'' source ./lib-git-p4.sh test_expect_success 'start p4d' ' start_p4d ' test_expect_success 'add p4 files' ' ( cd "$cli" && echo file1 >file1 && p4 add file1 && p4 submit -d "file1" && echo file2 >file2 && p4 add file2 && p4 submit -d "file2" ) ' test_expect_success 'basic git p4 clone' ' git p4 clone --dest="$git" //depot && test_when_finished cleanup_git && ( cd "$git" && git log --oneline >lines && test_line_count = 1 lines ) ' test_expect_success 'depot typo error' ' test_must_fail git p4 clone --dest="$git" /depot 2>errs && grep "Depot paths must start with" errs ' test_expect_success 'git p4 clone @all' ' git p4 clone --dest="$git" //depot@all && test_when_finished cleanup_git && ( cd "$git" && git log --oneline >lines && test_line_count = 2 lines ) ' test_expect_success 'git p4 sync uninitialized repo' ' test_create_repo "$git" && test_when_finished cleanup_git && ( cd "$git" && test_must_fail git p4 sync 2>errs && test_i18ngrep "Perhaps you never did" errs ) ' # # Create a git repo by hand. Add a commit so that HEAD is valid. # Test imports a new p4 repository into a new git branch. # test_expect_success 'git p4 sync new branch' ' test_create_repo "$git" && test_when_finished cleanup_git && ( cd "$git" && test_commit head && git p4 sync --branch=refs/remotes/p4/depot //depot@all && git log --oneline p4/depot >lines && test_line_count = 2 lines ) ' test_expect_success 'clone two dirs' ' ( cd "$cli" && mkdir sub1 sub2 && echo sub1/f1 >sub1/f1 && echo sub2/f2 >sub2/f2 && p4 add sub1/f1 && p4 submit -d "sub1/f1" && p4 add sub2/f2 && p4 submit -d "sub2/f2" ) && git p4 clone --dest="$git" //depot/sub1 //depot/sub2 && test_when_finished cleanup_git && ( cd "$git" && git ls-files >lines && test_line_count = 2 lines && git log --oneline p4/master >lines && test_line_count = 1 lines ) ' test_expect_success 'clone two dirs, @all' ' ( cd "$cli" && echo sub1/f3 >sub1/f3 && p4 add sub1/f3 && p4 submit -d "sub1/f3" ) && git p4 clone --dest="$git" //depot/sub1@all //depot/sub2@all && test_when_finished cleanup_git && ( cd "$git" && git ls-files >lines && test_line_count = 3 lines && git log --oneline p4/master >lines && test_line_count = 3 lines ) ' test_expect_success 'clone two dirs, @all, conflicting files' ' ( cd "$cli" && echo sub2/f3 >sub2/f3 && p4 add sub2/f3 && p4 submit -d "sub2/f3" ) && git p4 clone --dest="$git" //depot/sub1@all //depot/sub2@all && test_when_finished cleanup_git && ( cd "$git" && git ls-files >lines && test_line_count = 3 lines && git log --oneline p4/master >lines && test_line_count = 4 lines && echo sub2/f3 >expected && test_cmp expected f3 ) ' global revision_ranges := '"2000/01/01,#head \ 1,2080/01/01 \ 2000/01/01,2080/01/01 \ 2000/01/01,1000 \ 1,1000'" test_expect_success 'clone using non-numeric revision ranges' ' test_when_finished cleanup_git && for r in $revision_ranges do rm -fr "$git" && test ! -d "$git" && git p4 clone --dest="$git" //depot@$r && ( cd "$git" && git ls-files >lines && test_line_count = 6 lines ) done ' test_expect_success 'clone with date range, excluding some changes' ' test_when_finished cleanup_git && before=$(date +%Y/%m/%d:%H:%M:%S) && sleep 2 && ( cd "$cli" && :>date_range_test && p4 add date_range_test && p4 submit -d "Adding file" ) && git p4 clone --dest="$git" //depot@1,$before && ( cd "$git" && test_path_is_missing date_range_test ) ' test_expect_success 'exit when p4 fails to produce marshaled output' ' mkdir badp4dir && test_when_finished "rm badp4dir/p4 && rmdir badp4dir" && cat >badp4dir/p4 <<-EOF && #!$SHELL_PATH exit 1 EOF chmod 755 badp4dir/p4 && ( PATH="$TRASH_DIRECTORY/badp4dir:$PATH" && export PATH && test_expect_code 1 git p4 clone --dest="$git" //depot >errs 2>&1 ) && cat errs && test_i18ngrep ! Traceback errs ' # Hide a file from p4d, make sure we catch its complaint. This won't fail in # p4 changes, files, or describe; just in p4 print. If P4CLIENT is unset, the # message will include "Librarian checkout". test_expect_success 'exit gracefully for p4 server errors' ' test_when_finished "mv \"$db\"/depot/file1,v,hidden \"$db\"/depot/file1,v" && mv "$db"/depot/file1,v "$db"/depot/file1,v,hidden && test_when_finished cleanup_git && test_expect_code 1 git p4 clone --dest="$git" //depot@1 >out 2>err && test_i18ngrep "Error from p4 print" err ' test_expect_success 'clone --bare should make a bare repository' ' rm -rf "$git" && git p4 clone --dest="$git" --bare //depot && test_when_finished cleanup_git && ( cd "$git" && test_path_is_missing .git && git config --get --bool core.bare true && git rev-parse --verify refs/remotes/p4/master && git rev-parse --verify refs/remotes/p4/HEAD && git rev-parse --verify refs/heads/master && git rev-parse --verify HEAD ) ' # Sleep a bit so that the top-most p4 change did not happen "now". Then # import the repo and make sure that the initial import has the same time # as the top-most change. test_expect_success 'initial import time from top change time' ' p4change=$(p4 -G changes -m 1 //depot/... | marshal_dump change) && p4time=$(p4 -G changes -m 1 //depot/... | marshal_dump time) && sleep 3 && git p4 clone --dest="$git" //depot && test_when_finished cleanup_git && ( cd "$git" && gittime=$(git show -s --raw --pretty=format:%at HEAD) && echo $p4time $gittime && test $p4time = $gittime ) ' test_expect_success 'unresolvable host in P4PORT should display error' ' test_when_finished cleanup_git && git p4 clone --dest="$git" //depot && ( cd "$git" && P4PORT=nosuchhost:65537 && export P4PORT && test_expect_code 1 git p4 sync >out 2>err && grep "connect to nosuchhost" err ) ' test_expect_success 'submit from detached head' ' test_when_finished cleanup_git && git p4 clone --dest="$git" //depot && ( cd "$git" && git checkout p4/master && >detached_head_test && git add detached_head_test && git commit -m "add detached_head" && git config git-p4.skipSubmitEdit true && git p4 submit && git p4 rebase && git log p4/master | grep detached_head ) ' 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 tests">)} 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 <"add p4 files">)} { (SQ <"\n"> <"\t(\n"> <"\t\tcd \"$cli\" &&\n"> <"\t\techo file1 >file1 &&\n"> <"\t\tp4 add file1 &&\n"> <"\t\tp4 submit -d \"file1\" &&\n"> <"\t\techo file2 >file2 &&\n"> <"\t\tp4 add file2 &&\n"> <"\t\tp4 submit -d \"file2\"\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"basic git p4 clone">)} { (SQ <"\n"> <"\tgit p4 clone --dest=\"$git\" //depot &&\n"> <"\ttest_when_finished cleanup_git &&\n"> <"\t(\n"> <"\t\tcd \"$git\" &&\n"> <"\t\tgit log --oneline >lines &&\n"> <"\t\ttest_line_count = 1 lines\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"depot typo error">)} { (SQ <"\n"> <"\ttest_must_fail git p4 clone --dest=\"$git\" /depot 2>errs &&\n"> <"\tgrep \"Depot paths must start with\" errs\n"> ) } ) (C {(test_expect_success)} {(SQ <"git p4 clone @all">)} { (SQ <"\n"> <"\tgit p4 clone --dest=\"$git\" //depot@all &&\n"> <"\ttest_when_finished cleanup_git &&\n"> <"\t(\n"> <"\t\tcd \"$git\" &&\n"> <"\t\tgit log --oneline >lines &&\n"> <"\t\ttest_line_count = 2 lines\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"git p4 sync uninitialized repo">)} { (SQ <"\n"> <"\ttest_create_repo \"$git\" &&\n"> <"\ttest_when_finished cleanup_git &&\n"> <"\t(\n"> <"\t\tcd \"$git\" &&\n"> <"\t\ttest_must_fail git p4 sync 2>errs &&\n"> <"\t\ttest_i18ngrep \"Perhaps you never did\" errs\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"git p4 sync new branch">)} { (SQ <"\n"> <"\ttest_create_repo \"$git\" &&\n"> <"\ttest_when_finished cleanup_git &&\n"> <"\t(\n"> <"\t\tcd \"$git\" &&\n"> <"\t\ttest_commit head &&\n"> <"\t\tgit p4 sync --branch=refs/remotes/p4/depot //depot@all &&\n"> <"\t\tgit log --oneline p4/depot >lines &&\n"> <"\t\ttest_line_count = 2 lines\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"clone two dirs">)} { (SQ <"\n"> <"\t(\n"> <"\t\tcd \"$cli\" &&\n"> <"\t\tmkdir sub1 sub2 &&\n"> <"\t\techo sub1/f1 >sub1/f1 &&\n"> <"\t\techo sub2/f2 >sub2/f2 &&\n"> <"\t\tp4 add sub1/f1 &&\n"> <"\t\tp4 submit -d \"sub1/f1\" &&\n"> <"\t\tp4 add sub2/f2 &&\n"> <"\t\tp4 submit -d \"sub2/f2\"\n"> <"\t) &&\n"> <"\tgit p4 clone --dest=\"$git\" //depot/sub1 //depot/sub2 &&\n"> <"\ttest_when_finished cleanup_git &&\n"> <"\t(\n"> <"\t\tcd \"$git\" &&\n"> <"\t\tgit ls-files >lines &&\n"> <"\t\ttest_line_count = 2 lines &&\n"> <"\t\tgit log --oneline p4/master >lines &&\n"> <"\t\ttest_line_count = 1 lines\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"clone two dirs, @all">)} { (SQ <"\n"> <"\t(\n"> <"\t\tcd \"$cli\" &&\n"> <"\t\techo sub1/f3 >sub1/f3 &&\n"> <"\t\tp4 add sub1/f3 &&\n"> <"\t\tp4 submit -d \"sub1/f3\"\n"> <"\t) &&\n"> <"\tgit p4 clone --dest=\"$git\" //depot/sub1@all //depot/sub2@all &&\n"> <"\ttest_when_finished cleanup_git &&\n"> <"\t(\n"> <"\t\tcd \"$git\" &&\n"> <"\t\tgit ls-files >lines &&\n"> <"\t\ttest_line_count = 3 lines &&\n"> <"\t\tgit log --oneline p4/master >lines &&\n"> <"\t\ttest_line_count = 3 lines\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"clone two dirs, @all, conflicting files">)} { (SQ <"\n"> <"\t(\n"> <"\t\tcd \"$cli\" &&\n"> <"\t\techo sub2/f3 >sub2/f3 &&\n"> <"\t\tp4 add sub2/f3 &&\n"> <"\t\tp4 submit -d \"sub2/f3\"\n"> <"\t) &&\n"> <"\tgit p4 clone --dest=\"$git\" //depot/sub1@all //depot/sub2@all &&\n"> <"\ttest_when_finished cleanup_git &&\n"> <"\t(\n"> <"\t\tcd \"$git\" &&\n"> <"\t\tgit ls-files >lines &&\n"> <"\t\ttest_line_count = 3 lines &&\n"> <"\t\tgit log --oneline p4/master >lines &&\n"> <"\t\ttest_line_count = 4 lines &&\n"> <"\t\techo sub2/f3 >expected &&\n"> <"\t\ttest_cmp expected f3\n"> <"\t)\n"> ) } ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:revision_ranges) op: Equal rhs: { (DQ ("2000/01/01,#head ") ("\t\t 1,2080/01/01 ") ("\t\t 2000/01/01,2080/01/01 ") ("\t\t 2000/01/01,1000 ") ("\t\t 1,1000") ) } spids: [230] ) ] spids: [230] ) (C {(test_expect_success)} {(SQ <"clone using non-numeric revision ranges">)} { (SQ <"\n"> <"\ttest_when_finished cleanup_git &&\n"> <"\tfor r in $revision_ranges\n"> <"\tdo\n"> <"\t\trm -fr \"$git\" &&\n"> <"\t\ttest ! -d \"$git\" &&\n"> <"\t\tgit p4 clone --dest=\"$git\" //depot@$r &&\n"> <"\t\t(\n"> <"\t\t\tcd \"$git\" &&\n"> <"\t\t\tgit ls-files >lines &&\n"> <"\t\t\ttest_line_count = 6 lines\n"> <"\t\t)\n"> <"\tdone\n"> ) } ) (C {(test_expect_success)} {(SQ <"clone with date range, excluding some changes">)} { (SQ <"\n"> <"\ttest_when_finished cleanup_git &&\n"> <"\tbefore=$(date +%Y/%m/%d:%H:%M:%S) &&\n"> <"\tsleep 2 &&\n"> <"\t(\n"> <"\t\tcd \"$cli\" &&\n"> <"\t\t:>date_range_test &&\n"> <"\t\tp4 add date_range_test &&\n"> <"\t\tp4 submit -d \"Adding file\"\n"> <"\t) &&\n"> <"\tgit p4 clone --dest=\"$git\" //depot@1,$before &&\n"> <"\t(\n"> <"\t\tcd \"$git\" &&\n"> <"\t\ttest_path_is_missing date_range_test\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"exit when p4 fails to produce marshaled output">)} { (SQ <"\n"> <"\tmkdir badp4dir &&\n"> <"\ttest_when_finished \"rm badp4dir/p4 && rmdir badp4dir\" &&\n"> <"\tcat >badp4dir/p4 <<-EOF &&\n"> <"\t#!$SHELL_PATH\n"> <"\texit 1\n"> <"\tEOF\n"> <"\tchmod 755 badp4dir/p4 &&\n"> <"\t(\n"> <"\t\tPATH=\"$TRASH_DIRECTORY/badp4dir:$PATH\" &&\n"> <"\t\texport PATH &&\n"> <"\t\ttest_expect_code 1 git p4 clone --dest=\"$git\" //depot >errs 2>&1\n"> <"\t) &&\n"> <"\tcat errs &&\n"> <"\ttest_i18ngrep ! Traceback errs\n"> ) } ) (C {(test_expect_success)} {(SQ <"exit gracefully for p4 server errors">)} { (SQ <"\n"> < "\ttest_when_finished \"mv \\\"$db\\\"/depot/file1,v,hidden \\\"$db\\\"/depot/file1,v\" &&\n" > <"\tmv \"$db\"/depot/file1,v \"$db\"/depot/file1,v,hidden &&\n"> <"\ttest_when_finished cleanup_git &&\n"> <"\ttest_expect_code 1 git p4 clone --dest=\"$git\" //depot@1 >out 2>err &&\n"> <"\ttest_i18ngrep \"Error from p4 print\" err\n"> ) } ) (C {(test_expect_success)} {(SQ <"clone --bare should make a bare repository">)} { (SQ <"\n"> <"\trm -rf \"$git\" &&\n"> <"\tgit p4 clone --dest=\"$git\" --bare //depot &&\n"> <"\ttest_when_finished cleanup_git &&\n"> <"\t(\n"> <"\t\tcd \"$git\" &&\n"> <"\t\ttest_path_is_missing .git &&\n"> <"\t\tgit config --get --bool core.bare true &&\n"> <"\t\tgit rev-parse --verify refs/remotes/p4/master &&\n"> <"\t\tgit rev-parse --verify refs/remotes/p4/HEAD &&\n"> <"\t\tgit rev-parse --verify refs/heads/master &&\n"> <"\t\tgit rev-parse --verify HEAD\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"initial import time from top change time">)} { (SQ <"\n"> <"\tp4change=$(p4 -G changes -m 1 //depot/... | marshal_dump change) &&\n"> <"\tp4time=$(p4 -G changes -m 1 //depot/... | marshal_dump time) &&\n"> <"\tsleep 3 &&\n"> <"\tgit p4 clone --dest=\"$git\" //depot &&\n"> <"\ttest_when_finished cleanup_git &&\n"> <"\t(\n"> <"\t\tcd \"$git\" &&\n"> <"\t\tgittime=$(git show -s --raw --pretty=format:%at HEAD) &&\n"> <"\t\techo $p4time $gittime &&\n"> <"\t\ttest $p4time = $gittime\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"unresolvable host in P4PORT should display error">)} { (SQ <"\n"> <"\ttest_when_finished cleanup_git &&\n"> <"\tgit p4 clone --dest=\"$git\" //depot &&\n"> <"\t(\n"> <"\t\tcd \"$git\" &&\n"> <"\t\tP4PORT=nosuchhost:65537 &&\n"> <"\t\texport P4PORT &&\n"> <"\t\ttest_expect_code 1 git p4 sync >out 2>err &&\n"> <"\t\tgrep \"connect to nosuchhost\" err\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"submit from detached head">)} { (SQ <"\n"> <"\ttest_when_finished cleanup_git &&\n"> <"\tgit p4 clone --dest=\"$git\" //depot &&\n"> <"\t(\n"> <"\t\tcd \"$git\" &&\n"> <"\t\tgit checkout p4/master &&\n"> <"\t\t>detached_head_test &&\n"> <"\t\tgit add detached_head_test &&\n"> <"\t\tgit commit -m \"add detached_head\" &&\n"> <"\t\tgit config git-p4.skipSubmitEdit true &&\n"> <"\t\tgit p4 submit &&\n"> <"\t\tgit p4 rebase &&\n"> <"\t\tgit log p4/master | grep detached_head\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"kill p4d">)} {(SQ <"\n"> <"\tkill_p4d\n">)}) (C {(test_done)}) ] )