t / t9800-git-p4-basic.shon commit Merge branch 'jk/unify-exit-code-by-receiving-signal' (edb6ad5)
   1#!/bin/sh
   2
   3test_description='git p4 tests'
   4
   5. ./lib-git-p4.sh
   6
   7test_expect_success 'start p4d' '
   8        start_p4d
   9'
  10
  11test_expect_success 'add p4 files' '
  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
  23test_expect_success 'basic git p4 clone' '
  24        git p4 clone --dest="$git" //depot &&
  25        test_when_finished cleanup_git &&
  26        (
  27                cd "$git" &&
  28                git log --oneline >lines &&
  29                test_line_count = 1 lines
  30        )
  31'
  32
  33test_expect_success 'git p4 clone @all' '
  34        git p4 clone --dest="$git" //depot@all &&
  35        test_when_finished cleanup_git &&
  36        (
  37                cd "$git" &&
  38                git log --oneline >lines &&
  39                test_line_count = 2 lines
  40        )
  41'
  42
  43test_expect_success 'git p4 sync uninitialized repo' '
  44        test_create_repo "$git" &&
  45        test_when_finished cleanup_git &&
  46        (
  47                cd "$git" &&
  48                test_must_fail git p4 sync 2>errs &&
  49                test_i18ngrep "Perhaps you never did" errs
  50        )
  51'
  52
  53#
  54# Create a git repo by hand.  Add a commit so that HEAD is valid.
  55# Test imports a new p4 repository into a new git branch.
  56#
  57test_expect_success 'git p4 sync new branch' '
  58        test_create_repo "$git" &&
  59        test_when_finished cleanup_git &&
  60        (
  61                cd "$git" &&
  62                test_commit head &&
  63                git p4 sync --branch=refs/remotes/p4/depot //depot@all &&
  64                git log --oneline p4/depot >lines &&
  65                test_line_count = 2 lines
  66        )
  67'
  68
  69test_expect_success 'clone two dirs' '
  70        (
  71                cd "$cli" &&
  72                mkdir sub1 sub2 &&
  73                echo sub1/f1 >sub1/f1 &&
  74                echo sub2/f2 >sub2/f2 &&
  75                p4 add sub1/f1 &&
  76                p4 submit -d "sub1/f1" &&
  77                p4 add sub2/f2 &&
  78                p4 submit -d "sub2/f2"
  79        ) &&
  80        git p4 clone --dest="$git" //depot/sub1 //depot/sub2 &&
  81        test_when_finished cleanup_git &&
  82        (
  83                cd "$git" &&
  84                git ls-files >lines &&
  85                test_line_count = 2 lines &&
  86                git log --oneline p4/master >lines &&
  87                test_line_count = 1 lines
  88        )
  89'
  90
  91test_expect_success 'clone two dirs, @all' '
  92        (
  93                cd "$cli" &&
  94                echo sub1/f3 >sub1/f3 &&
  95                p4 add sub1/f3 &&
  96                p4 submit -d "sub1/f3"
  97        ) &&
  98        git p4 clone --dest="$git" //depot/sub1@all //depot/sub2@all &&
  99        test_when_finished cleanup_git &&
 100        (
 101                cd "$git" &&
 102                git ls-files >lines &&
 103                test_line_count = 3 lines &&
 104                git log --oneline p4/master >lines &&
 105                test_line_count = 3 lines
 106        )
 107'
 108
 109test_expect_success 'clone two dirs, @all, conflicting files' '
 110        (
 111                cd "$cli" &&
 112                echo sub2/f3 >sub2/f3 &&
 113                p4 add sub2/f3 &&
 114                p4 submit -d "sub2/f3"
 115        ) &&
 116        git p4 clone --dest="$git" //depot/sub1@all //depot/sub2@all &&
 117        test_when_finished cleanup_git &&
 118        (
 119                cd "$git" &&
 120                git ls-files >lines &&
 121                test_line_count = 3 lines &&
 122                git log --oneline p4/master >lines &&
 123                test_line_count = 4 lines &&
 124                echo sub2/f3 >expected &&
 125                test_cmp expected f3
 126        )
 127'
 128
 129test_expect_success 'exit when p4 fails to produce marshaled output' '
 130        mkdir badp4dir &&
 131        test_when_finished "rm badp4dir/p4 && rmdir badp4dir" &&
 132        cat >badp4dir/p4 <<-EOF &&
 133        #!$SHELL_PATH
 134        exit 1
 135        EOF
 136        chmod 755 badp4dir/p4 &&
 137        (
 138                PATH="$TRASH_DIRECTORY/badp4dir:$PATH" &&
 139                export PATH &&
 140                test_expect_code 1 git p4 clone --dest="$git" //depot >errs 2>&1
 141        ) &&
 142        cat errs &&
 143        ! test_i18ngrep Traceback errs
 144'
 145
 146# Hide a file from p4d, make sure we catch its complaint.  This won't fail in
 147# p4 changes, files, or describe; just in p4 print.  If P4CLIENT is unset, the
 148# message will include "Librarian checkout".
 149test_expect_success 'exit gracefully for p4 server errors' '
 150        test_when_finished "mv \"$db\"/depot/file1,v,hidden \"$db\"/depot/file1,v" &&
 151        mv "$db"/depot/file1,v "$db"/depot/file1,v,hidden &&
 152        test_when_finished cleanup_git &&
 153        test_expect_code 1 git p4 clone --dest="$git" //depot@1 >out 2>err &&
 154        test_i18ngrep "Error from p4 print" err
 155'
 156
 157test_expect_success 'clone --bare should make a bare repository' '
 158        rm -rf "$git" &&
 159        git p4 clone --dest="$git" --bare //depot &&
 160        test_when_finished cleanup_git &&
 161        (
 162                cd "$git" &&
 163                test ! -d .git &&
 164                bare=`git config --get core.bare` &&
 165                test "$bare" = true
 166        )
 167'
 168
 169# Sleep a bit so that the top-most p4 change did not happen "now".  Then
 170# import the repo and make sure that the initial import has the same time
 171# as the top-most change.
 172test_expect_success 'initial import time from top change time' '
 173        p4change=$(p4 -G changes -m 1 //depot/... | marshal_dump change) &&
 174        p4time=$(p4 -G changes -m 1 //depot/... | marshal_dump time) &&
 175        sleep 3 &&
 176        git p4 clone --dest="$git" //depot &&
 177        test_when_finished cleanup_git &&
 178        (
 179                cd "$git" &&
 180                gittime=$(git show -s --raw --pretty=format:%at HEAD) &&
 181                echo $p4time $gittime &&
 182                test $p4time = $gittime
 183        )
 184'
 185
 186test_expect_success 'unresolvable host in P4PORT should display error' '
 187        test_when_finished cleanup_git &&
 188        git p4 clone --dest="$git" //depot &&
 189        (
 190                cd "$git" &&
 191                P4PORT=nosuchhost:65537 &&
 192                export P4PORT &&
 193                test_expect_code 1 git p4 sync >out 2>err &&
 194                grep "connect to nosuchhost" err
 195        )
 196'
 197
 198test_expect_success 'kill p4d' '
 199        kill_p4d
 200'
 201
 202test_done