Skip to content

Commit f7bd35a

Browse files
author
Ben Chatelain
committed
Merge branch 'master' into phatblat/pr/swift1.2
2 parents 5792a9d + 30219e2 commit f7bd35a

File tree

7 files changed

+86
-2
lines changed

7 files changed

+86
-2
lines changed

ObjectiveGit/GTBranch.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,12 @@ - (GTBranch *)trackingBranchWithError:(NSError **)error success:(BOOL *)success
193193
}
194194

195195
- (BOOL)updateTrackingBranch:(GTBranch *)trackingBranch error:(NSError **)error {
196-
int result = git_branch_set_upstream(self.reference.git_reference, trackingBranch.shortName.UTF8String);
196+
int result = GIT_ENOTFOUND;
197+
if (trackingBranch.branchType == GTBranchTypeRemote) {
198+
result = git_branch_set_upstream(self.reference.git_reference, [trackingBranch.name stringByReplacingOccurrencesOfString:[GTBranch remoteNamePrefix] withString:@""].UTF8String);
199+
} else {
200+
result = git_branch_set_upstream(self.reference.git_reference, trackingBranch.shortName.UTF8String);
201+
}
197202
if (result != GIT_OK) {
198203
if (error != NULL) *error = [NSError git_errorFor:result description:@"Failed to update tracking branch for %@", self];
199204
return NO;

ObjectiveGit/GTRepository+RemoteOperations.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,18 @@ NS_ASSUME_NONNULL_BEGIN
8080
/// will point to an error describing what happened).
8181
- (BOOL)pushBranches:(NSArray *)branches toRemote:(GTRemote *)remote withOptions:(nullable NSDictionary *)options error:(NSError **)error progress:(nullable void (^)(unsigned int current, unsigned int total, size_t bytes, BOOL *stop))progressBlock;
8282

83+
/// Delete a remote branch
84+
///
85+
/// branch - The branch to push. Must not be nil.
86+
/// remote - The remote to push to. Must not be nil.
87+
/// options - Options applied to the push operation. Can be NULL.
88+
/// Recognized options are:
89+
/// `GTRepositoryRemoteOptionsCredentialProvider`
90+
/// error - The error if one occurred. Can be NULL.
91+
///
92+
/// Returns YES if the push was successful, NO otherwise (and `error`, if provided,
93+
/// will point to an error describing what happened).
94+
- (BOOL)deleteBranch:(GTBranch *)branch fromRemote:(GTRemote *)remote withOptions:(NSDictionary *)options error:(NSError **)error;
8395
@end
8496

8597
NS_ASSUME_NONNULL_END

ObjectiveGit/GTRepository+RemoteOperations.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,16 @@ - (BOOL)pushBranches:(NSArray *)branches toRemote:(GTRemote *)remote withOptions
196196
return [self pushRefspecs:refspecs toRemote:remote withOptions:options error:error progress:progressBlock];
197197
}
198198

199+
#pragma mark - Deletion (Public)
200+
- (BOOL)deleteBranch:(GTBranch *)branch fromRemote:(GTRemote *)remote withOptions:(NSDictionary *)options error:(NSError **)error {
201+
NSParameterAssert(branch != nil);
202+
NSParameterAssert(remote != nil);
203+
204+
NSArray *refspecs = @[ [NSString stringWithFormat:@":refs/heads/%@", branch.shortName] ];
205+
206+
return [self pushRefspecs:refspecs toRemote:remote withOptions:options error:error progress:nil];
207+
}
208+
199209
#pragma mark - Push (Private)
200210

201211
- (BOOL)pushRefspecs:(NSArray *)refspecs toRemote:(GTRemote *)remote withOptions:(NSDictionary *)options error:(NSError **)error progress:(GTRemotePushTransferProgressBlock)progressBlock {

ObjectiveGit/GTTree.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ - (GTTreeEntry *)entryWithName:(NSString *)name {
7171
- (GTTreeEntry *)entryWithPath:(NSString *)path error:(NSError **)error {
7272
git_tree_entry *internalEntry = NULL;
7373
int gitError = git_tree_entry_bypath(&internalEntry, self.git_tree, path.UTF8String);
74-
if (error != GIT_OK) {
74+
if (gitError != GIT_OK) {
7575
if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Failed to get tree entry %@", path];
7676
return nil;
7777
}

ObjectiveGitTests/GTBranchSpec.m

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,37 @@
228228
expect(trackingBranch).to(beNil());
229229
expect(@(success)).to(beTruthy());
230230
});
231+
232+
it(@"should set a remote tracking branch without branches amount change", ^{
233+
GTRepository *repository = self.testAppForkFixtureRepository;
234+
expect(repository).notTo(beNil());
235+
236+
NSError *error = nil;
237+
BOOL success = NO;
238+
GTBranch *remoteBranch = [repository lookUpBranchWithName:@"github/BranchC" type:GTBranchTypeRemote success:&success error:&error];
239+
expect(remoteBranch).notTo(beNil());
240+
expect(error).to(beNil());
241+
242+
NSArray *beforeBranches = [repository branches:&error];
243+
expect(error).to(beNil());
244+
245+
GTBranch *localBranch = [repository createBranchNamed:remoteBranch.shortName fromOID:remoteBranch.OID message:nil error:&error];
246+
expect(localBranch).notTo(beNil());
247+
expect(error).to(beNil());
248+
249+
NSArray *inBranches = [repository branches:&error];
250+
expect(error).to(beNil());
251+
252+
[localBranch updateTrackingBranch:remoteBranch error:&error];
253+
expect(error).to(beNil());
254+
255+
NSArray *afterBranches = [repository branches:&error];
256+
expect(error).to(beNil());
257+
258+
expect(@(beforeBranches.count + 1)).to(equal(@(inBranches.count)));
259+
expect(@(beforeBranches.count)).to(equal(@(afterBranches.count)));
260+
261+
});
231262
});
232263

233264
// TODO: Test branch renaming, branch upstream

ObjectiveGitTests/GTTreeSpec.m

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,30 @@
9999
expect([tree entryWithName:@"_does not exist"]).to(beNil());
100100
});
101101

102+
describe(@"fetching entries from paths", ^{
103+
it(@"should be able to fetch existing paths",^{
104+
NSError *error = nil;
105+
GTTreeEntry *entry;
106+
107+
entry = [tree entryWithPath:@"README" error:&error];
108+
expect(error).to(beNil());
109+
expect(entry).notTo(beNil());
110+
111+
entry = [tree entryWithPath:@"subdir/README" error:&error];
112+
expect(error).to(beNil());
113+
expect(entry).notTo(beNil());
114+
});
115+
116+
it(@"should return nil and fill error for non-existent paths",^{
117+
NSError *error = nil;
118+
GTTreeEntry *entry;
119+
120+
entry = [tree entryWithPath:@"does/not/exist" error:&error];
121+
expect(error).notTo(beNil());
122+
expect(entry).to(beNil());
123+
});
124+
});
125+
102126
afterEach(^{
103127
[self tearDown];
104128
});

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# ObjectiveGit
22

3+
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
4+
35
ObjectiveGit provides Cocoa bindings to the
46
[libgit2](https://github.com/libgit2/libgit2) library.
57

0 commit comments

Comments
 (0)