git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: pclouds@gmail.com
Cc: Johannes.Schindelin@gmx.de, git@vger.kernel.org, gitster@pobox.com
Subject: [PATCH v4 2/2] merge: add --quit
Date: Sat, 18 May 2019 18:30:43 +0700	[thread overview]
Message-ID: <20190518113043.18389-3-pclouds@gmail.com> (raw)
In-Reply-To: <20190518113043.18389-1-pclouds@gmail.com>

This allows to cancel the current merge without resetting 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've realized, 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            | 26 ++++++++++++++++++++++++++
 3 files changed, 43 insertions(+)

diff --git a/Documentation/git-merge.txt b/Documentation/git-merge.txt
index 4cc86469f3..b7d581fc76 100644
--- a/Documentation/git-merge.txt
+++ b/Documentation/git-merge.txt
@@ -99,6 +99,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 e9663f027a..598d56edfe 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;
@@ -267,6 +268,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,
@@ -1252,6 +1255,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..625a24a980 100755
--- a/t/t7600-merge.sh
+++ b/t/t7600-merge.sh
@@ -822,4 +822,30 @@ test_expect_success EXECKEEPSPID 'killed merge can be completed with --continue'
 	verify_parents $c0 $c1
 '
 
+test_expect_success 'merge --quit' '
+	git init merge-quit &&
+	(
+		cd merge-quit &&
+		test_commit base &&
+		echo one >>base.t &&
+		git commit -am one &&
+		git branch one &&
+		git checkout base &&
+		echo two >>base.t &&
+		git commit -am two &&
+		test_must_fail git -c rerere.enabled=true merge one &&
+		test_path_is_file .git/MERGE_HEAD &&
+		test_path_is_file .git/MERGE_MODE &&
+		test_path_is_file .git/MERGE_MSG &&
+		git rerere status >rerere.before &&
+		git merge --quit &&
+		test_path_is_missing .git/MERGE_HEAD &&
+		test_path_is_missing .git/MERGE_MODE &&
+		test_path_is_missing .git/MERGE_MSG &&
+		git rerere status >rerere.after &&
+		test_must_be_empty rerere.after &&
+		! test_cmp rerere.after rerere.before
+	)
+'
+
 test_done
-- 
2.22.0.rc0.322.g2b0371e29a


  parent reply	other threads:[~2019-05-18 11:31 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-01 13:11 [PATCH 0/2] Add "git merge --quit" Nguyễn Thái Ngọc Duy
2019-05-01 13:11 ` [PATCH 1/2] merge: remove drop_save() in favor of remove_merge_branch_state() Nguyễn Thái Ngọc Duy
2019-05-01 13:11 ` [PATCH 2/2] merge: add --quit Nguyễn Thái Ngọc Duy
2019-05-02 21:49   ` Emily Shaffer
2019-05-02 10:13 ` [PATCH 0/2] Add "git merge --quit" Phillip Wood
2019-05-09 10:10 ` [PATCH v2 0/2] nd/merge-quit update Nguyễn Thái Ngọc Duy
2019-05-09 10:10   ` [PATCH v2 1/2] merge: remove drop_save() in favor of remove_merge_branch_state() Nguyễn Thái Ngọc Duy
2019-05-09 10:10   ` [PATCH v2 2/2] merge: add --quit Nguyễn Thái Ngọc Duy
2019-05-14  9:13   ` [PATCH v3 0/2] nd/merge-quit updates Nguyễn Thái Ngọc Duy
2019-05-14  9:13     ` [PATCH v3 1/2] merge: remove drop_save() in favor of remove_merge_branch_state() Nguyễn Thái Ngọc Duy
2019-05-14  9:13     ` [PATCH v3 2/2] merge: add --quit Nguyễn Thái Ngọc Duy
2019-05-14 13:44       ` Johannes Schindelin
2019-05-15  2:58         ` Junio C Hamano
2019-05-15 15:00           ` Johannes Schindelin
2019-05-15  2:52       ` Junio C Hamano
2019-05-18 11:30     ` [PATCH v4 0/2] nd/merge-quit updates Nguyễn Thái Ngọc Duy
2019-05-18 11:30       ` [PATCH v4 1/2] merge: remove drop_save() in favor of remove_merge_branch_state() Nguyễn Thái Ngọc Duy
2019-05-18 11:30       ` Nguyễn Thái Ngọc Duy [this message]
2019-05-20 18:05         ` [PATCH v4 2/2] merge: add --quit Johannes Schindelin
2019-05-20 17:01       ` [PATCH v4 0/2] nd/merge-quit updates Johannes Schindelin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190518113043.18389-3-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).