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
11 test_expect_success
'start p4d' '
15 test_expect_success
'init depot' '
20 p4 submit -d "change 1" &&
23 p4 submit -d "change 2" &&
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 &&
39 git rev-parse refs/remotes/p4/sb >sb &&
40 git rev-parse refs/heads/main >main &&
42 git rev-parse HEAD >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 &&
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 &&
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 &&
85 git p4 sync --branch=refs/remotes/p4/b1 //depot@2 &&
86 git p4 sync --branch=refs/remotes/p4/b2 //depot@2 &&
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 &&
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 &&
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 &&
116 git rev-parse --verify refs/remotes/p4/master >master &&
117 git rev-parse --verify p4 >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 &&
127 git rev-parse --verify refs/remotes/p4/sb >sb &&
128 git rev-parse --verify p4 >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 &&
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 &&
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 &&
181 git log --oneline refs/heads/main >lines &&
182 test_line_count = 2 lines
186 test_expect_success
'clone --keep-path' '
190 echo f4 >sub/dir/f4 &&
192 p4 submit -d "change 4"
194 git p4 clone --dest="$git" --keep-path //depot/sub/dir@all &&
195 test_when_finished cleanup_git &&
198 test_path_is_missing f4 &&
199 test_path_is_file sub/dir/f4
202 git p4 clone --dest="$git" //depot/sub/dir@all &&
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' '
219 test_must_fail git p4 clone --dest="$git" --use-client-spec
221 # build a different client
222 cli2="$TRASH_DIRECTORY/cli2" &&
224 test_when_finished "rmdir \"$cli2\"" &&
225 test_when_finished cleanup_git &&
227 # group P4CLIENT and cli changes in a sub-shell
230 client_view "//depot/sub/... //client2/bus/..." &&
231 git p4 clone --dest="$git" --use-client-spec //depot/... &&
234 test_path_is_file bus/dir/f4 &&
235 test_path_is_missing file1
238 # same thing again, this time with variable instead of option
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" &&
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" &&
269 git p4 sync --branch=b2 //depot@1,3 &&
270 test_commit submit-2-branches &&
271 git config git-p4.skipSubmitEdit true &&
276 test_expect_success
'use --git-dir option and GIT_DIR' '
277 test_when_finished cleanup_git &&
278 git p4 clone //depot --destination="$git" &&
281 git config git-p4.skipSubmitEdit true &&
282 test_commit first-change &&
283 git p4 submit --git-dir "$git"
288 test_path_is_file first-change.t &&
289 echo "cli_file" >cli_file.t &&
291 p4 submit -d "cli change"
293 (git --git-dir "$git" p4 sync) &&
294 (cd "$git" && git checkout -q p4/master) &&
295 test_path_is_file "$git"/cli_file.t &&
298 echo "cli_file2" >cli_file2.t &&
299 p4 add cli_file2.t &&
300 p4 submit -d "cli change2"
302 (GIT_DIR="$git" git p4 sync) &&
303 (cd "$git" && git checkout -q p4/master) &&
304 test_path_is_file "$git"/cli_file2.t