diff*: fix worktree setup
This fixes "git diff", "git diff-files" and "git diff-index" to work correctly under worktree setup. Because diff* family works in many modes and not all of them require worktree, Junio made a nice summary (with a little modification from me): * diff-files is about comparing with work tree, so it obviously needs a work tree; * diff-index also does, except "diff-index --cached" or "diff --cached TREE" * no-index is about random files outside git context, so it obviously doesn't need any work tree; * comparing two (or more) trees doesn't; * comparing two blobs doesn't; * comparing a blob with a random file doesn't; Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
c67b1fa349
commit
4f38f6b5ba
@ -122,6 +122,8 @@ static int builtin_diff_index(struct rev_info *revs,
|
||||
usage(builtin_diff_usage);
|
||||
argv++; argc--;
|
||||
}
|
||||
if (!cached)
|
||||
setup_work_tree();
|
||||
/*
|
||||
* Make sure there is one revision (i.e. pending object),
|
||||
* and there is no revision filtering parameters.
|
||||
@ -225,6 +227,7 @@ static int builtin_diff_files(struct rev_info *revs, int argc, const char **argv
|
||||
(revs->diffopt.output_format & DIFF_FORMAT_PATCH))
|
||||
revs->combine_merges = revs->dense_combined_merges = 1;
|
||||
|
||||
setup_work_tree();
|
||||
if (read_cache() < 0) {
|
||||
perror("read_cache");
|
||||
return -1;
|
||||
|
Reference in New Issue
Block a user