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" &&
22 p4 add file_to_delete &&
23 p4 submit -d "file to delete"
27 test_expect_success 'initial clone' '
28 git p4 clone --dest="$git" //depot/@all
31 test_expect_success 'create shelved changelist' '
35 echo "a change" >>file1 &&
36 echo "new file" >file2 &&
38 p4 delete file_to_delete &&
49 //depot/file_to_delete
55 change=$(last_shelved_change) &&
56 git p4 unshelve $change &&
57 git show refs/remotes/p4/unshelved/$change | grep -q "Further description" &&
58 git cherry-pick refs/remotes/p4/unshelved/$change &&
59 test_path_is_file file2 &&
60 test_cmp file1 "$cli"/file1 &&
61 test_cmp file2 "$cli"/file2 &&
62 test_path_is_missing file_to_delete
66 test_expect_success 'update shelved changelist and re-unshelve' '
67 test_when_finished cleanup_git &&
70 change=$(last_shelved_change) &&
71 echo "file3" >file3 &&
72 p4 add -c $change file3 &&
73 p4 shelve -i -r <<EOF &&
83 //depot/file_to_delete
89 change=$(last_shelved_change) &&
90 git p4 unshelve $change &&
91 git diff refs/remotes/p4/unshelved/$change.0 refs/remotes/p4/unshelved/$change | grep -q file3
95 # This is the tricky case where the shelved changelist base revision doesn't
96 # match git-p4's idea of the base revision
98 # We will attempt to unshelve a change that is based on a change one commit
101 test_expect_success 'create shelved changelist based on p4 change ahead of p4/master' '
102 git p4 clone --dest="$git" //depot/@all &&
107 echo "foo" >>file1 &&
108 p4 submit -d "change:foo" &&
110 echo "bar" >>file1 &&
111 p4 shelve -i <<EOF &&
114 Change to be unshelved
118 change=$(last_shelved_change) &&
119 p4 describe -S $change | grep -q "Change to be unshelved"
123 # Now try to unshelve it. git-p4 should refuse to do so.
124 test_expect_success 'try to unshelve the change' '
125 test_when_finished cleanup_git &&
127 change=$(last_shelved_change) &&
129 test_must_fail git p4 unshelve $change 2>out.txt &&
130 grep -q "cannot unshelve" out.txt
134 test_expect_success 'kill p4d' '