merge: add --quit
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
May 18, 2019 at 18:30 UTC
f3f8311ec76f9bcdc7e26a125e585eb4e473a8d2
3 files changed
+43
Documentation/git-merge.txt
+4
@@ -99,6 +99,10 @@ commit or stash your changes before running 'git merge'.
99
'git merge --abort' is equivalent to 'git reset --merge' when
100
`MERGE_HEAD` is present.
101
102
+--quit::
103
+ Forget about the current merge in progress. Leave the index
104
+ and the working tree as-is.
105
+
106
--continue::
107
After a 'git merge' stops due to conflicts you can conclude the
108
merge by running 'git merge --continue' (see "HOW TO RESOLVE
builtin/merge.c
+13
@@ -73,6 +73,7 @@ static int option_renormalize;
73
static int verbosity;
74
static int allow_rerere_auto;
75
static int abort_current_merge;
76
+static int quit_current_merge;
77
static int continue_current_merge;
78
static int allow_unrelated_histories;
79
static int show_progress = -1;
@@ -267,6 +268,8 @@ static struct option builtin_merge_options[] = {
268
OPT__VERBOSITY(&verbosity),
269
OPT_BOOL(0, "abort", &abort_current_merge,
270
N_("abort the current in-progress merge")),
271
+ OPT_BOOL(0, "quit", &quit_current_merge,
272
+ N_("--abort but leave index and working tree alone")),
273
OPT_BOOL(0, "continue", &continue_current_merge,
274
N_("continue the current in-progress merge")),
275
OPT_BOOL(0, "allow-unrelated-histories", &allow_unrelated_histories,
@@ -1252,6 +1255,16 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1255
goto done;
1256
}
1257
1258
+ if (quit_current_merge) {
1259
+ if (orig_argc != 2)
1260
+ usage_msg_opt(_("--quit expects no arguments"),
1261
+ builtin_merge_usage,
1262
+ builtin_merge_options);
1263
+
1264
+ remove_merge_branch_state(the_repository);
1265
+ goto done;
1266
+ }
1267
+
1268
if (continue_current_merge) {
1269
int nargc = 1;
1270
const char *nargv[] = {"commit", NULL};
t/t7600-merge.sh
+26
@@ -822,4 +822,30 @@ test_expect_success EXECKEEPSPID 'killed merge can be completed with --continue'
822
verify_parents $c0 $c1
823
'
824
825
+test_expect_success 'merge --quit' '
826
+ git init merge-quit &&
827
+ (
828
+ cd merge-quit &&
829
+ test_commit base &&
830
+ echo one >>base.t &&
831
+ git commit -am one &&
832
+ git branch one &&
833
+ git checkout base &&
834
+ echo two >>base.t &&
835
+ git commit -am two &&
836
+ test_must_fail git -c rerere.enabled=true merge one &&
837
+ test_path_is_file .git/MERGE_HEAD &&
838
+ test_path_is_file .git/MERGE_MODE &&
839
+ test_path_is_file .git/MERGE_MSG &&
840
+ git rerere status >rerere.before &&
841
+ git merge --quit &&
842
+ test_path_is_missing .git/MERGE_HEAD &&
843
+ test_path_is_missing .git/MERGE_MODE &&
844
+ test_path_is_missing .git/MERGE_MSG &&
845
+ git rerere status >rerere.after &&
846
+ test_must_be_empty rerere.after &&
847
+ ! test_cmp rerere.after rerere.before
848
+ )
849
+'
850
+
851
test_done