Git Product home page Git Product logo

Comments (3)

davedelong avatar davedelong commented on June 16, 2024

Once you have the name of the reference, I think you can use -[GTRepository lookupObjectBySha:objectType:error:] (with the type GTObjectTypeTag) to turn the name into a GTTag object.

But this should be easier, I agree.

from objective-git.

indragiek avatar indragiek commented on June 16, 2024

Hi Dave,

Thanks for the suggestion. That's quite a long winded series of steps, but it does work and I created a GTRepository category method for it:

// Header

/**
 @return an array of GTTag objects with all the tags in the repository
 @param error will be set if an error is encountered during the process
 */
- (NSArray*)allTagsWithError:(NSError**)error;

// Implementation

- (NSArray*)allTagsWithError:(NSError**)error
{
    NSString *tagPrefix = @"refs/tags/";
    NSArray *referenceNames = [self listAllReferenceNamesAndReturnError:error];
    if (error && *error) { return nil; }
    NSMutableArray *filteredReferenceNames = [NSMutableArray array];
    for (NSString *refName in referenceNames) {
        if ([refName hasPrefix:tagPrefix]) {
            [filteredReferenceNames addObject:refName];
        }
    }
    NSMutableArray *tags = [NSMutableArray array];
    for (NSString *refName in filteredReferenceNames) {
        GTReference *ref = [GTReference referenceByLookingUpRef:refName inRepo:self error:error];
        if ((error && *error) || !ref) { continue; }
        GTObject *tag = [self lookupByOid:(git_oid*)ref.oid type:GTObjectTypeAny error:error];
        if ((error && *error) || !tag) { continue; }
        [tags addObject:tag];
    }
    return [NSArray arrayWithArray:tags];
}

Note that this returns an array of both lightweight and annotated tags (hence GTObjectTypeAny). Feel free to add this method to GTRepository or wherever you see fit :-).

from objective-git.

tclem avatar tclem commented on June 16, 2024

The best way to do this would be to use this functionality in libgit2.

from objective-git.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.