6 #include "run-command.h"
7 #include "resolve-undo.h"
9 #include "unpack-trees.h"
12 static const char *merge_argument(struct commit
*commit
)
14 return oid_to_hex(commit
? &commit
->object
.oid
: the_hash_algo
->empty_tree
);
17 int try_merge_command(const char *strategy
, size_t xopts_nr
,
18 const char **xopts
, struct commit_list
*common
,
19 const char *head_arg
, struct commit_list
*remotes
)
21 struct argv_array args
= ARGV_ARRAY_INIT
;
23 struct commit_list
*j
;
25 argv_array_pushf(&args
, "merge-%s", strategy
);
26 for (i
= 0; i
< xopts_nr
; i
++)
27 argv_array_pushf(&args
, "--%s", xopts
[i
]);
28 for (j
= common
; j
; j
= j
->next
)
29 argv_array_push(&args
, merge_argument(j
->item
));
30 argv_array_push(&args
, "--");
31 argv_array_push(&args
, head_arg
);
32 for (j
= remotes
; j
; j
= j
->next
)
33 argv_array_push(&args
, merge_argument(j
->item
));
35 ret
= run_command_v_opt(args
.argv
, RUN_GIT_CMD
);
36 argv_array_clear(&args
);
40 die(_("failed to read the cache"));
46 int checkout_fast_forward(const struct object_id
*head
,
47 const struct object_id
*remote
,
50 struct tree
*trees
[MAX_UNPACK_TREES
];
51 struct unpack_trees_options opts
;
52 struct tree_desc t
[MAX_UNPACK_TREES
];
54 struct dir_struct dir
;
55 struct lock_file lock_file
= LOCK_INIT
;
57 refresh_cache(REFRESH_QUIET
);
59 if (hold_locked_index(&lock_file
, LOCK_REPORT_ON_ERROR
) < 0)
62 memset(&trees
, 0, sizeof(trees
));
63 memset(&t
, 0, sizeof(t
));
65 trees
[nr_trees
] = parse_tree_indirect(head
);
66 if (!trees
[nr_trees
++]) {
67 rollback_lock_file(&lock_file
);
70 trees
[nr_trees
] = parse_tree_indirect(remote
);
71 if (!trees
[nr_trees
++]) {
72 rollback_lock_file(&lock_file
);
75 for (i
= 0; i
< nr_trees
; i
++) {
77 init_tree_desc(t
+i
, trees
[i
]->buffer
, trees
[i
]->size
);
80 memset(&opts
, 0, sizeof(opts
));
81 if (overwrite_ignore
) {
82 memset(&dir
, 0, sizeof(dir
));
83 dir
.flags
|= DIR_SHOW_IGNORED
;
84 setup_standard_excludes(&dir
);
89 opts
.src_index
= &the_index
;
90 opts
.dst_index
= &the_index
;
92 opts
.verbose_update
= 1;
94 opts
.fn
= twoway_merge
;
95 setup_unpack_trees_porcelain(&opts
, "merge");
97 if (unpack_trees(nr_trees
, t
, &opts
)) {
98 rollback_lock_file(&lock_file
);
99 clear_unpack_trees_porcelain(&opts
);
102 clear_unpack_trees_porcelain(&opts
);
104 if (write_locked_index(&the_index
, &lock_file
, COMMIT_LOCK
))
105 return error(_("unable to write new index file"));