Skip to content

Commit 7c64ab7

Browse files
committed
Added -updateTrackingBranch:error:.
1 parent 301a70c commit 7c64ab7

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

ObjectiveGit/GTBranch.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ typedef NS_ENUM(NSInteger, GTBranchType) {
7979
/// found, returns nil and sets `success` to YES.
8080
- (GTBranch *)trackingBranchWithError:(NSError **)error success:(BOOL *)success;
8181

82+
/// Update the tracking branch.
83+
///
84+
/// trackingBranch - The tracking branch for the receiver. If nil, it unsets the
85+
/// tracking branch.
86+
/// error - The error if one occurred.
87+
///
88+
/// Returns whether it was successful.
89+
- (BOOL)updateTrackingBranch:(GTBranch *)trackingBranch error:(NSError **)error;
90+
8291
/// Reloads the branch's reference and creates a new branch based off that newly
8392
/// loaded reference.
8493
///

ObjectiveGit/GTBranch.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,16 @@ - (GTBranch *)trackingBranchWithError:(NSError **)error success:(BOOL *)success
205205
return [[self class] branchWithReference:[[GTReference alloc] initWithGitReference:trackingRef repository:self.repository] repository:self.repository];
206206
}
207207

208+
- (BOOL)updateTrackingBranch:(GTBranch *)trackingBranch error:(NSError **)error {
209+
int result = git_branch_set_upstream(self.reference.git_reference, trackingBranch.name.UTF8String);
210+
if (result != GIT_OK) {
211+
if (error != NULL) *error = [NSError git_errorFor:result description:@"Failed to update tracking branch for %@", self];
212+
return NO;
213+
}
214+
215+
return YES;
216+
}
217+
208218
- (GTBranch *)reloadedBranchWithError:(NSError **)error {
209219
GTReference *reloadedRef = [self.reference reloadedReferenceWithError:error];
210220
if (reloadedRef == nil) return nil;

0 commit comments

Comments
 (0)