|
19 | 19 |
|
20 | 20 | #include "diff.h"
|
21 | 21 | #include "diffcore.h"
|
| 22 | +#include "dir.h" |
22 | 23 | #include "object-store.h"
|
23 | 24 | #include "strmap.h"
|
24 | 25 | #include "tree.h"
|
| 26 | +#include "unpack-trees.h" |
25 | 27 | #include "xdiff-interface.h"
|
26 | 28 |
|
27 | 29 | /*
|
@@ -975,7 +977,48 @@ static int checkout(struct merge_options *opt,
|
975 | 977 | struct tree *prev,
|
976 | 978 | struct tree *next)
|
977 | 979 | {
|
978 |
| - die("Not yet implemented."); |
| 980 | + /* Switch the index/working copy from old to new */ |
| 981 | + int ret; |
| 982 | + struct tree_desc trees[2]; |
| 983 | + struct unpack_trees_options unpack_opts; |
| 984 | + |
| 985 | + memset(&unpack_opts, 0, sizeof(unpack_opts)); |
| 986 | + unpack_opts.head_idx = -1; |
| 987 | + unpack_opts.src_index = opt->repo->index; |
| 988 | + unpack_opts.dst_index = opt->repo->index; |
| 989 | + |
| 990 | + setup_unpack_trees_porcelain(&unpack_opts, "merge"); |
| 991 | + |
| 992 | + /* |
| 993 | + * NOTE: if this were just "git checkout" code, we would probably |
| 994 | + * read or refresh the cache and check for a conflicted index, but |
| 995 | + * builtin/merge.c or sequencer.c really needs to read the index |
| 996 | + * and check for conflicted entries before starting merging for a |
| 997 | + * good user experience (no sense waiting for merges/rebases before |
| 998 | + * erroring out), so there's no reason to duplicate that work here. |
| 999 | + */ |
| 1000 | + |
| 1001 | + /* 2-way merge to the new branch */ |
| 1002 | + unpack_opts.update = 1; |
| 1003 | + unpack_opts.merge = 1; |
| 1004 | + unpack_opts.quiet = 0; /* FIXME: sequencer might want quiet? */ |
| 1005 | + unpack_opts.verbose_update = (opt->verbosity > 2); |
| 1006 | + unpack_opts.fn = twoway_merge; |
| 1007 | + if (1/* FIXME: opts->overwrite_ignore*/) { |
| 1008 | + unpack_opts.dir = xcalloc(1, sizeof(*unpack_opts.dir)); |
| 1009 | + unpack_opts.dir->flags |= DIR_SHOW_IGNORED; |
| 1010 | + setup_standard_excludes(unpack_opts.dir); |
| 1011 | + } |
| 1012 | + parse_tree(prev); |
| 1013 | + init_tree_desc(&trees[0], prev->buffer, prev->size); |
| 1014 | + parse_tree(next); |
| 1015 | + init_tree_desc(&trees[1], next->buffer, next->size); |
| 1016 | + |
| 1017 | + ret = unpack_trees(2, trees, &unpack_opts); |
| 1018 | + clear_unpack_trees_porcelain(&unpack_opts); |
| 1019 | + dir_clear(unpack_opts.dir); |
| 1020 | + FREE_AND_NULL(unpack_opts.dir); |
| 1021 | + return ret; |
979 | 1022 | }
|
980 | 1023 |
|
981 | 1024 | static int record_conflicted_index_entries(struct merge_options *opt,
|
|
0 commit comments