1 #define USE_THE_INDEX_COMPATIBILITY_MACROS
10 static const char diff_cache_usage
[] =
11 "git diff-index [-m] [--cached] "
12 "[<common-diff-options>] <tree-ish> [<path>...]"
13 COMMON_DIFF_OPTIONS_HELP
;
15 int cmd_diff_index(int argc
, const char **argv
, const char *prefix
)
22 if (argc
== 2 && !strcmp(argv
[1], "-h"))
23 usage(diff_cache_usage
);
25 git_config(git_diff_basic_config
, NULL
); /* no "diff" UI options */
26 repo_init_revisions(the_repository
, &rev
, prefix
);
28 precompose_argv(argc
, argv
);
30 argc
= setup_revisions(argc
, argv
, &rev
, NULL
);
31 for (i
= 1; i
< argc
; i
++) {
32 const char *arg
= argv
[i
];
34 if (!strcmp(arg
, "--cached"))
37 usage(diff_cache_usage
);
39 if (!rev
.diffopt
.output_format
)
40 rev
.diffopt
.output_format
= DIFF_FORMAT_RAW
;
43 * Make sure there is one revision (i.e. pending object),
44 * and there is no revision filtering parameters.
46 if (rev
.pending
.nr
!= 1 ||
47 rev
.max_count
!= -1 || rev
.min_age
!= -1 || rev
.max_age
!= -1)
48 usage(diff_cache_usage
);
51 if (read_cache_preload(&rev
.diffopt
.pathspec
) < 0) {
52 perror("read_cache_preload");
55 } else if (read_cache() < 0) {
59 result
= run_diff_index(&rev
, cached
);
61 return diff_result_code(&rev
.diffopt
, result
);