Merge branch 'ab/config-based-hooks-base' into seen
[git] / t / helper / test-partial-clone.c
1 #include "cache.h"
2 #include "test-tool.h"
3 #include "repository.h"
4 #include "object-store.h"
5
6 /*
7  * Prints the size of the object corresponding to the given hash in a specific
8  * gitdir. This is similar to "git -C gitdir cat-file -s", except that this
9  * exercises the code that accesses the object of an arbitrary repository that
10  * is not the_repository. ("git -C gitdir" makes it so that the_repository is
11  * the one in gitdir.)
12  */
13 static void object_info(const char *gitdir, const char *oid_hex)
14 {
15         struct repository r;
16         struct object_id oid;
17         unsigned long size;
18         struct object_info oi = {.sizep = &size};
19         const char *p;
20
21         if (repo_init(&r, gitdir, NULL))
22                 die("could not init repo");
23         if (parse_oid_hex(oid_hex, &oid, &p))
24                 die("could not parse oid");
25         if (oid_object_info_extended(&r, &oid, &oi, 0))
26                 die("could not obtain object info");
27         printf("%d\n", (int) size);
28 }
29
30 int cmd__partial_clone(int argc, const char **argv)
31 {
32         setup_git_directory();
33
34         if (argc < 4)
35                 die("too few arguments");
36
37         if (!strcmp(argv[1], "object-info"))
38                 object_info(argv[2], argv[3]);
39         else
40                 die("invalid argument '%s'", argv[1]);
41
42         return 0;
43 }