Skip to content

Commit

Permalink
cache-tree: protect against "git prune".
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Junio C Hamano committed Apr 24, 2006
1 parent 1744820 commit dd0c34c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion cache-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ static int update_one(struct cache_tree *it,
char *buffer;
int i;

if (0 <= it->entry_count)
if (0 <= it->entry_count && has_sha1_file(it->sha1))
return it->entry_count;

/*
Expand Down

0 comments on commit dd0c34c

Please sign in to comment.