clone_submodule: avoid using `access()` on directories
[git.git] / t / t9832-unshelve.sh
blob6b3cb0414aa08cb62817ba9f0710e6db4d282787
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 # Create an initial clone, with a commit unrelated to the P4 change
33 # on HEAD
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' '
41 cd "$cli" &&
42 p4 edit file1 &&
43 echo "a change" >>file1 &&
44 echo "new file" >file2 &&
45 p4 add 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 &&
50 p4 opened &&
51 p4 shelve -i <<EOF
52 Change: new
53 Description:
54 Test commit
56 Further description
57 Files:
58 //depot/file1
59 //depot/file2
60 //depot/file_to_delete
61 //depot/file_to_move
62 //depot/moved_file
63 //depot/integrated_file
64 EOF
66 ) &&
68 cd "$git" &&
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 &&
87 cd "$cli" &&
88 change=$(last_shelved_change) &&
89 echo "file3" >file3 &&
90 p4 add -c $change file3 &&
91 p4 shelve -i -r <<EOF &&
92 Change: $change
93 Description:
94 Test commit
96 Further description
97 Files:
98 //depot/file1
99 //depot/file2
100 //depot/file3
101 //depot/file_to_delete
103 p4 describe $change
104 ) &&
106 cd "$git" &&
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
113 shelve_one_file () {
114 description="Change to be unshelved" &&
115 file="$1" &&
116 p4 shelve -i <<EOF
117 Change: new
118 Description:
119 $description
120 Files:
121 $file
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
129 # ahead of p4/master
131 test_expect_success 'create shelved changelist based on p4 change ahead of p4/master' '
132 git p4 clone --dest="$git" //depot/@all &&
134 cd "$cli" &&
135 p4 revert ... &&
136 p4 edit file1 &&
137 echo "foo" >>file1 &&
138 p4 submit -d "change:foo" &&
139 p4 edit file1 &&
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) &&
153 cd "$git" &&
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' '
164 cd "$cli" &&
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" &&
171 : >file_to_shelve &&
172 p4 add file_to_shelve &&
173 shelve_one_file //depot/file_to_shelve
174 ) &&
175 test_when_finished cleanup_git &&
176 git p4 clone --dest="$git" //depot/@all &&
178 cd "$git" &&
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
188 test_done