Skip to content

Commit 1faac1c

Browse files
committed
merge: clarify "pulling into void" special case
Instead of having it as one of the three if/elseif/.. case arms, test the condition and handle this special case upfront. This makes it easier to follow the flow of logic. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7ad39a2 commit 1faac1c

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

builtin/merge.c

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,23 +1178,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
11781178
usage_with_options(builtin_merge_usage,
11791179
builtin_merge_options);
11801180

1181-
/*
1182-
* This could be traditional "merge <msg> HEAD <commit>..." and
1183-
* the way we can tell it is to see if the second token is HEAD,
1184-
* but some people might have misused the interface and used a
1185-
* commit-ish that is the same as HEAD there instead.
1186-
* Traditional format never would have "-m" so it is an
1187-
* additional safety measure to check for it.
1188-
*/
1189-
1190-
if (!have_message && head_commit &&
1191-
is_old_style_invocation(argc, argv, head_commit->object.sha1)) {
1192-
strbuf_addstr(&merge_msg, argv[0]);
1193-
head_arg = argv[1];
1194-
argv += 2;
1195-
argc -= 2;
1196-
remoteheads = collect_parents(head_commit, &head_subsumed, argc, argv);
1197-
} else if (!head_commit) {
1181+
if (!head_commit) {
11981182
struct commit *remote_head;
11991183
/*
12001184
* If the merged head is a valid one there is no reason
@@ -1217,6 +1201,23 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
12171201
update_ref("initial pull", "HEAD", remote_head->object.sha1,
12181202
NULL, 0, UPDATE_REFS_DIE_ON_ERR);
12191203
goto done;
1204+
}
1205+
1206+
/*
1207+
* This could be traditional "merge <msg> HEAD <commit>..." and
1208+
* the way we can tell it is to see if the second token is HEAD,
1209+
* but some people might have misused the interface and used a
1210+
* commit-ish that is the same as HEAD there instead.
1211+
* Traditional format never would have "-m" so it is an
1212+
* additional safety measure to check for it.
1213+
*/
1214+
if (!have_message &&
1215+
is_old_style_invocation(argc, argv, head_commit->object.sha1)) {
1216+
strbuf_addstr(&merge_msg, argv[0]);
1217+
head_arg = argv[1];
1218+
argv += 2;
1219+
argc -= 2;
1220+
remoteheads = collect_parents(head_commit, &head_subsumed, argc, argv);
12201221
} else {
12211222
struct strbuf merge_names = STRBUF_INIT;
12221223

0 commit comments

Comments
 (0)