Cloud storage: try to brute force your way around merge issues

This seems to do the right thing in several cases that I tested, but I'm
worried if it might end up causing us data loss in other cases. This needs
a TON of testing.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2015-08-23 18:16:59 -07:00
parent 70c38de3a1
commit f177b2ec53

View file

@ -203,8 +203,24 @@ static int try_to_git_merge(git_repository *repo, git_reference *local, git_refe
if (git_merge_trees(&merged_index, repo, base_tree, local_tree, remote_tree, &merge_options))
return report_error(translate("gettextFromC", "Remote storage and local data diverged. Error: merge failed (%s)"), giterr_last()->message);
if (git_index_has_conflicts(merged_index)) {
return report_error(translate("gettextFromC", "Remote storage and local data diverged. Error: merge conflict - manual intervention needed"));
} else {
int error;
const git_index_entry *ancestor = NULL,
*ours = NULL,
*theirs = NULL;
git_index_conflict_iterator *iter = NULL;
error = git_index_conflict_iterator_new(&iter, merged_index);
while (git_index_conflict_next(&ancestor, &ours, &theirs, iter)
!= GIT_ITEROVER) {
/* Mark this conflict as resolved */
fprintf(stderr, "conflict in %s / %s / %s\n",
ours ? ours->path : "-",
theirs ? theirs->path : "-",
ancestor ? ancestor->path : "-");
error = git_index_conflict_remove(merged_index, ours->path);
}
git_index_conflict_iterator_free(iter);
report_error(translate("gettextFromC", "Remote storage and local data diverged. Error: merge conflict - manual intervention needed"));
}
git_oid merge_oid, commit_oid;
git_tree *merged_tree;
git_signature *author;
@ -216,7 +232,7 @@ static int try_to_git_merge(git_repository *repo, git_reference *local, git_refe
return report_error(translate("gettextFromC", "Remote storage and local data diverged. Error: tree lookup failed (%s)"), giterr_last()->message);
if (git_signature_default(&author, repo) < 0)
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))
if (git_commit_create_v(&commit_oid, repo, NULL, 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);
@ -231,7 +247,7 @@ static int try_to_git_merge(git_repository *repo, git_reference *local, git_refe
return report_error("Error: failed to update branch (%s)", giterr_last()->message);
set_git_id(&commit_oid);
git_signature_free(author);
}
return 0;
}