-
Notifications
You must be signed in to change notification settings - Fork 284
Expand file tree
/
Copy pathGTUtilityFunctions.m
More file actions
49 lines (36 loc) · 1.67 KB
/
Copy pathGTUtilityFunctions.m
File metadata and controls
49 lines (36 loc) · 1.67 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
//
// GTUtilityFunctions.m
// ObjectiveGitFramework
//
// Created by Ben Chatelain on 6/28/15.
// Copyright (c) 2015 GitHub, Inc. All rights reserved.
//
@import ObjectiveGit;
@import Nimble;
@import Quick;
#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];
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) {
BOOL success = NO;
GTBranch *branch = [repo lookUpBranchWithName:branchName type:GTBranchTypeLocal success:&success error:NULL];
expect(branch).notTo(beNil());
expect(branch.shortName).to(equal(branchName));
return branch;
};