使用Objective-Git和libgit2它一直是很容易上演了一出文件準備提交取消階段文件:與libgit2
GTIndex *repoIndex = [self.repository indexWithError:&error];
[repoIndex removeFile:path error:&error];
if (status != GTFileStatusIgnored && status != GTFileStatusWorkingDeleted) {
// Now add the file to the index
[repoIndex addFile:path error:&error];
}
[repoIndex write:&error];
但是未分級的文件被證明是一點點更加棘手。簡單地從版本庫的索引中刪除它不起作用,因爲git認爲文件已被刪除,這是合理的。看起來我需要做的是將索引中的索引條目更改爲在索引之前的索引條目。
我曾嘗試做以下,使用diff來感受一下老DIFF三角洲和構建從一個git_index_entry
並將其插入:
GTIndex *repoIndex = [self.repository indexWithError:&error];
GTBranch *localBranch = [self.repository currentBranchWithError:&error];
GTCommit *localCommit = [localBranch targetCommitAndReturnError:&error];
GTDiff *indexCommitDiff = [GTDiff diffIndexFromTree:localCommit.tree inRepository:self.repository options:nil error:&error];
// Enumerate through the diff deltas until we get to the file we want to unstage
[indexCommitDiff enumerateDeltasUsingBlock:^(GTDiffDelta *delta, BOOL *stop) {
NSString *deltaPath = delta.newFile.path;
// Check if it matches the path we want to usntage
if ([deltaPath isEqualToString:path]) {
GTDiffFile *oldFile = delta.oldFile;
NSString *oldFileSHA = oldFile.OID.SHA;
git_oid oldFileOID;
int status = git_oid_fromstr(&oldFileOID, oldFileSHA.fileSystemRepresentation);
git_index_entry entry;
entry.mode = oldFile.mode;
entry.oid = oldFileOID;
entry.path = oldFile.path.fileSystemRepresentation;
[repoIndex removeFile:path error:&error];
status = git_index_add(repoIndex.git_index, &entry);
[repoIndex write:&error];
}
}];
然而,這葉損壞狀態造成任何混帳混帳指數命令記錄一個致命錯誤:
fatal: Unknown index entry format bfff0000
fatal: Unknown index entry format bfff0000
什麼是正確的方式來解除使用libgit2文件?
非常感謝Carlos,我會將致命錯誤報告爲一個問題,但我不確定這是否屬於我的錯,即使該條目似乎有效。那麼使用'git_tree_entry_bypath'應該可以使用'git_tree_entry'的細節來重新構建原始索引條目? – Joshua
無論用戶做什麼,寫出無效索引文件都是一個bug。從樹條目中,您可以獲取重要信息,即filemode和id。其他任何東西都主要存在於緩存索引中。 –