t/helper: stop using `the_index`
[git.git] / t / helper / test-dump-untracked-cache.c
blob9ff67c39676f9d2b0d66c9f23f433328a32f160c
1 #include "test-tool.h"
2 #include "dir.h"
3 #include "hex.h"
4 #include "read-cache-ll.h"
5 #include "repository.h"
6 #include "setup.h"
8 static int compare_untracked(const void *a_, const void *b_)
10 const char *const *a = a_;
11 const char *const *b = b_;
12 return strcmp(*a, *b);
15 static int compare_dir(const void *a_, const void *b_)
17 const struct untracked_cache_dir *const *a = a_;
18 const struct untracked_cache_dir *const *b = b_;
19 return strcmp((*a)->name, (*b)->name);
22 static void dump(struct untracked_cache_dir *ucd, struct strbuf *base)
24 int i, len;
25 QSORT(ucd->untracked, ucd->untracked_nr, compare_untracked);
26 QSORT(ucd->dirs, ucd->dirs_nr, compare_dir);
27 len = base->len;
28 strbuf_addf(base, "%s/", ucd->name);
29 printf("%s %s", base->buf,
30 oid_to_hex(&ucd->exclude_oid));
31 if (ucd->recurse)
32 fputs(" recurse", stdout);
33 if (ucd->check_only)
34 fputs(" check_only", stdout);
35 if (ucd->valid)
36 fputs(" valid", stdout);
37 printf("\n");
38 for (i = 0; i < ucd->untracked_nr; i++)
39 printf("%s\n", ucd->untracked[i]);
40 for (i = 0; i < ucd->dirs_nr; i++)
41 dump(ucd->dirs[i], base);
42 strbuf_setlen(base, len);
45 int cmd__dump_untracked_cache(int ac UNUSED, const char **av UNUSED)
47 struct untracked_cache *uc;
48 struct strbuf base = STRBUF_INIT;
50 /* Set core.untrackedCache=keep before setup_git_directory() */
51 xsetenv("GIT_CONFIG_COUNT", "1", 1);
52 xsetenv("GIT_CONFIG_KEY_0", "core.untrackedCache", 1);
53 xsetenv("GIT_CONFIG_VALUE_0", "keep", 1);
55 setup_git_directory();
56 if (repo_read_index(the_repository) < 0)
57 die("unable to read index file");
58 uc = the_repository->index->untracked;
59 if (!uc) {
60 printf("no untracked cache\n");
61 return 0;
63 printf("info/exclude %s\n", oid_to_hex(&uc->ss_info_exclude.oid));
64 printf("core.excludesfile %s\n", oid_to_hex(&uc->ss_excludes_file.oid));
65 printf("exclude_per_dir %s\n", uc->exclude_per_dir);
66 printf("flags %08x\n", uc->dir_flags);
67 if (uc->root)
68 dump(uc->root, &base);
69 return 0;