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" &&
26 echo file_to_integrate >file_to_integrate &&
27 p4 add file_to_integrate &&
28 p4 submit -d "add file to integrate"
32 # Create an initial clone, with a commit unrelated to the P4 change
34 test_expect_success
'initial clone' '
35 git p4 clone --dest="$git" //depot/@all &&
36 test_commit -C "$git" "unrelated"
39 test_expect_success
'create shelved changelist' '
43 echo "a change" >>file1 &&
44 echo "new file" >file2 &&
46 p4 delete file_to_delete &&
47 p4 edit file_to_move &&
48 p4 move file_to_move moved_file &&
49 p4 integrate file_to_integrate integrated_file &&
60 //depot/file_to_delete
63 //depot/integrated_file
69 change=$(last_shelved_change) &&
70 git p4 unshelve $change &&
71 git show refs/remotes/p4-unshelved/$change >actual &&
72 grep -q "Further description" actual &&
73 git cherry-pick refs/remotes/p4-unshelved/$change &&
74 test_path_is_file file2 &&
75 test_cmp file1 "$cli"/file1 &&
76 test_cmp file2 "$cli"/file2 &&
77 test_cmp file_to_integrate "$cli"/integrated_file &&
78 test_path_is_missing file_to_delete &&
79 test_path_is_missing file_to_move &&
80 test_path_is_file moved_file
84 test_expect_success
'update shelved changelist and re-unshelve' '
85 test_when_finished cleanup_git &&
88 change=$(last_shelved_change) &&
89 echo "file3" >file3 &&
90 p4 add -c $change file3 &&
91 p4 shelve -i -r <<EOF &&
101 //depot/file_to_delete
107 change=$(last_shelved_change) &&
108 git p4 unshelve $change &&
109 git diff refs/remotes/p4-unshelved/$change.0 refs/remotes/p4-unshelved/$change | grep -q file3
114 description
="Change to be unshelved" &&
125 # This is the tricky case where the shelved changelist base revision doesn't
126 # match git-p4's idea of the base revision
128 # We will attempt to unshelve a change that is based on a change one commit
131 test_expect_success
'create shelved changelist based on p4 change ahead of p4/master' '
132 git p4 clone --dest="$git" //depot/@all &&
137 echo "foo" >>file1 &&
138 p4 submit -d "change:foo" &&
140 echo "bar" >>file1 &&
141 shelve_one_file //depot/file1 &&
142 change=$(last_shelved_change) &&
143 p4 describe -S $change >out.txt &&
144 grep -q "Change to be unshelved" out.txt
148 # Now try to unshelve it.
149 test_expect_success
'try to unshelve the change' '
150 test_when_finished cleanup_git &&
152 change=$(last_shelved_change) &&
154 git p4 unshelve $change >out.txt &&
155 grep -q "unshelved changelist $change" out.txt
159 # Specify the origin. Create 2 unrelated files, and check that
160 # we only get the one in HEAD~, not the one in HEAD.
162 test_expect_success
'unshelve specifying the origin' '
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" &&
172 p4 add file_to_shelve &&
173 shelve_one_file //depot/file_to_shelve
175 test_when_finished cleanup_git &&
176 git p4 clone --dest="$git" //depot/@all &&
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