git p4: allow short ref names to --branch
[git/mjg.git] / t / t9806-git-p4-options.sh
blobc0d44337d2893de9f10deefe80237860c8d40657
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_failure 'sync when branch is not called master should work' '
44 git p4 clone --branch=refs/remotes/p4/sb --dest="$git" //depot@2 &&
45 test_when_finished cleanup_git &&
47 cd "$git" &&
48 git p4 sync &&
49 git show -s --format=%s refs/remotes/p4/sb >show &&
50 grep "change 3" show
54 test_expect_success 'sync --branch builds the full ref name correctly' '
55 test_when_finished cleanup_git &&
57 cd "$git" &&
58 git init &&
60 git p4 sync --branch=b1 //depot &&
61 git rev-parse --verify refs/remotes/p4/b1 &&
62 git p4 sync --branch=p4/b2 //depot &&
63 git rev-parse --verify refs/remotes/p4/b2 &&
65 git p4 sync --import-local --branch=h1 //depot &&
66 git rev-parse --verify refs/heads/p4/h1 &&
67 git p4 sync --import-local --branch=p4/h2 //depot &&
68 git rev-parse --verify refs/heads/p4/h2 &&
70 git p4 sync --branch=refs/stuff //depot &&
71 git rev-parse --verify refs/stuff
75 # engages --detect-branches code, which will do filename filtering so
76 # no sync to either b1 or b2
77 test_expect_success 'sync when two branches but no master should noop' '
78 test_when_finished cleanup_git &&
80 cd "$git" &&
81 git init &&
82 git p4 sync --branch=refs/remotes/p4/b1 //depot@2 &&
83 git p4 sync --branch=refs/remotes/p4/b2 //depot@2 &&
84 git p4 sync &&
85 git show -s --format=%s refs/remotes/p4/b1 >show &&
86 grep "Initial import" show &&
87 git show -s --format=%s refs/remotes/p4/b2 >show &&
88 grep "Initial import" show
92 test_expect_failure 'sync --branch updates specified branch' '
93 test_when_finished cleanup_git &&
95 cd "$git" &&
96 git init &&
97 git p4 sync --branch=refs/remotes/p4/b1 //depot@2 &&
98 git p4 sync --branch=refs/remotes/p4/b2 //depot@2 &&
99 git p4 sync --branch=refs/remotes/p4/b2 &&
100 git show -s --format=%s refs/remotes/p4/b1 >show &&
101 grep "Initial import" show &&
102 git show -s --format=%s refs/remotes/p4/b2 >show &&
103 grep "change 3" show
107 # allows using the refname "p4" as a short name for p4/master
108 test_expect_success 'clone creates HEAD symbolic reference' '
109 git p4 clone --dest="$git" //depot &&
110 test_when_finished cleanup_git &&
112 cd "$git" &&
113 git rev-parse --verify refs/remotes/p4/master >master &&
114 git rev-parse --verify p4 >p4 &&
115 test_cmp master p4
119 test_expect_success 'clone --branch creates HEAD symbolic reference' '
120 git p4 clone --branch=refs/remotes/p4/sb --dest="$git" //depot &&
121 test_when_finished cleanup_git &&
123 cd "$git" &&
124 git rev-parse --verify refs/remotes/p4/sb >sb &&
125 git rev-parse --verify p4 >p4 &&
126 test_cmp sb p4
130 test_expect_success 'clone --changesfile' '
131 test_when_finished "rm cf" &&
132 printf "1\n3\n" >cf &&
133 git p4 clone --changesfile="$TRASH_DIRECTORY/cf" --dest="$git" //depot &&
134 test_when_finished cleanup_git &&
136 cd "$git" &&
137 git log --oneline p4/master >lines &&
138 test_line_count = 2 lines
139 test_path_is_file file1 &&
140 test_path_is_missing file2 &&
141 test_path_is_file file3
145 test_expect_success 'clone --changesfile, @all' '
146 test_when_finished "rm cf" &&
147 printf "1\n3\n" >cf &&
148 test_must_fail git p4 clone --changesfile="$TRASH_DIRECTORY/cf" --dest="$git" //depot@all
151 # imports both master and p4/master in refs/heads
152 # requires --import-local on sync to find p4 refs/heads
153 # does not update master on sync, just p4/master
154 test_expect_success 'clone/sync --import-local' '
155 git p4 clone --import-local --dest="$git" //depot@1,2 &&
156 test_when_finished cleanup_git &&
158 cd "$git" &&
159 git log --oneline refs/heads/master >lines &&
160 test_line_count = 2 lines &&
161 git log --oneline refs/heads/p4/master >lines &&
162 test_line_count = 2 lines &&
163 test_must_fail git p4 sync &&
165 git p4 sync --import-local &&
166 git log --oneline refs/heads/master >lines &&
167 test_line_count = 2 lines &&
168 git log --oneline refs/heads/p4/master >lines &&
169 test_line_count = 3 lines
173 test_expect_success 'clone --max-changes' '
174 git p4 clone --dest="$git" --max-changes 2 //depot@all &&
175 test_when_finished cleanup_git &&
177 cd "$git" &&
178 git log --oneline refs/heads/master >lines &&
179 test_line_count = 2 lines
183 test_expect_success 'clone --keep-path' '
185 cd "$cli" &&
186 mkdir -p sub/dir &&
187 echo f4 >sub/dir/f4 &&
188 p4 add sub/dir/f4 &&
189 p4 submit -d "change 4"
190 ) &&
191 git p4 clone --dest="$git" --keep-path //depot/sub/dir@all &&
192 test_when_finished cleanup_git &&
194 cd "$git" &&
195 test_path_is_missing f4 &&
196 test_path_is_file sub/dir/f4
197 ) &&
198 cleanup_git &&
199 git p4 clone --dest="$git" //depot/sub/dir@all &&
201 cd "$git" &&
202 test_path_is_file f4 &&
203 test_path_is_missing sub/dir/f4
207 # clone --use-client-spec must still specify a depot path
208 # if given, it should rearrange files according to client spec
209 # when it has view lines that match the depot path
210 # XXX: should clone/sync just use the client spec exactly, rather
211 # than needing depot paths?
212 test_expect_success 'clone --use-client-spec' '
214 # big usage message
215 exec >/dev/null &&
216 test_must_fail git p4 clone --dest="$git" --use-client-spec
217 ) &&
218 cli2=$(test-path-utils real_path "$TRASH_DIRECTORY/cli2") &&
219 mkdir -p "$cli2" &&
220 test_when_finished "rmdir \"$cli2\"" &&
222 cd "$cli2" &&
223 p4 client -i <<-EOF
224 Client: client2
225 Description: client2
226 Root: $cli2
227 View: //depot/sub/... //client2/bus/...
229 ) &&
230 P4CLIENT=client2 &&
231 test_when_finished cleanup_git &&
232 git p4 clone --dest="$git" --use-client-spec //depot/... &&
234 cd "$git" &&
235 test_path_is_file bus/dir/f4 &&
236 test_path_is_missing file1
237 ) &&
238 cleanup_git &&
240 # same thing again, this time with variable instead of option
242 cd "$git" &&
243 git init &&
244 git config git-p4.useClientSpec true &&
245 git p4 sync //depot/... &&
246 git checkout -b master p4/master &&
247 test_path_is_file bus/dir/f4 &&
248 test_path_is_missing file1
252 test_expect_success 'kill p4d' '
253 kill_p4d
256 test_done