Code

Merge git://repo.or.cz/git-gui
[git.git] / builtin-reset.c
index 44582f23a21c97507351773e2c0a342a1eaa8c64..7ee811f0b8de34025a14a53d42f4fceb477a598e 100644 (file)
@@ -18,7 +18,7 @@
 #include "tree.h"
 
 static const char builtin_reset_usage[] =
-"git-reset [--mixed | --soft | --hard]  [<commit-ish>] [ [--] <paths>...]";
+"git-reset [--mixed | --soft | --hard] [-q] [<commit-ish>] [ [--] <paths>...]";
 
 static char *args_to_str(const char **argv)
 {
@@ -108,7 +108,6 @@ static int update_index_refresh(int fd, struct lock_file *index_lock)
                return error("Could not read index");
        result = refresh_cache(0) ? 1 : 0;
        if (write_cache(fd, active_cache, active_nr) ||
-                       close(fd) ||
                        commit_locked_index(index_lock))
                return error ("Could not refresh index");
        return result;
@@ -158,6 +157,7 @@ static int read_from_tree(const char *prefix, const char **argv,
                return 1;
        diffcore_std(&opt);
        diff_flush(&opt);
+       diff_tree_release_paths(&opt);
 
        if (!index_was_discarded)
                /* The index is still clobbered from do_diff_cache() */
@@ -180,7 +180,7 @@ static const char *reset_type_names[] = { "mixed", "soft", "hard", NULL };
 
 int cmd_reset(int argc, const char **argv, const char *prefix)
 {
-       int i = 1, reset_type = NONE, update_ref_status = 0;
+       int i = 1, reset_type = NONE, update_ref_status = 0, quiet = 0;
        const char *rev = "HEAD";
        unsigned char sha1[20], *orig = NULL, sha1_orig[20],
                                *old_orig = NULL, sha1_old_orig[20];
@@ -192,7 +192,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
        reflog_action = args_to_str(argv);
        setenv("GIT_REFLOG_ACTION", reflog_action, 0);
 
-       if (i < argc) {
+       while (i < argc) {
                if (!strcmp(argv[i], "--mixed")) {
                        reset_type = MIXED;
                        i++;
@@ -205,6 +205,12 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
                        reset_type = HARD;
                        i++;
                }
+               else if (!strcmp(argv[i], "-q")) {
+                       quiet = 1;
+                       i++;
+               }
+               else
+                       break;
        }
 
        if (i < argc && argv[i][0] != '-')
@@ -237,6 +243,9 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
        if (reset_type == NONE)
                reset_type = MIXED; /* by default */
 
+       if (reset_type == HARD && is_bare_repository())
+               die("hard reset makes no sense in a bare repository");
+
        /* Soft reset does not touch the index file nor the working tree
         * at all, but requires them in a good order.  Other resets reset
         * the index file to the tree object we are switching to. */
@@ -263,7 +272,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
 
        switch (reset_type) {
        case HARD:
-               if (!update_ref_status)
+               if (!update_ref_status && !quiet)
                        print_new_head_line(commit);
                break;
        case SOFT: /* Nothing else to do. */