t: test additional stashed objects with prune

In each of our tests of the "git lfs prune" command
when it follows the "git stash" command, we add LFS
objects on a branch and stash them before the branch
is deleted.  In all cases we expect the additional
stashed objects to be retained by "git lfs prune"
while unreferenced objects on the deleted branch are
pruned.

Note that these chnanges also ensure we are test
the "git lfs prune" command with multiple stashed
entries rather than just a single stash entry.
This commit is contained in:
Chris Darroch 2021-03-23 23:27:38 -07:00
parent 46c06171d2
commit fbac6e0a90

@ -619,6 +619,8 @@ begin_test "prune keep stashed changes"
oid_inrepo=$(calc_oid "$content_inrepo")
content_stashed="This data will be stashed and should not be deleted"
oid_stashed=$(calc_oid "$content_stashed")
content_stashedbranch="This data will be stashed on a branch and should not be deleted"
oid_stashedbranch=$(calc_oid "$content_stashedbranch")
# We need to test with older commits to ensure they get pruned as expected
echo "[
@ -654,20 +656,27 @@ begin_test "prune keep stashed changes"
# now modify the file, and stash it
printf '%s' "$content_stashed" > stashedfile.dat
git stash
# Switch to a branch, modify a file, stash it, and delete the branch
git checkout branch_to_delete
printf '%s' "$content_stashedbranch" > unreferenced.dat
git stash
git checkout main
git branch -D branch_to_delete
# Prove that the stashed data was stored in LFS (should call clean filter)
assert_local_object "$oid_stashed" "${#content_stashed}"
assert_local_object "$oid_stashedbranch" "${#content_stashedbranch}"
# Prune data, should NOT delete stashed file
# Prune data, should NOT delete stashed files
git lfs prune
refute_local_object "$oid_oldandpushed" "${#content_oldandpushed}"
refute_local_object "$oid_unreferenced" "${#content_unreferenced}"
assert_local_object "$oid_retain1" "${#content_retain1}"
assert_local_object "$oid_stashed" "${#content_stashed}"
assert_local_object "$oid_stashedbranch" "${#content_stashedbranch}"
)
end_test
@ -697,6 +706,10 @@ begin_test "prune keep stashed changes in index"
oid_indexstashed=$(calc_oid "$content_indexstashed")
content_stashed="This data will be stashed and should not be deleted"
oid_stashed=$(calc_oid "$content_stashed")
content_indexstashedbranch="This data will be stashed on a branch from the index and should not be deleted"
oid_indexstashedbranch=$(calc_oid "$content_indexstashedbranch")
content_stashedbranch="This data will be stashed on a branch and should not be deleted"
oid_stashedbranch=$(calc_oid "$content_stashedbranch")
# We need to test with older commits to ensure they get pruned as expected
echo "[
@ -736,13 +749,23 @@ begin_test "prune keep stashed changes in index"
# now modify the file again, and stash it
printf '%s' "$content_stashed" > stashedfile.dat
git stash
# Switch to a branch, modify a file in the index and working tree, stash it,
# and delete the branch
git checkout branch_to_delete
printf '%s' "$content_indexstashedbranch" > unreferenced.dat
git add unreferenced.dat
printf '%s' "$content_stashedbranch" > unreferenced.dat
git stash
git checkout main
git branch -D branch_to_delete
# Prove that the stashed data was stored in LFS (should call clean filter)
assert_local_object "$oid_indexstashed" "${#content_indexstashed}"
assert_local_object "$oid_stashed" "${#content_stashed}"
assert_local_object "$oid_indexstashedbranch" "${#content_indexstashedbranch}"
assert_local_object "$oid_stashedbranch" "${#content_stashedbranch}"
# Prune data, should NOT delete stashed file or stashed changes to index
git lfs prune
@ -752,6 +775,8 @@ begin_test "prune keep stashed changes in index"
assert_local_object "$oid_retain1" "${#content_retain1}"
assert_local_object "$oid_indexstashed" "${#content_indexstashed}"
assert_local_object "$oid_stashed" "${#content_stashed}"
assert_local_object "$oid_indexstashedbranch" "${#content_indexstashedbranch}"
assert_local_object "$oid_stashedbranch" "${#content_stashedbranch}"
)
end_test
@ -767,6 +792,11 @@ begin_test "prune keep stashed untracked files"
git lfs track "*.dat" 2>&1 | tee track.log
grep "Tracking \"\*.dat\"" track.log
# Commit .gitattributes first so it is not removed by "git stash -u" and then
# not restored when we checkout the branch and try to modify LFS objects.
git add .gitattributes
git commit -m attribs
# generate content we'll use
content_oldandpushed="To delete: pushed and too old"
oid_oldandpushed=$(calc_oid "$content_oldandpushed")
@ -783,6 +813,12 @@ begin_test "prune keep stashed untracked files"
oid_stashed=$(calc_oid "$content_stashed")
content_untrackedstashed="This UNTRACKED FILE data will be stashed and should not be deleted"
oid_untrackedstashed=$(calc_oid "$content_untrackedstashed")
content_indexstashedbranch="This data will be stashed on a branch from the index and should not be deleted"
oid_indexstashedbranch=$(calc_oid "$content_indexstashedbranch")
content_stashedbranch="This data will be stashed on a branch and should not be deleted"
oid_stashedbranch=$(calc_oid "$content_stashedbranch")
content_untrackedstashedbranch="This UNTRACKED FILE data will be stashed on a branch and should not be deleted"
oid_untrackedstashedbranch=$(calc_oid "$content_untrackedstashedbranch")
# We need to test with older commits to ensure they get pruned as expected
echo "[
@ -828,12 +864,25 @@ begin_test "prune keep stashed untracked files"
# stash, including untracked
git stash -u
# Switch to a branch, modify a file in the index and working tree,
# create an untracked file, stash them, and delete the branch
git checkout branch_to_delete
printf '%s' "$content_indexstashedbranch" > unreferenced.dat
git add unreferenced.dat
printf '%s' "$content_stashedbranch" > unreferenced.dat
printf '%s' "$content_untrackedstashedbranch" > untrackedfile.dat
git stash -u
git checkout main
git branch -D branch_to_delete
# Prove that ALL stashed data was stored in LFS (should call clean filter)
assert_local_object "$oid_indexstashed" "${#content_indexstashed}"
assert_local_object "$oid_stashed" "${#content_stashed}"
assert_local_object "$oid_untrackedstashed" "${#content_untrackedstashed}"
assert_local_object "$oid_indexstashedbranch" "${#content_indexstashedbranch}"
assert_local_object "$oid_stashedbranch" "${#content_stashedbranch}"
assert_local_object "$oid_untrackedstashedbranch" "${#content_untrackedstashedbranch}"
# Prune data, should NOT delete stashed file or stashed changes to index
git lfs prune
@ -844,6 +893,9 @@ begin_test "prune keep stashed untracked files"
assert_local_object "$oid_indexstashed" "${#content_indexstashed}"
assert_local_object "$oid_stashed" "${#content_stashed}"
assert_local_object "$oid_untrackedstashed" "${#content_untrackedstashed}"
assert_local_object "$oid_indexstashedbranch" "${#content_indexstashedbranch}"
assert_local_object "$oid_stashedbranch" "${#content_stashedbranch}"
assert_local_object "$oid_untrackedstashedbranch" "${#content_untrackedstashedbranch}"
)
end_test