Bug 540076 - CommitCommand will not remove files still on disk if setOnly has been used.
Summary: CommitCommand will not remove files still on disk if setOnly has been used.
Status: NEW
Alias: None
Product: JGit
Classification: Technology
Component: JGit (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 10
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-10-12 06:18 EDT by Tim Hosey CLA
Modified: 2018-10-12 06:18 EDT (History)
0 users

See Also:


Attachments
Patch to fix CommitCommand to allow setOnly to work on files removed using git rm --cached (564 bytes, application/octet-stream)
2018-10-12 06:18 EDT, Tim Hosey CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Tim Hosey CLA 2018-10-12 06:18:54 EDT
Created attachment 276219 [details]
Patch to fix CommitCommand to allow setOnly to work on files removed using git rm --cached

If CommitCommand is used with setOnly on a file that has been staged for removal, but is still on disk using git rm --cached, the command will error.

The error occurs because when setOnly has been used CommitCommand creates a filtered temporary copy of the index by comparing the file tree to the head commit tree without considering whether the file has been removed from the original index. 

The fix is quite simple and involves just adding a check that the original index tree is not empty before attempting to create a DirCacheEntry in the index copy.

Applying the attached patch allows setOnly to work with files that have been staged for removal using git rm.