2016-09-23 4 views
1

이 게시물 (libgit2 (fetch & merge & commit))의 답변을 살펴 봤지만 힘내 당기기를 사용하는 데 어려움을 겪고 있습니다. 오류 메시지가 표시되지 않습니다. 가져 오기는 작동하지만 병합은 발생하지 않습니다. 내가 그 병합 작동하지 않는 원인을하고있는 중이 야 무엇libgit2를 사용하여 힘내 당기기

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(); 
} 

...

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 

내 코드는 다음과 같습니다 ... 힘내 상태 내 지점 1 커밋에 의해 뒤에 것을 보여준다 이렇게?

답변

1

먼저 git_checkout_options.checkout_strategy은 다소 놀라운 것입니다. 기본값은 드라이 런입니다. 따라서 GIT_CHECKOUT_SAFE과 같은 것으로 변경하고 싶을 것입니다.

두 번째로 이해해야 할 점은 git_merge가 실제로 병합을 커밋하지 않는다는 것입니다. 병합을위한 작업 디렉토리와 색인 만 설정합니다. 충돌을 확인하고 git_commit_create으로 전화하여 병합을 완료해야합니다.

그러나이 특별한 경우에는 실제로 병합 할 필요가없는 것처럼 보입니다. 지점을 빨리 전달할 수 있습니다. 어떤 종류의 병합을 결정하려면 git_merge_analysis으로 전화하십시오. 현재 브랜치에서 git_reference_set_target 콜을 빨리 감기하려면 새로운 페치 헤드를 사용하십시오.

+0

감사합니다. Jason. 나는 커밋을하기 위해 당신의 제안을 시도했다. 로컬 브랜치와 리모트 브랜치를 모두 부모로 지정하지만, 로컬 리포는 리모컨보다 먼저 커밋됩니다. 리모컨은 "git pull"과 함께 발생하지 않습니다. – Anthony

+0

로컬 분기 * 병합 후 커밋해야합니다. 그러나 병합 할 필요가 없다는 것을 인식하지 못했습니다. 왜냐하면 병력이 원격 기록에서 벗어나지 않았기 때문입니다. 앞으로 감을 수 있습니다. 그에 따라 내 대답을 업데이트 할 것입니다. –