b2ddccd90d
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).
185 lines
5.0 KiB
Bash
Executable File
185 lines
5.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
. "$(dirname "$0")/testlib.sh"
|
|
|
|
begin_test "checkout"
|
|
(
|
|
set -e
|
|
|
|
reponame="$(basename "$0" ".sh")"
|
|
setup_remote_repo "$reponame"
|
|
|
|
clone_repo "$reponame" repo
|
|
|
|
git lfs track "*.dat" 2>&1 | tee track.log
|
|
grep "Tracking \"\*.dat\"" track.log
|
|
|
|
contents="something something"
|
|
contentsize=19
|
|
contents_oid=$(calc_oid "$contents")
|
|
|
|
# Same content everywhere is ok, just one object in lfs db
|
|
printf "%s" "$contents" > file1.dat
|
|
printf "%s" "$contents" > file2.dat
|
|
printf "%s" "$contents" > file3.dat
|
|
mkdir folder1 folder2
|
|
printf "%s" "$contents" > folder1/nested.dat
|
|
printf "%s" "$contents" > folder2/nested.dat
|
|
git add file1.dat file2.dat file3.dat folder1/nested.dat folder2/nested.dat
|
|
git add .gitattributes
|
|
git commit -m "add files"
|
|
|
|
[ "$contents" = "$(cat file1.dat)" ]
|
|
[ "$contents" = "$(cat file2.dat)" ]
|
|
[ "$contents" = "$(cat file3.dat)" ]
|
|
[ "$contents" = "$(cat folder1/nested.dat)" ]
|
|
[ "$contents" = "$(cat folder2/nested.dat)" ]
|
|
|
|
assert_pointer "master" "file1.dat" "$contents_oid" $contentsize
|
|
|
|
# Remove the working directory
|
|
rm -rf file1.dat file2.dat file3.dat folder1/nested.dat folder2/nested.dat
|
|
|
|
echo "checkout should replace all"
|
|
git lfs checkout 2>&1 | tee checkout.log
|
|
[ "$contents" = "$(cat file1.dat)" ]
|
|
[ "$contents" = "$(cat file2.dat)" ]
|
|
[ "$contents" = "$(cat file3.dat)" ]
|
|
[ "$contents" = "$(cat folder1/nested.dat)" ]
|
|
[ "$contents" = "$(cat folder2/nested.dat)" ]
|
|
grep "Checking out LFS objects: 100% (5/5), 95 B" checkout.log
|
|
|
|
# Remove the working directory
|
|
rm -rf file1.dat file2.dat file3.dat folder1/nested.dat folder2/nested.dat
|
|
|
|
echo "checkout with filters"
|
|
git lfs checkout file2.dat
|
|
[ "$contents" = "$(cat file2.dat)" ]
|
|
[ ! -f file1.dat ]
|
|
[ ! -f file3.dat ]
|
|
[ ! -f folder1/nested.dat ]
|
|
[ ! -f folder2/nested.dat ]
|
|
|
|
echo "quotes to avoid shell globbing"
|
|
git lfs checkout "file*.dat"
|
|
[ "$contents" = "$(cat file1.dat)" ]
|
|
[ "$contents" = "$(cat file3.dat)" ]
|
|
[ ! -f folder1/nested.dat ]
|
|
[ ! -f folder2/nested.dat ]
|
|
|
|
echo "test subdir context"
|
|
pushd folder1
|
|
git lfs checkout nested.dat
|
|
[ "$contents" = "$(cat nested.dat)" ]
|
|
[ ! -f ../folder2/nested.dat ]
|
|
# test '.' in current dir
|
|
rm nested.dat
|
|
git lfs checkout . 2>&1 | tee checkout.log
|
|
[ "$contents" = "$(cat nested.dat)" ]
|
|
popd
|
|
|
|
echo "test folder param"
|
|
git lfs checkout folder2
|
|
[ "$contents" = "$(cat folder2/nested.dat)" ]
|
|
|
|
echo "test '.' in current dir"
|
|
rm -rf file1.dat file2.dat file3.dat folder1/nested.dat folder2/nested.dat
|
|
git lfs checkout .
|
|
[ "$contents" = "$(cat file1.dat)" ]
|
|
[ "$contents" = "$(cat file2.dat)" ]
|
|
[ "$contents" = "$(cat file3.dat)" ]
|
|
[ "$contents" = "$(cat folder1/nested.dat)" ]
|
|
[ "$contents" = "$(cat folder2/nested.dat)" ]
|
|
|
|
echo "test checkout with missing data doesn't fail"
|
|
git push origin master
|
|
rm -rf .git/lfs/objects
|
|
rm file*.dat
|
|
git lfs checkout
|
|
[ "$(pointer $contents_oid $contentsize)" = "$(cat file1.dat)" ]
|
|
[ "$(pointer $contents_oid $contentsize)" = "$(cat file2.dat)" ]
|
|
[ "$(pointer $contents_oid $contentsize)" = "$(cat file3.dat)" ]
|
|
[ "$contents" = "$(cat folder1/nested.dat)" ]
|
|
[ "$contents" = "$(cat folder2/nested.dat)" ]
|
|
)
|
|
end_test
|
|
|
|
begin_test "checkout: without clean filter"
|
|
(
|
|
set -e
|
|
|
|
reponame="$(basename "$0" ".sh")"
|
|
git lfs uninstall
|
|
|
|
git clone "$GITSERVER/$reponame" checkout-without-clean
|
|
cd checkout-without-clean
|
|
|
|
echo "checkout without clean filter"
|
|
git lfs uninstall
|
|
git config --list > config.txt
|
|
grep "filter.lfs.clean" config.txt && {
|
|
echo "clean filter still configured:"
|
|
cat config.txt
|
|
exit 1
|
|
}
|
|
ls -al
|
|
|
|
git lfs checkout | tee checkout.txt
|
|
grep "Git LFS is not installed" checkout.txt
|
|
if [ "0" -ne "${PIPESTATUS[0]}" ]; then
|
|
echo >&2 "fatal: expected checkout to succeed ..."
|
|
exit 1
|
|
fi
|
|
|
|
contentsize=19
|
|
contents_oid=$(calc_oid "something something")
|
|
[ "$(pointer $contents_oid $contentsize)" = "$(cat file1.dat)" ]
|
|
[ "$(pointer $contents_oid $contentsize)" = "$(cat file2.dat)" ]
|
|
[ "$(pointer $contents_oid $contentsize)" = "$(cat file3.dat)" ]
|
|
[ "$(pointer $contents_oid $contentsize)" = "$(cat folder1/nested.dat)" ]
|
|
[ "$(pointer $contents_oid $contentsize)" = "$(cat folder2/nested.dat)" ]
|
|
)
|
|
end_test
|
|
|
|
begin_test "checkout: outside git repository"
|
|
(
|
|
set +e
|
|
git lfs checkout 2>&1 > checkout.log
|
|
res=$?
|
|
|
|
set -e
|
|
if [ "$res" = "0" ]; then
|
|
echo "Passes because $GIT_LFS_TEST_DIR is unset."
|
|
exit 0
|
|
fi
|
|
[ "$res" = "128" ]
|
|
grep "Not in a git repository" checkout.log
|
|
)
|
|
end_test
|
|
|
|
begin_test "checkout: write-only file"
|
|
(
|
|
set -e
|
|
|
|
reponame="checkout-locked"
|
|
filename="a.txt"
|
|
|
|
setup_remote_repo_with_file "$reponame" "$filename"
|
|
|
|
pushd "$TRASHDIR" > /dev/null
|
|
GIT_LFS_SKIP_SMUDGE=1 clone_repo "$reponame" "${reponame}_checkout"
|
|
|
|
chmod -w "$filename"
|
|
|
|
refute_file_writeable "$filename"
|
|
assert_pointer "refs/heads/master" "$filename" "$(calc_oid "$filename\n")" 6
|
|
|
|
git lfs fetch
|
|
git lfs checkout "$filename"
|
|
|
|
refute_file_writeable "$filename"
|
|
[ "$filename" = "$(cat "$filename")" ]
|
|
popd > /dev/null
|
|
)
|
|
end_test
|