1 #define USE_THE_REPOSITORY_VARIABLE
6 #include "merge-recursive.h"
7 #include "object-name.h"
9 static const char builtin_merge_recursive_usage
[] =
10 "git %s <base>... -- <head> <remote> ...";
12 static char *better_branch_name(const char *branch
)
14 static char githead_env
[8 + GIT_MAX_HEXSZ
+ 1];
17 if (strlen(branch
) != the_hash_algo
->hexsz
)
18 return xstrdup(branch
);
19 xsnprintf(githead_env
, sizeof(githead_env
), "GITHEAD_%s", branch
);
20 name
= getenv(githead_env
);
21 return xstrdup(name
? name
: branch
);
24 int cmd_merge_recursive(int argc
,
26 const char *prefix UNUSED
,
27 struct repository
*repo UNUSED
)
29 struct object_id bases
[21];
30 unsigned bases_count
= 0;
32 struct object_id h1
, h2
;
33 struct merge_options o
;
34 char *better1
, *better2
;
35 struct commit
*result
;
37 init_basic_merge_options(&o
, the_repository
);
38 if (argv
[0] && ends_with(argv
[0], "-subtree"))
42 usagef(builtin_merge_recursive_usage
, argv
[0]);
44 for (i
= 1; i
< argc
; ++i
) {
45 const char *arg
= argv
[i
];
47 if (starts_with(arg
, "--")) {
50 if (parse_merge_opt(&o
, arg
+ 2))
51 die(_("unknown option %s"), arg
);
54 if (bases_count
< ARRAY_SIZE(bases
)-1) {
55 if (repo_get_oid(the_repository
, argv
[i
], &bases
[bases_count
++]))
56 die(_("could not parse object '%s'"), argv
[i
]);
59 warning(Q_("cannot handle more than %d base. "
61 "cannot handle more than %d bases. "
64 (int)ARRAY_SIZE(bases
)-1, argv
[i
]);
66 if (argc
- i
!= 3) /* "--" "<head>" "<remote>" */
67 die(_("not handling anything other than two heads merge."));
69 if (repo_read_index_unmerged(the_repository
))
70 die_resolve_conflict("merge");
72 o
.branch1
= argv
[++i
];
73 o
.branch2
= argv
[++i
];
75 if (repo_get_oid(the_repository
, o
.branch1
, &h1
))
76 die(_("could not resolve ref '%s'"), o
.branch1
);
77 if (repo_get_oid(the_repository
, o
.branch2
, &h2
))
78 die(_("could not resolve ref '%s'"), o
.branch2
);
80 o
.branch1
= better1
= better_branch_name(o
.branch1
);
81 o
.branch2
= better2
= better_branch_name(o
.branch2
);
84 printf(_("Merging %s with %s\n"), o
.branch1
, o
.branch2
);
86 failed
= merge_recursive_generic(&o
, &h1
, &h2
, bases_count
, bases
, &result
);
92 return 128; /* die() error code */