Skip to content

fix: stage deleted files with libgit2 - #684

Merged
agavra merged 1 commit into
agavra:mainfrom
mvanhorn:fix/638-stage-deleted-files
Sep 7, 2026
Merged

agavra merged 1 commit into
agavra:mainfrom
mvanhorn:fix/638-stage-deleted-files

Conversation

@mvanhorn

@mvanhorn mvanhorn commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Update the existing stage_file primitive to distinguish a path that still exists in the repository worktree from a tracked path that has been removed. Continue using the current index add operation for present files, but remove an absent tracked path from the index before performing the existing index write so the deletion becomes staged. When a reviewed, tracked file has been removed from the working tree, :stage reaches the libgit2 staging adapter and fails because that adapter unconditionally asks the index to add the missing path. The Git CLI backend already handles this case through git add -- <path>, so the defect is specific to the default libgit2 backend.

A tracked and committed file is deleted from the worktree, then staged through the libgit2 primitive: the call succeeds and the file is absent from the index relative to HEAD, representing a staged deletion; An existing new or modified file is staged: the current add-to-index behavior continues to succeed and the path remains present in the index.

Fixes #638

AI was used for assistance.

@mvanhorn
mvanhorn force-pushed the fix/638-stage-deleted-files branch from ffce34b to 1ea9fdb Compare September 3, 2026 17:08

@agavra agavra left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @mvanhorn for the contribution! This looks good to me.

@agavra
agavra merged commit 05305a4 into agavra:main Sep 7, 2026
5 checks passed
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.

Staging removed file fails

2 participants