File: t-zero-len-file.sh

package info (click to toggle)
git-lfs 3.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,808 kB
  • sloc: sh: 21,256; makefile: 507; ruby: 417
file content (64 lines) | stat: -rwxr-xr-x 1,509 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env bash

. "$(dirname "$0")/testlib.sh"

reponame="$(basename "$0" ".sh")"

begin_test "push zero len file"
(
  set -e

  setup_remote_repo "$reponame"

  clone_repo "$reponame" repo

  git lfs track "*.dat"
  touch empty.dat

  contents="full"
  contents_oid=$(calc_oid "$contents")
  printf "%s" "$contents" > full.dat
  git add .gitattributes *.dat
  git commit -m "add files" | tee commit.log

  # cut from commit output
  #   $ git cat-file -p main
  #   tree 2d67d025fb1f9df9fa349412b4b130e982314e92
  tree="$(git cat-file -p main | cut -f 2 -d " " | head -n 1)"

  # cut from tree output
  #   $ git cat-file -p "$tree"
  #   100644 blob 1e9f8f7cafb6af3a6f6ddf211fa39c45fccea7ab	.gitattributes
  #   100644 blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391	empty.dat
  #   100644 blob c5de5ac7dec1c40bafe60d24da9b498937640332	full.dat
  emptyblob="$(git cat-file -p "$tree" | cut -f 3 -d " " | grep "empty.dat" | cut -f 1 -d$'\t')"

  # look for lfs pointer in git blob
  [ "0" = "$(git cat-file -p "$emptyblob" | grep "lfs" -c)" ]

  assert_pointer "main" "full.dat" "$contents_oid" 4

  git push origin main | tee push.log
  grep "Uploading LFS objects: 100% (1/1), 4 B" push.log
)
end_test

begin_test "pull zero len file"
(
  set -e

  clone_repo "$reponame" clone
  rm clone.log

  git status | grep -E "working (directory|tree) clean"
  ls -al

  if [ -s "empty.dat" ]; then
    echo "empty.dat has content:"
    cat empty.dat
    exit 1
  fi

  [ "full" = "$(cat full.dat)" ]
)
end_test