Skip to content

Commit 26973e2

Browse files
committed
Merge pull request #253 from PiersonBro/Give-GTTag-Some-Love
Give GTTag Some Love
2 parents 6cf41df + f39842e commit 26973e2

File tree

6 files changed

+64
-79
lines changed

6 files changed

+64
-79
lines changed

Classes/GTTag.h

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,27 @@
2727
// THE SOFTWARE.
2828
//
2929

30-
3130
#import "GTObject.h"
3231

3332
@class GTSignature;
3433
@class GTRepository;
3534

36-
3735
@interface GTTag : GTObject {}
3836

37+
// The author of the tag.
3938
@property (nonatomic, readonly, strong) GTSignature *tagger;
4039

41-
// The underlying `git_object` as a `git_tag` object.
42-
- (git_tag *)git_tag __attribute__((objc_returns_inner_pointer));
40+
// The description given when the tag was created.
41+
@property (nonatomic, readonly, strong) NSString *message;
42+
43+
// The label of the tag. Generally a version number.
44+
@property (nonatomic, readonly, strong) NSString *name;
4345

44-
- (NSString *)message;
45-
- (NSString *)name;
46-
- (GTObject *)target;
47-
- (NSString *)targetType;
46+
// The 'tagged' object.
47+
@property (nonatomic, readonly, strong) GTObject *target;
48+
49+
// The type of the 'tagged' object.
50+
@property (nonatomic, readonly) GTObjectType targetType;
4851

4952
// Recursively peel a tag until a non tag GTObject is found
5053
//
@@ -54,4 +57,7 @@
5457
// Returns the found object or nil on error.
5558
- (id)objectByPeelingTagError:(NSError **)error;
5659

60+
// The underlying `git_object` as a `git_tag` object.
61+
- (git_tag *)git_tag __attribute__((objc_returns_inner_pointer));
62+
5763
@end

Classes/GTTag.m

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,30 +38,28 @@
3838
@implementation GTTag
3939

4040
- (NSString *)description {
41-
return [NSString stringWithFormat:@"<%@: %p> name: %@, message: %@, targetType: %@", NSStringFromClass([self class]), self, [self name], [self message], [self targetType]];
41+
return [NSString stringWithFormat:@"<%@: %p> name: %@, message: %@, targetType: %d", NSStringFromClass([self class]), self,self.name, self.message, self.targetType];
4242
}
4343

44-
4544
#pragma mark API
4645

4746
- (NSString *)message {
48-
return [NSString stringWithUTF8String:git_tag_message(self.git_tag)];
47+
return @(git_tag_message(self.git_tag));
4948
}
5049

5150
- (NSString *)name {
52-
return [NSString stringWithUTF8String:git_tag_name(self.git_tag)];
51+
return @(git_tag_name(self.git_tag));
5352
}
5453

5554
- (GTObject *)target {
5655
git_object *t;
57-
// todo: might want to actually return an error here
5856
int gitError = git_tag_target(&t, self.git_tag);
59-
if(gitError < GIT_OK) return nil;
60-
return [GTObject objectWithObj:(git_object *)t inRepository:self.repository];
57+
if (gitError < GIT_OK) return nil;
58+
return [GTObject objectWithObj:(git_object *)t inRepository:self.repository];
6159
}
6260

63-
- (NSString *)targetType {
64-
return [NSString stringWithUTF8String:git_object_type2string(git_tag_target_type(self.git_tag))];
61+
- (GTObjectType)targetType {
62+
return (GTObjectType)git_tag_target_type(self.git_tag);
6563
}
6664

6765
- (GTSignature *)tagger {

ObjectiveGitFramework.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
04DB466E133AB5EB00D9C624 /* GTReference.m in Sources */ = {isa = PBXBuildFile; fileRef = BD441E07131ED0C300187010 /* GTReference.m */; };
7575
04DB466F133AB5EB00D9C624 /* GTBranch.m in Sources */ = {isa = PBXBuildFile; fileRef = 88F50F57132054D800584FBE /* GTBranch.m */; };
7676
04DB4672133AB5FE00D9C624 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 04DB4671133AB5FE00D9C624 /* libz.dylib */; };
77+
2089E43C17D9A58000F451DA /* GTTagSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 2089E43B17D9A58000F451DA /* GTTagSpec.m */; };
7778
3011D86B1668E48500CE3409 /* GTDiffFile.h in Headers */ = {isa = PBXBuildFile; fileRef = 3011D8691668E48500CE3409 /* GTDiffFile.h */; settings = {ATTRIBUTES = (Public, ); }; };
7879
3011D86C1668E48500CE3409 /* GTDiffFile.h in Headers */ = {isa = PBXBuildFile; fileRef = 3011D8691668E48500CE3409 /* GTDiffFile.h */; settings = {ATTRIBUTES = (Public, ); }; };
7980
3011D86D1668E48500CE3409 /* GTDiffFile.m in Sources */ = {isa = PBXBuildFile; fileRef = 3011D86A1668E48500CE3409 /* GTDiffFile.m */; };
@@ -161,7 +162,6 @@
161162
88F05ABA16011FFD00B7AD1D /* GTReferenceTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 88F05AA916011FFD00B7AD1D /* GTReferenceTest.m */; };
162163
88F05ABB16011FFD00B7AD1D /* GTRepositoryPackTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 88F05AAA16011FFD00B7AD1D /* GTRepositoryPackTest.m */; };
163164
88F05ABC16011FFD00B7AD1D /* GTRepositoryTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 88F05AAB16011FFD00B7AD1D /* GTRepositoryTest.m */; };
164-
88F05ABD16011FFD00B7AD1D /* GTTagTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 88F05AAC16011FFD00B7AD1D /* GTTagTest.m */; };
165165
88F05AC41601204200B7AD1D /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 88F05A7816011E5400B7AD1D /* InfoPlist.strings */; };
166166
88F05AC61601209A00B7AD1D /* ObjectiveGit.m in Sources */ = {isa = PBXBuildFile; fileRef = 88F05AC51601209A00B7AD1D /* ObjectiveGit.m */; };
167167
88F05AC716012CE500B7AD1D /* NSString+Git.m in Sources */ = {isa = PBXBuildFile; fileRef = 55C8057313874CDF004DCB0F /* NSString+Git.m */; };
@@ -342,6 +342,7 @@
342342
0867D6A5FE840307C02AAC07 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; };
343343
089C1667FE841158C02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = "<group>"; };
344344
1058C7B1FEA5585E11CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
345+
2089E43B17D9A58000F451DA /* GTTagSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTTagSpec.m; sourceTree = "<group>"; };
345346
3011D8691668E48500CE3409 /* GTDiffFile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GTDiffFile.h; sourceTree = "<group>"; };
346347
3011D86A1668E48500CE3409 /* GTDiffFile.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTDiffFile.m; sourceTree = "<group>"; };
347348
3011D86F1668E78500CE3409 /* GTDiffHunk.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GTDiffHunk.h; sourceTree = "<group>"; };
@@ -407,7 +408,6 @@
407408
88F05AA916011FFD00B7AD1D /* GTReferenceTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTReferenceTest.m; sourceTree = "<group>"; };
408409
88F05AAA16011FFD00B7AD1D /* GTRepositoryPackTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTRepositoryPackTest.m; sourceTree = "<group>"; };
409410
88F05AAB16011FFD00B7AD1D /* GTRepositoryTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTRepositoryTest.m; sourceTree = "<group>"; };
410-
88F05AAC16011FFD00B7AD1D /* GTTagTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTTagTest.m; sourceTree = "<group>"; };
411411
88F05AAF16011FFD00B7AD1D /* ObjectiveGitTests-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "ObjectiveGitTests-Info.plist"; sourceTree = "<group>"; };
412412
88F05AC51601209A00B7AD1D /* ObjectiveGit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ObjectiveGit.m; path = Classes/ObjectiveGit.m; sourceTree = "<group>"; };
413413
88F05AC91601335C00B7AD1D /* Specta.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Specta.xcodeproj; path = specta/Specta.xcodeproj; sourceTree = "<group>"; };
@@ -640,7 +640,7 @@
640640
D0AC906B172F941F00347DC4 /* GTRepositorySpec.m */,
641641
88F05AAB16011FFD00B7AD1D /* GTRepositoryTest.m */,
642642
D03B7C401756AB370034A610 /* GTSubmoduleSpec.m */,
643-
88F05AAC16011FFD00B7AD1D /* GTTagTest.m */,
643+
2089E43B17D9A58000F451DA /* GTTagSpec.m */,
644644
88A994C916FCED1D00402C7B /* GTTestCase.h */,
645645
88A994CA16FCED1D00402C7B /* GTTestCase.m */,
646646
30B1E7FF1703871900D0814D /* GTTimeAdditionsSpec.m */,
@@ -1217,9 +1217,9 @@
12171217
88F05ABA16011FFD00B7AD1D /* GTReferenceTest.m in Sources */,
12181218
88F05ABB16011FFD00B7AD1D /* GTRepositoryPackTest.m in Sources */,
12191219
88F05ABC16011FFD00B7AD1D /* GTRepositoryTest.m in Sources */,
1220-
88F05ABD16011FFD00B7AD1D /* GTTagTest.m in Sources */,
12211220
30865A91167F503400B1AB6E /* GTDiffSpec.m in Sources */,
12221221
88A994BA16FCE7D400402C7B /* GTBranchSpec.m in Sources */,
1222+
2089E43C17D9A58000F451DA /* GTTagSpec.m in Sources */,
12231223
88A994CB16FCED1D00402C7B /* GTTestCase.m in Sources */,
12241224
30B1E8001703871900D0814D /* GTTimeAdditionsSpec.m in Sources */,
12251225
88C0BC5917038CF3009E99AA /* GTConfigurationSpec.m in Sources */,

ObjectiveGitTests/GTRepositorySpec.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
expect(tag.message).to.equal(@"my tag\n");
107107
expect(tag.name).to.equal(@"a_new_tag");
108108
expect(tag.target.SHA).to.equal(@"5b5b025afb0b4c913b4c338a42934a3863bf3644");
109-
expect(tag.targetType).to.equal(@"commit");
109+
expect(tag.targetType).to.equal(GTObjectTypeCommit);
110110

111111
rm_loose(self.class, newOID.SHA);
112112
NSFileManager *m = [[NSFileManager alloc] init];

ObjectiveGitTests/GTTagSpec.m

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//
2+
// GTOIDSpec.m
3+
// ObjectiveGitFramework
4+
//
5+
// Created by Ezekiel Pierson on 2013-09-06.
6+
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
7+
//
8+
9+
#import "GTTag.h"
10+
11+
SpecBegin(GTTag)
12+
13+
__block GTTag *tag;
14+
15+
beforeEach(^{
16+
NSError *error = nil;
17+
GTRepository *repo = [GTRepository repositoryWithURL:[NSURL fileURLWithPath:TEST_REPO_PATH(self.class)] error:&error];
18+
NSString *tagSHA = @"0c37a5391bbff43c37f0d0371823a5509eed5b1d";
19+
tag = (GTTag *)[repo lookupObjectBySHA:tagSHA error:&error];
20+
expect(error).to.beFalsy;
21+
expect(tag).to.beTruthy;
22+
expect(tagSHA).to.equal(tag.SHA);
23+
});
24+
25+
it(@"can read tag data", ^{
26+
expect(tag.type).to.equal(@"tag");
27+
expect(tag.name).to.equal(@"v1.0");
28+
expect(tag.message).to.equal(@"test tag message\n");
29+
expect(tag.target.SHA).to.equal(@"5b5b025afb0b4c913b4c338a42934a3863bf3644");
30+
expect(GTObjectTypeCommit).to.equal(tag.targetType);
31+
32+
GTSignature *signature = tag.tagger;
33+
expect(signature.name).to.equal(@"Scott Chacon");
34+
expect((int)[signature.time timeIntervalSince1970]).to.equal(1288114383);
35+
expect(signature.email).to.equal(@"[email protected]");
36+
});
37+
38+
SpecEnd

ObjectiveGitTests/GTTagTest.m

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)