]> git.ipfire.org Git - thirdparty/git.git/blobdiff - builtin/reset.c
Merge branch 'jk/bundle-use-dash-for-stdfiles'
[thirdparty/git.git] / builtin / reset.c
index 28083387cbb7dd89b05b7538b449149b0b927501..24b04aeecb9222750fe9dd7dcff1e1ab97cb467f 100644 (file)
@@ -10,6 +10,7 @@
 #define USE_THE_INDEX_VARIABLE
 #include "builtin.h"
 #include "config.h"
+#include "hex.h"
 #include "lockfile.h"
 #include "tag.h"
 #include "object.h"
@@ -26,6 +27,7 @@
 #include "submodule.h"
 #include "submodule-config.h"
 #include "dir.h"
+#include "add-interactive.h"
 
 #define REFRESH_INDEX_DELAY_WARNING_IN_MS (2 * 1000)
 
@@ -391,7 +393,9 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
                if (reset_type != NONE)
                        die(_("options '%s' and '%s' cannot be used together"), "--patch", "--{hard,mixed,soft}");
                trace2_cmd_mode("patch-interactive");
-               return run_add_interactive(rev, "--patch=reset", &pathspec);
+               update_ref_status = !!run_add_p(the_repository, ADD_P_RESET, rev,
+                                  &pathspec);
+               goto cleanup;
        }
 
        /* git reset tree [--] paths... can be used to
@@ -440,8 +444,10 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
                                       LOCK_DIE_ON_ERROR);
                if (reset_type == MIXED) {
                        int flags = quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN;
-                       if (read_from_tree(&pathspec, &oid, intent_to_add))
-                               return 1;
+                       if (read_from_tree(&pathspec, &oid, intent_to_add)) {
+                               update_ref_status = 1;
+                               goto cleanup;
+                       }
                        the_index.updated_skipworktree = 1;
                        if (!no_refresh && get_git_work_tree()) {
                                uint64_t t_begin, t_delta_in_ms;
@@ -487,6 +493,10 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
        if (!pathspec.nr)
                remove_branch_state(the_repository, 0);
 
+       discard_index(&the_index);
+
+cleanup:
+       clear_pathspec(&pathspec);
        free(pathspec_from_file);
        return update_ref_status;
 }