t / t9806-git-p4-options.shon commit git p4: create p4/HEAD on initial clone (55d1243)
   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_failure '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
  54# engages --detect-branches code, which will do filename filtering so
  55# no sync to either b1 or b2
  56test_expect_success 'sync when two branches but no master should noop' '
  57        test_when_finished cleanup_git &&
  58        (
  59                cd "$git" &&
  60                git init &&
  61                git p4 sync --branch=refs/remotes/p4/b1 //depot@2 &&
  62                git p4 sync --branch=refs/remotes/p4/b2 //depot@2 &&
  63                git p4 sync &&
  64                git show -s --format=%s refs/remotes/p4/b1 >show &&
  65                grep "Initial import" show &&
  66                git show -s --format=%s refs/remotes/p4/b2 >show &&
  67                grep "Initial import" show
  68        )
  69'
  70
  71test_expect_failure 'sync --branch updates specified branch' '
  72        test_when_finished cleanup_git &&
  73        (
  74                cd "$git" &&
  75                git init &&
  76                git p4 sync --branch=refs/remotes/p4/b1 //depot@2 &&
  77                git p4 sync --branch=refs/remotes/p4/b2 //depot@2 &&
  78                git p4 sync --branch=refs/remotes/p4/b2 &&
  79                git show -s --format=%s refs/remotes/p4/b1 >show &&
  80                grep "Initial import" show &&
  81                git show -s --format=%s refs/remotes/p4/b2 >show &&
  82                grep "change 3" show
  83        )
  84'
  85
  86# allows using the refname "p4" as a short name for p4/master
  87test_expect_success 'clone creates HEAD symbolic reference' '
  88        git p4 clone --dest="$git" //depot &&
  89        test_when_finished cleanup_git &&
  90        (
  91                cd "$git" &&
  92                git rev-parse --verify refs/remotes/p4/master >master &&
  93                git rev-parse --verify p4 >p4 &&
  94                test_cmp master p4
  95        )
  96'
  97
  98test_expect_success 'clone --branch creates HEAD symbolic reference' '
  99        git p4 clone --branch=refs/remotes/p4/sb --dest="$git" //depot &&
 100        test_when_finished cleanup_git &&
 101        (
 102                cd "$git" &&
 103                git rev-parse --verify refs/remotes/p4/sb >sb &&
 104                git rev-parse --verify p4 >p4 &&
 105                test_cmp sb p4
 106        )
 107'
 108
 109test_expect_success 'clone --changesfile' '
 110        test_when_finished "rm cf" &&
 111        printf "1\n3\n" >cf &&
 112        git p4 clone --changesfile="$TRASH_DIRECTORY/cf" --dest="$git" //depot &&
 113        test_when_finished cleanup_git &&
 114        (
 115                cd "$git" &&
 116                git log --oneline p4/master >lines &&
 117                test_line_count = 2 lines
 118                test_path_is_file file1 &&
 119                test_path_is_missing file2 &&
 120                test_path_is_file file3
 121        )
 122'
 123
 124test_expect_success 'clone --changesfile, @all' '
 125        test_when_finished "rm cf" &&
 126        printf "1\n3\n" >cf &&
 127        test_must_fail git p4 clone --changesfile="$TRASH_DIRECTORY/cf" --dest="$git" //depot@all
 128'
 129
 130# imports both master and p4/master in refs/heads
 131# requires --import-local on sync to find p4 refs/heads
 132# does not update master on sync, just p4/master
 133test_expect_success 'clone/sync --import-local' '
 134        git p4 clone --import-local --dest="$git" //depot@1,2 &&
 135        test_when_finished cleanup_git &&
 136        (
 137                cd "$git" &&
 138                git log --oneline refs/heads/master >lines &&
 139                test_line_count = 2 lines &&
 140                git log --oneline refs/heads/p4/master >lines &&
 141                test_line_count = 2 lines &&
 142                test_must_fail git p4 sync &&
 143
 144                git p4 sync --import-local &&
 145                git log --oneline refs/heads/master >lines &&
 146                test_line_count = 2 lines &&
 147                git log --oneline refs/heads/p4/master >lines &&
 148                test_line_count = 3 lines
 149        )
 150'
 151
 152test_expect_success 'clone --max-changes' '
 153        git p4 clone --dest="$git" --max-changes 2 //depot@all &&
 154        test_when_finished cleanup_git &&
 155        (
 156                cd "$git" &&
 157                git log --oneline refs/heads/master >lines &&
 158                test_line_count = 2 lines
 159        )
 160'
 161
 162test_expect_success 'clone --keep-path' '
 163        (
 164                cd "$cli" &&
 165                mkdir -p sub/dir &&
 166                echo f4 >sub/dir/f4 &&
 167                p4 add sub/dir/f4 &&
 168                p4 submit -d "change 4"
 169        ) &&
 170        git p4 clone --dest="$git" --keep-path //depot/sub/dir@all &&
 171        test_when_finished cleanup_git &&
 172        (
 173                cd "$git" &&
 174                test_path_is_missing f4 &&
 175                test_path_is_file sub/dir/f4
 176        ) &&
 177        cleanup_git &&
 178        git p4 clone --dest="$git" //depot/sub/dir@all &&
 179        (
 180                cd "$git" &&
 181                test_path_is_file f4 &&
 182                test_path_is_missing sub/dir/f4
 183        )
 184'
 185
 186# clone --use-client-spec must still specify a depot path
 187# if given, it should rearrange files according to client spec
 188# when it has view lines that match the depot path
 189# XXX: should clone/sync just use the client spec exactly, rather
 190# than needing depot paths?
 191test_expect_success 'clone --use-client-spec' '
 192        (
 193                # big usage message
 194                exec >/dev/null &&
 195                test_must_fail git p4 clone --dest="$git" --use-client-spec
 196        ) &&
 197        cli2=$(test-path-utils real_path "$TRASH_DIRECTORY/cli2") &&
 198        mkdir -p "$cli2" &&
 199        test_when_finished "rmdir \"$cli2\"" &&
 200        (
 201                cd "$cli2" &&
 202                p4 client -i <<-EOF
 203                Client: client2
 204                Description: client2
 205                Root: $cli2
 206                View: //depot/sub/... //client2/bus/...
 207                EOF
 208        ) &&
 209        P4CLIENT=client2 &&
 210        test_when_finished cleanup_git &&
 211        git p4 clone --dest="$git" --use-client-spec //depot/... &&
 212        (
 213                cd "$git" &&
 214                test_path_is_file bus/dir/f4 &&
 215                test_path_is_missing file1
 216        ) &&
 217        cleanup_git &&
 218
 219        # same thing again, this time with variable instead of option
 220        (
 221                cd "$git" &&
 222                git init &&
 223                git config git-p4.useClientSpec true &&
 224                git p4 sync //depot/... &&
 225                git checkout -b master p4/master &&
 226                test_path_is_file bus/dir/f4 &&
 227                test_path_is_missing file1
 228        )
 229'
 230
 231test_expect_success 'kill p4d' '
 232        kill_p4d
 233'
 234
 235test_done