| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | . "$(dirname "$0")/testlib.sh" |
| 4 | |
| 5 | reponame="$(basename "$0" ".sh")" |
| 6 | |
| 7 | begin_test "push zero len file" |
| 8 | ( |
| 9 | set -e |
| 10 | |
| 11 | setup_remote_repo "$reponame" |
| 12 | |
| 13 | clone_repo "$reponame" repo |
| 14 | |
| 15 | git lfs track "*.dat" |
| 16 | touch empty.dat |
| 17 | |
| 18 | contents="full" |
| 19 | contents_oid=$(calc_oid "$contents") |
| 20 | printf "%s" "$contents" > full.dat |
| 21 | git add .gitattributes *.dat |
| 22 | git commit -m "add files" | tee commit.log |
| 23 | |
| 24 | # cut from commit output |
| 25 | # $ git cat-file -p main |
| 26 | # tree 2d67d025fb1f9df9fa349412b4b130e982314e92 |
| 27 | tree="$(git cat-file -p main | cut -f 2 -d " " | head -n 1)" |
| 28 | |
| 29 | # cut from tree output |
| 30 | # $ git cat-file -p "$tree" |
| 31 | # 100644 blob 1e9f8f7cafb6af3a6f6ddf211fa39c45fccea7ab .gitattributes |
| 32 | # 100644 blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 empty.dat |
| 33 | # 100644 blob c5de5ac7dec1c40bafe60d24da9b498937640332 full.dat |
| 34 | emptyblob="$(git cat-file -p "$tree" | cut -f 3 -d " " | grep "empty.dat" | cut -f 1 -d$'\t')" |
| 35 | |
| 36 | # look for lfs pointer in git blob |
| 37 | [ 0 -eq "$(git cat-file -p "$emptyblob" | grep -c "lfs")" ] |
| 38 | |
| 39 | assert_pointer "main" "full.dat" "$contents_oid" 4 |
| 40 | |
| 41 | git push origin main | tee push.log |
| 42 | grep "Uploading LFS objects: 100% (1/1), 4 B" push.log |
| 43 | ) |
| 44 | end_test |
| 45 | |
| 46 | begin_test "pull zero len file" |
| 47 | ( |
| 48 | set -e |
| 49 | |
| 50 | clone_repo "$reponame" clone |
| 51 | rm clone.log |
| 52 | |
| 53 | git status | grep -E "working (directory|tree) clean" |
| 54 | ls -al |
| 55 | |
| 56 | if [ -s "empty.dat" ]; then |
| 57 | echo "empty.dat has content:" |
| 58 | cat empty.dat |
| 59 | exit 1 |
| 60 | fi |
| 61 | |
| 62 | [ "full" = "$(cat full.dat)" ] |
| 63 | ) |
| 64 | end_test |