t / t9800-git-p4.shon commit Merge branch 'db/delta-applier' into db/text-delta (e9f3f8b)
   1#!/bin/sh
   2
   3test_description='git-p4 tests'
   4
   5. ./test-lib.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
  12GITP4=$GIT_BUILD_DIR/contrib/fast-import/git-p4
  13P4DPORT=10669
  14
  15db="$TRASH_DIRECTORY/db"
  16cli="$TRASH_DIRECTORY/cli"
  17git="$TRASH_DIRECTORY/git"
  18
  19test_debug 'echo p4d -q -d -r "$db" -p $P4DPORT'
  20test_expect_success setup '
  21        mkdir -p "$db" &&
  22        p4d -q -d -r "$db" -p $P4DPORT &&
  23        mkdir -p "$cli" &&
  24        mkdir -p "$git" &&
  25        export P4PORT=localhost:$P4DPORT
  26'
  27
  28test_expect_success 'add p4 files' '
  29        cd "$cli" &&
  30        p4 client -i <<-EOF &&
  31        Client: client
  32        Description: client
  33        Root: $cli
  34        View: //depot/... //client/...
  35        EOF
  36        export P4CLIENT=client &&
  37        echo file1 >file1 &&
  38        p4 add file1 &&
  39        p4 submit -d "file1" &&
  40        echo file2 >file2 &&
  41        p4 add file2 &&
  42        p4 submit -d "file2" &&
  43        cd "$TRASH_DIRECTORY"
  44'
  45
  46test_expect_success 'basic git-p4 clone' '
  47        "$GITP4" clone --dest="$git" //depot &&
  48        cd "$git" &&
  49        git log --oneline >lines &&
  50        test_line_count = 1 lines &&
  51        cd .. &&
  52        rm -rf "$git" && mkdir "$git"
  53'
  54
  55test_expect_success 'git-p4 clone @all' '
  56        "$GITP4" clone --dest="$git" //depot@all &&
  57        cd "$git" &&
  58        git log --oneline >lines &&
  59        test_line_count = 2 lines &&
  60        cd .. &&
  61        rm -rf "$git" && mkdir "$git"
  62'
  63
  64test_expect_success 'git-p4 sync uninitialized repo' '
  65        test_create_repo "$git" &&
  66        cd "$git" &&
  67        test_must_fail "$GITP4" sync &&
  68        rm -rf "$git" && mkdir "$git"
  69'
  70
  71#
  72# Create a git repo by hand.  Add a commit so that HEAD is valid.
  73# Test imports a new p4 repository into a new git branch.
  74#
  75test_expect_success 'git-p4 sync new branch' '
  76        test_create_repo "$git" &&
  77        cd "$git" &&
  78        test_commit head &&
  79        "$GITP4" sync --branch=refs/remotes/p4/depot //depot@all &&
  80        git log --oneline p4/depot >lines &&
  81        cat lines &&
  82        test_line_count = 2 lines &&
  83        cd .. &&
  84        rm -rf "$git" && mkdir "$git"
  85'
  86
  87test_expect_success 'exit when p4 fails to produce marshaled output' '
  88        badp4dir="$TRASH_DIRECTORY/badp4dir" &&
  89        mkdir -p "$badp4dir" &&
  90        cat >"$badp4dir"/p4 <<-EOF &&
  91        #!$SHELL_PATH
  92        exit 1
  93        EOF
  94        chmod 755 "$badp4dir"/p4 &&
  95        PATH="$badp4dir:$PATH" "$GITP4" clone --dest="$git" //depot >errs 2>&1 ; retval=$? &&
  96        test $retval -eq 1 &&
  97        test_must_fail grep -q Traceback errs
  98'
  99
 100test_expect_success 'add p4 files with wildcards in the names' '
 101        cd "$cli" &&
 102        echo file-wild-hash >file-wild#hash &&
 103        echo file-wild-star >file-wild\*star &&
 104        echo file-wild-at >file-wild@at &&
 105        echo file-wild-percent >file-wild%percent &&
 106        p4 add -f file-wild* &&
 107        p4 submit -d "file wildcards" &&
 108        cd "$TRASH_DIRECTORY"
 109'
 110
 111test_expect_success 'wildcard files git-p4 clone' '
 112        "$GITP4" clone --dest="$git" //depot &&
 113        cd "$git" &&
 114        test -f file-wild#hash &&
 115        test -f file-wild\*star &&
 116        test -f file-wild@at &&
 117        test -f file-wild%percent &&
 118        cd "$TRASH_DIRECTORY" &&
 119        rm -rf "$git" && mkdir "$git"
 120'
 121
 122test_expect_success 'clone bare' '
 123        "$GITP4" clone --dest="$git" --bare //depot &&
 124        cd "$git" &&
 125        test ! -d .git &&
 126        bare=`git config --get core.bare` &&
 127        test "$bare" = true &&
 128        cd "$TRASH_DIRECTORY" &&
 129        rm -rf "$git" && mkdir "$git"
 130'
 131
 132test_expect_success 'shutdown' '
 133        pid=`pgrep -f p4d` &&
 134        test -n "$pid" &&
 135        test_debug "ps wl `echo $pid`" &&
 136        kill $pid
 137'
 138
 139test_done