git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] builtin-merge: fail properly when we are in the middle of a conflicted merge

From
Miklos Vajna <vmiklos@frugalware.org>
Date
Aug 23, 2008, 10:57 UTC
Message-ID
<1219489071-5679-1-git-send-email-vmiklos@frugalware.org>
In-Reply-To
<7v3akw2jgo.fsf@gitster.siamese.dyndns.org>

Using unmerged_cache() without reading the cache first never will return anything. However, if we read the cache early then we have to discard it when we want to read it again from the disk.

Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>
---
On Sat, Aug 23, 2008 at 02:01:43AM -0700, Junio C Hamano <gitster@pobox.com> wrote:
Show 5 quoted lines
> With this, I do not think you would need to keep the read_cache() you
> added to the beginning of the read_tree_trivial(), for the same reason
> you
> are removing read_cache_unmerged() from the beginning of
> checkout_fast_forward() in this patch.
Right, I removed it as well. Also fixed the testcase (no more new file).
 builtin-merge.c            |    7 +++----
 t/t3030-merge-recursive.sh |   11 +++++++++++
 2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/builtin-merge.c b/builtin-merge.c
index dffe4b8..b280444 100644
--- a/builtin-merge.c
+++ b/builtin-merge.c
@@ -469,7 +469,6 @@ static int read_tree_trivial(unsigned char *common, unsigned char *head,
 	struct tree_desc t[MAX_UNPACK_TREES];
 	struct unpack_trees_options opts;
 
-	read_cache();
 	memset(&opts, 0, sizeof(opts));
 	opts.head_idx = 2;
 	opts.src_index = &the_index;
@@ -565,8 +564,6 @@ static int checkout_fast_forward(unsigned char *head, unsigned char *remote)
 	struct dir_struct dir;
 	struct lock_file *lock_file = xcalloc(1, sizeof(struct lock_file));
 
-	if (read_cache_unmerged())
-		die("you need to resolve your current index first");
 	refresh_cache(REFRESH_QUIET);
 
 	fd = hold_locked_index(lock_file, 1);
@@ -746,6 +743,7 @@ static int evaluate_result(void)
 	int cnt = 0;
 	struct rev_info rev;
 
+	discard_cache();
 	if (read_cache() < 0)
 		die("failed to read the cache");
 
@@ -779,7 +777,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 	struct commit_list **remotes = &remoteheads;
 
 	setup_work_tree();
-	if (unmerged_cache())
+	if (read_cache_unmerged())
 		die("You are in the middle of a conflicted merge.");
 
 	/*
@@ -1076,6 +1074,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 		}
 
 		/* Automerge succeeded. */
+		discard_cache();
 		write_tree_trivial(result_tree);
 		automerge_was_ok = 1;
 		break;
diff --git a/t/t3030-merge-recursive.sh b/t/t3030-merge-recursive.sh
index aff3603..f288015 100755
--- a/t/t3030-merge-recursive.sh
+++ b/t/t3030-merge-recursive.sh
@@ -269,6 +269,17 @@ test_expect_success 'merge-recursive result' '
 
 '
 
+test_expect_success 'fail if the index has unresolved entries' '
+
+	rm -fr [abcd] &&
+	git checkout -f "$c1" &&
+
+	test_must_fail git merge "$c5" &&
+	test_must_fail git merge "$c5" 2> out &&
+	grep "You are in the middle of a conflicted merge" out
+
+'
+
 test_expect_success 'merge-recursive remove conflict' '
 
 	rm -fr [abcd] &&
-- 
1.6.0.rc3.17.gc14c8.dirty
Previous: Junio C HamanoNext: Junio C Hamano
Message 7 of 22 in “[bug] git `next' does not do trivial merges”
  1. Paolo BonziniAug 22, 2008
  2. Jeff KingAug 22, 2008
  3. Miklos VajnaAug 23, 2008
  4. Fix in-index merge.Miklos Vajna, Aug 23, 2008
  5. builtin-merge: fail properly when we are in the middle of a conflicted mergeMiklos Vajna, Aug 23, 2008
  6. Junio C HamanoAug 23, 2008
  7. builtin-merge: fail properly when we are in the middle of a conflicted mergeMiklos Vajna, Aug 23, 2008
  8. Junio C HamanoAug 23, 2008
  9. 1/2 merge: fix numerus bugs around "trivial merge" areaJunio C Hamano, Aug 23, 2008
  10. Junio C HamanoAug 24, 2008
  11. builtin-merge: avoid run_command_v_opt() for recursive and subtreeMiklos Vajna, Aug 28, 2008
  12. 2/2 unpack_trees(): protect the handcrafted in-core index from read_cache()Junio C Hamano, Aug 23, 2008
  13. Junio C HamanoAug 23, 2008
  14. Junio C HamanoAug 23, 2008
  15. Fix in-index merge.Miklos Vajna, Aug 23, 2008
  16. Paolo BonziniAug 23, 2008
  17. Junio C HamanoAug 23, 2008
  18. Junio C HamanoAug 23, 2008
  19. [RFH] two and half potential fixlets to the in-core index handlingJunio C Hamano, Aug 23, 2008
  20. Linus TorvaldsAug 23, 2008
  21. Junio C HamanoAug 23, 2008
  22. Junio C HamanoAug 23, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.