]> git.ipfire.org Git - thirdparty/git.git/blob - merge-ort-wrappers.c
clone: allow "--bare" with "-o"
[thirdparty/git.git] / merge-ort-wrappers.c
1 #include "cache.h"
2 #include "merge-ort.h"
3 #include "merge-ort-wrappers.h"
4
5 #include "commit.h"
6
7 static int unclean(struct merge_options *opt, struct tree *head)
8 {
9 /* Sanity check on repo state; index must match head */
10 struct strbuf sb = STRBUF_INIT;
11
12 if (head && repo_index_has_changes(opt->repo, head, &sb)) {
13 fprintf(stderr, _("Your local changes to the following files would be overwritten by merge:\n %s"),
14 sb.buf);
15 strbuf_release(&sb);
16 return -1;
17 }
18
19 return 0;
20 }
21
22 int merge_ort_nonrecursive(struct merge_options *opt,
23 struct tree *head,
24 struct tree *merge,
25 struct tree *merge_base)
26 {
27 struct merge_result result;
28
29 if (unclean(opt, head))
30 return -1;
31
32 if (oideq(&merge_base->object.oid, &merge->object.oid)) {
33 printf_ln(_("Already up to date."));
34 return 1;
35 }
36
37 memset(&result, 0, sizeof(result));
38 merge_incore_nonrecursive(opt, merge_base, head, merge, &result);
39 merge_switch_to_result(opt, head, &result, 1, 1);
40
41 return result.clean;
42 }
43
44 int merge_ort_recursive(struct merge_options *opt,
45 struct commit *side1,
46 struct commit *side2,
47 struct commit_list *merge_bases,
48 struct commit **result)
49 {
50 struct tree *head = repo_get_commit_tree(opt->repo, side1);
51 struct merge_result tmp;
52
53 if (unclean(opt, head))
54 return -1;
55
56 memset(&tmp, 0, sizeof(tmp));
57 merge_incore_recursive(opt, merge_bases, side1, side2, &tmp);
58 merge_switch_to_result(opt, head, &tmp, 1, 1);
59 *result = NULL;
60
61 return tmp.clean;
62 }