Git 2.45
[git/gitster.git] / t / t9806-git-p4-options.sh
blobc26d29743307b5546d80e9c6d0cd16442a43a421
1 #!/bin/sh
3 test_description='git p4 options'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 . ./lib-git-p4.sh
10 test_expect_success 'start p4d' '
11 start_p4d
14 test_expect_success 'init depot' '
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"
29 test_expect_success 'clone no --git-dir' '
30 test_must_fail git p4 clone --git-dir=xx //depot
33 test_expect_success 'clone --branch should checkout main' '
34 git p4 clone --branch=refs/remotes/p4/sb --dest="$git" //depot &&
35 test_when_finished cleanup_git &&
37 cd "$git" &&
38 git rev-parse refs/remotes/p4/sb >sb &&
39 git rev-parse refs/heads/main >main &&
40 test_cmp sb main &&
41 git rev-parse HEAD >head &&
42 test_cmp sb head
46 test_expect_success 'sync when no master branch prints a nice error' '
47 test_when_finished cleanup_git &&
48 git p4 clone --branch=refs/remotes/p4/sb --dest="$git" //depot@2 &&
50 cd "$git" &&
51 test_must_fail git p4 sync 2>err &&
52 grep "Error: no branch refs/remotes/p4/master" err
56 test_expect_success 'sync --branch builds the full ref name correctly' '
57 test_when_finished cleanup_git &&
59 cd "$git" &&
60 git init &&
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 &&
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 &&
72 git p4 sync --branch=refs/stuff //depot &&
73 git rev-parse --verify refs/stuff
77 # engages --detect-branches code, which will do filename filtering so
78 # no sync to either b1 or b2
79 test_expect_success 'sync when two branches but no master should noop' '
80 test_when_finished cleanup_git &&
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
94 test_expect_success 'sync --branch updates specific branch, no detection' '
95 test_when_finished cleanup_git &&
97 cd "$git" &&
98 git init &&
99 git p4 sync --branch=b1 //depot@2 &&
100 git p4 sync --branch=b2 //depot@2 &&
101 git p4 sync --branch=b2 &&
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
109 # allows using the refname "p4" as a short name for p4/master
110 test_expect_success 'clone creates HEAD symbolic reference' '
111 git p4 clone --dest="$git" //depot &&
112 test_when_finished cleanup_git &&
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
121 test_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 &&
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
132 test_expect_success 'clone --changesfile' '
133 test_when_finished "rm cf" &&
134 printf "1\n3\n" >cf &&
135 git p4 clone --changesfile="$TRASH_DIRECTORY/cf" --dest="$git" //depot &&
136 test_when_finished cleanup_git &&
138 cd "$git" &&
139 git log --oneline p4/master >lines &&
140 test_line_count = 2 lines &&
141 test_path_is_file file1 &&
142 test_path_is_missing file2 &&
143 test_path_is_file file3
147 test_expect_success 'clone --changesfile, @all' '
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
153 # imports both main and p4/master in refs/heads
154 # requires --import-local on sync to find p4 refs/heads
155 # does not update main on sync, just p4/master
156 test_expect_success 'clone/sync --import-local' '
157 git p4 clone --import-local --dest="$git" //depot@1,2 &&
158 test_when_finished cleanup_git &&
160 cd "$git" &&
161 git log --oneline refs/heads/main >lines &&
162 test_line_count = 2 lines &&
163 git log --oneline refs/heads/p4/master >lines &&
164 test_line_count = 2 lines &&
165 test_must_fail git p4 sync &&
167 git p4 sync --import-local &&
168 git log --oneline refs/heads/main >lines &&
169 test_line_count = 2 lines &&
170 git log --oneline refs/heads/p4/master >lines &&
171 test_line_count = 3 lines
175 test_expect_success 'clone --max-changes' '
176 git p4 clone --dest="$git" --max-changes 2 //depot@all &&
177 test_when_finished cleanup_git &&
179 cd "$git" &&
180 git log --oneline refs/heads/main >lines &&
181 test_line_count = 2 lines
185 test_expect_success 'clone --keep-path' '
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 ) &&
193 git p4 clone --dest="$git" --keep-path //depot/sub/dir@all &&
194 test_when_finished cleanup_git &&
196 cd "$git" &&
197 test_path_is_missing f4 &&
198 test_path_is_file sub/dir/f4
199 ) &&
200 cleanup_git &&
201 git p4 clone --dest="$git" //depot/sub/dir@all &&
203 cd "$git" &&
204 test_path_is_file f4 &&
205 test_path_is_missing sub/dir/f4
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?
214 test_expect_success 'clone --use-client-spec' '
216 # big usage message
217 exec >/dev/null &&
218 test_must_fail git p4 clone --dest="$git" --use-client-spec
219 ) &&
220 # build a different client
221 cli2="$TRASH_DIRECTORY/cli2" &&
222 mkdir -p "$cli2" &&
223 test_when_finished "rmdir \"$cli2\"" &&
224 test_when_finished cleanup_git &&
226 # group P4CLIENT and cli changes in a sub-shell
227 P4CLIENT=client2 &&
228 cli="$cli2" &&
229 client_view "//depot/sub/... //client2/bus/..." &&
230 git p4 clone --dest="$git" --use-client-spec //depot/... &&
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
239 cd "$git" &&
240 git init &&
241 git config git-p4.useClientSpec true &&
242 git p4 sync //depot/... &&
243 git checkout -b main p4/master &&
244 test_path_is_file bus/dir/f4 &&
245 test_path_is_missing file1
250 test_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" &&
254 cd "$git" &&
255 test_commit submit-1-branch &&
256 git config git-p4.skipSubmitEdit true &&
257 git p4 submit --branch=b1
261 # The sync/rebase part post-submit will engage detect-branches
262 # machinery which will not do anything in this particular test.
263 test_expect_success 'submit works with two branches' '
264 test_when_finished cleanup_git &&
265 git p4 clone --branch=b1 //depot@1,2 --destination="$git" &&
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
275 test_expect_success 'use --git-dir option and GIT_DIR' '
276 test_when_finished cleanup_git &&
277 git p4 clone //depot --destination="$git" &&
279 cd "$git" &&
280 git config git-p4.skipSubmitEdit true &&
281 test_commit first-change &&
282 git p4 submit --git-dir "$git"
283 ) &&
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 &&
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
306 test_done