2018-07-05 17:18:59 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2018-07-10 18:48:02 +00:00
|
|
|
. "$(dirname "$0")/testlib.sh"
|
2018-07-05 17:18:59 +00:00
|
|
|
|
2018-07-05 17:23:49 +00:00
|
|
|
begin_test "push with missing objects (lfs.allowincompletepush true)"
|
2018-07-05 17:18:59 +00:00
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="push-with-missing-objects"
|
|
|
|
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
|
2018-07-05 17:18:59 +00:00
|
|
|
|
|
|
|
missing="missing"
|
|
|
|
missing_oid="$(calc_oid "$missing")"
|
2018-09-10 14:57:10 +00:00
|
|
|
printf "%s" "$missing" > missing.dat
|
2018-07-05 17:18:59 +00:00
|
|
|
|
|
|
|
git add missing.dat present.dat
|
|
|
|
git commit -m "add objects"
|
|
|
|
|
|
|
|
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"
|
|
|
|
|
2018-07-05 17:23:49 +00:00
|
|
|
git config lfs.allowincompletepush true
|
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
git push origin main 2>&1 | tee push.log
|
2018-07-05 17:18:59 +00:00
|
|
|
if [ "0" -ne "${PIPESTATUS[0]}" ]; then
|
2020-06-29 16:18:57 +00:00
|
|
|
echo >&2 "fatal: expected \`git push origin main\` to succeed ..."
|
2018-07-05 17:18:59 +00:00
|
|
|
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 "push reject missing objects (lfs.allowincompletepush false)"
|
2018-07-05 17:18:59 +00:00
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="push-reject-missing-objects"
|
|
|
|
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
|
2018-07-05 17:18:59 +00:00
|
|
|
|
|
|
|
missing="missing"
|
|
|
|
missing_oid="$(calc_oid "$missing")"
|
2018-09-10 14:57:10 +00:00
|
|
|
printf "%s" "$missing" > missing.dat
|
2018-07-05 17:18:59 +00:00
|
|
|
|
|
|
|
git add missing.dat present.dat
|
|
|
|
git commit -m "add objects"
|
|
|
|
|
|
|
|
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"
|
|
|
|
|
2018-07-05 17:23:49 +00:00
|
|
|
git config lfs.allowincompletepush false
|
2018-07-05 17:18:59 +00:00
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
git push origin main 2>&1 | tee push.log
|
2018-07-05 17:18:59 +00:00
|
|
|
if [ "1" -ne "${PIPESTATUS[0]}" ]; then
|
2020-06-29 16:18:57 +00:00
|
|
|
echo >&2 "fatal: expected \`git push origin main\` to succeed ..."
|
2018-07-05 17:18:59 +00:00
|
|
|
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
|
2018-07-05 17:18:59 +00:00
|
|
|
|
|
|
|
refute_server_object "$reponame" "$present_oid"
|
|
|
|
refute_server_object "$reponame" "$missing_oid"
|
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
2018-07-05 17:23:49 +00:00
|
|
|
begin_test "push reject missing objects (lfs.allowincompletepush default)"
|
2018-07-05 17:18:59 +00:00
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="push-missing-objects"
|
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
clone_repo "$reponame" "$reponame"
|
|
|
|
|
|
|
|
git lfs track "*.dat"
|
|
|
|
git add .gitattributes
|
|
|
|
git commit -m "initial commit"
|
|
|
|
|
|
|
|
missing="missing"
|
|
|
|
missing_oid="$(calc_oid "$missing")"
|
2018-09-10 14:57:10 +00:00
|
|
|
missing_len="$(printf "%s" "$missing" | wc -c | awk '{ print $1 }')"
|
|
|
|
printf "%s" "$missing" > missing.dat
|
2018-07-05 17:18:59 +00:00
|
|
|
git add missing.dat
|
|
|
|
git commit -m "add missing.dat"
|
|
|
|
|
|
|
|
present="present"
|
|
|
|
present_oid="$(calc_oid "$present")"
|
2018-09-10 14:57:10 +00:00
|
|
|
present_len="$(printf "%s" "$present" | wc -c | awk '{ print $1 }')"
|
|
|
|
printf "%s" "$present" > present.dat
|
2018-07-05 17:18:59 +00:00
|
|
|
git add present.dat
|
|
|
|
git commit -m "add present.dat"
|
|
|
|
|
|
|
|
assert_local_object "$missing_oid" "$missing_len"
|
|
|
|
assert_local_object "$present_oid" "$present_len"
|
|
|
|
|
|
|
|
delete_local_object "$missing_oid"
|
|
|
|
|
|
|
|
refute_local_object "$missing_oid"
|
|
|
|
assert_local_object "$present_oid" "$present_len"
|
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
git push origin main 2>&1 | tee push.log
|
2018-07-05 17:18:59 +00:00
|
|
|
|
|
|
|
if [ "0" -eq "${PIPESTATUS[0]}" ]; then
|
2020-06-29 16:18:57 +00:00
|
|
|
echo >&2 "fatal: expected 'git push origin main' to exit with non-zero code"
|
2018-07-05 17:18:59 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
grep "LFS upload failed:" push.log
|
|
|
|
grep " (missing) missing.dat ($missing_oid)" push.log
|
|
|
|
|
|
|
|
refute_server_object "$reponame" "$missing_oid"
|
|
|
|
assert_server_object "$reponame" "$present_oid"
|
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
2018-07-05 17:23:49 +00:00
|
|
|
begin_test "push reject corrupt objects (lfs.allowincompletepush default)"
|
2018-07-05 17:18:59 +00:00
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="push-corrupt-objects"
|
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
clone_repo "$reponame" "$reponame"
|
|
|
|
|
|
|
|
git lfs track "*.dat"
|
|
|
|
git add .gitattributes
|
|
|
|
git commit -m "initial commit"
|
|
|
|
|
|
|
|
corrupt="corrupt"
|
|
|
|
corrupt_oid="$(calc_oid "$corrupt")"
|
2018-09-10 14:57:10 +00:00
|
|
|
corrupt_len="$(printf "%s" "$corrupt" | wc -c | awk '{ print $1 }')"
|
|
|
|
printf "%s" "$corrupt" > corrupt.dat
|
2018-07-05 17:18:59 +00:00
|
|
|
git add corrupt.dat
|
|
|
|
git commit -m "add corrupt.dat"
|
|
|
|
|
|
|
|
present="present"
|
|
|
|
present_oid="$(calc_oid "$present")"
|
2018-09-10 14:57:10 +00:00
|
|
|
present_len="$(printf "%s" "$present" | wc -c | awk '{ print $1 }')"
|
|
|
|
printf "%s" "$present" > present.dat
|
2018-07-05 17:18:59 +00:00
|
|
|
git add present.dat
|
|
|
|
git commit -m "add present.dat"
|
|
|
|
|
|
|
|
assert_local_object "$corrupt_oid" "$corrupt_len"
|
|
|
|
assert_local_object "$present_oid" "$present_len"
|
|
|
|
|
|
|
|
corrupt_local_object "$corrupt_oid"
|
|
|
|
|
|
|
|
refute_local_object "$corrupt_oid" "$corrupt_len"
|
|
|
|
assert_local_object "$present_oid" "$present_len"
|
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
git push origin main 2>&1 | tee push.log
|
2018-07-05 17:18:59 +00:00
|
|
|
|
|
|
|
if [ "0" -eq "${PIPESTATUS[0]}" ]; then
|
2020-06-29 16:18:57 +00:00
|
|
|
echo >&2 "fatal: expected 'git push origin main' to exit with non-zero code"
|
2018-07-05 17:18:59 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
grep "LFS upload failed:" push.log
|
|
|
|
grep " (corrupt) corrupt.dat ($corrupt_oid)" push.log
|
|
|
|
|
|
|
|
refute_server_object "$reponame" "$corrupt_oid"
|
|
|
|
assert_server_object "$reponame" "$present_oid"
|
|
|
|
)
|
|
|
|
end_test
|