Sync with 'maint'
[gitweb.git] / builtin / reset.c
index 088ccffba07a4227150290492f22dc3bbac56fdc..f2f9d55392d2193432d5a572a70cd27afcf6b136 100644 (file)
@@ -143,7 +143,6 @@ static int read_from_tree(const struct pathspec *pathspec,
        opt.output_format = DIFF_FORMAT_CALLBACK;
        opt.format_callback = update_index_from_diff;
 
-       read_cache();
        if (do_diff_cache(tree_sha1, &opt))
                return 1;
        diffcore_std(&opt);
@@ -169,7 +168,7 @@ static void set_reflog_message(struct strbuf *sb, const char *action,
 
 static void die_if_unmerged_cache(int reset_type)
 {
-       if (is_merge() || read_cache() < 0 || unmerged_cache())
+       if (is_merge() || unmerged_cache())
                die(_("Cannot do a %s reset in the middle of a merge."),
                    _(reset_type_names[reset_type]));
 
@@ -220,13 +219,18 @@ static void parse_args(struct pathspec *pathspec,
                }
        }
        *rev_ret = rev;
+
+       if (read_cache() < 0)
+               die(_("index file corrupt"));
+
        parse_pathspec(pathspec, 0,
                       PATHSPEC_PREFER_FULL |
+                      PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP |
                       (patch_mode ? PATHSPEC_PREFIX_ORIGIN : 0),
                       prefix, argv);
 }
 
-static int update_refs(const char *rev, const unsigned char *sha1)
+static int reset_refs(const char *rev, const unsigned char *sha1)
 {
        int update_ref_status;
        struct strbuf msg = STRBUF_INIT;
@@ -354,7 +358,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
        if (!pathspec.nr && !unborn) {
                /* Any resets without paths update HEAD to the head being
                 * switched to, saving the previous head in ORIG_HEAD before. */
-               update_ref_status = update_refs(rev, sha1);
+               update_ref_status = reset_refs(rev, sha1);
 
                if (reset_type == HARD && !update_ref_status && !quiet)
                        print_new_head_line(lookup_commit_reference(sha1));