9 static const char diff_cache_usage
[] =
10 "git diff-index [-m] [--cached] "
11 "[<common-diff-options>] <tree-ish> [<path>...]"
12 COMMON_DIFF_OPTIONS_HELP
;
14 int cmd_diff_index(int argc
, const char **argv
, const char *prefix
)
21 if (argc
== 2 && !strcmp(argv
[1], "-h"))
22 usage(diff_cache_usage
);
24 git_config(git_diff_basic_config
, NULL
); /* no "diff" UI options */
25 repo_init_revisions(the_repository
, &rev
, prefix
);
27 precompose_argv(argc
, argv
);
29 argc
= setup_revisions(argc
, argv
, &rev
, NULL
);
30 for (i
= 1; i
< argc
; i
++) {
31 const char *arg
= argv
[i
];
33 if (!strcmp(arg
, "--cached"))
36 usage(diff_cache_usage
);
38 if (!rev
.diffopt
.output_format
)
39 rev
.diffopt
.output_format
= DIFF_FORMAT_RAW
;
42 * Make sure there is one revision (i.e. pending object),
43 * and there is no revision filtering parameters.
45 if (rev
.pending
.nr
!= 1 ||
46 rev
.max_count
!= -1 || rev
.min_age
!= -1 || rev
.max_age
!= -1)
47 usage(diff_cache_usage
);
50 if (read_cache_preload(&rev
.diffopt
.pathspec
) < 0) {
51 perror("read_cache_preload");
54 } else if (read_cache() < 0) {
58 result
= run_diff_index(&rev
, cached
);
60 return diff_result_code(&rev
.diffopt
, result
);