2015-07-30 02:37:31 +00:00
|
|
|
#!/usr/bin/env bash
|
2015-06-20 16:10:54 +00:00
|
|
|
|
2018-07-10 18:48:02 +00:00
|
|
|
. "$(dirname "$0")/testlib.sh"
|
2015-06-20 16:10:54 +00:00
|
|
|
|
2016-08-02 16:11:12 +00:00
|
|
|
contents="a"
|
|
|
|
contents_oid=$(calc_oid "$contents")
|
|
|
|
b="b"
|
|
|
|
b_oid=$(calc_oid "$b")
|
|
|
|
reponame="$(basename "$0" ".sh")"
|
|
|
|
|
|
|
|
begin_test "init for fetch tests"
|
2015-06-20 16:10:54 +00:00
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
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-06-20 16:10:54 +00:00
|
|
|
|
|
|
|
|
2018-09-10 14:57:10 +00:00
|
|
|
printf "%s" "$contents" > a.dat
|
2015-06-20 16:10:54 +00:00
|
|
|
git add a.dat
|
|
|
|
git add .gitattributes
|
|
|
|
git commit -m "add a.dat" 2>&1 | tee commit.log
|
2020-06-29 16:18:57 +00:00
|
|
|
grep "main (root-commit)" commit.log
|
2015-06-20 16:10:54 +00:00
|
|
|
grep "2 files changed" commit.log
|
|
|
|
grep "create mode 100644 a.dat" commit.log
|
|
|
|
grep "create mode 100644 .gitattributes" commit.log
|
|
|
|
|
|
|
|
[ "a" = "$(cat a.dat)" ]
|
|
|
|
|
2015-08-06 10:44:38 +00:00
|
|
|
assert_local_object "$contents_oid" 1
|
2015-06-20 16:10:54 +00:00
|
|
|
|
2015-07-06 18:19:18 +00:00
|
|
|
refute_server_object "$reponame" "$contents_oid"
|
2015-06-20 16:10:54 +00:00
|
|
|
|
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% (1/1), 1 B" push.log
|
2020-06-29 16:18:57 +00:00
|
|
|
grep "main -> main" push.log
|
2015-06-20 16:10:54 +00:00
|
|
|
|
2015-07-06 18:19:18 +00:00
|
|
|
assert_server_object "$reponame" "$contents_oid"
|
2015-06-20 16:10:54 +00:00
|
|
|
|
|
|
|
# Add a file in a different branch
|
|
|
|
git checkout -b newbranch
|
2018-09-10 14:57:10 +00:00
|
|
|
printf "%s" "$b" > b.dat
|
2015-06-20 16:10:54 +00:00
|
|
|
git add b.dat
|
|
|
|
git commit -m "add b.dat"
|
2015-08-06 10:44:38 +00:00
|
|
|
assert_local_object "$b_oid" 1
|
2015-06-20 16:10:54 +00:00
|
|
|
|
|
|
|
git push origin newbranch
|
2015-07-06 18:19:18 +00:00
|
|
|
assert_server_object "$reponame" "$b_oid"
|
2015-06-20 16:10:54 +00:00
|
|
|
|
2018-11-13 20:09:19 +00:00
|
|
|
# These clones are used for subsequent tests
|
2016-08-02 16:11:12 +00:00
|
|
|
clone_repo "$reponame" clone
|
2018-11-13 20:09:19 +00:00
|
|
|
git clone --shared "$TRASHDIR/clone" "$TRASHDIR/shared"
|
2016-08-02 16:11:12 +00:00
|
|
|
)
|
|
|
|
end_test
|
2015-06-20 16:10:54 +00:00
|
|
|
|
2016-08-02 16:11:12 +00:00
|
|
|
begin_test "fetch"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
cd clone
|
2015-06-20 16:10:54 +00:00
|
|
|
rm -rf .git/lfs/objects
|
2016-08-02 16:11:12 +00:00
|
|
|
|
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 fetch
|
2015-08-13 16:22:29 +00:00
|
|
|
assert_local_object "$contents_oid" 1
|
2018-01-30 13:05:26 +00:00
|
|
|
|
|
|
|
git lfs fsck 2>&1 | tee fsck.log
|
|
|
|
grep "Git LFS fsck OK" fsck.log
|
2016-08-02 16:11:12 +00:00
|
|
|
)
|
|
|
|
end_test
|
2015-06-20 16:10:54 +00:00
|
|
|
|
2021-09-27 12:33:22 +00:00
|
|
|
begin_test "fetch (empty file)"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
cd clone
|
|
|
|
rm -rf .git/lfs/objects
|
|
|
|
|
|
|
|
touch empty.dat
|
|
|
|
git add empty.dat
|
|
|
|
git commit -m 'empty'
|
|
|
|
|
|
|
|
git lfs fetch
|
|
|
|
|
|
|
|
git lfs fsck 2>&1 | tee fsck.log
|
|
|
|
grep "Git LFS fsck OK" fsck.log
|
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
2018-11-13 20:09:19 +00:00
|
|
|
begin_test "fetch (shared repository)"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
cd shared
|
|
|
|
rm -rf .git/lfs/objects
|
|
|
|
|
|
|
|
git lfs fetch 2>&1 | tee fetch.log
|
|
|
|
! grep "Could not scan" fetch.log
|
|
|
|
assert_local_object "$contents_oid" 1
|
|
|
|
|
|
|
|
git lfs fsck 2>&1 | tee fsck.log
|
|
|
|
grep "Git LFS fsck OK" fsck.log
|
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
2016-08-02 16:11:12 +00:00
|
|
|
begin_test "fetch with remote"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
cd clone
|
2015-08-13 16:22:29 +00:00
|
|
|
rm -rf .git/lfs/objects
|
2016-08-02 16:11:12 +00:00
|
|
|
|
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 fetch origin
|
2015-08-06 10:44:38 +00:00
|
|
|
assert_local_object "$contents_oid" 1
|
2016-08-02 16:11:12 +00:00
|
|
|
refute_local_object "$b_oid" 1
|
2018-01-30 13:05:26 +00:00
|
|
|
|
|
|
|
git lfs fsck 2>&1 | tee fsck.log
|
|
|
|
grep "Git LFS fsck OK" fsck.log
|
2016-08-02 16:11:12 +00:00
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
|
|
|
begin_test "fetch with remote and branches"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
cd clone
|
2015-06-20 16:10:54 +00:00
|
|
|
|
|
|
|
git checkout newbranch
|
2020-06-29 16:18:57 +00:00
|
|
|
git checkout main
|
2016-08-02 16:11:12 +00:00
|
|
|
|
2015-06-20 16:10:54 +00:00
|
|
|
rm -rf .git/lfs/objects
|
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
git lfs fetch origin main newbranch
|
2015-08-06 10:44:38 +00:00
|
|
|
assert_local_object "$contents_oid" 1
|
|
|
|
assert_local_object "$b_oid" 1
|
2018-01-30 13:05:26 +00:00
|
|
|
|
|
|
|
git lfs fsck 2>&1 | tee fsck.log
|
|
|
|
grep "Git LFS fsck OK" fsck.log
|
2016-08-02 16:11:12 +00:00
|
|
|
)
|
|
|
|
end_test
|
2015-08-06 13:56:57 +00:00
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
begin_test "fetch with main commit sha1"
|
2016-08-02 16:11:12 +00:00
|
|
|
(
|
|
|
|
set -e
|
|
|
|
cd clone
|
2016-06-24 09:00:53 +00:00
|
|
|
rm -rf .git/lfs/objects
|
2016-08-02 16:11:12 +00:00
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
main_sha1=$(git rev-parse main)
|
|
|
|
git lfs fetch origin "$main_sha1"
|
2016-06-24 09:00:53 +00:00
|
|
|
assert_local_object "$contents_oid" 1
|
|
|
|
refute_local_object "$b_oid" 1
|
2018-01-30 13:05:26 +00:00
|
|
|
|
|
|
|
git lfs fsck 2>&1 | tee fsck.log
|
|
|
|
grep "Git LFS fsck OK" fsck.log
|
2016-08-02 16:11:12 +00:00
|
|
|
)
|
|
|
|
end_test
|
2016-06-24 09:00:53 +00:00
|
|
|
|
2016-08-02 16:11:12 +00:00
|
|
|
begin_test "fetch with newbranch commit sha1"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
cd clone
|
2016-06-23 08:59:38 +00:00
|
|
|
rm -rf .git/lfs/objects
|
2016-08-02 16:11:12 +00:00
|
|
|
|
2016-06-23 08:59:38 +00:00
|
|
|
newbranch_sha1=$(git rev-parse newbranch)
|
|
|
|
git lfs fetch origin "$newbranch_sha1"
|
|
|
|
assert_local_object "$contents_oid" 1
|
|
|
|
assert_local_object "$b_oid" 1
|
2018-01-30 13:05:26 +00:00
|
|
|
|
|
|
|
git lfs fsck 2>&1 | tee fsck.log
|
|
|
|
grep "Git LFS fsck OK" fsck.log
|
2016-08-02 16:11:12 +00:00
|
|
|
)
|
|
|
|
end_test
|
2016-06-23 08:59:38 +00:00
|
|
|
|
2016-08-02 16:11:12 +00:00
|
|
|
begin_test "fetch with include filters in gitconfig"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
cd clone
|
2015-08-06 13:56:57 +00:00
|
|
|
rm -rf .git/lfs/objects
|
2016-08-02 16:11:12 +00:00
|
|
|
|
2015-08-06 13:56:57 +00:00
|
|
|
git config "lfs.fetchinclude" "a*"
|
2020-06-29 16:18:57 +00:00
|
|
|
git lfs fetch origin main newbranch
|
2015-08-06 13:56:57 +00:00
|
|
|
assert_local_object "$contents_oid" 1
|
|
|
|
refute_local_object "$b_oid"
|
2018-01-30 13:05:26 +00:00
|
|
|
|
|
|
|
git lfs fsck 2>&1 | tee fsck.log
|
|
|
|
grep "Git LFS fsck OK" fsck.log
|
2016-08-02 16:11:12 +00:00
|
|
|
)
|
|
|
|
end_test
|
2015-09-08 15:29:53 +00:00
|
|
|
|
2016-08-02 16:11:12 +00:00
|
|
|
begin_test "fetch with exclude filters in gitconfig"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
cd clone
|
2015-08-06 13:56:57 +00:00
|
|
|
git config --unset "lfs.fetchinclude"
|
2016-08-02 16:11:12 +00:00
|
|
|
rm -rf .git/lfs/objects
|
|
|
|
|
2015-08-06 13:56:57 +00:00
|
|
|
git config "lfs.fetchexclude" "a*"
|
2020-06-29 16:18:57 +00:00
|
|
|
git lfs fetch origin main newbranch
|
2015-08-06 13:56:57 +00:00
|
|
|
refute_local_object "$contents_oid"
|
|
|
|
assert_local_object "$b_oid" 1
|
2018-01-30 13:05:26 +00:00
|
|
|
|
|
|
|
git lfs fsck 2>&1 | tee fsck.log
|
|
|
|
grep "Git LFS fsck OK" fsck.log
|
2016-08-02 16:11:12 +00:00
|
|
|
)
|
|
|
|
end_test
|
2015-08-06 13:56:57 +00:00
|
|
|
|
2016-08-02 16:11:12 +00:00
|
|
|
begin_test "fetch with include/exclude filters in gitconfig"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
cd clone
|
2015-08-06 13:56:57 +00:00
|
|
|
rm -rf .git/lfs/objects
|
2016-08-02 16:11:12 +00:00
|
|
|
git config --unset "lfs.fetchexclude"
|
|
|
|
|
2015-08-06 13:56:57 +00:00
|
|
|
git config "lfs.fetchinclude" "a*,b*"
|
|
|
|
git config "lfs.fetchexclude" "c*,d*"
|
2020-06-29 16:18:57 +00:00
|
|
|
git lfs fetch origin main newbranch
|
2015-08-06 13:56:57 +00:00
|
|
|
assert_local_object "$contents_oid" 1
|
|
|
|
assert_local_object "$b_oid" 1
|
2015-09-08 15:29:53 +00:00
|
|
|
|
2015-08-06 13:56:57 +00:00
|
|
|
rm -rf .git/lfs/objects
|
|
|
|
git config "lfs.fetchinclude" "c*,d*"
|
|
|
|
git config "lfs.fetchexclude" "a*,b*"
|
2020-06-29 16:18:57 +00:00
|
|
|
git lfs fetch origin main newbranch
|
2015-08-06 13:56:57 +00:00
|
|
|
refute_local_object "$contents_oid"
|
|
|
|
refute_local_object "$b_oid"
|
2016-08-02 16:11:12 +00:00
|
|
|
)
|
|
|
|
end_test
|
2015-08-07 17:18:39 +00:00
|
|
|
|
2016-08-02 16:11:12 +00:00
|
|
|
begin_test "fetch with include filter in cli"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
cd clone
|
2015-08-07 17:18:39 +00:00
|
|
|
git config --unset "lfs.fetchinclude"
|
|
|
|
git config --unset "lfs.fetchexclude"
|
|
|
|
rm -rf .git/lfs/objects
|
2016-08-02 16:11:12 +00:00
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
git lfs fetch --include="a*" origin main newbranch
|
2015-08-07 17:18:39 +00:00
|
|
|
assert_local_object "$contents_oid" 1
|
|
|
|
refute_local_object "$b_oid"
|
2016-08-02 16:11:12 +00:00
|
|
|
)
|
|
|
|
end_test
|
2015-09-08 15:29:53 +00:00
|
|
|
|
2016-08-02 16:11:12 +00:00
|
|
|
begin_test "fetch with exclude filter in cli"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
cd clone
|
2015-08-07 17:18:39 +00:00
|
|
|
rm -rf .git/lfs/objects
|
2020-06-29 16:18:57 +00:00
|
|
|
git lfs fetch --exclude="a*" origin main newbranch
|
2015-08-07 17:18:39 +00:00
|
|
|
refute_local_object "$contents_oid"
|
|
|
|
assert_local_object "$b_oid" 1
|
2016-08-02 16:11:12 +00:00
|
|
|
)
|
|
|
|
end_test
|
2015-08-07 17:18:39 +00:00
|
|
|
|
2016-08-02 16:11:12 +00:00
|
|
|
begin_test "fetch with include/exclude filters in cli"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
cd clone
|
2015-08-07 17:18:39 +00:00
|
|
|
rm -rf .git/lfs/objects
|
2020-06-29 16:18:57 +00:00
|
|
|
git lfs fetch -I "a*,b*" -X "c*,d*" origin main newbranch
|
2015-08-07 17:18:39 +00:00
|
|
|
assert_local_object "$contents_oid" 1
|
|
|
|
assert_local_object "$b_oid" 1
|
2015-09-08 15:29:53 +00:00
|
|
|
|
2015-08-07 17:18:39 +00:00
|
|
|
rm -rf .git/lfs/objects
|
2020-06-29 16:18:57 +00:00
|
|
|
git lfs fetch --include="c*,d*" --exclude="a*,b*" origin main newbranch
|
2015-08-07 17:18:39 +00:00
|
|
|
refute_local_object "$contents_oid"
|
|
|
|
refute_local_object "$b_oid"
|
2016-08-02 16:11:12 +00:00
|
|
|
)
|
|
|
|
end_test
|
2015-10-13 14:29:25 +00:00
|
|
|
|
2016-08-02 16:11:12 +00:00
|
|
|
begin_test "fetch with include filter overriding exclude filter"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
cd clone
|
2016-08-01 22:47:41 +00:00
|
|
|
rm -rf .git/lfs/objects
|
|
|
|
git config lfs.fetchexclude "b*"
|
2020-06-29 16:18:57 +00:00
|
|
|
git lfs fetch -I "b.dat" -X "" origin main newbranch
|
2016-08-01 22:47:41 +00:00
|
|
|
assert_local_object "$b_oid" "1"
|
2016-08-02 16:11:12 +00:00
|
|
|
)
|
|
|
|
end_test
|
2016-08-01 22:47:41 +00:00
|
|
|
|
2016-08-02 16:11:12 +00:00
|
|
|
begin_test "fetch with missing object"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
cd clone
|
|
|
|
git config --unset lfs.fetchexclude
|
2015-10-13 14:29:25 +00:00
|
|
|
rm -rf .git/lfs/objects
|
2016-08-02 16:11:12 +00:00
|
|
|
|
2015-10-13 14:29:25 +00:00
|
|
|
delete_server_object "$reponame" "$b_oid"
|
|
|
|
refute_server_object "$reponame" "$b_oid"
|
2016-08-02 16:11:12 +00:00
|
|
|
|
2015-10-13 14:29:25 +00:00
|
|
|
# should return non-zero, but should also download all the other valid files too
|
|
|
|
set +e
|
2020-06-29 16:18:57 +00:00
|
|
|
git lfs fetch origin main newbranch
|
2015-10-13 14:29:25 +00:00
|
|
|
fetch_exit=$?
|
|
|
|
set -e
|
|
|
|
[ "$fetch_exit" != "0" ]
|
|
|
|
assert_local_object "$contents_oid" 1
|
|
|
|
refute_local_object "$b_oid"
|
2015-08-24 16:54:56 +00:00
|
|
|
)
|
|
|
|
end_test
|
2015-09-04 12:07:30 +00:00
|
|
|
|
|
|
|
begin_test "fetch-all"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="fetch-all"
|
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
|
|
|
|
clone_repo "$reponame" "$reponame"
|
|
|
|
|
|
|
|
git lfs track "*.dat" 2>&1 | tee track.log
|
2017-03-24 16:59:03 +00:00
|
|
|
grep "Tracking \"\*.dat\"" track.log
|
2015-09-04 12:07:30 +00:00
|
|
|
|
|
|
|
NUMFILES=12
|
|
|
|
# generate content we'll use
|
|
|
|
for ((a=0; a < NUMFILES ; a++))
|
|
|
|
do
|
|
|
|
content[$a]="filecontent$a"
|
2015-09-21 17:50:22 +00:00
|
|
|
oid[$a]=$(calc_oid "${content[$a]}")
|
2015-09-04 12:07:30 +00:00
|
|
|
done
|
2015-09-08 15:29:53 +00:00
|
|
|
|
2015-09-04 12:07:30 +00:00
|
|
|
echo "[
|
|
|
|
{
|
|
|
|
\"CommitDate\":\"$(get_date -180d)\",
|
|
|
|
\"Files\":[
|
|
|
|
{\"Filename\":\"file1.dat\",\"Size\":${#content[0]}, \"Data\":\"${content[0]}\"},
|
|
|
|
{\"Filename\":\"file2.dat\",\"Size\":${#content[1]}, \"Data\":\"${content[1]}\"}]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
\"NewBranch\":\"branch1\",
|
|
|
|
\"CommitDate\":\"$(get_date -140d)\",
|
|
|
|
\"Files\":[
|
|
|
|
{\"Filename\":\"file3.dat\",\"Size\":${#content[2]}, \"Data\":\"${content[2]}\"}]
|
|
|
|
},
|
|
|
|
{
|
2020-06-29 16:18:57 +00:00
|
|
|
\"ParentBranches\":[\"main\"],
|
2015-09-04 12:07:30 +00:00
|
|
|
\"CommitDate\":\"$(get_date -100d)\",
|
|
|
|
\"Files\":[
|
|
|
|
{\"Filename\":\"file1.dat\",\"Size\":${#content[3]}, \"Data\":\"${content[3]}\"}]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
\"NewBranch\":\"remote_branch_only\",
|
|
|
|
\"CommitDate\":\"$(get_date -80d)\",
|
|
|
|
\"Files\":[
|
|
|
|
{\"Filename\":\"file2.dat\",\"Size\":${#content[4]}, \"Data\":\"${content[4]}\"}]
|
|
|
|
},
|
|
|
|
{
|
2020-06-29 16:18:57 +00:00
|
|
|
\"ParentBranches\":[\"main\"],
|
2015-09-04 12:07:30 +00:00
|
|
|
\"CommitDate\":\"$(get_date -75d)\",
|
|
|
|
\"Files\":[
|
|
|
|
{\"Filename\":\"file4.dat\",\"Size\":${#content[5]}, \"Data\":\"${content[5]}\"}]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
\"NewBranch\":\"tag_only\",
|
|
|
|
\"Tags\":[\"tag1\"],
|
|
|
|
\"CommitDate\":\"$(get_date -70d)\",
|
|
|
|
\"Files\":[
|
|
|
|
{\"Filename\":\"file4.dat\",\"Size\":${#content[6]}, \"Data\":\"${content[6]}\"}]
|
|
|
|
},
|
|
|
|
{
|
2020-06-29 16:18:57 +00:00
|
|
|
\"ParentBranches\":[\"main\"],
|
2015-09-04 12:07:30 +00:00
|
|
|
\"CommitDate\":\"$(get_date -60d)\",
|
|
|
|
\"Files\":[
|
|
|
|
{\"Filename\":\"file1.dat\",\"Size\":${#content[7]}, \"Data\":\"${content[7]}\"}]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
\"NewBranch\":\"branch3\",
|
|
|
|
\"CommitDate\":\"$(get_date -50d)\",
|
|
|
|
\"Files\":[
|
|
|
|
{\"Filename\":\"file4.dat\",\"Size\":${#content[8]}, \"Data\":\"${content[8]}\"}]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
\"CommitDate\":\"$(get_date -40d)\",
|
2020-06-29 16:18:57 +00:00
|
|
|
\"ParentBranches\":[\"main\"],
|
2015-09-04 12:07:30 +00:00
|
|
|
\"Files\":[
|
|
|
|
{\"Filename\":\"file1.dat\",\"Size\":${#content[9]}, \"Data\":\"${content[9]}\"},
|
|
|
|
{\"Filename\":\"file2.dat\",\"Size\":${#content[10]}, \"Data\":\"${content[10]}\"}]
|
|
|
|
},
|
|
|
|
{
|
2020-06-29 16:18:57 +00:00
|
|
|
\"ParentBranches\":[\"main\"],
|
2015-09-04 12:07:30 +00:00
|
|
|
\"CommitDate\":\"$(get_date -30d)\",
|
|
|
|
\"Files\":[
|
|
|
|
{\"Filename\":\"file4.dat\",\"Size\":${#content[11]}, \"Data\":\"${content[11]}\"}]
|
|
|
|
}
|
|
|
|
]" | lfstest-testutils addcommits
|
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
git push origin main
|
2015-09-08 15:29:53 +00:00
|
|
|
git push origin branch1
|
2015-09-04 12:07:30 +00:00
|
|
|
git push origin branch3
|
2015-09-08 15:29:53 +00:00
|
|
|
git push origin remote_branch_only
|
2015-09-04 12:07:30 +00:00
|
|
|
git push origin tag_only
|
2019-10-12 23:46:08 +00:00
|
|
|
git push origin tag1
|
2015-09-04 12:07:30 +00:00
|
|
|
for ((a=0; a < NUMFILES ; a++))
|
|
|
|
do
|
|
|
|
assert_server_object "$reponame" "${oid[$a]}"
|
|
|
|
done
|
|
|
|
|
|
|
|
# delete remote_branch_only and make sure that objects are downloaded even
|
|
|
|
# though not checked out to a local branch (full backup always)
|
|
|
|
git branch -D remote_branch_only
|
|
|
|
|
|
|
|
# delete tag_only to make sure objects are downloaded when only reachable from tag
|
|
|
|
git branch -D tag_only
|
|
|
|
|
|
|
|
rm -rf .git/lfs/objects
|
|
|
|
|
|
|
|
git lfs fetch --all origin
|
|
|
|
for ((a=0; a < NUMFILES ; a++))
|
|
|
|
do
|
|
|
|
assert_local_object "${oid[$a]}" "${#content[$a]}"
|
|
|
|
done
|
|
|
|
|
2019-10-12 23:46:08 +00:00
|
|
|
rm -rf .git/lfs/objects
|
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
# fetch all objects reachable from the main branch only
|
|
|
|
git lfs fetch --all origin main
|
2019-10-12 23:46:08 +00:00
|
|
|
for a in 0 1 3 5 7 9 10 11
|
|
|
|
do
|
|
|
|
assert_local_object "${oid[$a]}" "${#content[$a]}"
|
|
|
|
done
|
|
|
|
for a in 2 4 6 8
|
|
|
|
do
|
|
|
|
refute_local_object "${oid[$a]}"
|
|
|
|
done
|
|
|
|
|
|
|
|
rm -rf .git/lfs/objects
|
|
|
|
|
|
|
|
# fetch all objects reachable from branch1 and tag1 only
|
|
|
|
git lfs fetch --all origin branch1 tag1
|
|
|
|
for a in 0 1 2 3 5 6
|
|
|
|
do
|
|
|
|
assert_local_object "${oid[$a]}" "${#content[$a]}"
|
|
|
|
done
|
|
|
|
for a in 4 7 8 9 10 11
|
|
|
|
do
|
|
|
|
refute_local_object "${oid[$a]}"
|
|
|
|
done
|
|
|
|
|
2016-06-16 16:15:11 +00:00
|
|
|
# Make a bare clone of the repository
|
|
|
|
cd ..
|
|
|
|
git clone --bare "$GITSERVER/$reponame" "$reponame-bare"
|
|
|
|
cd "$reponame-bare"
|
|
|
|
|
2022-01-05 06:49:08 +00:00
|
|
|
# Perform the same assertion as above, on the same data
|
2016-06-16 16:15:11 +00:00
|
|
|
git lfs fetch --all origin
|
2019-10-12 23:10:50 +00:00
|
|
|
for ((a=0; a < NUMFILES ; a++))
|
|
|
|
do
|
2016-06-16 16:15:11 +00:00
|
|
|
assert_local_object "${oid[$a]}" "${#content[$a]}"
|
|
|
|
done
|
2019-10-12 23:46:08 +00:00
|
|
|
|
|
|
|
rm -rf lfs/objects
|
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
# fetch all objects reachable from the main branch only
|
|
|
|
git lfs fetch --all origin main
|
2019-10-12 23:46:08 +00:00
|
|
|
for a in 0 1 3 5 7 9 10 11
|
|
|
|
do
|
|
|
|
assert_local_object "${oid[$a]}" "${#content[$a]}"
|
|
|
|
done
|
|
|
|
for a in 2 4 6 8
|
|
|
|
do
|
|
|
|
refute_local_object "${oid[$a]}"
|
|
|
|
done
|
|
|
|
|
|
|
|
rm -rf lfs/objects
|
|
|
|
|
|
|
|
# fetch all objects reachable from branch1 and tag1 only
|
|
|
|
git lfs fetch --all origin branch1 tag1
|
|
|
|
for a in 0 1 2 3 5 6
|
|
|
|
do
|
|
|
|
assert_local_object "${oid[$a]}" "${#content[$a]}"
|
|
|
|
done
|
|
|
|
for a in 4 7 8 9 10 11
|
|
|
|
do
|
|
|
|
refute_local_object "${oid[$a]}"
|
|
|
|
done
|
2015-09-04 12:07:30 +00:00
|
|
|
)
|
|
|
|
end_test
|
2015-09-08 15:29:53 +00:00
|
|
|
|
|
|
|
begin_test "fetch: outside git repository"
|
|
|
|
(
|
2015-09-08 16:20:52 +00:00
|
|
|
set +e
|
|
|
|
git lfs fetch 2>&1 > fetch.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" fetch.log
|
2015-09-08 15:29:53 +00:00
|
|
|
)
|
|
|
|
end_test
|
2015-10-06 16:27:36 +00:00
|
|
|
|
|
|
|
begin_test "fetch with no origin remote"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="fetch-no-remote"
|
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
|
|
|
|
clone_repo "$reponame" no-remote-clone
|
|
|
|
|
|
|
|
clone_repo "$reponame" no-remote-repo
|
|
|
|
|
|
|
|
git lfs track "*.dat" 2>&1 | tee track.log
|
2017-03-24 16:59:03 +00:00
|
|
|
grep "Tracking \"\*.dat\"" track.log
|
2015-10-06 16:27:36 +00:00
|
|
|
|
|
|
|
contents="a"
|
|
|
|
contents_oid=$(calc_oid "$contents")
|
|
|
|
|
2018-09-10 14:57:10 +00:00
|
|
|
printf "%s" "$contents" > a.dat
|
2015-10-06 16:27:36 +00:00
|
|
|
git add a.dat
|
|
|
|
git add .gitattributes
|
|
|
|
git commit -m "add a.dat" 2>&1 | tee commit.log
|
2020-06-29 16:18:57 +00:00
|
|
|
grep "main (root-commit)" commit.log
|
2015-10-06 16:27:36 +00:00
|
|
|
grep "2 files changed" commit.log
|
|
|
|
grep "create mode 100644 a.dat" commit.log
|
|
|
|
grep "create mode 100644 .gitattributes" commit.log
|
|
|
|
|
|
|
|
[ "a" = "$(cat a.dat)" ]
|
|
|
|
|
|
|
|
assert_local_object "$contents_oid" 1
|
|
|
|
|
|
|
|
refute_server_object "$reponame" "$contents_oid"
|
|
|
|
|
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% (1/1), 1 B" push.log
|
2020-06-29 16:18:57 +00:00
|
|
|
grep "main -> main" push.log
|
2015-10-06 16:27:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
# change to the clone's working directory
|
|
|
|
cd ../no-remote-clone
|
|
|
|
|
|
|
|
# pull commits & lfs
|
2020-06-29 16:18:57 +00:00
|
|
|
git pull origin main 2>&1
|
2015-10-06 16:27:36 +00:00
|
|
|
assert_local_object "$contents_oid" 1
|
|
|
|
|
|
|
|
# now checkout detached HEAD so we're not tracking anything on remote
|
|
|
|
git checkout --detach
|
|
|
|
|
|
|
|
# delete lfs
|
|
|
|
rm -rf .git/lfs
|
|
|
|
|
|
|
|
# rename remote from 'origin' to 'something'
|
|
|
|
git remote rename origin something
|
|
|
|
|
|
|
|
# fetch should still pick this remote as in the case of no tracked remote,
|
|
|
|
# and no origin, but only 1 remote, should pick the only one as default
|
|
|
|
git lfs fetch
|
|
|
|
assert_local_object "$contents_oid" 1
|
2015-11-09 17:46:29 +00:00
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
2015-10-15 15:35:26 +00:00
|
|
|
begin_test "fetch --prune"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="fetch_prune"
|
|
|
|
setup_remote_repo "remote_$reponame"
|
|
|
|
|
|
|
|
clone_repo "remote_$reponame" "clone_$reponame"
|
|
|
|
|
|
|
|
git lfs track "*.dat" 2>&1 | tee track.log
|
2017-03-24 16:59:03 +00:00
|
|
|
grep "Tracking \"\*.dat\"" track.log
|
2015-10-15 15:35:26 +00:00
|
|
|
|
|
|
|
content_head="HEAD content"
|
|
|
|
content_commit2="Content for commit 2 (prune)"
|
|
|
|
content_commit1="Content for commit 1 (prune)"
|
|
|
|
oid_head=$(calc_oid "$content_head")
|
|
|
|
oid_commit2=$(calc_oid "$content_commit2")
|
|
|
|
oid_commit1=$(calc_oid "$content_commit1")
|
|
|
|
|
|
|
|
echo "[
|
|
|
|
{
|
|
|
|
\"CommitDate\":\"$(get_date -50d)\",
|
|
|
|
\"Files\":[
|
|
|
|
{\"Filename\":\"file.dat\",\"Size\":${#content_commit1}, \"Data\":\"$content_commit1\"}]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
\"CommitDate\":\"$(get_date -35d)\",
|
|
|
|
\"Files\":[
|
|
|
|
{\"Filename\":\"file.dat\",\"Size\":${#content_commit2}, \"Data\":\"$content_commit2\"}]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
\"CommitDate\":\"$(get_date -25d)\",
|
|
|
|
\"Files\":[
|
|
|
|
{\"Filename\":\"file.dat\",\"Size\":${#content_head}, \"Data\":\"$content_head\"}]
|
|
|
|
}
|
|
|
|
]" | lfstest-testutils addcommits
|
2015-10-06 16:40:05 +00:00
|
|
|
|
2015-10-15 15:35:26 +00:00
|
|
|
# push all so no unpushed reason to not prune
|
2020-06-29 16:18:57 +00:00
|
|
|
git push origin main
|
2015-10-15 15:35:26 +00:00
|
|
|
|
|
|
|
# set no recents so max ability to prune
|
|
|
|
git config lfs.fetchrecentrefsdays 0
|
2015-11-09 17:46:29 +00:00
|
|
|
git config lfs.fetchrecentcommitsdays 0
|
2015-10-06 16:40:05 +00:00
|
|
|
|
2015-10-15 15:35:26 +00:00
|
|
|
# delete HEAD object to prove that we still download something
|
|
|
|
# also prune at the same time which will remove anything other than HEAD
|
|
|
|
delete_local_object "$oid_head"
|
|
|
|
git lfs fetch --prune
|
|
|
|
assert_local_object "$oid_head" "${#content_head}"
|
|
|
|
refute_local_object "$oid_commit1"
|
|
|
|
refute_local_object "$oid_commit2"
|
2015-10-06 16:27:36 +00:00
|
|
|
)
|
|
|
|
end_test
|
2016-02-03 20:06:05 +00:00
|
|
|
|
2016-08-15 21:11:05 +00:00
|
|
|
begin_test "fetch raw remote url"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
mkdir raw
|
|
|
|
cd raw
|
|
|
|
git init
|
|
|
|
git lfs install --local --skip-smudge
|
|
|
|
|
2018-07-11 21:56:18 +00:00
|
|
|
git remote add origin "$GITSERVER/$reponame"
|
2020-06-29 16:18:57 +00:00
|
|
|
git pull origin main
|
2016-08-15 21:11:05 +00:00
|
|
|
|
|
|
|
# LFS object not downloaded, pointer in working directory
|
|
|
|
refute_local_object "$contents_oid"
|
2016-08-16 18:08:37 +00:00
|
|
|
grep "$content_oid" a.dat
|
2016-08-15 21:11:05 +00:00
|
|
|
|
2018-07-11 21:56:18 +00:00
|
|
|
git lfs fetch "$GITSERVER/$reponame"
|
2016-08-15 21:11:05 +00:00
|
|
|
|
|
|
|
# LFS object downloaded, pointer still in working directory
|
|
|
|
assert_local_object "$contents_oid" 1
|
|
|
|
grep "$content_oid" a.dat
|
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
2016-02-03 20:06:05 +00:00
|
|
|
begin_test "fetch with invalid remote"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
cd repo
|
|
|
|
git lfs fetch not-a-remote 2>&1 | tee fetch.log
|
|
|
|
grep "Invalid remote name" fetch.log
|
|
|
|
)
|
|
|
|
end_test
|
2020-02-10 15:52:15 +00:00
|
|
|
|
|
|
|
begin_test "fetch fails when LFS directory has wrong permissions"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# Windows lacks POSIX permissions.
|
|
|
|
[ "$IS_WINDOWS" -eq 1 ] && exit 0
|
|
|
|
|
|
|
|
# Root is exempt from permissions.
|
|
|
|
[ "$(id -u)" -eq 0 ] && exit 0
|
|
|
|
|
|
|
|
cd shared
|
|
|
|
rm -rf .git/lfs/objects
|
|
|
|
mkdir .git/lfs/objects
|
|
|
|
chmod 400 .git/lfs/objects
|
|
|
|
|
|
|
|
git lfs fetch 2>&1 | tee fetch.log
|
|
|
|
grep "error trying to create local storage directory" fetch.log
|
|
|
|
)
|
|
|
|
end_test
|