merge: add '--continue' option as a synonym for 'git commit'
Teach 'git merge' the --continue option which allows 'continuing' a merge by completing it. The traditional way of completing a merge after resolving conflicts is to use 'git commit'. Now with commands like 'git rebase' and 'git cherry-pick' having a '--continue' option adding such an option to 'git merge' presents a consistent UI. Signed-off-by: Chris Packham <judge.packham@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Chris Packham committed
Dec 14, 2016 at 21:37 UTC
367ff694281ce569edd8f6e444fc770f92f5d215
3 files changed
+38
Documentation/git-merge.txt
+8
@@ -15,6 +15,7 @@ SYNOPSIS
15
[--[no-]rerere-autoupdate] [-m <msg>] [<commit>...]
16
'git merge' <msg> HEAD <commit>...
17
'git merge' --abort
18
+'git merge' --continue
19
20
DESCRIPTION
21
-----------
@@ -61,6 +62,8 @@ reconstruct the original (pre-merge) changes. Therefore:
62
discouraged: while possible, it may leave you in a state that is hard to
63
back out of in the case of a conflict.
64
65
+The fourth syntax ("`git merge --continue`") can only be run after the
66
+merge has resulted in conflicts.
67
68
OPTIONS
69
-------
@@ -99,6 +102,11 @@ commit or stash your changes before running 'git merge'.
102
'git merge --abort' is equivalent to 'git reset --merge' when
103
`MERGE_HEAD` is present.
104
105
+--continue::
106
+ After a 'git merge' stops due to conflicts you can conclude the
107
+ merge by running 'git merge --continue' (see "HOW TO RESOLVE
108
+ CONFLICTS" section below).
109
+
110
<commit>...::
111
Commits, usually other branch heads, to merge into our branch.
112
Specifying more than one commit will create a merge with
builtin/merge.c
+21
@@ -46,6 +46,7 @@ static const char * const builtin_merge_usage[] = {
46
N_("git merge [<options>] [<commit>...]"),
47
N_("git merge [<options>] <msg> HEAD <commit>"),
48
N_("git merge --abort"),
49
+ N_("git merge --continue"),
50
NULL
51
};
52
@@ -65,6 +66,7 @@ static int option_renormalize;
66
static int verbosity;
67
static int allow_rerere_auto;
68
static int abort_current_merge;
69
+static int continue_current_merge;
70
static int allow_unrelated_histories;
71
static int show_progress = -1;
72
static int default_to_upstream = 1;
@@ -223,6 +225,8 @@ static struct option builtin_merge_options[] = {
225
OPT__VERBOSITY(&verbosity),
226
OPT_BOOL(0, "abort", &abort_current_merge,
227
N_("abort the current in-progress merge")),
228
+ OPT_BOOL(0, "continue", &continue_current_merge,
229
+ N_("continue the current in-progress merge")),
230
OPT_BOOL(0, "allow-unrelated-histories", &allow_unrelated_histories,
231
N_("allow merging unrelated histories")),
232
OPT_SET_INT(0, "progress", &show_progress, N_("force progress reporting"), 1),
@@ -1125,6 +1129,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1129
const char *best_strategy = NULL, *wt_strategy = NULL;
1130
struct commit_list *remoteheads, *p;
1131
void *branch_to_free;
1132
+ int orig_argc = argc;
1133
1134
if (argc == 2 && !strcmp(argv[1], "-h"))
1135
usage_with_options(builtin_merge_usage, builtin_merge_options);
@@ -1166,6 +1171,22 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1171
goto done;
1172
}
1173
1174
+ if (continue_current_merge) {
1175
+ int nargc = 1;
1176
+ const char *nargv[] = {"commit", NULL};
1177
+
1178
+ if (orig_argc != 2)
1179
+ usage_msg_opt("--continue expects no arguments",
1180
+ builtin_merge_usage, builtin_merge_options);
1181
+
1182
+ if (!file_exists(git_path_merge_head()))
1183
+ die(_("There is no merge in progress (MERGE_HEAD missing)."));
1184
+
1185
+ /* Invoke 'git commit' */
1186
+ ret = cmd_commit(nargc, nargv, prefix);
1187
+ goto done;
1188
+ }
1189
+
1190
if (read_cache_unmerged())
1191
die_resolve_conflict("merge");
1192
t/t7600-merge.sh
+9
@@ -154,6 +154,8 @@ test_expect_success 'test option parsing' '
154
test_must_fail git merge -s foobar c1 &&
155
test_must_fail git merge -s=foobar c1 &&
156
test_must_fail git merge -m &&
157
+ test_must_fail git merge --continue foobar &&
158
+ test_must_fail git merge --continue --quiet &&
159
test_must_fail git merge
160
'
161
@@ -763,4 +765,11 @@ test_expect_success 'merge nothing into void' '
765
)
766
'
767
768
+test_expect_success 'merge can be completed with --continue' '
769
+ git reset --hard c0 &&
770
+ git merge --no-ff --no-commit c1 &&
771
+ git merge --continue &&
772
+ verify_parents $c0 $c1
773
+'
774
+
775
test_done