Skip to content

Commit 6099835

Browse files
committed
Allow git merge ":/<pattern>"
It probably is not such a good idea to use ":/<pattern>" to specify which commit to merge, as ":/<pattern>" can often hit unexpected commits, but somebody tried it and got a nonsense error message: fatal: ':/Foo bar' does not point to a commit So here is a for-the-sake-of-consistency update that is fairly useless that allows users to carefully try not shooting in the foot. Signed-off-by: Junio C Hamano <[email protected]>
1 parent f696543 commit 6099835

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

builtin/merge.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,16 @@ static void finish(const unsigned char *new_head, const char *msg)
405405
strbuf_release(&reflog_message);
406406
}
407407

408+
static struct object *want_commit(const char *name)
409+
{
410+
struct object *obj;
411+
unsigned char sha1[20];
412+
if (get_sha1(name, sha1))
413+
return NULL;
414+
obj = parse_object(sha1);
415+
return peel_to_type(name, 0, obj, OBJ_COMMIT);
416+
}
417+
408418
/* Get the name for the merge commit's message. */
409419
static void merge_name(const char *remote, struct strbuf *msg)
410420
{
@@ -420,7 +430,7 @@ static void merge_name(const char *remote, struct strbuf *msg)
420430
remote = bname.buf;
421431

422432
memset(branch_head, 0, sizeof(branch_head));
423-
remote_head = peel_to_type(remote, 0, NULL, OBJ_COMMIT);
433+
remote_head = want_commit(remote);
424434
if (!remote_head)
425435
die(_("'%s' does not point to a commit"), remote);
426436

@@ -1130,7 +1140,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
11301140
if (!allow_fast_forward)
11311141
die(_("Non-fast-forward commit does not make sense into "
11321142
"an empty head"));
1133-
remote_head = peel_to_type(argv[0], 0, NULL, OBJ_COMMIT);
1143+
remote_head = want_commit(argv[0]);
11341144
if (!remote_head)
11351145
die(_("%s - not something we can merge"), argv[0]);
11361146
read_empty(remote_head->sha1, 0);
@@ -1176,7 +1186,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
11761186
struct object *o;
11771187
struct commit *commit;
11781188

1179-
o = peel_to_type(argv[i], 0, NULL, OBJ_COMMIT);
1189+
o = want_commit(argv[i]);
11801190
if (!o)
11811191
die(_("%s - not something we can merge"), argv[i]);
11821192
commit = lookup_commit(o->sha1);
@@ -1244,8 +1254,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
12441254
if (have_message)
12451255
strbuf_addstr(&msg,
12461256
" (no commit created; -m option ignored)");
1247-
o = peel_to_type(sha1_to_hex(remoteheads->item->object.sha1),
1248-
0, NULL, OBJ_COMMIT);
1257+
o = want_commit(sha1_to_hex(remoteheads->item->object.sha1));
12491258
if (!o)
12501259
return 1;
12511260

sha1_name.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -501,12 +501,6 @@ struct object *peel_to_type(const char *name, int namelen,
501501
{
502502
if (name && !namelen)
503503
namelen = strlen(name);
504-
if (!o) {
505-
unsigned char sha1[20];
506-
if (get_sha1_1(name, namelen, sha1))
507-
return NULL;
508-
o = parse_object(sha1);
509-
}
510504
while (1) {
511505
if (!o || (!o->parsed && !parse_object(o->sha1)))
512506
return NULL;

0 commit comments

Comments
 (0)