From 8b1cafef2fa963faa2d274db2b8b30de08b75515 Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Thu, 16 May 2019 12:14:03 +0200 Subject: [PATCH] cLib: gitPull: Use the correct annoated_commit The annotated commit must be created from the remote's branch's ref. This entire thing is quite confusing, but for now at least git pull's work properly, though with an extra merge commit. --- gj_common/gitjournal.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/gj_common/gitjournal.c b/gj_common/gitjournal.c index fbc83c82..47ea649f 100644 --- a/gj_common/gitjournal.c +++ b/gj_common/gitjournal.c @@ -474,11 +474,8 @@ int gj_git_pull(const char *git_base_path, const char *author_name, const char * if (err < 0) goto cleanup; - git_merge_options merge_options = GIT_MERGE_OPTIONS_INIT; - git_checkout_options checkout_options = GIT_CHECKOUT_OPTIONS_INIT; - - // FIXME: Maybe I should be taking the head of the remote? - err = git_repository_head(&ref, repo); + // FIXME: Do not hardcode the master branch! + err = git_reference_lookup(&ref, repo, "refs/remotes/origin/master"); if (err < 0) goto cleanup; @@ -486,6 +483,9 @@ int gj_git_pull(const char *git_base_path, const char *author_name, const char * if (err < 0) goto cleanup; + git_merge_options merge_options = GIT_MERGE_OPTIONS_INIT; + git_checkout_options checkout_options = GIT_CHECKOUT_OPTIONS_INIT; + err = git_merge(repo, (const git_annotated_commit **)&annotated_commit, 1, &merge_options, &checkout_options); if (err < 0) @@ -552,9 +552,6 @@ int gj_git_pull(const char *git_base_path, const char *author_name, const char * if (err < 0) goto cleanup; - printf("Looked up origin head commit\n"); - printf("About to commit\n"); - const git_commit *parents[] = {head_commit, origin_head_commit}; char *message = "Custom Merge commit"; git_oid commit_id;