]>
Commit | Line | Data |
---|---|---|
3f46f313 | 1 | #include "clar_libgit2.h" |
2 | #include "tag.h" | |
3 | ||
4 | static git_repository *repo; | |
5 | static git_tag *tag; | |
6 | static git_object *target; | |
7 | ||
8 | void test_object_tag_peel__initialize(void) | |
9 | { | |
10 | cl_fixture_sandbox("testrepo.git"); | |
11 | cl_git_pass(git_repository_open(&repo, "testrepo.git")); | |
12 | } | |
13 | ||
14 | void test_object_tag_peel__cleanup(void) | |
15 | { | |
16 | git_tag_free(tag); | |
9094d30b SC |
17 | tag = NULL; |
18 | ||
3f46f313 | 19 | git_object_free(target); |
9094d30b SC |
20 | target = NULL; |
21 | ||
3f46f313 | 22 | git_repository_free(repo); |
9094d30b | 23 | repo = NULL; |
3f46f313 | 24 | |
25 | cl_fixture_cleanup("testrepo.git"); | |
26 | } | |
27 | ||
28 | static void retrieve_tag_from_oid(git_tag **tag_out, git_repository *repo, const char *sha) | |
29 | { | |
30 | git_oid oid; | |
ac3d33df | 31 | |
3f46f313 | 32 | cl_git_pass(git_oid_fromstr(&oid, sha)); |
33 | cl_git_pass(git_tag_lookup(tag_out, repo, &oid)); | |
34 | } | |
35 | ||
36 | void test_object_tag_peel__can_peel_to_a_commit(void) | |
37 | { | |
38 | retrieve_tag_from_oid(&tag, repo, "7b4384978d2493e851f9cca7858815fac9b10980"); | |
39 | ||
40 | cl_git_pass(git_tag_peel(&target, tag)); | |
ac3d33df | 41 | cl_assert(git_object_type(target) == GIT_OBJECT_COMMIT); |
3f46f313 | 42 | cl_git_pass(git_oid_streq(git_object_id(target), "e90810b8df3e80c413d903f631643c716887138d")); |
43 | } | |
44 | ||
45 | void test_object_tag_peel__can_peel_several_nested_tags_to_a_commit(void) | |
46 | { | |
47 | retrieve_tag_from_oid(&tag, repo, "b25fa35b38051e4ae45d4222e795f9df2e43f1d1"); | |
48 | ||
49 | cl_git_pass(git_tag_peel(&target, tag)); | |
ac3d33df | 50 | cl_assert(git_object_type(target) == GIT_OBJECT_COMMIT); |
3f46f313 | 51 | cl_git_pass(git_oid_streq(git_object_id(target), "e90810b8df3e80c413d903f631643c716887138d")); |
52 | } | |
53 | ||
54 | void test_object_tag_peel__can_peel_to_a_non_commit(void) | |
55 | { | |
56 | retrieve_tag_from_oid(&tag, repo, "521d87c1ec3aef9824daf6d96cc0ae3710766d91"); | |
57 | ||
58 | cl_git_pass(git_tag_peel(&target, tag)); | |
ac3d33df JK |
59 | cl_assert(git_object_type(target) == GIT_OBJECT_BLOB); |
60 | cl_git_pass(git_oid_streq(git_object_id(target), "1385f264afb75a56a5bec74243be9b367ba4ca08")); | |
3f46f313 | 61 | } |