2015-07-30 02:37:31 +00:00
|
|
|
#!/usr/bin/env bash
|
2015-07-27 16:26:55 +00:00
|
|
|
|
2018-07-10 18:48:02 +00:00
|
|
|
. "$(dirname "$0")/testlib.sh"
|
2015-07-27 16:26:55 +00:00
|
|
|
|
|
|
|
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
|
2017-03-24 16:59:03 +00:00
|
|
|
grep "Tracking \"\*.dat\"" track.log
|
2015-07-27 16:26:55 +00:00
|
|
|
|
|
|
|
contents="something something"
|
2015-08-06 16:12:11 +00:00
|
|
|
contentsize=19
|
2015-09-21 17:50:22 +00:00
|
|
|
contents_oid=$(calc_oid "$contents")
|
2015-07-27 16:26:55 +00:00
|
|
|
|
2017-09-27 23:11:42 +00:00
|
|
|
# Same content everywhere is ok, just one object in lfs db
|
2018-09-10 14:57:10 +00:00
|
|
|
printf "%s" "$contents" > file1.dat
|
|
|
|
printf "%s" "$contents" > file2.dat
|
|
|
|
printf "%s" "$contents" > file3.dat
|
2015-07-27 16:26:55 +00:00
|
|
|
mkdir folder1 folder2
|
2018-09-10 14:57:10 +00:00
|
|
|
printf "%s" "$contents" > folder1/nested.dat
|
|
|
|
printf "%s" "$contents" > folder2/nested.dat
|
2015-07-27 16:26:55 +00:00
|
|
|
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)" ]
|
|
|
|
|
2015-08-06 16:12:11 +00:00
|
|
|
assert_pointer "master" "file1.dat" "$contents_oid" $contentsize
|
2015-07-27 16:26:55 +00:00
|
|
|
|
|
|
|
# Remove the working directory
|
|
|
|
rm -rf file1.dat file2.dat file3.dat folder1/nested.dat folder2/nested.dat
|
|
|
|
|
2015-10-20 22:10:41 +00:00
|
|
|
echo "checkout should replace all"
|
2018-06-08 20:29:24 +00:00
|
|
|
git lfs checkout 2>&1 | tee checkout.log
|
2015-07-27 16:26:55 +00:00
|
|
|
[ "$contents" = "$(cat file1.dat)" ]
|
|
|
|
[ "$contents" = "$(cat file2.dat)" ]
|
|
|
|
[ "$contents" = "$(cat file3.dat)" ]
|
|
|
|
[ "$contents" = "$(cat folder1/nested.dat)" ]
|
|
|
|
[ "$contents" = "$(cat folder2/nested.dat)" ]
|
2018-06-08 20:29:24 +00:00
|
|
|
grep "Checking out LFS objects: 100% (5/5), 95 B" checkout.log
|
2015-07-27 16:26:55 +00:00
|
|
|
|
2017-09-27 23:11:42 +00:00
|
|
|
# Remove the working directory
|
2015-07-29 11:04:57 +00:00
|
|
|
rm -rf file1.dat file2.dat file3.dat folder1/nested.dat folder2/nested.dat
|
|
|
|
|
2015-10-20 22:10:41 +00:00
|
|
|
echo "checkout with filters"
|
2018-06-11 17:12:59 +00:00
|
|
|
git lfs checkout file2.dat
|
2015-07-29 11:04:57 +00:00
|
|
|
[ "$contents" = "$(cat file2.dat)" ]
|
|
|
|
[ ! -f file1.dat ]
|
|
|
|
[ ! -f file3.dat ]
|
|
|
|
[ ! -f folder1/nested.dat ]
|
|
|
|
[ ! -f folder2/nested.dat ]
|
|
|
|
|
2015-10-20 22:10:41 +00:00
|
|
|
echo "quotes to avoid shell globbing"
|
2018-06-11 17:12:59 +00:00
|
|
|
git lfs checkout "file*.dat"
|
2015-07-29 11:04:57 +00:00
|
|
|
[ "$contents" = "$(cat file1.dat)" ]
|
|
|
|
[ "$contents" = "$(cat file3.dat)" ]
|
|
|
|
[ ! -f folder1/nested.dat ]
|
|
|
|
[ ! -f folder2/nested.dat ]
|
|
|
|
|
2015-10-20 22:10:41 +00:00
|
|
|
echo "test subdir context"
|
2015-07-29 11:04:57 +00:00
|
|
|
pushd folder1
|
2018-06-11 17:28:14 +00:00
|
|
|
git lfs checkout nested.dat
|
2015-07-29 11:04:57 +00:00
|
|
|
[ "$contents" = "$(cat nested.dat)" ]
|
|
|
|
[ ! -f ../folder2/nested.dat ]
|
2015-07-30 13:51:30 +00:00
|
|
|
# test '.' in current dir
|
|
|
|
rm nested.dat
|
2018-06-08 20:29:24 +00:00
|
|
|
git lfs checkout . 2>&1 | tee checkout.log
|
2015-09-08 15:29:53 +00:00
|
|
|
[ "$contents" = "$(cat nested.dat)" ]
|
2015-07-29 11:04:57 +00:00
|
|
|
popd
|
|
|
|
|
2015-10-20 22:10:41 +00:00
|
|
|
echo "test folder param"
|
2018-06-11 17:12:59 +00:00
|
|
|
git lfs checkout folder2
|
2015-07-29 11:04:57 +00:00
|
|
|
[ "$contents" = "$(cat folder2/nested.dat)" ]
|
2015-07-30 13:51:30 +00:00
|
|
|
|
2015-10-20 22:10:41 +00:00
|
|
|
echo "test '.' in current dir"
|
2015-07-30 13:51:30 +00:00
|
|
|
rm -rf file1.dat file2.dat file3.dat folder1/nested.dat folder2/nested.dat
|
2018-06-11 17:12:59 +00:00
|
|
|
git lfs checkout .
|
2015-07-30 13:51:30 +00:00
|
|
|
[ "$contents" = "$(cat file1.dat)" ]
|
|
|
|
[ "$contents" = "$(cat file2.dat)" ]
|
|
|
|
[ "$contents" = "$(cat file3.dat)" ]
|
|
|
|
[ "$contents" = "$(cat folder1/nested.dat)" ]
|
|
|
|
[ "$contents" = "$(cat folder2/nested.dat)" ]
|
|
|
|
|
2015-10-20 22:10:41 +00:00
|
|
|
echo "test checkout with missing data doesn't fail"
|
2015-08-06 16:12:11 +00:00
|
|
|
git push origin master
|
|
|
|
rm -rf .git/lfs/objects
|
|
|
|
rm file*.dat
|
2018-06-11 17:12:59 +00:00
|
|
|
git lfs checkout
|
2015-08-06 16:12:11 +00:00
|
|
|
[ "$(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)" ]
|
2017-09-27 23:11:42 +00:00
|
|
|
)
|
|
|
|
end_test
|
2015-08-06 16:12:11 +00:00
|
|
|
|
2017-09-27 23:11:42 +00:00
|
|
|
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)" ]
|
2015-07-27 16:26:55 +00:00
|
|
|
)
|
|
|
|
end_test
|
2015-09-08 15:29:53 +00:00
|
|
|
|
|
|
|
begin_test "checkout: outside git repository"
|
|
|
|
(
|
2015-09-08 16:20:52 +00:00
|
|
|
set +e
|
|
|
|
git lfs checkout 2>&1 > checkout.log
|
|
|
|
res=$?
|
|
|
|
|
2015-09-08 15:29:53 +00:00
|
|
|
set -e
|
2015-09-08 20:12:51 +00:00
|
|
|
if [ "$res" = "0" ]; then
|
|
|
|
echo "Passes because $GIT_LFS_TEST_DIR is unset."
|
|
|
|
exit 0
|
|
|
|
fi
|
2015-09-08 16:20:52 +00:00
|
|
|
[ "$res" = "128" ]
|
|
|
|
grep "Not in a git repository" checkout.log
|
2015-09-08 15:29:53 +00:00
|
|
|
)
|
|
|
|
end_test
|
2018-07-09 19:15:03 +00:00
|
|
|
|
|
|
|
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
|