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