Apply lfs.fetchexclude
filter to previous commits when pruning
#4968
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In PR #2851 the
git lfs prune
command was changed to respect thelfs.fetchexclude
configuration option such that objects would always be pruned if they were referenced by files whose paths matched one of the patterns in the configuration option (unless they were referenced by an unpushed commit).However, while this filter was applied to files referenced by recent refs (including
HEAD
), it was not applied to files referenced only by recent commits previous to a recent ref. This can result in the unexpected consequence that an object inHEAD
is pruned because it is referenced only by a file that matches thelfs.fetchexclude
filter, but a recent previous version of the object is not pruned despite also only being referenced by the same file.We therefore add equivalent filtering to the
logPreviousSHAs()
internal function which is called by theScanPreviousVersions()
GitScanner
method used bypruneTaskGetPreviousVersionsOfRef()
in thegit lfs prune
command's main phase.(Note that in PR #1743 the Git log scanning functions were refactored, and a common
parseScannerLogOutput()
internal function was created to be used when performing log scans duringgit lfs prune
commands. This replaced the originallogPreviousSHAs()
function, which had support for path-based filtering; however, that functionality was apparently never used.)We also add a test which confirms that
git lfs prune
respects thelfs.fetchexclude
configuration option insofar as it prunes Git LFS objects for files whose paths match a pattern in the filter, both when they appear in commits directly referenced by a recent ref and when they only appear in commits previous to those.Note that we explicitly use a
gitattributes(5)
-compatible form of pattern match (i.e.,/foo/**
) for thelfs.fetchexclude
options in this new test because otherwise we will see failures as per #4945. When that issue is addressed in a future PR we will revise this test to use the/foo
pattern match form in order to demonstrate thatgitignore(5)
-style matching is being performed.Note too that we add one extra check to the existing
"prune unreferenced and old"
test for consistency with our new test./cc @larsxschneider as author of #2851.