forked from git-up/GitUp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GCBranch-Tests.m
82 lines (67 loc) · 3.82 KB
/
GCBranch-Tests.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright (C) 2015-2018 Pierre-Olivier Latour <[email protected]>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#if !__has_feature(objc_arc)
#error This file requires ARC
#endif
#import "GCTestCase.h"
@implementation GCMultipleCommitsRepositoryTests (GCBranch)
- (void)testBranches {
NSString* path = [NSTemporaryDirectory() stringByAppendingPathComponent:[[NSProcessInfo processInfo] globallyUniqueString]];
// Test branch names
XCTAssertFalse([GCRepository isValidBranchName:@"my^branch"]);
XCTAssertTrue([GCRepository isValidBranchName:@"my_branch"]);
// Create bare local repo with empty commit
GCRepository* bare = [self createLocalRepositoryAtPath:path bare:YES];
XCTAssertNotNil(bare);
GCCommit* emptyCommit = [bare createCommitFromHEADWithMessage:@"Empty" error:NULL];
XCTAssertNotNil(emptyCommit);
// Add remote from bare and fetch
GCRemote* remote = [self.repository addRemoteWithName:@"origin" url:[NSURL fileURLWithPath:path] error:NULL];
XCTAssertNotNil(remote);
NSUInteger updatedTips;
XCTAssertTrue([self.repository fetchDefaultRemoteBranchesFromRemote:remote tagMode:kGCFetchTagMode_None prune:NO updatedTips:&updatedTips error:NULL]);
XCTAssertEqual(updatedTips, 1);
// Find branches
GCLocalBranch* localMaster = [self.repository findLocalBranchWithName:@"master" error:NULL];
XCTAssertEqualObjects(localMaster, self.masterBranch);
GCRemoteBranch* remoteMaster = [self.repository findRemoteBranchWithName:@"origin/master" error:NULL];
XCTAssertNotNil(remoteMaster);
// List branches
NSArray* branches1 = @[ self.masterBranch, self.topicBranch ];
XCTAssertEqualObjects([self.repository listLocalBranches:NULL], branches1);
XCTAssertEqualObjects([self.repository listRemoteBranches:NULL], @[ remoteMaster ]);
NSArray* branches2 = @[ self.masterBranch, self.topicBranch, remoteMaster ];
XCTAssertEqualObjects([self.repository listAllBranches:NULL], branches2);
// Configure upstream
XCTAssertTrue([self.repository setUpstream:remoteMaster forLocalBranch:localMaster error:NULL]);
XCTAssertEqualObjects([self.repository lookupUpstreamForLocalBranch:localMaster error:NULL], remoteMaster);
XCTAssertTrue([self.repository unsetUpstreamForLocalBranch:localMaster error:NULL]);
XCTAssertNil([self.repository lookupUpstreamForLocalBranch:localMaster error:NULL]);
// Check branch tip
GCCommit* tipCommit = [self.repository lookupTipCommitForBranch:self.masterBranch error:NULL];
XCTAssertEqualObjects(tipCommit, self.commit3);
// Set branch tip
XCTAssertTrue([self.repository setTipCommit:self.commit2 forBranch:self.topicBranch reflogMessage:nil error:NULL]);
XCTAssertEqualObjects([self.repository lookupTipCommitForBranch:self.topicBranch error:NULL], self.commit2);
// Create temp branch
GCLocalBranch* tempBranch = [self.repository createLocalBranchFromCommit:self.commit1 withName:@"temp" force:NO error:NULL];
XCTAssertNotNil(tempBranch);
XCTAssertTrue([self.repository setName:@"test" forLocalBranch:tempBranch force:NO error:NULL]);
XCTAssertEqualObjects([self.repository findLocalBranchWithName:@"test" error:NULL], tempBranch);
XCTAssertTrue([self.repository deleteLocalBranch:tempBranch error:NULL]);
// Destroy bare local repo
[self destroyLocalRepository:bare];
}
@end