Skip to content

Split GTRepository API #297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 65 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
618570b
Rewrite tests for GTBlob.
tiennou Nov 7, 2013
ed0a2a8
Use `git_blob_create_fromdisk` instead of going through the `fromwork…
tiennou Nov 7, 2013
b7f671f
Asserts.
tiennou Nov 7, 2013
709c2b3
Move the contents of `GTBranchTest` where they belong.
tiennou Nov 7, 2013
9e69d7c
Remove `GTBranchTest`.
tiennou Nov 7, 2013
04fd3e7
Convert `GTCommitTest` to Expecta.
tiennou Nov 7, 2013
f578c4c
Convert `GTReferenceTest`.
tiennou Nov 7, 2013
9c2c3e2
Convert `GTRepositoryTest`.
tiennou Nov 7, 2013
f655dec
Cleanup `GTBlob`'s header.
tiennou Nov 9, 2013
1ea8499
Make `error` a local variable.
tiennou Nov 9, 2013
49ed41f
Expect errors to be nil here.
tiennou Nov 9, 2013
9b1bd6c
Reindent commented test.
tiennou Nov 9, 2013
8346974
Rename test.
tiennou Nov 9, 2013
bc98f3c
Cruft--;
tiennou Nov 9, 2013
86d4f7b
Dot-syntaxify.
tiennou Nov 9, 2013
173e177
Rename `isValidReference` and define it at declaration time.
tiennou Nov 9, 2013
5246535
Make `error` a local variable.
tiennou Nov 9, 2013
79fcc2d
Fix the `lookupObjectByRefspec:error:` name.
tiennou Nov 9, 2013
d4a1ae8
Whitespace.
tiennou Nov 9, 2013
e09ebb5
Test that the returned branches are the expected ones.
tiennou Nov 9, 2013
d07941e
Test the complete reference array in one step.
tiennou Nov 9, 2013
8f47b33
Clarify comment.
tiennou Nov 9, 2013
9bc13e2
Test the actual error domain & code.
tiennou Nov 9, 2013
b88903d
Convert local `file:` URLs to paths before handing over to `git_clone`.
tiennou Oct 24, 2013
2b2be90
Dot-syntaxify.
tiennou Oct 29, 2013
8265839
Use `-fileSystemRepresentation` here.
tiennou Oct 29, 2013
bcdd927
File reference URLs are file URLs; no need for a separate test.
tiennou Oct 29, 2013
aa510a6
Useless call; file reference URLs know how to path-ify themselves.
tiennou Oct 29, 2013
7f7cb21
Test that the remote set by `+clone…` looks fine to libgit2.
tiennou Oct 29, 2013
2986a6b
De-oneline-ify.
tiennou Nov 9, 2013
cff180a
Make `error` a local.
tiennou Nov 9, 2013
cbe71f8
Add methods to create new bare and non-bare repositories to `GTTestCa…
tiennou Nov 9, 2013
c43cad5
Test that new repos have unborn HEADs.
tiennou Nov 9, 2013
3dd9c70
Define `expectSHAForRevspec` inline.
tiennou Nov 9, 2013
378b31d
Use the clone tests from #280.
tiennou Nov 9, 2013
87efa74
Put the newly-cloned repo in the test-case managed temporary directory.
tiennou Nov 9, 2013
87fff3b
Huh, bare clones don't checkout...
tiennou Nov 9, 2013
c6720b3
Merge branch 'master' into tests-to-specs
tiennou Nov 11, 2013
60b6c7e
Reorganize methods.
tiennou Oct 29, 2013
7d686ba
Add `isTag` and `isBranch` to `GTReference`.
tiennou Oct 29, 2013
e16488a
Add a branch enumerator using `git_branch_foreach` and use it.
tiennou Oct 29, 2013
a73a08b
Add a method to enumerate a repository's references.
tiennou Oct 29, 2013
bac8e98
Fix the documentation of that one.
tiennou Oct 29, 2013
126b394
Reorganize GTBranch.
tiennou Nov 10, 2013
361e671
Gotta love documentation.
tiennou Nov 10, 2013
0cdd6be
Add new branch initializers based on the libgit2 functions.
tiennou Nov 9, 2013
f211658
Use the reference's repository instead of asking for one.
tiennou Nov 10, 2013
b00b007
Use the libgit2 enum for those.
tiennou Nov 10, 2013
04a4b82
Cut down the number of initialization methods on GTReference.
tiennou Nov 10, 2013
bb261ee
Use libgit2 function to get the branch name.
tiennou Nov 10, 2013
b561652
Use libgit2 function to get remote name.
tiennou Nov 10, 2013
9c50e69
Some more API for GTBranch.
tiennou Nov 10, 2013
2db6938
Add a way to restrict branch lookups by type.
tiennou Nov 10, 2013
a17178f
Remove `success` parameter from `-trackingBranchWithError:success`.
tiennou Nov 10, 2013
865c48a
Tests.
tiennou Nov 10, 2013
15735d3
Move the object lookup methods in `GTObject`.
tiennou Nov 7, 2013
e3531ec
Merge branch 'branch-cleanup' into split-gtrepo
tiennou Nov 11, 2013
7d8449e
Rename `-fileURL` to `-workingDirectoryURL` and provide `-displayURL`.
tiennou Nov 11, 2013
4a993b8
Merge branch 'gtref-cleanup' into split-gtrepo
tiennou Nov 11, 2013
fb0359d
`#pragma mark`s.
tiennou Nov 11, 2013
066cfad
Tag creation & deletion methods.
tiennou Nov 11, 2013
cc40bbb
Remove tag creation methods from `GTRepository`.
tiennou Nov 11, 2013
b373d5d
Move tag creation specs to `GTTagSpec`.
tiennou Nov 11, 2013
c544fa6
Merge branch 'gttag-cleanup' into split-gtrepo
tiennou Nov 11, 2013
14d6a5a
Remove branch creation method from GTRepository.
tiennou Nov 10, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 29 additions & 7 deletions Classes/GTBlob.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,37 @@
#import "GTObject.h"


@interface GTBlob : GTObject {}
@interface GTBlob : GTObject

+ (id)blobWithString:(NSString *)string inRepository:(GTRepository *)repository error:(NSError **)error;
+ (id)blobWithData:(NSData *)data inRepository:(GTRepository *)repository error:(NSError **)error;
+ (id)blobWithFile:(NSURL *)file inRepository:(GTRepository *)repository error:(NSError **)error;
// Convenience class methods
+ (instancetype)blobWithString:(NSString *)string inRepository:(GTRepository *)repository error:(NSError **)error;
+ (instancetype)blobWithData:(NSData *)data inRepository:(GTRepository *)repository error:(NSError **)error;
+ (instancetype)blobWithFile:(NSURL *)file inRepository:(GTRepository *)repository error:(NSError **)error;

- (id)initWithString:(NSString *)string inRepository:(GTRepository *)repository error:(NSError **)error;
- (id)initWithData:(NSData *)data inRepository:(GTRepository *)repository error:(NSError **)error;
- (id)initWithFile:(NSURL *)file inRepository:(GTRepository *)repository error:(NSError **)error;
// Convenience wrapper around `-initWithData:inRepository:error` that converts the string to UTF8 data
- (instancetype)initWithString:(NSString *)string inRepository:(GTRepository *)repository error:(NSError **)error;

// Creates a new blob from the passed data.
//
// This writes data to the repository's object database.
//
// data - The data to write.
// repository - The repository to put the object in.
// error - Will be set if an error occurs.
//
// Returns a newly created blob object, or nil if an error occurs.
- (instancetype)initWithData:(NSData *)data inRepository:(GTRepository *)repository error:(NSError **)error;

// Creates a new blob from the specified file.
//
// This copies the data from the file to the repository's object database.
//
// data - The file to copy contents from.
// repository - The repository to put the object in.
// error - Will be set if an error occurs.
//
// Returns a newly created blob object, or nil if an error occurs.
- (instancetype)initWithFile:(NSURL *)file inRepository:(GTRepository *)repository error:(NSError **)error;

// The underlying `git_object` as a `git_blob` object.
- (git_blob *)git_blob __attribute__((objc_returns_inner_pointer));
Expand Down
11 changes: 10 additions & 1 deletion Classes/GTBlob.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ + (id)blobWithFile:(NSURL *)file inRepository:(GTRepository *)repository error:(
}

- (id)initWithOid:(const git_oid *)oid inRepository:(GTRepository *)repository error:(NSError **)error {
NSParameterAssert(oid != NULL);
NSParameterAssert(repository != nil);

git_object *obj;
int gitError = git_object_lookup(&obj, repository.git_repository, oid, (git_otype) GTObjectTypeBlob);
if (gitError < GIT_OK) {
Expand All @@ -73,6 +76,9 @@ - (id)initWithString:(NSString *)string inRepository:(GTRepository *)repository
}

- (id)initWithData:(NSData *)data inRepository:(GTRepository *)repository error:(NSError **)error {
NSParameterAssert(data != nil);
NSParameterAssert(repository != nil);

git_oid oid;
int gitError = git_blob_create_frombuffer(&oid, repository.git_repository, [data bytes], data.length);
if(gitError < GIT_OK) {
Expand All @@ -86,8 +92,11 @@ - (id)initWithData:(NSData *)data inRepository:(GTRepository *)repository error:
}

- (id)initWithFile:(NSURL *)file inRepository:(GTRepository *)repository error:(NSError **)error {
NSParameterAssert(file != nil);
NSParameterAssert(repository != nil);

git_oid oid;
int gitError = git_blob_create_fromworkdir(&oid, repository.git_repository, [[file path] UTF8String]);
int gitError = git_blob_create_fromdisk(&oid, repository.git_repository, [[file path] fileSystemRepresentation]);
if(gitError < GIT_OK) {
if(error != NULL) {
*error = [NSError git_errorFor:gitError description:@"Failed to create blob from NSURL"];
Expand Down
98 changes: 72 additions & 26 deletions Classes/GTBranch.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,53 +30,68 @@
@class GTRepository;

typedef enum {
GTBranchTypeLocal = 1,
GTBranchTypeRemote
GTBranchTypeLocal = GIT_BRANCH_LOCAL,
GTBranchTypeRemote = GIT_BRANCH_REMOTE,
GTBranchTypeAny = GIT_BRANCH_REMOTE|GIT_BRANCH_LOCAL,
} GTBranchType;

@interface GTBranch : NSObject

@property (nonatomic, readonly, strong) GTRepository *repository;
@property (nonatomic, readonly, strong) GTReference *reference;
@property (nonatomic, readonly) NSString *name;
@property (nonatomic, readonly) NSString *shortName;
@property (nonatomic, readonly) NSString *SHA;
@property (nonatomic, readonly) NSString *remoteName;
@property (nonatomic, readonly) NSString *SHA;
@property (nonatomic, readonly) GTBranchType branchType;
@property (nonatomic, readonly, strong) GTRepository *repository;
@property (nonatomic, readonly, strong) GTReference *reference;
@property (nonatomic, assign) GTBranch *trackingBranch;
@property (nonatomic, readonly, getter=isHead) BOOL head;

// Lookup a branch by name. Performs a `GTBranchTypeAny` lookup.
// See `+branchByLookingUpBranchNamed:type:inRepository:error:`.
+ (instancetype)branchByLookingUpBranchNamed:(NSString *)name inRepository:(GTRepository *)repository error:(NSError **)error;

// Lookup a branch by name and branch type.
//
// name - The branch name to lookup.
// type - The type of lookup to perform. If `GTBranchTypeAny` is passed,
// local branches are checked first.
// repository - The repository to lookup the branch in.
// error - A pointer which will point to a valid error if the lookup fails.
//
// Returns the branch object with that name, or nil if an error occurred.
+ (instancetype)branchByLookingUpBranchNamed:(NSString *)name type:(GTBranchType)type inRepository:(GTRepository *)repository error:(NSError **)error;

+ (NSString *)localNamePrefix;
+ (NSString *)remoteNamePrefix;
// Create a branch from a name and target.
//
// name - The name of the branch to create.
// commit - The commit the branch should point to.
// force - If set to YES, a branch with same name would be deleted.
// repository - The repository to create the branch in.
// error - A pointer which will point to a valid error if the creation fails.
//
// Returns a newly created branch object, or nil if the branch couldn't be created.
+ (instancetype)branchByCreatingBranchNamed:(NSString *)name target:(GTCommit *)commit force:(BOOL)force inRepository:(GTRepository *)repository error:(NSError **)error;

// Convenience initializers
- (id)initWithName:(NSString *)branchName repository:(GTRepository *)repo error:(NSError **)error;
+ (id)branchWithName:(NSString *)branchName repository:(GTRepository *)repo error:(NSError **)error;
+ (id)branchWithReferenceNamed:(NSString *)referenceName inRepository:(GTRepository *)repo error:(NSError **)error;
+ (id)branchWithReference:(GTReference *)ref;

- (id)initWithReference:(GTReference *)ref repository:(GTRepository *)repo;
+ (id)branchWithReference:(GTReference *)ref repository:(GTRepository *)repo;
// Designated initializer
- (id)initWithReference:(GTReference *)ref;

// Get the target commit for this branch
//
// error(out) - will be filled if an error occurs
// error - A pointer which will point to a valid error if the target can't be found.
//
// returns a GTCommit object or nil if an error occurred
// Returns a GTCommit object or nil if an error occurred.
- (GTCommit *)targetCommitAndReturnError:(NSError **)error;

// Count all commits in this branch
//
// error(out) - will be filled if an error occurs
//
// returns number of commits in the branch or NSNotFound if an error occurred
- (NSUInteger)numberOfCommitsWithError:(NSError **)error;

- (NSArray *)uniqueCommitsRelativeToBranch:(GTBranch *)otherBranch error:(NSError **)error;

// Deletes the local branch and nils out the reference.
- (BOOL)deleteWithError:(NSError **)error;

// If the receiver is a local branch, looks up and returns its tracking branch.
// If the receiver is a remote branch, returns self. If no tracking branch was
// found, returns nil and sets `success` to YES.
- (GTBranch *)trackingBranchWithError:(NSError **)error success:(BOOL *)success;
// Renames the branch. Setting `force` to YES to delete another branch with the same name.
- (BOOL)rename:(NSString *)name force:(BOOL)force error:(NSError **)error;

// Reloads the branch's reference and creates a new branch based off that newly
// loaded reference.
Expand All @@ -88,6 +103,37 @@ typedef enum {
// Returns the reloaded branch, or nil if an error occurred.
- (GTBranch *)reloadedBranchWithError:(NSError **)error;

// Fetch the branch's remote tracking branch.
//
// If the receiver is a local branch, looks up and returns its tracking branch.
// If the receiver is a remote branch, returns self.
// If no tracking branch was found, returns nil with a nil error.
//
// error - The error if one occurred.
//
// Returns the tracking branch for the reciever if it's a local branch,
// nil if the receiver is a remote branch but without an error set,
// or nil if there was an error (and the error pointer will be set.
- (GTBranch *)trackingBranchWithError:(NSError **)error;

// Count all commits in this branch
//
// error - will be filled if an error occurs
//
// Returns the number of commits in the receiver or `NSNotFound` if an error occurred
- (NSUInteger)numberOfCommitsWithError:(NSError **)error;

// Get the unique commits between branches.
//
// This method returns an array representing the unique commits
// that exist between the receiver and `otherBranch`.
//
// otherBranch - The branch to compare against.
// error - Will be set if an error occurs.
//
// Returns an array of GTCommits, or nil if an error occurred.
- (NSArray *)uniqueCommitsRelativeToBranch:(GTBranch *)otherBranch error:(NSError **)error;

// Calculate the ahead/behind count from this branch to the given branch.
//
// ahead - The number of commits which are unique to the receiver. Cannot be
Expand Down
Loading