Skip to content

Commit eaa4e59

Browse files
committed
merge: do not check argc to determine number of remote heads
To reject merging multiple commits into an unborn branch, we check argc, thinking that collect_parents() that reads the remaining command line arguments from <argc, argv> will give us the same number of commits as its input, i.e. argc. Because what we really care about is the number of commits, let the function run and then make sure it returns only one commit instead. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1faac1c commit eaa4e59

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

builtin/merge.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,9 +1185,6 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
11851185
* to forbid "git merge" into a branch yet to be born.
11861186
* We do the same for "git pull".
11871187
*/
1188-
if (argc != 1)
1189-
die(_("Can merge only exactly one commit into "
1190-
"empty head"));
11911188
if (squash)
11921189
die(_("Squash commit into empty head not supported yet"));
11931190
if (fast_forward == FF_NO)
@@ -1197,6 +1194,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
11971194
remote_head = remoteheads->item;
11981195
if (!remote_head)
11991196
die(_("%s - not something we can merge"), argv[0]);
1197+
if (remoteheads->next)
1198+
die(_("Can merge only exactly one commit into empty head"));
12001199
read_empty(remote_head->object.sha1, 0);
12011200
update_ref("initial pull", "HEAD", remote_head->object.sha1,
12021201
NULL, 0, UPDATE_REFS_DIE_ON_ERR);

0 commit comments

Comments
 (0)