2015-07-30 02:37:31 +00:00
|
|
|
#!/usr/bin/env bash
|
2015-07-24 17:12:45 +00:00
|
|
|
|
2018-07-10 18:48:02 +00:00
|
|
|
. "$(dirname "$0")/testlib.sh"
|
2015-07-24 17:12:45 +00:00
|
|
|
|
|
|
|
begin_test "pull"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="$(basename "$0" ".sh")"
|
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
|
|
|
|
clone_repo "$reponame" clone
|
|
|
|
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-24 17:12:45 +00:00
|
|
|
|
|
|
|
contents="a"
|
2015-09-21 17:50:22 +00:00
|
|
|
contents_oid=$(calc_oid "$contents")
|
2016-02-21 18:10:36 +00:00
|
|
|
contents2="A"
|
|
|
|
contents2_oid=$(calc_oid "$contents2")
|
2017-10-03 16:48:18 +00:00
|
|
|
contents3="dir"
|
|
|
|
contents3_oid=$(calc_oid "$contents3")
|
2015-07-24 17:12:45 +00:00
|
|
|
|
2017-10-03 16:48:18 +00:00
|
|
|
mkdir dir
|
|
|
|
echo "*.log" > .gitignore
|
2018-09-10 14:57:10 +00:00
|
|
|
printf "%s" "$contents" > a.dat
|
|
|
|
printf "%s" "$contents2" > á.dat
|
|
|
|
printf "%s" "$contents3" > dir/dir.dat
|
2017-10-03 16:48:18 +00:00
|
|
|
git add .
|
2016-02-21 18:10:36 +00:00
|
|
|
git commit -m "add files" 2>&1 | tee commit.log
|
2020-06-29 16:18:57 +00:00
|
|
|
grep "main (root-commit)" commit.log
|
2017-10-03 16:48:18 +00:00
|
|
|
grep "5 files changed" commit.log
|
2015-07-24 17:12:45 +00:00
|
|
|
grep "create mode 100644 a.dat" commit.log
|
|
|
|
grep "create mode 100644 .gitattributes" commit.log
|
|
|
|
|
2016-02-21 18:10:36 +00:00
|
|
|
ls -al
|
2015-07-24 17:12:45 +00:00
|
|
|
[ "a" = "$(cat a.dat)" ]
|
2016-02-21 18:10:36 +00:00
|
|
|
[ "A" = "$(cat "á.dat")" ]
|
2017-10-03 16:48:18 +00:00
|
|
|
[ "dir" = "$(cat "dir/dir.dat")" ]
|
2015-07-24 17:12:45 +00:00
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
assert_pointer "main" "a.dat" "$contents_oid" 1
|
|
|
|
assert_pointer "main" "á.dat" "$contents2_oid" 1
|
|
|
|
assert_pointer "main" "dir/dir.dat" "$contents3_oid" 3
|
2015-07-24 17:12:45 +00:00
|
|
|
|
|
|
|
refute_server_object "$reponame" "$contents_oid"
|
2016-02-21 18:10:36 +00:00
|
|
|
refute_server_object "$reponame" "$contents2_oid"
|
2017-10-03 16:48:18 +00:00
|
|
|
refute_server_object "$reponame" "$contents33oid"
|
2015-07-24 17:12:45 +00:00
|
|
|
|
2016-02-21 18:10:36 +00:00
|
|
|
echo "initial push"
|
2020-06-29 16:18:57 +00:00
|
|
|
git push origin main 2>&1 | tee push.log
|
2018-01-06 02:01:50 +00:00
|
|
|
grep "Uploading LFS objects: 100% (3/3), 5 B" push.log
|
2020-06-29 16:18:57 +00:00
|
|
|
grep "main -> main" push.log
|
2015-07-24 17:12:45 +00:00
|
|
|
|
|
|
|
assert_server_object "$reponame" "$contents_oid"
|
2016-02-21 18:10:36 +00:00
|
|
|
assert_server_object "$reponame" "$contents2_oid"
|
2017-10-03 16:48:18 +00:00
|
|
|
assert_server_object "$reponame" "$contents3_oid"
|
2015-07-24 17:12:45 +00:00
|
|
|
|
|
|
|
# change to the clone's working directory
|
|
|
|
cd ../clone
|
|
|
|
|
2016-02-21 18:10:36 +00:00
|
|
|
echo "normal pull"
|
2020-06-29 16:18:57 +00:00
|
|
|
git config branch.main.remote origin
|
|
|
|
git config branch.main.merge refs/heads/main
|
2017-08-12 04:18:56 +00:00
|
|
|
git pull 2>&1
|
2015-07-24 17:12:45 +00:00
|
|
|
|
|
|
|
[ "a" = "$(cat a.dat)" ]
|
2016-02-21 18:10:36 +00:00
|
|
|
[ "A" = "$(cat "á.dat")" ]
|
2015-07-24 17:12:45 +00:00
|
|
|
|
2015-08-07 17:18:39 +00:00
|
|
|
assert_local_object "$contents_oid" 1
|
2016-02-21 18:10:36 +00:00
|
|
|
assert_local_object "$contents2_oid" 1
|
2017-10-03 16:48:18 +00:00
|
|
|
assert_clean_status
|
2015-07-24 17:12:45 +00:00
|
|
|
|
2016-02-21 18:10:36 +00:00
|
|
|
echo "lfs pull"
|
2017-10-03 16:48:18 +00:00
|
|
|
rm -r a.dat á.dat dir # removing files makes the status dirty
|
2015-07-24 17:12:45 +00:00
|
|
|
rm -rf .git/lfs/objects
|
t: fix flaky tests in CI
When we download objects, it's possible that one or more messages may
not be printed because the transfer meter is paused. This is not
normally a problem for production use, since we'll print a later update
out, but in our tests, we check for specific success messages, which
leads to flaky tests when those exact messages happen to be skipped.
Since our CI hosts are very fast and good at triggering race conditions,
we see this frequently there.
Instead of checking for these exact messages, let's instead check that
the objects we want to have downloaded have in fact been downloaded and
that git lfs fsck passes, which are more reliable indicators of a
successful download. In many cases, we're already doing one or more of
these, so we already have confidence that everything's working
correctly.
2019-10-30 20:21:12 +00:00
|
|
|
git lfs pull
|
2016-02-21 18:10:36 +00:00
|
|
|
ls -al
|
2015-07-24 17:12:45 +00:00
|
|
|
[ "a" = "$(cat a.dat)" ]
|
2016-02-21 18:10:36 +00:00
|
|
|
[ "A" = "$(cat "á.dat")" ]
|
2015-08-07 17:18:39 +00:00
|
|
|
assert_local_object "$contents_oid" 1
|
2016-02-21 18:10:36 +00:00
|
|
|
assert_local_object "$contents2_oid" 1
|
t: fix flaky tests in CI
When we download objects, it's possible that one or more messages may
not be printed because the transfer meter is paused. This is not
normally a problem for production use, since we'll print a later update
out, but in our tests, we check for specific success messages, which
leads to flaky tests when those exact messages happen to be skipped.
Since our CI hosts are very fast and good at triggering race conditions,
we see this frequently there.
Instead of checking for these exact messages, let's instead check that
the objects we want to have downloaded have in fact been downloaded and
that git lfs fsck passes, which are more reliable indicators of a
successful download. In many cases, we're already doing one or more of
these, so we already have confidence that everything's working
correctly.
2019-10-30 20:21:12 +00:00
|
|
|
git lfs fsck
|
2015-07-24 17:12:45 +00:00
|
|
|
|
2016-02-21 18:10:36 +00:00
|
|
|
echo "lfs pull with remote"
|
2017-10-03 16:48:18 +00:00
|
|
|
rm -r a.dat á.dat dir
|
2015-08-13 16:22:29 +00:00
|
|
|
rm -rf .git/lfs/objects
|
t: fix flaky tests in CI
When we download objects, it's possible that one or more messages may
not be printed because the transfer meter is paused. This is not
normally a problem for production use, since we'll print a later update
out, but in our tests, we check for specific success messages, which
leads to flaky tests when those exact messages happen to be skipped.
Since our CI hosts are very fast and good at triggering race conditions,
we see this frequently there.
Instead of checking for these exact messages, let's instead check that
the objects we want to have downloaded have in fact been downloaded and
that git lfs fsck passes, which are more reliable indicators of a
successful download. In many cases, we're already doing one or more of
these, so we already have confidence that everything's working
correctly.
2019-10-30 20:21:12 +00:00
|
|
|
git lfs pull origin
|
2015-08-13 16:22:29 +00:00
|
|
|
[ "a" = "$(cat a.dat)" ]
|
2016-02-21 18:10:36 +00:00
|
|
|
[ "A" = "$(cat "á.dat")" ]
|
2015-08-13 16:22:29 +00:00
|
|
|
assert_local_object "$contents_oid" 1
|
2016-02-21 18:10:36 +00:00
|
|
|
assert_local_object "$contents2_oid" 1
|
2017-10-04 16:26:38 +00:00
|
|
|
assert_clean_status
|
t: fix flaky tests in CI
When we download objects, it's possible that one or more messages may
not be printed because the transfer meter is paused. This is not
normally a problem for production use, since we'll print a later update
out, but in our tests, we check for specific success messages, which
leads to flaky tests when those exact messages happen to be skipped.
Since our CI hosts are very fast and good at triggering race conditions,
we see this frequently there.
Instead of checking for these exact messages, let's instead check that
the objects we want to have downloaded have in fact been downloaded and
that git lfs fsck passes, which are more reliable indicators of a
successful download. In many cases, we're already doing one or more of
these, so we already have confidence that everything's working
correctly.
2019-10-30 20:21:12 +00:00
|
|
|
git lfs fsck
|
2015-08-13 16:22:29 +00:00
|
|
|
|
2016-02-21 18:10:36 +00:00
|
|
|
echo "lfs pull with local storage"
|
|
|
|
rm a.dat á.dat
|
2015-07-27 10:41:30 +00:00
|
|
|
git lfs pull
|
|
|
|
[ "a" = "$(cat a.dat)" ]
|
2016-02-21 18:10:36 +00:00
|
|
|
[ "A" = "$(cat "á.dat")" ]
|
2017-10-04 16:26:38 +00:00
|
|
|
assert_clean_status
|
2015-07-24 17:12:45 +00:00
|
|
|
|
2016-02-21 18:10:36 +00:00
|
|
|
echo "lfs pull with include/exclude filters in gitconfig"
|
2015-08-07 17:18:39 +00:00
|
|
|
rm -rf .git/lfs/objects
|
|
|
|
git config "lfs.fetchinclude" "a*"
|
|
|
|
git lfs pull
|
|
|
|
assert_local_object "$contents_oid" 1
|
2017-10-04 16:26:38 +00:00
|
|
|
assert_clean_status
|
2015-09-08 15:29:53 +00:00
|
|
|
|
2015-08-07 17:18:39 +00:00
|
|
|
rm -rf .git/lfs/objects
|
|
|
|
git config --unset "lfs.fetchinclude"
|
|
|
|
git config "lfs.fetchexclude" "a*"
|
|
|
|
git lfs pull
|
|
|
|
refute_local_object "$contents_oid"
|
2017-10-04 16:26:38 +00:00
|
|
|
assert_clean_status
|
2015-08-07 17:18:39 +00:00
|
|
|
|
2016-02-21 18:10:36 +00:00
|
|
|
echo "lfs pull with include/exclude filters in command line"
|
2015-08-07 17:18:39 +00:00
|
|
|
git config --unset "lfs.fetchexclude"
|
|
|
|
rm -rf .git/lfs/objects
|
|
|
|
git lfs pull --include="a*"
|
|
|
|
assert_local_object "$contents_oid" 1
|
2017-10-04 16:26:38 +00:00
|
|
|
assert_clean_status
|
2015-09-08 15:29:53 +00:00
|
|
|
|
2015-08-07 17:18:39 +00:00
|
|
|
rm -rf .git/lfs/objects
|
|
|
|
git lfs pull --exclude="a*"
|
|
|
|
refute_local_object "$contents_oid"
|
2017-10-04 16:26:38 +00:00
|
|
|
assert_clean_status
|
2017-10-03 16:48:18 +00:00
|
|
|
|
|
|
|
echo "resetting to test status"
|
|
|
|
git reset --hard
|
|
|
|
assert_clean_status
|
|
|
|
|
|
|
|
echo "lfs pull clean status"
|
|
|
|
git lfs pull
|
|
|
|
assert_clean_status
|
|
|
|
|
|
|
|
echo "lfs pull with -I"
|
|
|
|
git lfs pull -I "*.dat"
|
|
|
|
assert_clean_status
|
|
|
|
|
2021-09-27 12:33:22 +00:00
|
|
|
echo "lfs pull with empty file"
|
|
|
|
touch empty.dat
|
|
|
|
git add empty.dat
|
|
|
|
git commit -m 'empty'
|
|
|
|
git lfs pull
|
|
|
|
[ -z "$(cat empty.dat)" ]
|
|
|
|
assert_clean_status
|
|
|
|
|
2017-10-03 16:48:18 +00:00
|
|
|
echo "lfs pull in subdir"
|
|
|
|
cd dir
|
|
|
|
git lfs pull
|
|
|
|
assert_clean_status
|
|
|
|
|
|
|
|
echo "lfs pull in subdir with -I"
|
|
|
|
git lfs pull -I "*.dat"
|
|
|
|
assert_clean_status
|
2015-07-24 17:12:45 +00:00
|
|
|
)
|
|
|
|
end_test
|
2015-09-08 15:29:53 +00:00
|
|
|
|
2017-09-27 23:11:42 +00:00
|
|
|
begin_test "pull without clean filter"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
2018-07-12 17:39:39 +00:00
|
|
|
GIT_LFS_SKIP_SMUDGE=1 git clone $GITSERVER/t-pull no-clean
|
2017-09-27 23:11:42 +00:00
|
|
|
cd no-clean
|
|
|
|
git lfs uninstall
|
|
|
|
git config --list > config.txt
|
|
|
|
grep "filter.lfs.clean" config.txt && {
|
|
|
|
echo "clean filter still configured:"
|
|
|
|
cat config.txt
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
contents="a"
|
|
|
|
contents_oid=$(calc_oid "$contents")
|
|
|
|
|
|
|
|
# LFS object not downloaded, pointer in working directory
|
|
|
|
grep "$contents_oid" a.dat || {
|
|
|
|
echo "a.dat not $contents_oid"
|
|
|
|
ls -al
|
|
|
|
cat a.dat
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
assert_local_object "$contents_oid"
|
|
|
|
|
|
|
|
git lfs pull | tee pull.txt
|
|
|
|
if [ "0" -ne "${PIPESTATUS[0]}" ]; then
|
|
|
|
echo >&2 "fatal: expected pull to succeed ..."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
grep "Git LFS is not installed" pull.txt
|
|
|
|
echo "pulled!"
|
|
|
|
|
|
|
|
# LFS object downloaded, pointer unchanged
|
|
|
|
grep "$contents_oid" a.dat || {
|
|
|
|
echo "a.dat not $contents_oid"
|
|
|
|
ls -al
|
|
|
|
cat a.dat
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
assert_local_object "$contents_oid" 1
|
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
2016-08-15 21:11:05 +00:00
|
|
|
begin_test "pull with raw remote url"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
mkdir raw
|
|
|
|
cd raw
|
|
|
|
git init
|
|
|
|
git lfs install --local --skip-smudge
|
|
|
|
|
2018-07-12 17:39:39 +00:00
|
|
|
git remote add origin $GITSERVER/t-pull
|
2020-06-29 16:18:57 +00:00
|
|
|
git pull origin main
|
2016-08-15 21:11:05 +00:00
|
|
|
|
|
|
|
contents="a"
|
|
|
|
contents_oid=$(calc_oid "$contents")
|
|
|
|
|
|
|
|
# LFS object not downloaded, pointer in working directory
|
|
|
|
refute_local_object "$contents_oid"
|
2016-08-16 18:08:37 +00:00
|
|
|
grep "$contents_oid" a.dat
|
2016-08-15 21:11:05 +00:00
|
|
|
|
2018-07-12 17:39:39 +00:00
|
|
|
git lfs pull "$GITSERVER/t-pull"
|
2016-08-15 21:11:05 +00:00
|
|
|
echo "pulled!"
|
|
|
|
|
|
|
|
# LFS object downloaded and in working directory
|
|
|
|
assert_local_object "$contents_oid" 1
|
2018-07-26 18:40:47 +00:00
|
|
|
[ "0" = "$(grep -c "$contents_oid" a.dat)" ]
|
|
|
|
[ "a" = "$(cat a.dat)" ]
|
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
|
|
|
begin_test "pull with multiple remotes"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
mkdir multiple
|
|
|
|
cd multiple
|
|
|
|
git init
|
|
|
|
git lfs install --local --skip-smudge
|
|
|
|
|
|
|
|
git remote add origin "$GITSERVER/t-pull"
|
|
|
|
git remote add bad-remote "invalid-url"
|
2020-06-29 16:18:57 +00:00
|
|
|
git pull origin main
|
2018-07-26 18:40:47 +00:00
|
|
|
|
|
|
|
contents="a"
|
|
|
|
contents_oid=$(calc_oid "$contents")
|
|
|
|
|
|
|
|
# LFS object not downloaded, pointer in working directory
|
|
|
|
refute_local_object "$contents_oid"
|
|
|
|
grep "$contents_oid" a.dat
|
|
|
|
|
|
|
|
# pull should default to origin instead of bad-remote
|
|
|
|
git lfs pull
|
|
|
|
echo "pulled!"
|
|
|
|
|
|
|
|
# LFS object downloaded and in working directory
|
|
|
|
assert_local_object "$contents_oid" 1
|
2016-08-15 21:11:05 +00:00
|
|
|
[ "0" = "$(grep -c "$contents_oid" a.dat)" ]
|
|
|
|
[ "a" = "$(cat a.dat)" ]
|
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
2019-04-03 04:01:37 +00:00
|
|
|
begin_test "pull with invalid insteadof"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
mkdir insteadof
|
|
|
|
cd insteadof
|
|
|
|
git init
|
|
|
|
git lfs install --local --skip-smudge
|
|
|
|
|
|
|
|
git remote add origin "$GITSERVER/t-pull"
|
2020-06-29 16:18:57 +00:00
|
|
|
git pull origin main
|
2019-04-03 04:01:37 +00:00
|
|
|
|
|
|
|
# set insteadOf to rewrite the href of downloading LFS object.
|
|
|
|
git config url."$GITSERVER/storage/invalid".insteadOf "$GITSERVER/storage/"
|
|
|
|
# Enable href rewriting explicitly.
|
|
|
|
git config lfs.transfer.enablehrefrewrite true
|
|
|
|
|
|
|
|
set +e
|
|
|
|
git lfs pull > pull.log 2>&1
|
|
|
|
res=$?
|
|
|
|
|
|
|
|
set -e
|
|
|
|
[ "$res" = "2" ]
|
|
|
|
|
|
|
|
# check rewritten href is used to download LFS object.
|
|
|
|
grep "LFS: Repository or object not found: $GITSERVER/storage/invalid" pull.log
|
|
|
|
|
2019-04-04 02:04:00 +00:00
|
|
|
# lfs-pull succeed after unsetting enableHrefRewrite config
|
2019-04-03 04:01:37 +00:00
|
|
|
git config --unset lfs.transfer.enablehrefrewrite
|
|
|
|
git lfs pull
|
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
2020-10-22 20:56:31 +00:00
|
|
|
begin_test "pull with merge conflict"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
git init pull-merge-conflict
|
|
|
|
cd pull-merge-conflict
|
|
|
|
|
|
|
|
git lfs track "*.bin"
|
|
|
|
git add .
|
|
|
|
git commit -m 'gitattributes'
|
|
|
|
printf abc > abc.bin
|
|
|
|
git add .
|
|
|
|
git commit -m 'abc'
|
|
|
|
|
|
|
|
git checkout -b def
|
|
|
|
printf def > abc.bin
|
|
|
|
git add .
|
|
|
|
git commit -m 'def'
|
|
|
|
|
|
|
|
git checkout main
|
|
|
|
printf ghi > abc.bin
|
|
|
|
git add .
|
|
|
|
git commit -m 'ghi'
|
|
|
|
|
|
|
|
# This will exit nonzero because of the merge conflict.
|
|
|
|
GIT_LFS_SKIP_SMUDGE=1 git merge def || true
|
|
|
|
git lfs pull > pull.log 2>&1
|
|
|
|
[ ! -s pull.log ]
|
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
2017-05-19 01:04:59 +00:00
|
|
|
begin_test "pull: with missing object"
|
|
|
|
(
|
|
|
|
set -e
|
2017-05-19 16:44:41 +00:00
|
|
|
|
|
|
|
# this clone is setup in the first test in this file
|
|
|
|
cd clone
|
2017-05-19 01:04:59 +00:00
|
|
|
rm -rf .git/lfs/objects
|
|
|
|
|
2017-05-19 16:44:41 +00:00
|
|
|
contents_oid=$(calc_oid "a")
|
|
|
|
reponame="$(basename "$0" ".sh")"
|
|
|
|
delete_server_object "$reponame" "$contents_oid"
|
|
|
|
refute_server_object "$reponame" "$contents_oid"
|
2017-05-19 01:04:59 +00:00
|
|
|
|
|
|
|
# should return non-zero, but should also download all the other valid files too
|
2020-06-29 16:18:57 +00:00
|
|
|
git config branch.main.remote origin
|
|
|
|
git config branch.main.merge refs/heads/main
|
2017-05-19 16:56:25 +00:00
|
|
|
git lfs pull 2>&1 | tee pull.log
|
|
|
|
pull_exit="${PIPESTATUS[0]}"
|
2017-05-19 01:04:59 +00:00
|
|
|
[ "$pull_exit" != "0" ]
|
2017-05-19 16:56:25 +00:00
|
|
|
|
|
|
|
grep "$contents_oid" pull.log
|
|
|
|
|
2017-05-19 16:44:41 +00:00
|
|
|
contents2_oid=$(calc_oid "A")
|
|
|
|
assert_local_object "$contents2_oid" 1
|
|
|
|
refute_local_object "$contents_oid"
|
2017-05-19 01:04:59 +00:00
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
2015-09-08 15:29:53 +00:00
|
|
|
begin_test "pull: outside git repository"
|
|
|
|
(
|
2015-09-08 16:20:52 +00:00
|
|
|
set +e
|
|
|
|
git lfs pull 2>&1 > pull.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" ]
|
2022-01-29 00:44:16 +00:00
|
|
|
grep "Not in a Git repository" pull.log
|
2015-09-08 15:29:53 +00:00
|
|
|
)
|
|
|
|
end_test
|