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

[PATCH] refuse to merge during a merge

From
Clemens Buchacher <drizzd@aon.at>
Date
May 31, 2009, 10:43 UTC
Message-ID
<20090531104359.GA19094@localhost>
In-Reply-To
<20090530083721.GA12963@localhost>

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 intented. Instead, refuse to merge again if a merge is in progress and present the user with his options.

"git reset --hard" is not suggested, because it potentially removes changes unrelated to the merge (if the work tree was dirty prior to the merge).

Reported-by: Dave Olszewski <cxreg@pobox.com>
Signed-off-by: Clemens Buchacher <drizzd@aon.at>
---
Ok, since I'm not seeing any more objections. Here's the code.
Clemens
 builtin-merge.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/builtin-merge.c b/builtin-merge.c
index 0b58e5e..8169ded 100644
--- a/builtin-merge.c
+++ b/builtin-merge.c
@@ -834,10 +834,16 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 	struct commit_list *common = NULL;
 	const char *best_strategy = NULL, *wt_strategy = NULL;
 	struct commit_list **remotes = &remoteheads;
+	int unmerged;
 
 	setup_work_tree();
-	if (read_cache_unmerged())
-		die("You are in the middle of a conflicted merge.");
+	unmerged = read_cache_unmerged();
+	if (unmerged || file_exists(git_path("MERGE_HEAD")))
+		die("You are in the middle of a %smerge. To complete "
+			"the merge %scommit the changes. To abort, "
+			"use \"git reset HEAD\".",
+			unmerged ? "conflicted " : "",
+			unmerged ? "resolve conflicts and " : "");
 
 	/*
 	 * Check if we are _not_ on a detached HEAD, i.e. if there is a
-- 
1.6.3.1.147.g637c3
Previous: Thomas RastNext: John Tapsell
Message 7 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.