]>
git.proxmox.com Git - libgit2.git/blob - tests/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_OBJECT_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_id(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_target(ref_tag
), &tag_id
) == 0);
62 cl_git_pass(git_reference_delete(ref_tag
));
63 git_reference_free(ref_tag
);
68 void test_object_tag_write__overwrite(void)
70 /* Attempt to write a tag bearing the same name than an already existing tag */
71 git_oid target_id
, tag_id
;
72 git_signature
*tagger
;
75 git_oid_fromstr(&target_id
, tagged_commit
);
76 cl_git_pass(git_object_lookup(&target
, g_repo
, &target_id
, GIT_OBJECT_COMMIT
));
78 /* create signature */
79 cl_git_pass(git_signature_new(&tagger
, tagger_name
, tagger_email
, 123456789, 60));
81 cl_assert_equal_i(GIT_EEXISTS
, git_tag_create(
90 git_object_free(target
);
91 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_OBJECT_COMMIT
));
105 cl_git_pass(git_reference_lookup(&ref_tag
, g_repo
, "refs/tags/e90810b"));
106 git_oid_cpy(&old_tag_id
, git_reference_target(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_target(ref_tag
), &tag_id
) == 0);
126 cl_assert(git_oid_cmp(git_reference_target(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_OBJECT_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_target(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_OBJECT_COMMIT
));
169 cl_assert_equal_i(GIT_EEXISTS
, 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
);
194 void test_object_tag_write__creating_with_an_invalid_name_returns_EINVALIDSPEC(void)
196 git_oid target_id
, tag_id
;
197 git_signature
*tagger
;
200 git_oid_fromstr(&target_id
, tagged_commit
);
201 cl_git_pass(git_object_lookup(&target
, g_repo
, &target_id
, GIT_OBJECT_COMMIT
));
203 cl_git_pass(git_signature_new(&tagger
, tagger_name
, tagger_email
, 123456789, 60));
205 cl_assert_equal_i(GIT_EINVALIDSPEC
,
206 git_tag_create(&tag_id
, g_repo
,
207 "Inv@{id", target
, tagger
, tagger_message
, 0)
210 cl_assert_equal_i(GIT_EINVALIDSPEC
,
211 git_tag_create_lightweight(&tag_id
, g_repo
,
212 "Inv@{id", target
, 0)
215 git_object_free(target
);
216 git_signature_free(tagger
);
219 void test_object_tag_write__deleting_with_an_invalid_name_returns_EINVALIDSPEC(void)
221 cl_assert_equal_i(GIT_EINVALIDSPEC
, git_tag_delete(g_repo
, "Inv@{id"));
224 static void create_annotation(git_oid
*tag_id
, const char *name
)
228 git_signature
*tagger
;
230 cl_git_pass(git_signature_new(&tagger
, tagger_name
, tagger_email
, 123456789, 60));
232 git_oid_fromstr(&target_id
, tagged_commit
);
233 cl_git_pass(git_object_lookup(&target
, g_repo
, &target_id
, GIT_OBJECT_COMMIT
));
235 cl_git_pass(git_tag_annotation_create(tag_id
, g_repo
, name
, target
, tagger
, "boom!"));
236 git_object_free(target
);
237 git_signature_free(tagger
);
240 void test_object_tag_write__creating_an_annotation_stores_the_new_object_in_the_odb(void)
245 create_annotation(&tag_id
, "new_tag");
247 cl_git_pass(git_tag_lookup(&tag
, g_repo
, &tag_id
));
248 cl_assert_equal_s("new_tag", git_tag_name(tag
));
253 void test_object_tag_write__creating_an_annotation_does_not_create_a_reference(void)
256 git_reference
*tag_ref
;
258 create_annotation(&tag_id
, "new_tag");
259 cl_git_fail_with(git_reference_lookup(&tag_ref
, g_repo
, "refs/tags/new_tag"), GIT_ENOTFOUND
);