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 <gitster@pobox.com>
Junio C Hamano committed
Apr 23, 2015 at 13:56 UTC
eaa4e59c8545f61c6e61559df33dc4792e455d5a
1 file changed
+2
-3
builtin/merge.c
+2
-3
@@ -1185,9 +1185,6 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1185
* to forbid "git merge" into a branch yet to be born.
1186
* We do the same for "git pull".
1187
*/
1188
- if (argc != 1)
1189
- die(_("Can merge only exactly one commit into "
1190
- "empty head"));
1188
if (squash)
1189
die(_("Squash commit into empty head not supported yet"));
1190
if (fast_forward == FF_NO)
@@ -1197,6 +1194,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1194
remote_head = remoteheads->item;
1195
if (!remote_head)
1196
die(_("%s - not something we can merge"), argv[0]);
1197
+ if (remoteheads->next)
1198
+ die(_("Can merge only exactly one commit into empty head"));
1199
read_empty(remote_head->object.sha1, 0);
1200
update_ref("initial pull", "HEAD", remote_head->object.sha1,
1201
NULL, 0, UPDATE_REFS_DIE_ON_ERR);