t / t9807-git-p4-submit.shon commit Merge branch 'sp/maint-http-enable-gzip' (c318040)
   1#!/bin/sh
   2
   3test_description='git p4 submit'
   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        )
  18'
  19
  20test_expect_success 'submit with no client dir' '
  21        test_when_finished cleanup_git &&
  22        git p4 clone --dest="$git" //depot &&
  23        (
  24                cd "$git" &&
  25                echo file2 >file2 &&
  26                git add file2 &&
  27                git commit -m "git commit 2" &&
  28                rm -rf "$cli" &&
  29                git config git-p4.skipSubmitEdit true &&
  30                git p4 submit
  31        ) &&
  32        (
  33                cd "$cli" &&
  34                test_path_is_file file1 &&
  35                test_path_is_file file2
  36        )
  37'
  38
  39# make two commits, but tell it to apply only from HEAD^
  40test_expect_success 'submit --origin' '
  41        test_when_finished cleanup_git &&
  42        git p4 clone --dest="$git" //depot &&
  43        (
  44                cd "$git" &&
  45                test_commit "file3" &&
  46                test_commit "file4" &&
  47                git config git-p4.skipSubmitEdit true &&
  48                git p4 submit --origin=HEAD^
  49        ) &&
  50        (
  51                cd "$cli" &&
  52                test_path_is_missing "file3.t" &&
  53                test_path_is_file "file4.t"
  54        )
  55'
  56
  57test_expect_success 'submit --dry-run' '
  58        test_when_finished cleanup_git &&
  59        git p4 clone --dest="$git" //depot &&
  60        (
  61                cd "$git" &&
  62                test_commit "dry-run1" &&
  63                test_commit "dry-run2" &&
  64                git p4 submit --dry-run >out &&
  65                test_i18ngrep "Would apply" out
  66        ) &&
  67        (
  68                cd "$cli" &&
  69                test_path_is_missing "dry-run1.t" &&
  70                test_path_is_missing "dry-run2.t"
  71        )
  72'
  73
  74test_expect_success 'submit --dry-run --export-labels' '
  75        test_when_finished cleanup_git &&
  76        git p4 clone --dest="$git" //depot &&
  77        (
  78                cd "$git" &&
  79                echo dry-run1 >dry-run1 &&
  80                git add dry-run1 &&
  81                git commit -m "dry-run1" dry-run1 &&
  82                git config git-p4.skipSubmitEdit true &&
  83                git p4 submit &&
  84                echo dry-run2 >dry-run2 &&
  85                git add dry-run2 &&
  86                git commit -m "dry-run2" dry-run2 &&
  87                git tag -m "dry-run-tag1" dry-run-tag1 HEAD^ &&
  88                git p4 submit --dry-run --export-labels >out &&
  89                test_i18ngrep "Would create p4 label" out
  90        ) &&
  91        (
  92                cd "$cli" &&
  93                test_path_is_file "dry-run1" &&
  94                test_path_is_missing "dry-run2"
  95        )
  96'
  97
  98test_expect_success 'submit with allowSubmit' '
  99        test_when_finished cleanup_git &&
 100        git p4 clone --dest="$git" //depot &&
 101        (
 102                cd "$git" &&
 103                test_commit "file5" &&
 104                git config git-p4.skipSubmitEdit true &&
 105                git config git-p4.allowSubmit "nobranch" &&
 106                test_must_fail git p4 submit &&
 107                git config git-p4.allowSubmit "nobranch,master" &&
 108                git p4 submit
 109        )
 110'
 111
 112test_expect_success 'submit with master branch name from argv' '
 113        test_when_finished cleanup_git &&
 114        git p4 clone --dest="$git" //depot &&
 115        (
 116                cd "$git" &&
 117                test_commit "file6" &&
 118                git config git-p4.skipSubmitEdit true &&
 119                test_must_fail git p4 submit nobranch &&
 120                git branch otherbranch &&
 121                git reset --hard HEAD^ &&
 122                test_commit "file7" &&
 123                git p4 submit otherbranch
 124        ) &&
 125        (
 126                cd "$cli" &&
 127                test_path_is_file "file6.t" &&
 128                test_path_is_missing "file7.t"
 129        )
 130'
 131
 132#
 133# Basic submit tests, the five handled cases
 134#
 135
 136test_expect_success 'submit modify' '
 137        test_when_finished cleanup_git &&
 138        git p4 clone --dest="$git" //depot &&
 139        (
 140                cd "$git" &&
 141                git config git-p4.skipSubmitEdit true &&
 142                echo line >>file1 &&
 143                git add file1 &&
 144                git commit -m file1 &&
 145                git p4 submit
 146        ) &&
 147        (
 148                cd "$cli" &&
 149                test_path_is_file file1 &&
 150                test_line_count = 2 file1
 151        )
 152'
 153
 154test_expect_success 'submit add' '
 155        test_when_finished cleanup_git &&
 156        git p4 clone --dest="$git" //depot &&
 157        (
 158                cd "$git" &&
 159                git config git-p4.skipSubmitEdit true &&
 160                echo file13 >file13 &&
 161                git add file13 &&
 162                git commit -m file13 &&
 163                git p4 submit
 164        ) &&
 165        (
 166                cd "$cli" &&
 167                test_path_is_file file13
 168        )
 169'
 170
 171test_expect_success 'submit delete' '
 172        test_when_finished cleanup_git &&
 173        git p4 clone --dest="$git" //depot &&
 174        (
 175                cd "$git" &&
 176                git config git-p4.skipSubmitEdit true &&
 177                git rm file4.t &&
 178                git commit -m "delete file4.t" &&
 179                git p4 submit
 180        ) &&
 181        (
 182                cd "$cli" &&
 183                test_path_is_missing file4.t
 184        )
 185'
 186
 187test_expect_success 'submit copy' '
 188        test_when_finished cleanup_git &&
 189        git p4 clone --dest="$git" //depot &&
 190        (
 191                cd "$git" &&
 192                git config git-p4.skipSubmitEdit true &&
 193                git config git-p4.detectCopies true &&
 194                git config git-p4.detectCopiesHarder true &&
 195                cp file5.t file5.ta &&
 196                git add file5.ta &&
 197                git commit -m "copy to file5.ta" &&
 198                git p4 submit
 199        ) &&
 200        (
 201                cd "$cli" &&
 202                test_path_is_file file5.ta &&
 203                test ! -w file5.ta
 204        )
 205'
 206
 207test_expect_success 'submit rename' '
 208        test_when_finished cleanup_git &&
 209        git p4 clone --dest="$git" //depot &&
 210        (
 211                cd "$git" &&
 212                git config git-p4.skipSubmitEdit true &&
 213                git config git-p4.detectRenames true &&
 214                git mv file6.t file6.ta &&
 215                git commit -m "rename file6.t to file6.ta" &&
 216                git p4 submit
 217        ) &&
 218        (
 219                cd "$cli" &&
 220                test_path_is_missing file6.t &&
 221                test_path_is_file file6.ta &&
 222                test ! -w file6.ta
 223        )
 224'
 225
 226#
 227# Converting git commit message to p4 change description, including
 228# parsing out the optional Jobs: line.
 229#
 230test_expect_success 'simple one-line description' '
 231        test_when_finished cleanup_git &&
 232        git p4 clone --dest="$git" //depot &&
 233        (
 234                cd "$git" &&
 235                echo desc2 >desc2 &&
 236                git add desc2 &&
 237                cat >msg <<-EOF &&
 238                One-line description line for desc2.
 239                EOF
 240                git commit -F - <msg &&
 241                git config git-p4.skipSubmitEdit true &&
 242                git p4 submit &&
 243                change=$(p4 -G changes -m 1 //depot/... | \
 244                         marshal_dump change) &&
 245                # marshal_dump always adds a newline
 246                p4 -G describe $change | marshal_dump desc | sed \$d >pmsg &&
 247                test_cmp msg pmsg
 248        )
 249'
 250
 251test_expect_success 'description with odd formatting' '
 252        test_when_finished cleanup_git &&
 253        git p4 clone --dest="$git" //depot &&
 254        (
 255                cd "$git" &&
 256                echo desc3 >desc3 &&
 257                git add desc3 &&
 258                (
 259                        printf "subject line\n\n\tExtra tab\nline.\n\n" &&
 260                        printf "Description:\n\tBogus description marker\n\n" &&
 261                        # git commit eats trailing newlines; only use one
 262                        printf "Files:\n\tBogus descs marker\n"
 263                ) >msg &&
 264                git commit -F - <msg &&
 265                git config git-p4.skipSubmitEdit true &&
 266                git p4 submit &&
 267                change=$(p4 -G changes -m 1 //depot/... | \
 268                         marshal_dump change) &&
 269                # marshal_dump always adds a newline
 270                p4 -G describe $change | marshal_dump desc | sed \$d >pmsg &&
 271                test_cmp msg pmsg
 272        )
 273'
 274
 275make_job() {
 276        name="$1" &&
 277        tab="$(printf \\t)" &&
 278        p4 job -o | \
 279        sed -e "/^Job:/s/.*/Job: $name/" \
 280            -e "/^Description/{ n; s/.*/$tab job text/; }" | \
 281        p4 job -i
 282}
 283
 284test_expect_success 'description with Jobs section at end' '
 285        test_when_finished cleanup_git &&
 286        git p4 clone --dest="$git" //depot &&
 287        (
 288                cd "$git" &&
 289                echo desc4 >desc4 &&
 290                git add desc4 &&
 291                echo 6060842 >jobname &&
 292                (
 293                        printf "subject line\n\n\tExtra tab\nline.\n\n" &&
 294                        printf "Files:\n\tBogus files marker\n" &&
 295                        printf "Junk: 3164175\n" &&
 296                        printf "Jobs: $(cat jobname)\n"
 297                ) >msg &&
 298                git commit -F - <msg &&
 299                git config git-p4.skipSubmitEdit true &&
 300                # build a job
 301                make_job $(cat jobname) &&
 302                git p4 submit &&
 303                change=$(p4 -G changes -m 1 //depot/... | \
 304                         marshal_dump change) &&
 305                # marshal_dump always adds a newline
 306                p4 -G describe $change | marshal_dump desc | sed \$d >pmsg &&
 307                # make sure Jobs line and all following is gone
 308                sed "/^Jobs:/,\$d" msg >jmsg &&
 309                test_cmp jmsg pmsg &&
 310                # make sure p4 knows about job
 311                p4 -G describe $change | marshal_dump job0 >job0 &&
 312                test_cmp jobname job0
 313        )
 314'
 315
 316test_expect_success 'description with Jobs and values on separate lines' '
 317        test_when_finished cleanup_git &&
 318        git p4 clone --dest="$git" //depot &&
 319        (
 320                cd "$git" &&
 321                echo desc5 >desc5 &&
 322                git add desc5 &&
 323                echo PROJ-6060842 >jobname1 &&
 324                echo PROJ-6060847 >jobname2 &&
 325                (
 326                        printf "subject line\n\n\tExtra tab\nline.\n\n" &&
 327                        printf "Files:\n\tBogus files marker\n" &&
 328                        printf "Junk: 3164175\n" &&
 329                        printf "Jobs:\n" &&
 330                        printf "\t$(cat jobname1)\n" &&
 331                        printf "\t$(cat jobname2)\n"
 332                ) >msg &&
 333                git commit -F - <msg &&
 334                git config git-p4.skipSubmitEdit true &&
 335                # build two jobs
 336                make_job $(cat jobname1) &&
 337                make_job $(cat jobname2) &&
 338                git p4 submit &&
 339                change=$(p4 -G changes -m 1 //depot/... | \
 340                         marshal_dump change) &&
 341                # marshal_dump always adds a newline
 342                p4 -G describe $change | marshal_dump desc | sed \$d >pmsg &&
 343                # make sure Jobs line and all following is gone
 344                sed "/^Jobs:/,\$d" msg >jmsg &&
 345                test_cmp jmsg pmsg &&
 346                # make sure p4 knows about the two jobs
 347                p4 -G describe $change >change &&
 348                (
 349                        marshal_dump job0 <change &&
 350                        marshal_dump job1 <change
 351                ) | sort >jobs &&
 352                cat jobname1 jobname2 | sort >expected &&
 353                test_cmp expected jobs
 354        )
 355'
 356
 357test_expect_success 'description with Jobs section and bogus following text' '
 358        test_when_finished cleanup_git &&
 359        git p4 clone --dest="$git" //depot &&
 360        (
 361                cd "$git" &&
 362                echo desc6 >desc6 &&
 363                git add desc6 &&
 364                echo 6060843 >jobname &&
 365                (
 366                        printf "subject line\n\n\tExtra tab\nline.\n\n" &&
 367                        printf "Files:\n\tBogus files marker\n" &&
 368                        printf "Junk: 3164175\n" &&
 369                        printf "Jobs: $(cat jobname)\n" &&
 370                        printf "MoreJunk: 3711\n"
 371                ) >msg &&
 372                git commit -F - <msg &&
 373                git config git-p4.skipSubmitEdit true &&
 374                # build a job
 375                make_job $(cat jobname) &&
 376                test_must_fail git p4 submit 2>err &&
 377                test_i18ngrep "Unknown field name" err
 378        ) &&
 379        (
 380                cd "$cli" &&
 381                p4 revert desc6 &&
 382                rm desc6
 383        )
 384'
 385
 386test_expect_success 'submit --prepare-p4-only' '
 387        test_when_finished cleanup_git &&
 388        git p4 clone --dest="$git" //depot &&
 389        (
 390                cd "$git" &&
 391                echo prep-only-add >prep-only-add &&
 392                git add prep-only-add &&
 393                git commit -m "prep only add" &&
 394                git p4 submit --prepare-p4-only >out &&
 395                test_i18ngrep "prepared for submission" out &&
 396                test_i18ngrep "must be deleted" out
 397        ) &&
 398        (
 399                cd "$cli" &&
 400                test_path_is_file prep-only-add &&
 401                p4 fstat -T action prep-only-add | grep -w add
 402        )
 403'
 404
 405test_expect_success 'kill p4d' '
 406        kill_p4d
 407'
 408
 409test_done