]>
Commit | Line | Data |
---|---|---|
b1aca6ea | 1 | #include "clar_libgit2.h" |
2 | ||
3 | static git_repository *_repo; | |
4 | static git_commit *commit; | |
5 | ||
6 | void test_commit_parent__initialize(void) | |
7 | { | |
8 | git_oid oid; | |
9 | ||
10 | cl_git_pass(git_repository_open(&_repo, cl_fixture("testrepo.git"))); | |
11 | ||
12 | git_oid_fromstr(&oid, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); | |
13 | cl_git_pass(git_commit_lookup(&commit, _repo, &oid)); | |
14 | } | |
15 | ||
16 | void test_commit_parent__cleanup(void) | |
17 | { | |
18 | git_commit_free(commit); | |
9094d30b SC |
19 | commit = NULL; |
20 | ||
b1aca6ea | 21 | git_repository_free(_repo); |
9094d30b | 22 | _repo = NULL; |
b1aca6ea | 23 | } |
24 | ||
25 | static void assert_nth_gen_parent(unsigned int gen, const char *expected_oid) | |
26 | { | |
27 | git_commit *parent = NULL; | |
28 | int error; | |
29 | ||
30 | error = git_commit_nth_gen_ancestor(&parent, commit, gen); | |
31 | ||
32 | if (expected_oid != NULL) { | |
33 | cl_assert_equal_i(0, error); | |
34 | cl_assert_equal_i(0, git_oid_streq(git_commit_id(parent), expected_oid)); | |
35 | } else | |
36 | cl_assert_equal_i(GIT_ENOTFOUND, error); | |
37 | ||
38 | git_commit_free(parent); | |
39 | } | |
40 | ||
41 | /* | |
42 | * $ git show be35~0 | |
43 | * commit be3563ae3f795b2b4353bcce3a527ad0a4f7f644 | |
44 | * | |
45 | * $ git show be35~1 | |
46 | * commit 9fd738e8f7967c078dceed8190330fc8648ee56a | |
47 | * | |
48 | * $ git show be35~3 | |
49 | * commit 5b5b025afb0b4c913b4c338a42934a3863bf3644 | |
50 | * | |
51 | * $ git show be35~42 | |
52 | * fatal: ambiguous argument 'be35~42': unknown revision or path not in the working tree. | |
53 | */ | |
54 | void test_commit_parent__can_retrieve_nth_generation_parent(void) | |
55 | { | |
56 | assert_nth_gen_parent(0, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); | |
57 | assert_nth_gen_parent(1, "9fd738e8f7967c078dceed8190330fc8648ee56a"); | |
58 | assert_nth_gen_parent(3, "5b5b025afb0b4c913b4c338a42934a3863bf3644"); | |
59 | assert_nth_gen_parent(42, NULL); | |
60 | } |