merge_trees(): ensure that the callers release output buffer
[gitweb.git] / builtin / checkout.c
index c3486bdec364fde395cf3523b778ec4dc9c3223a..8d852d458514ca8d2e9553bec6a818b140b0e478 100644 (file)
@@ -276,7 +276,7 @@ static int checkout_paths(const struct checkout_opts *opts,
 
        hold_locked_index(lock_file, 1);
        if (read_cache_preload(&opts->pathspec) < 0)
-               return error(_("corrupt index file"));
+               return error(_("index file corrupt"));
 
        if (opts->source_tree)
                read_tree_some(opts->source_tree, &opts->pathspec);
@@ -470,7 +470,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
 
        hold_locked_index(lock_file, 1);
        if (read_cache_preload(NULL) < 0)
-               return error(_("corrupt index file"));
+               return error(_("index file corrupt"));
 
        resolve_undo_clear();
        if (opts->force) {
@@ -567,10 +567,13 @@ static int merge_working_tree(const struct checkout_opts *opts,
                        o.ancestor = old->name;
                        o.branch1 = new->name;
                        o.branch2 = "local";
-                       merge_trees(&o, new->commit->tree, work,
+                       ret = merge_trees(&o, new->commit->tree, work,
                                old->commit->tree, &result);
+                       if (ret < 0)
+                               exit(128);
                        ret = reset_tree(new->commit->tree, opts, 0,
                                         writeout_error);
+                       strbuf_release(&o.obuf);
                        if (ret)
                                return ret;
                }
@@ -1138,7 +1141,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
                OPT_STRING('B', NULL, &opts.new_branch_force, N_("branch"),
                           N_("create/reset and checkout a branch")),
                OPT_BOOL('l', NULL, &opts.new_branch_log, N_("create reflog for new branch")),
-               OPT_BOOL(0, "detach", &opts.force_detach, N_("detach the HEAD at named commit")),
+               OPT_BOOL(0, "detach", &opts.force_detach, N_("detach HEAD at named commit")),
                OPT_SET_INT('t', "track",  &opts.track, N_("set upstream info for new branch"),
                        BRANCH_TRACK_EXPLICIT),
                OPT_STRING(0, "orphan", &opts.new_orphan_branch, N_("new-branch"), N_("new unparented branch")),