2015-07-30 02:37:31 +00:00
|
|
|
#!/usr/bin/env bash
|
2015-06-20 16:10:54 +00:00
|
|
|
|
|
|
|
. "test/testlib.sh"
|
|
|
|
|
|
|
|
begin_test "fetch"
|
|
|
|
(
|
|
|
|
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
|
|
|
|
grep "Tracking \*.dat" track.log
|
|
|
|
|
|
|
|
contents="a"
|
|
|
|
contents_oid=$(printf "$contents" | shasum -a 256 | cut -f 1 -d " ")
|
|
|
|
|
|
|
|
printf "$contents" > a.dat
|
|
|
|
git add a.dat
|
|
|
|
git add .gitattributes
|
|
|
|
git commit -m "add a.dat" 2>&1 | tee commit.log
|
|
|
|
grep "master (root-commit)" commit.log
|
|
|
|
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
|
|
|
|
|
|
|
git push origin master 2>&1 | tee push.log
|
|
|
|
grep "(1 of 1 files)" push.log
|
|
|
|
grep "master -> master" push.log
|
|
|
|
|
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
|
|
|
|
b="b"
|
|
|
|
b_oid=$(printf "$b" | shasum -a 256 | cut -f 1 -d " ")
|
|
|
|
printf "$b" > b.dat
|
|
|
|
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
|
|
|
|
|
|
|
# change to the clone's working directory
|
|
|
|
cd ../clone
|
|
|
|
|
|
|
|
git pull 2>&1 | grep "Downloading a.dat (1 B)"
|
|
|
|
|
|
|
|
[ "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
|
|
|
|
|
|
|
|
|
|
|
# Remove the working directory and lfs files
|
|
|
|
rm -rf .git/lfs/objects
|
|
|
|
git lfs fetch 2>&1 | grep "(1 of 1 files)"
|
2015-08-13 16:22:29 +00:00
|
|
|
assert_local_object "$contents_oid" 1
|
2015-06-20 16:10:54 +00:00
|
|
|
|
2015-08-13 16:22:29 +00:00
|
|
|
# test with just remote specified
|
|
|
|
rm -rf .git/lfs/objects
|
|
|
|
git lfs fetch origin 2>&1 | grep "(1 of 1 files)"
|
2015-08-06 10:44:38 +00:00
|
|
|
assert_local_object "$contents_oid" 1
|
2015-06-20 16:10:54 +00:00
|
|
|
|
|
|
|
git checkout newbranch
|
|
|
|
git checkout master
|
|
|
|
rm -rf .git/lfs/objects
|
|
|
|
|
2015-08-13 16:22:29 +00:00
|
|
|
git lfs fetch origin master newbranch
|
2015-08-06 10:44:38 +00:00
|
|
|
assert_local_object "$contents_oid" 1
|
|
|
|
assert_local_object "$b_oid" 1
|
2015-08-06 13:56:57 +00:00
|
|
|
|
2015-08-07 17:18:39 +00:00
|
|
|
# Test include / exclude filters supplied in gitconfig
|
2015-08-06 13:56:57 +00:00
|
|
|
rm -rf .git/lfs/objects
|
|
|
|
git config "lfs.fetchinclude" "a*"
|
2015-08-13 16:22:29 +00:00
|
|
|
git lfs fetch origin master newbranch
|
2015-08-06 13:56:57 +00:00
|
|
|
assert_local_object "$contents_oid" 1
|
|
|
|
refute_local_object "$b_oid"
|
2015-07-29 15:34:15 +00:00
|
|
|
|
2015-08-06 13:56:57 +00:00
|
|
|
rm -rf .git/lfs/objects
|
|
|
|
git config --unset "lfs.fetchinclude"
|
|
|
|
git config "lfs.fetchexclude" "a*"
|
2015-08-13 16:22:29 +00:00
|
|
|
git lfs fetch origin master newbranch
|
2015-08-06 13:56:57 +00:00
|
|
|
refute_local_object "$contents_oid"
|
|
|
|
assert_local_object "$b_oid" 1
|
|
|
|
|
|
|
|
rm -rf .git/lfs/objects
|
|
|
|
git config "lfs.fetchinclude" "a*,b*"
|
|
|
|
git config "lfs.fetchexclude" "c*,d*"
|
2015-08-13 16:22:29 +00:00
|
|
|
git lfs fetch origin master newbranch
|
2015-08-06 13:56:57 +00:00
|
|
|
assert_local_object "$contents_oid" 1
|
|
|
|
assert_local_object "$b_oid" 1
|
|
|
|
|
|
|
|
rm -rf .git/lfs/objects
|
|
|
|
git config "lfs.fetchinclude" "c*,d*"
|
|
|
|
git config "lfs.fetchexclude" "a*,b*"
|
2015-08-13 16:22:29 +00:00
|
|
|
git lfs fetch origin master newbranch
|
2015-08-06 13:56:57 +00:00
|
|
|
refute_local_object "$contents_oid"
|
|
|
|
refute_local_object "$b_oid"
|
2015-08-07 17:18:39 +00:00
|
|
|
|
|
|
|
# Test include / exclude filters supplied on the command line
|
|
|
|
git config --unset "lfs.fetchinclude"
|
|
|
|
git config --unset "lfs.fetchexclude"
|
|
|
|
rm -rf .git/lfs/objects
|
2015-08-13 16:22:29 +00:00
|
|
|
git lfs fetch --include="a*" origin master newbranch
|
2015-08-07 17:18:39 +00:00
|
|
|
assert_local_object "$contents_oid" 1
|
|
|
|
refute_local_object "$b_oid"
|
|
|
|
|
|
|
|
rm -rf .git/lfs/objects
|
2015-08-13 16:22:29 +00:00
|
|
|
git lfs fetch --exclude="a*" origin master newbranch
|
2015-08-07 17:18:39 +00:00
|
|
|
refute_local_object "$contents_oid"
|
|
|
|
assert_local_object "$b_oid" 1
|
|
|
|
|
|
|
|
rm -rf .git/lfs/objects
|
2015-08-13 16:22:29 +00:00
|
|
|
git lfs fetch -I "a*,b*" -X "c*,d*" origin master newbranch
|
2015-08-07 17:18:39 +00:00
|
|
|
assert_local_object "$contents_oid" 1
|
|
|
|
assert_local_object "$b_oid" 1
|
|
|
|
|
|
|
|
rm -rf .git/lfs/objects
|
2015-08-13 16:22:29 +00:00
|
|
|
git lfs fetch --include="c*,d*" --exclude="a*,b*" origin master newbranch
|
2015-08-07 17:18:39 +00:00
|
|
|
refute_local_object "$contents_oid"
|
|
|
|
refute_local_object "$b_oid"
|
2015-06-20 16:10:54 +00:00
|
|
|
)
|
|
|
|
end_test
|
2015-08-24 16:54:56 +00:00
|
|
|
|
|
|
|
begin_test "fetch-recent"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="fetch-recent"
|
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
|
|
|
|
clone_repo "$reponame" "$reponame"
|
|
|
|
|
2015-08-25 15:57:28 +00:00
|
|
|
git lfs track "*.dat" 2>&1 | tee track.log
|
|
|
|
grep "Tracking \*.dat" track.log
|
2015-08-24 16:54:56 +00:00
|
|
|
|
2015-08-25 15:57:28 +00:00
|
|
|
# generate content we'll use
|
2015-08-27 14:31:58 +00:00
|
|
|
content0="filecontent0"
|
2015-08-25 15:57:28 +00:00
|
|
|
content1="filecontent1"
|
|
|
|
content2="filecontent2"
|
|
|
|
content3="filecontent3"
|
|
|
|
content4="filecontent4"
|
2015-08-28 15:09:22 +00:00
|
|
|
content5="filecontent5"
|
2015-08-27 14:31:58 +00:00
|
|
|
oid0=$(printf "$content0" | shasum -a 256 | cut -f 1 -d " ")
|
2015-08-25 15:57:28 +00:00
|
|
|
oid1=$(printf "$content1" | shasum -a 256 | cut -f 1 -d " ")
|
|
|
|
oid2=$(printf "$content2" | shasum -a 256 | cut -f 1 -d " ")
|
|
|
|
oid3=$(printf "$content3" | shasum -a 256 | cut -f 1 -d " ")
|
|
|
|
oid4=$(printf "$content4" | shasum -a 256 | cut -f 1 -d " ")
|
2015-08-28 15:09:22 +00:00
|
|
|
oid5=$(printf "$content5" | shasum -a 256 | cut -f 1 -d " ")
|
2015-08-25 15:57:28 +00:00
|
|
|
|
|
|
|
echo "[
|
|
|
|
{
|
2015-08-27 14:31:58 +00:00
|
|
|
\"CommitDate\":\"$(get_date -18d)\",
|
2015-08-25 15:57:28 +00:00
|
|
|
\"Files\":[
|
2015-08-28 15:09:22 +00:00
|
|
|
{\"Filename\":\"file1.dat\",\"Size\":${#content0}, \"Data\":\"$content0\"},
|
|
|
|
{\"Filename\":\"file3.dat\",\"Size\":${#content5}, \"Data\":\"$content5\"}]
|
2015-08-25 15:57:28 +00:00
|
|
|
},
|
|
|
|
{
|
2015-08-27 14:31:58 +00:00
|
|
|
\"CommitDate\":\"$(get_date -14d)\",
|
2015-08-25 15:57:28 +00:00
|
|
|
\"Files\":[
|
|
|
|
{\"Filename\":\"file1.dat\",\"Size\":${#content1}, \"Data\":\"$content1\"}]
|
|
|
|
},
|
|
|
|
{
|
2015-08-26 15:23:09 +00:00
|
|
|
\"CommitDate\":\"$(get_date -5d)\",
|
2015-08-25 15:57:28 +00:00
|
|
|
\"NewBranch\":\"other_branch\",
|
|
|
|
\"Files\":[
|
|
|
|
{\"Filename\":\"file1.dat\",\"Size\":${#content4}, \"Data\":\"$content4\"}]
|
|
|
|
},
|
|
|
|
{
|
2015-08-26 15:23:09 +00:00
|
|
|
\"CommitDate\":\"$(get_date -1d)\",
|
2015-08-25 15:57:28 +00:00
|
|
|
\"ParentBranches\":[\"master\"],
|
|
|
|
\"Files\":[
|
|
|
|
{\"Filename\":\"file1.dat\",\"Size\":${#content2}, \"Data\":\"$content2\"},
|
|
|
|
{\"Filename\":\"file2.dat\",\"Size\":${#content3}, \"Data\":\"$content3\"}]
|
|
|
|
}
|
|
|
|
]" | lfstest-testutils addcommits
|
|
|
|
|
2015-09-01 11:06:30 +00:00
|
|
|
git push origin master
|
|
|
|
git push origin other_branch
|
2015-08-27 14:31:58 +00:00
|
|
|
assert_server_object "$reponame" "$oid0"
|
2015-08-25 15:57:28 +00:00
|
|
|
assert_server_object "$reponame" "$oid1"
|
|
|
|
assert_server_object "$reponame" "$oid2"
|
|
|
|
assert_server_object "$reponame" "$oid3"
|
|
|
|
assert_server_object "$reponame" "$oid4"
|
|
|
|
|
2015-08-26 15:23:09 +00:00
|
|
|
rm -rf .git/lfs/objects
|
|
|
|
|
|
|
|
git config lfs.fetchrecentalways false
|
|
|
|
git config lfs.fetchrecentrefsdays 0
|
|
|
|
git config lfs.fetchrecentremoterefs false
|
|
|
|
git config lfs.fetchrecentcommitsdays 7
|
|
|
|
|
|
|
|
# fetch normally, should just get the last state for file1/2
|
|
|
|
git lfs fetch origin master
|
|
|
|
assert_local_object "$oid2" "${#content2}"
|
|
|
|
assert_local_object "$oid3" "${#content3}"
|
2015-08-28 15:09:22 +00:00
|
|
|
assert_local_object "$oid5" "${#content5}"
|
2015-08-27 14:31:58 +00:00
|
|
|
refute_local_object "$oid0"
|
2015-08-26 15:23:09 +00:00
|
|
|
refute_local_object "$oid1"
|
|
|
|
refute_local_object "$oid4"
|
|
|
|
|
|
|
|
rm -rf .git/lfs/objects
|
|
|
|
|
|
|
|
# now fetch recent - just commits for now
|
|
|
|
git config lfs.fetchrecentrefsdays 0
|
|
|
|
git config lfs.fetchrecentremoterefs false
|
|
|
|
git config lfs.fetchrecentcommitsdays 7
|
2015-08-27 14:31:58 +00:00
|
|
|
|
2015-08-26 15:23:09 +00:00
|
|
|
git lfs fetch --recent origin
|
|
|
|
# that should have fetched master plus previous state needed within 7 days
|
|
|
|
# current state
|
|
|
|
assert_local_object "$oid2" "${#content2}"
|
|
|
|
assert_local_object "$oid3" "${#content3}"
|
|
|
|
# previous state is the 'before' state of any commits made in last 7 days
|
|
|
|
# ie you can check out anything in last 7 days (may have non-LFS commits in between)
|
|
|
|
assert_local_object "$oid1" "${#content1}"
|
2015-08-27 14:31:58 +00:00
|
|
|
refute_local_object "$oid0"
|
|
|
|
refute_local_object "$oid4"
|
|
|
|
|
|
|
|
rm -rf .git/lfs/objects
|
|
|
|
# now fetch other_branch as well
|
|
|
|
git config lfs.fetchrecentrefsdays 6
|
|
|
|
git config lfs.fetchrecentremoterefs false
|
|
|
|
git config lfs.fetchrecentcommitsdays 7
|
|
|
|
|
|
|
|
git lfs fetch --recent origin
|
|
|
|
# that should have fetched master plus previous state needed within 7 days
|
|
|
|
# current state PLUS refs within 6 days (& their commits within 7)
|
|
|
|
assert_local_object "$oid2" "${#content2}"
|
|
|
|
assert_local_object "$oid3" "${#content3}"
|
|
|
|
assert_local_object "$oid1" "${#content1}"
|
|
|
|
assert_local_object "$oid4" "${#content4}"
|
|
|
|
# still omits oid0 since that's at best 13 days prior to other_branch tip
|
|
|
|
refute_local_object "$oid0"
|
2015-08-26 15:23:09 +00:00
|
|
|
|
2015-08-27 14:31:58 +00:00
|
|
|
# now test that a 14 day limit picks oid0 up from other_branch
|
|
|
|
# because other_branch was itself 5 days ago, 5+14=19 day search limit
|
|
|
|
git config lfs.fetchrecentcommitsdays 14
|
|
|
|
|
|
|
|
git lfs fetch --recent origin
|
|
|
|
assert_local_object "$oid0" "${#content0}"
|
2015-08-26 15:23:09 +00:00
|
|
|
|
2015-08-27 16:09:40 +00:00
|
|
|
# push branch & test remote branch recent
|
|
|
|
git push origin other_branch
|
|
|
|
git branch -D other_branch
|
2015-08-25 15:57:28 +00:00
|
|
|
|
2015-08-27 16:09:40 +00:00
|
|
|
rm -rf .git/lfs/objects
|
|
|
|
git config lfs.fetchrecentcommitsdays 0
|
|
|
|
git config lfs.fetchrecentremoterefs false
|
|
|
|
git config lfs.fetchrecentrefsdays 6
|
|
|
|
git lfs fetch --recent origin
|
|
|
|
# should miss #4 until we include remote branches (#1 will always be missing commitdays=0)
|
|
|
|
assert_local_object "$oid2" "${#content2}"
|
|
|
|
assert_local_object "$oid3" "${#content3}"
|
|
|
|
refute_local_object "$oid1"
|
|
|
|
refute_local_object "$oid0"
|
|
|
|
refute_local_object "$oid4"
|
|
|
|
# pick up just snapshot at remote ref, ie #4
|
|
|
|
git config lfs.fetchrecentremoterefs true
|
|
|
|
git lfs fetch --recent origin
|
|
|
|
assert_local_object "$oid4" "${#content4}"
|
|
|
|
refute_local_object "$oid0"
|
|
|
|
refute_local_object "$oid1"
|
2015-08-24 16:54:56 +00:00
|
|
|
|
|
|
|
)
|
|
|
|
end_test
|