config parsing options: allow one flag multiple times
[alt-git.git] / t / t9806-git-p4-options.sh
blob254d428b73fe4983298f57e0d87405002abdfbc2
1 #!/bin/sh
3 test_description='git p4 options'
5 . ./lib-git-p4.sh
7 test_expect_success 'start p4d' '
8 start_p4d
11 test_expect_success 'init depot' '
13 cd "$cli" &&
14 echo file1 >file1 &&
15 p4 add file1 &&
16 p4 submit -d "change 1" &&
17 echo file2 >file2 &&
18 p4 add file2 &&
19 p4 submit -d "change 2" &&
20 echo file3 >file3 &&
21 p4 add file3 &&
22 p4 submit -d "change 3"
26 test_expect_success 'clone no --git-dir' '
27 test_must_fail git p4 clone --git-dir=xx //depot
30 test_expect_success 'clone --branch should checkout master' '
31 git p4 clone --branch=refs/remotes/p4/sb --dest="$git" //depot &&
32 test_when_finished cleanup_git &&
34 cd "$git" &&
35 git rev-parse refs/remotes/p4/sb >sb &&
36 git rev-parse refs/heads/master >master &&
37 test_cmp sb master &&
38 git rev-parse HEAD >head &&
39 test_cmp sb head
43 test_expect_success 'sync when no master branch prints a nice error' '
44 test_when_finished cleanup_git &&
45 git p4 clone --branch=refs/remotes/p4/sb --dest="$git" //depot@2 &&
47 cd "$git" &&
48 test_must_fail git p4 sync 2>err &&
49 grep "Error: no branch refs/remotes/p4/master" err
53 test_expect_success 'sync --branch builds the full ref name correctly' '
54 test_when_finished cleanup_git &&
56 cd "$git" &&
57 git init &&
59 git p4 sync --branch=b1 //depot &&
60 git rev-parse --verify refs/remotes/p4/b1 &&
61 git p4 sync --branch=p4/b2 //depot &&
62 git rev-parse --verify refs/remotes/p4/b2 &&
64 git p4 sync --import-local --branch=h1 //depot &&
65 git rev-parse --verify refs/heads/p4/h1 &&
66 git p4 sync --import-local --branch=p4/h2 //depot &&
67 git rev-parse --verify refs/heads/p4/h2 &&
69 git p4 sync --branch=refs/stuff //depot &&
70 git rev-parse --verify refs/stuff
74 # engages --detect-branches code, which will do filename filtering so
75 # no sync to either b1 or b2
76 test_expect_success 'sync when two branches but no master should noop' '
77 test_when_finished cleanup_git &&
79 cd "$git" &&
80 git init &&
81 git p4 sync --branch=refs/remotes/p4/b1 //depot@2 &&
82 git p4 sync --branch=refs/remotes/p4/b2 //depot@2 &&
83 git p4 sync &&
84 git show -s --format=%s refs/remotes/p4/b1 >show &&
85 grep "Initial import" show &&
86 git show -s --format=%s refs/remotes/p4/b2 >show &&
87 grep "Initial import" show
91 test_expect_success 'sync --branch updates specific branch, no detection' '
92 test_when_finished cleanup_git &&
94 cd "$git" &&
95 git init &&
96 git p4 sync --branch=b1 //depot@2 &&
97 git p4 sync --branch=b2 //depot@2 &&
98 git p4 sync --branch=b2 &&
99 git show -s --format=%s refs/remotes/p4/b1 >show &&
100 grep "Initial import" show &&
101 git show -s --format=%s refs/remotes/p4/b2 >show &&
102 grep "change 3" show
106 # allows using the refname "p4" as a short name for p4/master
107 test_expect_success 'clone creates HEAD symbolic reference' '
108 git p4 clone --dest="$git" //depot &&
109 test_when_finished cleanup_git &&
111 cd "$git" &&
112 git rev-parse --verify refs/remotes/p4/master >master &&
113 git rev-parse --verify p4 >p4 &&
114 test_cmp master p4
118 test_expect_success 'clone --branch creates HEAD symbolic reference' '
119 git p4 clone --branch=refs/remotes/p4/sb --dest="$git" //depot &&
120 test_when_finished cleanup_git &&
122 cd "$git" &&
123 git rev-parse --verify refs/remotes/p4/sb >sb &&
124 git rev-parse --verify p4 >p4 &&
125 test_cmp sb p4
129 test_expect_success 'clone --changesfile' '
130 test_when_finished "rm cf" &&
131 printf "1\n3\n" >cf &&
132 git p4 clone --changesfile="$TRASH_DIRECTORY/cf" --dest="$git" //depot &&
133 test_when_finished cleanup_git &&
135 cd "$git" &&
136 git log --oneline p4/master >lines &&
137 test_line_count = 2 lines
138 test_path_is_file file1 &&
139 test_path_is_missing file2 &&
140 test_path_is_file file3
144 test_expect_success 'clone --changesfile, @all' '
145 test_when_finished "rm cf" &&
146 printf "1\n3\n" >cf &&
147 test_must_fail git p4 clone --changesfile="$TRASH_DIRECTORY/cf" --dest="$git" //depot@all
150 # imports both master and p4/master in refs/heads
151 # requires --import-local on sync to find p4 refs/heads
152 # does not update master on sync, just p4/master
153 test_expect_success 'clone/sync --import-local' '
154 git p4 clone --import-local --dest="$git" //depot@1,2 &&
155 test_when_finished cleanup_git &&
157 cd "$git" &&
158 git log --oneline refs/heads/master >lines &&
159 test_line_count = 2 lines &&
160 git log --oneline refs/heads/p4/master >lines &&
161 test_line_count = 2 lines &&
162 test_must_fail git p4 sync &&
164 git p4 sync --import-local &&
165 git log --oneline refs/heads/master >lines &&
166 test_line_count = 2 lines &&
167 git log --oneline refs/heads/p4/master >lines &&
168 test_line_count = 3 lines
172 test_expect_success 'clone --max-changes' '
173 git p4 clone --dest="$git" --max-changes 2 //depot@all &&
174 test_when_finished cleanup_git &&
176 cd "$git" &&
177 git log --oneline refs/heads/master >lines &&
178 test_line_count = 2 lines
182 test_expect_success 'clone --keep-path' '
184 cd "$cli" &&
185 mkdir -p sub/dir &&
186 echo f4 >sub/dir/f4 &&
187 p4 add sub/dir/f4 &&
188 p4 submit -d "change 4"
189 ) &&
190 git p4 clone --dest="$git" --keep-path //depot/sub/dir@all &&
191 test_when_finished cleanup_git &&
193 cd "$git" &&
194 test_path_is_missing f4 &&
195 test_path_is_file sub/dir/f4
196 ) &&
197 cleanup_git &&
198 git p4 clone --dest="$git" //depot/sub/dir@all &&
200 cd "$git" &&
201 test_path_is_file f4 &&
202 test_path_is_missing sub/dir/f4
206 # clone --use-client-spec must still specify a depot path
207 # if given, it should rearrange files according to client spec
208 # when it has view lines that match the depot path
209 # XXX: should clone/sync just use the client spec exactly, rather
210 # than needing depot paths?
211 test_expect_success 'clone --use-client-spec' '
213 # big usage message
214 exec >/dev/null &&
215 test_must_fail git p4 clone --dest="$git" --use-client-spec
216 ) &&
217 # build a different client
218 cli2="$TRASH_DIRECTORY/cli2" &&
219 mkdir -p "$cli2" &&
220 test_when_finished "rmdir \"$cli2\"" &&
221 test_when_finished cleanup_git &&
223 # group P4CLIENT and cli changes in a sub-shell
224 P4CLIENT=client2 &&
225 cli="$cli2" &&
226 client_view "//depot/sub/... //client2/bus/..." &&
227 git p4 clone --dest="$git" --use-client-spec //depot/... &&
229 cd "$git" &&
230 test_path_is_file bus/dir/f4 &&
231 test_path_is_missing file1
232 ) &&
233 cleanup_git &&
234 # same thing again, this time with variable instead of option
236 cd "$git" &&
237 git init &&
238 git config git-p4.useClientSpec true &&
239 git p4 sync //depot/... &&
240 git checkout -b master p4/master &&
241 test_path_is_file bus/dir/f4 &&
242 test_path_is_missing file1
247 test_expect_success 'submit works with no p4/master' '
248 test_when_finished cleanup_git &&
249 git p4 clone --branch=b1 //depot@1,2 --destination="$git" &&
251 cd "$git" &&
252 test_commit submit-1-branch &&
253 git config git-p4.skipSubmitEdit true &&
254 git p4 submit --branch=b1
258 # The sync/rebase part post-submit will engage detect-branches
259 # machinery which will not do anything in this particular test.
260 test_expect_success 'submit works with two branches' '
261 test_when_finished cleanup_git &&
262 git p4 clone --branch=b1 //depot@1,2 --destination="$git" &&
264 cd "$git" &&
265 git p4 sync --branch=b2 //depot@1,3 &&
266 test_commit submit-2-branches &&
267 git config git-p4.skipSubmitEdit true &&
268 git p4 submit
272 test_expect_success 'kill p4d' '
273 kill_p4d
276 test_done