Skip to content

Conversation

@chrisd8088
Copy link
Member

@chrisd8088 chrisd8088 commented Apr 25, 2022

Several existing tests ensure that the git lfs prune command always retains Git LFS objects referenced by unpushed commits, stashes, and worktrees.

However, none of these tests perform checks of the appropriate behaviour when files matching an lfs.fetchexclude filter option are involved. Support for pruning Git LFS objects referenced by files matching the lfs.fetchexclude filter was added in PR #2851. (Support for retaining objects referenced by stashes was added later, in PR #4209).

We therefore expand these tests to check for the expected behaviour, which varies depending on the specific case.

For Git LFS objects referenced only by files in unpushed commits or any type of stash (normal, index, or untracked), we now confirm that even if the files' names match a pattern in lfs.fetchexclude, we still retain the objects locally when git lfs prune is run.

For Git LFS objects referenced only by files in a commit at the HEAD of a worktree, we now confirm that if the files' names match a pattern in lfs.fetchexclude, then the objects are pruned locally when git lfs prune is run. This matches how similar files' objects are pruned even if they are referenced by a regular working tree's HEAD commit.

It may be advantageous to review this PR commit-by-commit as each commit's description provides additional context and details.

Note that we explicitly use a gitattributes(5)-compatible form of pattern match (i.e., /foo/**) for the lfs.fetchexclude options in these changes because otherwise we will see failures as per #4945. When that issue is addressed in a future PR we will revise these tests to use the /foo pattern match form in order to demonstrate that gitignore(5)-style matching is being performed.

/cc @larsxschneider as author of #2851.

The "prune keep unpushed" test ensures that Git LFS objects
referenced by unpushed commits are always retained when the
"git lfs prune" command is run.

However, it does not at present check that objects belonging to
files which match a "lfs.fetchexclude" pattern, which would
otherwise be pruned regardless of their status, will be retained
because they have not yet been pushed.  Logic in the "git lfs prune"
command to prune objects from files matching the "lfs.fetchexclude"
filter was added in PR git-lfs#2851, and it should demonstrate this
behaviour, but no checks actually confirm it.

We therefore expand the "prune keep unpushed" test so that its
simulated commit history includes objects whose file path matches
a path we then exclude using the "lfs.fetchexclude" filter.  We then
confirm that all these objects are retained by "git lfs prune" until
they are pushed, after which they are all pruned by the same command,
even the object referenced by the new HEAD ref.
The "prune keep stashed changes", "prune keep stashed changes
in index", and "prune keep stashed untracked files" tests ensure
that Git LFS objects referenced by stashes are always retained
when the "git lfs prune" command is run.

However, they do not at present check that objects belonging to
files which match a "lfs.fetchexclude" pattern, which would
otherwise be pruned regardless of their status, will be retained
because they have been stashed.  Logic in the "git lfs prune"
command to retain objects from stashed changes was added in
PR git-lfs#4209, and it should demonstrate this behaviour, but no checks
actually confirm it.

We therefore expand these three tests so that their simulated
commit histories include objects whose file path matches a path we
then exclude using the "lfs.fetchexclude" filter.  We then confirm
that all these objects are retained by "git lfs prune" when they are
stashed, included when they are stashed from the index and when they
are untracked files stashed with "git stash -u".
The "prune worktree" test ensures that Git LFS objects
referenced by worktrees are always retained when the "git lfs
prune" command is run.

However, it does not at present check that objects belonging to
files which match a "lfs.fetchexclude" pattern are pruned even
when they are referenced by a commit at the HEAD of a worktree.
Logic in the "git lfs prune" command to prune objects from files
matching the "lfs.fetchexclude" filter was added in PR git-lfs#2851,
and it should demonstrate this behaviour, but no checks actually
confirm it.

We therefore expand the "prune worktree" test so that its
simulated commit history includes objects in each worktree's
branch whose file path matches a path we then exclude using the
"lfs.fetchexclude" filter.  We then confirm that these objects
are pruned by "git lfs prune", despite being referenced by the
worktrees' HEAD refs.
@chrisd8088 chrisd8088 requested a review from a team as a code owner April 25, 2022 18:47
@chrisd8088 chrisd8088 merged commit bb25ccf into git-lfs:main Apr 26, 2022
@chrisd8088 chrisd8088 deleted the prune-check-excluded-files branch April 26, 2022 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants