4 #include "merge-recursive.h"
5 #include "xdiff-interface.h"
7 static const char builtin_merge_recursive_usage
[] =
8 "git %s <base>... -- <head> <remote> ...";
10 static const char *better_branch_name(const char *branch
)
12 static char githead_env
[8 + 40 + 1];
15 if (strlen(branch
) != 40)
17 sprintf(githead_env
, "GITHEAD_%s", branch
);
18 name
= getenv(githead_env
);
19 return name
? name
: branch
;
22 int cmd_merge_recursive(int argc
, const char **argv
, const char *prefix
)
24 const unsigned char *bases
[21];
25 unsigned bases_count
= 0;
27 unsigned char h1
[20], h2
[20];
28 struct merge_options o
;
29 struct commit
*result
;
31 init_merge_options(&o
);
32 if (argv
[0] && !suffixcmp(argv
[0], "-subtree"))
36 usagef(builtin_merge_recursive_usage
, argv
[0]);
38 for (i
= 1; i
< argc
; ++i
) {
39 const char *arg
= argv
[i
];
41 if (!prefixcmp(arg
, "--")) {
44 if (parse_merge_opt(&o
, arg
+ 2))
45 die("Unknown option %s", arg
);
48 if (bases_count
< ARRAY_SIZE(bases
)-1) {
49 unsigned char *sha
= xmalloc(20);
50 if (get_sha1(argv
[i
], sha
))
51 die("Could not parse object '%s'", argv
[i
]);
52 bases
[bases_count
++] = sha
;
55 warning("Cannot handle more than %d bases. "
57 (int)ARRAY_SIZE(bases
)-1, argv
[i
]);
59 if (argc
- i
!= 3) /* "--" "<head>" "<remote>" */
60 die("Not handling anything other than two heads merge.");
62 o
.branch1
= argv
[++i
];
63 o
.branch2
= argv
[++i
];
65 if (get_sha1(o
.branch1
, h1
))
66 die("Could not resolve ref '%s'", o
.branch1
);
67 if (get_sha1(o
.branch2
, h2
))
68 die("Could not resolve ref '%s'", o
.branch2
);
70 o
.branch1
= better_branch_name(o
.branch1
);
71 o
.branch2
= better_branch_name(o
.branch2
);
74 printf("Merging %s with %s\n", o
.branch1
, o
.branch2
);
76 failed
= merge_recursive_generic(&o
, h1
, h2
, bases_count
, bases
, &result
);
78 return 128; /* die() error code */