Code

reset: disallow using --keep when there are unmerged entries
[git.git] / builtin-update-index.c
index 97b9ea61f7605970875776bd5c84c00abbb0f2f6..3ab214d24e537865875d6d1e3acd8cf6b019ff22 100644 (file)
@@ -9,6 +9,7 @@
 #include "tree-walk.h"
 #include "builtin.h"
 #include "refs.h"
+#include "resolve-undo.h"
 
 /*
  * Default to not allowing changes to the list of files. The
@@ -28,6 +29,7 @@ static int mark_skip_worktree_only;
 #define MARK_FLAG 1
 #define UNMARK_FLAG 2
 
+__attribute__((format (printf, 1, 2)))
 static void report(const char *fmt, ...)
 {
        va_list vp;
@@ -439,7 +441,18 @@ static int unresolve_one(const char *path)
 
        /* See if there is such entry in the index. */
        pos = cache_name_pos(path, namelen);
-       if (pos < 0) {
+       if (0 <= pos) {
+               /* already merged */
+               pos = unmerge_cache_entry_at(pos);
+               if (pos < active_nr) {
+                       struct cache_entry *ce = active_cache[pos];
+                       if (ce_stage(ce) &&
+                           ce_namelen(ce) == namelen &&
+                           !memcmp(ce->name, path, namelen))
+                               return 0;
+               }
+               /* no resolve-undo information; fall back */
+       } else {
                /* If there isn't, either it is unmerged, or
                 * resolved as "removed" by mistake.  We do not
                 * want to do anything in the former case.
@@ -718,6 +731,10 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
                                verbose = 1;
                                continue;
                        }
+                       if (!strcmp(path, "--clear-resolve-undo")) {
+                               resolve_undo_clear();
+                               continue;
+                       }
                        if (!strcmp(path, "-h") || !strcmp(path, "--help"))
                                usage(update_index_usage);
                        die("unknown option %s", path);