t / t9806-git-p4-options.shon commit git p4: allow short ref names to --branch (40d69ac)
   1#!/bin/sh
   2
   3test_description='git p4 options'
   4
   5. ./lib-git-p4.sh
   6
   7test_expect_success 'start p4d' '
   8        start_p4d
   9'
  10
  11test_expect_success 'init depot' '
  12        (
  13                cd "$cli" &&
  14                echo file1 >file1 &&
  15                p4 add file1 &&
  16                p4 submit -d "change 1" &&
  17                echo file2 >file2 &&
  18                p4 add file2 &&
  19                p4 submit -d "change 2" &&
  20                echo file3 >file3 &&
  21                p4 add file3 &&
  22                p4 submit -d "change 3"
  23        )
  24'
  25
  26test_expect_success 'clone no --git-dir' '
  27        test_must_fail git p4 clone --git-dir=xx //depot
  28'
  29
  30test_expect_success 'clone --branch should checkout master' '
  31        git p4 clone --branch=refs/remotes/p4/sb --dest="$git" //depot &&
  32        test_when_finished cleanup_git &&
  33        (
  34                cd "$git" &&
  35                git rev-parse refs/remotes/p4/sb >sb &&
  36                git rev-parse refs/heads/master >master &&
  37                test_cmp sb master &&
  38                git rev-parse HEAD >head &&
  39                test_cmp sb head
  40        )
  41'
  42
  43test_expect_failure 'sync when branch is not called master should work' '
  44        git p4 clone --branch=refs/remotes/p4/sb --dest="$git" //depot@2 &&
  45        test_when_finished cleanup_git &&
  46        (
  47                cd "$git" &&
  48                git p4 sync &&
  49                git show -s --format=%s refs/remotes/p4/sb >show &&
  50                grep "change 3" show
  51        )
  52'
  53
  54test_expect_success 'sync --branch builds the full ref name correctly' '
  55        test_when_finished cleanup_git &&
  56        (
  57                cd "$git" &&
  58                git init &&
  59
  60                git p4 sync --branch=b1 //depot &&
  61                git rev-parse --verify refs/remotes/p4/b1 &&
  62                git p4 sync --branch=p4/b2 //depot &&
  63                git rev-parse --verify refs/remotes/p4/b2 &&
  64
  65                git p4 sync --import-local --branch=h1 //depot &&
  66                git rev-parse --verify refs/heads/p4/h1 &&
  67                git p4 sync --import-local --branch=p4/h2 //depot &&
  68                git rev-parse --verify refs/heads/p4/h2 &&
  69
  70                git p4 sync --branch=refs/stuff //depot &&
  71                git rev-parse --verify refs/stuff
  72        )
  73'
  74
  75# engages --detect-branches code, which will do filename filtering so
  76# no sync to either b1 or b2
  77test_expect_success 'sync when two branches but no master should noop' '
  78        test_when_finished cleanup_git &&
  79        (
  80                cd "$git" &&
  81                git init &&
  82                git p4 sync --branch=refs/remotes/p4/b1 //depot@2 &&
  83                git p4 sync --branch=refs/remotes/p4/b2 //depot@2 &&
  84                git p4 sync &&
  85                git show -s --format=%s refs/remotes/p4/b1 >show &&
  86                grep "Initial import" show &&
  87                git show -s --format=%s refs/remotes/p4/b2 >show &&
  88                grep "Initial import" show
  89        )
  90'
  91
  92test_expect_failure 'sync --branch updates specified branch' '
  93        test_when_finished cleanup_git &&
  94        (
  95                cd "$git" &&
  96                git init &&
  97                git p4 sync --branch=refs/remotes/p4/b1 //depot@2 &&
  98                git p4 sync --branch=refs/remotes/p4/b2 //depot@2 &&
  99                git p4 sync --branch=refs/remotes/p4/b2 &&
 100                git show -s --format=%s refs/remotes/p4/b1 >show &&
 101                grep "Initial import" show &&
 102                git show -s --format=%s refs/remotes/p4/b2 >show &&
 103                grep "change 3" show
 104        )
 105'
 106
 107# allows using the refname "p4" as a short name for p4/master
 108test_expect_success 'clone creates HEAD symbolic reference' '
 109        git p4 clone --dest="$git" //depot &&
 110        test_when_finished cleanup_git &&
 111        (
 112                cd "$git" &&
 113                git rev-parse --verify refs/remotes/p4/master >master &&
 114                git rev-parse --verify p4 >p4 &&
 115                test_cmp master p4
 116        )
 117'
 118
 119test_expect_success 'clone --branch creates HEAD symbolic reference' '
 120        git p4 clone --branch=refs/remotes/p4/sb --dest="$git" //depot &&
 121        test_when_finished cleanup_git &&
 122        (
 123                cd "$git" &&
 124                git rev-parse --verify refs/remotes/p4/sb >sb &&
 125                git rev-parse --verify p4 >p4 &&
 126                test_cmp sb p4
 127        )
 128'
 129
 130test_expect_success 'clone --changesfile' '
 131        test_when_finished "rm cf" &&
 132        printf "1\n3\n" >cf &&
 133        git p4 clone --changesfile="$TRASH_DIRECTORY/cf" --dest="$git" //depot &&
 134        test_when_finished cleanup_git &&
 135        (
 136                cd "$git" &&
 137                git log --oneline p4/master >lines &&
 138                test_line_count = 2 lines
 139                test_path_is_file file1 &&
 140                test_path_is_missing file2 &&
 141                test_path_is_file file3
 142        )
 143'
 144
 145test_expect_success 'clone --changesfile, @all' '
 146        test_when_finished "rm cf" &&
 147        printf "1\n3\n" >cf &&
 148        test_must_fail git p4 clone --changesfile="$TRASH_DIRECTORY/cf" --dest="$git" //depot@all
 149'
 150
 151# imports both master and p4/master in refs/heads
 152# requires --import-local on sync to find p4 refs/heads
 153# does not update master on sync, just p4/master
 154test_expect_success 'clone/sync --import-local' '
 155        git p4 clone --import-local --dest="$git" //depot@1,2 &&
 156        test_when_finished cleanup_git &&
 157        (
 158                cd "$git" &&
 159                git log --oneline refs/heads/master >lines &&
 160                test_line_count = 2 lines &&
 161                git log --oneline refs/heads/p4/master >lines &&
 162                test_line_count = 2 lines &&
 163                test_must_fail git p4 sync &&
 164
 165                git p4 sync --import-local &&
 166                git log --oneline refs/heads/master >lines &&
 167                test_line_count = 2 lines &&
 168                git log --oneline refs/heads/p4/master >lines &&
 169                test_line_count = 3 lines
 170        )
 171'
 172
 173test_expect_success 'clone --max-changes' '
 174        git p4 clone --dest="$git" --max-changes 2 //depot@all &&
 175        test_when_finished cleanup_git &&
 176        (
 177                cd "$git" &&
 178                git log --oneline refs/heads/master >lines &&
 179                test_line_count = 2 lines
 180        )
 181'
 182
 183test_expect_success 'clone --keep-path' '
 184        (
 185                cd "$cli" &&
 186                mkdir -p sub/dir &&
 187                echo f4 >sub/dir/f4 &&
 188                p4 add sub/dir/f4 &&
 189                p4 submit -d "change 4"
 190        ) &&
 191        git p4 clone --dest="$git" --keep-path //depot/sub/dir@all &&
 192        test_when_finished cleanup_git &&
 193        (
 194                cd "$git" &&
 195                test_path_is_missing f4 &&
 196                test_path_is_file sub/dir/f4
 197        ) &&
 198        cleanup_git &&
 199        git p4 clone --dest="$git" //depot/sub/dir@all &&
 200        (
 201                cd "$git" &&
 202                test_path_is_file f4 &&
 203                test_path_is_missing sub/dir/f4
 204        )
 205'
 206
 207# clone --use-client-spec must still specify a depot path
 208# if given, it should rearrange files according to client spec
 209# when it has view lines that match the depot path
 210# XXX: should clone/sync just use the client spec exactly, rather
 211# than needing depot paths?
 212test_expect_success 'clone --use-client-spec' '
 213        (
 214                # big usage message
 215                exec >/dev/null &&
 216                test_must_fail git p4 clone --dest="$git" --use-client-spec
 217        ) &&
 218        cli2=$(test-path-utils real_path "$TRASH_DIRECTORY/cli2") &&
 219        mkdir -p "$cli2" &&
 220        test_when_finished "rmdir \"$cli2\"" &&
 221        (
 222                cd "$cli2" &&
 223                p4 client -i <<-EOF
 224                Client: client2
 225                Description: client2
 226                Root: $cli2
 227                View: //depot/sub/... //client2/bus/...
 228                EOF
 229        ) &&
 230        P4CLIENT=client2 &&
 231        test_when_finished cleanup_git &&
 232        git p4 clone --dest="$git" --use-client-spec //depot/... &&
 233        (
 234                cd "$git" &&
 235                test_path_is_file bus/dir/f4 &&
 236                test_path_is_missing file1
 237        ) &&
 238        cleanup_git &&
 239
 240        # same thing again, this time with variable instead of option
 241        (
 242                cd "$git" &&
 243                git init &&
 244                git config git-p4.useClientSpec true &&
 245                git p4 sync //depot/... &&
 246                git checkout -b master p4/master &&
 247                test_path_is_file bus/dir/f4 &&
 248                test_path_is_missing file1
 249        )
 250'
 251
 252test_expect_success 'kill p4d' '
 253        kill_p4d
 254'
 255
 256test_done