Skip to content

Commit e86b888

Browse files
committed
Add -[GTBranch rename:]
1 parent ef52f32 commit e86b888

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

ObjectiveGit/GTBranch.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ NS_ASSUME_NONNULL_BEGIN
8080
/// returns a GTCommit object or nil if an error occurred
8181
- (nullable GTCommit *)targetCommitWithError:(NSError **)error;
8282

83+
/// Renames the branch. Setting `force` to YES to delete another branch with the same name.
84+
- (BOOL)rename:(NSString *)name force:(BOOL)force error:(NSError **)error;
85+
8386
/// Count all commits in this branch
8487
///
8588
/// error(out) - will be filled if an error occurs

ObjectiveGit/GTBranch.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,19 @@ - (BOOL)deleteWithError:(NSError **)error {
171171
return YES;
172172
}
173173

174+
- (BOOL)rename:(NSString *)name force:(BOOL)force error:(NSError **)error {
175+
git_reference *git_ref;
176+
int gitError = git_branch_move(&git_ref, self.reference.git_reference, name.UTF8String, (force ? 0 : 1));
177+
if (gitError != GIT_OK) {
178+
if (error) *error = [NSError git_errorFor:gitError description:@"Rename branch failed"];
179+
return NO;
180+
}
181+
182+
_reference = [[GTReference alloc] initWithGitReference:git_ref repository:self.repository];
183+
184+
return YES;
185+
}
186+
174187
- (GTBranch *)trackingBranchWithError:(NSError **)error success:(BOOL *)success {
175188
if (self.branchType == GTBranchTypeRemote) {
176189
if (success != NULL) *success = YES;

0 commit comments

Comments
 (0)