5 #include "merge-recursive.h"
6 #include "xdiff-interface.h"
8 static const char builtin_merge_recursive_usage
[] =
9 "git %s <base>... -- <head> <remote> ...";
11 static char *better_branch_name(const char *branch
)
13 static char githead_env
[8 + GIT_MAX_HEXSZ
+ 1];
16 if (strlen(branch
) != the_hash_algo
->hexsz
)
17 return xstrdup(branch
);
18 xsnprintf(githead_env
, sizeof(githead_env
), "GITHEAD_%s", branch
);
19 name
= getenv(githead_env
);
20 return xstrdup(name
? name
: branch
);
23 int cmd_merge_recursive(int argc
, const char **argv
, const char *prefix
)
25 const struct object_id
*bases
[21];
26 unsigned bases_count
= 0;
28 struct object_id h1
, h2
;
29 struct merge_options o
;
30 char *better1
, *better2
;
31 struct commit
*result
;
33 init_merge_options(&o
, the_repository
);
34 if (argv
[0] && ends_with(argv
[0], "-subtree"))
38 usagef(builtin_merge_recursive_usage
, argv
[0]);
40 for (i
= 1; i
< argc
; ++i
) {
41 const char *arg
= argv
[i
];
43 if (starts_with(arg
, "--")) {
46 if (parse_merge_opt(&o
, arg
+ 2))
47 die(_("unknown option %s"), arg
);
50 if (bases_count
< ARRAY_SIZE(bases
)-1) {
51 struct object_id
*oid
= xmalloc(sizeof(struct object_id
));
52 if (get_oid(argv
[i
], oid
))
53 die(_("could not parse object '%s'"), argv
[i
]);
54 bases
[bases_count
++] = oid
;
57 warning(Q_("cannot handle more than %d base. "
59 "cannot handle more than %d bases. "
62 (int)ARRAY_SIZE(bases
)-1, argv
[i
]);
64 if (argc
- i
!= 3) /* "--" "<head>" "<remote>" */
65 die(_("not handling anything other than two heads merge."));
67 if (repo_read_index_unmerged(the_repository
))
68 die_resolve_conflict("merge");
70 o
.branch1
= argv
[++i
];
71 o
.branch2
= argv
[++i
];
73 if (get_oid(o
.branch1
, &h1
))
74 die(_("could not resolve ref '%s'"), o
.branch1
);
75 if (get_oid(o
.branch2
, &h2
))
76 die(_("could not resolve ref '%s'"), o
.branch2
);
78 o
.branch1
= better1
= better_branch_name(o
.branch1
);
79 o
.branch2
= better2
= better_branch_name(o
.branch2
);
82 printf(_("Merging %s with %s\n"), o
.branch1
, o
.branch2
);
84 failed
= merge_recursive_generic(&o
, &h1
, &h2
, bases_count
, bases
, &result
);
90 return 128; /* die() error code */