t / t9832-unshelve.shon commit t6500(mingw): use the Windows PID of the shell (c871fbe)
   1#!/bin/sh
   2
   3last_shelved_change () {
   4        p4 changes -s shelved -m1 | cut -d " " -f 2
   5}
   6
   7test_description='git p4 unshelve'
   8
   9. ./lib-git-p4.sh
  10
  11test_expect_success 'start p4d' '
  12        start_p4d
  13'
  14
  15test_expect_success 'init depot' '
  16        (
  17                cd "$cli" &&
  18                echo file1 >file1 &&
  19                p4 add file1 &&
  20                p4 submit -d "change 1" &&
  21                : >file_to_delete &&
  22                : >file_to_move &&
  23                p4 add file_to_delete &&
  24                p4 add file_to_move &&
  25                p4 submit -d "add files to delete"
  26        )
  27'
  28
  29test_expect_success 'initial clone' '
  30        git p4 clone --dest="$git" //depot/@all
  31'
  32
  33test_expect_success 'create shelved changelist' '
  34        (
  35                cd "$cli" &&
  36                p4 edit file1 &&
  37                echo "a change" >>file1 &&
  38                echo "new file" >file2 &&
  39                p4 add file2 &&
  40                p4 delete file_to_delete &&
  41                p4 edit file_to_move &&
  42                p4 move file_to_move moved_file &&
  43                p4 opened &&
  44                p4 shelve -i <<EOF
  45Change: new
  46Description:
  47        Test commit
  48
  49        Further description
  50Files:
  51        //depot/file1
  52        //depot/file2
  53        //depot/file_to_delete
  54        //depot/file_to_move
  55        //depot/moved_file
  56EOF
  57
  58        ) &&
  59        (
  60                cd "$git" &&
  61                change=$(last_shelved_change) &&
  62                git p4 unshelve $change &&
  63                git show refs/remotes/p4-unshelved/$change | grep -q "Further description" &&
  64                git cherry-pick refs/remotes/p4-unshelved/$change &&
  65                test_path_is_file file2 &&
  66                test_cmp file1 "$cli"/file1 &&
  67                test_cmp file2 "$cli"/file2 &&
  68                test_path_is_missing file_to_delete &&
  69                test_path_is_missing file_to_move &&
  70                test_path_is_file moved_file
  71        )
  72'
  73
  74test_expect_success 'update shelved changelist and re-unshelve' '
  75        test_when_finished cleanup_git &&
  76        (
  77                cd "$cli" &&
  78                change=$(last_shelved_change) &&
  79                echo "file3" >file3 &&
  80                p4 add -c $change file3 &&
  81                p4 shelve -i -r <<EOF &&
  82Change: $change
  83Description:
  84        Test commit
  85
  86        Further description
  87Files:
  88        //depot/file1
  89        //depot/file2
  90        //depot/file3
  91        //depot/file_to_delete
  92EOF
  93                p4 describe $change
  94        ) &&
  95        (
  96                cd "$git" &&
  97                change=$(last_shelved_change) &&
  98                git p4 unshelve $change &&
  99                git diff refs/remotes/p4-unshelved/$change.0 refs/remotes/p4-unshelved/$change | grep -q file3
 100        )
 101'
 102
 103shelve_one_file () {
 104        description="Change to be unshelved" &&
 105        file="$1" &&
 106        p4 shelve -i <<EOF
 107Change: new
 108Description:
 109        $description
 110Files:
 111        $file
 112EOF
 113}
 114
 115# This is the tricky case where the shelved changelist base revision doesn't
 116# match git-p4's idea of the base revision
 117#
 118# We will attempt to unshelve a change that is based on a change one commit
 119# ahead of p4/master
 120
 121test_expect_success 'create shelved changelist based on p4 change ahead of p4/master' '
 122        git p4 clone --dest="$git" //depot/@all &&
 123        (
 124                cd "$cli" &&
 125                p4 revert ... &&
 126                p4 edit file1 &&
 127                echo "foo" >>file1 &&
 128                p4 submit -d "change:foo" &&
 129                p4 edit file1 &&
 130                echo "bar" >>file1 &&
 131                shelve_one_file //depot/file1 &&
 132                change=$(last_shelved_change) &&
 133                p4 describe -S $change >out.txt &&
 134                grep -q "Change to be unshelved" out.txt
 135        )
 136'
 137
 138# Now try to unshelve it.
 139test_expect_success 'try to unshelve the change' '
 140        test_when_finished cleanup_git &&
 141        (
 142                change=$(last_shelved_change) &&
 143                cd "$git" &&
 144                git p4 unshelve $change >out.txt &&
 145                grep -q "unshelved changelist $change" out.txt
 146        )
 147'
 148
 149# Specify the origin. Create 2 unrelated files, and check that
 150# we only get the one in HEAD~, not the one in HEAD.
 151
 152test_expect_success 'unshelve specifying the origin' '
 153        (
 154                cd "$cli" &&
 155                : >unrelated_file0 &&
 156                p4 add unrelated_file0 &&
 157                p4 submit -d "unrelated" &&
 158                : >unrelated_file1 &&
 159                p4 add unrelated_file1 &&
 160                p4 submit -d "unrelated" &&
 161                : >file_to_shelve &&
 162                p4 add file_to_shelve &&
 163                shelve_one_file //depot/file_to_shelve
 164        ) &&
 165        test_when_finished cleanup_git &&
 166        git p4 clone --dest="$git" //depot/@all &&
 167        (
 168                cd "$git" &&
 169                change=$(last_shelved_change) &&
 170                git p4 unshelve --origin HEAD~ $change &&
 171                git checkout refs/remotes/p4-unshelved/$change &&
 172                test_path_is_file unrelated_file0 &&
 173                test_path_is_missing unrelated_file1 &&
 174                test_path_is_file file_to_shelve
 175        )
 176'
 177test_expect_success 'kill p4d' '
 178        kill_p4d
 179'
 180
 181test_done