Skip to content

Commit 8a67e08

Browse files
committed
Use libgit2 function to get the branch name.
1 parent b16d6c4 commit 8a67e08

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

ObjectiveGit/GTBranch.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,11 @@ - (instancetype)initWithReference:(GTReference *)ref {
8787
}
8888

8989
- (NSString *)name {
90-
return self.reference.name;
90+
const char *charName;
91+
int gitError = git_branch_name(&charName, self.reference.git_reference);
92+
if (gitError != GIT_OK || charName == NULL) return nil;
93+
94+
return @(charName);
9195
}
9296

9397
- (NSString *)shortName {

ObjectiveGit/GTRepository+Merging.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ - (BOOL)mergeBranchIntoCurrentBranch:(GTBranch *)branch withError:(NSError **)er
158158
NSArray *parents = @[ localCommit, remoteCommit ];
159159

160160
// FIXME: This is stepping on the local tree
161-
GTCommit *mergeCommit = [self createCommitWithTree:newTree message:message parents:parents updatingReferenceNamed:localBranch.name error:error];
161+
GTCommit *mergeCommit = [self createCommitWithTree:newTree message:message parents:parents updatingReferenceNamed:localBranch.reference.name error:error];
162162
if (!mergeCommit) {
163163
return NO;
164164
}

ObjectiveGitTests/GTBranchSpec.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@
3535
expect(error).to(beNil());
3636
});
3737

38+
describe(@"name", ^{
39+
it(@"should use just the branch name for a local branch", ^{
40+
expect(masterBranch.name).to(equal(@"master"));
41+
});
42+
43+
it(@"should include the remote name for a tracking branch", ^{
44+
expect(trackingBranch.name).to(equal(@"origin/master"));
45+
});
46+
});
47+
3848
describe(@"shortName", ^{
3949
it(@"should use just the branch name for a local branch", ^{
4050
expect(masterBranch.shortName).to(equal(@"master"));

ObjectiveGitTests/GTRepositorySpec.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@
292292
GTBranch *currentBranch = [repository currentBranchWithError:&error];
293293
expect(currentBranch).notTo(beNil());
294294
expect(error).to(beNil());
295-
expect(currentBranch.name).to(equal(@"refs/heads/master"));
295+
expect(currentBranch.name).to(equal(@"master"));
296296
});
297297
});
298298

@@ -332,7 +332,7 @@
332332
expect(error).to(beNil());
333333
expect(@(branches.count)).to(equal(@1));
334334
GTBranch *remoteBranch = branches[0];
335-
expect(remoteBranch.name).to(equal(@"refs/remotes/origin/master"));
335+
expect(remoteBranch.name).to(equal(@"origin/master"));
336336
});
337337
});
338338

0 commit comments

Comments
 (0)