t/t-prune.sh: add tag check to unpushed test

In PR #742 the "git lfs prune" command was introduced along with
accompanying tests, one of which is the "prune keep unpushed"
test that checks whether Git LFS objects referenced by not-yet-
pushed commits are always retained by "git lfs prune".

In commit 978899e3b538bdd7df0873c2b50d229d5748605d of that PR
the initial version of the "prune" tests included some fixture
data with commits that were referenced via a tag only, not via
a branch ref.  However, the test never confirmed that the Git LFS
objects in these commits were retained by the "prune" command.

This initial test was then refactored into several tests in
commits 03b85e08acf727428c4e9c0d805f5a8a3da501e7 and
58dfa23c9e87bd638eb2bd7b4c8e208eab8031e7, including the "prune
keep unpushed" one, and in the process two lines were left
which referred to the fixture data ("oid_keepunpushedtagged1"
and "oid_keepunpushedtagged2") but this data was otherwise
dropped from the test, and no tag check was implemented.

We therefore re-introduce some fixture data for this test
which simulates a tag that points to a commit from a deleted
branch, so that the tag is the only reference to this commit
and its ancestors.  We then ensure that "git lfs prune" retains
all the Git LFS objects from these commits, even if they
are not recent, when they have not been pushed.  Once they are
pushed, we then confirm that only the object in the tagged commit
is retained (because it is a referenced by a recent ref).

We also update a comment in the "prune unreferenced and old"
test which refers to a filename in its fixture data that
corresponds to how it was originally defined in commit
978899e3b538bdd7df0873c2b50d229d5748605d, but which was
subsequently changed (at the same time the comment was added)
in commit 03b85e08acf727428c4e9c0d805f5a8a3da501e7.
This commit is contained in:
Chris Darroch 2022-04-24 16:14:58 -07:00
parent 54f101f87e
commit cb151ee89f

@ -28,9 +28,9 @@ begin_test "prune unreferenced and old"
# Remember for something to be 'too old' it has to appear on the MINUS side
# of the diff outside the prune window, i.e. it's not when it was introduced
# but when it disappeared from relevance. That's why changes to file1.dat on main
# but when it disappeared from relevance. That's why changes to old.dat on main
# from 7d ago are included even though the commit itself is outside of the window,
# that content of file1.dat was relevant until it was removed with a commit, inside the window
# that content of old.dat was relevant until it was removed with a commit, inside the window
# think of it as windows of relevance that overlap until the content is replaced
# we also make sure we commit today on main so that the recent commits measured
@ -115,14 +115,18 @@ begin_test "prune keep unpushed"
content_keepunpushedbranch1="Keep: unpushed second branch 1"
content_keepunpushedbranch2="Keep: unpushed second branch 2"
content_keepunpushedbranch3="Keep: unpushed second branch 3"
content_keepunpushedtag1="Keep: unpushed tag only 1"
content_keepunpushedtag2="Keep: unpushed tag only 2"
content_keepunpushedtag3="Keep: unpushed tag only 3"
oid_keepunpushedhead1=$(calc_oid "$content_keepunpushedhead1")
oid_keepunpushedhead2=$(calc_oid "$content_keepunpushedhead2")
oid_keepunpushedhead3=$(calc_oid "$content_keepunpushedhead3")
oid_keepunpushedbranch1=$(calc_oid "$content_keepunpushedbranch1")
oid_keepunpushedbranch2=$(calc_oid "$content_keepunpushedbranch2")
oid_keepunpushedbranch3=$(calc_oid "$content_keepunpushedbranch3")
oid_keepunpushedtagged1=$(calc_oid "$content_keepunpushedtagged1")
oid_keepunpushedtagged2=$(calc_oid "$content_keepunpushedtagged1")
oid_keepunpushedtag1=$(calc_oid "$content_keepunpushedtag1")
oid_keepunpushedtag2=$(calc_oid "$content_keepunpushedtag2")
oid_keepunpushedtag3=$(calc_oid "$content_keepunpushedtag3")
echo "[
{
@ -147,6 +151,24 @@ begin_test "prune keep unpushed"
\"Files\":[
{\"Filename\":\"file.dat\",\"Size\":${#content_keepunpushedbranch3}, \"Data\":\"$content_keepunpushedbranch3\"}]
},
{
\"CommitDate\":\"$(get_date -31d)\",
\"ParentBranches\":[\"main\"],
\"NewBranch\":\"branch_unpushed_tagged_only\",
\"Files\":[
{\"Filename\":\"file2.dat\",\"Size\":${#content_keepunpushedtag1}, \"Data\":\"$content_keepunpushedtag1\"}]
},
{
\"CommitDate\":\"$(get_date -16d)\",
\"Files\":[
{\"Filename\":\"file2.dat\",\"Size\":${#content_keepunpushedtag2}, \"Data\":\"$content_keepunpushedtag2\"}]
},
{
\"CommitDate\":\"$(get_date -2d)\",
\"Tags\":[\"tag_unpushed\"],
\"Files\":[
{\"Filename\":\"file2.dat\",\"Size\":${#content_keepunpushedtag3}, \"Data\":\"$content_keepunpushedtag3\"}]
},
{
\"CommitDate\":\"$(get_date -21d)\",
\"ParentBranches\":[\"main\"],
@ -168,39 +190,49 @@ begin_test "prune keep unpushed"
# force color codes in git diff meta-information
git config color.diff always
git branch -D branch_unpushed_tagged_only
git lfs prune
# Now push main and show that only older versions on main will be removed.
git push origin main
git lfs prune --verbose 2>&1 | tee prune.log
grep "prune: 6 local objects, 4 retained" prune.log
grep "prune: 9 local objects, 7 retained" prune.log
grep "prune: Deleting objects: 100% (2/2), done." prune.log
grep "$oid_keepunpushedhead1" prune.log
grep "$oid_keepunpushedhead2" prune.log
refute_local_object "$oid_keepunpushedhead1"
refute_local_object "$oid_keepunpushedhead2"
# Merge the unpushed branch, delete it, and then push main.
# Merge the unpushed branch and tag, delete them, and then push main.
# Resolve conflicts by taking other branch.
git merge -Xtheirs branch_unpushed
git merge tag_unpushed
git branch -D branch_unpushed
git tag -d tag_unpushed
git push origin main
# Now make sure we purged all the intermediate commits but also make sure
# they are on the remote.
git lfs prune --verbose 2>&1 | tee prune.log
grep "prune: 4 local objects, 1 retained" prune.log
grep "prune: Deleting objects: 100% (3/3), done." prune.log
grep "prune: 7 local objects, 2 retained" prune.log
grep "prune: Deleting objects: 100% (5/5), done." prune.log
grep "$oid_keepunpushedbranch1" prune.log
grep "$oid_keepunpushedbranch2" prune.log
grep "$oid_keepunpushedtag1" prune.log
grep "$oid_keepunpushedtag2" prune.log
grep "$oid_keepunpushedhead3" prune.log
refute_local_object "$oid_keepunpushedbranch1"
refute_local_object "$oid_keepunpushedbranch2"
refute_local_object "$oid_keepunpushedtag1"
refute_local_object "$oid_keepunpushedtag2"
# We used -Xtheirs when merging the branch so the old HEAD is now obsolete.
refute_local_object "$oid_keepunpushedhead3"
assert_server_object "remote_$reponame" "$oid_keepunpushedbranch1"
assert_server_object "remote_$reponame" "$oid_keepunpushedbranch2"
assert_server_object "remote_$reponame" "$oid_keepunpushedtag1"
assert_server_object "remote_$reponame" "$oid_keepunpushedtag2"
assert_server_object "remote_$reponame" "$oid_keepunpushedhead3"
)
end_test