t / t9807-git-p4-submit.shon commit i18n: status: mark parseopt strings for translation (f227631)
   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 with allowSubmit' '
  58        test_when_finished cleanup_git &&
  59        git p4 clone --dest="$git" //depot &&
  60        (
  61                cd "$git" &&
  62                test_commit "file5" &&
  63                git config git-p4.skipSubmitEdit true &&
  64                git config git-p4.allowSubmit "nobranch" &&
  65                test_must_fail git p4 submit &&
  66                git config git-p4.allowSubmit "nobranch,master" &&
  67                git p4 submit
  68        )
  69'
  70
  71test_expect_success 'submit with master branch name from argv' '
  72        test_when_finished cleanup_git &&
  73        git p4 clone --dest="$git" //depot &&
  74        (
  75                cd "$git" &&
  76                test_commit "file6" &&
  77                git config git-p4.skipSubmitEdit true &&
  78                test_must_fail git p4 submit nobranch &&
  79                git branch otherbranch &&
  80                git reset --hard HEAD^ &&
  81                test_commit "file7" &&
  82                git p4 submit otherbranch
  83        ) &&
  84        (
  85                cd "$cli" &&
  86                test_path_is_file "file6.t" &&
  87                test_path_is_missing "file7.t"
  88        )
  89'
  90
  91#
  92# Basic submit tests, the five handled cases
  93#
  94
  95test_expect_success 'submit modify' '
  96        test_when_finished cleanup_git &&
  97        git p4 clone --dest="$git" //depot &&
  98        (
  99                cd "$git" &&
 100                git config git-p4.skipSubmitEdit true &&
 101                echo line >>file1 &&
 102                git add file1 &&
 103                git commit -m file1 &&
 104                git p4 submit
 105        ) &&
 106        (
 107                cd "$cli" &&
 108                test_path_is_file file1 &&
 109                test_line_count = 2 file1
 110        )
 111'
 112
 113test_expect_success 'submit add' '
 114        test_when_finished cleanup_git &&
 115        git p4 clone --dest="$git" //depot &&
 116        (
 117                cd "$git" &&
 118                git config git-p4.skipSubmitEdit true &&
 119                echo file13 >file13 &&
 120                git add file13 &&
 121                git commit -m file13 &&
 122                git p4 submit
 123        ) &&
 124        (
 125                cd "$cli" &&
 126                test_path_is_file file13
 127        )
 128'
 129
 130test_expect_success 'submit delete' '
 131        test_when_finished cleanup_git &&
 132        git p4 clone --dest="$git" //depot &&
 133        (
 134                cd "$git" &&
 135                git config git-p4.skipSubmitEdit true &&
 136                git rm file4.t &&
 137                git commit -m "delete file4.t" &&
 138                git p4 submit
 139        ) &&
 140        (
 141                cd "$cli" &&
 142                test_path_is_missing file4.t
 143        )
 144'
 145
 146test_expect_success 'submit copy' '
 147        test_when_finished cleanup_git &&
 148        git p4 clone --dest="$git" //depot &&
 149        (
 150                cd "$git" &&
 151                git config git-p4.skipSubmitEdit true &&
 152                git config git-p4.detectCopies true &&
 153                git config git-p4.detectCopiesHarder true &&
 154                cp file5.t file5.ta &&
 155                git add file5.ta &&
 156                git commit -m "copy to file5.ta" &&
 157                git p4 submit
 158        ) &&
 159        (
 160                cd "$cli" &&
 161                test_path_is_file file5.ta &&
 162                test ! -w file5.ta
 163        )
 164'
 165
 166test_expect_success 'submit rename' '
 167        test_when_finished cleanup_git &&
 168        git p4 clone --dest="$git" //depot &&
 169        (
 170                cd "$git" &&
 171                git config git-p4.skipSubmitEdit true &&
 172                git config git-p4.detectRenames true &&
 173                git mv file6.t file6.ta &&
 174                git commit -m "rename file6.t to file6.ta" &&
 175                git p4 submit
 176        ) &&
 177        (
 178                cd "$cli" &&
 179                test_path_is_missing file6.t &&
 180                test_path_is_file file6.ta &&
 181                test ! -w file6.ta
 182        )
 183'
 184
 185#
 186# Converting git commit message to p4 change description, including
 187# parsing out the optional Jobs: line.
 188#
 189test_expect_success 'simple one-line description' '
 190        test_when_finished cleanup_git &&
 191        git p4 clone --dest="$git" //depot &&
 192        (
 193                cd "$git" &&
 194                echo desc2 >desc2 &&
 195                git add desc2 &&
 196                cat >msg <<-EOF &&
 197                One-line description line for desc2.
 198                EOF
 199                git commit -F - <msg &&
 200                git config git-p4.skipSubmitEdit true &&
 201                git p4 submit &&
 202                change=$(p4 -G changes -m 1 //depot/... | \
 203                         marshal_dump change) &&
 204                # marshal_dump always adds a newline
 205                p4 -G describe $change | marshal_dump desc | sed \$d >pmsg &&
 206                test_cmp msg pmsg
 207        )
 208'
 209
 210test_expect_success 'description with odd formatting' '
 211        test_when_finished cleanup_git &&
 212        git p4 clone --dest="$git" //depot &&
 213        (
 214                cd "$git" &&
 215                echo desc3 >desc3 &&
 216                git add desc3 &&
 217                (
 218                        printf "subject line\n\n\tExtra tab\nline.\n\n" &&
 219                        printf "Description:\n\tBogus description marker\n\n" &&
 220                        # git commit eats trailing newlines; only use one
 221                        printf "Files:\n\tBogus descs marker\n"
 222                ) >msg &&
 223                git commit -F - <msg &&
 224                git config git-p4.skipSubmitEdit true &&
 225                git p4 submit &&
 226                change=$(p4 -G changes -m 1 //depot/... | \
 227                         marshal_dump change) &&
 228                # marshal_dump always adds a newline
 229                p4 -G describe $change | marshal_dump desc | sed \$d >pmsg &&
 230                test_cmp msg pmsg
 231        )
 232'
 233
 234make_job() {
 235        name="$1" &&
 236        tab="$(printf \\t)" &&
 237        p4 job -o | \
 238        sed -e "/^Job:/s/.*/Job: $name/" \
 239            -e "/^Description/{ n; s/.*/$tab job text/; }" | \
 240        p4 job -i
 241}
 242
 243test_expect_success 'description with Jobs section at end' '
 244        test_when_finished cleanup_git &&
 245        git p4 clone --dest="$git" //depot &&
 246        (
 247                cd "$git" &&
 248                echo desc4 >desc4 &&
 249                git add desc4 &&
 250                echo 6060842 >jobname &&
 251                (
 252                        printf "subject line\n\n\tExtra tab\nline.\n\n" &&
 253                        printf "Files:\n\tBogus files marker\n" &&
 254                        printf "Junk: 3164175\n" &&
 255                        printf "Jobs: $(cat jobname)\n"
 256                ) >msg &&
 257                git commit -F - <msg &&
 258                git config git-p4.skipSubmitEdit true &&
 259                # build a job
 260                make_job $(cat jobname) &&
 261                git p4 submit &&
 262                change=$(p4 -G changes -m 1 //depot/... | \
 263                         marshal_dump change) &&
 264                # marshal_dump always adds a newline
 265                p4 -G describe $change | marshal_dump desc | sed \$d >pmsg &&
 266                # make sure Jobs line and all following is gone
 267                sed "/^Jobs:/,\$d" msg >jmsg &&
 268                test_cmp jmsg pmsg &&
 269                # make sure p4 knows about job
 270                p4 -G describe $change | marshal_dump job0 >job0 &&
 271                test_cmp jobname job0
 272        )
 273'
 274
 275test_expect_success 'description with Jobs and values on separate lines' '
 276        test_when_finished cleanup_git &&
 277        git p4 clone --dest="$git" //depot &&
 278        (
 279                cd "$git" &&
 280                echo desc5 >desc5 &&
 281                git add desc5 &&
 282                echo PROJ-6060842 >jobname1 &&
 283                echo PROJ-6060847 >jobname2 &&
 284                (
 285                        printf "subject line\n\n\tExtra tab\nline.\n\n" &&
 286                        printf "Files:\n\tBogus files marker\n" &&
 287                        printf "Junk: 3164175\n" &&
 288                        printf "Jobs:\n" &&
 289                        printf "\t$(cat jobname1)\n" &&
 290                        printf "\t$(cat jobname2)\n"
 291                ) >msg &&
 292                git commit -F - <msg &&
 293                git config git-p4.skipSubmitEdit true &&
 294                # build two jobs
 295                make_job $(cat jobname1) &&
 296                make_job $(cat jobname2) &&
 297                git p4 submit &&
 298                change=$(p4 -G changes -m 1 //depot/... | \
 299                         marshal_dump change) &&
 300                # marshal_dump always adds a newline
 301                p4 -G describe $change | marshal_dump desc | sed \$d >pmsg &&
 302                # make sure Jobs line and all following is gone
 303                sed "/^Jobs:/,\$d" msg >jmsg &&
 304                test_cmp jmsg pmsg &&
 305                # make sure p4 knows about the two jobs
 306                p4 -G describe $change >change &&
 307                (
 308                        marshal_dump job0 <change &&
 309                        marshal_dump job1 <change
 310                ) | sort >jobs &&
 311                cat jobname1 jobname2 | sort >expected &&
 312                test_cmp expected jobs
 313        )
 314'
 315
 316test_expect_success 'description with Jobs section and bogus following text' '
 317        test_when_finished cleanup_git &&
 318        git p4 clone --dest="$git" //depot &&
 319        (
 320                cd "$git" &&
 321                echo desc6 >desc6 &&
 322                git add desc6 &&
 323                echo 6060843 >jobname &&
 324                (
 325                        printf "subject line\n\n\tExtra tab\nline.\n\n" &&
 326                        printf "Files:\n\tBogus files marker\n" &&
 327                        printf "Junk: 3164175\n" &&
 328                        printf "Jobs: $(cat jobname)\n" &&
 329                        printf "MoreJunk: 3711\n"
 330                ) >msg &&
 331                git commit -F - <msg &&
 332                git config git-p4.skipSubmitEdit true &&
 333                # build a job
 334                make_job $(cat jobname) &&
 335                test_must_fail git p4 submit 2>err &&
 336                test_i18ngrep "Unknown field name" err
 337        )
 338'
 339
 340test_expect_success 'kill p4d' '
 341        kill_p4d
 342'
 343
 344test_done