396
397
struct merge_tree_options {
398
int mode;
399
+ int show_messages;
400
};
401
402
static int real_merge(struct merge_tree_options *o,
436
merge_incore_recursive(&opt, merge_bases, parent1, parent2, &result);
437
if (result.clean < 0)
438
die(_("failure to merge"));
439
+
440
+ if (o->show_messages == -1)
441
+ o->show_messages = !result.clean;
442
+
443
puts(oid_to_hex(&result.tree->object.oid));
444
+ if (o->show_messages) {
445
+ printf("\n");
446
+ merge_display_update_messages(&opt, &result);
447
+ }
448
merge_finalize(&opt, &result);
449
return !result.clean; /* result.clean < 0 handled above */
450
}
451
452
int cmd_merge_tree(int argc, const char **argv, const char *prefix)
453
{
445
- struct merge_tree_options o = { 0 };
454
+ struct merge_tree_options o = { .show_messages = -1 };
455
int expected_remaining_argc;
456
+ int original_argc;
457
458
const char * const merge_tree_usage[] = {
449
- N_("git merge-tree [--write-tree] <branch1> <branch2>"),
459
+ N_("git merge-tree [--write-tree] [<options>] <branch1> <branch2>"),
460
N_("git merge-tree [--trivial-merge] <base-tree> <branch1> <branch2>"),
461
NULL
462
};
466
MODE_REAL),
467
OPT_CMDMODE(0, "trivial-merge", &o.mode,
468
N_("do a trivial merge only"), MODE_TRIVIAL),
469
+ OPT_BOOL(0, "messages", &o.show_messages,
470
+ N_("also show informational/conflict messages")),
471
OPT_END()
472
};
473
474
/* Parse arguments */
475
+ original_argc = argc - 1; /* ignoring argv[0] */
476
argc = parse_options(argc, argv, prefix, mt_options,
477
merge_tree_usage, PARSE_OPT_STOP_AT_NON_OPTION);
478
switch (o.mode) {
496
break;
497
case MODE_TRIVIAL:
498
expected_remaining_argc = 3;
499
+ /* Removal of `--trivial-merge` is expected */
500
+ original_argc--;
501
break;
502
}
503
+ if (o.mode == MODE_TRIVIAL && argc < original_argc)
504
+ die(_("--trivial-merge is incompatible with all other options"));
505
506
if (argc != expected_remaining_argc)
507
usage_with_options(merge_tree_usage, mt_options);