2015-07-30 02:37:31 +00:00
|
|
|
#!/usr/bin/env bash
|
2015-05-26 20:58:03 +00:00
|
|
|
|
2018-07-10 18:48:02 +00:00
|
|
|
. "$(dirname "$0")/testlib.sh"
|
2015-05-26 20:58:03 +00:00
|
|
|
|
2018-01-05 18:12:57 +00:00
|
|
|
begin_test "pre-push with good ref"
|
|
|
|
(
|
|
|
|
set -e
|
2020-06-29 16:18:57 +00:00
|
|
|
reponame="pre-push-main-branch-required"
|
2018-01-05 18:12:57 +00:00
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
clone_repo "$reponame" "$reponame"
|
|
|
|
|
|
|
|
git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame").locksverify" false
|
|
|
|
git lfs track "*.dat"
|
|
|
|
echo "hi" > a.dat
|
|
|
|
git add .gitattributes a.dat
|
|
|
|
git commit -m "add a.dat"
|
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
refute_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 "refs/heads/main"
|
2018-01-05 18:12:57 +00:00
|
|
|
|
|
|
|
# for some reason, using 'tee' and $PIPESTATUS does not work here
|
2020-06-29 16:18:57 +00:00
|
|
|
echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
|
2018-01-05 18:12:57 +00:00
|
|
|
git lfs pre-push origin "$GITSERVER/$reponame" 2>&1 > push.log
|
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
assert_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 "refs/heads/main"
|
2018-01-05 18:12:57 +00:00
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
|
|
|
begin_test "pre-push with tracked ref"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
reponame="pre-push-tracked-branch-required"
|
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
clone_repo "$reponame" "$reponame"
|
|
|
|
|
|
|
|
git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame").locksverify" false
|
|
|
|
git lfs track "*.dat"
|
|
|
|
echo "hi" > a.dat
|
|
|
|
git add .gitattributes a.dat
|
|
|
|
git commit -m "add a.dat"
|
|
|
|
|
|
|
|
refute_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 "refs/heads/tracked"
|
|
|
|
|
|
|
|
# for some reason, using 'tee' and $PIPESTATUS does not work here
|
2020-06-29 16:18:57 +00:00
|
|
|
echo "refs/heads/main main refs/heads/tracked 0000000000000000000000000000000000000000" |
|
|
|
|
git lfs pre-push origin main 2>&1 > push.log
|
2018-01-05 18:12:57 +00:00
|
|
|
|
|
|
|
assert_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 "refs/heads/tracked"
|
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
|
|
|
begin_test "pre-push with bad ref"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
reponame="pre-push-other-branch-required"
|
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
clone_repo "$reponame" "$reponame"
|
|
|
|
|
|
|
|
git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame").locksverify" false
|
|
|
|
git lfs track "*.dat"
|
|
|
|
echo "hi" > a.dat
|
|
|
|
git add .gitattributes a.dat
|
|
|
|
git commit -m "add a.dat"
|
|
|
|
|
|
|
|
refute_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 "refs/heads/other"
|
|
|
|
|
|
|
|
# for some reason, using 'tee' and $PIPESTATUS does not work here
|
|
|
|
set +e
|
2020-06-29 16:18:57 +00:00
|
|
|
echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
|
2018-01-05 18:12:57 +00:00
|
|
|
git lfs pre-push origin "$GITSERVER/$reponame" 2> push.log
|
|
|
|
pushcode=$?
|
|
|
|
set -e
|
|
|
|
|
|
|
|
if [ "0" -eq "$pushcode" ]; then
|
|
|
|
echo "expected command to fail"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
grep 'Expected ref "refs/heads/other", got "refs/heads/main"' push.log
|
2018-01-05 18:12:57 +00:00
|
|
|
|
|
|
|
refute_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 "refs/heads/other"
|
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
2015-05-26 20:58:03 +00:00
|
|
|
begin_test "pre-push"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="$(basename "$0" ".sh")"
|
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
|
|
|
|
clone_repo "$reponame" repo
|
|
|
|
git lfs track "*.dat"
|
|
|
|
git add .gitattributes
|
|
|
|
git commit -m "add git attributes"
|
|
|
|
|
2017-02-16 00:24:22 +00:00
|
|
|
git config "lfs.$(repo_endpoint $GITSERVER $reponame).locksverify" true
|
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
|
2018-09-18 20:45:00 +00:00
|
|
|
git lfs pre-push origin "$GITSERVER/$reponame" |
|
2015-05-27 20:18:02 +00:00
|
|
|
tee push.log
|
2015-07-27 17:01:39 +00:00
|
|
|
# no output if nothing to do
|
|
|
|
[ "$(du -k push.log | cut -f 1)" == "0" ]
|
2015-05-26 20:58:03 +00:00
|
|
|
|
|
|
|
git lfs track "*.dat"
|
|
|
|
echo "hi" > hi.dat
|
|
|
|
git add hi.dat
|
|
|
|
git commit -m "add hi.dat"
|
|
|
|
git show
|
|
|
|
|
2015-07-06 18:19:18 +00:00
|
|
|
refute_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4
|
2015-05-26 20:58:03 +00:00
|
|
|
|
|
|
|
# push file to the git lfs server
|
2020-06-29 16:18:57 +00:00
|
|
|
echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
|
2015-05-26 20:58:03 +00:00
|
|
|
git lfs pre-push origin "$GITSERVER/$reponame" 2>&1 |
|
2015-05-27 20:18:02 +00:00
|
|
|
tee push.log
|
2018-01-06 02:01:50 +00:00
|
|
|
grep "Uploading LFS objects: 100% (1/1), 3 B" push.log
|
2015-05-26 20:58:03 +00:00
|
|
|
|
2015-07-06 18:19:18 +00:00
|
|
|
assert_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4
|
2015-05-26 20:58:03 +00:00
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
|
|
|
begin_test "pre-push dry-run"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="$(basename "$0" ".sh")-dry-run"
|
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
|
|
|
|
clone_repo "$reponame" repo-dry-run
|
|
|
|
git lfs track "*.dat"
|
|
|
|
git add .gitattributes
|
|
|
|
git commit -m "add git attributes"
|
|
|
|
|
2017-02-16 00:24:22 +00:00
|
|
|
git config "lfs.$(repo_endpoint $GITSERVER $reponame).locksverify" true
|
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
|
2018-09-18 20:45:00 +00:00
|
|
|
git lfs pre-push --dry-run origin "$GITSERVER/$reponame" |
|
2015-05-26 20:58:03 +00:00
|
|
|
tee push.log
|
|
|
|
|
2015-05-26 22:15:52 +00:00
|
|
|
[ "" = "$(cat push.log)" ]
|
2015-05-26 20:58:03 +00:00
|
|
|
|
|
|
|
git lfs track "*.dat"
|
|
|
|
echo "dry" > hi.dat
|
|
|
|
git add hi.dat
|
|
|
|
git commit -m "add hi.dat"
|
|
|
|
git show
|
|
|
|
|
2015-07-06 18:19:18 +00:00
|
|
|
refute_server_object "$reponame" 2840e0eafda1d0760771fe28b91247cf81c76aa888af28a850b5648a338dc15b
|
2015-05-26 20:58:03 +00:00
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
|
2018-09-18 20:45:00 +00:00
|
|
|
git lfs pre-push --dry-run origin "$GITSERVER/$reponame" |
|
2015-05-27 20:18:02 +00:00
|
|
|
tee push.log
|
2015-09-08 20:47:13 +00:00
|
|
|
grep "push 2840e0eafda1d0760771fe28b91247cf81c76aa888af28a850b5648a338dc15b => hi.dat" push.log
|
2015-07-27 16:43:41 +00:00
|
|
|
cat push.log
|
2015-07-06 18:19:18 +00:00
|
|
|
[ `wc -l < push.log` = 1 ]
|
2015-05-26 20:58:03 +00:00
|
|
|
|
2015-07-06 18:19:18 +00:00
|
|
|
refute_server_object "$reponame" 2840e0eafda1d0760771fe28b91247cf81c76aa888af28a850b5648a338dc15b
|
2015-05-26 20:58:03 +00:00
|
|
|
)
|
|
|
|
end_test
|
2015-06-27 15:42:50 +00:00
|
|
|
|
2020-09-29 09:29:44 +00:00
|
|
|
begin_test "pre-push skip-push"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="$(basename "$0" ".sh")-skip-push"
|
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
|
|
|
|
clone_repo "$reponame" repo-skip-push
|
|
|
|
git lfs track "*.dat"
|
|
|
|
git add .gitattributes
|
|
|
|
git commit -m "add git attributes"
|
|
|
|
|
|
|
|
git config "lfs.$(repo_endpoint $GITSERVER $reponame).locksverify" true
|
|
|
|
|
|
|
|
echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
|
|
|
|
GIT_LFS_SKIP_PUSH=true git lfs pre-push origin "$GITSERVER/$reponame" |
|
|
|
|
tee push.log
|
|
|
|
|
|
|
|
[ "" = "$(cat push.log)" ]
|
|
|
|
|
|
|
|
git lfs track "*.dat"
|
|
|
|
echo "dry" > hi.dat
|
|
|
|
git add hi.dat
|
|
|
|
git commit -m "add hi.dat"
|
|
|
|
git show
|
|
|
|
|
|
|
|
refute_server_object "$reponame" 2840e0eafda1d0760771fe28b91247cf81c76aa888af28a850b5648a338dc15b
|
|
|
|
|
|
|
|
echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
|
|
|
|
GIT_LFS_SKIP_PUSH=true git lfs pre-push origin "$GITSERVER/$reponame" |
|
|
|
|
tee push.log
|
|
|
|
|
|
|
|
[ "" = "$(cat push.log)" ]
|
|
|
|
|
|
|
|
refute_server_object "$reponame" 2840e0eafda1d0760771fe28b91247cf81c76aa888af28a850b5648a338dc15b
|
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
2015-06-29 11:57:50 +00:00
|
|
|
begin_test "pre-push 307 redirects"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="$(basename "$0" ".sh")"
|
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
|
|
|
|
clone_repo "$reponame" repo-307
|
|
|
|
git lfs track "*.dat"
|
|
|
|
git add .gitattributes
|
|
|
|
git commit -m "add git attributes"
|
|
|
|
|
|
|
|
# relative redirect
|
|
|
|
git config remote.origin.lfsurl "$GITSERVER/redirect307/rel/$reponame.git/info/lfs"
|
|
|
|
|
|
|
|
git lfs track "*.dat"
|
|
|
|
echo "hi" > hi.dat
|
|
|
|
git add hi.dat
|
|
|
|
git commit -m "add hi.dat"
|
|
|
|
git show
|
|
|
|
|
|
|
|
# push file to the git lfs server
|
2020-06-29 16:18:57 +00:00
|
|
|
echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
|
2015-06-29 11:57:50 +00:00
|
|
|
git lfs pre-push origin "$GITSERVER/redirect307/rel/$reponame.git/info/lfs" 2>&1 |
|
|
|
|
tee push.log
|
2018-01-06 02:01:50 +00:00
|
|
|
grep "Uploading LFS objects: 100% (1/1), 3 B" push.log
|
2015-06-29 11:57:50 +00:00
|
|
|
|
2015-07-06 18:19:18 +00:00
|
|
|
assert_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4
|
2015-06-29 11:57:50 +00:00
|
|
|
|
|
|
|
# absolute redirect
|
|
|
|
git config remote.origin.lfsurl "$GITSERVER/redirect307/abs/$reponame.git/info/lfs"
|
|
|
|
|
|
|
|
echo "hi" > hi2.dat
|
|
|
|
git add hi2.dat
|
|
|
|
git commit -m "add hi2.dat"
|
|
|
|
git show
|
|
|
|
|
|
|
|
# push file to the git lfs server
|
2020-06-29 16:18:57 +00:00
|
|
|
echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
|
2015-06-29 11:57:50 +00:00
|
|
|
git lfs pre-push origin "$GITSERVER/redirect307/abs/$reponame.git/info/lfs" 2>&1 |
|
|
|
|
tee push.log
|
2018-01-06 02:01:50 +00:00
|
|
|
grep "Uploading LFS objects: 100% (1/1), 3 B" push.log
|
2015-06-29 11:57:50 +00:00
|
|
|
)
|
|
|
|
end_test
|
2015-07-06 16:47:17 +00:00
|
|
|
|
2015-06-27 15:42:50 +00:00
|
|
|
begin_test "pre-push with existing file"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="$(basename "$0" ".sh")-existing-file"
|
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
|
2015-06-28 13:33:20 +00:00
|
|
|
clone_repo "$reponame" existing-file
|
2015-06-27 15:42:50 +00:00
|
|
|
echo "existing" > existing.dat
|
|
|
|
git add existing.dat
|
|
|
|
git commit -m "add existing dat"
|
|
|
|
|
|
|
|
git lfs track "*.dat"
|
|
|
|
echo "new" > new.dat
|
|
|
|
git add new.dat
|
|
|
|
git add .gitattributes
|
|
|
|
git commit -m "add new file through git lfs"
|
|
|
|
|
|
|
|
# push file to the git lfs server
|
2020-06-29 16:18:57 +00:00
|
|
|
echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
|
2015-06-27 15:42:50 +00:00
|
|
|
git lfs pre-push origin "$GITSERVER/$reponame" 2>&1 |
|
|
|
|
tee push.log
|
2018-01-06 02:01:50 +00:00
|
|
|
grep "Uploading LFS objects: 100% (1/1), 4 B" push.log
|
2015-06-27 15:42:50 +00:00
|
|
|
|
|
|
|
# now the file exists
|
2015-07-06 18:19:18 +00:00
|
|
|
assert_server_object "$reponame" 7aa7a5359173d05b63cfd682e3c38487f3cb4f7f1d60659fe59fab1505977d4c
|
2015-06-27 15:42:50 +00:00
|
|
|
)
|
|
|
|
end_test
|
2015-06-28 13:33:20 +00:00
|
|
|
|
|
|
|
begin_test "pre-push with existing pointer"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="$(basename "$0" ".sh")-existing-pointer"
|
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
clone_repo "$reponame" existing-pointer
|
|
|
|
|
|
|
|
echo "$(pointer "7aa7a5359173d05b63cfd682e3c38487f3cb4f7f1d60659fe59fab1505977d4c" 4)" > new.dat
|
|
|
|
git add new.dat
|
|
|
|
git commit -m "add new pointer"
|
|
|
|
mkdir -p .git/lfs/objects/7a/a7
|
|
|
|
echo "new" > .git/lfs/objects/7a/a7/7aa7a5359173d05b63cfd682e3c38487f3cb4f7f1d60659fe59fab1505977d4c
|
|
|
|
|
|
|
|
# push file to the git lfs server
|
2020-06-29 16:18:57 +00:00
|
|
|
echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
|
2015-06-28 13:33:20 +00:00
|
|
|
git lfs pre-push origin "$GITSERVER/$reponame" 2>&1 |
|
|
|
|
tee push.log
|
2018-01-06 02:01:50 +00:00
|
|
|
grep "Uploading LFS objects: 100% (1/1), 4 B" push.log
|
2015-06-28 13:33:20 +00:00
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
2015-08-11 14:01:57 +00:00
|
|
|
begin_test "pre-push with missing pointer not on server"
|
2015-06-28 13:33:20 +00:00
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="$(basename "$0" ".sh")-missing-pointer"
|
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
clone_repo "$reponame" missing-pointer
|
|
|
|
|
2017-03-24 20:37:29 +00:00
|
|
|
oid="7aa7a5359173d05b63cfd682e3c38487f3cb4f7f1d60659fe59fab1505977d4c"
|
|
|
|
|
|
|
|
echo "$(pointer "$oid" 4)" > new.dat
|
2015-06-28 13:33:20 +00:00
|
|
|
git add new.dat
|
|
|
|
git commit -m "add new pointer"
|
|
|
|
|
|
|
|
# assert that push fails
|
|
|
|
set +e
|
2020-06-29 16:18:57 +00:00
|
|
|
echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
|
2015-06-28 13:33:20 +00:00
|
|
|
git lfs pre-push origin "$GITSERVER/$reponame" 2>&1 |
|
|
|
|
tee push.log
|
|
|
|
set -e
|
2017-03-24 20:37:29 +00:00
|
|
|
|
|
|
|
grep " (missing) new.dat ($oid)" push.log
|
2015-06-28 13:33:20 +00:00
|
|
|
)
|
|
|
|
end_test
|
2015-08-11 14:01:57 +00:00
|
|
|
|
|
|
|
begin_test "pre-push with missing pointer which is on server"
|
|
|
|
(
|
|
|
|
# should permit push if files missing locally but are on server, shouldn't
|
|
|
|
# require client to have every file (prune)
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="$(basename "$0" ".sh")-missing-but-on-server"
|
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
clone_repo "$reponame" missing-but-on-server
|
|
|
|
|
|
|
|
contents="common data"
|
2015-09-21 17:50:22 +00:00
|
|
|
contents_oid=$(calc_oid "$contents")
|
2015-08-11 14:01:57 +00:00
|
|
|
git lfs track "*.dat"
|
2018-09-10 14:57:10 +00:00
|
|
|
printf "%s" "$contents" > common1.dat
|
2015-08-11 14:01:57 +00:00
|
|
|
git add common1.dat
|
|
|
|
git add .gitattributes
|
|
|
|
git commit -m "add first file"
|
|
|
|
|
|
|
|
# push file to the git lfs server
|
2020-06-29 16:18:57 +00:00
|
|
|
echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
|
2015-08-12 16:36:40 +00:00
|
|
|
git lfs pre-push origin "$GITSERVER/$reponame" 2>&1 |
|
|
|
|
tee push.log
|
2018-01-06 02:01:50 +00:00
|
|
|
grep "Uploading LFS objects: 100% (1/1), 11 B" push.log
|
2015-08-12 16:36:40 +00:00
|
|
|
|
|
|
|
# now the file exists
|
|
|
|
assert_server_object "$reponame" "$contents_oid"
|
|
|
|
|
|
|
|
# create another commit referencing same oid, then delete local data & push
|
2018-09-10 14:57:10 +00:00
|
|
|
printf "%s" "$contents" > common2.dat
|
2015-08-12 16:36:40 +00:00
|
|
|
git add common2.dat
|
|
|
|
git commit -m "add second file, same content"
|
|
|
|
rm -rf .git/lfs/objects
|
2020-06-29 16:18:57 +00:00
|
|
|
echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
|
2015-08-12 16:36:40 +00:00
|
|
|
git lfs pre-push origin "$GITSERVER/$reponame" 2>&1 |
|
|
|
|
tee push.log
|
|
|
|
# make sure there were no errors reported
|
|
|
|
[ -z "$(grep -i 'Error' push.log)" ]
|
|
|
|
|
|
|
|
)
|
|
|
|
end_test
|
2015-09-04 13:51:07 +00:00
|
|
|
|
2018-07-05 17:23:49 +00:00
|
|
|
begin_test "pre-push with missing and present pointers (lfs.allowincompletepush true)"
|
2017-05-04 17:21:15 +00:00
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="pre-push-missing-and-present"
|
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
clone_repo "$reponame" "$reponame"
|
|
|
|
|
|
|
|
git lfs track "*.dat"
|
|
|
|
git add .gitattributes
|
|
|
|
git commit -m "initial commit"
|
|
|
|
|
|
|
|
present="present"
|
|
|
|
present_oid="$(calc_oid "$present")"
|
2018-09-10 14:57:10 +00:00
|
|
|
printf "%s" "$present" > present.dat
|
2017-05-04 17:21:15 +00:00
|
|
|
|
|
|
|
missing="missing"
|
|
|
|
missing_oid="$(calc_oid "$missing")"
|
2018-09-10 14:57:10 +00:00
|
|
|
printf "%s" "$missing" > missing.dat
|
2017-05-04 17:21:15 +00:00
|
|
|
|
|
|
|
git add present.dat missing.dat
|
|
|
|
git commit -m "add present.dat and missing.dat"
|
|
|
|
|
2017-09-12 14:19:36 +00:00
|
|
|
git rm missing.dat
|
|
|
|
git commit -m "remove missing"
|
|
|
|
|
2017-05-04 17:21:15 +00:00
|
|
|
# :fire: the "missing" object
|
|
|
|
missing_oid_part_1="$(echo "$missing_oid" | cut -b 1-2)"
|
|
|
|
missing_oid_part_2="$(echo "$missing_oid" | cut -b 3-4)"
|
|
|
|
missing_oid_path=".git/lfs/objects/$missing_oid_part_1/$missing_oid_part_2/$missing_oid"
|
|
|
|
rm "$missing_oid_path"
|
|
|
|
|
2018-07-05 17:23:49 +00:00
|
|
|
git config lfs.allowincompletepush true
|
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
|
2017-05-04 17:21:15 +00:00
|
|
|
git lfs pre-push origin "$GITSERVER/$reponame" 2>&1 |
|
|
|
|
tee push.log
|
|
|
|
|
|
|
|
if [ "0" -ne "${PIPESTATUS[1]}" ]; then
|
|
|
|
echo >&2 "fatal: expected \`git lfs pre-push origin $GITSERVER/$reponame\` to succeed..."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
grep "LFS upload missing objects" push.log
|
|
|
|
grep " (missing) missing.dat ($missing_oid)" push.log
|
|
|
|
|
|
|
|
assert_server_object "$reponame" "$present_oid"
|
|
|
|
refute_server_object "$reponame" "$missing_oid"
|
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
2018-07-05 17:23:49 +00:00
|
|
|
begin_test "pre-push reject missing pointers (lfs.allowincompletepush default)"
|
2017-09-12 14:33:52 +00:00
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="pre-push-reject-missing-and-present"
|
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
clone_repo "$reponame" "$reponame"
|
|
|
|
|
|
|
|
git lfs track "*.dat"
|
|
|
|
git add .gitattributes
|
|
|
|
git commit -m "initial commit"
|
|
|
|
|
|
|
|
present="present"
|
|
|
|
present_oid="$(calc_oid "$present")"
|
2018-09-10 14:57:10 +00:00
|
|
|
printf "%s" "$present" > present.dat
|
2017-09-12 14:33:52 +00:00
|
|
|
|
|
|
|
missing="missing"
|
|
|
|
missing_oid="$(calc_oid "$missing")"
|
2018-09-10 14:57:10 +00:00
|
|
|
printf "%s" "$missing" > missing.dat
|
2017-09-12 14:33:52 +00:00
|
|
|
|
|
|
|
git add present.dat missing.dat
|
|
|
|
git commit -m "add present.dat and missing.dat"
|
|
|
|
|
|
|
|
git rm missing.dat
|
|
|
|
git commit -m "remove missing"
|
|
|
|
|
|
|
|
# :fire: the "missing" object
|
|
|
|
missing_oid_part_1="$(echo "$missing_oid" | cut -b 1-2)"
|
|
|
|
missing_oid_part_2="$(echo "$missing_oid" | cut -b 3-4)"
|
|
|
|
missing_oid_path=".git/lfs/objects/$missing_oid_part_1/$missing_oid_part_2/$missing_oid"
|
|
|
|
rm "$missing_oid_path"
|
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
|
2017-09-12 14:33:52 +00:00
|
|
|
git lfs pre-push origin "$GITSERVER/$reponame" 2>&1 |
|
|
|
|
tee push.log
|
|
|
|
|
|
|
|
if [ "2" -ne "${PIPESTATUS[1]}" ]; then
|
|
|
|
echo >&2 "fatal: expected \`git lfs pre-push origin $GITSERVER/$reponame\` to fail..."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
Don't fail if we lack objects the server has
A Git LFS client may not have the entire history of the objects for the
repository. However, in some situations, we traverse the entire history
of a branch when pushing it, meaning that we need to process every
LFS object in the history of that branch. If the objects for the entire
history are not present, we currently fail to push.
Instead, let's mark objects we don't have on disk as missing and only
fail when we would need to upload those objects. We'll know the server
has the objects if the batch response provides no actions to take for
them when we request an upload. Pass the missing flag down through the
code, and always set it to false for non-uploads.
If for some reason we fail to properly flag a missing object, we will
still fail later on when we cannot open the file, just in a messier and
more poorly controlled way. The technique used here will attempt to
abort the batch as soon as we notice a problem, which means that in the
common case (less than 100 objects) we won't have transferred any
objects, so the user can notice the failure as soon as possible.
Update the tests to look for a string which will occur in the error
message, since we no longer produce the system error message for ENOENT.
2019-04-30 19:18:18 +00:00
|
|
|
grep 'Unable to find source' push.log
|
2017-09-12 14:33:52 +00:00
|
|
|
|
|
|
|
refute_server_object "$reponame" "$present_oid"
|
|
|
|
refute_server_object "$reponame" "$missing_oid"
|
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
2015-09-04 13:51:07 +00:00
|
|
|
begin_test "pre-push multiple branches"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="$(basename "$0" ".sh")-multiple-branches"
|
|
|
|
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 13:51:07 +00:00
|
|
|
|
|
|
|
NUMFILES=6
|
|
|
|
# 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 13:51:07 +00:00
|
|
|
done
|
2015-09-08 20:47:13 +00:00
|
|
|
|
2015-09-04 13:51:07 +00:00
|
|
|
echo "[
|
|
|
|
{
|
|
|
|
\"CommitDate\":\"$(get_date -10d)\",
|
|
|
|
\"Files\":[
|
|
|
|
{\"Filename\":\"file1.dat\",\"Size\":${#content[0]}, \"Data\":\"${content[0]}\"},
|
|
|
|
{\"Filename\":\"file2.dat\",\"Size\":${#content[1]}, \"Data\":\"${content[1]}\"}]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
\"NewBranch\":\"branch1\",
|
|
|
|
\"CommitDate\":\"$(get_date -5d)\",
|
|
|
|
\"Files\":[
|
|
|
|
{\"Filename\":\"file2.dat\",\"Size\":${#content[2]}, \"Data\":\"${content[2]}\"}]
|
|
|
|
},
|
|
|
|
{
|
2020-06-29 16:18:57 +00:00
|
|
|
\"ParentBranches\":[\"main\"],
|
2015-09-04 13:51:07 +00:00
|
|
|
\"NewBranch\":\"branch2\",
|
|
|
|
\"CommitDate\":\"$(get_date -5d)\",
|
|
|
|
\"Files\":[
|
|
|
|
{\"Filename\":\"file3.dat\",\"Size\":${#content[3]}, \"Data\":\"${content[3]}\"}]
|
|
|
|
},
|
|
|
|
{
|
2020-06-29 16:18:57 +00:00
|
|
|
\"ParentBranches\":[\"main\"],
|
2015-09-04 13:51:07 +00:00
|
|
|
\"NewBranch\":\"branch3\",
|
|
|
|
\"CommitDate\":\"$(get_date -2d)\",
|
|
|
|
\"Files\":[
|
|
|
|
{\"Filename\":\"file1.dat\",\"Size\":${#content[4]}, \"Data\":\"${content[4]}\"}]
|
|
|
|
},
|
|
|
|
{
|
2020-06-29 16:18:57 +00:00
|
|
|
\"ParentBranches\":[\"main\"],
|
2015-09-04 13:51:07 +00:00
|
|
|
\"NewBranch\":\"branch4\",
|
|
|
|
\"CommitDate\":\"$(get_date -1d)\",
|
|
|
|
\"Files\":[
|
|
|
|
{\"Filename\":\"file4.dat\",\"Size\":${#content[5]}, \"Data\":\"${content[5]}\"}]
|
|
|
|
}
|
|
|
|
]" | lfstest-testutils addcommits
|
|
|
|
|
|
|
|
# make sure when called via git push all branches are updated
|
2020-06-29 16:18:57 +00:00
|
|
|
git push origin main branch1 branch2 branch3 branch4
|
2015-09-04 13:51:07 +00:00
|
|
|
for ((a=0; a < NUMFILES ; a++))
|
|
|
|
do
|
|
|
|
assert_server_object "$reponame" "${oid[$a]}"
|
|
|
|
done
|
|
|
|
|
|
|
|
)
|
|
|
|
end_test
|
2016-02-03 21:23:27 +00:00
|
|
|
|
|
|
|
begin_test "pre-push with bad remote"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
cd repo
|
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
|
2016-02-03 21:23:27 +00:00
|
|
|
git lfs pre-push not-a-remote "$GITSERVER/$reponame" 2>&1 |
|
|
|
|
tee pre-push.log
|
|
|
|
grep "Invalid remote name" pre-push.log
|
|
|
|
)
|
|
|
|
end_test
|
2016-02-29 15:07:01 +00:00
|
|
|
|
|
|
|
begin_test "pre-push unfetched deleted remote branch & server GC"
|
|
|
|
(
|
|
|
|
# point of this is to simulate the case where the local cache of the remote
|
|
|
|
# branch state contains a branch which has actually been deleted on the remote,
|
|
|
|
# the client just doesn't know yet (hasn't done 'git fetch origin --prune')
|
|
|
|
# If the server GC'd the objects that deleted branch contained, but they were
|
|
|
|
# referenced by a branch being pushed (earlier commit), push might assume it
|
|
|
|
# doesn't have to push it, but it does. Tests that we check the real remote refs
|
|
|
|
# before making an assumption about the diff we need to push
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="$(basename "$0" ".sh")-server-deleted-branch-gc"
|
|
|
|
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
|
2016-02-29 15:07:01 +00:00
|
|
|
|
|
|
|
NUMFILES=4
|
|
|
|
# generate content we'll use
|
|
|
|
for ((a=0; a < NUMFILES ; a++))
|
|
|
|
do
|
|
|
|
content[$a]="filecontent$a"
|
|
|
|
oid[$a]=$(calc_oid "${content[$a]}")
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "[
|
|
|
|
{
|
|
|
|
\"CommitDate\":\"$(get_date -10d)\",
|
|
|
|
\"Files\":[
|
|
|
|
{\"Filename\":\"file1.dat\",\"Size\":${#content[0]}, \"Data\":\"${content[0]}\"},
|
|
|
|
{\"Filename\":\"file2.dat\",\"Size\":${#content[1]}, \"Data\":\"${content[1]}\"}]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
\"NewBranch\":\"branch-to-delete\",
|
|
|
|
\"CommitDate\":\"$(get_date -5d)\",
|
|
|
|
\"Files\":[
|
|
|
|
{\"Filename\":\"file3.dat\",\"Size\":${#content[2]}, \"Data\":\"${content[2]}\"}]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
\"NewBranch\":\"branch-to-push-after\",
|
|
|
|
\"CommitDate\":\"$(get_date -2d)\",
|
|
|
|
\"Files\":[
|
|
|
|
{\"Filename\":\"file4.dat\",\"Size\":${#content[3]}, \"Data\":\"${content[3]}\"}]
|
|
|
|
}
|
|
|
|
]" | lfstest-testutils addcommits
|
|
|
|
|
|
|
|
# push only the first 2 branches
|
2020-06-29 16:18:57 +00:00
|
|
|
git push origin main branch-to-delete
|
2016-02-29 15:07:01 +00:00
|
|
|
for ((a=0; a < 3 ; a++))
|
|
|
|
do
|
|
|
|
assert_server_object "$reponame" "${oid[$a]}"
|
|
|
|
done
|
|
|
|
# confirm we haven't pushed the last one yet
|
|
|
|
refute_server_object "$reponame" "${oid[3]}"
|
|
|
|
# copy the cached remote ref for the branch we're going to delete remotely
|
|
|
|
cp .git/refs/remotes/origin/branch-to-delete branch-to-delete.ref
|
|
|
|
# now delete the branch on the server
|
|
|
|
git push origin --delete branch-to-delete
|
|
|
|
# remove the OID in it, as if GC'd
|
|
|
|
delete_server_object "$reponame" "${oid[2]}"
|
|
|
|
refute_server_object "$reponame" "${oid[2]}"
|
|
|
|
# Now put the cached remote ref back, as if someone else had deleted it but
|
|
|
|
# we hadn't done git fetch --prune yet
|
|
|
|
mv branch-to-delete.ref .git/refs/remotes/origin/branch-to-delete
|
|
|
|
# Confirm that local cache of remote branch is back
|
2016-04-06 19:06:34 +00:00
|
|
|
git branch -r 2>&1 | tee branch-r.log
|
2016-02-29 15:07:01 +00:00
|
|
|
grep "origin/branch-to-delete" branch-r.log
|
|
|
|
# Now push later branch which should now need to re-push previous commits LFS too
|
|
|
|
git push origin branch-to-push-after
|
|
|
|
# all objects should now be there even though cached remote branch claimed it already had file3.dat
|
|
|
|
for ((a=0; a < NUMFILES ; a++))
|
|
|
|
do
|
|
|
|
assert_server_object "$reponame" "${oid[$a]}"
|
|
|
|
done
|
|
|
|
|
|
|
|
)
|
|
|
|
end_test
|
2016-04-05 10:54:22 +00:00
|
|
|
|
|
|
|
begin_test "pre-push delete branch"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="$(basename "$0" ".sh")-delete-branch"
|
|
|
|
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
|
2016-04-05 10:54:22 +00:00
|
|
|
|
|
|
|
NUMFILES=4
|
|
|
|
# generate content we'll use
|
|
|
|
for ((a=0; a < NUMFILES ; a++))
|
|
|
|
do
|
|
|
|
content[$a]="filecontent$a"
|
|
|
|
oid[$a]=$(calc_oid "${content[$a]}")
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "[
|
|
|
|
{
|
|
|
|
\"CommitDate\":\"$(get_date -2d)\",
|
|
|
|
\"Files\":[
|
|
|
|
{\"Filename\":\"file1.dat\",\"Size\":${#content[0]}, \"Data\":\"${content[0]}\"},
|
|
|
|
{\"Filename\":\"file2.dat\",\"Size\":${#content[1]}, \"Data\":\"${content[1]}\"}]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
\"NewBranch\":\"branch-to-delete\",
|
|
|
|
\"CommitDate\":\"$(get_date -1d)\",
|
|
|
|
\"Files\":[
|
|
|
|
{\"Filename\":\"file3.dat\",\"Size\":${#content[2]}, \"Data\":\"${content[2]}\"}]
|
|
|
|
},
|
|
|
|
{
|
2020-06-29 16:18:57 +00:00
|
|
|
\"ParentBranches\":[\"main\"],
|
2016-04-05 10:54:22 +00:00
|
|
|
\"CommitDate\":\"$(get_date -0d)\",
|
|
|
|
\"Files\":[
|
|
|
|
{\"Filename\":\"file4.dat\",\"Size\":${#content[3]}, \"Data\":\"${content[3]}\"}]
|
|
|
|
}
|
|
|
|
]" | lfstest-testutils addcommits
|
|
|
|
|
|
|
|
# push all branches
|
2020-06-29 16:18:57 +00:00
|
|
|
git push origin main branch-to-delete
|
2016-04-05 10:54:22 +00:00
|
|
|
for ((a=0; a < NUMFILES ; a++))
|
|
|
|
do
|
|
|
|
assert_server_object "$reponame" "${oid[$a]}"
|
|
|
|
done
|
|
|
|
|
2016-04-06 19:06:34 +00:00
|
|
|
# deleting a branch with git push should not fail
|
2016-04-05 10:54:22 +00:00
|
|
|
# (requires correct special casing of "(delete) 0000000000.." in hook)
|
|
|
|
git push origin --delete branch-to-delete
|
|
|
|
)
|
2016-04-06 19:06:34 +00:00
|
|
|
end_test
|
2016-12-28 18:49:01 +00:00
|
|
|
|
2017-02-01 20:08:11 +00:00
|
|
|
begin_test "pre-push with our lock"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="pre_push_owned_locks"
|
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
clone_repo "$reponame" "$reponame"
|
2016-12-28 18:49:01 +00:00
|
|
|
|
2017-02-01 20:08:11 +00:00
|
|
|
git lfs track "*.dat"
|
|
|
|
git add .gitattributes
|
|
|
|
git commit -m "initial commit"
|
|
|
|
|
|
|
|
contents="locked contents"
|
2018-09-10 14:57:10 +00:00
|
|
|
printf "%s" "$contents" > locked.dat
|
2017-02-01 20:08:11 +00:00
|
|
|
git add locked.dat
|
|
|
|
git commit -m "add locked.dat"
|
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
git push origin main
|
2017-02-01 20:08:11 +00:00
|
|
|
|
2017-02-23 19:47:14 +00:00
|
|
|
git lfs lock --json "locked.dat" | tee lock.log
|
2017-02-01 20:08:11 +00:00
|
|
|
|
2017-02-23 19:47:14 +00:00
|
|
|
id=$(assert_lock lock.log locked.dat)
|
2017-02-01 20:08:11 +00:00
|
|
|
assert_server_lock $id
|
|
|
|
|
|
|
|
printf "authorized changes" >> locked.dat
|
|
|
|
git add locked.dat
|
|
|
|
git commit -m "add unauthorized changes"
|
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
GIT_CURL_VERBOSE=1 git push origin main 2>&1 | tee push.log
|
2017-11-01 23:35:43 +00:00
|
|
|
grep "Consider unlocking your own locked files" push.log
|
2017-01-13 22:57:58 +00:00
|
|
|
grep "* locked.dat" push.log
|
2017-02-01 20:08:11 +00:00
|
|
|
|
|
|
|
assert_server_lock "$id"
|
2016-12-28 18:49:01 +00:00
|
|
|
)
|
|
|
|
end_test
|
2016-12-28 18:49:44 +00:00
|
|
|
|
2017-02-16 23:53:00 +00:00
|
|
|
begin_test "pre-push with their lock on lfs file"
|
2016-12-28 18:49:44 +00:00
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="pre_push_unowned_lock"
|
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
clone_repo "$reponame" "$reponame"
|
|
|
|
|
|
|
|
git lfs track "*.dat"
|
|
|
|
git add .gitattributes
|
|
|
|
git commit -m "initial commit"
|
|
|
|
|
|
|
|
contents="locked contents"
|
2017-02-01 20:08:11 +00:00
|
|
|
|
|
|
|
# any lock path with "theirs" is returned as "their" lock by /locks/verify
|
2018-09-10 14:57:10 +00:00
|
|
|
printf "%s" "$contents" > locked_theirs.dat
|
2017-02-01 20:08:11 +00:00
|
|
|
git add locked_theirs.dat
|
|
|
|
git commit -m "add locked_theirs.dat"
|
2016-12-28 18:49:44 +00:00
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
git push origin main
|
2016-12-28 18:49:44 +00:00
|
|
|
|
2017-02-23 19:47:14 +00:00
|
|
|
git lfs lock --json "locked_theirs.dat" | tee lock.log
|
|
|
|
id=$(assert_lock lock.log locked_theirs.dat)
|
2016-12-28 18:49:44 +00:00
|
|
|
assert_server_lock $id
|
|
|
|
|
|
|
|
pushd "$TRASHDIR" >/dev/null
|
|
|
|
clone_repo "$reponame" "$reponame-assert"
|
2017-04-21 21:33:30 +00:00
|
|
|
git config lfs.locksverify true
|
2016-12-28 18:49:44 +00:00
|
|
|
|
2017-02-01 20:08:11 +00:00
|
|
|
printf "unauthorized changes" >> locked_theirs.dat
|
|
|
|
git add locked_theirs.dat
|
2016-12-29 00:22:52 +00:00
|
|
|
# --no-verify is used to avoid the pre-commit hook which is not under test
|
2017-02-01 20:08:11 +00:00
|
|
|
git commit --no-verify -m "add unauthorized changes"
|
2016-12-28 18:49:44 +00:00
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
git push origin main 2>&1 | tee push.log
|
2017-04-21 21:33:30 +00:00
|
|
|
res="${PIPESTATUS[0]}"
|
|
|
|
if [ "0" -eq "$res" ]; then
|
|
|
|
echo "push should fail"
|
|
|
|
exit 1
|
|
|
|
fi
|
2016-12-28 18:49:44 +00:00
|
|
|
|
2017-11-01 23:35:43 +00:00
|
|
|
grep "Unable to push locked files" push.log
|
2017-02-03 17:48:31 +00:00
|
|
|
grep "* locked_theirs.dat - Git LFS Tests" push.log
|
2017-04-26 19:43:59 +00:00
|
|
|
|
2022-01-03 21:02:56 +00:00
|
|
|
grep "Cannot update locked files." push.log
|
2017-04-26 19:43:59 +00:00
|
|
|
refute_server_object "$reponame" "$(calc_oid_file locked_theirs.dat)"
|
2016-12-28 18:49:44 +00:00
|
|
|
popd >/dev/null
|
|
|
|
)
|
|
|
|
end_test
|
2017-02-16 23:53:00 +00:00
|
|
|
|
|
|
|
begin_test "pre-push with their lock on non-lfs lockable file"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="pre_push_unowned_lock_not_lfs"
|
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
clone_repo "$reponame" "$reponame"
|
|
|
|
|
|
|
|
echo "*.dat lockable" > .gitattributes
|
|
|
|
git add .gitattributes
|
|
|
|
git commit -m "initial commit"
|
|
|
|
|
|
|
|
# any lock path with "theirs" is returned as "their" lock by /locks/verify
|
|
|
|
echo "hi" > readme.txt
|
|
|
|
echo "tiny" > tiny_locked_theirs.dat
|
|
|
|
git help > large_locked_theirs.dat
|
|
|
|
git add readme.txt tiny_locked_theirs.dat large_locked_theirs.dat
|
|
|
|
git commit -m "add initial files"
|
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
git push origin main
|
2017-02-16 23:53:00 +00:00
|
|
|
|
2017-02-23 19:47:14 +00:00
|
|
|
git lfs lock --json "tiny_locked_theirs.dat" | tee lock.log
|
|
|
|
id=$(assert_lock lock.log tiny_locked_theirs.dat)
|
2017-02-16 23:53:00 +00:00
|
|
|
assert_server_lock $id
|
|
|
|
|
2017-02-23 19:47:14 +00:00
|
|
|
git lfs lock --json "large_locked_theirs.dat" | tee lock.log
|
|
|
|
id=$(assert_lock lock.log large_locked_theirs.dat)
|
2017-02-16 23:53:00 +00:00
|
|
|
assert_server_lock $id
|
|
|
|
|
|
|
|
pushd "$TRASHDIR" >/dev/null
|
|
|
|
clone_repo "$reponame" "$reponame-assert"
|
2017-04-21 21:33:30 +00:00
|
|
|
git config lfs.locksverify true
|
2017-02-16 23:53:00 +00:00
|
|
|
|
|
|
|
git lfs update # manually add pre-push hook, since lfs clean hook is not used
|
|
|
|
echo "other changes" >> readme.txt
|
|
|
|
echo "unauthorized changes" >> large_locked_theirs.dat
|
|
|
|
echo "unauthorized changes" >> tiny_locked_theirs.dat
|
|
|
|
# --no-verify is used to avoid the pre-commit hook which is not under test
|
|
|
|
git commit --no-verify -am "add unauthorized changes"
|
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
git push origin main 2>&1 | tee push.log
|
2017-04-21 21:33:30 +00:00
|
|
|
res="${PIPESTATUS[0]}"
|
|
|
|
if [ "0" -eq "$res" ]; then
|
|
|
|
echo "push should fail"
|
|
|
|
exit 1
|
|
|
|
fi
|
2017-02-16 23:53:00 +00:00
|
|
|
|
2017-11-01 23:35:43 +00:00
|
|
|
grep "Unable to push locked files" push.log
|
2017-02-16 23:53:00 +00:00
|
|
|
grep "* large_locked_theirs.dat - Git LFS Tests" push.log
|
|
|
|
grep "* tiny_locked_theirs.dat - Git LFS Tests" push.log
|
2022-01-03 21:02:56 +00:00
|
|
|
grep "Cannot update locked files." push.log
|
2017-04-26 19:43:59 +00:00
|
|
|
|
|
|
|
refute_server_object "$reponame" "$(calc_oid_file large_locked_theirs.dat)"
|
|
|
|
refute_server_object "$reponame" "$(calc_oid_file tiny_locked_theirs.dat)"
|
2017-02-16 23:53:00 +00:00
|
|
|
popd >/dev/null
|
|
|
|
)
|
|
|
|
end_test
|
2017-02-17 17:14:00 +00:00
|
|
|
|
2017-02-16 00:26:09 +00:00
|
|
|
begin_test "pre-push locks verify 5xx with verification enabled"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="lock-enabled-verify-5xx"
|
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
clone_repo "$reponame" "$reponame"
|
|
|
|
|
|
|
|
endpoint="$(repo_endpoint $GITSERVER $reponame)"
|
|
|
|
|
2017-02-16 20:37:03 +00:00
|
|
|
contents="example"
|
|
|
|
contents_oid="$(calc_oid "$contents")"
|
2018-09-10 14:57:10 +00:00
|
|
|
printf "%s" "$contents" > a.dat
|
2017-02-16 00:26:09 +00:00
|
|
|
git lfs track "*.dat"
|
|
|
|
git add .gitattributes a.dat
|
|
|
|
git commit --message "initial commit"
|
|
|
|
|
|
|
|
git config "lfs.$endpoint.locksverify" true
|
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
git push origin main 2>&1 | tee push.log
|
2022-01-27 17:31:41 +00:00
|
|
|
grep "\"origin\" does not support the Git LFS locking API" push.log
|
2017-05-09 15:21:10 +00:00
|
|
|
grep "git config lfs.$endpoint.locksverify false" push.log
|
2017-02-16 20:37:03 +00:00
|
|
|
|
|
|
|
refute_server_object "$reponame" "$contents_oid"
|
2017-02-16 00:26:09 +00:00
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
2017-05-01 21:09:41 +00:00
|
|
|
begin_test "pre-push disable locks verify on exact url"
|
2017-02-16 00:26:09 +00:00
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="lock-disabled-verify-5xx"
|
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
clone_repo "$reponame" "$reponame"
|
|
|
|
|
|
|
|
endpoint="$(repo_endpoint $GITSERVER $reponame)"
|
|
|
|
|
2017-02-16 21:21:41 +00:00
|
|
|
contents="example"
|
|
|
|
contents_oid="$(calc_oid "$contents")"
|
2018-09-10 14:57:10 +00:00
|
|
|
printf "%s" "$contents" > a.dat
|
2017-02-16 00:26:09 +00:00
|
|
|
git lfs track "*.dat"
|
|
|
|
git add .gitattributes a.dat
|
|
|
|
git commit --message "initial commit"
|
|
|
|
|
|
|
|
git config "lfs.$endpoint.locksverify" false
|
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
git push origin main 2>&1 | tee push.log
|
2022-01-27 17:31:41 +00:00
|
|
|
[ "0" -eq "$(grep -c "\"origin\" does not support the Git LFS locking API" push.log)" ]
|
2017-02-16 20:37:03 +00:00
|
|
|
|
2017-02-16 21:21:41 +00:00
|
|
|
assert_server_object "$reponame" "$contents_oid"
|
2017-02-16 00:26:09 +00:00
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
2017-05-01 21:09:41 +00:00
|
|
|
begin_test "pre-push disable locks verify on partial url"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="lock-disabled-verify-5xx-partial"
|
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
clone_repo "$reponame" "$reponame"
|
|
|
|
|
|
|
|
endpoint="$server/$repo"
|
|
|
|
|
|
|
|
contents="example"
|
|
|
|
contents_oid="$(calc_oid "$contents")"
|
2018-09-10 14:57:10 +00:00
|
|
|
printf "%s" "$contents" > a.dat
|
2017-05-01 21:09:41 +00:00
|
|
|
git lfs track "*.dat"
|
|
|
|
git add .gitattributes a.dat
|
|
|
|
git commit --message "initial commit"
|
|
|
|
|
|
|
|
git config "lfs.$endpoint.locksverify" false
|
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
git push origin main 2>&1 | tee push.log
|
2022-01-27 17:31:41 +00:00
|
|
|
[ "0" -eq "$(grep -c "\"origin\" does not support the Git LFS locking API" push.log)" ]
|
2017-05-01 21:09:41 +00:00
|
|
|
|
|
|
|
assert_server_object "$reponame" "$contents_oid"
|
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
2017-10-31 17:23:37 +00:00
|
|
|
begin_test "pre-push locks verify 403 with good ref"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
reponame="lock-verify-main-branch-required"
|
2017-10-31 17:23:37 +00:00
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
clone_repo "$reponame" "$reponame"
|
|
|
|
|
|
|
|
contents="example"
|
|
|
|
contents_oid="$(calc_oid "$contents")"
|
2018-09-10 14:57:10 +00:00
|
|
|
printf "%s" "$contents" > a.dat
|
2017-10-31 17:23:37 +00:00
|
|
|
git lfs track "*.dat"
|
|
|
|
git add .gitattributes a.dat
|
|
|
|
git commit --message "initial commit"
|
|
|
|
|
|
|
|
git config "lfs.$GITSERVER/$reponame.git.locksverify" true
|
2020-06-29 16:18:57 +00:00
|
|
|
git push origin main 2>&1 | tee push.log
|
2017-10-31 17:23:37 +00:00
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
assert_server_object "$reponame" "$contents_oid" "refs/heads/main"
|
2017-10-31 17:23:37 +00:00
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
|
|
|
begin_test "pre-push locks verify 403 with good tracked ref"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
2017-11-08 22:04:40 +00:00
|
|
|
reponame="lock-verify-tracked-branch-required"
|
2017-10-31 17:23:37 +00:00
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
clone_repo "$reponame" "$reponame"
|
|
|
|
|
|
|
|
contents="example"
|
|
|
|
contents_oid="$(calc_oid "$contents")"
|
2018-09-10 14:57:10 +00:00
|
|
|
printf "%s" "$contents" > a.dat
|
2017-10-31 17:23:37 +00:00
|
|
|
git lfs track "*.dat"
|
|
|
|
git add .gitattributes a.dat
|
|
|
|
git commit --message "initial commit"
|
|
|
|
|
2017-11-02 19:30:31 +00:00
|
|
|
git config push.default upstream
|
2020-06-29 16:18:57 +00:00
|
|
|
git config branch.main.merge refs/heads/tracked
|
|
|
|
git config branch.main.remote origin
|
2017-10-31 17:23:37 +00:00
|
|
|
git config "lfs.$GITSERVER/$reponame.git.locksverify" true
|
2017-11-02 19:30:31 +00:00
|
|
|
git push 2>&1 | tee push.log
|
2017-10-31 17:23:37 +00:00
|
|
|
|
2018-01-05 18:12:57 +00:00
|
|
|
assert_server_object "$reponame" "$contents_oid" "refs/heads/tracked"
|
2017-10-31 17:23:37 +00:00
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
2017-11-02 20:21:43 +00:00
|
|
|
begin_test "pre-push locks verify 403 with explicit ref"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
2017-11-08 22:04:40 +00:00
|
|
|
reponame="lock-verify-explicit-branch-required"
|
2017-11-02 20:21:43 +00:00
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
clone_repo "$reponame" "$reponame"
|
|
|
|
|
|
|
|
contents="example"
|
|
|
|
contents_oid="$(calc_oid "$contents")"
|
2018-09-10 14:57:10 +00:00
|
|
|
printf "%s" "$contents" > a.dat
|
2017-11-02 20:21:43 +00:00
|
|
|
git lfs track "*.dat"
|
|
|
|
git add .gitattributes a.dat
|
|
|
|
git commit --message "initial commit"
|
|
|
|
|
|
|
|
git config "lfs.$GITSERVER/$reponame.git.locksverify" true
|
2020-06-29 16:18:57 +00:00
|
|
|
git push origin main:explicit 2>&1 | tee push.log
|
2017-11-02 20:21:43 +00:00
|
|
|
|
2018-01-05 18:12:57 +00:00
|
|
|
assert_server_object "$reponame" "$contents_oid" "refs/heads/explicit"
|
2017-11-02 20:21:43 +00:00
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
2017-10-31 17:23:37 +00:00
|
|
|
begin_test "pre-push locks verify 403 with bad ref"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
2017-11-08 22:04:40 +00:00
|
|
|
reponame="lock-verify-other-branch-required"
|
2017-10-31 17:23:37 +00:00
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
clone_repo "$reponame" "$reponame"
|
|
|
|
|
|
|
|
contents="example"
|
|
|
|
contents_oid="$(calc_oid "$contents")"
|
2018-09-10 14:57:10 +00:00
|
|
|
printf "%s" "$contents" > a.dat
|
2017-10-31 17:23:37 +00:00
|
|
|
git lfs track "*.dat"
|
|
|
|
git add .gitattributes a.dat
|
|
|
|
git commit --message "initial commit"
|
|
|
|
|
|
|
|
git config "lfs.$GITSERVER/$reponame.git.locksverify" true
|
2020-06-29 16:18:57 +00:00
|
|
|
git push origin main 2>&1 | tee push.log
|
2017-10-31 17:23:37 +00:00
|
|
|
grep "failed to push some refs" push.log
|
2018-01-05 18:12:57 +00:00
|
|
|
refute_server_object "$reponame" "$contents_oid" "refs/heads/other"
|
2017-10-31 17:23:37 +00:00
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
2017-02-16 00:26:09 +00:00
|
|
|
begin_test "pre-push locks verify 5xx with verification unset"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="lock-unset-verify-5xx"
|
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
clone_repo "$reponame" "$reponame"
|
|
|
|
|
|
|
|
endpoint="$(repo_endpoint $GITSERVER $reponame)"
|
|
|
|
|
2017-02-16 21:21:41 +00:00
|
|
|
contents="example"
|
|
|
|
contents_oid="$(calc_oid "$contents")"
|
2018-09-10 14:57:10 +00:00
|
|
|
printf "%s" "$contents" > a.dat
|
2017-02-16 00:26:09 +00:00
|
|
|
git lfs track "*.dat"
|
|
|
|
git add .gitattributes a.dat
|
|
|
|
git commit --message "initial commit"
|
|
|
|
|
|
|
|
[ -z "$(git config "lfs.$endpoint.locksverify")" ]
|
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
git push origin main 2>&1 | tee push.log
|
2022-01-27 17:31:41 +00:00
|
|
|
grep "\"origin\" does not support the Git LFS locking API" push.log
|
2017-02-16 20:37:03 +00:00
|
|
|
|
2017-02-16 21:21:41 +00:00
|
|
|
assert_server_object "$reponame" "$contents_oid"
|
2017-02-16 00:26:09 +00:00
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
|
|
|
begin_test "pre-push locks verify 501 with verification enabled"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="lock-enabled-verify-501"
|
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
clone_repo "$reponame" "$reponame"
|
|
|
|
|
|
|
|
endpoint="$(repo_endpoint $GITSERVER $reponame)"
|
|
|
|
|
2017-02-16 20:37:03 +00:00
|
|
|
contents="example"
|
|
|
|
contents_oid="$(calc_oid "$contents")"
|
2018-09-10 14:57:10 +00:00
|
|
|
printf "%s" "$contents" > a.dat
|
2017-02-16 00:26:09 +00:00
|
|
|
git lfs track "*.dat"
|
|
|
|
git add .gitattributes a.dat
|
|
|
|
git commit --message "initial commit"
|
|
|
|
|
|
|
|
git config "lfs.$endpoint.locksverify" true
|
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
git push origin main 2>&1 | tee push.log
|
2017-02-16 00:26:09 +00:00
|
|
|
|
2017-02-16 20:37:03 +00:00
|
|
|
assert_server_object "$reponame" "$contents_oid"
|
2017-02-16 00:26:09 +00:00
|
|
|
[ "false" = "$(git config "lfs.$endpoint.locksverify")" ]
|
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
|
|
|
|
|
|
|
begin_test "pre-push locks verify 501 with verification disabled"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="lock-disabled-verify-501"
|
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
clone_repo "$reponame" "$reponame"
|
|
|
|
|
|
|
|
endpoint="$(repo_endpoint $GITSERVER $reponame)"
|
|
|
|
|
2017-02-16 20:37:03 +00:00
|
|
|
contents="example"
|
|
|
|
contents_oid="$(calc_oid "$contents")"
|
2018-09-10 14:57:10 +00:00
|
|
|
printf "%s" "$contents" > a.dat
|
2017-02-16 00:26:09 +00:00
|
|
|
git lfs track "*.dat"
|
|
|
|
git add .gitattributes a.dat
|
|
|
|
git commit --message "initial commit"
|
|
|
|
|
|
|
|
git config "lfs.$endpoint.locksverify" false
|
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
git push origin main 2>&1 | tee push.log
|
2017-02-16 00:26:09 +00:00
|
|
|
|
2017-02-16 20:37:03 +00:00
|
|
|
assert_server_object "$reponame" "$contents_oid"
|
2017-02-16 00:26:09 +00:00
|
|
|
[ "false" = "$(git config "lfs.$endpoint.locksverify")" ]
|
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
|
|
|
begin_test "pre-push locks verify 501 with verification unset"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="lock-unset-verify-501"
|
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
clone_repo "$reponame" "$reponame"
|
|
|
|
|
|
|
|
endpoint="$(repo_endpoint $GITSERVER $reponame)"
|
|
|
|
|
2017-02-16 20:37:03 +00:00
|
|
|
contents="example"
|
|
|
|
contents_oid="$(calc_oid "$contents")"
|
2018-09-10 14:57:10 +00:00
|
|
|
printf "%s" "$contents" > a.dat
|
2017-02-16 00:26:09 +00:00
|
|
|
git lfs track "*.dat"
|
|
|
|
git add .gitattributes a.dat
|
|
|
|
git commit --message "initial commit"
|
|
|
|
|
|
|
|
[ -z "$(git config "lfs.$endpoint.locksverify")" ]
|
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
git push origin main 2>&1 | tee push.log
|
2017-02-16 00:26:09 +00:00
|
|
|
|
2017-02-16 20:37:03 +00:00
|
|
|
assert_server_object "$reponame" "$contents_oid"
|
2017-02-16 00:26:09 +00:00
|
|
|
[ "false" = "$(git config "lfs.$endpoint.locksverify")" ]
|
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
|
|
|
begin_test "pre-push locks verify 200"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="lock-verify-200"
|
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
clone_repo "$reponame" "$reponame"
|
|
|
|
|
|
|
|
endpoint="$(repo_endpoint $GITSERVER $reponame)"
|
|
|
|
[ -z "$(git config "lfs.$endpoint.locksverify")" ]
|
|
|
|
|
2017-02-16 20:37:03 +00:00
|
|
|
contents="example"
|
|
|
|
contents_oid="$(calc_oid "$contents")"
|
2018-09-10 14:57:10 +00:00
|
|
|
printf "%s" "$contents" > a.dat
|
2017-02-16 00:26:09 +00:00
|
|
|
git lfs track "*.dat"
|
|
|
|
git add .gitattributes a.dat
|
|
|
|
git commit --message "initial commit"
|
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
git push origin main 2>&1 | tee push.log
|
2017-02-16 00:26:09 +00:00
|
|
|
|
|
|
|
grep "Locking support detected on remote \"origin\"." push.log
|
2017-05-09 15:21:10 +00:00
|
|
|
grep "git config lfs.$endpoint.locksverify true" push.log
|
2017-02-16 20:37:03 +00:00
|
|
|
assert_server_object "$reponame" "$contents_oid"
|
2017-02-16 00:26:09 +00:00
|
|
|
)
|
2017-04-17 21:19:03 +00:00
|
|
|
end_test
|
2017-03-29 21:54:16 +00:00
|
|
|
|
|
|
|
begin_test "pre-push locks verify 403 with verification enabled"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="lock-enabled-verify-403"
|
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
clone_repo "$reponame" "$reponame"
|
|
|
|
|
|
|
|
endpoint="$(repo_endpoint $GITSERVER $reponame)"
|
|
|
|
|
|
|
|
contents="example"
|
|
|
|
contents_oid="$(calc_oid "$contents")"
|
2018-09-10 14:57:10 +00:00
|
|
|
printf "%s" "$contents" > a.dat
|
2017-03-29 21:54:16 +00:00
|
|
|
git lfs track "*.dat"
|
|
|
|
git add .gitattributes a.dat
|
|
|
|
git commit --message "initial commit"
|
|
|
|
|
|
|
|
git config "lfs.$endpoint.locksverify" true
|
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
git push origin main 2>&1 | tee push.log
|
2022-01-03 20:45:57 +00:00
|
|
|
grep "error: Authentication error" push.log
|
2017-03-29 21:54:16 +00:00
|
|
|
|
2017-04-27 16:49:15 +00:00
|
|
|
refute_server_object "$reponame" "$contents_oid"
|
2017-03-29 21:54:16 +00:00
|
|
|
[ "true" = "$(git config "lfs.$endpoint.locksverify")" ]
|
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
|
|
|
begin_test "pre-push locks verify 403 with verification disabled"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="lock-disabled-verify-403"
|
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
clone_repo "$reponame" "$reponame"
|
|
|
|
|
|
|
|
endpoint="$(repo_endpoint $GITSERVER $reponame)"
|
|
|
|
|
|
|
|
contents="example"
|
|
|
|
contents_oid="$(calc_oid "$contents")"
|
2018-09-10 14:57:10 +00:00
|
|
|
printf "%s" "$contents" > a.dat
|
2017-03-29 21:54:16 +00:00
|
|
|
git lfs track "*.dat"
|
|
|
|
git add .gitattributes a.dat
|
|
|
|
git commit --message "initial commit"
|
|
|
|
|
|
|
|
git config "lfs.$endpoint.locksverify" false
|
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
git push origin main 2>&1 | tee push.log
|
2017-03-29 21:54:16 +00:00
|
|
|
|
|
|
|
assert_server_object "$reponame" "$contents_oid"
|
|
|
|
[ "false" = "$(git config "lfs.$endpoint.locksverify")" ]
|
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
|
|
|
begin_test "pre-push locks verify 403 with verification unset"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="lock-unset-verify-403"
|
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
clone_repo "$reponame" "$reponame"
|
|
|
|
|
|
|
|
endpoint="$(repo_endpoint $GITSERVER $reponame)"
|
|
|
|
|
|
|
|
contents="example"
|
|
|
|
contents_oid="$(calc_oid "$contents")"
|
2018-09-10 14:57:10 +00:00
|
|
|
printf "%s" "$contents" > a.dat
|
2017-03-29 21:54:16 +00:00
|
|
|
git lfs track "*.dat"
|
|
|
|
git add .gitattributes a.dat
|
|
|
|
git commit --message "initial commit"
|
|
|
|
|
|
|
|
[ -z "$(git config "lfs.$endpoint.locksverify")" ]
|
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
git push origin main 2>&1 | tee push.log
|
2022-01-03 20:45:57 +00:00
|
|
|
grep "warning: Authentication error" push.log
|
2017-03-29 21:54:16 +00:00
|
|
|
|
2017-04-27 17:03:28 +00:00
|
|
|
assert_server_object "$reponame" "$contents_oid"
|
2017-03-29 21:54:16 +00:00
|
|
|
[ -z "$(git config "lfs.$endpoint.locksverify")" ]
|
|
|
|
)
|
|
|
|
end_test
|
2019-03-27 21:41:33 +00:00
|
|
|
|
|
|
|
begin_test "pre-push with pushDefault and explicit remote"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
reponame="pre-push-pushdefault-explicit"
|
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
clone_repo "$reponame" "$reponame"
|
|
|
|
|
|
|
|
git remote add wrong "$(repo_endpoint "$GITSERVER" "wrong-url")"
|
|
|
|
|
|
|
|
git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame").locksverify" false
|
|
|
|
git config remote.pushDefault wrong
|
|
|
|
git lfs track "*.dat"
|
|
|
|
echo "hi" > a.dat
|
|
|
|
git add .gitattributes a.dat
|
|
|
|
git commit -m "add a.dat"
|
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
refute_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 "refs/heads/main"
|
2019-03-27 21:41:33 +00:00
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
GIT_TRACE=1 GIT_TRANSFER_TRACE=1 git push origin main 2>&1 | tee push.log
|
2019-03-27 21:41:33 +00:00
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
assert_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 "refs/heads/main"
|
t: avoid incorrect negated commands
When `set -e` is enabled, not all commands trigger an error exit if they
return false. For example, it's clear that commands in an `if` or
`while` statement don't cause an error if they are false.
What is less obvious, however, is that negated commands and negated
pipelines also have no effect on `set -e`. From POSIX 1003.1-2017 (on
`sh -e`):
When this option is on, if a simple command fails for any of the
reasons listed in Consequences of Shell Errors or returns an exit
status value >0, and is not part of the compound list following a
while, until, or if keyword, and is not a part of an AND or OR list,
and is not a pipeline preceded by the ! reserved word, then the
shell shall immediately exit.
As such, writing something like `! grep` will never fail. Fortunately,
we can append `&& exit 1` instead of the `!` and that will work
correctly.
To make this work, run the following command to make the code properly
check the exit status of our commands:
git grep -l '! [a-z]' t | \
xargs ruby -pi -e '$_.gsub!(/^(\s+)! ([a-z].*)$/, "\\1\\2 && exit 1")'
Because such a command will still have a non-zero exit status, even if
it doesn't trigger `set -e`, add a `true` if this is the last statement
in a block, so that the test exits successfully and therefore passes.
2023-02-13 19:49:59 +00:00
|
|
|
grep wrong-url push.log && exit 1
|
|
|
|
true
|
2019-03-27 21:41:33 +00:00
|
|
|
)
|
|
|
|
end_test
|
2019-08-05 16:39:47 +00:00
|
|
|
|
2020-04-17 14:10:54 +00:00
|
|
|
begin_test "pre-push uses optimization if remote URL matches"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
reponame="pre-push-remote-url-optimization"
|
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
clone_repo "$reponame" "$reponame"
|
|
|
|
|
|
|
|
endpoint=$(git config remote.origin.url)
|
|
|
|
contents_oid=$(calc_oid 'hi\n')
|
|
|
|
git config "lfs.$endpoint.locksverify" false
|
|
|
|
git lfs track "*.dat"
|
|
|
|
echo "hi" > a.dat
|
|
|
|
git add .gitattributes a.dat
|
|
|
|
git commit -m "add a.dat"
|
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
refute_server_object "$reponame" $contents_oid "refs/heads/main"
|
2020-04-17 14:10:54 +00:00
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
GIT_TRACE=1 GIT_TRANSFER_TRACE=1 git push "$endpoint" main 2>&1 | tee push.log
|
2020-04-17 14:10:54 +00:00
|
|
|
grep 'rev-list.*--not --remotes=origin' push.log
|
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
2019-08-05 16:39:47 +00:00
|
|
|
begin_test "pre-push does not traverse Git objects server has"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
reponame="pre-push-traverse-server-objects"
|
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
clone_repo "$reponame" "$reponame"
|
|
|
|
|
|
|
|
endpoint=$(git config remote.origin.url)
|
|
|
|
contents_oid=$(calc_oid 'hi\n')
|
|
|
|
git config "lfs.$endpoint.locksverify" false
|
|
|
|
git lfs track "*.dat"
|
|
|
|
echo "hi" > a.dat
|
|
|
|
git add .gitattributes a.dat
|
|
|
|
git commit -m "add a.dat"
|
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
refute_server_object "$reponame" $contents_oid "refs/heads/main"
|
2019-08-05 16:39:47 +00:00
|
|
|
|
2020-04-17 14:10:54 +00:00
|
|
|
# We use a different URL instead of a named remote or the remote URL so that
|
|
|
|
# we can't make use of the optimization that ignores objects we already have
|
|
|
|
# in remote tracking branches.
|
2020-06-29 16:18:57 +00:00
|
|
|
GIT_TRACE=1 GIT_TRANSFER_TRACE=1 git push "$endpoint.git" main 2>&1 | tee push.log
|
2019-08-05 16:39:47 +00:00
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
assert_server_object "$reponame" $contents_oid "refs/heads/main"
|
2019-08-05 16:39:47 +00:00
|
|
|
|
|
|
|
contents2_oid=$(calc_oid 'hello\n')
|
|
|
|
echo "hello" > b.dat
|
|
|
|
git add .gitattributes b.dat
|
|
|
|
git commit -m "add b.dat"
|
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
refute_server_object "$reponame" $contents2_oid "refs/heads/main"
|
2019-08-05 16:39:47 +00:00
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
GIT_TRACE=1 GIT_TRANSFER_TRACE=1 git push "$endpoint.git" main 2>&1 | tee push.log
|
2019-08-05 16:39:47 +00:00
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
assert_server_object "$reponame" $contents2_oid "refs/heads/main"
|
2019-08-05 16:39:47 +00:00
|
|
|
|
|
|
|
# Verify that we haven't tried to push or query for the object we already
|
|
|
|
# pushed before; i.e., we didn't see it because we ignored its Git object
|
|
|
|
# during traversal.
|
t: avoid incorrect negated commands
When `set -e` is enabled, not all commands trigger an error exit if they
return false. For example, it's clear that commands in an `if` or
`while` statement don't cause an error if they are false.
What is less obvious, however, is that negated commands and negated
pipelines also have no effect on `set -e`. From POSIX 1003.1-2017 (on
`sh -e`):
When this option is on, if a simple command fails for any of the
reasons listed in Consequences of Shell Errors or returns an exit
status value >0, and is not part of the compound list following a
while, until, or if keyword, and is not a part of an AND or OR list,
and is not a pipeline preceded by the ! reserved word, then the
shell shall immediately exit.
As such, writing something like `! grep` will never fail. Fortunately,
we can append `&& exit 1` instead of the `!` and that will work
correctly.
To make this work, run the following command to make the code properly
check the exit status of our commands:
git grep -l '! [a-z]' t | \
xargs ruby -pi -e '$_.gsub!(/^(\s+)! ([a-z].*)$/, "\\1\\2 && exit 1")'
Because such a command will still have a non-zero exit status, even if
it doesn't trigger `set -e`, add a `true` if this is the last statement
in a block, so that the test exits successfully and therefore passes.
2023-02-13 19:49:59 +00:00
|
|
|
grep $contents_oid push.log && exit 1
|
|
|
|
true
|
2019-08-05 16:39:47 +00:00
|
|
|
)
|
|
|
|
end_test
|
2020-04-16 20:55:23 +00:00
|
|
|
|
|
|
|
begin_test "pre-push with force-pushed ref"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
reponame="pre-push-force-pushed-ref"
|
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
clone_repo "$reponame" "$reponame"
|
|
|
|
|
|
|
|
git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame").locksverify" false
|
|
|
|
git lfs track "*.dat"
|
|
|
|
echo "hi" > a.dat
|
|
|
|
git add .gitattributes a.dat
|
|
|
|
git commit -m "add a.dat"
|
|
|
|
git tag -a -m tagname tagname
|
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
refute_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 "refs/heads/main"
|
2020-04-16 20:55:23 +00:00
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
git push origin main tagname
|
2020-04-16 20:55:23 +00:00
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
assert_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 "refs/heads/main"
|
2020-04-16 20:55:23 +00:00
|
|
|
|
|
|
|
# We pick a different message so that we get different object IDs even if both
|
|
|
|
# commands run in the same second.
|
|
|
|
git tag -f -a -m tagname2 tagname
|
|
|
|
# Prune the old tag object.
|
|
|
|
git reflog expire --all --expire=now
|
|
|
|
git gc --prune=now
|
|
|
|
# Make sure we deal with us missing the object for the old value of the tag ref.
|
|
|
|
git push origin +tagname
|
|
|
|
)
|
|
|
|
end_test
|
2020-05-04 21:14:49 +00:00
|
|
|
|
|
|
|
begin_test "pre-push with local path"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
reponame="pre-push-local-path"
|
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
clone_repo "$reponame" "$reponame-2"
|
|
|
|
cd ..
|
|
|
|
clone_repo "$reponame" "$reponame"
|
|
|
|
|
|
|
|
git lfs track "*.dat"
|
|
|
|
echo "hi" > a.dat
|
|
|
|
git add .gitattributes a.dat
|
|
|
|
git commit -m "add a.dat"
|
|
|
|
|
|
|
|
# Push to the other repo.
|
2020-06-29 16:18:57 +00:00
|
|
|
git push "../$reponame-2" main:foo
|
2020-05-04 21:14:49 +00:00
|
|
|
|
|
|
|
# Push to . to make sure that works.
|
2020-06-29 16:18:57 +00:00
|
|
|
git push "." main:foo
|
2020-05-04 21:14:49 +00:00
|
|
|
|
|
|
|
git lfs fsck
|
|
|
|
cd "../$reponame-2"
|
|
|
|
git checkout foo
|
|
|
|
git lfs fsck
|
|
|
|
)
|
|
|
|
end_test
|