I am writing an app that allows performing basic git operations using Objective-Git, but I am having trouble figuring out how to "unstage" a file. More specifically, I have a file with changes that have previously been added to the current GTIndex and I now want to discard those changes (without losing the file's current state on disk).
Here is a rough outline of the relevant logic my program currently follows when toggling the "staged" state of a file:
- Fetch current GTIndex using GTRepository.indexWithError:
- Fetch GTIndexEntry for the file using GTIndex.entryWithPath:
- If the file has an index and GTIndexEntry.status == GTIndexEntryStatusUpdated:
- Here's where I'm stuck
According to this old unanswered question I need to lookup the file's info in the current HEAD. In that case, this is the logic I arrived at:
- Fetch head's GTReference using GTRepository.headReferenceWithError:
- If the reference resolves to a GTCommit object:
- Fetch the GTTree using GTCommit.tree
- Fetch the file's GTTreeEntry using GTTree.entryWithPath:error:
- Stuck again! Do I convert GTTreeEntry to GTIndexEntry somehow?
Any guidance is appreciated! I'm not scared of jumping directly into libgit2 if I have to (this project has already necessitated it once or twice), but since I'm working in Swift I'd like to avoid it if I can and "unstaging" a file seems like such a standard procedure that I figured I must not be understanding how the Objective-Git classes tie together.