git p4: test sync/clone --branch behavior
[git] / t / t9806-git-p4-options.sh
1 #!/bin/sh
2
3 test_description='git p4 options'
4
5 . ./lib-git-p4.sh
6
7 test_expect_success 'start p4d' '
8         start_p4d
9 '
10
11 test_expect_success 'init depot' '
12         (
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"
23         )
24 '
25
26 test_expect_success 'clone no --git-dir' '
27         test_must_fail git p4 clone --git-dir=xx //depot
28 '
29
30 test_expect_failure 'clone --branch should checkout master' '
31         git p4 clone --branch=refs/remotes/p4/sb --dest="$git" //depot &&
32         test_when_finished cleanup_git &&
33         (
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
40         )
41 '
42
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 &&
46         (
47                 cd "$git" &&
48                 git p4 sync &&
49                 git show -s --format=%s refs/remotes/p4/sb >show &&
50                 grep "change 3" show
51         )
52 '
53
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 &&
58         (
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
68         )
69 '
70
71 test_expect_failure 'sync --branch updates specified branch' '
72         test_when_finished cleanup_git &&
73         (
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
83         )
84 '
85
86 test_expect_success 'clone --changesfile' '
87         test_when_finished "rm cf" &&
88         printf "1\n3\n" >cf &&
89         git p4 clone --changesfile="$TRASH_DIRECTORY/cf" --dest="$git" //depot &&
90         test_when_finished cleanup_git &&
91         (
92                 cd "$git" &&
93                 git log --oneline p4/master >lines &&
94                 test_line_count = 2 lines
95                 test_path_is_file file1 &&
96                 test_path_is_missing file2 &&
97                 test_path_is_file file3
98         )
99 '
100
101 test_expect_success 'clone --changesfile, @all' '
102         test_when_finished "rm cf" &&
103         printf "1\n3\n" >cf &&
104         test_must_fail git p4 clone --changesfile="$TRASH_DIRECTORY/cf" --dest="$git" //depot@all
105 '
106
107 # imports both master and p4/master in refs/heads
108 # requires --import-local on sync to find p4 refs/heads
109 # does not update master on sync, just p4/master
110 test_expect_success 'clone/sync --import-local' '
111         git p4 clone --import-local --dest="$git" //depot@1,2 &&
112         test_when_finished cleanup_git &&
113         (
114                 cd "$git" &&
115                 git log --oneline refs/heads/master >lines &&
116                 test_line_count = 2 lines &&
117                 git log --oneline refs/heads/p4/master >lines &&
118                 test_line_count = 2 lines &&
119                 test_must_fail git p4 sync &&
120
121                 git p4 sync --import-local &&
122                 git log --oneline refs/heads/master >lines &&
123                 test_line_count = 2 lines &&
124                 git log --oneline refs/heads/p4/master >lines &&
125                 test_line_count = 3 lines
126         )
127 '
128
129 test_expect_success 'clone --max-changes' '
130         git p4 clone --dest="$git" --max-changes 2 //depot@all &&
131         test_when_finished cleanup_git &&
132         (
133                 cd "$git" &&
134                 git log --oneline refs/heads/master >lines &&
135                 test_line_count = 2 lines
136         )
137 '
138
139 test_expect_success 'clone --keep-path' '
140         (
141                 cd "$cli" &&
142                 mkdir -p sub/dir &&
143                 echo f4 >sub/dir/f4 &&
144                 p4 add sub/dir/f4 &&
145                 p4 submit -d "change 4"
146         ) &&
147         git p4 clone --dest="$git" --keep-path //depot/sub/dir@all &&
148         test_when_finished cleanup_git &&
149         (
150                 cd "$git" &&
151                 test_path_is_missing f4 &&
152                 test_path_is_file sub/dir/f4
153         ) &&
154         cleanup_git &&
155         git p4 clone --dest="$git" //depot/sub/dir@all &&
156         (
157                 cd "$git" &&
158                 test_path_is_file f4 &&
159                 test_path_is_missing sub/dir/f4
160         )
161 '
162
163 # clone --use-client-spec must still specify a depot path
164 # if given, it should rearrange files according to client spec
165 # when it has view lines that match the depot path
166 # XXX: should clone/sync just use the client spec exactly, rather
167 # than needing depot paths?
168 test_expect_success 'clone --use-client-spec' '
169         (
170                 # big usage message
171                 exec >/dev/null &&
172                 test_must_fail git p4 clone --dest="$git" --use-client-spec
173         ) &&
174         cli2=$(test-path-utils real_path "$TRASH_DIRECTORY/cli2") &&
175         mkdir -p "$cli2" &&
176         test_when_finished "rmdir \"$cli2\"" &&
177         (
178                 cd "$cli2" &&
179                 p4 client -i <<-EOF
180                 Client: client2
181                 Description: client2
182                 Root: $cli2
183                 View: //depot/sub/... //client2/bus/...
184                 EOF
185         ) &&
186         P4CLIENT=client2 &&
187         test_when_finished cleanup_git &&
188         git p4 clone --dest="$git" --use-client-spec //depot/... &&
189         (
190                 cd "$git" &&
191                 test_path_is_file bus/dir/f4 &&
192                 test_path_is_missing file1
193         ) &&
194         cleanup_git &&
195
196         # same thing again, this time with variable instead of option
197         (
198                 cd "$git" &&
199                 git init &&
200                 git config git-p4.useClientSpec true &&
201                 git p4 sync //depot/... &&
202                 git checkout -b master p4/master &&
203                 test_path_is_file bus/dir/f4 &&
204                 test_path_is_missing file1
205         )
206 '
207
208 test_expect_success 'kill p4d' '
209         kill_p4d
210 '
211
212 test_done