Introduce git_merge__extract_conflict_paths
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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
diff --git a/src/merge.c b/src/merge.c
index dd6a39f..371fad7 100644
--- a/src/merge.c
+++ b/src/merge.c
@@ -2469,6 +2469,47 @@ done:
return error;
}
+int git_merge__append_conflicts_to_merge_msg(
+ git_repository *repo,
+ git_index *index)
+{
+ git_filebuf file = GIT_FILEBUF_INIT;
+ git_buf file_path = GIT_BUF_INIT;
+ const char *last = NULL;
+ size_t i;
+ int error;
+
+ if ((error = git_buf_joinpath(&file_path, repo->path_repository, GIT_MERGE_MSG_FILE)) < 0 ||
+ (error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_APPEND, GIT_MERGE_FILE_MODE)) < 0)
+ goto cleanup;
+
+ if (git_index_has_conflicts(index))
+ git_filebuf_printf(&file, "\nConflicts:\n");
+
+ for (i = 0; i < git_index_entrycount(index); i++) {
+ const git_index_entry *e = git_index_get_byindex(index, i);
+
+ if (git_index_entry_stage(e) == 0)
+ continue;
+
+ if (last == NULL || strcmp(e->path, last) != 0)
+ git_filebuf_printf(&file, "\t%s\n", e->path);
+
+ last = e->path;
+ }
+
+ error = git_filebuf_commit(&file);
+
+cleanup:
+ if (error < 0)
+ git_filebuf_cleanup(&file);
+
+ git_buf_free(&file_path);
+
+ return error;
+}
+
+
static int merge_state_cleanup(git_repository *repo)
{
const char *state_files[] = {
diff --git a/src/merge.h b/src/merge.h
index 2362da0..00f6197 100644
--- a/src/merge.h
+++ b/src/merge.h
@@ -151,4 +151,6 @@ int git_merge__setup(
int git_merge__indexes(git_repository *repo, git_index *index_new);
+int git_merge__append_conflicts_to_merge_msg(git_repository *repo, git_index *index);
+
#endif