3 test_description='git p4 options'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10 test_expect_success 'start p4d' '
14 test_expect_success 'init depot' '
19 p4 submit -d "change 1" &&
22 p4 submit -d "change 2" &&
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 &&
38 git rev-parse refs/remotes/p4/sb >sb &&
39 git rev-parse refs/heads/main >main &&
41 git rev-parse HEAD >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 &&
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 &&
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 &&
84 git p4 sync --branch=refs/remotes/p4/b1 //depot@2 &&
85 git p4 sync --branch=refs/remotes/p4/b2 //depot@2 &&
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 &&
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 &&
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 &&
115 git rev-parse --verify refs/remotes/p4/master >master &&
116 git rev-parse --verify p4 >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 &&
126 git rev-parse --verify refs/remotes/p4/sb >sb &&
127 git rev-parse --verify p4 >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 &&
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 &&
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 &&
180 git log --oneline refs/heads/main >lines &&
181 test_line_count = 2 lines
185 test_expect_success 'clone --keep-path' '
189 echo f4 >sub/dir/f4 &&
191 p4 submit -d "change 4"
193 git p4 clone --dest="$git" --keep-path //depot/sub/dir@all &&
194 test_when_finished cleanup_git &&
197 test_path_is_missing f4 &&
198 test_path_is_file sub/dir/f4
201 git p4 clone --dest="$git" //depot/sub/dir@all &&
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' '
218 test_must_fail git p4 clone --dest="$git" --use-client-spec
220 # build a different client
221 cli2="$TRASH_DIRECTORY/cli2" &&
223 test_when_finished "rmdir \"$cli2\"" &&
224 test_when_finished cleanup_git &&
226 # group P4CLIENT and cli changes in a sub-shell
229 client_view "//depot/sub/... //client2/bus/..." &&
230 git p4 clone --dest="$git" --use-client-spec //depot/... &&
233 test_path_is_file bus/dir/f4 &&
234 test_path_is_missing file1
237 # same thing again, this time with variable instead of option
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" &&
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" &&
268 git p4 sync --branch=b2 //depot@1,3 &&
269 test_commit submit-2-branches &&
270 git config git-p4.skipSubmitEdit true &&
275 test_expect_success 'use --git-dir option and GIT_DIR' '
276 test_when_finished cleanup_git &&
277 git p4 clone //depot --destination="$git" &&
280 git config git-p4.skipSubmitEdit true &&
281 test_commit first-change &&
282 git p4 submit --git-dir "$git"
287 test_path_is_file first-change.t &&
288 echo "cli_file" >cli_file.t &&
290 p4 submit -d "cli change"
292 (git --git-dir "$git" p4 sync) &&
293 (cd "$git" && git checkout -q p4/master) &&
294 test_path_is_file "$git"/cli_file.t &&
297 echo "cli_file2" >cli_file2.t &&
298 p4 add cli_file2.t &&
299 p4 submit -d "cli change2"
301 (GIT_DIR="$git" git p4 sync) &&
302 (cd "$git" && git checkout -q p4/master) &&
303 test_path_is_file "$git"/cli_file2.t