3 test_description='git p4 submit'
 
   7 test_expect_success 'start p4d' '
 
  11 test_expect_success 'init depot' '
 
  16                 p4 submit -d "change 1"
 
  20 test_expect_success 'is_cli_file_writeable function' '
 
  24                 is_cli_file_writeable a &&
 
  25                 ! is_cli_file_writeable file1 &&
 
  30 test_expect_success 'submit with no client dir' '
 
  31         test_when_finished cleanup_git &&
 
  32         git p4 clone --dest="$git" //depot &&
 
  37                 git commit -m "git commit 2" &&
 
  39                 git config git-p4.skipSubmitEdit true &&
 
  44                 test_path_is_file file1 &&
 
  45                 test_path_is_file file2
 
  49 # make two commits, but tell it to apply only from HEAD^
 
  50 test_expect_success 'submit --origin' '
 
  51         test_when_finished cleanup_git &&
 
  52         git p4 clone --dest="$git" //depot &&
 
  55                 test_commit "file3" &&
 
  56                 test_commit "file4" &&
 
  57                 git config git-p4.skipSubmitEdit true &&
 
  58                 git p4 submit --origin=HEAD^
 
  62                 test_path_is_missing "file3.t" &&
 
  63                 test_path_is_file "file4.t"
 
  67 test_expect_success 'submit --dry-run' '
 
  68         test_when_finished cleanup_git &&
 
  69         git p4 clone --dest="$git" //depot &&
 
  72                 test_commit "dry-run1" &&
 
  73                 test_commit "dry-run2" &&
 
  74                 git p4 submit --dry-run >out &&
 
  75                 test_i18ngrep "Would apply" out
 
  79                 test_path_is_missing "dry-run1.t" &&
 
  80                 test_path_is_missing "dry-run2.t"
 
  84 test_expect_success 'submit --dry-run --export-labels' '
 
  85         test_when_finished cleanup_git &&
 
  86         git p4 clone --dest="$git" //depot &&
 
  89                 echo dry-run1 >dry-run1 &&
 
  91                 git commit -m "dry-run1" dry-run1 &&
 
  92                 git config git-p4.skipSubmitEdit true &&
 
  94                 echo dry-run2 >dry-run2 &&
 
  96                 git commit -m "dry-run2" dry-run2 &&
 
  97                 git tag -m "dry-run-tag1" dry-run-tag1 HEAD^ &&
 
  98                 git p4 submit --dry-run --export-labels >out &&
 
  99                 test_i18ngrep "Would create p4 label" out
 
 103                 test_path_is_file "dry-run1" &&
 
 104                 test_path_is_missing "dry-run2"
 
 108 test_expect_success 'submit with allowSubmit' '
 
 109         test_when_finished cleanup_git &&
 
 110         git p4 clone --dest="$git" //depot &&
 
 113                 test_commit "file5" &&
 
 114                 git config git-p4.skipSubmitEdit true &&
 
 115                 git config git-p4.allowSubmit "nobranch" &&
 
 116                 test_must_fail git p4 submit &&
 
 117                 git config git-p4.allowSubmit "nobranch,master" &&
 
 122 test_expect_success 'submit with master branch name from argv' '
 
 123         test_when_finished cleanup_git &&
 
 124         git p4 clone --dest="$git" //depot &&
 
 127                 test_commit "file6" &&
 
 128                 git config git-p4.skipSubmitEdit true &&
 
 129                 test_must_fail git p4 submit nobranch &&
 
 130                 git branch otherbranch &&
 
 131                 git reset --hard HEAD^ &&
 
 132                 test_commit "file7" &&
 
 133                 git p4 submit otherbranch
 
 137                 test_path_is_file "file6.t" &&
 
 138                 test_path_is_missing "file7.t"
 
 142 test_expect_success 'allow submit from branch with same revision but different name' '
 
 143         test_when_finished cleanup_git &&
 
 144         git p4 clone --dest="$git" //depot &&
 
 147                 test_commit "file8" &&
 
 148                 git checkout -b branch1 &&
 
 149                 git checkout -b branch2 &&
 
 150                 git config git-p4.skipSubmitEdit true &&
 
 151                 git config git-p4.allowSubmit "branch1" &&
 
 152                 test_must_fail git p4 submit &&
 
 153                 git checkout branch1 &&
 
 158 # make two commits, but tell it to apply only one
 
 160 test_expect_success 'submit --commit one' '
 
 161         test_when_finished cleanup_git &&
 
 162         git p4 clone --dest="$git" //depot &&
 
 165                 test_commit "file9" &&
 
 166                 test_commit "file10" &&
 
 167                 git config git-p4.skipSubmitEdit true &&
 
 168                 git p4 submit --commit HEAD
 
 172                 test_path_is_missing "file9.t" &&
 
 173                 test_path_is_file "file10.t"
 
 177 # make three commits, but tell it to apply only range
 
 179 test_expect_success 'submit --commit range' '
 
 180         test_when_finished cleanup_git &&
 
 181         git p4 clone --dest="$git" //depot &&
 
 184                 test_commit "file11" &&
 
 185                 test_commit "file12" &&
 
 186                 test_commit "file13" &&
 
 187                 git config git-p4.skipSubmitEdit true &&
 
 188                 git p4 submit --commit HEAD~2..HEAD
 
 192                 test_path_is_missing "file11.t" &&
 
 193                 test_path_is_file "file12.t" &&
 
 194                 test_path_is_file "file13.t"
 
 199 # Basic submit tests, the five handled cases
 
 202 test_expect_success 'submit modify' '
 
 203         test_when_finished cleanup_git &&
 
 204         git p4 clone --dest="$git" //depot &&
 
 207                 git config git-p4.skipSubmitEdit true &&
 
 210                 git commit -m file1 &&
 
 215                 test_path_is_file file1 &&
 
 216                 test_line_count = 2 file1
 
 220 test_expect_success 'submit add' '
 
 221         test_when_finished cleanup_git &&
 
 222         git p4 clone --dest="$git" //depot &&
 
 225                 git config git-p4.skipSubmitEdit true &&
 
 226                 echo file13 >file13 &&
 
 228                 git commit -m file13 &&
 
 233                 test_path_is_file file13
 
 237 test_expect_success 'submit delete' '
 
 238         test_when_finished cleanup_git &&
 
 239         git p4 clone --dest="$git" //depot &&
 
 242                 git config git-p4.skipSubmitEdit true &&
 
 244                 git commit -m "delete file4.t" &&
 
 249                 test_path_is_missing file4.t
 
 253 test_expect_success 'submit copy' '
 
 254         test_when_finished cleanup_git &&
 
 255         git p4 clone --dest="$git" //depot &&
 
 258                 git config git-p4.skipSubmitEdit true &&
 
 259                 git config git-p4.detectCopies true &&
 
 260                 git config git-p4.detectCopiesHarder true &&
 
 261                 cp file5.t file5.ta &&
 
 263                 git commit -m "copy to file5.ta" &&
 
 268                 test_path_is_file file5.ta &&
 
 269                 ! is_cli_file_writeable file5.ta
 
 273 test_expect_success 'submit rename' '
 
 274         test_when_finished cleanup_git &&
 
 275         git p4 clone --dest="$git" //depot &&
 
 278                 git config git-p4.skipSubmitEdit true &&
 
 279                 git config git-p4.detectRenames true &&
 
 280                 git mv file6.t file6.ta &&
 
 281                 git commit -m "rename file6.t to file6.ta" &&
 
 286                 test_path_is_missing file6.t &&
 
 287                 test_path_is_file file6.ta &&
 
 288                 ! is_cli_file_writeable file6.ta
 
 293 # Converting git commit message to p4 change description, including
 
 294 # parsing out the optional Jobs: line.
 
 296 test_expect_success 'simple one-line description' '
 
 297         test_when_finished cleanup_git &&
 
 298         git p4 clone --dest="$git" //depot &&
 
 304                 One-line description line for desc2.
 
 306                 git commit -F - <msg &&
 
 307                 git config git-p4.skipSubmitEdit true &&
 
 309                 change=$(p4 -G changes -m 1 //depot/... | \
 
 310                          marshal_dump change) &&
 
 311                 # marshal_dump always adds a newline
 
 312                 p4 -G describe $change | marshal_dump desc | sed \$d >pmsg &&
 
 317 test_expect_success 'description with odd formatting' '
 
 318         test_when_finished cleanup_git &&
 
 319         git p4 clone --dest="$git" //depot &&
 
 325                         printf "subject line\n\n\tExtra tab\nline.\n\n" &&
 
 326                         printf "Description:\n\tBogus description marker\n\n" &&
 
 327                         # git commit eats trailing newlines; only use one
 
 328                         printf "Files:\n\tBogus descs marker\n"
 
 330                 git commit -F - <msg &&
 
 331                 git config git-p4.skipSubmitEdit true &&
 
 333                 change=$(p4 -G changes -m 1 //depot/... | \
 
 334                          marshal_dump change) &&
 
 335                 # marshal_dump always adds a newline
 
 336                 p4 -G describe $change | marshal_dump desc | sed \$d >pmsg &&
 
 343         tab="$(printf \\t)" &&
 
 345         sed -e "/^Job:/s/.*/Job: $name/" \
 
 346             -e "/^Description/{ n; s/.*/$tab job text/; }" | \
 
 350 test_expect_success 'description with Jobs section at end' '
 
 351         test_when_finished cleanup_git &&
 
 352         git p4 clone --dest="$git" //depot &&
 
 357                 echo 6060842 >jobname &&
 
 359                         printf "subject line\n\n\tExtra tab\nline.\n\n" &&
 
 360                         printf "Files:\n\tBogus files marker\n" &&
 
 361                         printf "Junk: 3164175\n" &&
 
 362                         printf "Jobs: $(cat jobname)\n"
 
 364                 git commit -F - <msg &&
 
 365                 git config git-p4.skipSubmitEdit true &&
 
 367                 make_job $(cat jobname) &&
 
 369                 change=$(p4 -G changes -m 1 //depot/... | \
 
 370                          marshal_dump change) &&
 
 371                 # marshal_dump always adds a newline
 
 372                 p4 -G describe $change | marshal_dump desc | sed \$d >pmsg &&
 
 373                 # make sure Jobs line and all following is gone
 
 374                 sed "/^Jobs:/,\$d" msg >jmsg &&
 
 375                 test_cmp jmsg pmsg &&
 
 376                 # make sure p4 knows about job
 
 377                 p4 -G describe $change | marshal_dump job0 >job0 &&
 
 378                 test_cmp jobname job0
 
 382 test_expect_success 'description with Jobs and values on separate lines' '
 
 383         test_when_finished cleanup_git &&
 
 384         git p4 clone --dest="$git" //depot &&
 
 389                 echo PROJ-6060842 >jobname1 &&
 
 390                 echo PROJ-6060847 >jobname2 &&
 
 392                         printf "subject line\n\n\tExtra tab\nline.\n\n" &&
 
 393                         printf "Files:\n\tBogus files marker\n" &&
 
 394                         printf "Junk: 3164175\n" &&
 
 396                         printf "\t$(cat jobname1)\n" &&
 
 397                         printf "\t$(cat jobname2)\n"
 
 399                 git commit -F - <msg &&
 
 400                 git config git-p4.skipSubmitEdit true &&
 
 402                 make_job $(cat jobname1) &&
 
 403                 make_job $(cat jobname2) &&
 
 405                 change=$(p4 -G changes -m 1 //depot/... | \
 
 406                          marshal_dump change) &&
 
 407                 # marshal_dump always adds a newline
 
 408                 p4 -G describe $change | marshal_dump desc | sed \$d >pmsg &&
 
 409                 # make sure Jobs line and all following is gone
 
 410                 sed "/^Jobs:/,\$d" msg >jmsg &&
 
 411                 test_cmp jmsg pmsg &&
 
 412                 # make sure p4 knows about the two jobs
 
 413                 p4 -G describe $change >change &&
 
 415                         marshal_dump job0 <change &&
 
 416                         marshal_dump job1 <change
 
 418                 cat jobname1 jobname2 | sort >expected &&
 
 419                 test_cmp expected jobs
 
 423 test_expect_success 'description with Jobs section and bogus following text' '
 
 424         test_when_finished cleanup_git &&
 
 425         git p4 clone --dest="$git" //depot &&
 
 430                 echo 6060843 >jobname &&
 
 432                         printf "subject line\n\n\tExtra tab\nline.\n\n" &&
 
 433                         printf "Files:\n\tBogus files marker\n" &&
 
 434                         printf "Junk: 3164175\n" &&
 
 435                         printf "Jobs: $(cat jobname)\n" &&
 
 436                         printf "MoreJunk: 3711\n"
 
 438                 git commit -F - <msg &&
 
 439                 git config git-p4.skipSubmitEdit true &&
 
 441                 make_job $(cat jobname) &&
 
 442                 test_must_fail git p4 submit 2>err &&
 
 443                 test_i18ngrep "Unknown field name" err
 
 452 test_expect_success 'submit --prepare-p4-only' '
 
 453         test_when_finished cleanup_git &&
 
 454         git p4 clone --dest="$git" //depot &&
 
 457                 echo prep-only-add >prep-only-add &&
 
 458                 git add prep-only-add &&
 
 459                 git commit -m "prep only add" &&
 
 460                 git p4 submit --prepare-p4-only >out &&
 
 461                 test_i18ngrep "prepared for submission" out &&
 
 462                 test_i18ngrep "must be deleted" out &&
 
 463                 test_i18ngrep ! "everything below this line is just the diff" out
 
 467                 test_path_is_file prep-only-add &&
 
 468                 p4 fstat -T action prep-only-add | grep -w add
 
 472 test_expect_success 'submit --shelve' '
 
 473         test_when_finished cleanup_git &&
 
 474         git p4 clone --dest="$git" //depot &&
 
 479                 git config git-p4.skipSubmitEdit true &&
 
 480                 test_commit "shelveme1" &&
 
 481                 git p4 submit --origin=HEAD^ &&
 
 483                 echo 654321 >shelveme2.t &&
 
 484                 echo 123456 >>shelveme1.t &&
 
 486                 git commit -m"shelvetest" &&
 
 487                 git p4 submit --shelve --origin=HEAD^ &&
 
 489                 test_path_is_file shelveme1.t &&
 
 490                 test_path_is_file shelveme2.t
 
 494                 change=$(p4 -G changes -s shelved -m 1 //depot/... | \
 
 495                          marshal_dump change) &&
 
 496                 p4 describe -S $change | grep shelveme2 &&
 
 497                 p4 describe -S $change | grep 123456 &&
 
 498                 test_path_is_file shelveme1.t &&
 
 499                 test_path_is_missing shelveme2.t
 
 504         p4 -G changes -s shelved -m 1 //depot/... | marshal_dump change
 
 508         test_commit "$1" >/dev/null &&
 
 509         git p4 submit --origin HEAD^ --shelve >/dev/null &&
 
 510         p4 -G changes -s shelved -m 1 | marshal_dump change
 
 513 # Update existing shelved changelists
 
 515 test_expect_success 'submit --update-shelve' '
 
 516         test_when_finished cleanup_git &&
 
 517         git p4 clone --dest="$git" //depot &&
 
 522                 git config git-p4.skipSubmitEdit true &&
 
 523                 shelved_cl0=$(make_shelved_cl "shelved-change-0") &&
 
 524                 echo shelved_cl0=$shelved_cl0 &&
 
 525                 shelved_cl1=$(make_shelved_cl "shelved-change-1") &&
 
 527                 echo "updating shelved change lists $shelved_cl0 and $shelved_cl1" &&
 
 529                 echo "updated-line" >>shelf.t &&
 
 530                 echo added-file.t >added-file.t &&
 
 531                 git add shelf.t added-file.t &&
 
 532                 git rm -f shelved-change-1.t &&
 
 533                 git commit --amend -C HEAD &&
 
 534                 git show --stat HEAD &&
 
 535                 git p4 submit -v --origin HEAD~2 --update-shelve $shelved_cl0 --update-shelve $shelved_cl1 &&
 
 536                 echo "done git p4 submit"
 
 540                 change=$(last_shelve) &&
 
 541                 p4 unshelve -c $change -s $change &&
 
 542                 grep -q updated-line shelf.t &&
 
 543                 p4 describe -S $change | grep added-file.t &&
 
 544                 test_path_is_missing shelved-change-1.t &&
 
 549 test_expect_success 'update a shelve involving moved and copied files' '
 
 550         test_when_finished cleanup_git &&
 
 554                 p4 add file_to_move &&
 
 555                 p4 submit -d "change1" &&
 
 556                 p4 edit file_to_move &&
 
 557                 echo change >>file_to_move &&
 
 558                 p4 submit -d "change2" &&
 
 561         git p4 clone --dest="$git" //depot &&
 
 564                 git config git-p4.detectCopies true &&
 
 565                 git config git-p4.detectRenames true &&
 
 566                 git config git-p4.skipSubmitEdit true &&
 
 568                 cp file_to_move copy_of_file &&
 
 569                 git add copy_of_file &&
 
 570                 git mv file_to_move moved/ &&
 
 571                 git commit -m "rename a file" &&
 
 572                 git p4 submit -M --shelve --origin HEAD^ &&
 
 575                 git commit --amend &&
 
 576                 git show --stat HEAD &&
 
 577                 change=$(last_shelve) &&
 
 578                 git p4 submit -M --update-shelve $change --commit HEAD
 
 582                 change=$(last_shelve) &&
 
 583                 echo change=$change &&
 
 584                 p4 unshelve -s $change &&
 
 585                 p4 submit -d "Testing update-shelve" &&
 
 586                 test_path_is_file copy_of_file &&
 
 587                 test_path_is_file moved/file_to_move &&
 
 588                 test_path_is_missing file_to_move &&
 
 589                 test_path_is_file new_file &&
 
 590                 echo "unshelved and submitted change $change" &&
 
 591                 p4 changes moved/file_to_move | grep "Testing update-shelve" &&
 
 592                 p4 changes copy_of_file | grep "Testing update-shelve"