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

[PATCH v3] refuse to merge during a merge

From
Clemens Buchacher <drizzd@aon.at>
Date
Jun 1, 2009, 09:20 UTC
Message-ID
<20090601092056.GA6933@localhost>
In-Reply-To
<7vd49prrne.fsf@alter.siamese.dyndns.org>

The following is an easy mistake to make for users coming from version control systems with an "update and commit"-style workflow.

        1. git pull
        2. resolve conflicts
        3. git pull

Step 3 overrides MERGE_HEAD, starting a new merge with dirty index. IOW, probably not what the user intended. Instead, refuse to merge again if a merge is in progress.

Reported-by: Dave Olszewski <cxreg@pobox.com>
Signed-off-by: Clemens Buchacher <drizzd@aon.at>
---
On Sun, May 31, 2009 at 12:36:37PM -0700, Junio C Hamano wrote:
Show 7 quoted lines
> For example, "git merge" may learn "git merge --abort" like other commands
> that have "attempt, stop, let the user fix up to conclude" modes of
> operations (i.e. rebase and am), and we may suggest to use that to recover
> in the message, instead of 'git reset'.  But that can only be used if we
> stopped because we saw MERGE_HEAD; you definitely do not want to suggest
> "git merge --abort" if the index is unmerged due to a conflicted rebase in
> progress.
Indeed. I wasn't thinking.
Clemens
 builtin-merge.c            |    5 ++++-
 t/t3030-merge-recursive.sh |    3 +++
 2 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/builtin-merge.c b/builtin-merge.c
index 0b58e5e..9e9bd52 100644
--- a/builtin-merge.c
+++ b/builtin-merge.c
@@ -836,8 +836,11 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 	struct commit_list **remotes = &remoteheads;
 
 	setup_work_tree();
+	if (file_exists(git_path("MERGE_HEAD")))
+		die("You have not concluded your merge. (MERGE_HEAD exists)");
 	if (read_cache_unmerged())
-		die("You are in the middle of a conflicted merge.");
+		die("You are in the middle of a conflicted merge."
+				" (index unmerged)");
 
 	/*
 	 * Check if we are _not_ on a detached HEAD, i.e. if there is a
diff --git a/t/t3030-merge-recursive.sh b/t/t3030-merge-recursive.sh
index 0de613d..9b3fa2b 100755
--- a/t/t3030-merge-recursive.sh
+++ b/t/t3030-merge-recursive.sh
@@ -276,6 +276,9 @@ test_expect_success 'fail if the index has unresolved entries' '
 
 	test_must_fail git merge "$c5" &&
 	test_must_fail git merge "$c5" 2> out &&
+	grep "You have not concluded your merge" out &&
+	rm -f .git/MERGE_HEAD &&
+	test_must_fail git merge "$c5" 2> out &&
 	grep "You are in the middle of a conflicted merge" out
 
 '
-- 
1.6.3.1.147.g637c3
Previous: Junio C Hamano
Message 11 of 11 in “refuse to merge during a merge”
  1. refuse to merge during a mergeClemens Buchacher, May 27, 2009
  2. Constantine PlotnikovMay 28, 2009
  3. John TapsellMay 28, 2009
  4. Clemens BuchacherMay 30, 2009
  5. Jakub NarebskiMay 30, 2009
  6. Thomas RastMay 30, 2009
  7. refuse to merge during a mergeClemens Buchacher, May 31, 2009
  8. John TapsellMay 31, 2009
  9. Clemens BuchacherMay 31, 2009
  10. Junio C HamanoMay 31, 2009
  11. refuse to merge during a mergeClemens Buchacher, Jun 1, 2009

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.