|
| 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