Я использую Objective-Git. Я не могу получить следующий метод работы:Objective-Git Merge
- (GTIndex *)merge:(GTTree *)otherTree ancestor:(GTTree *)ancestorTree error:(NSError **)error
ошибки не возвращается, но индекс вернулся пуст, в то время как она существует, все атрибуты равны нулю. Операция слияния не выполняется, я не могу записать дерево, поскольку я не могу получить индекс, полученный в результате попытки слияния.
Неужели кому-то удалось успешно выполнить слияние с использованием объективного git - How? Помогите!
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);
}
}
}
Действительно! Вы также можете поменять новый индекс на индекс своего репозитория, но это, вероятно, не рекомендуется, если вы не будете очень осторожны, чтобы убедиться, что у вас нет незафиксированных отслеживаемых изменений в индексе для начала. (Намного лучше объединить два индекса и поместить результат как новый индекс репозитория.) –
Спасибо за ответы. Я добавил билет Артура. @Edward, возможно ли это, не отбрасывая libgit2? – Coxy1989