Skip to content

Commit 324d237

Browse files
pcloudsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b643355 commit 324d237

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

Documentation/git-merge.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ commit or stash your changes before running 'git merge'.
9999
'git merge --abort' is equivalent to 'git reset --merge' when
100100
`MERGE_HEAD` is present.
101101

102+
--quit::
103+
Forget about the current merge in progress. Leave the index
104+
and the working tree as-is.
105+
102106
--continue::
103107
After a 'git merge' stops due to conflicts you can conclude the
104108
merge by running 'git merge --continue' (see "HOW TO RESOLVE

builtin/merge.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ static int option_renormalize;
7373
static int verbosity;
7474
static int allow_rerere_auto;
7575
static int abort_current_merge;
76+
static int quit_current_merge;
7677
static int continue_current_merge;
7778
static int allow_unrelated_histories;
7879
static int show_progress = -1;
@@ -267,6 +268,8 @@ static struct option builtin_merge_options[] = {
267268
OPT__VERBOSITY(&verbosity),
268269
OPT_BOOL(0, "abort", &abort_current_merge,
269270
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")),
270273
OPT_BOOL(0, "continue", &continue_current_merge,
271274
N_("continue the current in-progress merge")),
272275
OPT_BOOL(0, "allow-unrelated-histories", &allow_unrelated_histories,
@@ -1252,6 +1255,16 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
12521255
goto done;
12531256
}
12541257

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+
12551268
if (continue_current_merge) {
12561269
int nargc = 1;
12571270
const char *nargv[] = {"commit", NULL};

t/t7600-merge.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,4 +822,18 @@ test_expect_success EXECKEEPSPID 'killed merge can be completed with --continue'
822822
verify_parents $c0 $c1
823823
'
824824

825+
test_expect_success 'merge --quit' '
826+
git reset --hard side &&
827+
test_must_fail git -c rerere.enabled=true merge master &&
828+
test_path_is_file .git/MERGE_HEAD &&
829+
test_path_is_file .git/MERGE_MODE &&
830+
test_path_is_file .git/MERGE_MSG &&
831+
test_path_is_file .git/MERGE_RR &&
832+
git merge --quit &&
833+
test_path_is_missing .git/MERGE_HEAD &&
834+
test_path_is_missing .git/MERGE_MODE &&
835+
test_path_is_missing .git/MERGE_MSG &&
836+
test_path_is_missing .git/MERGE_RR
837+
'
838+
825839
test_done

0 commit comments

Comments
 (0)