私はobjecitive-gitとlibgit2を使ってプル機能を実装しようとしています。asgit pull
は単なる「磁器」コマンドであり、その後にgit fetch
続くgit merge origin/master
then で構成されており、それが私がそれを実装した方法です。
フェッチは、github のフェッチ ブランチから object-git のメソッドを使用して実行されます。
[remote fetchWithCredentialProvider:nil error:&error progress:nil];
以下のコードは、フェッチ後に実行されるものです (成功することがわかっています)。
// Get the local branch
GTBranch *localBranch = [repo localBranchesWithError:nil][0];
// Get the remote branch
GTBranch *remoteBranch = [repo remoteBranchesWithError:nil][0];
// Get the local & remote commit
GTCommit *localCommit = [localBranch targetCommitAndReturnError:nil];
GTCommit *remoteCommit = [remoteBranch targetCommitAndReturnError:nil];
// Get the trees of both
GTTree *localTree = localCommit.tree;
GTTree *remoteTree = remoteCommit.tree;
// Get OIDs of both commits too
GTOID *localOID = localCommit.OID;
GTOID *remoteOID = remoteCommit.OID;
// Find a merge base to act as the ancestor between these two commits
GTCommit *ancestor = [repo mergeBaseBetweenFirstOID:localOID secondOID:remoteOID error:&error];
if (error) {
NSLog(@"Error finding merge base: %@", error);
}
// Get the ancestors tree
GTTree *ancestorTree = ancestor.tree;
// Merge into the local tree
GTIndex *mergedIndex = [localTree merge:remoteTree ancestor:ancestorTree error:&error];
if (error) {
NSLog(@"Error mergeing: %@", error);
}
// Write the merge to disk and store the new tree
GTTree *newTree = [mergedIndex writeTreeToRepository:repo error:&error];
if (error) {
NSLog(@"Error writing merge index to disk: %@", error);
}
mergedIndex
メモリ内で始まる がツリーとしてディスクに書き込まれた後( writeTreeToRepository
uses git_index_write_tree_to
)、git repos ステータスに変更はありません。新しいツリーを HEAD にするか、HEAD などとマージするための最後のステップが欠けていると思いますが、正確にはわかりません。
どんな助けも大いに義務付けられます。