Commit 9e680bcc by nulltoken

Add git_tag_delete()

parent a50c1458
...@@ -247,6 +247,20 @@ GIT_EXTERN(int) git_tag_create_o_f( ...@@ -247,6 +247,20 @@ GIT_EXTERN(int) git_tag_create_o_f(
const git_signature *tagger, const git_signature *tagger,
const char *message); const char *message);
/**
* Delete an existing tag reference.
*
* @param repo Repository where lives the tag
*
* @param tag_name Name of the tag to be deleted;
* this name is validated for consistency.
*
* @return 0 on success; error code otherwise.
*/
GIT_EXTERN(int) git_tag_delete(
git_repository *repo,
const char *tag_name);
/** @} */ /** @} */
GIT_END_DECL GIT_END_DECL
#endif #endif
...@@ -153,6 +153,21 @@ static int parse_tag_buffer(git_tag *tag, char *buffer, const char *buffer_end) ...@@ -153,6 +153,21 @@ static int parse_tag_buffer(git_tag *tag, char *buffer, const char *buffer_end)
return GIT_SUCCESS; return GIT_SUCCESS;
} }
static int retreive_tag_reference(git_reference **tag_reference_out, char *ref_name_out, git_repository *repo, const char *tag_name)
{
git_reference *tag_ref;
int error;
git__joinpath(ref_name_out, GIT_REFS_TAGS_DIR, tag_name);
error = git_reference_lookup(&tag_ref, repo, ref_name_out);
if (error < GIT_SUCCESS)
return error;
*tag_reference_out = tag_ref;;
return GIT_SUCCESS;
}
static int tag_create( static int tag_create(
git_oid *oid, git_oid *oid,
git_repository *repo, git_repository *repo,
...@@ -177,8 +192,7 @@ static int tag_create( ...@@ -177,8 +192,7 @@ static int tag_create(
/** Ensure the tag name doesn't conflict with an already existing /** Ensure the tag name doesn't conflict with an already existing
reference unless overwriting has explictly been requested **/ reference unless overwriting has explictly been requested **/
git__joinpath(ref_name, GIT_REFS_TAGS_DIR, tag_name); error = retreive_tag_reference(&new_ref, ref_name, repo, tag_name);
error = git_reference_lookup(&new_ref, repo, ref_name);
switch (error) { switch (error) {
case GIT_SUCCESS: case GIT_SUCCESS:
...@@ -305,6 +319,19 @@ int git_tag_create_f( ...@@ -305,6 +319,19 @@ int git_tag_create_f(
tagger, message, 1); tagger, message, 1);
} }
int git_tag_delete(git_repository *repo, const char *tag_name)
{
int error;
git_reference *tag_ref;
char ref_name[MAX_GITDIR_TREE_STRUCTURE_PATH_LENGTH];
error = retreive_tag_reference(&tag_ref, ref_name, repo, tag_name);
if (error < GIT_SUCCESS)
return error;
return git_reference_delete(tag_ref);
}
int git_tag__parse(git_tag *tag, git_odb_object *obj) int git_tag__parse(git_tag *tag, git_odb_object *obj)
{ {
assert(tag); assert(tag);
......
...@@ -225,6 +225,20 @@ BEGIN_TEST(write3, "Replace an already existing tag") ...@@ -225,6 +225,20 @@ BEGIN_TEST(write3, "Replace an already existing tag")
END_TEST END_TEST
BEGIN_TEST(write4, "Delete an already existing tag")
git_repository *repo;
git_reference *ref_tag;
must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER));
must_pass(git_tag_delete(repo,"very-simple"));
must_fail(git_reference_lookup(&ref_tag, repo, "refs/tags/very-simple"));
close_temp_repo(repo);
END_TEST
BEGIN_SUITE(tag) BEGIN_SUITE(tag)
ADD_TEST(read0); ADD_TEST(read0);
ADD_TEST(write0); ADD_TEST(write0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment