Skip to content

Commit 80dac00

Browse files
committed
Use libgit2 function to get the branch name.
1 parent c31df0c commit 80dac00

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 @@ - (nullable 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
@@ -159,7 +159,7 @@ - (BOOL)mergeBranchIntoCurrentBranch:(GTBranch *)branch withError:(NSError **)er
159159
NSArray *parents = @[ localCommit, remoteCommit ];
160160

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

ObjectiveGitTests/GTBranchSpec.m

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

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

ObjectiveGitTests/GTRepositorySpec.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@
268268
GTBranch *currentBranch = [repository currentBranchWithError:&error];
269269
expect(currentBranch).notTo(beNil());
270270
expect(error).to(beNil());
271-
expect(currentBranch.name).to(equal(@"refs/heads/master"));
271+
expect(currentBranch.name).to(equal(@"master"));
272272
});
273273
});
274274

@@ -308,7 +308,7 @@
308308
expect(error).to(beNil());
309309
expect(@(branches.count)).to(equal(@1));
310310
GTBranch *remoteBranch = branches[0];
311-
expect(remoteBranch.name).to(equal(@"refs/remotes/origin/master"));
311+
expect(remoteBranch.name).to(equal(@"origin/master"));
312312
});
313313
});
314314

0 commit comments

Comments
 (0)