t / t9801-git-p4-branch.shon commit ident: rename IDENT_ERROR_ON_NO_NAME to IDENT_STRICT (f9bc573)
   1#!/bin/sh
   2
   3test_description='git p4 tests for p4 branches'
   4
   5. ./lib-git-p4.sh
   6
   7test_expect_success 'start p4d' '
   8        start_p4d
   9'
  10
  11#
  12# 1: //depot/main/f1
  13# 2: //depot/main/f2
  14# 3: integrate //depot/main/... -> //depot/branch1/...
  15# 4: //depot/main/f4
  16# 5: //depot/branch1/f5
  17# .: named branch branch2
  18# 6: integrate -b branch2
  19# 7: //depot/branch2/f7
  20# 8: //depot/main/f8
  21#
  22test_expect_success 'basic p4 branches' '
  23        (
  24                cd "$cli" &&
  25                mkdir -p main &&
  26
  27                echo f1 >main/f1 &&
  28                p4 add main/f1 &&
  29                p4 submit -d "main/f1" &&
  30
  31                echo f2 >main/f2 &&
  32                p4 add main/f2 &&
  33                p4 submit -d "main/f2" &&
  34
  35                p4 integrate //depot/main/... //depot/branch1/... &&
  36                p4 submit -d "integrate main to branch1" &&
  37
  38                echo f4 >main/f4 &&
  39                p4 add main/f4 &&
  40                p4 submit -d "main/f4" &&
  41
  42                echo f5 >branch1/f5 &&
  43                p4 add branch1/f5 &&
  44                p4 submit -d "branch1/f5" &&
  45
  46                p4 branch -i <<-EOF &&
  47                Branch: branch2
  48                View: //depot/main/... //depot/branch2/...
  49                EOF
  50
  51                p4 integrate -b branch2 &&
  52                p4 submit -d "integrate main to branch2" &&
  53
  54                echo f7 >branch2/f7 &&
  55                p4 add branch2/f7 &&
  56                p4 submit -d "branch2/f7" &&
  57
  58                echo f8 >main/f8 &&
  59                p4 add main/f8 &&
  60                p4 submit -d "main/f8"
  61        )
  62'
  63
  64test_expect_success 'import main, no branch detection' '
  65        test_when_finished cleanup_git &&
  66        git p4 clone --dest="$git" //depot/main@all &&
  67        (
  68                cd "$git" &&
  69                git log --oneline --graph --decorate --all &&
  70                git rev-list master >wc &&
  71                test_line_count = 4 wc
  72        )
  73'
  74
  75test_expect_success 'import branch1, no branch detection' '
  76        test_when_finished cleanup_git &&
  77        git p4 clone --dest="$git" //depot/branch1@all &&
  78        (
  79                cd "$git" &&
  80                git log --oneline --graph --decorate --all &&
  81                git rev-list master >wc &&
  82                test_line_count = 2 wc
  83        )
  84'
  85
  86test_expect_success 'import branch2, no branch detection' '
  87        test_when_finished cleanup_git &&
  88        git p4 clone --dest="$git" //depot/branch2@all &&
  89        (
  90                cd "$git" &&
  91                git log --oneline --graph --decorate --all &&
  92                git rev-list master >wc &&
  93                test_line_count = 2 wc
  94        )
  95'
  96
  97test_expect_success 'import depot, no branch detection' '
  98        test_when_finished cleanup_git &&
  99        git p4 clone --dest="$git" //depot@all &&
 100        (
 101                cd "$git" &&
 102                git log --oneline --graph --decorate --all &&
 103                git rev-list master >wc &&
 104                test_line_count = 8 wc
 105        )
 106'
 107
 108test_expect_success 'import depot, branch detection' '
 109        test_when_finished cleanup_git &&
 110        git p4 clone --dest="$git" --detect-branches //depot@all &&
 111        (
 112                cd "$git" &&
 113
 114                git log --oneline --graph --decorate --all &&
 115
 116                # 4 main commits
 117                git rev-list master >wc &&
 118                test_line_count = 4 wc &&
 119
 120                # 3 main, 1 integrate, 1 on branch2
 121                git rev-list p4/depot/branch2 >wc &&
 122                test_line_count = 5 wc &&
 123
 124                # no branch1, since no p4 branch created for it
 125                test_must_fail git show-ref p4/depot/branch1
 126        )
 127'
 128
 129test_expect_success 'import depot, branch detection, branchList branch definition' '
 130        test_when_finished cleanup_git &&
 131        test_create_repo "$git" &&
 132        (
 133                cd "$git" &&
 134                git config git-p4.branchList main:branch1 &&
 135                git p4 clone --dest=. --detect-branches //depot@all &&
 136
 137                git log --oneline --graph --decorate --all &&
 138
 139                # 4 main commits
 140                git rev-list master >wc &&
 141                test_line_count = 4 wc &&
 142
 143                # 3 main, 1 integrate, 1 on branch2
 144                git rev-list p4/depot/branch2 >wc &&
 145                test_line_count = 5 wc &&
 146
 147                # 2 main, 1 integrate, 1 on branch1
 148                git rev-list p4/depot/branch1 >wc &&
 149                test_line_count = 4 wc
 150        )
 151'
 152
 153test_expect_success 'restart p4d' '
 154        kill_p4d &&
 155        start_p4d
 156'
 157
 158#
 159# 1: //depot/branch1/file1
 160#    //depot/branch1/file2
 161# 2: integrate //depot/branch1/... -> //depot/branch2/...
 162# 3: //depot/branch1/file3
 163# 4: //depot/branch1/file2 (edit)
 164# 5: integrate //depot/branch1/... -> //depot/branch3/...
 165#
 166## Create a simple branch structure in P4 depot.
 167test_expect_success 'add simple p4 branches' '
 168        (
 169                cd "$cli" &&
 170                mkdir branch1 &&
 171                cd branch1 &&
 172                echo file1 >file1 &&
 173                echo file2 >file2 &&
 174                p4 add file1 file2 &&
 175                p4 submit -d "Create branch1" &&
 176                p4 integrate //depot/branch1/... //depot/branch2/... &&
 177                p4 submit -d "Integrate branch2 from branch1" &&
 178                echo file3 >file3 &&
 179                p4 add file3 &&
 180                p4 submit -d "add file3 in branch1" &&
 181                p4 open file2 &&
 182                echo update >>file2 &&
 183                p4 submit -d "update file2 in branch1" &&
 184                p4 integrate //depot/branch1/... //depot/branch3/... &&
 185                p4 submit -d "Integrate branch3 from branch1"
 186        )
 187'
 188
 189# Configure branches through git-config and clone them.
 190# All files are tested to make sure branches were cloned correctly.
 191# Finally, make an update to branch1 on P4 side to check if it is imported
 192# correctly by git p4.
 193test_expect_success 'git p4 clone simple branches' '
 194        test_when_finished cleanup_git &&
 195        test_create_repo "$git" &&
 196        (
 197                cd "$git" &&
 198                git config git-p4.branchList branch1:branch2 &&
 199                git config --add git-p4.branchList branch1:branch3 &&
 200                git p4 clone --dest=. --detect-branches //depot@all &&
 201                git log --all --graph --decorate --stat &&
 202                git reset --hard p4/depot/branch1 &&
 203                test -f file1 &&
 204                test -f file2 &&
 205                test -f file3 &&
 206                grep update file2 &&
 207                git reset --hard p4/depot/branch2 &&
 208                test -f file1 &&
 209                test -f file2 &&
 210                test ! -f file3 &&
 211                ! grep update file2 &&
 212                git reset --hard p4/depot/branch3 &&
 213                test -f file1 &&
 214                test -f file2 &&
 215                test -f file3 &&
 216                grep update file2 &&
 217                cd "$cli" &&
 218                cd branch1 &&
 219                p4 edit file2 &&
 220                echo file2_ >>file2 &&
 221                p4 submit -d "update file2 in branch3" &&
 222                cd "$git" &&
 223                git reset --hard p4/depot/branch1 &&
 224                git p4 rebase &&
 225                grep file2_ file2
 226        )
 227'
 228
 229# Create a complex branch structure in P4 depot to check if they are correctly
 230# cloned. The branches are created from older changelists to check if git p4 is
 231# able to correctly detect them.
 232# The final expected structure is:
 233# `branch1
 234# | `- file1
 235# | `- file2 (updated)
 236# | `- file3
 237# `branch2
 238# | `- file1
 239# | `- file2
 240# `branch3
 241# | `- file1
 242# | `- file2 (updated)
 243# | `- file3
 244# `branch4
 245# | `- file1
 246# | `- file2
 247# `branch5
 248#   `- file1
 249#   `- file2
 250#   `- file3
 251test_expect_success 'git p4 add complex branches' '
 252        test_when_finished cleanup_git &&
 253        test_create_repo "$git" &&
 254        (
 255                cd "$cli" &&
 256                changelist=$(p4 changes -m1 //depot/... | cut -d" " -f2) &&
 257                changelist=$(($changelist - 5)) &&
 258                p4 integrate //depot/branch1/...@$changelist //depot/branch4/... &&
 259                p4 submit -d "Integrate branch4 from branch1@${changelist}" &&
 260                changelist=$(($changelist + 2)) &&
 261                p4 integrate //depot/branch1/...@$changelist //depot/branch5/... &&
 262                p4 submit -d "Integrate branch5 from branch1@${changelist}"
 263        )
 264'
 265
 266# Configure branches through git-config and clone them. git p4 will only be able
 267# to clone the original structure if it is able to detect the origin changelist
 268# of each branch.
 269test_expect_success 'git p4 clone complex branches' '
 270        test_when_finished cleanup_git &&
 271        test_create_repo "$git" &&
 272        (
 273                cd "$git" &&
 274                git config git-p4.branchList branch1:branch2 &&
 275                git config --add git-p4.branchList branch1:branch3 &&
 276                git config --add git-p4.branchList branch1:branch4 &&
 277                git config --add git-p4.branchList branch1:branch5 &&
 278                git p4 clone --dest=. --detect-branches //depot@all &&
 279                git log --all --graph --decorate --stat &&
 280                git reset --hard p4/depot/branch1 &&
 281                test_path_is_file file1 &&
 282                test_path_is_file file2 &&
 283                test_path_is_file file3 &&
 284                grep update file2 &&
 285                git reset --hard p4/depot/branch2 &&
 286                test_path_is_file file1 &&
 287                test_path_is_file file2 &&
 288                test_path_is_missing file3 &&
 289                ! grep update file2 &&
 290                git reset --hard p4/depot/branch3 &&
 291                test_path_is_file file1 &&
 292                test_path_is_file file2 &&
 293                test_path_is_file file3 &&
 294                grep update file2 &&
 295                git reset --hard p4/depot/branch4 &&
 296                test_path_is_file file1 &&
 297                test_path_is_file file2 &&
 298                test_path_is_missing file3 &&
 299                ! grep update file2 &&
 300                git reset --hard p4/depot/branch5 &&
 301                test_path_is_file file1 &&
 302                test_path_is_file file2 &&
 303                test_path_is_file file3 &&
 304                ! grep update file2 &&
 305                test_path_is_missing .git/git-p4-tmp
 306        )
 307'
 308
 309test_expect_success 'kill p4d' '
 310        kill_p4d
 311'
 312
 313test_done