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