]>
git.proxmox.com Git - libgit2.git/blob - tests-clar/object/tag/write.c
1 #include "clar_libgit2.h"
3 static const char* tagger_name
= "Vicent Marti";
4 static const char* tagger_email
= "vicent@github.com";
5 static const char* tagger_message
= "This is my tag.\n\nThere are many tags, but this one is mine\n";
7 static const char *tag2_id
= "7b4384978d2493e851f9cca7858815fac9b10980";
8 static const char *tagged_commit
= "e90810b8df3e80c413d903f631643c716887138d";
10 static git_repository
*g_repo
;
12 // Fixture setup and teardown
13 void test_object_tag_write__initialize(void)
15 g_repo
= cl_git_sandbox_init("testrepo");
18 void test_object_tag_write__cleanup(void)
20 cl_git_sandbox_cleanup();
23 void test_object_tag_write__basic(void)
25 // write a tag to the repository and read it again
27 git_oid target_id
, tag_id
;
28 git_signature
*tagger
;
29 const git_signature
*tagger1
;
30 git_reference
*ref_tag
;
33 git_oid_fromstr(&target_id
, tagged_commit
);
34 cl_git_pass(git_object_lookup(&target
, g_repo
, &target_id
, GIT_OBJ_COMMIT
));
36 /* create signature */
37 cl_git_pass(git_signature_new(&tagger
, tagger_name
, tagger_email
, 123456789, 60));
40 git_tag_create(&tag_id
, g_repo
,
41 "the-tag", target
, tagger
, tagger_message
, 0)
44 git_object_free(target
);
45 git_signature_free(tagger
);
47 cl_git_pass(git_tag_lookup(&tag
, g_repo
, &tag_id
));
48 cl_assert(git_oid_cmp(git_tag_target_oid(tag
), &target_id
) == 0);
50 /* Check attributes were set correctly */
51 tagger1
= git_tag_tagger(tag
);
52 cl_assert(tagger1
!= NULL
);
53 cl_assert_equal_s(tagger1
->name
, tagger_name
);
54 cl_assert_equal_s(tagger1
->email
, tagger_email
);
55 cl_assert(tagger1
->when
.time
== 123456789);
56 cl_assert(tagger1
->when
.offset
== 60);
58 cl_assert_equal_s(git_tag_message(tag
), tagger_message
);
60 cl_git_pass(git_reference_lookup(&ref_tag
, g_repo
, "refs/tags/the-tag"));
61 cl_assert(git_oid_cmp(git_reference_oid(ref_tag
), &tag_id
) == 0);
62 cl_git_pass(git_reference_delete(ref_tag
));
67 void test_object_tag_write__overwrite(void)
69 // Attempt to write a tag bearing the same name than an already existing tag
70 git_oid target_id
, tag_id
;
71 git_signature
*tagger
;
74 git_oid_fromstr(&target_id
, tagged_commit
);
75 cl_git_pass(git_object_lookup(&target
, g_repo
, &target_id
, GIT_OBJ_COMMIT
));
77 /* create signature */
78 cl_git_pass(git_signature_new(&tagger
, tagger_name
, tagger_email
, 123456789, 60));
80 cl_git_fail(git_tag_create(
89 git_object_free(target
);
90 git_signature_free(tagger
);
94 void test_object_tag_write__replace(void)
96 // Replace an already existing tag
97 git_oid target_id
, tag_id
, old_tag_id
;
98 git_signature
*tagger
;
99 git_reference
*ref_tag
;
102 git_oid_fromstr(&target_id
, tagged_commit
);
103 cl_git_pass(git_object_lookup(&target
, g_repo
, &target_id
, GIT_OBJ_COMMIT
));
105 cl_git_pass(git_reference_lookup(&ref_tag
, g_repo
, "refs/tags/e90810b"));
106 git_oid_cpy(&old_tag_id
, git_reference_oid(ref_tag
));
107 git_reference_free(ref_tag
);
109 /* create signature */
110 cl_git_pass(git_signature_new(&tagger
, tagger_name
, tagger_email
, 123456789, 60));
112 cl_git_pass(git_tag_create(
113 &tag_id
, /* out id */
121 git_object_free(target
);
122 git_signature_free(tagger
);
124 cl_git_pass(git_reference_lookup(&ref_tag
, g_repo
, "refs/tags/e90810b"));
125 cl_assert(git_oid_cmp(git_reference_oid(ref_tag
), &tag_id
) == 0);
126 cl_assert(git_oid_cmp(git_reference_oid(ref_tag
), &old_tag_id
) != 0);
128 git_reference_free(ref_tag
);
131 void test_object_tag_write__lightweight(void)
133 // write a lightweight tag to the repository and read it again
134 git_oid target_id
, object_id
;
135 git_reference
*ref_tag
;
138 git_oid_fromstr(&target_id
, tagged_commit
);
139 cl_git_pass(git_object_lookup(&target
, g_repo
, &target_id
, GIT_OBJ_COMMIT
));
141 cl_git_pass(git_tag_create_lightweight(
148 git_object_free(target
);
150 cl_assert(git_oid_cmp(&object_id
, &target_id
) == 0);
152 cl_git_pass(git_reference_lookup(&ref_tag
, g_repo
, "refs/tags/light-tag"));
153 cl_assert(git_oid_cmp(git_reference_oid(ref_tag
), &target_id
) == 0);
155 cl_git_pass(git_tag_delete(g_repo
, "light-tag"));
157 git_reference_free(ref_tag
);
160 void test_object_tag_write__lightweight_over_existing(void)
162 // Attempt to write a lightweight tag bearing the same name than an already existing tag
163 git_oid target_id
, object_id
, existing_object_id
;
166 git_oid_fromstr(&target_id
, tagged_commit
);
167 cl_git_pass(git_object_lookup(&target
, g_repo
, &target_id
, GIT_OBJ_COMMIT
));
169 cl_git_fail(git_tag_create_lightweight(
176 git_oid_fromstr(&existing_object_id
, tag2_id
);
177 cl_assert(git_oid_cmp(&object_id
, &existing_object_id
) == 0);
179 git_object_free(target
);
182 void test_object_tag_write__delete(void)
184 // Delete an already existing tag
185 git_reference
*ref_tag
;
187 cl_git_pass(git_tag_delete(g_repo
, "e90810b"));
189 cl_git_fail(git_reference_lookup(&ref_tag
, g_repo
, "refs/tags/e90810b"));
191 git_reference_free(ref_tag
);