git p4 doc: fix branch detection example
[git/mjg.git] / t / t9806-git-p4-options.sh
blob2ad3a3e0ca21c467e400536165a324d309ec66d0
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 # engages --detect-branches code, which will do filename filtering so
55 # no sync to either b1 or b2
56 test_expect_success 'sync when two branches but no master should noop' '
57 test_when_finished cleanup_git &&
59 cd "$git" &&
60 git init &&
61 git p4 sync --branch=refs/remotes/p4/b1 //depot@2 &&
62 git p4 sync --branch=refs/remotes/p4/b2 //depot@2 &&
63 git p4 sync &&
64 git show -s --format=%s refs/remotes/p4/b1 >show &&
65 grep "Initial import" show &&
66 git show -s --format=%s refs/remotes/p4/b2 >show &&
67 grep "Initial import" show
71 test_expect_failure 'sync --branch updates specified branch' '
72 test_when_finished cleanup_git &&
74 cd "$git" &&
75 git init &&
76 git p4 sync --branch=refs/remotes/p4/b1 //depot@2 &&
77 git p4 sync --branch=refs/remotes/p4/b2 //depot@2 &&
78 git p4 sync --branch=refs/remotes/p4/b2 &&
79 git show -s --format=%s refs/remotes/p4/b1 >show &&
80 grep "Initial import" show &&
81 git show -s --format=%s refs/remotes/p4/b2 >show &&
82 grep "change 3" show
86 # allows using the refname "p4" as a short name for p4/master
87 test_expect_success 'clone creates HEAD symbolic reference' '
88 git p4 clone --dest="$git" //depot &&
89 test_when_finished cleanup_git &&
91 cd "$git" &&
92 git rev-parse --verify refs/remotes/p4/master >master &&
93 git rev-parse --verify p4 >p4 &&
94 test_cmp master p4
98 test_expect_success 'clone --branch creates HEAD symbolic reference' '
99 git p4 clone --branch=refs/remotes/p4/sb --dest="$git" //depot &&
100 test_when_finished cleanup_git &&
102 cd "$git" &&
103 git rev-parse --verify refs/remotes/p4/sb >sb &&
104 git rev-parse --verify p4 >p4 &&
105 test_cmp sb p4
109 test_expect_success 'clone --changesfile' '
110 test_when_finished "rm cf" &&
111 printf "1\n3\n" >cf &&
112 git p4 clone --changesfile="$TRASH_DIRECTORY/cf" --dest="$git" //depot &&
113 test_when_finished cleanup_git &&
115 cd "$git" &&
116 git log --oneline p4/master >lines &&
117 test_line_count = 2 lines
118 test_path_is_file file1 &&
119 test_path_is_missing file2 &&
120 test_path_is_file file3
124 test_expect_success 'clone --changesfile, @all' '
125 test_when_finished "rm cf" &&
126 printf "1\n3\n" >cf &&
127 test_must_fail git p4 clone --changesfile="$TRASH_DIRECTORY/cf" --dest="$git" //depot@all
130 # imports both master and p4/master in refs/heads
131 # requires --import-local on sync to find p4 refs/heads
132 # does not update master on sync, just p4/master
133 test_expect_success 'clone/sync --import-local' '
134 git p4 clone --import-local --dest="$git" //depot@1,2 &&
135 test_when_finished cleanup_git &&
137 cd "$git" &&
138 git log --oneline refs/heads/master >lines &&
139 test_line_count = 2 lines &&
140 git log --oneline refs/heads/p4/master >lines &&
141 test_line_count = 2 lines &&
142 test_must_fail git p4 sync &&
144 git p4 sync --import-local &&
145 git log --oneline refs/heads/master >lines &&
146 test_line_count = 2 lines &&
147 git log --oneline refs/heads/p4/master >lines &&
148 test_line_count = 3 lines
152 test_expect_success 'clone --max-changes' '
153 git p4 clone --dest="$git" --max-changes 2 //depot@all &&
154 test_when_finished cleanup_git &&
156 cd "$git" &&
157 git log --oneline refs/heads/master >lines &&
158 test_line_count = 2 lines
162 test_expect_success 'clone --keep-path' '
164 cd "$cli" &&
165 mkdir -p sub/dir &&
166 echo f4 >sub/dir/f4 &&
167 p4 add sub/dir/f4 &&
168 p4 submit -d "change 4"
169 ) &&
170 git p4 clone --dest="$git" --keep-path //depot/sub/dir@all &&
171 test_when_finished cleanup_git &&
173 cd "$git" &&
174 test_path_is_missing f4 &&
175 test_path_is_file sub/dir/f4
176 ) &&
177 cleanup_git &&
178 git p4 clone --dest="$git" //depot/sub/dir@all &&
180 cd "$git" &&
181 test_path_is_file f4 &&
182 test_path_is_missing sub/dir/f4
186 # clone --use-client-spec must still specify a depot path
187 # if given, it should rearrange files according to client spec
188 # when it has view lines that match the depot path
189 # XXX: should clone/sync just use the client spec exactly, rather
190 # than needing depot paths?
191 test_expect_success 'clone --use-client-spec' '
193 # big usage message
194 exec >/dev/null &&
195 test_must_fail git p4 clone --dest="$git" --use-client-spec
196 ) &&
197 cli2=$(test-path-utils real_path "$TRASH_DIRECTORY/cli2") &&
198 mkdir -p "$cli2" &&
199 test_when_finished "rmdir \"$cli2\"" &&
201 cd "$cli2" &&
202 p4 client -i <<-EOF
203 Client: client2
204 Description: client2
205 Root: $cli2
206 View: //depot/sub/... //client2/bus/...
208 ) &&
209 P4CLIENT=client2 &&
210 test_when_finished cleanup_git &&
211 git p4 clone --dest="$git" --use-client-spec //depot/... &&
213 cd "$git" &&
214 test_path_is_file bus/dir/f4 &&
215 test_path_is_missing file1
216 ) &&
217 cleanup_git &&
219 # same thing again, this time with variable instead of option
221 cd "$git" &&
222 git init &&
223 git config git-p4.useClientSpec true &&
224 git p4 sync //depot/... &&
225 git checkout -b master p4/master &&
226 test_path_is_file bus/dir/f4 &&
227 test_path_is_missing file1
231 test_expect_success 'kill p4d' '
232 kill_p4d
235 test_done