Skip to content

Commit 4d166f3

Browse files
author
Ben Chatelain
committed
Add GTRemotePushSpec.m
1 parent e7ff5b5 commit 4d166f3

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

ObjectiveGitFramework.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@
306306
DD3D9513182A81E1004AF532 /* GTBlame.m in Sources */ = {isa = PBXBuildFile; fileRef = DD3D9511182A81E1004AF532 /* GTBlame.m */; };
307307
DD3D951C182AB25C004AF532 /* GTBlameHunk.h in Headers */ = {isa = PBXBuildFile; fileRef = DD3D951A182AB25C004AF532 /* GTBlameHunk.h */; settings = {ATTRIBUTES = (Public, ); }; };
308308
DD3D951D182AB25C004AF532 /* GTBlameHunk.m in Sources */ = {isa = PBXBuildFile; fileRef = DD3D951B182AB25C004AF532 /* GTBlameHunk.m */; };
309+
F8E4A2911A170CA6006485A8 /* GTRemotePushSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = F8E4A2901A170CA6006485A8 /* GTRemotePushSpec.m */; };
309310
/* End PBXBuildFile section */
310311

311312
/* Begin PBXContainerItemProxy section */
@@ -554,6 +555,7 @@
554555
DD3D951B182AB25C004AF532 /* GTBlameHunk.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTBlameHunk.m; sourceTree = "<group>"; };
555556
E46931A7172740D300F2077D /* update_libgit2 */ = {isa = PBXFileReference; lastKnownFileType = text; name = update_libgit2; path = script/update_libgit2; sourceTree = "<group>"; };
556557
E46931A8172740D300F2077D /* update_libgit2_ios */ = {isa = PBXFileReference; lastKnownFileType = text; name = update_libgit2_ios; path = script/update_libgit2_ios; sourceTree = "<group>"; };
558+
F8E4A2901A170CA6006485A8 /* GTRemotePushSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTRemotePushSpec.m; sourceTree = "<group>"; };
557559
/* End PBXFileReference section */
558560

559561
/* Begin PBXFrameworksBuildPhase section */
@@ -703,6 +705,7 @@
703705
88F05AA816011FFD00B7AD1D /* GTObjectSpec.m */,
704706
D00F6815175D373C004DB9D6 /* GTReferenceSpec.m */,
705707
88215482171499BE00D76B76 /* GTReflogSpec.m */,
708+
F8E4A2901A170CA6006485A8 /* GTRemotePushSpec.m */,
706709
4DBA4A3117DA73CE006CD5F5 /* GTRemoteSpec.m */,
707710
200578C418932A82001C06C3 /* GTBlameSpec.m */,
708711
D0AC906B172F941F00347DC4 /* GTRepositorySpec.m */,
@@ -1250,6 +1253,7 @@
12501253
88E353061982EA6B0051001F /* GTRepositoryAttributesSpec.m in Sources */,
12511254
88234B2618F2FE260039972E /* GTRepositoryResetSpec.m in Sources */,
12521255
5BE612931745EEBC00266D8C /* GTTreeBuilderSpec.m in Sources */,
1256+
F8E4A2911A170CA6006485A8 /* GTRemotePushSpec.m in Sources */,
12531257
D06D9E011755D10000558C17 /* GTEnumeratorSpec.m in Sources */,
12541258
D03B7C411756AB370034A610 /* GTSubmoduleSpec.m in Sources */,
12551259
D00F6816175D373C004DB9D6 /* GTReferenceSpec.m in Sources */,
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
//
2+
// GTRemotePushSpec.m
3+
// ObjectiveGitFramework
4+
//
5+
// Created by Ben Chatelain on 11/14/2014.
6+
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
7+
//
8+
9+
#import <Nimble/Nimble.h>
10+
#import <ObjectiveGit/ObjectiveGit.h>
11+
#import <Quick/Quick.h>
12+
13+
#import "QuickSpec+GTFixtures.h"
14+
15+
QuickSpecBegin(GTRemotePushSpec)
16+
17+
describe(@"push to local filesystem bare repo", ^{
18+
__block GTRepository *localRepo;
19+
__block GTRepository *remoteRepo;
20+
__block GTRemote *remote;
21+
__block NSURL *remoteRepoFileURL;
22+
__block NSURL *localRepoURL;
23+
24+
beforeEach(^{
25+
NSError *error = nil;
26+
27+
// This repo is not really "bare"
28+
GTRepository *notBareRepo = self.bareFixtureRepository;
29+
expect(notBareRepo).notTo(beNil());
30+
expect(@(notBareRepo.isBare)).to(beFalse());
31+
32+
// Make a bare clone to serve as the remote
33+
NSURL *bareRepoURL = [notBareRepo.gitDirectoryURL.URLByDeletingLastPathComponent URLByAppendingPathComponent:@"barerepo.git"];
34+
NSDictionary *options = @{ GTRepositoryCloneOptionsBare: @(1) };
35+
remoteRepo = [GTRepository cloneFromURL:notBareRepo.gitDirectoryURL toWorkingDirectory:bareRepoURL options:options error:&error transferProgressBlock:NULL checkoutProgressBlock:NULL];
36+
expect(error).to(beNil());
37+
expect(remoteRepo).notTo(beNil());
38+
expect(@(remoteRepo.isBare)).to(beTruthy()); // that's better
39+
40+
NSURL *remoteRepoFileURL = remoteRepo.gitDirectoryURL;
41+
expect(remoteRepoFileURL).notTo(beNil());
42+
NSURL *localRepoURL = [remoteRepoFileURL.URLByDeletingLastPathComponent URLByAppendingPathComponent:@"localpushrepo"];
43+
expect(localRepoURL).notTo(beNil());
44+
45+
// Local clone for testing pushes
46+
localRepo = [GTRepository cloneFromURL:remoteRepoFileURL toWorkingDirectory:localRepoURL options:nil error:&error transferProgressBlock:NULL checkoutProgressBlock:NULL];
47+
48+
expect(error).to(beNil());
49+
expect(localRepo).notTo(beNil());
50+
51+
GTConfiguration *configuration = [localRepo configurationWithError:&error];
52+
expect(error).to(beNil());
53+
expect(configuration).notTo(beNil());
54+
55+
expect(@(configuration.remotes.count)).to(equal(@1));
56+
57+
remote = configuration.remotes[0];
58+
expect(remote.name).to(equal(@"origin"));
59+
});
60+
61+
afterEach(^{
62+
[NSFileManager.defaultManager removeItemAtURL:remoteRepoFileURL error:NULL];
63+
[NSFileManager.defaultManager removeItemAtURL:localRepoURL error:NULL];
64+
});
65+
66+
describe(@"-pushBranch:toRemote:withOptions:error:progress:", ^{
67+
it(@"pushes nothing when the branch on local and remote are in sync", ^{
68+
NSError *error = nil;
69+
NSArray *branches = [localRepo allBranchesWithError:&error];
70+
expect(error).to(beNil());
71+
expect(branches).notTo(beNil());
72+
73+
GTBranch *branch = branches[0];
74+
expect(branch.shortName).to(equal(@"master"));
75+
76+
BOOL result = [localRepo pushBranch:branch toRemote:remote withOptions:nil error:&error progress:NULL];
77+
expect(error).to(beNil());
78+
expect(@(result)).to(beTruthy());
79+
});
80+
});
81+
82+
});
83+
84+
QuickSpecEnd

0 commit comments

Comments
 (0)