class Rugged::TagCollection
Public Class Methods
static VALUE rb_git_tag_collection_initialize(VALUE self, VALUE repo) { rugged_set_owner(self, repo); return self; }
Public Instance Methods
Lookup a tag in repo
, with the given name
.
name
can be a short or canonical tag name (e.g. v0.1.0
or refs/tags/v0.1.0
).
Returns the looked up tag, or nil
if the tag doesn’t exist.
static VALUE rb_git_tag_collection_aref(VALUE self, VALUE rb_name) { git_reference *tag; git_repository *repo; int error; VALUE rb_repo = rugged_owner(self); rugged_check_repo(rb_repo); Data_Get_Struct(rb_repo, git_repository, repo); Check_Type(rb_name, T_STRING); error = git_reference_lookup(&tag, repo, StringValueCStr(rb_name)); if (error == GIT_ENOTFOUND || error == GIT_EINVALIDSPEC) { char *canonical_ref = xmalloc((RSTRING_LEN(rb_name) + strlen("refs/tags/") + 1) * sizeof(char)); strcpy(canonical_ref, "refs/tags/"); strcat(canonical_ref, StringValueCStr(rb_name)); error = git_reference_lookup(&tag, repo, canonical_ref); xfree(canonical_ref); if (error == GIT_ENOTFOUND) return Qnil; } rugged_exception_check(error); return rugged_ref_new(rb_cRuggedTag, rb_repo, tag); }
Create a new tag with the specified name
on target
in repo
.
If annotation
is not nil
, it will cause the creation of an annotated tag object. annotation
has to contain the following key value pairs:
- :tagger
-
An optional Hash containing a git signature. Defaults to the signature from the configuration if only ‘:message` is given. Will cause the creation of an annotated tag object if present.
- :message
-
An optional string containing the message for the new tag.
Returns the OID of the newly created tag.
static VALUE rb_git_tag_collection_create(int argc, VALUE *argv, VALUE self) { git_oid tag_oid; git_repository *repo = NULL; git_object *target = NULL; int error, force = 0; VALUE rb_repo = rugged_owner(self), rb_name, rb_target, rb_force, rb_annotation; rb_scan_args(argc, argv, "21:", &rb_name, &rb_target, &rb_force, &rb_annotation); rugged_check_repo(rb_repo); Data_Get_Struct(rb_repo, git_repository, repo); Check_Type(rb_name, T_STRING); if (!NIL_P(rb_force)) force = rugged_parse_bool(rb_force); target = rugged_object_get(repo, rb_target, GIT_OBJ_ANY); if (NIL_P(rb_annotation)) { error = git_tag_create_lightweight( &tag_oid, repo, StringValueCStr(rb_name), target, force ); } else { git_signature *tagger = rugged_signature_get( rb_hash_aref(rb_annotation, CSTR2SYM("tagger")), repo ); VALUE rb_message = rb_hash_aref(rb_annotation, CSTR2SYM("message")); Check_Type(rb_message, T_STRING); error = git_tag_create( &tag_oid, repo, StringValueCStr(rb_name), target, tagger, StringValueCStr(rb_message), force ); git_signature_free(tagger); } git_object_free(target); rugged_exception_check(error); return rb_git_tag_collection_aref(self, rb_name); }
Create a new annotated tag object with the specified name
on target
in repo
.
Unlike the create
method, create_annotation
simply creates a tag object. It does not write a tag ref.
annotation
must have the following keys:
- :tagger
-
An optional Hash containing a git signature. Defaults to the signature from the configuration if only ‘:message` is given. Will cause the creation of an annotated tag object if present.
- :message
-
An optional string containing the message for the new tag.
Returns an instance of Rugged::Tag::Annotation
representing the newly created annotation.
static VALUE rb_git_tag_collection_create_annotation(VALUE self, VALUE rb_name, VALUE rb_target, VALUE rb_annotation) { git_oid tag_oid; git_repository *repo = NULL; git_object *target = NULL, *tag = NULL; git_signature *tagger = NULL; VALUE rb_message; int error; VALUE rb_repo = rugged_owner(self); rugged_check_repo(rb_repo); Data_Get_Struct(rb_repo, git_repository, repo); Check_Type(rb_name, T_STRING); target = rugged_object_get(repo, rb_target, GIT_OBJ_ANY); rb_message = rb_hash_aref(rb_annotation, CSTR2SYM("message")); Check_Type(rb_message, T_STRING); tagger = rugged_signature_get( rb_hash_aref(rb_annotation, CSTR2SYM("tagger")), repo ); error = git_tag_annotation_create( &tag_oid, repo, StringValueCStr(rb_name), target, tagger, StringValueCStr(rb_message) ); git_object_free(target); git_signature_free(tagger); rugged_exception_check(error); error = git_object_lookup(&tag, repo, &tag_oid, GIT_OBJ_TAG); rugged_exception_check(error); return rugged_object_new(rb_repo, tag); }
Delete the tag reference identified by name
.
static VALUE rb_git_tag_collection_delete(VALUE self, VALUE rb_name) { VALUE rb_repo = rugged_owner(self); git_repository *repo; int error; rugged_check_repo(rb_repo); Data_Get_Struct(rb_repo, git_repository, repo); Check_Type(rb_name, T_STRING); error = git_tag_delete(repo, StringValueCStr(rb_name)); rugged_exception_check(error); return Qnil; }
Iterate through all the tags in repo
. Iteration can be optionally filtered to the ones matching the given pattern
, a standard Unix filename glob.
If pattern
is empty or not given, all tag names will be returned.
The given block will be called once with the name for each tag.
If no block is given, an enumerator will be returned.
static VALUE rb_git_tag_collection_each(int argc, VALUE *argv, VALUE self) { return each_tag(argc, argv, self, 0); }
Iterate through all the tag names in repo
. Iteration can be optionally filtered to the ones matching the given pattern
, a standard Unix filename glob.
If pattern
is empty or not given, all tag names will be returned.
The given block will be called once with the name for each tag.
If no block is given, an enumerator will be returned.
static VALUE rb_git_tag_collection_each_name(int argc, VALUE *argv, VALUE self) { return each_tag(argc, argv, self, 1); }