Merge branch 'jk/t4205-cleanup' into maint
[git/raj.git] / t / t9824-git-p4-git-lfs.sh
blob110a7e792475fcf19ef782fae1d265ae81653853
1 #!/bin/sh
3 test_description='Clone repositories and store files in Git LFS'
5 . ./lib-git-p4.sh
7 git lfs help >/dev/null 2>&1 || {
8 skip_all='skipping git p4 Git LFS tests; Git LFS not found'
9 test_done
12 test_file_in_lfs () {
13 FILE="$1" &&
14 SIZE="$2" &&
15 EXPECTED_CONTENT="$3" &&
16 sed -n '1,1 p' "$FILE" | grep "^version " &&
17 sed -n '2,2 p' "$FILE" | grep "^oid " &&
18 sed -n '3,3 p' "$FILE" | grep "^size " &&
19 test_line_count = 3 "$FILE" &&
20 cat "$FILE" | grep "size $SIZE" &&
21 HASH=$(cat "$FILE" | grep "oid sha256:" | sed -e "s/oid sha256://g") &&
22 LFS_FILE=".git/lfs/objects/$(echo "$HASH" | cut -c1-2)/$(echo "$HASH" | cut -c3-4)/$HASH" &&
23 echo $EXPECTED_CONTENT >expect &&
24 test_path_is_file "$FILE" &&
25 test_path_is_file "$LFS_FILE" &&
26 test_cmp expect "$LFS_FILE"
29 test_file_count_in_dir () {
30 DIR="$1" &&
31 EXPECTED_COUNT="$2" &&
32 find "$DIR" -type f >actual &&
33 test_line_count = $EXPECTED_COUNT actual
36 test_expect_success 'start p4d' '
37 start_p4d
40 test_expect_success 'Create repo with binary files' '
41 client_view "//depot/... //client/..." &&
43 cd "$cli" &&
45 echo "content 1 txt 23 bytes" >file1.txt &&
46 p4 add file1.txt &&
47 echo "content 2-3 bin 25 bytes" >file2.dat &&
48 p4 add file2.dat &&
49 p4 submit -d "Add text and binary file" &&
51 mkdir "path with spaces" &&
52 echo "content 2-3 bin 25 bytes" >"path with spaces/file3.bin" &&
53 p4 add "path with spaces/file3.bin" &&
54 p4 submit -d "Add another binary file with same content and spaces in path" &&
56 echo "content 4 bin 26 bytes XX" >file4.bin &&
57 p4 add file4.bin &&
58 p4 submit -d "Add another binary file with different content"
62 test_expect_success 'Store files in LFS based on size (>24 bytes)' '
63 client_view "//depot/... //client/..." &&
64 test_when_finished cleanup_git &&
66 cd "$git" &&
67 git init . &&
68 git config git-p4.useClientSpec true &&
69 git config git-p4.largeFileSystem GitLFS &&
70 git config git-p4.largeFileThreshold 24 &&
71 git p4 clone --destination="$git" //depot@all &&
73 test_file_in_lfs file2.dat 25 "content 2-3 bin 25 bytes" &&
74 test_file_in_lfs "path with spaces/file3.bin" 25 "content 2-3 bin 25 bytes" &&
75 test_file_in_lfs file4.bin 26 "content 4 bin 26 bytes XX" &&
77 test_file_count_in_dir ".git/lfs/objects" 2 &&
79 cat >expect <<-\EOF &&
82 # Git LFS (see https://git-lfs.github.com/)
84 /file2.dat filter=lfs -text
85 /file4.bin filter=lfs -text
86 /path[[:space:]]with[[:space:]]spaces/file3.bin filter=lfs -text
87 EOF
88 test_path_is_file .gitattributes &&
89 test_cmp expect .gitattributes
93 test_expect_success 'Store files in LFS based on size (>25 bytes)' '
94 client_view "//depot/... //client/..." &&
95 test_when_finished cleanup_git &&
97 cd "$git" &&
98 git init . &&
99 git config git-p4.useClientSpec true &&
100 git config git-p4.largeFileSystem GitLFS &&
101 git config git-p4.largeFileThreshold 25 &&
102 git p4 clone --destination="$git" //depot@all &&
104 test_file_in_lfs file4.bin 26 "content 4 bin 26 bytes XX" &&
105 test_file_count_in_dir ".git/lfs/objects" 1 &&
107 cat >expect <<-\EOF &&
110 # Git LFS (see https://git-lfs.github.com/)
112 /file4.bin filter=lfs -text
114 test_path_is_file .gitattributes &&
115 test_cmp expect .gitattributes
119 test_expect_success 'Store files in LFS based on extension (dat)' '
120 client_view "//depot/... //client/..." &&
121 test_when_finished cleanup_git &&
123 cd "$git" &&
124 git init . &&
125 git config git-p4.useClientSpec true &&
126 git config git-p4.largeFileSystem GitLFS &&
127 git config git-p4.largeFileExtensions dat &&
128 git p4 clone --destination="$git" //depot@all &&
130 test_file_in_lfs file2.dat 25 "content 2-3 bin 25 bytes" &&
131 test_file_count_in_dir ".git/lfs/objects" 1 &&
133 cat >expect <<-\EOF &&
136 # Git LFS (see https://git-lfs.github.com/)
138 *.dat filter=lfs -text
140 test_path_is_file .gitattributes &&
141 test_cmp expect .gitattributes
145 test_expect_success 'Store files in LFS based on size (>25 bytes) and extension (dat)' '
146 client_view "//depot/... //client/..." &&
147 test_when_finished cleanup_git &&
149 cd "$git" &&
150 git init . &&
151 git config git-p4.useClientSpec true &&
152 git config git-p4.largeFileSystem GitLFS &&
153 git config git-p4.largeFileExtensions dat &&
154 git config git-p4.largeFileThreshold 25 &&
155 git p4 clone --destination="$git" //depot@all &&
157 test_file_in_lfs file2.dat 25 "content 2-3 bin 25 bytes" &&
158 test_file_in_lfs file4.bin 26 "content 4 bin 26 bytes XX" &&
159 test_file_count_in_dir ".git/lfs/objects" 2 &&
161 cat >expect <<-\EOF &&
164 # Git LFS (see https://git-lfs.github.com/)
166 *.dat filter=lfs -text
167 /file4.bin filter=lfs -text
169 test_path_is_file .gitattributes &&
170 test_cmp expect .gitattributes
174 test_expect_success 'Remove file from repo and store files in LFS based on size (>24 bytes)' '
175 client_view "//depot/... //client/..." &&
177 cd "$cli" &&
178 p4 delete file4.bin &&
179 p4 submit -d "Remove file"
180 ) &&
182 client_view "//depot/... //client/..." &&
183 test_when_finished cleanup_git &&
185 cd "$git" &&
186 git init . &&
187 git config git-p4.useClientSpec true &&
188 git config git-p4.largeFileSystem GitLFS &&
189 git config git-p4.largeFileThreshold 24 &&
190 git p4 clone --destination="$git" //depot@all &&
192 test_file_in_lfs file2.dat 25 "content 2-3 bin 25 bytes" &&
193 test_file_in_lfs "path with spaces/file3.bin" 25 "content 2-3 bin 25 bytes" &&
194 test_path_is_missing file4.bin &&
195 test_file_count_in_dir ".git/lfs/objects" 2 &&
197 cat >expect <<-\EOF &&
200 # Git LFS (see https://git-lfs.github.com/)
202 /file2.dat filter=lfs -text
203 /path[[:space:]]with[[:space:]]spaces/file3.bin filter=lfs -text
205 test_path_is_file .gitattributes &&
206 test_cmp expect .gitattributes
210 test_expect_success 'Add .gitattributes and store files in LFS based on size (>24 bytes)' '
211 client_view "//depot/... //client/..." &&
213 cd "$cli" &&
214 echo "*.txt text" >.gitattributes &&
215 p4 add .gitattributes &&
216 p4 submit -d "Add .gitattributes"
217 ) &&
219 client_view "//depot/... //client/..." &&
220 test_when_finished cleanup_git &&
222 cd "$git" &&
223 git init . &&
224 git config git-p4.useClientSpec true &&
225 git config git-p4.largeFileSystem GitLFS &&
226 git config git-p4.largeFileThreshold 24 &&
227 git p4 clone --destination="$git" //depot@all &&
229 test_file_in_lfs file2.dat 25 "content 2-3 bin 25 bytes" &&
230 test_file_in_lfs "path with spaces/file3.bin" 25 "content 2-3 bin 25 bytes" &&
231 test_path_is_missing file4.bin &&
232 test_file_count_in_dir ".git/lfs/objects" 2 &&
234 cat >expect <<-\EOF &&
235 *.txt text
238 # Git LFS (see https://git-lfs.github.com/)
240 /file2.dat filter=lfs -text
241 /path[[:space:]]with[[:space:]]spaces/file3.bin filter=lfs -text
243 test_path_is_file .gitattributes &&
244 test_cmp expect .gitattributes
248 test_expect_success 'Add big files to repo and store files in LFS based on compressed size (>28 bytes)' '
249 client_view "//depot/... //client/..." &&
251 cd "$cli" &&
252 echo "content 5 bin 40 bytes XXXXXXXXXXXXXXXX" >file5.bin &&
253 p4 add file5.bin &&
254 p4 submit -d "Add file with small footprint after compression" &&
256 echo "content 6 bin 39 bytes XXXXXYYYYYZZZZZ" >file6.bin &&
257 p4 add file6.bin &&
258 p4 submit -d "Add file with large footprint after compression"
259 ) &&
261 client_view "//depot/... //client/..." &&
262 test_when_finished cleanup_git &&
264 cd "$git" &&
265 git init . &&
266 git config git-p4.useClientSpec true &&
267 git config git-p4.largeFileSystem GitLFS &&
268 git config git-p4.largeFileCompressedThreshold 28 &&
269 # We only import HEAD here ("@all" is missing!)
270 git p4 clone --destination="$git" //depot &&
272 test_file_in_lfs file6.bin 39 "content 6 bin 39 bytes XXXXXYYYYYZZZZZ" &&
273 test_file_count_in_dir ".git/lfs/objects" 1 &&
275 cat >expect <<-\EOF &&
276 *.txt text
279 # Git LFS (see https://git-lfs.github.com/)
281 /file6.bin filter=lfs -text
283 test_path_is_file .gitattributes &&
284 test_cmp expect .gitattributes
288 test_expect_success 'kill p4d' '
289 kill_p4d
292 test_done