Merge branch 'ja/doc-synopsis-markup'
[git/gitster.git] / t / t9832-unshelve.sh
bloba2667754086a5c64addc6c079fd017d313809883
1 #!/bin/sh
3 last_shelved_change () {
4 p4 changes -s shelved -m1 | cut -d " " -f 2
7 test_description='git p4 unshelve'
9 TEST_PASSES_SANITIZE_LEAK=true
10 . ./lib-git-p4.sh
12 test_expect_success 'start p4d' '
13 start_p4d
16 test_expect_success 'init depot' '
18 cd "$cli" &&
19 echo file1 >file1 &&
20 p4 add file1 &&
21 p4 submit -d "change 1" &&
22 : >file_to_delete &&
23 : >file_to_move &&
24 p4 add file_to_delete &&
25 p4 add file_to_move &&
26 p4 submit -d "add files to delete" &&
27 echo file_to_integrate >file_to_integrate &&
28 p4 add file_to_integrate &&
29 p4 submit -d "add file to integrate"
33 # Create an initial clone, with a commit unrelated to the P4 change
34 # on HEAD
35 test_expect_success 'initial clone' '
36 git p4 clone --dest="$git" //depot/@all &&
37 test_commit -C "$git" "unrelated"
40 test_expect_success 'create shelved changelist' '
42 cd "$cli" &&
43 p4 edit file1 &&
44 echo "a change" >>file1 &&
45 echo "new file" >file2 &&
46 p4 add file2 &&
47 p4 delete file_to_delete &&
48 p4 edit file_to_move &&
49 p4 move file_to_move moved_file &&
50 p4 integrate file_to_integrate integrated_file &&
51 p4 opened &&
52 p4 shelve -i <<EOF
53 Change: new
54 Description:
55 Test commit
57 Further description
58 Files:
59 //depot/file1
60 //depot/file2
61 //depot/file_to_delete
62 //depot/file_to_move
63 //depot/moved_file
64 //depot/integrated_file
65 EOF
67 ) &&
69 cd "$git" &&
70 change=$(last_shelved_change) &&
71 git p4 unshelve $change &&
72 git show refs/remotes/p4-unshelved/$change >actual &&
73 grep -q "Further description" actual &&
74 git cherry-pick refs/remotes/p4-unshelved/$change &&
75 test_path_is_file file2 &&
76 test_cmp file1 "$cli"/file1 &&
77 test_cmp file2 "$cli"/file2 &&
78 test_cmp file_to_integrate "$cli"/integrated_file &&
79 test_path_is_missing file_to_delete &&
80 test_path_is_missing file_to_move &&
81 test_path_is_file moved_file
85 test_expect_success 'update shelved changelist and re-unshelve' '
86 test_when_finished cleanup_git &&
88 cd "$cli" &&
89 change=$(last_shelved_change) &&
90 echo "file3" >file3 &&
91 p4 add -c $change file3 &&
92 p4 shelve -i -r <<EOF &&
93 Change: $change
94 Description:
95 Test commit
97 Further description
98 Files:
99 //depot/file1
100 //depot/file2
101 //depot/file3
102 //depot/file_to_delete
104 p4 describe $change
105 ) &&
107 cd "$git" &&
108 change=$(last_shelved_change) &&
109 git p4 unshelve $change &&
110 git diff refs/remotes/p4-unshelved/$change.0 refs/remotes/p4-unshelved/$change | grep -q file3
114 shelve_one_file () {
115 description="Change to be unshelved" &&
116 file="$1" &&
117 p4 shelve -i <<EOF
118 Change: new
119 Description:
120 $description
121 Files:
122 $file
126 # This is the tricky case where the shelved changelist base revision doesn't
127 # match git-p4's idea of the base revision
129 # We will attempt to unshelve a change that is based on a change one commit
130 # ahead of p4/master
132 test_expect_success 'create shelved changelist based on p4 change ahead of p4/master' '
133 git p4 clone --dest="$git" //depot/@all &&
135 cd "$cli" &&
136 p4 revert ... &&
137 p4 edit file1 &&
138 echo "foo" >>file1 &&
139 p4 submit -d "change:foo" &&
140 p4 edit file1 &&
141 echo "bar" >>file1 &&
142 shelve_one_file //depot/file1 &&
143 change=$(last_shelved_change) &&
144 p4 describe -S $change >out.txt &&
145 grep -q "Change to be unshelved" out.txt
149 # Now try to unshelve it.
150 test_expect_success 'try to unshelve the change' '
151 test_when_finished cleanup_git &&
153 change=$(last_shelved_change) &&
154 cd "$git" &&
155 git p4 unshelve $change >out.txt &&
156 grep -q "unshelved changelist $change" out.txt
160 # Specify the origin. Create 2 unrelated files, and check that
161 # we only get the one in HEAD~, not the one in HEAD.
163 test_expect_success 'unshelve specifying the origin' '
165 cd "$cli" &&
166 : >unrelated_file0 &&
167 p4 add unrelated_file0 &&
168 p4 submit -d "unrelated" &&
169 : >unrelated_file1 &&
170 p4 add unrelated_file1 &&
171 p4 submit -d "unrelated" &&
172 : >file_to_shelve &&
173 p4 add file_to_shelve &&
174 shelve_one_file //depot/file_to_shelve
175 ) &&
176 test_when_finished cleanup_git &&
177 git p4 clone --dest="$git" //depot/@all &&
179 cd "$git" &&
180 change=$(last_shelved_change) &&
181 git p4 unshelve --origin HEAD~ $change &&
182 git checkout refs/remotes/p4-unshelved/$change &&
183 test_path_is_file unrelated_file0 &&
184 test_path_is_missing unrelated_file1 &&
185 test_path_is_file file_to_shelve
189 test_done