Merge branch 'bc/t3430-fixup'
[git.git] / t / t9832-unshelve.sh
blob48ec7679b8d9632259c3b319d11ad8eb1acd5ceb
1 #!/bin/sh
3 last_shelved_change () {
4 p4 changes -s shelved -m1 | cut -d " " -f 2
7 test_description='git p4 unshelve'
9 . ./lib-git-p4.sh
11 test_expect_success 'start p4d' '
12 start_p4d
15 test_expect_success 'init depot' '
17 cd "$cli" &&
18 echo file1 >file1 &&
19 p4 add file1 &&
20 p4 submit -d "change 1" &&
21 : >file_to_delete &&
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' '
33 cd "$cli" &&
34 p4 edit file1 &&
35 echo "a change" >>file1 &&
36 echo "new file" >file2 &&
37 p4 add file2 &&
38 p4 delete file_to_delete &&
39 p4 opened &&
40 p4 shelve -i <<EOF
41 Change: new
42 Description:
43 Test commit
45 Further description
46 Files:
47 //depot/file1
48 //depot/file2
49 //depot/file_to_delete
50 EOF
52 ) &&
54 cd "$git" &&
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 &&
69 cd "$cli" &&
70 change=$(last_shelved_change) &&
71 echo "file3" >file3 &&
72 p4 add -c $change file3 &&
73 p4 shelve -i -r <<EOF &&
74 Change: $change
75 Description:
76 Test commit
78 Further description
79 Files:
80 //depot/file1
81 //depot/file2
82 //depot/file3
83 //depot/file_to_delete
84 EOF
85 p4 describe $change
86 ) &&
88 cd "$git" &&
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
99 # ahead of p4/master
101 test_expect_success 'create shelved changelist based on p4 change ahead of p4/master' '
102 git p4 clone --dest="$git" //depot/@all &&
104 cd "$cli" &&
105 p4 revert ... &&
106 p4 edit file1 &&
107 echo "foo" >>file1 &&
108 p4 submit -d "change:foo" &&
109 p4 edit file1 &&
110 echo "bar" >>file1 &&
111 p4 shelve -i <<EOF &&
112 Change: new
113 Description:
114 Change to be unshelved
115 Files:
116 //depot/file1
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) &&
128 cd "$git" &&
129 test_must_fail git p4 unshelve $change 2>out.txt &&
130 grep -q "cannot unshelve" out.txt
134 test_expect_success 'kill p4d' '
135 kill_p4d
138 test_done