t / t9806-git-p4-options.shon commit Let core.attributesfile default to $XDG_CONFIG_HOME/git/attributes (684e40f)
   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' '
  31        git p4 clone --branch=refs/remotes/p4/sb --dest="$git" //depot &&
  32        test_when_finished cleanup_git &&
  33        (
  34                cd "$git" &&
  35                git ls-files >files &&
  36                test_line_count = 0 files &&
  37                test_path_is_file .git/refs/remotes/p4/sb
  38        )
  39'
  40
  41test_expect_success 'clone --changesfile' '
  42        cf="$TRASH_DIRECTORY/cf" &&
  43        test_when_finished "rm \"$cf\"" &&
  44        printf "1\n3\n" >"$cf" &&
  45        git p4 clone --changesfile="$cf" --dest="$git" //depot &&
  46        test_when_finished cleanup_git &&
  47        (
  48                cd "$git" &&
  49                git log --oneline p4/master >lines &&
  50                test_line_count = 2 lines
  51                test_path_is_file file1 &&
  52                test_path_is_missing file2 &&
  53                test_path_is_file file3
  54        )
  55'
  56
  57test_expect_success 'clone --changesfile, @all' '
  58        cf="$TRASH_DIRECTORY/cf" &&
  59        test_when_finished "rm \"$cf\"" &&
  60        printf "1\n3\n" >"$cf" &&
  61        test_must_fail git p4 clone --changesfile="$cf" --dest="$git" //depot@all
  62'
  63
  64# imports both master and p4/master in refs/heads
  65# requires --import-local on sync to find p4 refs/heads
  66# does not update master on sync, just p4/master
  67test_expect_success 'clone/sync --import-local' '
  68        git p4 clone --import-local --dest="$git" //depot@1,2 &&
  69        test_when_finished cleanup_git &&
  70        (
  71                cd "$git" &&
  72                git log --oneline refs/heads/master >lines &&
  73                test_line_count = 2 lines &&
  74                git log --oneline refs/heads/p4/master >lines &&
  75                test_line_count = 2 lines &&
  76                test_must_fail git p4 sync &&
  77
  78                git p4 sync --import-local &&
  79                git log --oneline refs/heads/master >lines &&
  80                test_line_count = 2 lines &&
  81                git log --oneline refs/heads/p4/master >lines &&
  82                test_line_count = 3 lines
  83        )
  84'
  85
  86test_expect_success 'clone --max-changes' '
  87        git p4 clone --dest="$git" --max-changes 2 //depot@all &&
  88        test_when_finished cleanup_git &&
  89        (
  90                cd "$git" &&
  91                git log --oneline refs/heads/master >lines &&
  92                test_line_count = 2 lines
  93        )
  94'
  95
  96test_expect_success 'clone --keep-path' '
  97        (
  98                cd "$cli" &&
  99                mkdir -p sub/dir &&
 100                echo f4 >sub/dir/f4 &&
 101                p4 add sub/dir/f4 &&
 102                p4 submit -d "change 4"
 103        ) &&
 104        git p4 clone --dest="$git" --keep-path //depot/sub/dir@all &&
 105        test_when_finished cleanup_git &&
 106        (
 107                cd "$git" &&
 108                test_path_is_missing f4 &&
 109                test_path_is_file sub/dir/f4
 110        ) &&
 111        cleanup_git &&
 112        git p4 clone --dest="$git" //depot/sub/dir@all &&
 113        (
 114                cd "$git" &&
 115                test_path_is_file f4 &&
 116                test_path_is_missing sub/dir/f4
 117        )
 118'
 119
 120# clone --use-client-spec must still specify a depot path
 121# if given, it should rearrange files according to client spec
 122# when it has view lines that match the depot path
 123# XXX: should clone/sync just use the client spec exactly, rather
 124# than needing depot paths?
 125test_expect_success 'clone --use-client-spec' '
 126        (
 127                # big usage message
 128                exec >/dev/null &&
 129                test_must_fail git p4 clone --dest="$git" --use-client-spec
 130        ) &&
 131        cli2="$TRASH_DIRECTORY/cli2" &&
 132        mkdir -p "$cli2" &&
 133        test_when_finished "rmdir \"$cli2\"" &&
 134        (
 135                cd "$cli2" &&
 136                p4 client -i <<-EOF
 137                Client: client2
 138                Description: client2
 139                Root: $cli2
 140                View: //depot/sub/... //client2/bus/...
 141                EOF
 142        ) &&
 143        P4CLIENT=client2 &&
 144        test_when_finished cleanup_git &&
 145        git p4 clone --dest="$git" --use-client-spec //depot/... &&
 146        (
 147                cd "$git" &&
 148                test_path_is_file bus/dir/f4 &&
 149                test_path_is_missing file1
 150        ) &&
 151        cleanup_git &&
 152
 153        # same thing again, this time with variable instead of option
 154        mkdir "$git" &&
 155        (
 156                cd "$git" &&
 157                git init &&
 158                git config git-p4.useClientSpec true &&
 159                git p4 sync //depot/... &&
 160                git checkout -b master p4/master &&
 161                test_path_is_file bus/dir/f4 &&
 162                test_path_is_missing file1
 163        )
 164'
 165
 166test_expect_success 'kill p4d' '
 167        kill_p4d
 168'
 169
 170test_done