From 9c4d6c0297b7d6167bf330853139b0515b351b89 Mon Sep 17 00:00:00 2001 From: David Turner Date: Sun, 13 Jul 2014 13:28:19 -0700 Subject: cache-tree: Write updated cache-tree after commit During the commit process, update the cache-tree. Write this updated cache-tree so that it's ready for subsequent commands. Add test code which demonstrates that git commit now writes the cache tree. Make all tests test the entire cache-tree, not just the root level. Signed-off-by: David Turner Signed-off-by: Junio C Hamano --- builtin/commit.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'builtin') diff --git a/builtin/commit.c b/builtin/commit.c index 12afc42d19..77570c48ba 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -342,6 +342,17 @@ 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) { + fd = open(index_lock.filename, O_WRONLY); + if (fd >= 0) + if (write_cache(fd, active_cache, active_nr) < 0) + die(_("unable to write index file")); + else + close_lock_file(&index_lock); + else + die(_("unable to write index file")); + } else + warning(_("Failed to update main cache tree")); commit_style = COMMIT_NORMAL; return index_lock.filename; @@ -383,8 +394,12 @@ static char *prepare_index(int argc, const char **argv, const char *prefix, if (!only && !pathspec.nr) { fd = 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_cache(fd, active_cache, active_nr) || commit_locked_index(&index_lock)) die(_("unable to write new_index file")); @@ -435,6 +450,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix, fd = hold_locked_index(&index_lock, 1); add_remove_files(&partial); refresh_cache(REFRESH_QUIET); + update_main_cache_tree(WRITE_TREE_SILENT); if (write_cache(fd, active_cache, active_nr) || close_lock_file(&index_lock)) die(_("unable to write new_index file")); -- cgit v1.2.3