]>
Commit | Line | Data |
---|---|---|
123f6317 LD |
1 | #!/bin/sh |
2 | ||
3 | last_shelved_change () { | |
4 | p4 changes -s shelved -m1 | cut -d " " -f 2 | |
5 | } | |
6 | ||
7 | test_description='git p4 unshelve' | |
8 | ||
9 | . ./lib-git-p4.sh | |
10 | ||
11 | test_expect_success 'start p4d' ' | |
12 | start_p4d | |
13 | ' | |
14 | ||
15 | test_expect_success 'init depot' ' | |
16 | ( | |
17 | cd "$cli" && | |
18 | echo file1 >file1 && | |
19 | p4 add file1 && | |
20 | p4 submit -d "change 1" && | |
21 | : >file_to_delete && | |
89143ac2 | 22 | : >file_to_move && |
123f6317 | 23 | p4 add file_to_delete && |
89143ac2 | 24 | p4 add file_to_move && |
0108f47e SW |
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" | |
123f6317 LD |
29 | ) |
30 | ' | |
31 | ||
677fa8d1 LD |
32 | # Create an initial clone, with a commit unrelated to the P4 change |
33 | # on HEAD | |
123f6317 | 34 | test_expect_success 'initial clone' ' |
677fa8d1 LD |
35 | git p4 clone --dest="$git" //depot/@all && |
36 | test_commit -C "$git" "unrelated" | |
123f6317 LD |
37 | ' |
38 | ||
39 | test_expect_success 'create shelved changelist' ' | |
40 | ( | |
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 && | |
89143ac2 LD |
47 | p4 edit file_to_move && |
48 | p4 move file_to_move moved_file && | |
0108f47e | 49 | p4 integrate file_to_integrate integrated_file && |
123f6317 LD |
50 | p4 opened && |
51 | p4 shelve -i <<EOF | |
52 | Change: new | |
53 | Description: | |
54 | Test commit | |
55 | ||
56 | Further description | |
57 | Files: | |
58 | //depot/file1 | |
59 | //depot/file2 | |
60 | //depot/file_to_delete | |
89143ac2 LD |
61 | //depot/file_to_move |
62 | //depot/moved_file | |
0108f47e | 63 | //depot/integrated_file |
123f6317 LD |
64 | EOF |
65 | ||
66 | ) && | |
67 | ( | |
68 | cd "$git" && | |
69 | change=$(last_shelved_change) && | |
70 | git p4 unshelve $change && | |
08813127 LD |
71 | git show refs/remotes/p4-unshelved/$change | grep -q "Further description" && |
72 | git cherry-pick refs/remotes/p4-unshelved/$change && | |
123f6317 LD |
73 | test_path_is_file file2 && |
74 | test_cmp file1 "$cli"/file1 && | |
75 | test_cmp file2 "$cli"/file2 && | |
0108f47e | 76 | test_cmp file_to_integrate "$cli"/integrated_file && |
89143ac2 LD |
77 | test_path_is_missing file_to_delete && |
78 | test_path_is_missing file_to_move && | |
79 | test_path_is_file moved_file | |
123f6317 LD |
80 | ) |
81 | ' | |
82 | ||
677fa8d1 | 83 | test_expect_failure 'update shelved changelist and re-unshelve' ' |
123f6317 LD |
84 | test_when_finished cleanup_git && |
85 | ( | |
86 | cd "$cli" && | |
87 | change=$(last_shelved_change) && | |
88 | echo "file3" >file3 && | |
89 | p4 add -c $change file3 && | |
90 | p4 shelve -i -r <<EOF && | |
91 | Change: $change | |
92 | Description: | |
93 | Test commit | |
94 | ||
95 | Further description | |
96 | Files: | |
97 | //depot/file1 | |
98 | //depot/file2 | |
99 | //depot/file3 | |
100 | //depot/file_to_delete | |
101 | EOF | |
102 | p4 describe $change | |
103 | ) && | |
104 | ( | |
105 | cd "$git" && | |
106 | change=$(last_shelved_change) && | |
107 | git p4 unshelve $change && | |
08813127 | 108 | git diff refs/remotes/p4-unshelved/$change.0 refs/remotes/p4-unshelved/$change | grep -q file3 |
123f6317 LD |
109 | ) |
110 | ' | |
111 | ||
89143ac2 LD |
112 | shelve_one_file () { |
113 | description="Change to be unshelved" && | |
114 | file="$1" && | |
115 | p4 shelve -i <<EOF | |
116 | Change: new | |
117 | Description: | |
118 | $description | |
119 | Files: | |
120 | $file | |
121 | EOF | |
122 | } | |
123 | ||
123f6317 LD |
124 | # This is the tricky case where the shelved changelist base revision doesn't |
125 | # match git-p4's idea of the base revision | |
126 | # | |
127 | # We will attempt to unshelve a change that is based on a change one commit | |
128 | # ahead of p4/master | |
129 | ||
130 | test_expect_success 'create shelved changelist based on p4 change ahead of p4/master' ' | |
131 | git p4 clone --dest="$git" //depot/@all && | |
132 | ( | |
133 | cd "$cli" && | |
134 | p4 revert ... && | |
135 | p4 edit file1 && | |
136 | echo "foo" >>file1 && | |
137 | p4 submit -d "change:foo" && | |
138 | p4 edit file1 && | |
139 | echo "bar" >>file1 && | |
89143ac2 | 140 | shelve_one_file //depot/file1 && |
123f6317 | 141 | change=$(last_shelved_change) && |
89143ac2 LD |
142 | p4 describe -S $change >out.txt && |
143 | grep -q "Change to be unshelved" out.txt | |
123f6317 LD |
144 | ) |
145 | ' | |
146 | ||
89143ac2 | 147 | # Now try to unshelve it. |
123f6317 LD |
148 | test_expect_success 'try to unshelve the change' ' |
149 | test_when_finished cleanup_git && | |
150 | ( | |
151 | change=$(last_shelved_change) && | |
152 | cd "$git" && | |
89143ac2 LD |
153 | git p4 unshelve $change >out.txt && |
154 | grep -q "unshelved changelist $change" out.txt | |
123f6317 LD |
155 | ) |
156 | ' | |
157 | ||
89143ac2 LD |
158 | # Specify the origin. Create 2 unrelated files, and check that |
159 | # we only get the one in HEAD~, not the one in HEAD. | |
160 | ||
161 | test_expect_success 'unshelve specifying the origin' ' | |
162 | ( | |
163 | cd "$cli" && | |
164 | : >unrelated_file0 && | |
165 | p4 add unrelated_file0 && | |
166 | p4 submit -d "unrelated" && | |
167 | : >unrelated_file1 && | |
168 | p4 add unrelated_file1 && | |
169 | p4 submit -d "unrelated" && | |
170 | : >file_to_shelve && | |
171 | p4 add file_to_shelve && | |
172 | shelve_one_file //depot/file_to_shelve | |
173 | ) && | |
174 | test_when_finished cleanup_git && | |
175 | git p4 clone --dest="$git" //depot/@all && | |
176 | ( | |
177 | cd "$git" && | |
178 | change=$(last_shelved_change) && | |
179 | git p4 unshelve --origin HEAD~ $change && | |
180 | git checkout refs/remotes/p4-unshelved/$change && | |
181 | test_path_is_file unrelated_file0 && | |
182 | test_path_is_missing unrelated_file1 && | |
183 | test_path_is_file file_to_shelve | |
184 | ) | |
185 | ' | |
123f6317 LD |
186 | |
187 | test_done |