|
14 | 14 |
|
15 | 15 | QuickSpecBegin(GTRemotePushSpec) |
16 | 16 |
|
17 | | -describe(@"push to local filesystem bare repo", ^{ |
| 17 | +describe(@"push to remote", ^{ |
18 | 18 | __block GTRepository *localRepo; |
19 | 19 | __block GTRepository *remoteRepo; |
20 | 20 | __block GTRemote *remote; |
| 21 | + __block NSURL *notBareRepoURL; |
21 | 22 | __block NSURL *remoteRepoFileURL; |
22 | 23 | __block NSURL *localRepoURL; |
| 24 | + __block GTBranch *masterBranch; |
23 | 25 |
|
24 | 26 | beforeEach(^{ |
25 | 27 | NSError *error = nil; |
|
30 | 32 | expect(@(notBareRepo.isBare)).to(beFalse()); |
31 | 33 |
|
32 | 34 | // Make a bare clone to serve as the remote |
33 | | - NSURL *bareRepoURL = [notBareRepo.gitDirectoryURL.URLByDeletingLastPathComponent URLByAppendingPathComponent:@"barerepo.git"]; |
| 35 | + notBareRepoURL = [notBareRepo.gitDirectoryURL.URLByDeletingLastPathComponent URLByAppendingPathComponent:@"barerepo.git"]; |
34 | 36 | NSDictionary *options = @{ GTRepositoryCloneOptionsBare: @(1) }; |
35 | | - remoteRepo = [GTRepository cloneFromURL:notBareRepo.gitDirectoryURL toWorkingDirectory:bareRepoURL options:options error:&error transferProgressBlock:NULL checkoutProgressBlock:NULL]; |
| 37 | + remoteRepo = [GTRepository cloneFromURL:notBareRepo.gitDirectoryURL toWorkingDirectory:notBareRepoURL options:options error:&error transferProgressBlock:NULL checkoutProgressBlock:NULL]; |
36 | 38 | expect(error).to(beNil()); |
37 | 39 | expect(remoteRepo).notTo(beNil()); |
38 | 40 | expect(@(remoteRepo.isBare)).to(beTruthy()); // that's better |
|
42 | 44 | NSURL *localRepoURL = [remoteRepoFileURL.URLByDeletingLastPathComponent URLByAppendingPathComponent:@"localpushrepo"]; |
43 | 45 | expect(localRepoURL).notTo(beNil()); |
44 | 46 |
|
| 47 | + // Ensure repo destination is clear before clone |
| 48 | + [NSFileManager.defaultManager removeItemAtURL:localRepoURL error:NULL]; |
| 49 | + |
45 | 50 | // Local clone for testing pushes |
46 | 51 | localRepo = [GTRepository cloneFromURL:remoteRepoFileURL toWorkingDirectory:localRepoURL options:nil error:&error transferProgressBlock:NULL checkoutProgressBlock:NULL]; |
47 | 52 |
|
|
56 | 61 |
|
57 | 62 | remote = configuration.remotes[0]; |
58 | 63 | expect(remote.name).to(equal(@"origin")); |
| 64 | + |
| 65 | + // TODO: Verify tracking between local and remote branches |
| 66 | + NSArray *branches = [localRepo allBranchesWithError:&error]; |
| 67 | + expect(error).to(beNil()); |
| 68 | + expect(branches).notTo(beNil()); |
| 69 | + |
| 70 | + masterBranch = branches[0]; |
| 71 | + expect(masterBranch.shortName).to(equal(@"master")); |
59 | 72 | }); |
60 | 73 |
|
61 | 74 | afterEach(^{ |
| 75 | + [NSFileManager.defaultManager removeItemAtURL:notBareRepoURL error:NULL]; |
62 | 76 | [NSFileManager.defaultManager removeItemAtURL:remoteRepoFileURL error:NULL]; |
63 | 77 | [NSFileManager.defaultManager removeItemAtURL:localRepoURL error:NULL]; |
64 | 78 | }); |
65 | 79 |
|
| 80 | + // Helper to quickly create commits |
| 81 | + GTCommit *(^createCommitInRepository)(NSString *, NSData *, NSString *, GTRepository *) = ^(NSString *message, NSData *fileData, NSString *fileName, GTRepository *repo) { |
| 82 | + GTTreeBuilder *treeBuilder = [[GTTreeBuilder alloc] initWithTree:nil error:nil]; |
| 83 | + [treeBuilder addEntryWithData:fileData fileName:fileName fileMode:GTFileModeBlob error:nil]; |
| 84 | + |
| 85 | + GTTree *testTree = [treeBuilder writeTreeToRepository:repo error:nil]; |
| 86 | + |
| 87 | + // We need the parent commit to make the new one |
| 88 | + GTReference *headReference = [repo headReferenceWithError:nil]; |
| 89 | + |
| 90 | + GTEnumerator *commitEnum = [[GTEnumerator alloc] initWithRepository:repo error:nil]; |
| 91 | + [commitEnum pushSHA:[headReference targetSHA] error:nil]; |
| 92 | + GTCommit *parent = [commitEnum nextObject]; |
| 93 | + |
| 94 | + GTCommit *testCommit = [repo createCommitWithTree:testTree message:message parents:@[parent] updatingReferenceNamed:headReference.name error:nil]; |
| 95 | + expect(testCommit).notTo(beNil()); |
| 96 | + |
| 97 | + return testCommit; |
| 98 | + }; |
| 99 | + |
66 | 100 | describe(@"-pushBranch:toRemote:withOptions:error:progress:", ^{ |
67 | 101 | it(@"pushes nothing when the branch on local and remote are in sync", ^{ |
68 | 102 | NSError *error = nil; |
69 | | - NSArray *branches = [localRepo allBranchesWithError:&error]; |
| 103 | + |
| 104 | + BOOL result = [localRepo pushBranch:masterBranch toRemote:remote withOptions:nil error:&error progress:NULL]; |
70 | 105 | expect(error).to(beNil()); |
71 | | - expect(branches).notTo(beNil()); |
| 106 | + expect(@(result)).to(beTruthy()); |
| 107 | + }); |
| 108 | + |
| 109 | + it(@"pushes a new local commit to the remote", ^{ |
| 110 | + NSError *error = nil; |
72 | 111 |
|
73 | | - GTBranch *branch = branches[0]; |
74 | | - expect(branch.shortName).to(equal(@"master")); |
| 112 | + // Create a new commit in the master repo |
| 113 | + NSString *testData = @"Test"; |
| 114 | + NSString *fileName = @"test.txt"; |
| 115 | + GTCommit *testCommit = createCommitInRepository(@"Test commit", [testData dataUsingEncoding:NSUTF8StringEncoding], fileName, localRepo); |
| 116 | + expect(testCommit).notTo(beNil()); |
75 | 117 |
|
76 | | - BOOL result = [localRepo pushBranch:branch toRemote:remote withOptions:nil error:&error progress:NULL]; |
| 118 | + // Push |
| 119 | + BOOL result = [localRepo pushBranch:masterBranch toRemote:remote withOptions:nil error:&error progress:NULL]; |
77 | 120 | expect(error).to(beNil()); |
78 | 121 | expect(@(result)).to(beTruthy()); |
| 122 | + |
| 123 | + // Verify commit is in remote |
| 124 | + GTCommit *pushedCommit = [remoteRepo lookUpObjectByOID:testCommit.OID objectType:GTObjectTypeCommit error:&error]; |
| 125 | + expect(error).to(beNil()); |
| 126 | + expect(pushedCommit).notTo(beNil()); |
| 127 | + expect(pushedCommit.OID).to(equal(testCommit.OID)); |
| 128 | + |
| 129 | + GTTreeEntry *entry = [[pushedCommit tree] entryWithName:fileName]; |
| 130 | + expect(entry).notTo(beNil()); |
| 131 | + |
| 132 | + GTBlob *fileData = (GTBlob *)[entry GTObject:&error]; |
| 133 | + expect(error).to(beNil()); |
| 134 | + expect(fileData).notTo(beNil()); |
| 135 | + expect(fileData.content).to(equal(testData)); |
79 | 136 | }); |
80 | 137 | }); |
81 | 138 |
|
|
0 commit comments