2016-09-23 8 views
1

私はこのポスト(libgit2 (fetch & merge & commit))の答えを見てきましたが、私はGit Pullを動作させるのに苦労しています。エラーメッセージは表示されません。フェッチは機能しているように見えますが、マージは行われません。 ...私のコードは以下の通りですlibgit2でGit Pullを実行する

On branch Branch_1_1. 
Your branch is behind 'origin/Branch_1_1' by 1 commit, and can be fast-forwarded. 
    (use "git pull" to update your local branch) 
nothing to commit, working directory clean 

... Gitのステータスが、私のブランチがコミット1での背後にあることを示している

static int fetchhead_ref_cb(const char *name, const char *url, 
    const git_oid *oid, unsigned int is_merge, void *payload) 

{ 
    if (is_merge) 
    { 
     strcpy_s(branchToMerge, 100, name); 
     memcpy(&branchOidToMerge, oid, sizeof(git_oid)); 
    } 
    return 0; 
} 

void GitPull() 
{ 
    git_libgit2_init(); 

    git_repository *repo = NULL; 
    git_remote *remote; 

    int error = git_repository_open(&repo, "C:\\work\\GitTestRepos\\Repo1"); 
    CHECK_FOR_ERROR 

    error = git_remote_lookup(&remote, repo, "origin"); 
    CHECK_FOR_ERROR 

    git_fetch_options options = GIT_FETCH_OPTIONS_INIT; 
    error = git_remote_fetch(remote, NULL, &options, NULL); 
    CHECK_FOR_ERROR 

    git_repository_fetchhead_foreach(repo, fetchhead_ref_cb, NULL); 

    git_merge_options merge_options = GIT_MERGE_OPTIONS_INIT; 
    git_checkout_options checkout_options = GIT_CHECKOUT_OPTIONS_INIT; 
    git_annotated_commit *heads[ 1 ]; 
    git_reference *ref; 

    error = git_annotated_commit_lookup(&heads[ 0 ], repo, &branchOidToMerge); 
    CHECK_FOR_ERROR 
    error = git_merge(repo, (const git_annotated_commit **)heads, 1, &merge_options, &checkout_options); 
    CHECK_FOR_ERROR 

    git_annotated_commit_free(heads[ 0 ]); 
    git_repository_state_cleanup(repo); 
    git_libgit2_shutdown(); 
} 

私はそれが動作しないマージを引き起こして何をしているのですがやって?

答えて

1

まず、git_checkout_options.checkout_strategyはかなり驚くべきデフォルトを持っています。デフォルトはドライランです。だからおそらくGIT_CHECKOUT_SAFEのようなものに変更したいと思うでしょう。

2番目のことは、git_mergeが実際にマージをコミットしないことです。これは、作業ディレクトリとマージ用のインデックスのみを設定します。まだコンフリクトをチェックし、git_commit_createに電話してマージを終了する必要があります。

しかし、実際にこの特定のケースでマージする必要はないようです。あなたの支店は早送りすることができます。どの種類のマージを行うかは、git_merge_analysisに問い合わせてください。現在のブランチのgit_reference_set_targetを新しいフェッチヘッドで早送りする。

+0

ありがとうございました。私はあなたの提案をコミットするように試みました。私は親としてローカルブランチとリモートブランチの両方を指定しますが、 "git pull"で起こっていないリモートより先にローカルリポジトリをコミットします。 – Anthony

+0

ローカルブランチ*は、マージをコミットした後でコミットする必要があります。しかし、私はあなたの地域の歴史が遠隔の歴史から逸脱していないので、あなたが本当に併合する必要はないことを認識できませんでした。早送りすることができます。私はそれに応じて私の答えを更新します。 –