-
Notifications
You must be signed in to change notification settings - Fork 285
Expand file tree
/
Copy pathGTUtilityFunctions.m
More file actions
50 lines (37 loc) · 1.81 KB
/
Copy pathGTUtilityFunctions.m
File metadata and controls
50 lines (37 loc) · 1.81 KB
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
//
// GTUtilityFunctions.m
// ObjectiveGitFramework
//
// Created by Ben Chatelain on 6/28/15.
// Copyright (c) 2015 GitHub, Inc. All rights reserved.
//
#import <Nimble/Nimble.h>
#import <ObjectiveGit/ObjectiveGit.h>
#import <Quick/Quick.h>
#import "GTUtilityFunctions.h"
#pragma mark - Commit
CreateCommitBlock createCommitInRepository = ^ GTCommit * (NSString *message, NSData *fileData, NSString *fileName, GTRepository *repo) {
GTReference *head = [repo headReferenceWithError:NULL];
GTBranch *branch = [GTBranch branchWithReference:head repository:repo];
GTCommit *headCommit = [branch targetCommitWithError:NULL];
GTTreeBuilder *treeBuilder = [[GTTreeBuilder alloc] initWithTree:headCommit.tree repository:repo error:nil];
[treeBuilder addEntryWithData:fileData fileName:fileName fileMode:GTFileModeBlob error:nil];
GTTree *testTree = [treeBuilder writeTree:nil];
// We need the parent commit to make the new one
GTReference *headReference = [repo headReferenceWithError:nil];
GTEnumerator *commitEnum = [[GTEnumerator alloc] initWithRepository:repo error:nil];
[commitEnum pushSHA:[headReference targetOID].SHA error:nil];
GTCommit *parent = [commitEnum nextObject];
GTCommit *testCommit = [repo createCommitWithTree:testTree message:message parents:@[ parent ] updatingReferenceNamed:headReference.name error:nil];
expect(testCommit).notTo(beNil());
return testCommit;
};
#pragma mark - Branch
BranchBlock localBranchWithName = ^ GTBranch * (NSString *branchName, GTRepository *repo) {
NSString *reference = [GTBranch.localNamePrefix stringByAppendingString:branchName];
NSArray *branches = [repo branchesWithPrefix:reference error:NULL];
expect(branches).notTo(beNil());
expect(@(branches.count)).to(equal(@1));
expect(((GTBranch *)branches[0]).shortName).to(equal(branchName));
return branches[0];
};