Merge branch 'aj/xfuncname-ada'
[git.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_success 'clone --branch' '
31         git p4 clone --branch=refs/remotes/p4/sb --dest="$git" //depot &&
32         test_when_finished cleanup_git &&
33         (
34                 cd "$git" &&
35                 git ls-files >files &&
36                 test_line_count = 0 files &&
37                 test_path_is_file .git/refs/remotes/p4/sb
38         )
39 '
40
41 test_expect_success 'clone --changesfile' '
42         test_when_finished "rm cf" &&
43         printf "1\n3\n" >cf &&
44         git p4 clone --changesfile="$TRASH_DIRECTORY/cf" --dest="$git" //depot &&
45         test_when_finished cleanup_git &&
46         (
47                 cd "$git" &&
48                 git log --oneline p4/master >lines &&
49                 test_line_count = 2 lines
50                 test_path_is_file file1 &&
51                 test_path_is_missing file2 &&
52                 test_path_is_file file3
53         )
54 '
55
56 test_expect_success 'clone --changesfile, @all' '
57         test_when_finished "rm cf" &&
58         printf "1\n3\n" >cf &&
59         test_must_fail git p4 clone --changesfile="$TRASH_DIRECTORY/cf" --dest="$git" //depot@all
60 '
61
62 # imports both master and p4/master in refs/heads
63 # requires --import-local on sync to find p4 refs/heads
64 # does not update master on sync, just p4/master
65 test_expect_success 'clone/sync --import-local' '
66         git p4 clone --import-local --dest="$git" //depot@1,2 &&
67         test_when_finished cleanup_git &&
68         (
69                 cd "$git" &&
70                 git log --oneline refs/heads/master >lines &&
71                 test_line_count = 2 lines &&
72                 git log --oneline refs/heads/p4/master >lines &&
73                 test_line_count = 2 lines &&
74                 test_must_fail git p4 sync &&
75
76                 git p4 sync --import-local &&
77                 git log --oneline refs/heads/master >lines &&
78                 test_line_count = 2 lines &&
79                 git log --oneline refs/heads/p4/master >lines &&
80                 test_line_count = 3 lines
81         )
82 '
83
84 test_expect_success 'clone --max-changes' '
85         git p4 clone --dest="$git" --max-changes 2 //depot@all &&
86         test_when_finished cleanup_git &&
87         (
88                 cd "$git" &&
89                 git log --oneline refs/heads/master >lines &&
90                 test_line_count = 2 lines
91         )
92 '
93
94 test_expect_success 'clone --keep-path' '
95         (
96                 cd "$cli" &&
97                 mkdir -p sub/dir &&
98                 echo f4 >sub/dir/f4 &&
99                 p4 add sub/dir/f4 &&
100                 p4 submit -d "change 4"
101         ) &&
102         git p4 clone --dest="$git" --keep-path //depot/sub/dir@all &&
103         test_when_finished cleanup_git &&
104         (
105                 cd "$git" &&
106                 test_path_is_missing f4 &&
107                 test_path_is_file sub/dir/f4
108         ) &&
109         cleanup_git &&
110         git p4 clone --dest="$git" //depot/sub/dir@all &&
111         (
112                 cd "$git" &&
113                 test_path_is_file f4 &&
114                 test_path_is_missing sub/dir/f4
115         )
116 '
117
118 # clone --use-client-spec must still specify a depot path
119 # if given, it should rearrange files according to client spec
120 # when it has view lines that match the depot path
121 # XXX: should clone/sync just use the client spec exactly, rather
122 # than needing depot paths?
123 test_expect_success 'clone --use-client-spec' '
124         (
125                 # big usage message
126                 exec >/dev/null &&
127                 test_must_fail git p4 clone --dest="$git" --use-client-spec
128         ) &&
129         cli2=$(test-path-utils real_path "$TRASH_DIRECTORY/cli2") &&
130         mkdir -p "$cli2" &&
131         test_when_finished "rmdir \"$cli2\"" &&
132         (
133                 cd "$cli2" &&
134                 p4 client -i <<-EOF
135                 Client: client2
136                 Description: client2
137                 Root: $cli2
138                 View: //depot/sub/... //client2/bus/...
139                 EOF
140         ) &&
141         P4CLIENT=client2 &&
142         test_when_finished cleanup_git &&
143         git p4 clone --dest="$git" --use-client-spec //depot/... &&
144         (
145                 cd "$git" &&
146                 test_path_is_file bus/dir/f4 &&
147                 test_path_is_missing file1
148         ) &&
149         cleanup_git &&
150
151         # same thing again, this time with variable instead of option
152         (
153                 cd "$git" &&
154                 git init &&
155                 git config git-p4.useClientSpec true &&
156                 git p4 sync //depot/... &&
157                 git checkout -b master p4/master &&
158                 test_path_is_file bus/dir/f4 &&
159                 test_path_is_missing file1
160         )
161 '
162
163 test_expect_success 'kill p4d' '
164         kill_p4d
165 '
166
167 test_done