git-lfs/t/t-reference-clone.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

94 lines
2.0 KiB
Bash
Executable File

#!/usr/bin/env bash
. "$(dirname "$0")/testlib.sh"
assert_same_inode() {
local repo1=$1
local repo2=$2
local oid=$3
if ! uname -s | grep -qE 'CYGWIN|MSYS|MINGW'; then
cfg1=$(cd "$repo1"; git lfs env | grep LocalMediaDir)
f1="${cfg1:14}/${oid:0:2}/${oid:2:2}/$oid"
inode1=$(ls -i $f1 | cut -f1 -d\ )
cfg2=$(cd "$repo2"; git lfs env | grep LocalMediaDir)
f2="${cfg2:14}/${oid:0:2}/${oid:2:2}/$oid"
inode2=$(ls -i $f2 | cut -f1 -d\ )
[ "$inode1" == "$inode2" ]
fi
}
begin_test "clone with reference"
(
set -e
reponame="$(basename "$0" ".sh")"
setup_remote_repo "$reponame"
ref_repo=clone_reference_repo
ref_repo_dir=$TRASHDIR/$ref_repo
clone_repo "$reponame" "$ref_repo"
git lfs track "*.dat"
contents="a"
oid=$(calc_oid "$contents")
printf "%s" "$contents" > a.dat
git add a.dat
git add .gitattributes
git commit -m "add a.dat" 2>&1
git push origin master
delete_server_object "$reponame" "$oid"
repo=test_repo
repo_dir=$TRASHDIR/$repo
git clone --reference "$ref_repo_dir/.git" \
"$GITSERVER/$reponame" "$repo_dir"
cd "$TRASHDIR/$repo"
assert_pointer "master" "a.dat" "$oid" 1
assert_same_inode "$repo_dir" "$ref_repo_dir" "$oid"
)
end_test
begin_test "fetch from clone reference"
(
set -e
reponame="$(basename "$0" ".sh")2"
setup_remote_repo "$reponame"
ref_repo=clone_reference_repo2
ref_repo_dir=$TRASHDIR/$ref_repo
clone_repo "$reponame" "$ref_repo"
repo=test_repo2
repo_dir=$TRASHDIR/$repo
git clone --reference "$ref_repo_dir/.git" \
"$GITSERVER/$reponame" "$repo_dir" 2> clone.log
cd "$ref_repo_dir"
git lfs track "*.dat"
contents="a"
oid=$(calc_oid "$contents")
printf "%s" "$contents" > a.dat
git add a.dat
git add .gitattributes
git commit -m "add a.dat" 2>&1
git push origin master
delete_server_object "$reponame" "$oid"
cd "$repo_dir"
GIT_LFS_SKIP_SMUDGE=1 git pull
git lfs pull
assert_pointer "master" "a.dat" "$oid" 1
assert_same_inode "$TRASHDIR/$repo" "$TRASHDIR/$ref_repo" "$oid"
)
end_test