summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2015-08-23 11:33:15 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-08-25 10:43:16 -0700
commit471af6c2fd63fa6139682aade26aa5039df911c0 (patch)
treedb531478f6e4860590d70e5a369c55523009e117
parentf5eb0e2bbb6224b69bcf95b4d89d443c576808ad (diff)
downloadsubsurface-471af6c2fd63fa6139682aade26aa5039df911c0.tar.gz
Cloud storage: clean up after the merge
Make sure the branch is pointing at the merge commit, etc. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--git-access.c13
-rw-r--r--save-git.c2
2 files changed, 14 insertions, 1 deletions
diff --git a/git-access.c b/git-access.c
index 07eb76a68..2b44cb6b3 100644
--- a/git-access.c
+++ b/git-access.c
@@ -217,6 +217,19 @@ static int try_to_git_merge(git_repository *repo, git_reference *local, git_refe
return report_error(translate("gettextFromC", "Failed to get author: (%s)"), giterr_last()->message);
if (git_commit_create_v(&commit_oid, repo, "HEAD", author, author, NULL, "automatic merge", merged_tree, 2, local_commit, remote_commit))
return report_error(translate("gettextFromC", "Remote storage and local data diverged. Error: git commit create failed (%s)"), giterr_last()->message);
+ if (git_commit_lookup(&commit, repo, &commit_oid))
+ return report_error(translate("gettextFromC", "Error: could not lookup the merge commit I just created (%s)"), giterr_last()->message);
+ if (git_branch_is_head(local) && !git_repository_is_bare(repo)) {
+ git_object *parent;
+ git_reference_peel(&parent, local, GIT_OBJ_COMMIT);
+ if (update_git_checkout(repo, parent, merged_tree)) {
+ report_error("Warning: checked out branch is inconsistent with git data");
+ }
+ }
+ if (git_reference_set_target(&local, local, &commit_oid, "Subsurface merge event"))
+ return report_error("Error: failed to update branch (%s)", giterr_last()->message);
+ set_git_id(&commit_oid);
+ git_signature_free(author);
}
return 0;
}
diff --git a/save-git.c b/save-git.c
index 9ae1d572e..3cd8a8a2c 100644
--- a/save-git.c
+++ b/save-git.c
@@ -997,7 +997,7 @@ static git_tree *get_git_tree(git_repository *repo, git_object *parent)
return tree;
}
-static int update_git_checkout(git_repository *repo, git_object *parent, git_tree *tree)
+int update_git_checkout(git_repository *repo, git_object *parent, git_tree *tree)
{
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;