Skip to content

Commit db23293

Browse files
committed
Add branch upstream management methods
1 parent e86b888 commit db23293

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

ObjectiveGit/GTBranch.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ NS_ASSUME_NONNULL_BEGIN
5151
@property (nonatomic, readonly, strong) GTRepository *repository;
5252
@property (nonatomic, readonly, strong) GTReference *reference;
5353
@property (nonatomic, readonly, getter=isHEAD) BOOL HEAD;
54+
@property (nonatomic, assign) GTBranch *upstreamBranch;
5455

5556
+ (NSString *)localNamePrefix;
5657
+ (NSString *)remoteNamePrefix;

ObjectiveGit/GTBranch.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,19 @@ - (BOOL)isHEAD {
156156
return (git_branch_is_head(self.reference.git_reference) ? YES : NO);
157157
}
158158

159+
- (GTBranch *)upstreamBranch {
160+
git_reference *git_ref;
161+
int gitError = git_branch_upstream(&git_ref, self.reference.git_reference);
162+
if (gitError != GIT_OK) return nil;
163+
164+
GTReference *ref = [[GTReference alloc] initWithGitReference:git_ref repository:self.repository];
165+
return [GTBranch branchWithReference:ref];
166+
}
167+
168+
- (void)setUpstreamBranch:(GTBranch *)branch {
169+
git_branch_set_upstream(self.reference.git_reference, (branch ? branch.name.UTF8String : NULL));
170+
}
171+
159172
- (NSArray *)uniqueCommitsRelativeToBranch:(GTBranch *)otherBranch error:(NSError **)error {
160173
GTEnumerator *enumerator = [self.repository enumeratorForUniqueCommitsFromOID:self.OID relativeToOID:otherBranch.OID error:error];
161174
return [enumerator allObjectsWithError:error];

0 commit comments

Comments
 (0)