t3401: add another directory rename testcase for rebase and am
[git] / t / t9806-git-p4-options.sh
1 #!/bin/sh
2
3 test_description='git p4 options'
4
5 . ./lib-git-p4.sh
6
7 test_expect_success 'start p4d' '
8         start_p4d
9 '
10
11 test_expect_success 'init depot' '
12         (
13                 cd "$cli" &&
14                 echo file1 >file1 &&
15                 p4 add file1 &&
16                 p4 submit -d "change 1" &&
17                 echo file2 >file2 &&
18                 p4 add file2 &&
19                 p4 submit -d "change 2" &&
20                 echo file3 >file3 &&
21                 p4 add file3 &&
22                 p4 submit -d "change 3"
23         )
24 '
25
26 test_expect_success 'clone no --git-dir' '
27         test_must_fail git p4 clone --git-dir=xx //depot
28 '
29
30 test_expect_success 'clone --branch should checkout master' '
31         git p4 clone --branch=refs/remotes/p4/sb --dest="$git" //depot &&
32         test_when_finished cleanup_git &&
33         (
34                 cd "$git" &&
35                 git rev-parse refs/remotes/p4/sb >sb &&
36                 git rev-parse refs/heads/master >master &&
37                 test_cmp sb master &&
38                 git rev-parse HEAD >head &&
39                 test_cmp sb head
40         )
41 '
42
43 test_expect_success 'sync when no master branch prints a nice error' '
44         test_when_finished cleanup_git &&
45         git p4 clone --branch=refs/remotes/p4/sb --dest="$git" //depot@2 &&
46         (
47                 cd "$git" &&
48                 test_must_fail git p4 sync 2>err &&
49                 grep "Error: no branch refs/remotes/p4/master" err
50         )
51 '
52
53 test_expect_success 'sync --branch builds the full ref name correctly' '
54         test_when_finished cleanup_git &&
55         (
56                 cd "$git" &&
57                 git init &&
58
59                 git p4 sync --branch=b1 //depot &&
60                 git rev-parse --verify refs/remotes/p4/b1 &&
61                 git p4 sync --branch=p4/b2 //depot &&
62                 git rev-parse --verify refs/remotes/p4/b2 &&
63
64                 git p4 sync --import-local --branch=h1 //depot &&
65                 git rev-parse --verify refs/heads/p4/h1 &&
66                 git p4 sync --import-local --branch=p4/h2 //depot &&
67                 git rev-parse --verify refs/heads/p4/h2 &&
68
69                 git p4 sync --branch=refs/stuff //depot &&
70                 git rev-parse --verify refs/stuff
71         )
72 '
73
74 # engages --detect-branches code, which will do filename filtering so
75 # no sync to either b1 or b2
76 test_expect_success 'sync when two branches but no master should noop' '
77         test_when_finished cleanup_git &&
78         (
79                 cd "$git" &&
80                 git init &&
81                 git p4 sync --branch=refs/remotes/p4/b1 //depot@2 &&
82                 git p4 sync --branch=refs/remotes/p4/b2 //depot@2 &&
83                 git p4 sync &&
84                 git show -s --format=%s refs/remotes/p4/b1 >show &&
85                 grep "Initial import" show &&
86                 git show -s --format=%s refs/remotes/p4/b2 >show &&
87                 grep "Initial import" show
88         )
89 '
90
91 test_expect_success 'sync --branch updates specific branch, no detection' '
92         test_when_finished cleanup_git &&
93         (
94                 cd "$git" &&
95                 git init &&
96                 git p4 sync --branch=b1 //depot@2 &&
97                 git p4 sync --branch=b2 //depot@2 &&
98                 git p4 sync --branch=b2 &&
99                 git show -s --format=%s refs/remotes/p4/b1 >show &&
100                 grep "Initial import" show &&
101                 git show -s --format=%s refs/remotes/p4/b2 >show &&
102                 grep "change 3" show
103         )
104 '
105
106 # allows using the refname "p4" as a short name for p4/master
107 test_expect_success 'clone creates HEAD symbolic reference' '
108         git p4 clone --dest="$git" //depot &&
109         test_when_finished cleanup_git &&
110         (
111                 cd "$git" &&
112                 git rev-parse --verify refs/remotes/p4/master >master &&
113                 git rev-parse --verify p4 >p4 &&
114                 test_cmp master p4
115         )
116 '
117
118 test_expect_success 'clone --branch creates HEAD symbolic reference' '
119         git p4 clone --branch=refs/remotes/p4/sb --dest="$git" //depot &&
120         test_when_finished cleanup_git &&
121         (
122                 cd "$git" &&
123                 git rev-parse --verify refs/remotes/p4/sb >sb &&
124                 git rev-parse --verify p4 >p4 &&
125                 test_cmp sb p4
126         )
127 '
128
129 test_expect_success 'clone --changesfile' '
130         test_when_finished "rm cf" &&
131         printf "1\n3\n" >cf &&
132         git p4 clone --changesfile="$TRASH_DIRECTORY/cf" --dest="$git" //depot &&
133         test_when_finished cleanup_git &&
134         (
135                 cd "$git" &&
136                 git log --oneline p4/master >lines &&
137                 test_line_count = 2 lines
138                 test_path_is_file file1 &&
139                 test_path_is_missing file2 &&
140                 test_path_is_file file3
141         )
142 '
143
144 test_expect_success 'clone --changesfile, @all' '
145         test_when_finished "rm cf" &&
146         printf "1\n3\n" >cf &&
147         test_must_fail git p4 clone --changesfile="$TRASH_DIRECTORY/cf" --dest="$git" //depot@all
148 '
149
150 # imports both master and p4/master in refs/heads
151 # requires --import-local on sync to find p4 refs/heads
152 # does not update master on sync, just p4/master
153 test_expect_success 'clone/sync --import-local' '
154         git p4 clone --import-local --dest="$git" //depot@1,2 &&
155         test_when_finished cleanup_git &&
156         (
157                 cd "$git" &&
158                 git log --oneline refs/heads/master >lines &&
159                 test_line_count = 2 lines &&
160                 git log --oneline refs/heads/p4/master >lines &&
161                 test_line_count = 2 lines &&
162                 test_must_fail git p4 sync &&
163
164                 git p4 sync --import-local &&
165                 git log --oneline refs/heads/master >lines &&
166                 test_line_count = 2 lines &&
167                 git log --oneline refs/heads/p4/master >lines &&
168                 test_line_count = 3 lines
169         )
170 '
171
172 test_expect_success 'clone --max-changes' '
173         git p4 clone --dest="$git" --max-changes 2 //depot@all &&
174         test_when_finished cleanup_git &&
175         (
176                 cd "$git" &&
177                 git log --oneline refs/heads/master >lines &&
178                 test_line_count = 2 lines
179         )
180 '
181
182 test_expect_success 'clone --keep-path' '
183         (
184                 cd "$cli" &&
185                 mkdir -p sub/dir &&
186                 echo f4 >sub/dir/f4 &&
187                 p4 add sub/dir/f4 &&
188                 p4 submit -d "change 4"
189         ) &&
190         git p4 clone --dest="$git" --keep-path //depot/sub/dir@all &&
191         test_when_finished cleanup_git &&
192         (
193                 cd "$git" &&
194                 test_path_is_missing f4 &&
195                 test_path_is_file sub/dir/f4
196         ) &&
197         cleanup_git &&
198         git p4 clone --dest="$git" //depot/sub/dir@all &&
199         (
200                 cd "$git" &&
201                 test_path_is_file f4 &&
202                 test_path_is_missing sub/dir/f4
203         )
204 '
205
206 # clone --use-client-spec must still specify a depot path
207 # if given, it should rearrange files according to client spec
208 # when it has view lines that match the depot path
209 # XXX: should clone/sync just use the client spec exactly, rather
210 # than needing depot paths?
211 test_expect_success 'clone --use-client-spec' '
212         (
213                 # big usage message
214                 exec >/dev/null &&
215                 test_must_fail git p4 clone --dest="$git" --use-client-spec
216         ) &&
217         # build a different client
218         cli2="$TRASH_DIRECTORY/cli2" &&
219         mkdir -p "$cli2" &&
220         test_when_finished "rmdir \"$cli2\"" &&
221         test_when_finished cleanup_git &&
222         (
223                 # group P4CLIENT and cli changes in a sub-shell
224                 P4CLIENT=client2 &&
225                 cli="$cli2" &&
226                 client_view "//depot/sub/... //client2/bus/..." &&
227                 git p4 clone --dest="$git" --use-client-spec //depot/... &&
228                 (
229                         cd "$git" &&
230                         test_path_is_file bus/dir/f4 &&
231                         test_path_is_missing file1
232                 ) &&
233                 cleanup_git &&
234                 # same thing again, this time with variable instead of option
235                 (
236                         cd "$git" &&
237                         git init &&
238                         git config git-p4.useClientSpec true &&
239                         git p4 sync //depot/... &&
240                         git checkout -b master p4/master &&
241                         test_path_is_file bus/dir/f4 &&
242                         test_path_is_missing file1
243                 )
244         )
245 '
246
247 test_expect_success 'submit works with no p4/master' '
248         test_when_finished cleanup_git &&
249         git p4 clone --branch=b1 //depot@1,2 --destination="$git" &&
250         (
251                 cd "$git" &&
252                 test_commit submit-1-branch &&
253                 git config git-p4.skipSubmitEdit true &&
254                 git p4 submit --branch=b1
255         )
256 '
257
258 # The sync/rebase part post-submit will engage detect-branches
259 # machinery which will not do anything in this particular test.
260 test_expect_success 'submit works with two branches' '
261         test_when_finished cleanup_git &&
262         git p4 clone --branch=b1 //depot@1,2 --destination="$git" &&
263         (
264                 cd "$git" &&
265                 git p4 sync --branch=b2 //depot@1,3 &&
266                 test_commit submit-2-branches &&
267                 git config git-p4.skipSubmitEdit true &&
268                 git p4 submit
269         )
270 '
271
272 test_expect_success 'use --git-dir option and GIT_DIR' '
273         test_when_finished cleanup_git &&
274         git p4 clone //depot --destination="$git" &&
275         (
276                 cd "$git" &&
277                 git config git-p4.skipSubmitEdit true &&
278                 test_commit first-change &&
279                 git p4 submit --git-dir "$git"
280         ) &&
281         (
282                 cd "$cli" &&
283                 p4 sync &&
284                 test_path_is_file first-change.t &&
285                 echo "cli_file" >cli_file.t &&
286                 p4 add cli_file.t &&
287                 p4 submit -d "cli change"
288         ) &&
289         (git --git-dir "$git" p4 sync) &&
290         (cd "$git" && git checkout -q p4/master) &&
291         test_path_is_file "$git"/cli_file.t &&
292         (
293                 cd "$cli" &&
294                 echo "cli_file2" >cli_file2.t &&
295                 p4 add cli_file2.t  &&
296                 p4 submit -d "cli change2"
297         ) &&
298         (GIT_DIR="$git" git p4 sync) &&
299         (cd "$git" && git checkout -q p4/master) &&
300         test_path_is_file "$git"/cli_file2.t
301 '
302
303
304 test_expect_success 'kill p4d' '
305         kill_p4d
306 '
307
308 test_done