0

私はobjecitive-gitとlibgit2を使ってプル機能を実装しようとしています。asgit pullは単なる「磁器」コマンドであり、その後にgit fetch続くgit merge origin/masterthen で構成されており、それが私がそれを実装した方法です。

フェッチは、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メモリ内で始まる がツリーとしてディスクに書き込まれた後( writeTreeToRepositoryuses git_index_write_tree_to)、git repos ステータスに変更はありません。新しいツリーを HEAD にするか、HEAD などとマージするための最後のステップが欠けていると思いますが、正確にはわかりません。

どんな助けも大いに義務付けられます。

4

1 に答える 1

2

マージ コミットに使用するツリーを取得したら、マージ コミットを作成する必要があります。マージ コミットは、他の作成と同じ方法で作成できますが、両方の祖先を親として使用しますcreateCommitWithTreeGTRepositoryこの機能を使用すると、リポジトリが静止状態にあると予想される場合に、ライブラリに特定のブランチを更新するように依頼することもできます。

于 2014-03-23T12:04:56.850 に答える