1
我正在使用Objective-Git。我不能让下面的方法来工作:返回Objective-Git合并
- (GTIndex *)merge:(GTTree *)otherTree ancestor:(GTTree *)ancestorTree error:(NSError **)error
没有错误,但返回的索引是空的,而它的存在,所有的属性都是零。合并操作没有发生,我不能写出一棵树,因为我无法获得尝试合并产生的索引。
有没有人成功地使用目标git进行合并 - 如何?帮帮我!
GTBranch *branch1 = branches[0];
GTCommit *commit1 = [branch1 targetCommitAndReturnError:NULL];
GTOID *oid1 = commit1.OID;
GTTree *tree1 = commit1.tree;
GTBranch *branch2 = branches[1];
GTCommit *commit2 = [branch2 targetCommitAndReturnError:NULL];
GTTree *tree2 = commit2.tree;
GTOID *oid2 = commit2.OID;
GTRepository *repo = branch1.repository;
NSError *error;
GTCommit *ancestor = [repo mergeBaseBetweenFirstOID:oid1 secondOID:oid2 error:&error];
if (error){
NSLog(@"%@", error.description);
}
GTTree *ancTree = ancestor.tree;
NSError *someError;
NSLog(@"attempting merge into ""%@"" from ""%@"" with ancestor ""%@""", commit2.message, commit1.message,ancestor.message);
GTIndex *mergedIndex = [tree2 merge:tree1 ancestor: ancTree error:&someError]; //returns index not backed by existing repo --> index_file_path = nil, all attributes of git_index are nil
if (someError){
NSLog(@"%@", someError.description);
}
NSError *theError;
GTTree *mergedtree = [mergedIndex writeTree:&theError]; //can't write out the tree as the index given back by merge: ancestor: error: does not reference a repo
if (theError){
NSLog(@"%@",theError);
}
}
}
确实!您也可以将新索引交换到您的存储库索引,但除非您非常小心地确保索引中没有未提交的跟踪更改,否则可能不会提示。 (更好地合并两个索引并将结果作为新的存储库索引。) –
感谢您的回答。我已经添加了票亚瑟。 @爱德华,这可能没有下降到libgit2? – Coxy1989