Skip to content

Commit b16d6c4

Browse files
committed
Use libgit2 function to get remote name.
1 parent d07a747 commit b16d6c4

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

ObjectiveGit/GTBranch.m

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#import "GTRemote.h"
3333
#import "GTRepository.h"
3434
#import "NSError+Git.h"
35+
#import "NSData+Git.h"
3536

3637
#import "git2/branch.h"
3738
#import "git2/errors.h"
@@ -110,17 +111,12 @@ - (GTOID *)OID {
110111
}
111112

112113
- (NSString *)remoteName {
113-
if (self.branchType == GTBranchTypeLocal) return nil;
114-
115-
const char *name;
116-
int gitError = git_branch_name(&name, self.reference.git_reference);
114+
git_buf remote_name = GIT_BUF_INIT_CONST(0, NULL);
115+
int gitError = git_branch_remote_name(&remote_name, self.repository.git_repository, self.reference.name.UTF8String);
117116
if (gitError != GIT_OK) return nil;
118117

119-
// Find out where the remote name ends.
120-
const char *end = strchr(name, '/');
121-
if (end == NULL || end == name) return nil;
122-
123-
return [[NSString alloc] initWithBytes:name length:end - name encoding:NSUTF8StringEncoding];
118+
NSData *data = [NSData git_dataWithBuffer:&remote_name];
119+
return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
124120
}
125121

126122
- (GTCommit *)targetCommitWithError:(NSError **)error {

0 commit comments

Comments
 (0)