Merge branch 'js/plug-leaks' into maint
[git] / t / t9823-git-p4-mock-lfs.sh
1 #!/bin/sh
2
3 test_description='Clone repositories and store files in Mock LFS'
4
5 . ./lib-git-p4.sh
6
7 test_file_is_not_in_mock_lfs () {
8         FILE="$1" &&
9         CONTENT="$2" &&
10         echo "$CONTENT" >expect_content &&
11         test_path_is_file "$FILE" &&
12         test_cmp expect_content "$FILE"
13 }
14
15 test_file_is_in_mock_lfs () {
16         FILE="$1" &&
17         CONTENT="$2" &&
18         LOCAL_STORAGE=".git/mock-storage/local/$CONTENT" &&
19         SERVER_STORAGE=".git/mock-storage/remote/$CONTENT" &&
20         echo "pointer-$CONTENT" >expect_pointer &&
21         echo "$CONTENT" >expect_content &&
22         test_path_is_file "$FILE" &&
23         test_path_is_file "$LOCAL_STORAGE" &&
24         test_path_is_file "$SERVER_STORAGE" &&
25         test_cmp expect_pointer "$FILE" &&
26         test_cmp expect_content "$LOCAL_STORAGE" &&
27         test_cmp expect_content "$SERVER_STORAGE"
28 }
29
30 test_file_is_deleted_in_mock_lfs () {
31         FILE="$1" &&
32         CONTENT="$2" &&
33         LOCAL_STORAGE=".git/mock-storage/local/$CONTENT" &&
34         SERVER_STORAGE=".git/mock-storage/remote/$CONTENT" &&
35         echo "pointer-$CONTENT" >expect_pointer &&
36         echo "$CONTENT" >expect_content &&
37         test_path_is_missing "$FILE" &&
38         test_path_is_file "$LOCAL_STORAGE" &&
39         test_path_is_file "$SERVER_STORAGE" &&
40         test_cmp expect_content "$LOCAL_STORAGE" &&
41         test_cmp expect_content "$SERVER_STORAGE"
42 }
43
44 test_file_count_in_dir () {
45         DIR="$1" &&
46         EXPECTED_COUNT="$2" &&
47         find "$DIR" -type f >actual &&
48         test_line_count = $EXPECTED_COUNT actual
49 }
50
51 test_expect_success 'start p4d' '
52         start_p4d
53 '
54
55 test_expect_success 'Create repo with binary files' '
56         client_view "//depot/... //client/..." &&
57         (
58                 cd "$cli" &&
59
60                 echo "content 1 txt 23 bytes" >file1.txt &&
61                 p4 add file1.txt &&
62                 echo "content 2-3 bin 25 bytes" >file2.dat &&
63                 p4 add file2.dat &&
64                 p4 submit -d "Add text and binary file" &&
65
66                 mkdir "path with spaces" &&
67                 echo "content 2-3 bin 25 bytes" >"path with spaces/file3.bin" &&
68                 p4 add "path with spaces/file3.bin" &&
69                 p4 submit -d "Add another binary file with same content and spaces in path" &&
70
71                 echo "content 4 bin 26 bytes XX" >file4.bin &&
72                 p4 add file4.bin &&
73                 p4 submit -d "Add another binary file with different content"
74         )
75 '
76
77 test_expect_success 'Store files in Mock LFS based on size (>24 bytes)' '
78         client_view "//depot/... //client/..." &&
79         test_when_finished cleanup_git &&
80         (
81                 cd "$git" &&
82                 git init . &&
83                 git config git-p4.useClientSpec true &&
84                 git config git-p4.largeFileSystem MockLFS &&
85                 git config git-p4.largeFileThreshold 24 &&
86                 git config git-p4.largeFilePush True &&
87                 git p4 clone --destination="$git" //depot@all &&
88
89                 test_file_is_not_in_mock_lfs file1.txt "content 1 txt 23 bytes" &&
90                 test_file_is_in_mock_lfs file2.dat "content 2-3 bin 25 bytes" &&
91                 test_file_is_in_mock_lfs "path with spaces/file3.bin" "content 2-3 bin 25 bytes" &&
92                 test_file_is_in_mock_lfs file4.bin "content 4 bin 26 bytes XX" &&
93
94                 test_file_count_in_dir ".git/mock-storage/local" 2 &&
95                 test_file_count_in_dir ".git/mock-storage/remote" 2
96         )
97 '
98
99 test_expect_success 'Store files in Mock LFS based on extension (dat)' '
100         client_view "//depot/... //client/..." &&
101         test_when_finished cleanup_git &&
102         (
103                 cd "$git" &&
104                 git init . &&
105                 git config git-p4.useClientSpec true &&
106                 git config git-p4.largeFileSystem MockLFS &&
107                 git config git-p4.largeFileExtensions dat &&
108                 git config git-p4.largeFilePush True &&
109                 git p4 clone --destination="$git" //depot@all &&
110
111                 test_file_is_not_in_mock_lfs file1.txt "content 1 txt 23 bytes" &&
112                 test_file_is_in_mock_lfs file2.dat "content 2-3 bin 25 bytes" &&
113                 test_file_is_not_in_mock_lfs "path with spaces/file3.bin" "content 2-3 bin 25 bytes" &&
114                 test_file_is_not_in_mock_lfs file4.bin "content 4 bin 26 bytes XX" &&
115
116                 test_file_count_in_dir ".git/mock-storage/local" 1 &&
117                 test_file_count_in_dir ".git/mock-storage/remote" 1
118         )
119 '
120
121 test_expect_success 'Store files in Mock LFS based on extension (dat) and use git p4 sync and no client spec' '
122         test_when_finished cleanup_git &&
123         (
124                 cd "$git" &&
125                 git init &&
126                 git config git-p4.useClientSpec true &&
127                 git config git-p4.largeFileSystem MockLFS &&
128                 git config git-p4.largeFileExtensions dat &&
129                 git config git-p4.largeFilePush True &&
130                 git p4 sync //depot &&
131                 git checkout p4/master &&
132
133                 test_file_is_not_in_mock_lfs file1.txt "content 1 txt 23 bytes" &&
134                 test_file_is_in_mock_lfs file2.dat "content 2-3 bin 25 bytes" &&
135                 test_file_is_not_in_mock_lfs "path with spaces/file3.bin" "content 2-3 bin 25 bytes" &&
136                 test_file_is_not_in_mock_lfs file4.bin "content 4 bin 26 bytes XX" &&
137
138                 test_file_count_in_dir ".git/mock-storage/local" 1 &&
139                 test_file_count_in_dir ".git/mock-storage/remote" 1
140         )
141 '
142
143 test_expect_success 'Remove file from repo and store files in Mock LFS based on size (>24 bytes)' '
144         client_view "//depot/... //client/..." &&
145         (
146                 cd "$cli" &&
147                 p4 delete file4.bin &&
148                 p4 submit -d "Remove file"
149         ) &&
150
151         client_view "//depot/... //client/..." &&
152         test_when_finished cleanup_git &&
153         (
154                 cd "$git" &&
155                 git init . &&
156                 git config git-p4.useClientSpec true &&
157                 git config git-p4.largeFileSystem MockLFS &&
158                 git config git-p4.largeFileThreshold 24 &&
159                 git config git-p4.largeFilePush True &&
160                 git p4 clone --destination="$git" //depot@all &&
161
162                 test_file_is_not_in_mock_lfs file1.txt "content 1 txt 23 bytes" &&
163                 test_file_is_in_mock_lfs file2.dat "content 2-3 bin 25 bytes" &&
164                 test_file_is_in_mock_lfs "path with spaces/file3.bin" "content 2-3 bin 25 bytes" &&
165                 test_file_is_deleted_in_mock_lfs file4.bin "content 4 bin 26 bytes XX" &&
166
167                 test_file_count_in_dir ".git/mock-storage/local" 2 &&
168                 test_file_count_in_dir ".git/mock-storage/remote" 2
169         )
170 '
171
172 test_expect_success 'Run git p4 submit in repo configured with large file system' '
173         client_view "//depot/... //client/..." &&
174         test_when_finished cleanup_git &&
175         (
176                 cd "$git" &&
177                 git init . &&
178                 git config git-p4.useClientSpec true &&
179                 git config git-p4.largeFileSystem MockLFS &&
180                 git config git-p4.largeFileThreshold 24 &&
181                 git config git-p4.largeFilePush True &&
182                 git p4 clone --destination="$git" //depot@all &&
183
184                 test_must_fail git p4 submit
185         )
186 '
187
188 test_expect_success 'kill p4d' '
189         kill_p4d
190 '
191
192 test_done