3 test_description='Clone repositories and store files in Git LFS'
7 git lfs help >/dev/null 2>&1 || {
8 skip_all='skipping git p4 Git LFS tests; Git LFS not found'
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 () {
31 EXPECTED_COUNT="$2" &&
32 find "$DIR" -type f >actual &&
33 test_line_count = $EXPECTED_COUNT actual
36 test_expect_success 'start p4d' '
40 test_expect_success 'Create repo with binary files' '
41 client_view "//depot/... //client/..." &&
47 echo "content 1 txt 23 bytes" >file1.txt &&
49 echo "content 2-3 bin 25 bytes" >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 &&
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 &&
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
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 &&
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 &&
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 &&
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/..." &&
180 p4 delete file4.bin &&
181 p4 submit -d "Remove file"
184 client_view "//depot/... //client/..." &&
185 test_when_finished cleanup_git &&
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/..." &&
216 echo "*.txt text" >.gitattributes &&
217 p4 add .gitattributes &&
218 p4 submit -d "Add .gitattributes"
221 client_view "//depot/... //client/..." &&
222 test_when_finished cleanup_git &&
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 &&
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/..." &&
254 echo "content 5 bin 40 bytes XXXXXXXXXXXXXXXX" >file5.bin &&
256 p4 submit -d "Add file with small footprint after compression" &&
258 echo "content 6 bin 39 bytes XXXXXYYYYYZZZZZ" >file6.bin &&
260 p4 submit -d "Add file with large footprint after compression"
263 client_view "//depot/... //client/..." &&
264 test_when_finished cleanup_git &&
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 &&
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