3 . "$(dirname "$0")/testlib.sh"
15 file_1_oid="$(calc_oid "$file_1")"
16 file_1_oid_short="$(echo "$file_1_oid" | head -c 7)"
17 printf "$file_1" > file1.dat
19 git commit -m "file1.dat"
21 file_1_new="other data"
22 file_1_new_oid="$(calc_oid "$file_1_new")"
23 file_1_new_oid_short="$(echo "$file_1_new_oid" | head -c 7)"
24 printf "$file_1_new" > file1.dat
27 file_2_oid="$(calc_oid "$file_2")"
28 file_2_oid_short="$(echo "$file_2_oid" | head -c 7)"
29 printf "$file_2" > file2.dat
33 file_3_oid="$(calc_oid "$file_3")"
34 file_3_oid_short="$(echo "$file_3_oid" | head -c 7)"
35 printf "$file_3" > file3.dat
38 file_3_new="file3 other data"
39 file_3_new_oid="$(calc_oid "$file_3_new")"
40 file_3_new_oid_short="$(echo "$file_3_new_oid" | head -c 7)"
41 printf "$file_3_new" > file3.dat
43 expected="On branch master
45 Git LFS objects to be committed:
47 file2.dat (LFS: $file_2_oid_short)
48 file3.dat (LFS: $file_3_oid_short)
50 Git LFS objects not staged for commit:
52 file1.dat (LFS: $file_1_oid_short -> File: $file_1_new_oid_short)
53 file3.dat (File: $file_3_new_oid_short)"
55 [ "$expected" = "$(git lfs status)" ]
59 begin_test "status --porcelain"
67 echo "some data" > file1.dat
69 git commit -m "file1.dat"
71 echo "other data" > file1.dat
72 echo "file2 data" > file2.dat
75 echo "file3 data" > file3.dat
78 echo "file3 other data" > file3.dat
80 expected=" M file1.dat
84 [ "$expected" = "$(git lfs status --porcelain)" ]
88 begin_test "status --json"
96 echo "some data" > file1.dat
98 git commit -m "file1.dat"
100 echo "other data" > file1.dat
102 expected='{"files":{"file1.dat":{"status":"M"}}}'
103 [ "$expected" = "$(git lfs status --json)" ]
106 git commit -m "file1.dat changed"
107 git mv file1.dat file2.dat
109 expected='{"files":{"file2.dat":{"status":"R","from":"file1.dat"}}}'
110 [ "$expected" = "$(git lfs status --json)" ]
112 git commit -m "file1.dat -> file2.dat"
114 # Ensure status --json does not include non-lfs files
117 expected='{"files":{}}'
118 [ "$expected" = "$(git lfs status --json)" ]
122 begin_test "status in a sub-directory"
126 reponame="status-sub-directory"
130 git lfs track "*.dat"
131 printf "asdf" > file.dat
133 git add .gitattributes file.dat
134 git commit -m "initial commit"
136 printf "ASDF" > file.dat
138 expected="On branch master
140 Git LFS objects to be committed:
143 Git LFS objects not staged for commit:
145 ../file.dat (LFS: f0e4c2f -> File: 99b3bcf)"
147 [ "$expected" = "$(cd dir && git lfs status)" ]
151 begin_test "status: outside git repository"
154 git lfs status 2>&1 > status.log
158 if [ "$res" = "0" ]; then
159 echo "Passes because $GIT_LFS_TEST_DIR is unset."
163 grep "Not in a git repository" status.log
167 begin_test "status - before initial commit"
171 git init repo-initial
173 git lfs track "*.dat"
175 # should not fail when nothing to display (ignore output, will be blank)
179 contents_oid="$(calc_oid "$contents")"
180 contents_oid_short="$(echo "$contents_oid" | head -c 7)"
182 printf "$contents" > file1.dat
186 Git LFS objects to be committed:
188 file1.dat (LFS: $contents_oid_short)
190 Git LFS objects not staged for commit:"
192 [ "$expected" = "$(git lfs status)" ]
196 begin_test "status shows multiple files with identical contents"
200 reponame="uniq-status"
205 git lfs track "*.dat"
208 printf "$contents" > a.dat
209 printf "$contents" > b.dat
213 git lfs status | tee status.log
215 [ "1" -eq "$(grep -c "a.dat" status.log)" ]
216 [ "1" -eq "$(grep -c "b.dat" status.log)" ]
220 begin_test "status shows multiple copies of partially staged files"
224 reponame="status-partially-staged"
228 git lfs track "*.dat"
229 git add .gitattributes
230 git commit -m "initial commit"
233 contents_1_oid="$(calc_oid "$contents_1")"
234 contents_1_oid_short="$(echo "$contents_1_oid" | head -c 7)"
235 printf "$contents_1" > a.dat
237 # "$contents_1" changes are staged
240 # "$contents_2" changes are unstaged
242 contents_2_oid="$(calc_oid "$contents_2")"
243 contents_2_oid_short="$(echo "$contents_2_oid" | head -c 7)"
244 printf "$contents_2" > a.dat
246 expected="On branch master
248 Git LFS objects to be committed:
250 a.dat (LFS: $contents_1_oid_short)
252 Git LFS objects not staged for commit:
254 a.dat (File: $contents_2_oid_short)"
255 actual="$(git lfs status)"
257 diff -u <(echo "$expected") <(echo "$actual")
261 begin_test "status: LFS to LFS change"
265 reponame="status-lfs-to-lfs-change"
266 setup_remote_repo "$reponame"
267 clone_repo "$reponame" "$reponame"
270 contents_oid="$(calc_oid "$contents")"
271 contents_oid_short="$(echo "$contents_oid" | head -c 7)"
273 git lfs track "*.dat"
274 git add .gitattributes
275 git commit -m "track *.dat files"
277 printf "$contents" > a.dat
279 git commit -m "add a.dat"
281 contents_new="$contents +extra"
282 contents_new_oid="$(calc_oid "$contents_new")"
283 contents_new_oid_short="$(echo $contents_new_oid | head -c 7)"
285 printf "$contents_new" > a.dat
288 expected="On branch master
290 Git LFS objects to be committed:
292 a.dat (LFS: $contents_oid_short -> LFS: $contents_new_oid_short)
294 Git LFS objects not staged for commit:"
295 actual="$(git lfs status)"
297 [ "$expected" = "$actual" ]
301 begin_test "status: Git to LFS change"
305 reponame="status-git-to-lfs-change"
306 setup_remote_repo "$reponame"
307 clone_repo "$reponame" "$reponame"
310 contents_oid="$(calc_oid "$contents")"
311 contents_oid_short="$(echo "$contents_oid" | head -c 7)"
313 printf "$contents" > a.dat
315 git commit -m "add a.dat"
317 git lfs track "*.dat"
318 git add .gitattributes
319 git commit -m "track *.dat files"
321 contents_new="$contents +extra"
322 contents_new_oid="$(calc_oid "$contents_new")"
323 contents_new_oid_short="$(echo $contents_new_oid | head -c 7)"
325 printf "$contents_new" > a.dat
328 expected="On branch master
330 Git LFS objects to be committed:
332 a.dat (Git: $contents_oid_short -> LFS: $contents_new_oid_short)
334 Git LFS objects not staged for commit:"
335 actual="$(git lfs status)"
337 [ "$expected" = "$actual" ]
341 begin_test "status: Git to LFS conversion"
345 reponame="status-git-to-lfs-conversion"
346 setup_remote_repo "$reponame"
347 clone_repo "$reponame" "$reponame"
350 contents_oid="$(calc_oid "$contents")"
351 contents_oid_short="$(echo "$contents_oid" | head -c 7)"
353 printf "$contents" > a.dat
355 git commit -m "add a.dat"
357 git lfs track "*.dat"
358 git add .gitattributes
359 git commit -m "track *.dat"
361 git push origin master
363 pushd "$TRASHDIR" > /dev/null
364 clone_repo "$reponame" "$reponame-2"
368 git lfs status 2>&1 | tee status.log
369 if [ "0" -ne "${PIPESTATUS[0]}" ]; then
370 echo >&2 "git lfs status should have succeeded, didn't ..."
374 expected="On branch master
375 Git LFS objects to be pushed to origin/master:
378 Git LFS objects to be committed:
380 a.dat (Git: $contents_oid_short -> LFS: $contents_oid_short)
382 Git LFS objects not staged for commit:"
383 actual="$(cat status.log)"
385 [ "$expected" = "$actual" ]
390 begin_test "status (missing objects)"
394 reponame="status-missing-objects"
398 git lfs track "*.dat"
401 git add .gitattributes a.dat
402 git commit -m "initial commit"
404 # Remove the original object "a.dat" (ensure '--no-filters' is not given).
405 oid="$(git hash-object -t blob -- a.dat)"
406 rm -rf ".git/objects/${oid:0:2}/${oid:2}"
408 # Create an unstaged change against a source file that doesn't exist.
413 | grep "a.dat (?: <missing> -> LFS: $(calc_oid b | head -c 7))"
417 begin_test "status (unpushed objects)"
421 reponame="status-unpushed-objects"
422 setup_remote_repo "$reponame"
423 clone_repo "$reponame" "$reponame"
425 git lfs track "*.dat"
426 git add .gitattributes
427 git commit -m "initial commit"
429 git push origin master
432 oid="$(calc_oid "$contents")"
433 printf "$contents" > a.dat
436 git commit -m "add a large file"
438 expected="On branch master
439 Git LFS objects to be pushed to origin/master:
443 Git LFS objects to be committed:
446 Git LFS objects not staged for commit:"
448 [ "$expected" = "$(git lfs status)" ]