Merge branch 'master' of git://repo.or.cz/alt-git
[git/mingw.git] / t / t9824-git-p4-git-lfs.sh
blob0b664a377c453d56ada45153b587a1422c837ecc
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 cat "$FILE" | grep "size $SIZE" &&
17 HASH=$(cat "$FILE" | grep "oid sha256:" | sed -e "s/oid sha256://g") &&
18 LFS_FILE=".git/lfs/objects/$(echo "$HASH" | cut -c1-2)/$(echo "$HASH" | cut -c3-4)/$HASH" &&
19 echo $EXPECTED_CONTENT >expect &&
20 test_path_is_file "$FILE" &&
21 test_path_is_file "$LFS_FILE" &&
22 test_cmp expect "$LFS_FILE"
25 test_file_count_in_dir () {
26 DIR="$1" &&
27 EXPECTED_COUNT="$2" &&
28 find "$DIR" -type f >actual &&
29 test_line_count = $EXPECTED_COUNT actual
32 test_expect_success 'start p4d' '
33 start_p4d
36 test_expect_success 'Create repo with binary files' '
37 client_view "//depot/... //client/..." &&
39 cd "$cli" &&
41 echo "content 1 txt 23 bytes" >file1.txt &&
42 p4 add file1.txt &&
43 echo "content 2-3 bin 25 bytes" >file2.dat &&
44 p4 add file2.dat &&
45 p4 submit -d "Add text and binary file" &&
47 mkdir "path with spaces" &&
48 echo "content 2-3 bin 25 bytes" >"path with spaces/file3.bin" &&
49 p4 add "path with spaces/file3.bin" &&
50 p4 submit -d "Add another binary file with same content and spaces in path" &&
52 echo "content 4 bin 26 bytes XX" >file4.bin &&
53 p4 add file4.bin &&
54 p4 submit -d "Add another binary file with different content"
58 test_expect_success 'Store files in LFS based on size (>24 bytes)' '
59 client_view "//depot/... //client/..." &&
60 test_when_finished cleanup_git &&
62 cd "$git" &&
63 git init . &&
64 git config git-p4.useClientSpec true &&
65 git config git-p4.largeFileSystem GitLFS &&
66 git config git-p4.largeFileThreshold 24 &&
67 git p4 clone --destination="$git" //depot@all &&
69 test_file_in_lfs file2.dat 25 "content 2-3 bin 25 bytes" &&
70 test_file_in_lfs "path with spaces/file3.bin" 25 "content 2-3 bin 25 bytes" &&
71 test_file_in_lfs file4.bin 26 "content 4 bin 26 bytes XX" &&
73 test_file_count_in_dir ".git/lfs/objects" 2 &&
75 cat >expect <<-\EOF &&
78 # Git LFS (see https://git-lfs.github.com/)
80 /file2.dat filter=lfs -text
81 /file4.bin filter=lfs -text
82 /path[[:space:]]with[[:space:]]spaces/file3.bin filter=lfs -text
83 EOF
84 test_path_is_file .gitattributes &&
85 test_cmp expect .gitattributes
89 test_expect_success 'Store files in LFS based on size (>25 bytes)' '
90 client_view "//depot/... //client/..." &&
91 test_when_finished cleanup_git &&
93 cd "$git" &&
94 git init . &&
95 git config git-p4.useClientSpec true &&
96 git config git-p4.largeFileSystem GitLFS &&
97 git config git-p4.largeFileThreshold 25 &&
98 git p4 clone --destination="$git" //depot@all &&
100 test_file_in_lfs file4.bin 26 "content 4 bin 26 bytes XX" &&
101 test_file_count_in_dir ".git/lfs/objects" 1 &&
103 cat >expect <<-\EOF &&
106 # Git LFS (see https://git-lfs.github.com/)
108 /file4.bin filter=lfs -text
110 test_path_is_file .gitattributes &&
111 test_cmp expect .gitattributes
115 test_expect_success 'Store files in LFS based on extension (dat)' '
116 client_view "//depot/... //client/..." &&
117 test_when_finished cleanup_git &&
119 cd "$git" &&
120 git init . &&
121 git config git-p4.useClientSpec true &&
122 git config git-p4.largeFileSystem GitLFS &&
123 git config git-p4.largeFileExtensions dat &&
124 git p4 clone --destination="$git" //depot@all &&
126 test_file_in_lfs file2.dat 25 "content 2-3 bin 25 bytes" &&
127 test_file_count_in_dir ".git/lfs/objects" 1 &&
129 cat >expect <<-\EOF &&
132 # Git LFS (see https://git-lfs.github.com/)
134 *.dat filter=lfs -text
136 test_path_is_file .gitattributes &&
137 test_cmp expect .gitattributes
141 test_expect_success 'Store files in LFS based on size (>25 bytes) and extension (dat)' '
142 client_view "//depot/... //client/..." &&
143 test_when_finished cleanup_git &&
145 cd "$git" &&
146 git init . &&
147 git config git-p4.useClientSpec true &&
148 git config git-p4.largeFileSystem GitLFS &&
149 git config git-p4.largeFileExtensions dat &&
150 git config git-p4.largeFileThreshold 25 &&
151 git p4 clone --destination="$git" //depot@all &&
153 test_file_in_lfs file2.dat 25 "content 2-3 bin 25 bytes" &&
154 test_file_in_lfs file4.bin 26 "content 4 bin 26 bytes XX" &&
155 test_file_count_in_dir ".git/lfs/objects" 2 &&
157 cat >expect <<-\EOF &&
160 # Git LFS (see https://git-lfs.github.com/)
162 *.dat filter=lfs -text
163 /file4.bin filter=lfs -text
165 test_path_is_file .gitattributes &&
166 test_cmp expect .gitattributes
170 test_expect_success 'Remove file from repo and store files in LFS based on size (>24 bytes)' '
171 client_view "//depot/... //client/..." &&
173 cd "$cli" &&
174 p4 delete file4.bin &&
175 p4 submit -d "Remove file"
176 ) &&
178 client_view "//depot/... //client/..." &&
179 test_when_finished cleanup_git &&
181 cd "$git" &&
182 git init . &&
183 git config git-p4.useClientSpec true &&
184 git config git-p4.largeFileSystem GitLFS &&
185 git config git-p4.largeFileThreshold 24 &&
186 git p4 clone --destination="$git" //depot@all &&
188 test_file_in_lfs file2.dat 25 "content 2-3 bin 25 bytes" &&
189 test_file_in_lfs "path with spaces/file3.bin" 25 "content 2-3 bin 25 bytes" &&
190 test_path_is_missing file4.bin &&
191 test_file_count_in_dir ".git/lfs/objects" 2 &&
193 cat >expect <<-\EOF &&
196 # Git LFS (see https://git-lfs.github.com/)
198 /file2.dat filter=lfs -text
199 /path[[:space:]]with[[:space:]]spaces/file3.bin filter=lfs -text
201 test_path_is_file .gitattributes &&
202 test_cmp expect .gitattributes
206 test_expect_success 'Add .gitattributes and store files in LFS based on size (>24 bytes)' '
207 client_view "//depot/... //client/..." &&
209 cd "$cli" &&
210 echo "*.txt text" >.gitattributes &&
211 p4 add .gitattributes &&
212 p4 submit -d "Add .gitattributes"
213 ) &&
215 client_view "//depot/... //client/..." &&
216 test_when_finished cleanup_git &&
218 cd "$git" &&
219 git init . &&
220 git config git-p4.useClientSpec true &&
221 git config git-p4.largeFileSystem GitLFS &&
222 git config git-p4.largeFileThreshold 24 &&
223 git p4 clone --destination="$git" //depot@all &&
225 test_file_in_lfs file2.dat 25 "content 2-3 bin 25 bytes" &&
226 test_file_in_lfs "path with spaces/file3.bin" 25 "content 2-3 bin 25 bytes" &&
227 test_path_is_missing file4.bin &&
228 test_file_count_in_dir ".git/lfs/objects" 2 &&
230 cat >expect <<-\EOF &&
231 *.txt text
234 # Git LFS (see https://git-lfs.github.com/)
236 /file2.dat filter=lfs -text
237 /path[[:space:]]with[[:space:]]spaces/file3.bin filter=lfs -text
239 test_path_is_file .gitattributes &&
240 test_cmp expect .gitattributes
244 test_expect_success 'Add big files to repo and store files in LFS based on compressed size (>28 bytes)' '
245 client_view "//depot/... //client/..." &&
247 cd "$cli" &&
248 echo "content 5 bin 40 bytes XXXXXXXXXXXXXXXX" >file5.bin &&
249 p4 add file5.bin &&
250 p4 submit -d "Add file with small footprint after compression" &&
252 echo "content 6 bin 39 bytes XXXXXYYYYYZZZZZ" >file6.bin &&
253 p4 add file6.bin &&
254 p4 submit -d "Add file with large footprint after compression"
255 ) &&
257 client_view "//depot/... //client/..." &&
258 test_when_finished cleanup_git &&
260 cd "$git" &&
261 git init . &&
262 git config git-p4.useClientSpec true &&
263 git config git-p4.largeFileSystem GitLFS &&
264 git config git-p4.largeFileCompressedThreshold 28 &&
265 # We only import HEAD here ("@all" is missing!)
266 git p4 clone --destination="$git" //depot &&
268 test_file_in_lfs file6.bin 13 "content 6 bin 39 bytes XXXXXYYYYYZZZZZ"
269 test_file_count_in_dir ".git/lfs/objects" 1 &&
271 cat >expect <<-\EOF &&
272 *.txt text
275 # Git LFS (see https://git-lfs.github.com/)
277 /file6.bin filter=lfs -text
279 test_path_is_file .gitattributes &&
280 test_cmp expect .gitattributes
284 test_expect_success 'kill p4d' '
285 kill_p4d
288 test_done