Merge branch 'dt/cache-tree-repair'
[gitweb.git] / builtin / commit.c
index 5911447486f5b2325dff4747872a25dd4325c1e2..41f481bd030ba96f8883e64517eda95931344545 100644 (file)
@@ -353,6 +353,13 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,
 
                discard_cache();
                read_cache_from(index_lock.filename);
+               if (update_main_cache_tree(WRITE_TREE_SILENT) == 0) {
+                       if (reopen_lock_file(&index_lock) < 0)
+                               die(_("unable to write index file"));
+                       if (write_locked_index(&the_index, &index_lock, CLOSE_LOCK))
+                               die(_("unable to update temporary index"));
+               } else
+                       warning(_("Failed to update main cache tree"));
 
                commit_style = COMMIT_NORMAL;
                return index_lock.filename;
@@ -393,8 +400,12 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,
        if (!only && !pathspec.nr) {
                hold_locked_index(&index_lock, 1);
                refresh_cache_or_die(refresh_flags);
-               if (active_cache_changed) {
+               if (active_cache_changed
+                   || !cache_tree_fully_valid(active_cache_tree)) {
                        update_main_cache_tree(WRITE_TREE_SILENT);
+                       active_cache_changed = 1;
+               }
+               if (active_cache_changed) {
                        if (write_locked_index(&the_index, &index_lock,
                                               COMMIT_LOCK))
                                die(_("unable to write new_index file"));
@@ -444,6 +455,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,
        hold_locked_index(&index_lock, 1);
        add_remove_files(&partial);
        refresh_cache(REFRESH_QUIET);
+       update_main_cache_tree(WRITE_TREE_SILENT);
        if (write_locked_index(&the_index, &index_lock, CLOSE_LOCK))
                die(_("unable to write new_index file"));