Support union merges via .gitattributes file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
diff --git a/src/merge.c b/src/merge.c
index d2f92cc..767564b 100644
--- a/src/merge.c
+++ b/src/merge.c
@@ -1819,6 +1819,28 @@ static git_iterator *iterator_given_or_empty(git_iterator **empty, git_iterator
return *empty;
}
+static int lookup_file_favor(
+ git_merge_file_favor_t *file_favor,
+ git_repository *repo,
+ const char *path)
+{
+ int error = 0;
+ const char *value = NULL;
+
+ if (path) {
+ if ((error = git_attr_get(&value, repo, 0, path, "merge")) < 0)
+ goto done;
+
+ if (*file_favor == GIT_MERGE_FILE_FAVOR_NORMAL &&
+ value && strcmp(value, "union") == 0) {
+ *file_favor |= GIT_MERGE_FILE_FAVOR_UNION;
+ }
+ }
+
+done:
+ return error;
+}
+
int git_merge__iterators(
git_index **out,
git_repository *repo,
@@ -1877,6 +1899,10 @@ int git_merge__iterators(
git_vector_foreach(&changes, i, conflict) {
int resolved = 0;
+ /* Check for merge options in .gitattributes */
+ if ((error = lookup_file_favor(&opts.file_favor, repo, conflict->our_entry.path) < 0))
+ goto done;
+
if ((error = merge_conflict_resolve(
&resolved, diff_list, conflict, &file_opts)) < 0)
goto done;