The third batch
[git/raj.git] / t / t9832-unshelve.sh
blobe9276c48f4a2e795899a03681a737c70635ab39c
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 : >file_to_move &&
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 test_expect_success 'initial clone' '
33 git p4 clone --dest="$git" //depot/@all
36 test_expect_success 'create shelved changelist' '
38 cd "$cli" &&
39 p4 edit file1 &&
40 echo "a change" >>file1 &&
41 echo "new file" >file2 &&
42 p4 add file2 &&
43 p4 delete file_to_delete &&
44 p4 edit file_to_move &&
45 p4 move file_to_move moved_file &&
46 p4 integrate file_to_integrate integrated_file &&
47 p4 opened &&
48 p4 shelve -i <<EOF
49 Change: new
50 Description:
51 Test commit
53 Further description
54 Files:
55 //depot/file1
56 //depot/file2
57 //depot/file_to_delete
58 //depot/file_to_move
59 //depot/moved_file
60 //depot/integrated_file
61 EOF
63 ) &&
65 cd "$git" &&
66 change=$(last_shelved_change) &&
67 git p4 unshelve $change &&
68 git show refs/remotes/p4-unshelved/$change | grep -q "Further description" &&
69 git cherry-pick refs/remotes/p4-unshelved/$change &&
70 test_path_is_file file2 &&
71 test_cmp file1 "$cli"/file1 &&
72 test_cmp file2 "$cli"/file2 &&
73 test_cmp file_to_integrate "$cli"/integrated_file &&
74 test_path_is_missing file_to_delete &&
75 test_path_is_missing file_to_move &&
76 test_path_is_file moved_file
80 test_expect_success 'update shelved changelist and re-unshelve' '
81 test_when_finished cleanup_git &&
83 cd "$cli" &&
84 change=$(last_shelved_change) &&
85 echo "file3" >file3 &&
86 p4 add -c $change file3 &&
87 p4 shelve -i -r <<EOF &&
88 Change: $change
89 Description:
90 Test commit
92 Further description
93 Files:
94 //depot/file1
95 //depot/file2
96 //depot/file3
97 //depot/file_to_delete
98 EOF
99 p4 describe $change
100 ) &&
102 cd "$git" &&
103 change=$(last_shelved_change) &&
104 git p4 unshelve $change &&
105 git diff refs/remotes/p4-unshelved/$change.0 refs/remotes/p4-unshelved/$change | grep -q file3
109 shelve_one_file () {
110 description="Change to be unshelved" &&
111 file="$1" &&
112 p4 shelve -i <<EOF
113 Change: new
114 Description:
115 $description
116 Files:
117 $file
121 # This is the tricky case where the shelved changelist base revision doesn't
122 # match git-p4's idea of the base revision
124 # We will attempt to unshelve a change that is based on a change one commit
125 # ahead of p4/master
127 test_expect_success 'create shelved changelist based on p4 change ahead of p4/master' '
128 git p4 clone --dest="$git" //depot/@all &&
130 cd "$cli" &&
131 p4 revert ... &&
132 p4 edit file1 &&
133 echo "foo" >>file1 &&
134 p4 submit -d "change:foo" &&
135 p4 edit file1 &&
136 echo "bar" >>file1 &&
137 shelve_one_file //depot/file1 &&
138 change=$(last_shelved_change) &&
139 p4 describe -S $change >out.txt &&
140 grep -q "Change to be unshelved" out.txt
144 # Now try to unshelve it.
145 test_expect_success 'try to unshelve the change' '
146 test_when_finished cleanup_git &&
148 change=$(last_shelved_change) &&
149 cd "$git" &&
150 git p4 unshelve $change >out.txt &&
151 grep -q "unshelved changelist $change" out.txt
155 # Specify the origin. Create 2 unrelated files, and check that
156 # we only get the one in HEAD~, not the one in HEAD.
158 test_expect_success 'unshelve specifying the origin' '
160 cd "$cli" &&
161 : >unrelated_file0 &&
162 p4 add unrelated_file0 &&
163 p4 submit -d "unrelated" &&
164 : >unrelated_file1 &&
165 p4 add unrelated_file1 &&
166 p4 submit -d "unrelated" &&
167 : >file_to_shelve &&
168 p4 add file_to_shelve &&
169 shelve_one_file //depot/file_to_shelve
170 ) &&
171 test_when_finished cleanup_git &&
172 git p4 clone --dest="$git" //depot/@all &&
174 cd "$git" &&
175 change=$(last_shelved_change) &&
176 git p4 unshelve --origin HEAD~ $change &&
177 git checkout refs/remotes/p4-unshelved/$change &&
178 test_path_is_file unrelated_file0 &&
179 test_path_is_missing unrelated_file1 &&
180 test_path_is_file file_to_shelve
184 test_done