git-lfs/t/t-zero-len-file.sh
brian m. carlson b2ddccd90d t: avoid using shell variables in printf's first argument
The printf(1) command, like it's C cousin, takes a format string as its
first argument.  If a shell variable is passed as the first argument, it
will be interpreted as a format string; this can lead to surprising
behavior and can cause the test suite to fail if we accidentally insert
a format string character into the variable.

Modify all the places in the individual tests that we use a plain quoted
variable as the format string by running the following Ruby one-liner:

  ruby -i -pe '$_.gsub!(/printf "\$/, %q(printf "%s" "$))' t/t-*.sh

Avoid modifying the test helpers, as there are places (such as calc_oid)
where we want to pass text containing escapes (such as "\n") and have
those be properly interpreted by printf(1).
2018-09-10 14:57:10 +00:00

65 lines
1.5 KiB
Bash
Executable File

#!/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 master
# tree 2d67d025fb1f9df9fa349412b4b130e982314e92
tree="$(git cat-file -p master | 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 "master" "full.dat" "$contents_oid" 4
git push origin master | 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