4 #include "run-command.h"
5 #include "resolve-undo.h"
7 #include "unpack-trees.h"
10 static const char *merge_argument(struct commit *commit)
13 return oid_to_hex(&commit->object.oid);
15 return EMPTY_TREE_SHA1_HEX;
18 int try_merge_command(const char *strategy, size_t xopts_nr,
19 const char **xopts, struct commit_list *common,
20 const char *head_arg, struct commit_list *remotes)
22 struct argv_array args = ARGV_ARRAY_INIT;
24 struct commit_list *j;
26 argv_array_pushf(&args, "merge-%s", strategy);
27 for (i = 0; i < xopts_nr; i++)
28 argv_array_pushf(&args, "--%s", xopts[i]);
29 for (j = common; j; j = j->next)
30 argv_array_push(&args, merge_argument(j->item));
31 argv_array_push(&args, "--");
32 argv_array_push(&args, head_arg);
33 for (j = remotes; j; j = j->next)
34 argv_array_push(&args, merge_argument(j->item));
36 ret = run_command_v_opt(args.argv, RUN_GIT_CMD);
37 argv_array_clear(&args);
41 die(_("failed to read the cache"));
47 int checkout_fast_forward(const struct object_id *head,
48 const struct object_id *remote,
51 struct tree *trees[MAX_UNPACK_TREES];
52 struct unpack_trees_options opts;
53 struct tree_desc t[MAX_UNPACK_TREES];
55 struct dir_struct dir;
56 struct lock_file *lock_file = xcalloc(1, sizeof(struct lock_file));
58 refresh_cache(REFRESH_QUIET);
60 if (hold_locked_index(lock_file, LOCK_REPORT_ON_ERROR) < 0)
63 memset(&trees, 0, sizeof(trees));
64 memset(&opts, 0, sizeof(opts));
65 memset(&t, 0, sizeof(t));
66 if (overwrite_ignore) {
67 memset(&dir, 0, sizeof(dir));
68 dir.flags |= DIR_SHOW_IGNORED;
69 setup_standard_excludes(&dir);
74 opts.src_index = &the_index;
75 opts.dst_index = &the_index;
77 opts.verbose_update = 1;
79 opts.fn = twoway_merge;
80 setup_unpack_trees_porcelain(&opts, "merge");
82 trees[nr_trees] = parse_tree_indirect(head);
83 if (!trees[nr_trees++])
85 trees[nr_trees] = parse_tree_indirect(remote);
86 if (!trees[nr_trees++])
88 for (i = 0; i < nr_trees; i++) {
90 init_tree_desc(t+i, trees[i]->buffer, trees[i]->size);
92 if (unpack_trees(nr_trees, t, &opts))
94 if (write_locked_index(&the_index, lock_file, COMMIT_LOCK)) {
95 rollback_lock_file(lock_file);
96 return error(_("unable to write new index file"));