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

[PATCH 2/2] merge: add --quit

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
May 1, 2019, 13:11 UTC
Message-ID
<20190501131152.314-3-pclouds@gmail.com>
In-Reply-To
<20190501131152.314-1-pclouds@gmail.com>

This allows to cancel the current merge without reseting worktree/index, which is what --abort is for. Like other --quit(s), this is often used when you forgot that you're in the middle of a merge and already switched away, doing different things. By the time you're realize, you can't even continue the merge anymore.

This also makes all in-progress commands, am, merge, rebase, revert and cherry-pick, take all three --abort, --continue and --quit (bisect has a different UI).

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 Documentation/git-merge.txt |  4 ++++
 builtin/merge.c             | 13 +++++++++++++
 t/t7600-merge.sh            | 14 ++++++++++++++
 3 files changed, 31 insertions(+)
diff --git a/Documentation/git-merge.txt b/Documentation/git-merge.txt
index 6294dbc09d..c01cfa6595 100644
--- a/Documentation/git-merge.txt
+++ b/Documentation/git-merge.txt
@@ -100,6 +100,10 @@ commit or stash your changes before running 'git merge'.
 'git merge --abort' is equivalent to 'git reset --merge' when
 `MERGE_HEAD` is present.
 
+--quit::
+	Forget about the current merge in progress. Leave the index
+	and the working tree as-is.
+
 --continue::
 	After a 'git merge' stops due to conflicts you can conclude the
 	merge by running 'git merge --continue' (see "HOW TO RESOLVE
diff --git a/builtin/merge.c b/builtin/merge.c
index 0fd448b403..13392ba1cf 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -73,6 +73,7 @@ static int option_renormalize;
 static int verbosity;
 static int allow_rerere_auto;
 static int abort_current_merge;
+static int quit_current_merge;
 static int continue_current_merge;
 static int allow_unrelated_histories;
 static int show_progress = -1;
@@ -270,6 +271,8 @@ static struct option builtin_merge_options[] = {
 	OPT__VERBOSITY(&verbosity),
 	OPT_BOOL(0, "abort", &abort_current_merge,
 		N_("abort the current in-progress merge")),
+	OPT_BOOL(0, "quit", &quit_current_merge,
+		N_("--abort but leave index and working tree alone")),
 	OPT_BOOL(0, "continue", &continue_current_merge,
 		N_("continue the current in-progress merge")),
 	OPT_BOOL(0, "allow-unrelated-histories", &allow_unrelated_histories,
@@ -1255,6 +1258,16 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 		goto done;
 	}
 
+	if (quit_current_merge) {
+		if (orig_argc != 2)
+			usage_msg_opt(_("--quit expects no arguments"),
+				      builtin_merge_usage,
+				      builtin_merge_options);
+
+		remove_merge_branch_state(the_repository);
+		goto done;
+	}
+
 	if (continue_current_merge) {
 		int nargc = 1;
 		const char *nargv[] = {"commit", NULL};
diff --git a/t/t7600-merge.sh b/t/t7600-merge.sh
index 106148254d..ea82cb744b 100755
--- a/t/t7600-merge.sh
+++ b/t/t7600-merge.sh
@@ -822,4 +822,18 @@ test_expect_success EXECKEEPSPID 'killed merge can be completed with --continue'
 	verify_parents $c0 $c1
 '
 
+test_expect_success 'merge --quit' '
+	git reset --hard side &&
+	test_must_fail git -c rerere.enabled=true merge master &&
+	test_path_is_file .git/MERGE_HEAD &&
+	test_path_is_file .git/MERGE_MODE &&
+	test_path_is_file .git/MERGE_MSG &&
+	test_path_is_file .git/MERGE_RR &&
+	git merge --quit &&
+	test_path_is_missing .git/MERGE_HEAD &&
+	test_path_is_missing .git/MERGE_MODE &&
+	test_path_is_missing .git/MERGE_MSG &&
+	test_path_is_missing .git/MERGE_RR
+'
+
 test_done
-- 
2.21.0.1110.g9614c01b33
Previous: Nguyễn Thái Ngọc DuyNext: Emily Shaffer
Message 3 of 20 in “Add "git merge --quit"”
  1. 0/2 Add "git merge --quit"Nguyễn Thái Ngọc Duy, May 1, 2019
  2. 1/2 merge: remove drop_save() in favor of remove_merge_branch_state()Nguyễn Thái Ngọc Duy, May 1, 2019
  3. 2/2 merge: add --quitNguyễn Thái Ngọc Duy, May 1, 2019
  4. Emily ShafferMay 2, 2019
  5. Phillip WoodMay 2, 2019
  6. 0/2 nd/merge-quit updateNguyễn Thái Ngọc Duy, May 9, 2019
  7. 1/2 merge: remove drop_save() in favor of remove_merge_branch_state()Nguyễn Thái Ngọc Duy, May 9, 2019
  8. 2/2 merge: add --quitNguyễn Thái Ngọc Duy, May 9, 2019
  9. 0/2 nd/merge-quit updatesNguyễn Thái Ngọc Duy, May 14, 2019
  10. 1/2 merge: remove drop_save() in favor of remove_merge_branch_state()Nguyễn Thái Ngọc Duy, May 14, 2019
  11. 2/2 merge: add --quitNguyễn Thái Ngọc Duy, May 14, 2019
  12. Johannes SchindelinMay 14, 2019
  13. Junio C HamanoMay 15, 2019
  14. Johannes SchindelinMay 15, 2019
  15. Junio C HamanoMay 15, 2019
  16. 0/2 nd/merge-quit updatesNguyễn Thái Ngọc Duy, May 18, 2019
  17. 1/2 merge: remove drop_save() in favor of remove_merge_branch_state()Nguyễn Thái Ngọc Duy, May 18, 2019
  18. 2/2 merge: add --quitNguyễn Thái Ngọc Duy, May 18, 2019
  19. Johannes SchindelinMay 20, 2019
  20. Johannes SchindelinMay 20, 2019

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.