X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;ds=inline;f=builtin-checkout.c;h=b5dd9c07b42e0130384259715730f52bc8c4e6c3;hb=e8c35317172aab9da7afe555da603021a3ae89e5;hp=464fd2570735485a35d34c4aa8d50e5a1930228c;hpb=168d5bd57b8183f8da0ea30a0d4d3c2422eec4e4;p=git.git diff --git a/builtin-checkout.c b/builtin-checkout.c index 464fd2570..b5dd9c07b 100644 --- a/builtin-checkout.c +++ b/builtin-checkout.c @@ -228,7 +228,8 @@ static int checkout_paths(struct tree *source_tree, const char **pathspec, struct lock_file *lock_file = xcalloc(1, sizeof(struct lock_file)); newfd = hold_locked_index(lock_file, 1); - read_cache(); + if (read_cache() < 0) + return error("corrupt index file"); if (source_tree) read_tree_some(source_tree, pathspec); @@ -371,7 +372,9 @@ static int merge_working_tree(struct checkout_opts *opts, int ret; struct lock_file *lock_file = xcalloc(1, sizeof(struct lock_file)); int newfd = hold_locked_index(lock_file, 1); - read_cache(); + + if (read_cache() < 0) + return error("corrupt index file"); if (opts->force) { ret = reset_tree(new->commit->tree, opts, 1); @@ -553,7 +556,7 @@ static int switch_branches(struct checkout_opts *opts, struct branch_info *new) if (!opts->quiet && !old.path && old.commit && new->commit != old.commit) describe_detached_head("Previous HEAD position was", old.commit); - if (!old.commit) { + if (!old.commit && !opts->force) { if (!opts->quiet) { fprintf(stderr, "warning: You appear to be on a branch yet to be born.\n"); fprintf(stderr, "warning: Forcing checkout of %s.\n", new->name); @@ -678,8 +681,8 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) argv++; argc--; + new.name = arg; if ((new.commit = lookup_commit_reference_gently(rev, 1))) { - new.name = arg; setup_branch_path(&new); if (resolve_ref(new.path, rev, 1, NULL)) new.commit = lookup_commit_reference(rev);