t / t9811-git-p4-label-import.shon commit Merge branch 'en/merge-fixes' (10b8084)
   1#!/bin/sh
   2
   3test_description='git p4 label tests'
   4
   5. ./lib-git-p4.sh
   6
   7test_expect_success 'start p4d' '
   8        start_p4d
   9'
  10
  11# Basic p4 label import tests.
  12#
  13test_expect_success 'basic p4 labels' '
  14        test_when_finished cleanup_git &&
  15        (
  16                cd "$cli" &&
  17                mkdir -p main &&
  18
  19                echo f1 >main/f1 &&
  20                p4 add main/f1 &&
  21                p4 submit -d "main/f1" &&
  22
  23                echo f2 >main/f2 &&
  24                p4 add main/f2 &&
  25                p4 submit -d "main/f2" &&
  26
  27                echo f3 >main/file_with_\$metachar &&
  28                p4 add main/file_with_\$metachar &&
  29                p4 submit -d "file with metachar" &&
  30
  31                p4 tag -l TAG_F1_ONLY main/f1 &&
  32                p4 tag -l TAG_WITH\$_SHELL_CHAR main/... &&
  33                p4 tag -l this_tag_will_be\ skipped main/... &&
  34
  35                echo f4 >main/f4 &&
  36                p4 add main/f4 &&
  37                p4 submit -d "main/f4" &&
  38
  39                p4 label -i <<-EOF &&
  40                Label: TAG_LONG_LABEL
  41                Description:
  42                   A Label first line
  43                   A Label second line
  44                View:   //depot/...
  45                EOF
  46
  47                p4 tag -l TAG_LONG_LABEL ... &&
  48
  49                p4 labels ... &&
  50
  51                git p4 clone --dest="$git" //depot@all &&
  52                cd "$git" &&
  53                git config git-p4.labelImportRegexp ".*TAG.*" &&
  54                git p4 sync --import-labels --verbose &&
  55
  56                git tag &&
  57                git tag >taglist &&
  58                test_line_count = 3 taglist &&
  59
  60                cd main &&
  61                git checkout TAG_F1_ONLY &&
  62                ! test -f f2 &&
  63                git checkout TAG_WITH\$_SHELL_CHAR &&
  64                test -f f1 && test -f f2 && test -f file_with_\$metachar &&
  65
  66                git show TAG_LONG_LABEL | grep -q "A Label second line"
  67        )
  68'
  69# Test some label corner cases:
  70#
  71# - two tags on the same file; both should be available
  72# - a tag that is only on one file; this kind of tag
  73#   cannot be imported (at least not easily).
  74
  75test_expect_success 'two labels on the same changelist' '
  76        test_when_finished cleanup_git &&
  77        (
  78                cd "$cli" &&
  79                mkdir -p main &&
  80
  81                p4 edit main/f1 main/f2 &&
  82                echo "hello world" >main/f1 &&
  83                echo "not in the tag" >main/f2 &&
  84                p4 submit -d "main/f[12]: testing two labels" &&
  85
  86                p4 tag -l TAG_F1_1 main/... &&
  87                p4 tag -l TAG_F1_2 main/... &&
  88
  89                p4 labels ... &&
  90
  91                git p4 clone --dest="$git" //depot@all &&
  92                cd "$git" &&
  93                git p4 sync --import-labels &&
  94
  95                git tag | grep TAG_F1 &&
  96                git tag | grep -q TAG_F1_1 &&
  97                git tag | grep -q TAG_F1_2 &&
  98
  99                cd main &&
 100
 101                git checkout TAG_F1_1 &&
 102                ls &&
 103                test -f f1 &&
 104
 105                git checkout TAG_F1_2 &&
 106                ls &&
 107                test -f f1
 108        )
 109'
 110
 111# Export some git tags to p4
 112test_expect_success 'export git tags to p4' '
 113        test_when_finished cleanup_git &&
 114        git p4 clone --dest="$git" //depot@all &&
 115        (
 116                cd "$git" &&
 117                git tag -m "A tag created in git:xyzzy" GIT_TAG_1 &&
 118                echo "hello world" >main/f10 &&
 119                git add main/f10 &&
 120                git commit -m "Adding file for export test" &&
 121                git config git-p4.skipSubmitEdit true &&
 122                git p4 submit &&
 123                git tag -m "Another git tag" GIT_TAG_2 &&
 124                git tag LIGHTWEIGHT_TAG &&
 125                git p4 rebase --import-labels --verbose &&
 126                git p4 submit --export-labels --verbose
 127        ) &&
 128        (
 129                cd "$cli" &&
 130                p4 sync ... &&
 131                p4 labels ... | grep GIT_TAG_1 &&
 132                p4 labels ... | grep GIT_TAG_2 &&
 133                p4 labels ... | grep LIGHTWEIGHT_TAG &&
 134                p4 label -o GIT_TAG_1 | grep "tag created in git:xyzzy" &&
 135                p4 sync ...@GIT_TAG_1 &&
 136                ! test -f main/f10
 137                p4 sync ...@GIT_TAG_2 &&
 138                test -f main/f10
 139        )
 140'
 141
 142# Export a tag from git where an affected file is deleted later on
 143# Need to create git tags after rebase, since only then can the
 144# git commits be mapped to p4 changelists.
 145test_expect_success 'export git tags to p4 with deletion' '
 146        test_when_finished cleanup_git &&
 147        git p4 clone --dest="$git" //depot@all &&
 148        (
 149                cd "$git" &&
 150                git p4 sync --import-labels &&
 151                echo "deleted file" >main/deleted_file &&
 152                git add main/deleted_file &&
 153                git commit -m "create deleted file" &&
 154                git rm main/deleted_file &&
 155                echo "new file" >main/f11 &&
 156                git add main/f11 &&
 157                git commit -m "delete the deleted file" &&
 158                git config git-p4.skipSubmitEdit true &&
 159                git p4 submit &&
 160                git p4 rebase --import-labels --verbose &&
 161                git tag -m "tag on deleted file" GIT_TAG_ON_DELETED HEAD~1 &&
 162                git tag -m "tag after deletion" GIT_TAG_AFTER_DELETION HEAD &&
 163                git p4 submit --export-labels --verbose
 164        ) &&
 165        (
 166                cd "$cli" &&
 167                p4 sync ... &&
 168                p4 sync ...@GIT_TAG_ON_DELETED &&
 169                test -f main/deleted_file &&
 170                p4 sync ...@GIT_TAG_AFTER_DELETION &&
 171                ! test -f main/deleted_file &&
 172                echo "checking label contents" &&
 173                p4 label -o GIT_TAG_ON_DELETED | grep "tag on deleted file"
 174        )
 175'
 176
 177# Create a tag in git that cannot be exported to p4
 178test_expect_success 'tag that cannot be exported' '
 179        test_when_finished cleanup_git &&
 180        git p4 clone --dest="$git" //depot@all &&
 181        (
 182                cd "$git" &&
 183                git checkout -b a_branch &&
 184                echo "hello" >main/f12 &&
 185                git add main/f12 &&
 186                git commit -m "adding f12" &&
 187                git tag -m "tag on a_branch" GIT_TAG_ON_A_BRANCH &&
 188                git checkout master &&
 189                git p4 submit --export-labels
 190        ) &&
 191        (
 192                cd "$cli" &&
 193                p4 sync ... &&
 194                !(p4 labels | grep GIT_TAG_ON_A_BRANCH)
 195        )
 196'
 197
 198test_expect_success 'use git config to enable import/export of tags' '
 199        git p4 clone --verbose --dest="$git" //depot@all &&
 200        (
 201                cd "$git" &&
 202                git config git-p4.exportLabels true &&
 203                git config git-p4.importLabels true &&
 204                git tag CFG_A_GIT_TAG &&
 205                git p4 rebase --verbose &&
 206                git p4 submit --verbose &&
 207                git tag &&
 208                git tag | grep TAG_F1_1
 209        ) &&
 210        (
 211                cd "$cli" &&
 212                p4 labels &&
 213                p4 labels | grep CFG_A_GIT_TAG
 214        )
 215'
 216
 217p4_head_revision() {
 218        p4 changes -m 1 "$@" | awk '{print $2}'
 219}
 220
 221# Importing a label that references a P4 commit that
 222# has not been seen. The presence of a label on a commit
 223# we haven't seen should not cause git-p4 to fail. It should
 224# merely skip that label, and still import other labels.
 225test_expect_success 'importing labels with missing revisions' '
 226        test_when_finished cleanup_git &&
 227        (
 228                rm -fr "$cli" "$git" &&
 229                mkdir "$cli" &&
 230                P4CLIENT=missing-revision &&
 231                client_view "//depot/missing-revision/... //missing-revision/..." &&
 232                cd "$cli" &&
 233                >f1 && p4 add f1 && p4 submit -d "start" &&
 234
 235                p4 tag -l TAG_S0 ... &&
 236
 237                >f2 && p4 add f2 && p4 submit -d "second" &&
 238
 239                startrev=$(p4_head_revision //depot/missing-revision/...) &&
 240
 241                >f3 && p4 add f3 && p4 submit -d "third" &&
 242
 243                p4 edit f2 && date >f2 && p4 submit -d "change" f2 &&
 244
 245                endrev=$(p4_head_revision //depot/missing-revision/...) &&
 246
 247                p4 tag -l TAG_S1 ... &&
 248
 249                # we should skip TAG_S0 since it is before our startpoint,
 250                # but pick up TAG_S1.
 251
 252                git p4 clone --dest="$git" --import-labels -v \
 253                        //depot/missing-revision/...@$startrev,$endrev &&
 254                (
 255                        cd "$git" &&
 256                        git rev-parse TAG_S1 &&
 257                        ! git rev-parse TAG_S0
 258                )
 259        )
 260'
 261
 262
 263test_expect_success 'kill p4d' '
 264        kill_p4d
 265'
 266
 267test_done