@matheusbsbs / matheus-bagliano / commits / 04c9e11f2c
Fork 0

checkout: error out when index is unmerged even with -m

Even when -m is given to allow fallilng back to 3-way merge while switching branches, we should refuse if the original index is unmerged. Signed-off-by: Junio C Hamano <gitster@pobox.com> Acked-by: Daniel Barkalow <barkalow@iabervon.org>

Junio C Hamano committed Feb 23, 2008 at 15:45 UTC 04c9e11f2cffaf84dd20602f811bf377f6033cb6
1 file changed +18 -17
builtin-checkout.c
+18 -17
@@ -226,24 +226,25 @@ static int merge_working_tree(struct checkout_opts *opts,
226 refresh_cache(REFRESH_QUIET);
227
228 if (unmerged_cache()) {
229 - ret = opts->merge ? -1 :
230 - error("you need to resolve your current index first");
231 - } else {
232 - topts.update = 1;
233 - topts.merge = 1;
234 - topts.gently = opts->merge;
235 - topts.verbose_update = !opts->quiet;
236 - topts.fn = twoway_merge;
237 - topts.dir = xcalloc(1, sizeof(*topts.dir));
238 - topts.dir->show_ignored = 1;
239 - topts.dir->exclude_per_dir = ".gitignore";
240 - tree = parse_tree_indirect(old->commit->object.sha1);
241 - init_tree_desc(&trees[0], tree->buffer, tree->size);
242 - tree = parse_tree_indirect(new->commit->object.sha1);
243 - init_tree_desc(&trees[1], tree->buffer, tree->size);
244 - ret = unpack_trees(2, trees, &topts);
229 + error("you need to resolve your current index first");
230 + return 1;
231 }
246 - if (ret) {
232 +
233 + /* 2-way merge to the new branch */
234 + topts.update = 1;
235 + topts.merge = 1;
236 + topts.gently = opts->merge;
237 + topts.verbose_update = !opts->quiet;
238 + topts.fn = twoway_merge;
239 + topts.dir = xcalloc(1, sizeof(*topts.dir));
240 + topts.dir->show_ignored = 1;
241 + topts.dir->exclude_per_dir = ".gitignore";
242 + tree = parse_tree_indirect(old->commit->object.sha1);
243 + init_tree_desc(&trees[0], tree->buffer, tree->size);
244 + tree = parse_tree_indirect(new->commit->object.sha1);
245 + init_tree_desc(&trees[1], tree->buffer, tree->size);
246 +
247 + if (unpack_trees(2, trees, &topts)) {
248 /*
249 * Unpack couldn't do a trivial merge; either
250 * give up or do a real merge, depending on