Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checkout: gracefully handle files deleted from the index #5698

Merged
merged 1 commit into from
Apr 16, 2024

Conversation

bk2204
Copy link
Member

@bk2204 bk2204 commented Apr 2, 2024

Right now, when someone deletes a pointer from the index with git rm and then runs git lfs checkout, the operation fails with a message of "Could not update the index" because our invocation of git update-index is missing the --add flag.

Obviously, the user does not expect an error in this case, and git checkout simply ignores files staged for deletation, so let's do the same thing. If a file on disk is deleted, check the index with git diff-index to see if it's deleted from HEAD. If so, ignore the file, just like Git does. Note that we use git diff-index specifically because it doesn't refresh the index and is therefore much cheaper than alternatives, such as git status, which might do that.

Fixes #5669

@bk2204 bk2204 marked this pull request as ready for review April 3, 2024 14:58
@bk2204 bk2204 requested a review from a team as a code owner April 3, 2024 14:58
t/t-checkout.sh Outdated Show resolved Hide resolved
Right now, when someone deletes a pointer from the index with `git rm`
and then runs `git lfs checkout`, the operation fails with a message of
"Could not update the index" because our invocation of `git
update-index` is missing the `--add` flag.

Obviously, the user does not expect an error in this case, and `git
checkout` simply ignores files staged for deletation, so let's do the
same thing.  If a file on disk is deleted, check the index with `git
diff-index` to see if it's deleted from `HEAD`.  If so, ignore the file,
just like Git does. Note that we use `git diff-index` specifically
because it doesn't refresh the index and is therefore much cheaper than
alternatives, such as `git status`, which might do that.
@bk2204 bk2204 merged commit 3d1ca20 into git-lfs:main Apr 16, 2024
10 checks passed
@bk2204 bk2204 deleted the checkout-ignore-missing branch April 16, 2024 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

checkout does not respect files which have been staged for removal with git rm
2 participants