@matheusbsbs / matheus-bagliano / commits / dd0c34c46b
Fork 0

cache-tree: protect against "git prune".

We reused the cache-tree data without verifying the tree object still exists. Recompute in cache_tree_update() an otherwise valid cache-tree entry when the tree object disappeared. This is not usually a problem, but theoretically without this fix things can break when the user does something like this: - read-index from a side branch - write-tree the result - remove the side branch with "git branch -D" - remove the unreachable objects with "git prune" - write-tree what is in the index. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Apr 24, 2006 at 15:12 UTC dd0c34c46bdda0c20fd92d00516e711a4c9f7837
1 file changed +1 -1
cache-tree.c
+1 -1
@@ -177,7 +177,7 @@ static int update_one(struct cache_tree *it,
177 char *buffer;
178 int i;
179
180 - if (0 <= it->entry_count)
180 + if (0 <= it->entry_count && has_sha1_file(it->sha1))
181 return it->entry_count;
182
183 /*