Merge branch 'ab/config-based-hooks-base' into seen
[git] / t / helper / test-read-cache-again.c
1 #include "test-tool.h"
2 #include "cache.h"
3 #include "parse-options.h"
4
5 static const char *read_cache_again_usage[] = {
6         "test-tool read-cache-again [<options>...] <file>",
7         NULL
8 };
9
10 int cmd__read_cache_again(int argc, const char **argv)
11 {
12         struct repository *r = the_repository;
13         int cnt = -1;
14         const char *name;
15         struct option options[] = {
16                 OPT_INTEGER(0, "count", &cnt, "number of passes"),
17                 OPT_END()
18         };
19
20         argc = parse_options(argc, argv, "test-tools", options,
21                              read_cache_again_usage, 0);
22         if (argc != 1)
23                 usage_msg_opt("Too many arguments.", read_cache_again_usage,
24                               options);
25         if (cnt == -1)
26                 cnt = 2;
27         else if (cnt < 1)
28                 usage_msg_opt("Need at least one pass.", read_cache_again_usage,
29                               options);
30         name = argv[2];
31
32         setup_git_directory();
33         while (cnt--) {
34                 int pos;
35                 repo_read_index(r);
36                 refresh_index(r->index, REFRESH_QUIET,
37                               NULL, NULL, NULL);
38                 pos = index_name_pos(r->index, name, strlen(name));
39                 if (pos < 0)
40                         die("%s not in index", name);
41                 printf("%s is%s up to date\n", name,
42                        ce_uptodate(r->index->cache[pos]) ? "" : " not");
43                 write_file(name, "%d\n", cnt);
44                 discard_index(r->index);
45         }
46         return 0;
47 }