]> git.ipfire.org Git - thirdparty/git.git/blame - t/t9806-git-p4-options.sh
hashmap: use *_entry APIs for iteration
[thirdparty/git.git] / t / t9806-git-p4-options.sh
CommitLineData
ef86890c
PW
1#!/bin/sh
2
6ab1d76c 3test_description='git p4 options'
ef86890c
PW
4
5. ./lib-git-p4.sh
6
7test_expect_success 'start p4d' '
8 start_p4d
9'
10
11test_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
26test_expect_success 'clone no --git-dir' '
6ab1d76c 27 test_must_fail git p4 clone --git-dir=xx //depot
ef86890c
PW
28'
29
c595956d 30test_expect_success 'clone --branch should checkout master' '
6ab1d76c 31 git p4 clone --branch=refs/remotes/p4/sb --dest="$git" //depot &&
1471c6b1
PW
32 test_when_finished cleanup_git &&
33 (
34 cd "$git" &&
46738bd7
PW
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
5a8e84cd 43test_expect_success 'sync when no master branch prints a nice error' '
46738bd7 44 test_when_finished cleanup_git &&
5a8e84cd 45 git p4 clone --branch=refs/remotes/p4/sb --dest="$git" //depot@2 &&
46738bd7
PW
46 (
47 cd "$git" &&
5a8e84cd
PW
48 test_must_fail git p4 sync 2>err &&
49 grep "Error: no branch refs/remotes/p4/master" err
46738bd7
PW
50 )
51'
52
40d69ac3
PW
53test_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
46738bd7
PW
74# engages --detect-branches code, which will do filename filtering so
75# no sync to either b1 or b2
76test_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
8c9e8b6e 91test_expect_success 'sync --branch updates specific branch, no detection' '
46738bd7
PW
92 test_when_finished cleanup_git &&
93 (
94 cd "$git" &&
95 git init &&
8c9e8b6e
PW
96 git p4 sync --branch=b1 //depot@2 &&
97 git p4 sync --branch=b2 //depot@2 &&
98 git p4 sync --branch=b2 &&
46738bd7
PW
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
1471c6b1
PW
103 )
104'
105
55d12437
PW
106# allows using the refname "p4" as a short name for p4/master
107test_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
118test_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
58c8bc7c 129test_expect_success 'clone --changesfile' '
08c5eb7a
PW
130 test_when_finished "rm cf" &&
131 printf "1\n3\n" >cf &&
132 git p4 clone --changesfile="$TRASH_DIRECTORY/cf" --dest="$git" //depot &&
58c8bc7c
PW
133 test_when_finished cleanup_git &&
134 (
135 cd "$git" &&
136 git log --oneline p4/master >lines &&
cff4243d 137 test_line_count = 2 lines &&
58c8bc7c
PW
138 test_path_is_file file1 &&
139 test_path_is_missing file2 &&
140 test_path_is_file file3
141 )
142'
143
144test_expect_success 'clone --changesfile, @all' '
08c5eb7a
PW
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
58c8bc7c
PW
148'
149
5a92a6ce
PW
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
153test_expect_success 'clone/sync --import-local' '
6ab1d76c 154 git p4 clone --import-local --dest="$git" //depot@1,2 &&
5a92a6ce
PW
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 &&
6ab1d76c 162 test_must_fail git p4 sync &&
5a92a6ce 163
6ab1d76c 164 git p4 sync --import-local &&
5a92a6ce
PW
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
7fbe1ce9 172test_expect_success 'clone --max-changes' '
6ab1d76c 173 git p4 clone --dest="$git" --max-changes 2 //depot@all &&
7fbe1ce9
PW
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
ae3f41f2
PW
182test_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 ) &&
6ab1d76c 190 git p4 clone --dest="$git" --keep-path //depot/sub/dir@all &&
ae3f41f2
PW
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 &&
6ab1d76c 198 git p4 clone --dest="$git" //depot/sub/dir@all &&
ae3f41f2
PW
199 (
200 cd "$git" &&
201 test_path_is_file f4 &&
202 test_path_is_missing sub/dir/f4
203 )
204'
205
09fca77b
PW
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?
211test_expect_success 'clone --use-client-spec' '
212 (
213 # big usage message
214 exec >/dev/null &&
6ab1d76c 215 test_must_fail git p4 clone --dest="$git" --use-client-spec
09fca77b 216 ) &&
50038ba9 217 # build a different client
cfa96496 218 cli2="$TRASH_DIRECTORY/cli2" &&
09fca77b
PW
219 mkdir -p "$cli2" &&
220 test_when_finished "rmdir \"$cli2\"" &&
09fca77b 221 test_when_finished cleanup_git &&
af8c0092 222 (
50038ba9 223 # group P4CLIENT and cli changes in a sub-shell
af8c0092 224 P4CLIENT=client2 &&
50038ba9
PW
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 )
09fca77b
PW
244 )
245'
246
44e8d26c
PW
247test_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.
260test_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
378f7be1
LD
272test_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
ef86890c 303test_done