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