Fix git lfs prune is deleting staged files in the index#5637
Fix git lfs prune is deleting staged files in the index#5637bk2204 merged 6 commits intogit-lfs:mainfrom
Conversation
bk2204
left a comment
There was a problem hiding this comment.
I think there's a situation with multiple worktrees we'll probably want to handle here (and some tests for that case would be helpful as well). In addition, it looks like we're failing some tests, too.
commands/command_prune.go
Outdated
| func pruneTaskGetRetainedIndex(gitscanner *lfs.GitScanner, retainChan chan string, errorChan chan error, waitg *sync.WaitGroup, sem *semaphore.Weighted) { | ||
| defer waitg.Done() | ||
|
|
||
| err := gitscanner.ScanIndex("HEAD", func(p *lfs.WrappedPointer, err error) { |
There was a problem hiding this comment.
We probably want to handle multiple indices, one for each worktree. It might therefore be helpful to call this from pruneTaskGetRetainedWorktree. If we don't do that, we might produce wrong results if I do git add in worktree A and then git lfs prune in another worktree.
|
Good point, I'll take a look at this |
|
I do also want to just say thanks for sending a patch for this before we even got a chance to look at the issue. I'm overall really happy with the direction this is going in. |
Sure thing, I appreciate that you guys are very busy and would like to increase the likelihood of this being fixed. I am actually a little bit stuck how to implement this for worktrees. The problem is that to use git diff-index I'd need to |
The way I would do this is to pass an additional argument to |
Makes perfect sense, thanks for your input. I'll update the PR once I'd like some feedback! |
Running git lfs prune right after git add will prune the indexed files from the LFS cache so that any commit will result in a rightfully rejected push. Even worse, doing multiple commits on changes of the same file will permanently delete LFS data that is not recoverable. This change retains all files that are in the indices of all worktrees by diffing each index against the corresponding HEAD.
|
@bk2204 I have force pushed a new solution taking worktrees into account |
|
It looks like we still have one or two failing tests here. Once that's fixed, I'll do a final review. |
… e.g. for bare repositories
|
@bk2204 yeah, it was failing with git 2.0.0 as no worktrees were supported back then and the git.go RootDir() function was not handling missing working directories correctly. Should be all green now 🤞 |
bk2204
left a comment
There was a problem hiding this comment.
This looks good. Thanks again for the patch.
This PR should fix #5636
Running git lfs prune right after git add will prune the indexed files from the LFS cache so that any commit will result in a rightfully rejected push. Even worse, doing multiple commits on changes of the same file will permanently delete LFS data that is not recoverable.
This change retains all files that are in the index by diffing the index against the HEAD.