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