git-lfs/t/t-fetch-include.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

86 lines
1.8 KiB
Bash
Executable File

#!/usr/bin/env bash
. "$(dirname "$0")/testlib.sh"
reponame="$(basename "$0" ".sh")"
contents="big file"
contents_oid=$(calc_oid "$contents")
begin_test "fetch: setup for include test"
(
set -e
setup_remote_repo "$reponame"
clone_repo "$reponame" repo
git lfs track "*.big"
mkdir -p big/a
mkdir -p big/b
printf "%s" "$contents" > big/a/a1.big
printf "%s" "$contents" > big/b/b1.big
contents2="big file 2"
printf "%s" "$contents2" > big/big1.big
printf "%s" "$contents2" > big/big2.big
printf "%s" "$contents2" > big/big3.big
git add .gitattributes big
git commit -m "commit" | tee commit.log
grep "6 files changed" commit.log
grep "create mode 100644 .gitattributes" commit.log
grep "create mode 100644 big/a/a1.big" commit.log
grep "create mode 100644 big/b/b1.big" commit.log
grep "create mode 100644 big/big1.big" commit.log
grep "create mode 100644 big/big2.big" commit.log
grep "create mode 100644 big/big3.big" commit.log
git push origin master | tee push.log
grep "Uploading LFS objects: 100% (2/2), 18 B" push.log
assert_server_object "$reponame" "$contents_oid"
)
end_test
begin_test "fetch: include first matching file"
(
set -e
mkdir clone-1
cd clone-1
git init
git lfs install --local --skip-smudge
git remote add origin $GITSERVER/$reponame
git pull origin master
refute_local_object "$contents_oid"
git lfs ls-files
git lfs fetch --include=big/a
assert_local_object "$contents_oid" "8"
)
end_test
begin_test "fetch: include second matching file"
(
set -e
mkdir clone-2
cd clone-2
git init
git lfs install --local --skip-smudge
git remote add origin $GITSERVER/$reponame
git pull origin master
refute_local_object "$contents_oid"
git lfs ls-files
git lfs fetch --include=big/b
assert_local_object "$contents_oid" "8"
)
end_test