t / t9800-git-p4-basic.shon commit Merge branch 'nd/apply-report-skip' (11cfcc5)
   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 'depot typo error' '
  34        test_must_fail git p4 clone --dest="$git" /depot 2>errs &&
  35        grep "Depot paths must start with" errs
  36'
  37
  38test_expect_success 'git p4 clone @all' '
  39        git p4 clone --dest="$git" //depot@all &&
  40        test_when_finished cleanup_git &&
  41        (
  42                cd "$git" &&
  43                git log --oneline >lines &&
  44                test_line_count = 2 lines
  45        )
  46'
  47
  48test_expect_success 'git p4 sync uninitialized repo' '
  49        test_create_repo "$git" &&
  50        test_when_finished cleanup_git &&
  51        (
  52                cd "$git" &&
  53                test_must_fail git p4 sync 2>errs &&
  54                test_i18ngrep "Perhaps you never did" errs
  55        )
  56'
  57
  58#
  59# Create a git repo by hand.  Add a commit so that HEAD is valid.
  60# Test imports a new p4 repository into a new git branch.
  61#
  62test_expect_success 'git p4 sync new branch' '
  63        test_create_repo "$git" &&
  64        test_when_finished cleanup_git &&
  65        (
  66                cd "$git" &&
  67                test_commit head &&
  68                git p4 sync --branch=refs/remotes/p4/depot //depot@all &&
  69                git log --oneline p4/depot >lines &&
  70                test_line_count = 2 lines
  71        )
  72'
  73
  74test_expect_success 'clone two dirs' '
  75        (
  76                cd "$cli" &&
  77                mkdir sub1 sub2 &&
  78                echo sub1/f1 >sub1/f1 &&
  79                echo sub2/f2 >sub2/f2 &&
  80                p4 add sub1/f1 &&
  81                p4 submit -d "sub1/f1" &&
  82                p4 add sub2/f2 &&
  83                p4 submit -d "sub2/f2"
  84        ) &&
  85        git p4 clone --dest="$git" //depot/sub1 //depot/sub2 &&
  86        test_when_finished cleanup_git &&
  87        (
  88                cd "$git" &&
  89                git ls-files >lines &&
  90                test_line_count = 2 lines &&
  91                git log --oneline p4/master >lines &&
  92                test_line_count = 1 lines
  93        )
  94'
  95
  96test_expect_success 'clone two dirs, @all' '
  97        (
  98                cd "$cli" &&
  99                echo sub1/f3 >sub1/f3 &&
 100                p4 add sub1/f3 &&
 101                p4 submit -d "sub1/f3"
 102        ) &&
 103        git p4 clone --dest="$git" //depot/sub1@all //depot/sub2@all &&
 104        test_when_finished cleanup_git &&
 105        (
 106                cd "$git" &&
 107                git ls-files >lines &&
 108                test_line_count = 3 lines &&
 109                git log --oneline p4/master >lines &&
 110                test_line_count = 3 lines
 111        )
 112'
 113
 114test_expect_success 'clone two dirs, @all, conflicting files' '
 115        (
 116                cd "$cli" &&
 117                echo sub2/f3 >sub2/f3 &&
 118                p4 add sub2/f3 &&
 119                p4 submit -d "sub2/f3"
 120        ) &&
 121        git p4 clone --dest="$git" //depot/sub1@all //depot/sub2@all &&
 122        test_when_finished cleanup_git &&
 123        (
 124                cd "$git" &&
 125                git ls-files >lines &&
 126                test_line_count = 3 lines &&
 127                git log --oneline p4/master >lines &&
 128                test_line_count = 4 lines &&
 129                echo sub2/f3 >expected &&
 130                test_cmp expected f3
 131        )
 132'
 133
 134revision_ranges="2000/01/01,#head \
 135                 1,2080/01/01 \
 136                 2000/01/01,2080/01/01 \
 137                 2000/01/01,1000 \
 138                 1,1000"
 139
 140test_expect_success 'clone using non-numeric revision ranges' '
 141        test_when_finished cleanup_git &&
 142        for r in $revision_ranges
 143        do
 144                rm -fr "$git" &&
 145                test ! -d "$git" &&
 146                git p4 clone --dest="$git" //depot@$r &&
 147                (
 148                        cd "$git" &&
 149                        git ls-files >lines &&
 150                        test_line_count = 6 lines
 151                )
 152        done
 153'
 154
 155test_expect_success 'clone with date range, excluding some changes' '
 156        test_when_finished cleanup_git &&
 157        before=$(date +%Y/%m/%d:%H:%M:%S) &&
 158        sleep 2 &&
 159        (
 160                cd "$cli" &&
 161                :>date_range_test &&
 162                p4 add date_range_test &&
 163                p4 submit -d "Adding file"
 164        ) &&
 165        git p4 clone --dest="$git" //depot@1,$before &&
 166        (
 167                cd "$git" &&
 168                test_path_is_missing date_range_test
 169        )
 170'
 171
 172test_expect_success 'exit when p4 fails to produce marshaled output' '
 173        mkdir badp4dir &&
 174        test_when_finished "rm badp4dir/p4 && rmdir badp4dir" &&
 175        cat >badp4dir/p4 <<-EOF &&
 176        #!$SHELL_PATH
 177        exit 1
 178        EOF
 179        chmod 755 badp4dir/p4 &&
 180        (
 181                PATH="$TRASH_DIRECTORY/badp4dir:$PATH" &&
 182                export PATH &&
 183                test_expect_code 1 git p4 clone --dest="$git" //depot >errs 2>&1
 184        ) &&
 185        cat errs &&
 186        test_i18ngrep ! Traceback errs
 187'
 188
 189# Hide a file from p4d, make sure we catch its complaint.  This won't fail in
 190# p4 changes, files, or describe; just in p4 print.  If P4CLIENT is unset, the
 191# message will include "Librarian checkout".
 192test_expect_success 'exit gracefully for p4 server errors' '
 193        test_when_finished "mv \"$db\"/depot/file1,v,hidden \"$db\"/depot/file1,v" &&
 194        mv "$db"/depot/file1,v "$db"/depot/file1,v,hidden &&
 195        test_when_finished cleanup_git &&
 196        test_expect_code 1 git p4 clone --dest="$git" //depot@1 >out 2>err &&
 197        test_i18ngrep "Error from p4 print" err
 198'
 199
 200test_expect_success 'clone --bare should make a bare repository' '
 201        rm -rf "$git" &&
 202        git p4 clone --dest="$git" --bare //depot &&
 203        test_when_finished cleanup_git &&
 204        (
 205                cd "$git" &&
 206                test_path_is_missing .git &&
 207                git config --get --bool core.bare true &&
 208                git rev-parse --verify refs/remotes/p4/master &&
 209                git rev-parse --verify refs/remotes/p4/HEAD &&
 210                git rev-parse --verify refs/heads/master &&
 211                git rev-parse --verify HEAD
 212        )
 213'
 214
 215# Sleep a bit so that the top-most p4 change did not happen "now".  Then
 216# import the repo and make sure that the initial import has the same time
 217# as the top-most change.
 218test_expect_success 'initial import time from top change time' '
 219        p4change=$(p4 -G changes -m 1 //depot/... | marshal_dump change) &&
 220        p4time=$(p4 -G changes -m 1 //depot/... | marshal_dump time) &&
 221        sleep 3 &&
 222        git p4 clone --dest="$git" //depot &&
 223        test_when_finished cleanup_git &&
 224        (
 225                cd "$git" &&
 226                gittime=$(git show -s --raw --pretty=format:%at HEAD) &&
 227                echo $p4time $gittime &&
 228                test $p4time = $gittime
 229        )
 230'
 231
 232test_expect_success 'unresolvable host in P4PORT should display error' '
 233        test_when_finished cleanup_git &&
 234        git p4 clone --dest="$git" //depot &&
 235        (
 236                cd "$git" &&
 237                P4PORT=nosuchhost:65537 &&
 238                export P4PORT &&
 239                test_expect_code 1 git p4 sync >out 2>err &&
 240                grep "connect to nosuchhost" err
 241        )
 242'
 243
 244test_expect_success 'submit from detached head' '
 245        test_when_finished cleanup_git &&
 246        git p4 clone --dest="$git" //depot &&
 247        (
 248                cd "$git" &&
 249                git checkout p4/master &&
 250                >detached_head_test &&
 251                git add detached_head_test &&
 252                git commit -m "add detached_head" &&
 253                git config git-p4.skipSubmitEdit true &&
 254                git p4 submit &&
 255                git p4 rebase &&
 256                git log p4/master | grep detached_head
 257        )
 258'
 259
 260test_expect_success 'kill p4d' '
 261        kill_p4d
 262'
 263
 264test_done