Commit 6fefb7af84170fb67a7e6c8493fc00421787bb87

Jacques Germishuys 2014-04-13T19:53:35

Capture conflict information in MERGE_MSG for revert and merge

diff --git a/src/merge.c b/src/merge.c
index 371fad7..10c19b5 100644
--- a/src/merge.c
+++ b/src/merge.c
@@ -2662,6 +2662,7 @@ int git_merge(
 	if ((error = git_merge_trees(&index_new, repo, ancestor_tree, our_tree, their_trees[0], merge_opts)) < 0 ||
 		(error = git_merge__indexes(repo, index_new)) < 0 ||
 		(error = git_repository_index(&index_repo, repo)) < 0 ||
+		(error = git_merge__append_conflicts_to_merge_msg(repo, index_repo)) < 0 ||
 		(error = git_checkout_index(repo, index_repo, &checkout_opts)) < 0)
 		goto on_error;
 
diff --git a/src/revert.c b/src/revert.c
index 4039ec3..29e124f 100644
--- a/src/revert.c
+++ b/src/revert.c
@@ -201,6 +201,7 @@ int git_revert(
 		(error = git_revert_commit(&index_new, repo, commit, our_commit, opts.mainline, &opts.merge_opts)) < 0 ||
 		(error = git_merge__indexes(repo, index_new)) < 0 ||
 		(error = git_repository_index(&index_repo, repo)) < 0 ||
+		(error = git_merge__append_conflicts_to_merge_msg(repo, index_repo)) < 0 ||
 		(error = git_checkout_index(repo, index_repo, &opts.checkout_opts)) < 0)
 		goto on_error;
 
diff --git a/tests/merge/workdir/simple.c b/tests/merge/workdir/simple.c
index 032e97f..cf5b16e 100644
--- a/tests/merge/workdir/simple.c
+++ b/tests/merge/workdir/simple.c
@@ -214,7 +214,7 @@ void test_merge_workdir_simple__automerge_crlf(void)
 
 void test_merge_workdir_simple__mergefile(void)
 {
-	git_buf conflicting_buf = GIT_BUF_INIT;
+	git_buf conflicting_buf = GIT_BUF_INIT, mergemsg_buf = GIT_BUF_INIT;
 
 	struct merge_index_entry merge_index_entries[] = {
 		ADDED_IN_MASTER_INDEX_ENTRY,
@@ -240,7 +240,15 @@ void test_merge_workdir_simple__mergefile(void)
 	cl_git_pass(git_futils_readbuffer(&conflicting_buf,
 		TEST_REPO_PATH "/conflicting.txt"));
 	cl_assert(strcmp(conflicting_buf.ptr, CONFLICTING_MERGE_FILE) == 0);
+	cl_git_pass(git_futils_readbuffer(&mergemsg_buf,
+		TEST_REPO_PATH "/.git/MERGE_MSG"));
+	cl_assert(strcmp(git_buf_cstr(&mergemsg_buf),
+		"Merge commit '7cb63eed597130ba4abb87b3e544b85021905520'\n" \
+		"\n" \
+		"Conflicts:\n" \
+		"\tconflicting.txt\n") == 0);
 	git_buf_free(&conflicting_buf);
+	git_buf_free(&mergemsg_buf);
 
 	cl_assert(merge_test_index(repo_index, merge_index_entries, 8));
 	cl_assert(merge_test_reuc(repo_index, merge_reuc_entries, 3));
diff --git a/tests/revert/workdir.c b/tests/revert/workdir.c
index 694f247..e3d7e96 100644
--- a/tests/revert/workdir.c
+++ b/tests/revert/workdir.c
@@ -66,7 +66,7 @@ void test_revert_workdir__conflicts(void)
 	git_reference *head_ref;
 	git_commit *head, *commit;
 	git_oid revert_oid;
-	git_buf conflicting_buf = GIT_BUF_INIT;
+	git_buf conflicting_buf = GIT_BUF_INIT, mergemsg_buf = GIT_BUF_INIT;
 
 	struct merge_index_entry merge_index_entries[] = {
 		{ 0100644, "7731926a337c4eaba1e2187d90ebfa0a93659382", 1, "file1.txt" },
@@ -112,9 +112,21 @@ void test_revert_workdir__conflicts(void)
 		"File one\n" \
 		">>>>>>> parent of 72333f4... automergeable changes\n") == 0);
 
+	cl_assert(git_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG"));
+	cl_git_pass(git_futils_readbuffer(&mergemsg_buf,
+		TEST_REPO_PATH "/.git/MERGE_MSG"));
+	cl_assert(strcmp(mergemsg_buf.ptr,
+		"Revert \"automergeable changes\"\n" \
+		"\n" \
+		"This reverts commit 72333f47d4e83616630ff3b0ffe4c0faebcc3c45.\n"
+		"\n" \
+		"Conflicts:\n" \
+		"\tfile1.txt\n") == 0);
+
 	git_commit_free(commit);
 	git_commit_free(head);
 	git_reference_free(head_ref);
+	git_buf_free(&mergemsg_buf);
 	git_buf_free(&conflicting_buf);
 }