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)" ]
|
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
assert_pointer "main" "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-11-02 16:36:48 +00:00
|
|
|
GIT_TRACE=1 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
|
2018-11-02 16:36:48 +00:00
|
|
|
grep 'accepting "file1.dat"' checkout.log
|
|
|
|
! grep 'rejecting "file1.dat"' 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"
|
2020-06-29 16:18:57 +00:00
|
|
|
git push origin main
|
2015-08-06 16:12:11 +00:00
|
|
|
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"
|
2020-06-29 16:18:57 +00:00
|
|
|
assert_pointer "refs/heads/main" "$filename" "$(calc_oid "$filename\n")" 6
|
2018-07-09 19:15:03 +00:00
|
|
|
|
|
|
|
git lfs fetch
|
|
|
|
git lfs checkout "$filename"
|
|
|
|
|
|
|
|
refute_file_writeable "$filename"
|
|
|
|
[ "$filename" = "$(cat "$filename")" ]
|
|
|
|
popd > /dev/null
|
|
|
|
)
|
|
|
|
end_test
|
2018-10-01 18:37:45 +00:00
|
|
|
|
|
|
|
begin_test "checkout: conflicts"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="checkout-conflicts"
|
|
|
|
filename="file1.dat"
|
|
|
|
|
|
|
|
setup_remote_repo_with_file "$reponame" "$filename"
|
|
|
|
|
|
|
|
pushd "$TRASHDIR" > /dev/null
|
|
|
|
clone_repo "$reponame" "${reponame}_checkout"
|
|
|
|
|
|
|
|
git tag base
|
|
|
|
git checkout -b first
|
|
|
|
echo "abc123" > file1.dat
|
|
|
|
git add -u
|
2021-12-07 04:26:43 +00:00
|
|
|
echo "first" > other.txt
|
|
|
|
git add other.txt
|
2018-10-01 18:37:45 +00:00
|
|
|
git commit -m "first"
|
|
|
|
|
2021-12-07 04:26:43 +00:00
|
|
|
git lfs checkout --to base.txt 2>&1 | tee output.txt
|
|
|
|
grep -- '--to and exactly one of --theirs, --ours, and --base must be used together' output.txt
|
|
|
|
|
|
|
|
git lfs checkout --base 2>&1 | tee output.txt
|
|
|
|
grep -- '--to and exactly one of --theirs, --ours, and --base must be used together' output.txt
|
|
|
|
|
|
|
|
git lfs checkout --to base.txt --ours --theirs 2>&1 | tee output.txt
|
|
|
|
grep -- 'at most one of --base, --theirs, and --ours is allowed' output.txt
|
|
|
|
|
|
|
|
git lfs checkout --to base.txt --base 2>&1 | tee output.txt
|
|
|
|
grep -- '--to requires exactly one Git LFS object file path' output.txt
|
|
|
|
|
|
|
|
git lfs checkout --to base.txt --base 2>&1 abc def | tee output.txt
|
|
|
|
grep -- '--to requires exactly one Git LFS object file path' output.txt
|
|
|
|
|
2018-10-01 18:37:45 +00:00
|
|
|
git lfs checkout --to base.txt --base file1.dat 2>&1 | tee output.txt
|
|
|
|
grep 'Could not checkout.*not in the middle of a merge' output.txt
|
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
git checkout -b second main
|
2018-10-01 18:37:45 +00:00
|
|
|
echo "def456" > file1.dat
|
|
|
|
git add -u
|
2021-12-07 04:26:43 +00:00
|
|
|
echo "second" > other.txt
|
|
|
|
git add other.txt
|
2018-10-01 18:37:45 +00:00
|
|
|
git commit -m "second"
|
|
|
|
|
|
|
|
# This will cause a conflict.
|
|
|
|
! git merge first
|
|
|
|
|
|
|
|
git lfs checkout --to base.txt --base file1.dat
|
|
|
|
git lfs checkout --to ours.txt --ours file1.dat
|
|
|
|
git lfs checkout --to theirs.txt --theirs file1.dat
|
|
|
|
|
|
|
|
echo "file1.dat" | cmp - base.txt
|
|
|
|
echo "abc123" | cmp - theirs.txt
|
|
|
|
echo "def456" | cmp - ours.txt
|
2021-12-07 04:26:43 +00:00
|
|
|
|
|
|
|
git lfs checkout --to base.txt --ours other.txt 2>&1 | tee output.txt
|
|
|
|
grep 'Could not find decoder pointer for object' output.txt
|
2018-10-01 18:37:45 +00:00
|
|
|
popd > /dev/null
|
|
|
|
)
|
|
|
|
end_test
|
commands: make sure we're in the working tree
In the normal case, Git commands perform repository autodiscovery based
on the current working directory. However, in some cases, it's possible
to specify a Git working tree unrelated to the current working directory
by using GIT_WORK_TREE. In such a case, we want to make sure that we
change into the working tree such that our working directory is always
within the working tree, if one exists. This is what Git does, and it
means that when we write files into the repository, such as a
.gitattributes file, we write them into the proper place.
Note also that we adjust the code to require that the working directory
be non-empty when we require a working copy instead of that the
repository be non-bare. That's because we don't want people to be
working inside of the Git directory in such situations, where the
repository would be non-bare but would not have a working tree.
We add tests for this case for track and untrack, which require a
working tree, and for checkout, which requires only a repository. This
means that we can verify the behavior of the functions we've added
without needing to add tests for this case to each of the subcommands.
2020-10-02 19:03:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
begin_test "checkout: GIT_WORK_TREE"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="checkout-work-tree"
|
|
|
|
remotename="$(basename "$0" ".sh")"
|
|
|
|
export GIT_WORK_TREE="$reponame" GIT_DIR="$reponame-git"
|
|
|
|
mkdir "$GIT_WORK_TREE" "$GIT_DIR"
|
|
|
|
git init
|
|
|
|
git remote add origin "$GITSERVER/$remotename"
|
|
|
|
|
|
|
|
git lfs uninstall --skip-repo
|
|
|
|
|
|
|
|
git fetch origin
|
|
|
|
git checkout -B main origin/main
|
|
|
|
|
|
|
|
git lfs install
|
|
|
|
git lfs fetch
|
|
|
|
git lfs checkout
|
|
|
|
|
|
|
|
contents="something something"
|
|
|
|
[ "$contents" = "$(cat "$reponame/file1.dat")" ]
|
|
|
|
)
|
|
|
|
end_test
|