mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 14:25:27 +00:00
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 <dirk@hohndel.org>
This commit is contained in:
parent
fe0864be60
commit
b8575221b1
1 changed files with 5 additions and 1 deletions
|
@ -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"));
|
||||
|
|
Loading…
Add table
Reference in a new issue