diagnose.c: add option to configure archive contents
[alt-git.git] / t / t9824-git-p4-git-lfs.sh
bloba28dbbdd566ca69212f23958056d95b735a0127c
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 >file0.dat &&
46 p4 add file0.dat &&
47 echo "content 1 txt 23 bytes" >file1.txt &&
48 p4 add file1.txt &&
49 echo "content 2-3 bin 25 bytes" >file2.dat &&
50 p4 add file2.dat &&
51 p4 submit -d "Add text and binary file" &&
53 mkdir "path with spaces" &&
54 echo "content 2-3 bin 25 bytes" >"path with spaces/file3.bin" &&
55 p4 add "path with spaces/file3.bin" &&
56 p4 submit -d "Add another binary file with same content and spaces in path" &&
58 echo "content 4 bin 26 bytes XX" >file4.bin &&
59 p4 add file4.bin &&
60 p4 submit -d "Add another binary file with different content"
64 test_expect_success 'Store files in LFS based on size (>24 bytes)' '
65 client_view "//depot/... //client/..." &&
66 test_when_finished cleanup_git &&
68 cd "$git" &&
69 git init . &&
70 git config git-p4.useClientSpec true &&
71 git config git-p4.largeFileSystem GitLFS &&
72 git config git-p4.largeFileThreshold 24 &&
73 git p4 clone --destination="$git" //depot@all &&
75 test_file_in_lfs file2.dat 25 "content 2-3 bin 25 bytes" &&
76 test_file_in_lfs "path with spaces/file3.bin" 25 "content 2-3 bin 25 bytes" &&
77 test_file_in_lfs file4.bin 26 "content 4 bin 26 bytes XX" &&
79 test_file_count_in_dir ".git/lfs/objects" 2 &&
81 cat >expect <<-\EOF &&
84 # Git LFS (see https://git-lfs.github.com/)
86 /file2.dat filter=lfs diff=lfs merge=lfs -text
87 /file4.bin filter=lfs diff=lfs merge=lfs -text
88 /path[[:space:]]with[[:space:]]spaces/file3.bin filter=lfs diff=lfs merge=lfs -text
89 EOF
90 test_path_is_file .gitattributes &&
91 test_cmp expect .gitattributes
95 test_expect_success 'Store files in LFS based on size (>25 bytes)' '
96 client_view "//depot/... //client/..." &&
97 test_when_finished cleanup_git &&
99 cd "$git" &&
100 git init . &&
101 git config git-p4.useClientSpec true &&
102 git config git-p4.largeFileSystem GitLFS &&
103 git config git-p4.largeFileThreshold 25 &&
104 git p4 clone --destination="$git" //depot@all &&
106 test_file_in_lfs file4.bin 26 "content 4 bin 26 bytes XX" &&
107 test_file_count_in_dir ".git/lfs/objects" 1 &&
109 cat >expect <<-\EOF &&
112 # Git LFS (see https://git-lfs.github.com/)
114 /file4.bin filter=lfs diff=lfs merge=lfs -text
116 test_path_is_file .gitattributes &&
117 test_cmp expect .gitattributes
121 test_expect_success 'Store files in LFS based on extension (dat)' '
122 client_view "//depot/... //client/..." &&
123 test_when_finished cleanup_git &&
125 cd "$git" &&
126 git init . &&
127 git config git-p4.useClientSpec true &&
128 git config git-p4.largeFileSystem GitLFS &&
129 git config git-p4.largeFileExtensions dat &&
130 git p4 clone --destination="$git" //depot@all &&
132 test_file_in_lfs file2.dat 25 "content 2-3 bin 25 bytes" &&
133 test_file_count_in_dir ".git/lfs/objects" 1 &&
135 cat >expect <<-\EOF &&
138 # Git LFS (see https://git-lfs.github.com/)
140 *.dat filter=lfs diff=lfs merge=lfs -text
142 test_path_is_file .gitattributes &&
143 test_cmp expect .gitattributes
147 test_expect_success 'Store files in LFS based on size (>25 bytes) and extension (dat)' '
148 client_view "//depot/... //client/..." &&
149 test_when_finished cleanup_git &&
151 cd "$git" &&
152 git init . &&
153 git config git-p4.useClientSpec true &&
154 git config git-p4.largeFileSystem GitLFS &&
155 git config git-p4.largeFileExtensions dat &&
156 git config git-p4.largeFileThreshold 25 &&
157 git p4 clone --destination="$git" //depot@all &&
159 test_file_in_lfs file2.dat 25 "content 2-3 bin 25 bytes" &&
160 test_file_in_lfs file4.bin 26 "content 4 bin 26 bytes XX" &&
161 test_file_count_in_dir ".git/lfs/objects" 2 &&
163 cat >expect <<-\EOF &&
166 # Git LFS (see https://git-lfs.github.com/)
168 *.dat filter=lfs diff=lfs merge=lfs -text
169 /file4.bin filter=lfs diff=lfs merge=lfs -text
171 test_path_is_file .gitattributes &&
172 test_cmp expect .gitattributes
176 test_expect_success 'Remove file from repo and store files in LFS based on size (>24 bytes)' '
177 client_view "//depot/... //client/..." &&
179 cd "$cli" &&
180 p4 delete file4.bin &&
181 p4 submit -d "Remove file"
182 ) &&
184 client_view "//depot/... //client/..." &&
185 test_when_finished cleanup_git &&
187 cd "$git" &&
188 git init . &&
189 git config git-p4.useClientSpec true &&
190 git config git-p4.largeFileSystem GitLFS &&
191 git config git-p4.largeFileThreshold 24 &&
192 git p4 clone --destination="$git" //depot@all &&
194 test_file_in_lfs file2.dat 25 "content 2-3 bin 25 bytes" &&
195 test_file_in_lfs "path with spaces/file3.bin" 25 "content 2-3 bin 25 bytes" &&
196 test_path_is_missing file4.bin &&
197 test_file_count_in_dir ".git/lfs/objects" 2 &&
199 cat >expect <<-\EOF &&
202 # Git LFS (see https://git-lfs.github.com/)
204 /file2.dat filter=lfs diff=lfs merge=lfs -text
205 /path[[:space:]]with[[:space:]]spaces/file3.bin filter=lfs diff=lfs merge=lfs -text
207 test_path_is_file .gitattributes &&
208 test_cmp expect .gitattributes
212 test_expect_success 'Add .gitattributes and store files in LFS based on size (>24 bytes)' '
213 client_view "//depot/... //client/..." &&
215 cd "$cli" &&
216 echo "*.txt text" >.gitattributes &&
217 p4 add .gitattributes &&
218 p4 submit -d "Add .gitattributes"
219 ) &&
221 client_view "//depot/... //client/..." &&
222 test_when_finished cleanup_git &&
224 cd "$git" &&
225 git init . &&
226 git config git-p4.useClientSpec true &&
227 git config git-p4.largeFileSystem GitLFS &&
228 git config git-p4.largeFileThreshold 24 &&
229 git p4 clone --destination="$git" //depot@all &&
231 test_file_in_lfs file2.dat 25 "content 2-3 bin 25 bytes" &&
232 test_file_in_lfs "path with spaces/file3.bin" 25 "content 2-3 bin 25 bytes" &&
233 test_path_is_missing file4.bin &&
234 test_file_count_in_dir ".git/lfs/objects" 2 &&
236 cat >expect <<-\EOF &&
237 *.txt text
240 # Git LFS (see https://git-lfs.github.com/)
242 /file2.dat filter=lfs diff=lfs merge=lfs -text
243 /path[[:space:]]with[[:space:]]spaces/file3.bin filter=lfs diff=lfs merge=lfs -text
245 test_path_is_file .gitattributes &&
246 test_cmp expect .gitattributes
250 test_expect_success 'Add big files to repo and store files in LFS based on compressed size (>28 bytes)' '
251 client_view "//depot/... //client/..." &&
253 cd "$cli" &&
254 echo "content 5 bin 40 bytes XXXXXXXXXXXXXXXX" >file5.bin &&
255 p4 add file5.bin &&
256 p4 submit -d "Add file with small footprint after compression" &&
258 echo "content 6 bin 39 bytes XXXXXYYYYYZZZZZ" >file6.bin &&
259 p4 add file6.bin &&
260 p4 submit -d "Add file with large footprint after compression"
261 ) &&
263 client_view "//depot/... //client/..." &&
264 test_when_finished cleanup_git &&
266 cd "$git" &&
267 git init . &&
268 git config git-p4.useClientSpec true &&
269 git config git-p4.largeFileSystem GitLFS &&
270 git config git-p4.largeFileCompressedThreshold 28 &&
271 # We only import HEAD here ("@all" is missing!)
272 git p4 clone --destination="$git" //depot &&
274 test_file_in_lfs file6.bin 39 "content 6 bin 39 bytes XXXXXYYYYYZZZZZ" &&
275 test_file_count_in_dir ".git/lfs/objects" 1 &&
277 cat >expect <<-\EOF &&
278 *.txt text
281 # Git LFS (see https://git-lfs.github.com/)
283 /file6.bin filter=lfs diff=lfs merge=lfs -text
285 test_path_is_file .gitattributes &&
286 test_cmp expect .gitattributes
290 test_done