/src/git/builtin/merge-recursive.c
Line | Count | Source (jump to first uncovered line) |
1 | | #include "builtin.h" |
2 | | #include "advice.h" |
3 | | #include "gettext.h" |
4 | | #include "hash.h" |
5 | | #include "merge-recursive.h" |
6 | | #include "object-name.h" |
7 | | #include "repository.h" |
8 | | |
9 | | static const char builtin_merge_recursive_usage[] = |
10 | | "git %s <base>... -- <head> <remote> ..."; |
11 | | |
12 | | static char *better_branch_name(const char *branch) |
13 | 0 | { |
14 | 0 | static char githead_env[8 + GIT_MAX_HEXSZ + 1]; |
15 | 0 | char *name; |
16 | |
|
17 | 0 | if (strlen(branch) != the_hash_algo->hexsz) |
18 | 0 | return xstrdup(branch); |
19 | 0 | xsnprintf(githead_env, sizeof(githead_env), "GITHEAD_%s", branch); |
20 | 0 | name = getenv(githead_env); |
21 | 0 | return xstrdup(name ? name : branch); |
22 | 0 | } |
23 | | |
24 | | int cmd_merge_recursive(int argc, const char **argv, const char *prefix UNUSED) |
25 | 0 | { |
26 | 0 | struct object_id bases[21]; |
27 | 0 | unsigned bases_count = 0; |
28 | 0 | int i, failed; |
29 | 0 | struct object_id h1, h2; |
30 | 0 | struct merge_options o; |
31 | 0 | char *better1, *better2; |
32 | 0 | struct commit *result; |
33 | |
|
34 | 0 | init_basic_merge_options(&o, the_repository); |
35 | 0 | if (argv[0] && ends_with(argv[0], "-subtree")) |
36 | 0 | o.subtree_shift = ""; |
37 | |
|
38 | 0 | if (argc < 4) |
39 | 0 | usagef(builtin_merge_recursive_usage, argv[0]); |
40 | | |
41 | 0 | for (i = 1; i < argc; ++i) { |
42 | 0 | const char *arg = argv[i]; |
43 | |
|
44 | 0 | if (starts_with(arg, "--")) { |
45 | 0 | if (!arg[2]) |
46 | 0 | break; |
47 | 0 | if (parse_merge_opt(&o, arg + 2)) |
48 | 0 | die(_("unknown option %s"), arg); |
49 | 0 | continue; |
50 | 0 | } |
51 | 0 | if (bases_count < ARRAY_SIZE(bases)-1) { |
52 | 0 | if (repo_get_oid(the_repository, argv[i], &bases[bases_count++])) |
53 | 0 | die(_("could not parse object '%s'"), argv[i]); |
54 | 0 | } |
55 | 0 | else |
56 | 0 | warning(Q_("cannot handle more than %d base. " |
57 | 0 | "Ignoring %s.", |
58 | 0 | "cannot handle more than %d bases. " |
59 | 0 | "Ignoring %s.", |
60 | 0 | ARRAY_SIZE(bases)-1), |
61 | 0 | (int)ARRAY_SIZE(bases)-1, argv[i]); |
62 | 0 | } |
63 | 0 | if (argc - i != 3) /* "--" "<head>" "<remote>" */ |
64 | 0 | die(_("not handling anything other than two heads merge.")); |
65 | | |
66 | 0 | if (repo_read_index_unmerged(the_repository)) |
67 | 0 | die_resolve_conflict("merge"); |
68 | | |
69 | 0 | o.branch1 = argv[++i]; |
70 | 0 | o.branch2 = argv[++i]; |
71 | |
|
72 | 0 | if (repo_get_oid(the_repository, o.branch1, &h1)) |
73 | 0 | die(_("could not resolve ref '%s'"), o.branch1); |
74 | 0 | if (repo_get_oid(the_repository, o.branch2, &h2)) |
75 | 0 | die(_("could not resolve ref '%s'"), o.branch2); |
76 | | |
77 | 0 | o.branch1 = better1 = better_branch_name(o.branch1); |
78 | 0 | o.branch2 = better2 = better_branch_name(o.branch2); |
79 | |
|
80 | 0 | if (o.verbosity >= 3) |
81 | 0 | printf(_("Merging %s with %s\n"), o.branch1, o.branch2); |
82 | |
|
83 | 0 | failed = merge_recursive_generic(&o, &h1, &h2, bases_count, bases, &result); |
84 | |
|
85 | 0 | free(better1); |
86 | 0 | free(better2); |
87 | |
|
88 | 0 | if (failed < 0) |
89 | 0 | return 128; /* die() error code */ |
90 | 0 | return failed; |
91 | 0 | } |