2015-07-30 02:37:31 +00:00
|
|
|
#!/usr/bin/env bash
|
2015-05-19 22:54:15 +00:00
|
|
|
# This is a sample Git LFS test. See test/README.md and testhelpers.sh for
|
|
|
|
# more documentation.
|
2015-05-14 17:56:05 +00:00
|
|
|
|
2018-07-10 18:48:02 +00:00
|
|
|
. "$(dirname "$0")/testlib.sh"
|
2015-05-15 16:52:42 +00:00
|
|
|
|
2015-05-18 19:44:22 +00:00
|
|
|
begin_test "happy path"
|
|
|
|
(
|
|
|
|
set -e
|
2015-05-15 16:52:42 +00:00
|
|
|
|
2015-05-19 22:54:15 +00:00
|
|
|
# This initializes a new bare git repository in test/remote.
|
|
|
|
# These remote repositories are global to every test, so keep the names
|
|
|
|
# unique.
|
2015-05-18 23:28:58 +00:00
|
|
|
reponame="$(basename "$0" ".sh")"
|
2015-05-18 22:49:21 +00:00
|
|
|
setup_remote_repo "$reponame"
|
2015-05-15 16:52:42 +00:00
|
|
|
|
2015-05-20 17:25:20 +00:00
|
|
|
# Clone the repository from the test Git server. This is empty, and will be
|
|
|
|
# used to test a "git pull" below. The repo is cloned to $TRASHDIR/clone
|
|
|
|
clone_repo "$reponame" clone
|
|
|
|
|
|
|
|
# Clone the repository again to $TRASHDIR/repo. This will be used to commit
|
|
|
|
# and push objects.
|
2015-05-18 22:49:21 +00:00
|
|
|
clone_repo "$reponame" repo
|
2015-05-14 17:56:05 +00:00
|
|
|
|
2015-05-19 22:54:15 +00:00
|
|
|
# This executes Git LFS from the local repo that was just cloned.
|
2015-05-27 19:59:52 +00:00
|
|
|
git lfs track "*.dat" 2>&1 | tee track.log
|
2017-03-24 16:59:03 +00:00
|
|
|
grep "Tracking \"\*.dat\"" track.log
|
2015-05-18 22:49:21 +00:00
|
|
|
|
2015-05-26 21:52:54 +00:00
|
|
|
contents="a"
|
2015-09-21 17:50:22 +00:00
|
|
|
contents_oid=$(calc_oid "$contents")
|
2015-05-18 22:49:21 +00:00
|
|
|
|
2015-05-19 22:54:15 +00:00
|
|
|
# Regular Git commands can be used.
|
2018-09-10 14:57:10 +00:00
|
|
|
printf "%s" "$contents" > a.dat
|
2015-05-18 22:49:21 +00:00
|
|
|
git add a.dat
|
|
|
|
git add .gitattributes
|
2015-05-26 21:52:54 +00:00
|
|
|
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
|
2015-05-18 22:49:21 +00:00
|
|
|
|
2015-05-27 19:59:52 +00:00
|
|
|
[ "a" = "$(cat a.dat)" ]
|
2015-05-18 22:49:21 +00:00
|
|
|
|
2015-05-19 22:54:15 +00:00
|
|
|
# This is a small shell function that runs several git commands together.
|
2015-05-18 22:49:21 +00:00
|
|
|
assert_pointer "master" "a.dat" "$contents_oid" 1
|
|
|
|
|
2015-07-06 18:19:18 +00:00
|
|
|
refute_server_object "$reponame" "$contents_oid"
|
2015-05-18 22:49:21 +00:00
|
|
|
|
2015-05-19 22:54:15 +00:00
|
|
|
# This pushes to the remote repository set up at the top of the test.
|
2015-05-26 21:52:54 +00:00
|
|
|
git push origin master 2>&1 | tee push.log
|
2018-01-06 02:01:50 +00:00
|
|
|
grep "Uploading LFS objects: 100% (1/1), 1 B" push.log
|
2015-05-26 21:52:54 +00:00
|
|
|
grep "master -> master" push.log
|
2015-05-18 22:49:21 +00:00
|
|
|
|
2015-07-06 18:19:18 +00:00
|
|
|
assert_server_object "$reponame" "$contents_oid"
|
2015-05-18 22:49:21 +00:00
|
|
|
|
2015-05-20 17:25:20 +00:00
|
|
|
# change to the clone's working directory
|
|
|
|
cd ../clone
|
|
|
|
|
2017-08-12 04:18:56 +00:00
|
|
|
git pull
|
2015-05-18 22:49:21 +00:00
|
|
|
|
2015-05-27 19:59:52 +00:00
|
|
|
[ "a" = "$(cat a.dat)" ]
|
2015-05-18 22:49:21 +00:00
|
|
|
|
|
|
|
assert_pointer "master" "a.dat" "$contents_oid" 1
|
2015-05-18 19:44:22 +00:00
|
|
|
)
|
|
|
|
end_test
|
2015-10-27 13:22:23 +00:00
|
|
|
|
2017-10-27 23:01:25 +00:00
|
|
|
begin_test "happy path on non-origin remote"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="happy-without-origin"
|
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
|
|
|
|
clone_repo "$reponame" repo-without-origin
|
|
|
|
git lfs track "*.dat"
|
|
|
|
git add .gitattributes
|
|
|
|
git commit -m "track"
|
|
|
|
git push origin master
|
|
|
|
|
|
|
|
clone_repo "$reponame" clone-without-origin
|
|
|
|
git remote rename origin happy-path
|
|
|
|
|
|
|
|
cd ../repo-without-origin
|
|
|
|
echo "a" > a.dat
|
|
|
|
git add a.dat
|
|
|
|
git commit -m "boom"
|
|
|
|
git push origin master
|
|
|
|
|
|
|
|
cd ../clone-without-origin
|
|
|
|
echo "remotes:"
|
|
|
|
git remote
|
|
|
|
git pull happy-path master
|
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
2018-01-05 22:01:29 +00:00
|
|
|
begin_test "happy path on good ref"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="happy-path-master-branch-required"
|
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
clone_repo "$reponame" "$reponame"
|
|
|
|
|
|
|
|
git lfs track "*.dat"
|
|
|
|
echo "a" > a.dat
|
|
|
|
git add .gitattributes a.dat
|
|
|
|
git commit -m "add a.dat"
|
|
|
|
|
|
|
|
git push origin master
|
|
|
|
|
|
|
|
# $ echo "a" | shasum -a 256
|
|
|
|
oid="87428fc522803d31065e7bce3cf03fe475096631e5e07bbd7a0fde60c4cf25c7"
|
|
|
|
assert_local_object "$oid" 2
|
|
|
|
assert_server_object "$reponame" "$oid" "refs/heads/master"
|
|
|
|
|
|
|
|
clone_repo "$reponame" "$reponame-clone"
|
|
|
|
assert_local_object "$oid" 2
|
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
|
|
|
begin_test "happy path on tracked ref"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="happy-path-tracked-branch-required"
|
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
clone_repo "$reponame" "$reponame"
|
|
|
|
|
|
|
|
git lfs track "*.dat"
|
|
|
|
echo "a" > a.dat
|
|
|
|
git add .gitattributes a.dat
|
|
|
|
git commit -m "add a.dat"
|
|
|
|
|
|
|
|
git push origin master:tracked
|
|
|
|
|
|
|
|
# $ echo "a" | shasum -a 256
|
|
|
|
oid="87428fc522803d31065e7bce3cf03fe475096631e5e07bbd7a0fde60c4cf25c7"
|
|
|
|
assert_local_object "$oid" 2
|
|
|
|
assert_server_object "$reponame" "$oid" "refs/heads/tracked"
|
|
|
|
|
|
|
|
git lfs clone "$GITSERVER/$reponame" --exclude "*"
|
|
|
|
|
|
|
|
git config credential.helper lfstest
|
|
|
|
git config push.default upstream
|
|
|
|
git config branch.master.merge refs/heads/tracked
|
|
|
|
|
|
|
|
git checkout
|
|
|
|
assert_local_object "$oid" 2
|
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
2015-10-27 13:22:23 +00:00
|
|
|
begin_test "clears local temp objects"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
mkdir repo-temp-objects
|
|
|
|
cd repo-temp-objects
|
|
|
|
git init
|
|
|
|
|
|
|
|
# abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz01
|
|
|
|
mkdir -p .git/lfs/objects/go/od
|
|
|
|
mkdir -p .git/lfs/tmp/objects
|
|
|
|
|
|
|
|
touch .git/lfs/objects/go/od/goodabcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwx
|
|
|
|
touch .git/lfs/tmp/objects/goodabcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwx-rand123
|
|
|
|
touch .git/lfs/tmp/objects/goodabcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwx-rand456
|
|
|
|
touch .git/lfs/tmp/objects/badabcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxy-rand123
|
|
|
|
touch .git/lfs/tmp/objects/badabcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxy-rand456
|
|
|
|
|
|
|
|
GIT_TRACE=5 git lfs env
|
|
|
|
|
|
|
|
# object file exists
|
|
|
|
[ -e ".git/lfs/objects/go/od/goodabcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwx" ]
|
|
|
|
|
|
|
|
# newer tmp files exist
|
|
|
|
[ -e ".git/lfs/tmp/objects/badabcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxy-rand123" ]
|
|
|
|
[ -e ".git/lfs/tmp/objects/badabcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxy-rand456" ]
|
|
|
|
|
|
|
|
# existing tmp files were cleaned up
|
|
|
|
[ ! -e ".git/lfs/tmp/objects/goodabcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwx-rand123" ]
|
|
|
|
[ ! -e ".git/lfs/tmp/objects/goodabcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwx-rand456" ]
|
|
|
|
)
|
|
|
|
end_test
|