From b8575221b19bf0a77319318a505a27c00e33e375 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sat, 22 Aug 2015 16:19:17 -0700 Subject: Cloud storage: use merge options to avoid conflicts In many cases Subsurface will do something "reasonable" if we have conflicting edits and then try to merge. GIT_MERGE_FILE_FAVOR_UNION means that both edits will be added to the final file and then Subsurface should quietly take one or the other - this will need quite a bit of testing. Signed-off-by: Dirk Hohndel --- git-access.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'git-access.c') diff --git a/git-access.c b/git-access.c index ff00b85a3..3602b80f0 100644 --- a/git-access.c +++ b/git-access.c @@ -218,6 +218,10 @@ static int try_to_update(git_repository *repo, git_remote *origin, git_reference git_tree *local_tree, *remote_tree, *base_tree; git_commit *local_commit, *remote_commit, *base_commit; git_index *merged_index; + git_merge_options merge_options; + git_merge_init_options(&merge_options, GIT_MERGE_OPTIONS_VERSION); + merge_options.tree_flags = GIT_MERGE_TREE_FIND_RENAMES; + merge_options.file_favor = GIT_MERGE_FILE_FAVOR_UNION; if (git_commit_lookup(&local_commit, repo, local_id)) return report_error(translate("gettextFromC", "Remote storage and local data diverged. Error: can't get commit (%s)"), giterr_last()->message); if (git_commit_tree(&local_tree, local_commit)) @@ -230,7 +234,7 @@ static int try_to_update(git_repository *repo, git_remote *origin, git_reference return report_error(translate("gettextFromC", "Remote storage and local data diverged. Error: can't get commit: (%s)"), giterr_last()->message); if (git_commit_tree(&base_tree, base_commit)) return report_error(translate("gettextFromC", "Remote storage and local data diverged. Error: failed base tree lookup: (%s)"), giterr_last()->message); - if (git_merge_trees(&merged_index, repo, base_tree, local_tree, remote_tree, 0)) + 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")); -- cgit v1.2.3-70-g09d2