3 last_shelved_change
() {
4 p4 changes
-s shelved
-m1 | cut
-d " " -f 2
7 test_description
='git p4 unshelve'
11 test_expect_success
'start p4d' '
15 test_expect_success
'init depot' '
20 p4 submit -d "change 1" &&
23 p4 add file_to_delete &&
24 p4 add file_to_move &&
25 p4 submit -d "add files to delete"
29 test_expect_success
'initial clone' '
30 git p4 clone --dest="$git" //depot/@all
33 test_expect_success
'create shelved changelist' '
37 echo "a change" >>file1 &&
38 echo "new file" >file2 &&
40 p4 delete file_to_delete &&
41 p4 edit file_to_move &&
42 p4 move file_to_move moved_file &&
53 //depot/file_to_delete
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
74 test_expect_success
'update shelved changelist and re-unshelve' '
75 test_when_finished cleanup_git &&
78 change=$(last_shelved_change) &&
79 echo "file3" >file3 &&
80 p4 add -c $change file3 &&
81 p4 shelve -i -r <<EOF &&
91 //depot/file_to_delete
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
104 description
="Change to be unshelved" &&
115 # This is the tricky case where the shelved changelist base revision doesn't
116 # match git-p4's idea of the base revision
118 # We will attempt to unshelve a change that is based on a change one commit
121 test_expect_success
'create shelved changelist based on p4 change ahead of p4/master' '
122 git p4 clone --dest="$git" //depot/@all &&
127 echo "foo" >>file1 &&
128 p4 submit -d "change:foo" &&
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
138 # Now try to unshelve it.
139 test_expect_success
'try to unshelve the change' '
140 test_when_finished cleanup_git &&
142 change=$(last_shelved_change) &&
144 git p4 unshelve $change >out.txt &&
145 grep -q "unshelved changelist $change" out.txt
149 # Specify the origin. Create 2 unrelated files, and check that
150 # we only get the one in HEAD~, not the one in HEAD.
152 test_expect_success
'unshelve specifying the origin' '
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" &&
162 p4 add file_to_shelve &&
163 shelve_one_file //depot/file_to_shelve
165 test_when_finished cleanup_git &&
166 git p4 clone --dest="$git" //depot/@all &&
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
177 test_expect_success
'kill p4d' '