t / t9815-git-p4-submit-fail.shon commit test-lib: factor out $GIT_UNZIP setup (f838ce5)
   1#!/bin/sh
   2
   3test_description='git p4 submit failure handling'
   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                p4 client -o | sed "/LineEnd/s/:.*/:unix/" | p4 client -i &&
  15                echo line1 >file1 &&
  16                p4 add file1 &&
  17                p4 submit -d "line1 in file1"
  18        )
  19'
  20
  21test_expect_success 'conflict on one commit' '
  22        test_when_finished cleanup_git &&
  23        git p4 clone --dest="$git" //depot &&
  24        (
  25                cd "$cli" &&
  26                p4 open file1 &&
  27                echo line2 >>file1 &&
  28                p4 submit -d "line2 in file1"
  29        ) &&
  30        (
  31                # now this commit should cause a conflict
  32                cd "$git" &&
  33                git config git-p4.skipSubmitEdit true &&
  34                echo line3 >>file1 &&
  35                git add file1 &&
  36                git commit -m "line3 in file1 will conflict" &&
  37                test_expect_code 1 git p4 submit >out &&
  38                test_i18ngrep "No commits applied" out
  39        )
  40'
  41
  42test_expect_success 'conflict on second of two commits' '
  43        test_when_finished cleanup_git &&
  44        git p4 clone --dest="$git" //depot &&
  45        (
  46                cd "$cli" &&
  47                p4 open file1 &&
  48                echo line3 >>file1 &&
  49                p4 submit -d "line3 in file1"
  50        ) &&
  51        (
  52                cd "$git" &&
  53                git config git-p4.skipSubmitEdit true &&
  54                # this commit is okay
  55                test_commit "first_commit_okay" &&
  56                # now this submit should cause a conflict
  57                echo line4 >>file1 &&
  58                git add file1 &&
  59                git commit -m "line4 in file1 will conflict" &&
  60                test_expect_code 1 git p4 submit >out &&
  61                test_i18ngrep "Applied only the commits" out
  62        )
  63'
  64
  65test_expect_success 'conflict on first of two commits, skip' '
  66        test_when_finished cleanup_git &&
  67        git p4 clone --dest="$git" //depot &&
  68        (
  69                cd "$cli" &&
  70                p4 open file1 &&
  71                echo line4 >>file1 &&
  72                p4 submit -d "line4 in file1"
  73        ) &&
  74        (
  75                cd "$git" &&
  76                git config git-p4.skipSubmitEdit true &&
  77                # this submit should cause a conflict
  78                echo line5 >>file1 &&
  79                git add file1 &&
  80                git commit -m "line5 in file1 will conflict" &&
  81                # but this commit is okay
  82                test_commit "okay_commit_after_skip" &&
  83                echo s | test_expect_code 1 git p4 submit >out &&
  84                test_i18ngrep "Applied only the commits" out
  85        )
  86'
  87
  88test_expect_success 'conflict on first of two commits, quit' '
  89        test_when_finished cleanup_git &&
  90        git p4 clone --dest="$git" //depot &&
  91        (
  92                cd "$cli" &&
  93                p4 open file1 &&
  94                echo line7 >>file1 &&
  95                p4 submit -d "line7 in file1"
  96        ) &&
  97        (
  98                cd "$git" &&
  99                git config git-p4.skipSubmitEdit true &&
 100                # this submit should cause a conflict
 101                echo line8 >>file1 &&
 102                git add file1 &&
 103                git commit -m "line8 in file1 will conflict" &&
 104                # but this commit is okay
 105                test_commit "okay_commit_after_quit" &&
 106                echo q | test_expect_code 1 git p4 submit >out &&
 107                test_i18ngrep "No commits applied" out
 108        )
 109'
 110
 111test_expect_success 'conflict cli and config options' '
 112        test_when_finished cleanup_git &&
 113        git p4 clone --dest="$git" //depot &&
 114        (
 115                cd "$git" &&
 116                git p4 submit --conflict=ask &&
 117                git p4 submit --conflict=skip &&
 118                git p4 submit --conflict=quit &&
 119                test_expect_code 2 git p4 submit --conflict=foo &&
 120                test_expect_code 2 git p4 submit --conflict &&
 121                git config git-p4.conflict foo &&
 122                test_expect_code 1 git p4 submit &&
 123                git config --unset git-p4.conflict &&
 124                git p4 submit
 125        )
 126'
 127
 128test_expect_success 'conflict on first of two commits, --conflict=skip' '
 129        test_when_finished cleanup_git &&
 130        git p4 clone --dest="$git" //depot &&
 131        (
 132                cd "$cli" &&
 133                p4 open file1 &&
 134                echo line9 >>file1 &&
 135                p4 submit -d "line9 in file1"
 136        ) &&
 137        (
 138                cd "$git" &&
 139                git config git-p4.skipSubmitEdit true &&
 140                # this submit should cause a conflict
 141                echo line10 >>file1 &&
 142                git add file1 &&
 143                git commit -m "line10 in file1 will conflict" &&
 144                # but this commit is okay
 145                test_commit "okay_commit_after_auto_skip" &&
 146                test_expect_code 1 git p4 submit --conflict=skip >out &&
 147                test_i18ngrep "Applied only the commits" out
 148        )
 149'
 150
 151test_expect_success 'conflict on first of two commits, --conflict=quit' '
 152        test_when_finished cleanup_git &&
 153        git p4 clone --dest="$git" //depot &&
 154        (
 155                cd "$cli" &&
 156                p4 open file1 &&
 157                echo line11 >>file1 &&
 158                p4 submit -d "line11 in file1"
 159        ) &&
 160        (
 161                cd "$git" &&
 162                git config git-p4.skipSubmitEdit true &&
 163                # this submit should cause a conflict
 164                echo line12 >>file1 &&
 165                git add file1 &&
 166                git commit -m "line12 in file1 will conflict" &&
 167                # but this commit is okay
 168                test_commit "okay_commit_after_auto_quit" &&
 169                test_expect_code 1 git p4 submit --conflict=quit >out &&
 170                test_i18ngrep "No commits applied" out
 171        )
 172'
 173
 174#
 175# Cleanup after submit fail, all cases.  Some modifications happen
 176# before trying to apply the patch.  Make sure these are unwound
 177# properly.  Put each one in a diff along with something that will
 178# obviously conflict.  Make sure it is back to normal after.
 179#
 180
 181test_expect_success 'cleanup edit p4 populate' '
 182        (
 183                cd "$cli" &&
 184                echo text file >text &&
 185                p4 add text &&
 186                echo text+x file >text+x &&
 187                chmod 755 text+x &&
 188                p4 add text+x &&
 189                p4 submit -d "populate p4"
 190        )
 191'
 192
 193setup_conflict() {
 194        # clone before modifying file1 to force it to conflict
 195        test_when_finished cleanup_git &&
 196        git p4 clone --dest="$git" //depot &&
 197        # ticks outside subshells
 198        test_tick &&
 199        (
 200                cd "$cli" &&
 201                p4 open file1 &&
 202                echo $test_tick >>file1 &&
 203                p4 submit -d "$test_tick in file1"
 204        ) &&
 205        test_tick &&
 206        (
 207                cd "$git" &&
 208                git config git-p4.skipSubmitEdit true &&
 209                # easy conflict
 210                echo $test_tick >>file1 &&
 211                git add file1
 212                # caller will add more and submit
 213        )
 214}
 215
 216test_expect_success 'cleanup edit after submit fail' '
 217        setup_conflict &&
 218        (
 219                cd "$git" &&
 220                echo another line >>text &&
 221                git add text &&
 222                git commit -m "conflict" &&
 223                test_expect_code 1 git p4 submit
 224        ) &&
 225        (
 226                cd "$cli" &&
 227                # make sure it is not open
 228                ! p4 fstat -T action text
 229        )
 230'
 231
 232test_expect_success 'cleanup add after submit fail' '
 233        setup_conflict &&
 234        (
 235                cd "$git" &&
 236                echo new file >textnew &&
 237                git add textnew &&
 238                git commit -m "conflict" &&
 239                test_expect_code 1 git p4 submit
 240        ) &&
 241        (
 242                cd "$cli" &&
 243                # make sure it is not there
 244                # and that p4 thinks it is not added
 245                #   P4 returns 0 both for "not there but added" and
 246                #   "not there", so grep.
 247                test_path_is_missing textnew &&
 248                p4 fstat -T action textnew 2>&1 | grep "no such file"
 249        )
 250'
 251
 252test_expect_success 'cleanup delete after submit fail' '
 253        setup_conflict &&
 254        (
 255                cd "$git" &&
 256                git rm text+x &&
 257                git commit -m "conflict" &&
 258                test_expect_code 1 git p4 submit
 259        ) &&
 260        (
 261                cd "$cli" &&
 262                # make sure it is there
 263                test_path_is_file text+x &&
 264                ! p4 fstat -T action text+x
 265        )
 266'
 267
 268test_expect_success 'cleanup copy after submit fail' '
 269        setup_conflict &&
 270        (
 271                cd "$git" &&
 272                cp text text2 &&
 273                git add text2 &&
 274                git commit -m "conflict" &&
 275                git config git-p4.detectCopies true &&
 276                git config git-p4.detectCopiesHarder true &&
 277                # make sure setup is okay
 278                git diff-tree -r -C --find-copies-harder HEAD | grep text2 | grep C100 &&
 279                test_expect_code 1 git p4 submit
 280        ) &&
 281        (
 282                cd "$cli" &&
 283                test_path_is_missing text2 &&
 284                p4 fstat -T action text2 2>&1 | grep "no such file"
 285        )
 286'
 287
 288test_expect_success 'cleanup rename after submit fail' '
 289        setup_conflict &&
 290        (
 291                cd "$git" &&
 292                git mv text text2 &&
 293                git commit -m "conflict" &&
 294                git config git-p4.detectRenames true &&
 295                # make sure setup is okay
 296                git diff-tree -r -M HEAD | grep text2 | grep R100 &&
 297                test_expect_code 1 git p4 submit
 298        ) &&
 299        (
 300                cd "$cli" &&
 301                test_path_is_missing text2 &&
 302                p4 fstat -T action text2 2>&1 | grep "no such file"
 303        )
 304'
 305
 306#
 307# Cleanup after deciding not to submit during editTemplate.  This
 308# involves unwinding more work, because files have been added, deleted
 309# and chmod-ed now.  Same approach as above.
 310#
 311
 312test_expect_success 'cleanup edit after submit cancel' '
 313        test_when_finished cleanup_git &&
 314        git p4 clone --dest="$git" //depot &&
 315        (
 316                cd "$git" &&
 317                echo line >>text &&
 318                git add text &&
 319                git commit -m text &&
 320                echo n | test_expect_code 1 git p4 submit &&
 321                git reset --hard HEAD^
 322        ) &&
 323        (
 324                cd "$cli" &&
 325                ! p4 fstat -T action text &&
 326                test_cmp "$git"/text text
 327        )
 328'
 329
 330test_expect_success 'cleanup add after submit cancel' '
 331        test_when_finished cleanup_git &&
 332        git p4 clone --dest="$git" //depot &&
 333        (
 334                cd "$git" &&
 335                echo line >textnew &&
 336                git add textnew &&
 337                git commit -m textnew &&
 338                echo n | test_expect_code 1 git p4 submit
 339        ) &&
 340        (
 341                cd "$cli" &&
 342                test_path_is_missing textnew &&
 343                p4 fstat -T action textnew 2>&1 | grep "no such file"
 344        )
 345'
 346
 347test_expect_success 'cleanup delete after submit cancel' '
 348        test_when_finished cleanup_git &&
 349        git p4 clone --dest="$git" //depot &&
 350        (
 351                cd "$git" &&
 352                git rm text &&
 353                git commit -m "rm text" &&
 354                echo n | test_expect_code 1 git p4 submit
 355        ) &&
 356        (
 357                cd "$cli" &&
 358                test_path_is_file text &&
 359                ! p4 fstat -T action text
 360        )
 361'
 362
 363test_expect_success 'cleanup copy after submit cancel' '
 364        test_when_finished cleanup_git &&
 365        git p4 clone --dest="$git" //depot &&
 366        (
 367                cd "$git" &&
 368                cp text text2 &&
 369                git add text2 &&
 370                git commit -m text2 &&
 371                git config git-p4.detectCopies true &&
 372                git config git-p4.detectCopiesHarder true &&
 373                git diff-tree -r -C --find-copies-harder HEAD | grep text2 | grep C100 &&
 374                echo n | test_expect_code 1 git p4 submit
 375        ) &&
 376        (
 377                cd "$cli" &&
 378                test_path_is_missing text2 &&
 379                p4 fstat -T action text2 2>&1 | grep "no such file"
 380        )
 381'
 382
 383test_expect_success 'cleanup rename after submit cancel' '
 384        test_when_finished cleanup_git &&
 385        git p4 clone --dest="$git" //depot &&
 386        (
 387                cd "$git" &&
 388                git mv text text2 &&
 389                git commit -m text2 &&
 390                git config git-p4.detectRenames true &&
 391                git diff-tree -r -M HEAD | grep text2 | grep R100 &&
 392                echo n | test_expect_code 1 git p4 submit
 393        ) &&
 394        (
 395                cd "$cli" &&
 396                test_path_is_missing text2 &&
 397                p4 fstat -T action text2 2>&1 | grep "no such file"
 398                test_path_is_file text &&
 399                ! p4 fstat -T action text
 400        )
 401'
 402
 403test_expect_success 'cleanup chmod after submit cancel' '
 404        test_when_finished cleanup_git &&
 405        git p4 clone --dest="$git" //depot &&
 406        (
 407                cd "$git" &&
 408                chmod u+x text &&
 409                chmod u-x text+x &&
 410                git add text text+x &&
 411                git commit -m "chmod texts" &&
 412                echo n | test_expect_code 1 git p4 submit
 413        ) &&
 414        (
 415                cd "$cli" &&
 416                test_path_is_file text &&
 417                ! p4 fstat -T action text &&
 418                stat --format=%A text | egrep ^-r-- &&
 419                test_path_is_file text+x &&
 420                ! p4 fstat -T action text+x &&
 421                stat --format=%A text+x | egrep ^-r-x
 422        )
 423'
 424
 425test_expect_success 'kill p4d' '
 426        kill_p4d
 427'
 428
 429test_done