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