From 618570bb0f89717de7fb3715732b58a8e4052ded Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Thu, 7 Nov 2013 18:36:47 +0100 Subject: [PATCH 01/38] Rewrite tests for GTBlob. --- .../project.pbxproj | 8 +- ObjectiveGitTests/GTBlobSpec.m | 92 ++++++++++++++ ObjectiveGitTests/GTBlobTest.m | 118 ------------------ 3 files changed, 96 insertions(+), 122 deletions(-) create mode 100644 ObjectiveGitTests/GTBlobSpec.m delete mode 100644 ObjectiveGitTests/GTBlobTest.m diff --git a/ObjectiveGitFramework.xcodeproj/project.pbxproj b/ObjectiveGitFramework.xcodeproj/project.pbxproj index a42b5973a..d2f777562 100644 --- a/ObjectiveGitFramework.xcodeproj/project.pbxproj +++ b/ObjectiveGitFramework.xcodeproj/project.pbxproj @@ -139,6 +139,7 @@ 3E0A23E5159E0FDB00A6068F /* GTObjectDatabase.h in Headers */ = {isa = PBXBuildFile; fileRef = 55C8054C13861F34004DCB0F /* GTObjectDatabase.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4D103ADD1819CFAA0029DB24 /* libiconv.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 4D103ADC1819CFAA0029DB24 /* libiconv.dylib */; }; 4D123240178E009E0048F785 /* GTRepositoryCommittingSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D12323F178E009E0048F785 /* GTRepositoryCommittingSpec.m */; }; + 4D1C40D8182C006D00BE2960 /* GTBlobSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D1C40D7182C006D00BE2960 /* GTBlobSpec.m */; }; 4D26799F178DAF31002A2795 /* GTTreeEntry+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 4D26799D178DAF31002A2795 /* GTTreeEntry+Private.h */; settings = {ATTRIBUTES = (Private, ); }; }; 4D79C0EE17DF9F4D00997DE4 /* GTCredential.h in Headers */ = {isa = PBXBuildFile; fileRef = 4D79C0EC17DF9F4D00997DE4 /* GTCredential.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4D79C0EF17DF9F4D00997DE4 /* GTCredential.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D79C0ED17DF9F4D00997DE4 /* GTCredential.m */; }; @@ -199,7 +200,6 @@ 88EB7E4E14AEBA600046FEA4 /* GTConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = 88EB7E4C14AEBA600046FEA4 /* GTConfiguration.m */; }; 88F05A9D16011F6A00B7AD1D /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 88F05A9C16011F6A00B7AD1D /* SenTestingKit.framework */; }; 88F05A9E16011F6E00B7AD1D /* ObjectiveGit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8DC2EF5B0486A6940098B216 /* ObjectiveGit.framework */; }; - 88F05AB316011FFD00B7AD1D /* GTBlobTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 88F05AA216011FFD00B7AD1D /* GTBlobTest.m */; }; 88F05AB416011FFD00B7AD1D /* GTBranchTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 88F05AA316011FFD00B7AD1D /* GTBranchTest.m */; }; 88F05AB516011FFD00B7AD1D /* GTCommitTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 88F05AA416011FFD00B7AD1D /* GTCommitTest.m */; }; 88F05AB916011FFD00B7AD1D /* GTObjectTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 88F05AA816011FFD00B7AD1D /* GTObjectTest.m */; }; @@ -515,6 +515,7 @@ 32DBCF5E0370ADEE00C91783 /* ObjectiveGitFramework_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ObjectiveGitFramework_Prefix.pch; sourceTree = ""; }; 4D103ADC1819CFAA0029DB24 /* libiconv.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libiconv.dylib; path = usr/lib/libiconv.dylib; sourceTree = SDKROOT; }; 4D12323F178E009E0048F785 /* GTRepositoryCommittingSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTRepositoryCommittingSpec.m; sourceTree = ""; }; + 4D1C40D7182C006D00BE2960 /* GTBlobSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTBlobSpec.m; sourceTree = ""; }; 4D26799D178DAF31002A2795 /* GTTreeEntry+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "GTTreeEntry+Private.h"; sourceTree = ""; }; 4D79C0EC17DF9F4D00997DE4 /* GTCredential.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GTCredential.h; sourceTree = ""; }; 4D79C0ED17DF9F4D00997DE4 /* GTCredential.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTCredential.m; sourceTree = ""; }; @@ -566,7 +567,6 @@ 88F05A7916011E5400B7AD1D /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 88F05A7E16011E5400B7AD1D /* ObjectiveGitTests-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "ObjectiveGitTests-Prefix.pch"; sourceTree = ""; }; 88F05A9C16011F6A00B7AD1D /* SenTestingKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SenTestingKit.framework; path = Library/Frameworks/SenTestingKit.framework; sourceTree = DEVELOPER_DIR; }; - 88F05AA216011FFD00B7AD1D /* GTBlobTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTBlobTest.m; sourceTree = ""; }; 88F05AA316011FFD00B7AD1D /* GTBranchTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTBranchTest.m; sourceTree = ""; }; 88F05AA416011FFD00B7AD1D /* GTCommitTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTCommitTest.m; sourceTree = ""; }; 88F05AA816011FFD00B7AD1D /* GTObjectTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTObjectTest.m; sourceTree = ""; }; @@ -821,7 +821,7 @@ isa = PBXGroup; children = ( 88F05A7616011E5400B7AD1D /* Supporting Files */, - 88F05AA216011FFD00B7AD1D /* GTBlobTest.m */, + 4D1C40D7182C006D00BE2960 /* GTBlobSpec.m */, 88A994B916FCE7D400402C7B /* GTBranchSpec.m */, 88F05AA316011FFD00B7AD1D /* GTBranchTest.m */, 88F05AA416011FFD00B7AD1D /* GTCommitTest.m */, @@ -1523,8 +1523,8 @@ files = ( 88F05AC816012CEE00B7AD1D /* NSData+Git.m in Sources */, 88F05AC716012CE500B7AD1D /* NSString+Git.m in Sources */, - 88F05AB316011FFD00B7AD1D /* GTBlobTest.m in Sources */, 88F05AB416011FFD00B7AD1D /* GTBranchTest.m in Sources */, + 4D1C40D8182C006D00BE2960 /* GTBlobSpec.m in Sources */, 88F05AB516011FFD00B7AD1D /* GTCommitTest.m in Sources */, 88F05AB916011FFD00B7AD1D /* GTObjectTest.m in Sources */, 88F05ABA16011FFD00B7AD1D /* GTReferenceTest.m in Sources */, diff --git a/ObjectiveGitTests/GTBlobSpec.m b/ObjectiveGitTests/GTBlobSpec.m new file mode 100644 index 000000000..1344b6bf7 --- /dev/null +++ b/ObjectiveGitTests/GTBlobSpec.m @@ -0,0 +1,92 @@ +// +// GTBlobSpec.m +// ObjectiveGitFramework +// +// Created by Etienne Samson on 2013-11-07. +// Copyright (c) 2013 GitHub, Inc. All rights reserved. +// + +#import "GTBlob.h" + +SpecBegin(GTBlob) + +__block GTRepository *repository; +__block NSString *blobSHA; +__block GTBlob *blob; +__block NSError *error; + +beforeEach(^{ + error = nil; +}); + +describe(@"blob properties can be accessed", ^{ + beforeEach(^{ + repository = self.bareFixtureRepository; + blobSHA = @"fa49b077972391ad58037050f2a75f74e3671e92"; + blob = [repository lookupObjectBySHA:blobSHA objectType:GTObjectTypeBlob error:NULL]; + expect(blob).notTo.beNil(); + }); + + it(@"has a size", ^{ + expect(blob.size).to.equal(9); + }); + + it(@"has content", ^{ + expect(blob.content).to.equal(@"new file\n"); + }); + + it(@"has type", ^{ + expect(blob.type).to.equal(@"blob"); + }); + + it(@"has a SHA", ^{ + expect(blob.SHA).to.equal(blobSHA); + }); +}); + +describe(@"blobs can be created", ^{ + beforeEach(^{ + repository = self.testAppFixtureRepository; + }); + + describe(@"+blobWithString:inRepository:error", ^{ + it(@"works with valid parameters", ^{ + blob = [GTBlob blobWithString:@"a new blob content" inRepository:repository error:&error]; + expect(error).to.beNil(); + expect(blob).notTo.beNil(); + expect(blob.SHA).notTo.beNil(); + }); + }); + + describe(@"+blobWithData:inRepository:error", ^{ + it(@"works with valid parameters", ^{ + char bytes[] = "100644 example_helper.rb\00\xD3\xD5\xED\x9D A4_\x00 40000 examples"; + NSData *content = [NSData dataWithBytes:bytes length:sizeof(bytes)]; + + blob = [GTBlob blobWithData:content inRepository:repository error:&error]; + expect(error).to.beNil(); + expect(blob).notTo.beNil(); + expect(blob.SHA).notTo.beNil(); + }); + }); + + describe(@"+blobWithFile:inRepository:error", ^{ + it(@"works with valid parameters", ^{ + NSString *fileContent = @"Test contents\n"; + NSString *fileName = @"myfile.txt"; + NSURL *fileURL = [repository.fileURL URLByAppendingPathComponent:fileName]; + + BOOL success = [fileContent writeToURL:fileURL atomically:YES encoding:NSUTF8StringEncoding error:&error]; + expect(success).to.beTruthy(); + expect(error).to.beNil(); + + blob = [GTBlob blobWithFile:fileURL inRepository:repository error:&error]; + expect(error).to.beNil(); + expect(blob).notTo.beNil(); + expect(blob.SHA).notTo.beNil(); + expect(blob.content).to.equal(fileContent); + }); + }); +}); + +SpecEnd diff --git a/ObjectiveGitTests/GTBlobTest.m b/ObjectiveGitTests/GTBlobTest.m deleted file mode 100644 index 69de7b34e..000000000 --- a/ObjectiveGitTests/GTBlobTest.m +++ /dev/null @@ -1,118 +0,0 @@ -// -// GTBlobTest.m -// ObjectiveGitFramework -// -// Created by Timothy Clem on 2/25/11. -// -// The MIT License -// -// Copyright (c) 2011 Tim Clem -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// - -@interface GTBlobTest : GTTestCase { - - GTRepository *repo; - NSString *blobSHA; -} -@end - -@implementation GTBlobTest - -- (void)setUp { - repo = self.bareFixtureRepository; - blobSHA = @"fa49b077972391ad58037050f2a75f74e3671e92"; -} - -- (void)testCanReadBlobData { - NSError *error = nil; - GTBlob *blob = [repo lookupObjectBySHA:blobSHA error:&error]; - STAssertEquals(9, (int)blob.size, nil); - STAssertEqualObjects(@"new file\n", blob.content, nil); - STAssertEqualObjects(@"blob", blob.type, nil); - STAssertEqualObjects(blobSHA, blob.SHA, nil); -} - -// todo -/* -- (void)testCanRewriteBlobData { - - NSError *error = nil; - GTBlob *blob = (GTBlob *)[repo lookupBySha:sha error:&error]; - blob.content = @"my new content"; - STAssertEqualObjects(sha, blob.sha, nil); - - NSString *newSha = [blob writeAndReturnError:&error]; - - STAssertNil(error, [error localizedDescription]); - STAssertEqualObjects(@"2dd916ea1ff086d61fbc1c286079305ffad4e92e", blob.sha, nil); - STAssertEqualObjects(@"2dd916ea1ff086d61fbc1c286079305ffad4e92e", newSha, nil); - rm_loose(blob.sha); -} -*/ - -- (void)testCanWriteNewBlobData { - - NSError *error = nil; - GTBlob *blob = [GTBlob blobWithString:@"a new blob content" inRepository:repo error:&error]; - NSString *newSHA = [blob SHA]; - STAssertNotNil(newSHA, [error localizedDescription]); -} - -- (void)testCanWriteNewBlobData2 { - - NSError *error = nil; - GTBlob *blob = [GTBlob blobWithString:@"a new blob content" inRepository:repo error:&error]; - STAssertNotNil(blob, [error localizedDescription]); -} - -//- (void)testCanGetCompleteContentWithNulls { -// -// NSError *error = nil; -// char bytes[] = "100644 example_helper.rb\00\xD3\xD5\xED\x9D A4_\x00 40000 examples"; -// NSData *content = [NSData dataWithBytes:bytes length:sizeof(bytes)]; -// -// GTBlob *blob = [GTBlob blobWithData:content inRepository:repo error:&error]; -// NSString *newSha = [blob sha]; -// STAssertNotNil(newSha, [error localizedDescription]); -// -// rm_loose(self.class, newSha); -// -// //todo -// /*GTRawObject *obj = [GTRawObject rawObjectWithType:GTObjectTypeBlob data:content]; -// NSString *newSha = [repo write:obj error:&error]; -// -// STAssertNil(error, [error localizedDescription]); -// STAssertNotNil(newSha, nil); -// GTBlob *blob = (GTBlob *)[repo lookupBySha:newSha error:&error]; -// GTRawObject *newObj = [blob readRawAndReturnError:&error]; -// STAssertNil(error, [error localizedDescription]); -// NSLog(@"original content = %@", [obj data]); -// NSLog(@"lookup content = %@", [newObj data]); -// STAssertEqualObjects(newObj.data, obj.data, nil); -// rm_loose(newSha);*/ -//} - -// todo -//- (void)testCanCreateBlobFromFile { -// -//} - -@end From ed0a2a80e4098b83284bb129c8a357a7e1265872 Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Thu, 7 Nov 2013 18:38:13 +0100 Subject: [PATCH 02/38] Use `git_blob_create_fromdisk` instead of going through the `fromworkdir` version. Because I don't want to handle the pain of relativizing the passed URL. --- Classes/GTBlob.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/GTBlob.m b/Classes/GTBlob.m index e65b11b91..4bd5ff1cf 100644 --- a/Classes/GTBlob.m +++ b/Classes/GTBlob.m @@ -87,7 +87,7 @@ - (id)initWithData:(NSData *)data inRepository:(GTRepository *)repository error: - (id)initWithFile:(NSURL *)file inRepository:(GTRepository *)repository error:(NSError **)error { 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"]; From b7f671f431798324aebb7c72c8884bde058a3c16 Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Thu, 7 Nov 2013 18:39:48 +0100 Subject: [PATCH 03/38] Asserts. --- Classes/GTBlob.m | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Classes/GTBlob.m b/Classes/GTBlob.m index 4bd5ff1cf..c522e8be8 100644 --- a/Classes/GTBlob.m +++ b/Classes/GTBlob.m @@ -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) { @@ -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) { @@ -86,6 +92,9 @@ - (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_fromdisk(&oid, repository.git_repository, [[file path] fileSystemRepresentation]); if(gitError < GIT_OK) { From 709c2b31e00fbeec9eb39fe2ee2689c0a3f3a7c5 Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Thu, 7 Nov 2013 19:39:57 +0100 Subject: [PATCH 04/38] Move the contents of `GTBranchTest` where they belong. --- ObjectiveGitTests/GTBranchSpec.m | 78 ++++++++++++++++++++++++++++ ObjectiveGitTests/GTBranchTest.m | 60 --------------------- ObjectiveGitTests/GTRepositorySpec.m | 29 +++++++++++ 3 files changed, 107 insertions(+), 60 deletions(-) diff --git a/ObjectiveGitTests/GTBranchSpec.m b/ObjectiveGitTests/GTBranchSpec.m index 7b1e30e0f..ed8c0a318 100644 --- a/ObjectiveGitTests/GTBranchSpec.m +++ b/ObjectiveGitTests/GTBranchSpec.m @@ -127,4 +127,82 @@ }); }); +describe(@"-numberOfCommitsWithError:", ^{ + it(@"should return the count of commits in the branch", ^{ + NSError *error = nil; + NSUInteger commitCount = [masterBranch numberOfCommitsWithError:&error]; + expect(commitCount).to.equal(164); + }); +}); + +describe(@"-trackingBranchWithError:success:", ^{ + it(@"should return the tracking branch for a local branch that tracks a remote branch", ^{ + NSError *error = nil; + GTBranch *masterBranch = [GTBranch branchWithName:@"refs/heads/master" repository:repository error:&error]; + expect(masterBranch).notTo.beNil(); + expect(error).to.beNil(); + + BOOL success = NO; + GTBranch *trackingBranch = [masterBranch trackingBranchWithError:&error success:&success]; + expect(trackingBranch).notTo.beNil(); + expect(success).to.beTruthy(); + }); + + it(@"should return nil for a local branch that doesn't track a remote branch", ^{ + NSError *error = nil; + GTReference *otherRef = [GTReference referenceByCreatingReferenceNamed:@"refs/heads/yet-another-branch" fromReferenceTarget:@"6b0c1c8b8816416089c534e474f4c692a76ac14f" inRepository:repository error:&error]; + expect(otherRef).notTo.beNil(); + expect(error).to.beNil(); + + GTBranch *otherBranch = [GTBranch branchWithReference:otherRef repository:repository]; + expect(otherBranch).notTo.beNil(); + expect(error).to.beNil(); + + BOOL success = NO; + trackingBranch = [otherBranch trackingBranchWithError:&error success:&success]; + expect(trackingBranch).to.beNil(); + expect(success).to.beTruthy(); + }); + + it(@"should return itself for a remote branch", ^{ + NSError *error = nil; + GTReference *remoteRef = [GTReference referenceByLookingUpReferencedNamed:@"refs/remotes/origin/master" inRepository:repository error:&error]; + expect(remoteRef).notTo.beNil(); + expect(error).to.beNil(); + + GTBranch *remoteBranch = [GTBranch branchWithReference:remoteRef repository:repository]; + expect(remoteBranch).notTo.beNil(); + + BOOL success = NO; + GTBranch *remoteTrackingBranch = [remoteBranch trackingBranchWithError:&error success:&success]; + expect(remoteTrackingBranch).to.equal(remoteBranch); + expect(success).to.beTruthy(); + }); +}); + +// TODO: Test branch renaming, branch upstream +/* + - (void)testCanRenameBranch { + + NSError *error = nil; + GTRepository *repo = [GTRepository repoByOpeningRepositoryInDirectory:[NSURL URLWithString:TEST_REPO_PATH()] error:&error]; + STAssertNil(error, [error localizedDescription]); + + NSArray *branches = [GTBranch listAllLocalBranchesInRepository:repo error:&error]; + STAssertNotNil(branches, [error localizedDescription], nil); + STAssertEquals(2, (int)branches.count, nil); + + NSString *newBranchName = [NSString stringWithFormat:@"%@%@", [GTBranch localNamePrefix], @"this_is_the_renamed_branch"]; + GTBranch *firstBranch = [branches objectAtIndex:0]; + NSString *originalBranchName = firstBranch.name; + BOOL success = [firstBranch.reference setName:newBranchName error:&error]; + STAssertTrue(success, [error localizedDescription]); + STAssertEqualObjects(firstBranch.name, newBranchName, nil); + + success = [firstBranch.reference setName:originalBranchName error:&error]; + STAssertTrue(success, [error localizedDescription]); + STAssertEqualObjects(firstBranch.name, originalBranchName, nil); + } + */ + SpecEnd diff --git a/ObjectiveGitTests/GTBranchTest.m b/ObjectiveGitTests/GTBranchTest.m index 83252e65a..4f9ff2077 100644 --- a/ObjectiveGitTests/GTBranchTest.m +++ b/ObjectiveGitTests/GTBranchTest.m @@ -18,42 +18,6 @@ - (void)setUp { repo = self.bareFixtureRepository; } -- (void)testCanOpenHeadInRepo { - - NSError *error = nil; - GTBranch *current = [repo currentBranchWithError:&error]; - STAssertNil(error, [error localizedDescription]); - STAssertNotNil(current, nil); -} - -- (void)testCanListLocalBranchesInRepo { - - NSError *error = nil; - NSArray *branches = [repo localBranchesWithError:&error]; - STAssertNotNil(branches, [error localizedDescription], nil); - STAssertEquals(2, (int)branches.count, nil); -} - -- (void)testCanListRemoteBranchesInRepo { - - NSError *error = nil; - NSArray *branches = [repo remoteBranchesWithError:&error]; - STAssertNotNil(branches, [error localizedDescription], nil); - STAssertEquals(0, (int)branches.count, nil); -} - -- (void)testCanCountCommitsInBranch { - - NSError *error = nil; - GTReference *head = [repo headReferenceWithError:&error]; - STAssertNotNil(head, [error localizedDescription]); - GTBranch *master = [GTBranch branchWithReference:head repository:repo]; - STAssertNotNil(master, [error localizedDescription]); - - NSUInteger n = [master numberOfCommitsWithError:&error]; - STAssertEquals((NSUInteger)3, n, nil); -} - - (void)testRetainOfBranchCreatedWithRef { // Hard to test the autoreleasepool, so manually alloc/init instead. @@ -69,28 +33,4 @@ - (void)testRetainOfBranchCreatedWithRef { STAssertNotNil(current.reference, nil); } -/* -- (void)testCanRenameBranch { - - NSError *error = nil; - GTRepository *repo = [GTRepository repoByOpeningRepositoryInDirectory:[NSURL URLWithString:TEST_REPO_PATH()] error:&error]; - STAssertNil(error, [error localizedDescription]); - - NSArray *branches = [GTBranch listAllLocalBranchesInRepository:repo error:&error]; - STAssertNotNil(branches, [error localizedDescription], nil); - STAssertEquals(2, (int)branches.count, nil); - - NSString *newBranchName = [NSString stringWithFormat:@"%@%@", [GTBranch localNamePrefix], @"this_is_the_renamed_branch"]; - GTBranch *firstBranch = [branches objectAtIndex:0]; - NSString *originalBranchName = firstBranch.name; - BOOL success = [firstBranch.reference setName:newBranchName error:&error]; - STAssertTrue(success, [error localizedDescription]); - STAssertEqualObjects(firstBranch.name, newBranchName, nil); - - success = [firstBranch.reference setName:originalBranchName error:&error]; - STAssertTrue(success, [error localizedDescription]); - STAssertEqualObjects(firstBranch.name, originalBranchName, nil); -} - */ - @end diff --git a/ObjectiveGitTests/GTRepositorySpec.m b/ObjectiveGitTests/GTRepositorySpec.m index f430d147f..ff49f2717 100644 --- a/ObjectiveGitTests/GTRepositorySpec.m +++ b/ObjectiveGitTests/GTRepositorySpec.m @@ -87,6 +87,35 @@ }); }); +describe(@"-currentBranchWithError:", ^{ + it(@"should return the current branch", ^{ + NSError *error = nil; + GTBranch *currentBranch = [repository currentBranchWithError:&error]; + expect(currentBranch).notTo.beNil(); + expect(error).to.beNil(); + }); +}); + +describe(@"-localBranchesWithError:", ^{ + it(@"should return the local branches", ^{ + NSError *error = nil; + NSArray *branches = [repository localBranchesWithError:&error]; + expect(branches).notTo.beNil(); + expect(error).to.beNil(); + expect(branches.count).to.equal(13); + }); +}); + +describe(@"-remoteBranchesWithError:", ^{ + it(@"should return remote branches", ^{ + NSError *error = nil; + NSArray *branches = [repository remoteBranchesWithError:&error]; + expect(branches).notTo.beNil(); + expect(error).to.beNil(); + expect(branches.count).to.equal(1); + }); +}); + describe(@"-OIDByCreatingTagNamed:target:tagger:message:error", ^{ it(@"should create a new tag",^{ NSError *error = nil; From 9e69d7c90933877d27cb1c9718e201e2d71361db Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Thu, 7 Nov 2013 19:40:51 +0100 Subject: [PATCH 05/38] Remove `GTBranchTest`. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I know there's still a test in here, but I'm not sure what it's testing since we're ARC now… --- .../project.pbxproj | 4 --- ObjectiveGitTests/GTBranchTest.m | 36 ------------------- 2 files changed, 40 deletions(-) delete mode 100644 ObjectiveGitTests/GTBranchTest.m diff --git a/ObjectiveGitFramework.xcodeproj/project.pbxproj b/ObjectiveGitFramework.xcodeproj/project.pbxproj index d2f777562..bd596d4e5 100644 --- a/ObjectiveGitFramework.xcodeproj/project.pbxproj +++ b/ObjectiveGitFramework.xcodeproj/project.pbxproj @@ -200,7 +200,6 @@ 88EB7E4E14AEBA600046FEA4 /* GTConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = 88EB7E4C14AEBA600046FEA4 /* GTConfiguration.m */; }; 88F05A9D16011F6A00B7AD1D /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 88F05A9C16011F6A00B7AD1D /* SenTestingKit.framework */; }; 88F05A9E16011F6E00B7AD1D /* ObjectiveGit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8DC2EF5B0486A6940098B216 /* ObjectiveGit.framework */; }; - 88F05AB416011FFD00B7AD1D /* GTBranchTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 88F05AA316011FFD00B7AD1D /* GTBranchTest.m */; }; 88F05AB516011FFD00B7AD1D /* GTCommitTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 88F05AA416011FFD00B7AD1D /* GTCommitTest.m */; }; 88F05AB916011FFD00B7AD1D /* GTObjectTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 88F05AA816011FFD00B7AD1D /* GTObjectTest.m */; }; 88F05ABA16011FFD00B7AD1D /* GTReferenceTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 88F05AA916011FFD00B7AD1D /* GTReferenceTest.m */; }; @@ -567,7 +566,6 @@ 88F05A7916011E5400B7AD1D /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 88F05A7E16011E5400B7AD1D /* ObjectiveGitTests-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "ObjectiveGitTests-Prefix.pch"; sourceTree = ""; }; 88F05A9C16011F6A00B7AD1D /* SenTestingKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SenTestingKit.framework; path = Library/Frameworks/SenTestingKit.framework; sourceTree = DEVELOPER_DIR; }; - 88F05AA316011FFD00B7AD1D /* GTBranchTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTBranchTest.m; sourceTree = ""; }; 88F05AA416011FFD00B7AD1D /* GTCommitTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTCommitTest.m; sourceTree = ""; }; 88F05AA816011FFD00B7AD1D /* GTObjectTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTObjectTest.m; sourceTree = ""; }; 88F05AA916011FFD00B7AD1D /* GTReferenceTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTReferenceTest.m; sourceTree = ""; }; @@ -823,7 +821,6 @@ 88F05A7616011E5400B7AD1D /* Supporting Files */, 4D1C40D7182C006D00BE2960 /* GTBlobSpec.m */, 88A994B916FCE7D400402C7B /* GTBranchSpec.m */, - 88F05AA316011FFD00B7AD1D /* GTBranchTest.m */, 88F05AA416011FFD00B7AD1D /* GTCommitTest.m */, 88C0BC5817038CF3009E99AA /* GTConfigurationSpec.m */, 30865A90167F503400B1AB6E /* GTDiffSpec.m */, @@ -1523,7 +1520,6 @@ files = ( 88F05AC816012CEE00B7AD1D /* NSData+Git.m in Sources */, 88F05AC716012CE500B7AD1D /* NSString+Git.m in Sources */, - 88F05AB416011FFD00B7AD1D /* GTBranchTest.m in Sources */, 4D1C40D8182C006D00BE2960 /* GTBlobSpec.m in Sources */, 88F05AB516011FFD00B7AD1D /* GTCommitTest.m in Sources */, 88F05AB916011FFD00B7AD1D /* GTObjectTest.m in Sources */, diff --git a/ObjectiveGitTests/GTBranchTest.m b/ObjectiveGitTests/GTBranchTest.m deleted file mode 100644 index 4f9ff2077..000000000 --- a/ObjectiveGitTests/GTBranchTest.m +++ /dev/null @@ -1,36 +0,0 @@ -// -// GTBranchTest.m -// ObjectiveGitFramework -// -// Created by Timothy Clem on 3/10/11. -// Copyright 2011 GitHub, Inc. All rights reserved. -// - -@interface GTBranchTest : GTTestCase { - - GTRepository *repo; -} -@end - -@implementation GTBranchTest - -- (void)setUp { - repo = self.bareFixtureRepository; -} - -- (void)testRetainOfBranchCreatedWithRef { - - // Hard to test the autoreleasepool, so manually alloc/init instead. - // This allows us to release the object and test that the branch - // is retaining properly. - NSError *error = nil; - GTReference *head = [[GTReference alloc] initByLookingUpReferenceNamed:@"HEAD" inRepository:repo error:&error]; - STAssertNotNil(head, [error localizedDescription]); - GTBranch *current = [GTBranch branchWithReference:head repository:repo]; - STAssertNotNil(current, [error localizedDescription]); - - - STAssertNotNil(current.reference, nil); -} - -@end From 04fd3e714844b14c9f9e5bc2c5b8d9b244c85993 Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Thu, 7 Nov 2013 19:56:50 +0100 Subject: [PATCH 06/38] Convert `GTCommitTest` to Expecta. --- .../project.pbxproj | 8 +- ObjectiveGitTests/GTCommitSpec.m | 65 ++++++++++++++ ObjectiveGitTests/GTCommitTest.m | 89 ------------------- 3 files changed, 69 insertions(+), 93 deletions(-) create mode 100644 ObjectiveGitTests/GTCommitSpec.m delete mode 100644 ObjectiveGitTests/GTCommitTest.m diff --git a/ObjectiveGitFramework.xcodeproj/project.pbxproj b/ObjectiveGitFramework.xcodeproj/project.pbxproj index bd596d4e5..a5e002075 100644 --- a/ObjectiveGitFramework.xcodeproj/project.pbxproj +++ b/ObjectiveGitFramework.xcodeproj/project.pbxproj @@ -200,7 +200,7 @@ 88EB7E4E14AEBA600046FEA4 /* GTConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = 88EB7E4C14AEBA600046FEA4 /* GTConfiguration.m */; }; 88F05A9D16011F6A00B7AD1D /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 88F05A9C16011F6A00B7AD1D /* SenTestingKit.framework */; }; 88F05A9E16011F6E00B7AD1D /* ObjectiveGit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8DC2EF5B0486A6940098B216 /* ObjectiveGit.framework */; }; - 88F05AB516011FFD00B7AD1D /* GTCommitTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 88F05AA416011FFD00B7AD1D /* GTCommitTest.m */; }; + 88F05AB516011FFD00B7AD1D /* GTCommitSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 88F05AA416011FFD00B7AD1D /* GTCommitSpec.m */; }; 88F05AB916011FFD00B7AD1D /* GTObjectTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 88F05AA816011FFD00B7AD1D /* GTObjectTest.m */; }; 88F05ABA16011FFD00B7AD1D /* GTReferenceTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 88F05AA916011FFD00B7AD1D /* GTReferenceTest.m */; }; 88F05ABC16011FFD00B7AD1D /* GTRepositoryTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 88F05AAB16011FFD00B7AD1D /* GTRepositoryTest.m */; }; @@ -566,7 +566,7 @@ 88F05A7916011E5400B7AD1D /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 88F05A7E16011E5400B7AD1D /* ObjectiveGitTests-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "ObjectiveGitTests-Prefix.pch"; sourceTree = ""; }; 88F05A9C16011F6A00B7AD1D /* SenTestingKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SenTestingKit.framework; path = Library/Frameworks/SenTestingKit.framework; sourceTree = DEVELOPER_DIR; }; - 88F05AA416011FFD00B7AD1D /* GTCommitTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTCommitTest.m; sourceTree = ""; }; + 88F05AA416011FFD00B7AD1D /* GTCommitSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTCommitSpec.m; sourceTree = ""; }; 88F05AA816011FFD00B7AD1D /* GTObjectTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTObjectTest.m; sourceTree = ""; }; 88F05AA916011FFD00B7AD1D /* GTReferenceTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTReferenceTest.m; sourceTree = ""; }; 88F05AAB16011FFD00B7AD1D /* GTRepositoryTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTRepositoryTest.m; sourceTree = ""; }; @@ -821,7 +821,7 @@ 88F05A7616011E5400B7AD1D /* Supporting Files */, 4D1C40D7182C006D00BE2960 /* GTBlobSpec.m */, 88A994B916FCE7D400402C7B /* GTBranchSpec.m */, - 88F05AA416011FFD00B7AD1D /* GTCommitTest.m */, + 88F05AA416011FFD00B7AD1D /* GTCommitSpec.m */, 88C0BC5817038CF3009E99AA /* GTConfigurationSpec.m */, 30865A90167F503400B1AB6E /* GTDiffSpec.m */, D06D9E001755D10000558C17 /* GTEnumeratorSpec.m */, @@ -1521,7 +1521,7 @@ 88F05AC816012CEE00B7AD1D /* NSData+Git.m in Sources */, 88F05AC716012CE500B7AD1D /* NSString+Git.m in Sources */, 4D1C40D8182C006D00BE2960 /* GTBlobSpec.m in Sources */, - 88F05AB516011FFD00B7AD1D /* GTCommitTest.m in Sources */, + 88F05AB516011FFD00B7AD1D /* GTCommitSpec.m in Sources */, 88F05AB916011FFD00B7AD1D /* GTObjectTest.m in Sources */, 88F05ABA16011FFD00B7AD1D /* GTReferenceTest.m in Sources */, 88F05ABC16011FFD00B7AD1D /* GTRepositoryTest.m in Sources */, diff --git a/ObjectiveGitTests/GTCommitSpec.m b/ObjectiveGitTests/GTCommitSpec.m new file mode 100644 index 000000000..81013008e --- /dev/null +++ b/ObjectiveGitTests/GTCommitSpec.m @@ -0,0 +1,65 @@ +// +// GTCommitSpec.m +// ObjectiveGitFramework +// +// Created by Etienne Samson on 2013-11-07. +// Copyright (c) 2013 GitHub, Inc. All rights reserved. +// + +#import "GTCommit.h" + +SpecBegin(GTCommit) + +__block GTRepository *repository; +__block NSError *error; + +beforeEach(^{ + repository = self.bareFixtureRepository; + error = nil; +}); + +it(@"can read commit data", ^{ + NSString *commitSHA = @"8496071c1b46c854b31185ea97743be6a8774479"; + GTCommit *commit = [repository lookupObjectBySHA:commitSHA error:&error]; + + expect(commit).notTo.beNil(); + expect(error).to.beNil(); + + expect(commit).to.beInstanceOf([GTCommit class]); + expect(commit.type).to.equal(@"commit"); + expect(commit.SHA).to.equal(commitSHA); + + expect(commit.message).to.equal(@"testing\n"); + expect(commit.messageSummary).to.equal(@"testing"); + expect(commit.messageDetails).to.equal(@""); + expect(commit.commitDate).to.equal([NSDate dateWithTimeIntervalSince1970:1273360386]); + +// STAssertEquals((int)[commit.commitDate timeIntervalSince1970], 1273360386, nil); + + GTSignature *author = commit.author; + expect(author).notTo.beNil(); + expect(author.name).to.equal(@"Scott Chacon"); + expect(author.email).to.equal(@"schacon@gmail.com"); + expect(author.time).to.equal([NSDate dateWithTimeIntervalSince1970:1273360386]); +// STAssertEquals((int)[author.time timeIntervalSince1970], 1273360386, nil); + + GTSignature *committer = commit.committer; + expect(committer).notTo.beNil(); + expect(committer.name).to.equal(@"Scott Chacon"); + expect(committer.email).to.equal(@"schacon@gmail.com"); + expect(committer.time).to.equal([NSDate dateWithTimeIntervalSince1970:1273360386]); + + expect(commit.tree.SHA).to.equal(@"181037049a54a1eb5fab404658a3a250b44335d7"); + expect(commit.parents.count).to.equal(0); +}); + +it(@"canHaveMultipleParents", ^{ + NSString *commitSHA = @"a4a7dce85cf63874e984719f4fdd239f5145052f"; + GTCommit *commit = [repository lookupObjectBySHA:commitSHA error:&error]; + expect(commit).notTo.beNil(); + expect(error).to.beNil(); + + expect(commit.parents.count).to.equal(2); +}); + +SpecEnd diff --git a/ObjectiveGitTests/GTCommitTest.m b/ObjectiveGitTests/GTCommitTest.m deleted file mode 100644 index e872ba4ac..000000000 --- a/ObjectiveGitTests/GTCommitTest.m +++ /dev/null @@ -1,89 +0,0 @@ -// -// GTCommitTest.m -// ObjectiveGitFramework -// -// Created by Timothy Clem on 2/22/11. -// -// The MIT License -// -// Copyright (c) 2011 Tim Clem -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// - -@interface GTCommitTest : GTTestCase { - - GTRepository *repo; -} -@end - -@implementation GTCommitTest - - -- (void)setUp { - repo = self.bareFixtureRepository; - STAssertNotNil(repo, @"Could not create fixture repository."); -} - -- (void)testCanReadCommitData { - - NSString *commitSHA = @"8496071c1b46c854b31185ea97743be6a8774479"; - NSError *error = nil; - GTObject *obj = [repo lookupObjectBySHA:commitSHA error:&error]; - - STAssertNil(error, [error localizedDescription]); - STAssertNotNil(obj, nil); - STAssertTrue([obj isKindOfClass:[GTCommit class]], nil); - STAssertEqualObjects(obj.type, @"commit", nil); - STAssertEqualObjects(obj.SHA, commitSHA, nil); - - GTCommit *commit = (GTCommit *)obj; - STAssertEqualObjects(commit.message, @"testing\n", nil); - STAssertEqualObjects(commit.messageSummary, @"testing", nil); - STAssertEqualObjects(commit.messageDetails, @"", nil); - STAssertEquals((int)[commit.commitDate timeIntervalSince1970], 1273360386, nil); - - GTSignature *author = commit.author; - STAssertEqualObjects(author.name, @"Scott Chacon", nil); - STAssertEqualObjects(author.email, @"schacon@gmail.com", nil); - STAssertEquals((int)[author.time timeIntervalSince1970], 1273360386, nil); - - GTSignature *committer = commit.committer; - STAssertEqualObjects(committer.name, @"Scott Chacon", nil); - STAssertEqualObjects(committer.email, @"schacon@gmail.com", nil); - STAssertEquals((int)[committer.time timeIntervalSince1970], 1273360386, nil); - - STAssertEqualObjects(commit.tree.SHA, @"181037049a54a1eb5fab404658a3a250b44335d7", nil); - STAssertTrue([commit.parents count] == 0, nil); -} - -- (void)testCanHaveMultipleParents { - - NSString *commitSHA = @"a4a7dce85cf63874e984719f4fdd239f5145052f"; - NSError *error = nil; - GTObject *obj = [repo lookupObjectBySHA:commitSHA error:&error]; - - STAssertNil(error, [error localizedDescription]); - STAssertNotNil(obj, nil); - - GTCommit *commit = (GTCommit *)obj; - STAssertTrue([commit.parents count] == 2, nil); -} - -@end From f578c4c6f4deea223bb03339c1da2d584d35a033 Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Thu, 7 Nov 2013 20:47:31 +0100 Subject: [PATCH 07/38] Convert `GTReferenceTest`. --- .../project.pbxproj | 4 - ObjectiveGitTests/GTReferenceSpec.m | 65 ++++++++++++++ ObjectiveGitTests/GTReferenceTest.m | 90 ------------------- ObjectiveGitTests/GTRepositorySpec.m | 15 ++++ 4 files changed, 80 insertions(+), 94 deletions(-) delete mode 100644 ObjectiveGitTests/GTReferenceTest.m diff --git a/ObjectiveGitFramework.xcodeproj/project.pbxproj b/ObjectiveGitFramework.xcodeproj/project.pbxproj index a5e002075..437c5cda8 100644 --- a/ObjectiveGitFramework.xcodeproj/project.pbxproj +++ b/ObjectiveGitFramework.xcodeproj/project.pbxproj @@ -202,7 +202,6 @@ 88F05A9E16011F6E00B7AD1D /* ObjectiveGit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8DC2EF5B0486A6940098B216 /* ObjectiveGit.framework */; }; 88F05AB516011FFD00B7AD1D /* GTCommitSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 88F05AA416011FFD00B7AD1D /* GTCommitSpec.m */; }; 88F05AB916011FFD00B7AD1D /* GTObjectTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 88F05AA816011FFD00B7AD1D /* GTObjectTest.m */; }; - 88F05ABA16011FFD00B7AD1D /* GTReferenceTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 88F05AA916011FFD00B7AD1D /* GTReferenceTest.m */; }; 88F05ABC16011FFD00B7AD1D /* GTRepositoryTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 88F05AAB16011FFD00B7AD1D /* GTRepositoryTest.m */; }; 88F05AC41601204200B7AD1D /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 88F05A7816011E5400B7AD1D /* InfoPlist.strings */; }; 88F05AC61601209A00B7AD1D /* ObjectiveGit.m in Sources */ = {isa = PBXBuildFile; fileRef = 88F05AC51601209A00B7AD1D /* ObjectiveGit.m */; }; @@ -568,7 +567,6 @@ 88F05A9C16011F6A00B7AD1D /* SenTestingKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SenTestingKit.framework; path = Library/Frameworks/SenTestingKit.framework; sourceTree = DEVELOPER_DIR; }; 88F05AA416011FFD00B7AD1D /* GTCommitSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTCommitSpec.m; sourceTree = ""; }; 88F05AA816011FFD00B7AD1D /* GTObjectTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTObjectTest.m; sourceTree = ""; }; - 88F05AA916011FFD00B7AD1D /* GTReferenceTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTReferenceTest.m; sourceTree = ""; }; 88F05AAB16011FFD00B7AD1D /* GTRepositoryTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTRepositoryTest.m; sourceTree = ""; }; 88F05AAF16011FFD00B7AD1D /* ObjectiveGitTests-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "ObjectiveGitTests-Info.plist"; sourceTree = ""; }; 88F05AC51601209A00B7AD1D /* ObjectiveGit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ObjectiveGit.m; path = Classes/ObjectiveGit.m; sourceTree = ""; }; @@ -828,7 +826,6 @@ 8832811E173D8816006D7DCF /* GTIndexSpec.m */, 88F05AA816011FFD00B7AD1D /* GTObjectTest.m */, D00F6815175D373C004DB9D6 /* GTReferenceSpec.m */, - 88F05AA916011FFD00B7AD1D /* GTReferenceTest.m */, 88215482171499BE00D76B76 /* GTReflogSpec.m */, D0AC906B172F941F00347DC4 /* GTRepositorySpec.m */, F6ED8DA0180E713200A32D40 /* GTRemoteSpec.m */, @@ -1523,7 +1520,6 @@ 4D1C40D8182C006D00BE2960 /* GTBlobSpec.m in Sources */, 88F05AB516011FFD00B7AD1D /* GTCommitSpec.m in Sources */, 88F05AB916011FFD00B7AD1D /* GTObjectTest.m in Sources */, - 88F05ABA16011FFD00B7AD1D /* GTReferenceTest.m in Sources */, 88F05ABC16011FFD00B7AD1D /* GTRepositoryTest.m in Sources */, 30865A91167F503400B1AB6E /* GTDiffSpec.m in Sources */, 88A994BA16FCE7D400402C7B /* GTBranchSpec.m in Sources */, diff --git a/ObjectiveGitTests/GTReferenceSpec.m b/ObjectiveGitTests/GTReferenceSpec.m index 6c29d2ad5..ad6a52bcb 100644 --- a/ObjectiveGitTests/GTReferenceSpec.m +++ b/ObjectiveGitTests/GTReferenceSpec.m @@ -107,4 +107,69 @@ }); }); +__block GTRepository *bareRepository; +__block NSError *error; +__block void (^isValidReference)(GTReference *ref, NSString *SHA, GTReferenceType type, NSString *name); + +beforeEach(^{ + bareRepository = self.bareFixtureRepository; + error = nil; + isValidReference = ^(GTReference *ref, NSString *SHA, GTReferenceType type, NSString *name) { + expect(ref).notTo.beNil(); + expect(ref.targetSHA).to.equal(SHA); + expect(ref.referenceType).to.equal(type); + expect(ref.name).to.equal(name); + }; +}); + +describe(@"+referenceByLookingUpReferenceNamed:inRepository:error:", ^{ + it(@"should return a valid reference to a branch", ^{ + GTReference *ref = [GTReference referenceByLookingUpReferencedNamed:@"refs/heads/master" inRepository:bareRepository error:&error]; + expect(ref).notTo.beNil(); + expect(error).to.beNil(); + + isValidReference(ref, @"36060c58702ed4c2a40832c51758d5344201d89a", GTReferenceTypeOid, @"refs/heads/master"); + }); + + it(@"should return a valid reference to a tag", ^{ + GTReference *ref = [GTReference referenceByLookingUpReferencedNamed:@"refs/tags/v0.9" inRepository:bareRepository error:&error]; + expect(ref).notTo.beNil(); + expect(error).to.beNil(); + + isValidReference(ref, @"5b5b025afb0b4c913b4c338a42934a3863bf3644", GTReferenceTypeOid, @"refs/tags/v0.9"); + }); +}); + +describe(@"+referenceByCreatingReferenceNamed:fromReferenceTarget:inRepository:error:", ^{ + it(@"can create a reference from a symbolic reference", ^{ + GTReference *ref = [GTReference referenceByCreatingReferenceNamed:@"refs/heads/unit_test" fromReferenceTarget:@"refs/heads/master" inRepository:bareRepository error:&error]; + expect(error).to.beNil(); + expect(ref).notTo.beNil(); + + isValidReference(ref, @"36060c58702ed4c2a40832c51758d5344201d89a", GTReferenceTypeSymbolic, @"refs/heads/unit_test"); + expect(ref.resolvedReference.name).to.equal(@"refs/heads/master"); + }); + + it(@"can create a reference from an SHA/OID", ^{ + GTReference *ref = [GTReference referenceByCreatingReferenceNamed:@"refs/heads/unit_test" fromReferenceTarget:@"36060c58702ed4c2a40832c51758d5344201d89a" inRepository:bareRepository error:&error]; + expect(error).to.beNil(); + expect(ref).notTo.beNil(); + + isValidReference(ref, @"36060c58702ed4c2a40832c51758d5344201d89a", GTReferenceTypeOid, @"refs/heads/unit_test"); + }); +}); + +describe(@"-deleteWithError:", ^{ + it(@"can delete references", ^{ + GTReference *ref = [GTReference referenceByCreatingReferenceNamed:@"refs/heads/unit_test" fromReferenceTarget:@"36060c58702ed4c2a40832c51758d5344201d89a" inRepository:bareRepository error:&error]; + + expect(error).to.beNil(); + expect(ref).notTo.beNil(); + + BOOL success = [ref deleteWithError:&error]; + expect(success).to.beTruthy(); + expect(error).to.beNil(); + }); +}); + SpecEnd diff --git a/ObjectiveGitTests/GTReferenceTest.m b/ObjectiveGitTests/GTReferenceTest.m deleted file mode 100644 index 22b80d09e..000000000 --- a/ObjectiveGitTests/GTReferenceTest.m +++ /dev/null @@ -1,90 +0,0 @@ -// -// GTReferenceTest.m -// ObjectiveGitFramework -// -// Created by Timothy Clem on 3/2/11. -// Copyright 2011 GitHub Inc. All rights reserved. -// - -@interface GTReferenceTest : GTTestCase { - NSArray *expectedRefs; -} -@end - -@implementation GTReferenceTest - -- (void)setUp { - - expectedRefs = [NSArray arrayWithObjects:@"refs/heads/packed", @"refs/heads/master", @"refs/tags/v0.9", @"refs/tags/v1.0", nil]; -} - -- (void)testCanOpenRef { - GTRepository *repo = self.bareFixtureRepository; - STAssertNotNil(repo, @"Could not create reposiotry"); - NSError *error = nil; - GTReference *ref = [GTReference referenceByLookingUpReferencedNamed:@"refs/heads/master" inRepository:repo error:&error]; - STAssertNil(error, [error localizedDescription]); - STAssertNotNil(ref, nil); - - STAssertEqualObjects(@"36060c58702ed4c2a40832c51758d5344201d89a", ref.targetSHA, nil); - STAssertEquals(GTReferenceTypeOid, ref.referenceType, nil); - STAssertEqualObjects(@"refs/heads/master", ref.name, nil); -} - -- (void)testCanOpenTagRef { - GTRepository *repo = self.bareFixtureRepository; - NSError *error = nil; - GTReference *ref = [GTReference referenceByLookingUpReferencedNamed:@"refs/tags/v0.9" inRepository:repo error:&error]; - STAssertNil(error, [error localizedDescription]); - STAssertNotNil(ref, nil); - - STAssertEqualObjects(@"5b5b025afb0b4c913b4c338a42934a3863bf3644", ref.targetSHA, nil); - STAssertEquals(GTReferenceTypeOid, ref.referenceType, nil); - STAssertEqualObjects(@"refs/tags/v0.9", ref.name, nil); -} - -- (void)testCanCreateRefFromSymbolicRef { - GTRepository *repo = self.bareFixtureRepository; - NSError *error = nil; - GTReference *ref = [GTReference referenceByCreatingReferenceNamed:@"refs/heads/unit_test" fromReferenceTarget:@"refs/heads/master" inRepository:repo error:&error]; - STAssertNil(error, [error localizedDescription]); - STAssertNotNil(ref, nil); - - STAssertEqualObjects(@"refs/heads/master", ref.resolvedReference.name, nil); - STAssertEquals(GTReferenceTypeSymbolic, ref.referenceType, nil); - STAssertEqualObjects(@"refs/heads/unit_test", ref.name, nil); - - BOOL success = [ref deleteWithError:&error]; - STAssertTrue(success, [error localizedDescription]); -} - -- (void)testCanCreateRefFromSha { - - GTRepository *repo = self.bareFixtureRepository; - NSError *error = nil; - GTReference *ref = [GTReference referenceByCreatingReferenceNamed:@"refs/heads/unit_test" fromReferenceTarget:@"36060c58702ed4c2a40832c51758d5344201d89a" inRepository:repo error:&error]; - STAssertNil(error, [error localizedDescription]); - STAssertNotNil(ref, nil); - - STAssertEqualObjects(@"36060c58702ed4c2a40832c51758d5344201d89a", ref.targetSHA, nil); - STAssertEquals(GTReferenceTypeOid, ref.referenceType, nil); - STAssertEqualObjects(@"refs/heads/unit_test", ref.name, nil); - - BOOL success = [ref deleteWithError:&error]; - STAssertTrue(success, [error localizedDescription]); -} - -- (void)testCanListAllReferences { - GTRepository *repo = self.bareFixtureRepository; - NSError *error = nil; - NSArray *refs = [repo referenceNamesWithError:&error]; - STAssertNil(error, [error localizedDescription]); - STAssertEquals(4, (int)refs.count, nil); - - for (NSUInteger i = 0; i < refs.count; i++) { - NSLog(@"%@", [refs objectAtIndex:i]); - STAssertTrue([expectedRefs containsObject:[refs objectAtIndex:i]], nil); - } -} - -@end diff --git a/ObjectiveGitTests/GTRepositorySpec.m b/ObjectiveGitTests/GTRepositorySpec.m index ff49f2717..f4debc20b 100644 --- a/ObjectiveGitTests/GTRepositorySpec.m +++ b/ObjectiveGitTests/GTRepositorySpec.m @@ -116,6 +116,21 @@ }); }); +describe(@"-referenceNamesWithError:", ^{ + it(@"should return reference names", ^{ + NSError *error = nil; + NSArray *refs = [self.bareFixtureRepository referenceNamesWithError:&error]; + expect(refs).notTo.beNil(); + expect(error).to.beNil(); + + expect(refs.count).to.equal(4); + expect(refs).to.contain(@"refs/heads/packed"); + expect(refs).to.contain(@"refs/heads/master"); + expect(refs).to.contain(@"refs/tags/v0.9"); + expect(refs).to.contain(@"refs/tags/v1.0"); + }); +}); + describe(@"-OIDByCreatingTagNamed:target:tagger:message:error", ^{ it(@"should create a new tag",^{ NSError *error = nil; From 9c2c3e2741d58dce8bcdb694ce173a3dccff410e Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Thu, 7 Nov 2013 21:35:23 +0100 Subject: [PATCH 08/38] Convert `GTRepositoryTest`. --- .../project.pbxproj | 4 - ObjectiveGitTests/GTRepositorySpec.m | 161 ++++++++++++- ObjectiveGitTests/GTRepositoryTest.m | 223 ------------------ 3 files changed, 160 insertions(+), 228 deletions(-) delete mode 100644 ObjectiveGitTests/GTRepositoryTest.m diff --git a/ObjectiveGitFramework.xcodeproj/project.pbxproj b/ObjectiveGitFramework.xcodeproj/project.pbxproj index 437c5cda8..a0a2b90a7 100644 --- a/ObjectiveGitFramework.xcodeproj/project.pbxproj +++ b/ObjectiveGitFramework.xcodeproj/project.pbxproj @@ -202,7 +202,6 @@ 88F05A9E16011F6E00B7AD1D /* ObjectiveGit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8DC2EF5B0486A6940098B216 /* ObjectiveGit.framework */; }; 88F05AB516011FFD00B7AD1D /* GTCommitSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 88F05AA416011FFD00B7AD1D /* GTCommitSpec.m */; }; 88F05AB916011FFD00B7AD1D /* GTObjectTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 88F05AA816011FFD00B7AD1D /* GTObjectTest.m */; }; - 88F05ABC16011FFD00B7AD1D /* GTRepositoryTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 88F05AAB16011FFD00B7AD1D /* GTRepositoryTest.m */; }; 88F05AC41601204200B7AD1D /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 88F05A7816011E5400B7AD1D /* InfoPlist.strings */; }; 88F05AC61601209A00B7AD1D /* ObjectiveGit.m in Sources */ = {isa = PBXBuildFile; fileRef = 88F05AC51601209A00B7AD1D /* ObjectiveGit.m */; }; 88F05AC716012CE500B7AD1D /* NSString+Git.m in Sources */ = {isa = PBXBuildFile; fileRef = 55C8057313874CDF004DCB0F /* NSString+Git.m */; }; @@ -567,7 +566,6 @@ 88F05A9C16011F6A00B7AD1D /* SenTestingKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SenTestingKit.framework; path = Library/Frameworks/SenTestingKit.framework; sourceTree = DEVELOPER_DIR; }; 88F05AA416011FFD00B7AD1D /* GTCommitSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTCommitSpec.m; sourceTree = ""; }; 88F05AA816011FFD00B7AD1D /* GTObjectTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTObjectTest.m; sourceTree = ""; }; - 88F05AAB16011FFD00B7AD1D /* GTRepositoryTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTRepositoryTest.m; sourceTree = ""; }; 88F05AAF16011FFD00B7AD1D /* ObjectiveGitTests-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "ObjectiveGitTests-Info.plist"; sourceTree = ""; }; 88F05AC51601209A00B7AD1D /* ObjectiveGit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ObjectiveGit.m; path = Classes/ObjectiveGit.m; sourceTree = ""; }; 88F05AC91601335C00B7AD1D /* Specta.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Specta.xcodeproj; path = specta/Specta.xcodeproj; sourceTree = ""; }; @@ -830,7 +828,6 @@ D0AC906B172F941F00347DC4 /* GTRepositorySpec.m */, F6ED8DA0180E713200A32D40 /* GTRemoteSpec.m */, 4D12323F178E009E0048F785 /* GTRepositoryCommittingSpec.m */, - 88F05AAB16011FFD00B7AD1D /* GTRepositoryTest.m */, D03B7C401756AB370034A610 /* GTSubmoduleSpec.m */, 2089E43B17D9A58000F451DA /* GTTagSpec.m */, 30B1E7FF1703871900D0814D /* GTTimeAdditionsSpec.m */, @@ -1520,7 +1517,6 @@ 4D1C40D8182C006D00BE2960 /* GTBlobSpec.m in Sources */, 88F05AB516011FFD00B7AD1D /* GTCommitSpec.m in Sources */, 88F05AB916011FFD00B7AD1D /* GTObjectTest.m in Sources */, - 88F05ABC16011FFD00B7AD1D /* GTRepositoryTest.m in Sources */, 30865A91167F503400B1AB6E /* GTDiffSpec.m in Sources */, 88A994BA16FCE7D400402C7B /* GTBranchSpec.m in Sources */, 2089E43C17D9A58000F451DA /* GTTagSpec.m in Sources */, diff --git a/ObjectiveGitTests/GTRepositorySpec.m b/ObjectiveGitTests/GTRepositorySpec.m index f4debc20b..9387be9b0 100644 --- a/ObjectiveGitTests/GTRepositorySpec.m +++ b/ObjectiveGitTests/GTRepositorySpec.m @@ -12,13 +12,15 @@ SpecBegin(GTRepository) __block GTRepository *repository; +__block NSError *error = nil; beforeEach(^{ repository = self.testAppFixtureRepository; expect(repository).notTo.beNil(); + error = nil; }); -describe(@"-initializeEmptyRepositoryAtFileURL:bare:error:", ^{ +describe(@"+initializeEmptyRepositoryAtFileURL:bare:error:", ^{ __block GTRepository * (^createRepository)(BOOL bare); beforeEach(^{ @@ -44,6 +46,100 @@ }); }); +describe(@"+repositoryWithURL:error:", ^{ + it(@"should fail to initialize non-existent repos", ^{ + GTRepository *badRepo = [GTRepository repositoryWithURL:[NSURL fileURLWithPath:@"fake/1235"] error:&error]; + expect(badRepo).to.beNil(); + expect(error).notTo.beNil(); + }); +}); + +describe(@"+cloneFromURL:toWorkingDirectory:...", ^{ + __block BOOL transferProgressCalled = NO; + __block BOOL checkoutProgressCalled = NO; + __block void (^transferProgressBlock)(const git_transfer_progress *); + __block void (^checkoutProgressBlock)(NSString *, NSUInteger, NSUInteger); + __block NSURL *originURL; + __block NSURL *workdirURL; + + beforeEach(^{ + error = nil; + transferProgressCalled = NO; + checkoutProgressCalled = NO; + transferProgressBlock = ^(const git_transfer_progress *progress) { transferProgressCalled = YES; }; + checkoutProgressBlock = ^(NSString *path, NSUInteger completedSteps, NSUInteger totalSteps) { checkoutProgressCalled = YES; }; + + originURL = self.bareFixtureRepository.gitDirectoryURL; //[NSURL URLWithString: @"https://github.com/libgit2/TestGitRepository"]; + workdirURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"unit_test"]]; + }); + + afterEach(^{ + if ([NSFileManager.defaultManager fileExistsAtPath:workdirURL.path isDirectory:NULL]) { + NSError *error = nil; + BOOL success = [NSFileManager.defaultManager removeItemAtURL:workdirURL error:&error]; + expect(success).to.beTruthy(); + expect(error).to.beNil(); + } + }); + + it(@"should handle normal clones", ^{ + repository = [GTRepository cloneFromURL:originURL toWorkingDirectory:workdirURL options:nil error:&error transferProgressBlock:transferProgressBlock checkoutProgressBlock:checkoutProgressBlock]; + expect(repository).notTo.beNil(); + expect(error).to.beNil(); + expect(transferProgressCalled).to.beTruthy(); + expect(checkoutProgressCalled).to.beTruthy(); + + expect(repository.isBare).to.beFalsy(); + + GTReference *head = [repository headReferenceWithError:&error]; + expect(head).notTo.beNil(); + expect(error).to.beNil(); + expect(head.targetSHA).to.equal(@"36060c58702ed4c2a40832c51758d5344201d89a"); + expect(head.referenceType).to.equal(GTReferenceTypeOid); + }); + + it(@"should handle bare clones", ^{ + NSDictionary *options = @{ GTRepositoryCloneOptionsBare: @YES }; + repository = [GTRepository cloneFromURL:originURL toWorkingDirectory:workdirURL options:options error:&error transferProgressBlock:transferProgressBlock checkoutProgressBlock:checkoutProgressBlock]; + expect(repository).notTo.beNil(); + expect(error).to.beNil(); + expect(transferProgressCalled).to.beTruthy(); + expect(checkoutProgressCalled).to.beTruthy(); + + expect(repository.isBare).to.beTruthy(); + + GTReference *head = [repository headReferenceWithError:&error]; + expect(head).notTo.beNil(); + expect(error).to.beNil(); + expect(head.targetSHA).to.equal(@"36060c58702ed4c2a40832c51758d5344201d89a"); + expect(head.referenceType).to.equal(GTReferenceTypeOid); + + }); +}); + +describe(@"-headReferenceWithError:", ^{ + it(@"should allow HEAD to be looked up", ^{ + GTReference *head = [self.bareFixtureRepository headReferenceWithError:&error]; + expect(head).notTo.beNil(); + expect(error).to.beNil(); + expect(head.targetSHA).to.equal(@"36060c58702ed4c2a40832c51758d5344201d89a"); + expect(head.referenceType).to.equal(GTReferenceTypeOid); + }); +}); + +describe(@"-isEmpty", ^{ + it(@"should return NO for a non-empty repository", ^{ + expect(repository.isEmpty).to.beFalsy(); + }); + + it(@"should return YES for a new repository", ^{ + NSURL *fileURL = [self.tempDirectoryFileURL URLByAppendingPathComponent:@"newrepo"]; + GTRepository *newRepo = [GTRepository initializeEmptyRepositoryAtFileURL:fileURL error:&error]; + expect(newRepo.isEmpty).to.beTruthy(); + [NSFileManager.defaultManager removeItemAtURL:fileURL error:NULL]; + }); +}); + describe(@"-preparedMessage", ^{ it(@"should return nil by default", ^{ __block NSError *error = nil; @@ -186,4 +282,67 @@ }); }); +describe(@"-resetToCommit:withResetType:error:", ^{ + beforeEach(^{ + repository = self.bareFixtureRepository; + }); + + it(@"should move HEAD when used", ^{ + GTReference *originalHead = [repository headReferenceWithError:NULL]; + NSString *resetTargetSHA = @"8496071c1b46c854b31185ea97743be6a8774479"; + + GTCommit *commit = [repository lookupObjectBySHA:resetTargetSHA error:NULL]; + expect(commit).notTo.beNil(); + GTCommit *originalHeadCommit = [repository lookupObjectBySHA:originalHead.targetSHA error:NULL]; + expect(originalHeadCommit).notTo.beNil(); + + BOOL success = [repository resetToCommit:commit withResetType:GTRepositoryResetTypeSoft error:&error]; + expect(success).to.beTruthy(); + expect(error).to.beNil(); + + GTReference *head = [repository headReferenceWithError:&error]; + expect(head).notTo.beNil(); + expect(head.targetSHA).to.equal(resetTargetSHA); + + success = [repository resetToCommit:originalHeadCommit withResetType:GTRepositoryResetTypeSoft error:&error]; + expect(success).to.beTruthy(); + expect(error).to.beNil(); + + head = [repository headReferenceWithError:&error]; + expect(head.targetSHA).to.equal(originalHead.targetSHA); + }); +}); + +describe(@"-lookupObjectByRefspec:error:", ^{ + __block void (^expectSHAForRevspec)(NSString *SHA, NSString *revspec); + + beforeEach(^{ + repository = self.bareFixtureRepository; + error = nil; + + expectSHAForRevspec = ^(NSString *SHA, NSString *revspec) { + error = nil; + GTObject *obj = [repository lookupObjectByRefspec:revspec error:&error]; + + if (SHA != nil) { + expect(error).to.beNil(); + expect(obj).notTo.beNil(); + expect(obj.SHA).to.equal(SHA); + } else { + expect(error).notTo.beNil(); + expect(obj).to.beNil(); + } + }; + }); + + it(@"should parse various revspecs", ^{ + expectSHAForRevspec(@"36060c58702ed4c2a40832c51758d5344201d89a", @"master"); + expectSHAForRevspec(@"5b5b025afb0b4c913b4c338a42934a3863bf3644", @"master~"); + expectSHAForRevspec(@"8496071c1b46c854b31185ea97743be6a8774479", @"master@{2}"); + expectSHAForRevspec(nil, @"master^2"); + expectSHAForRevspec(nil, @""); + expectSHAForRevspec(@"0c37a5391bbff43c37f0d0371823a5509eed5b1d", @"v1.0"); + }); +}); + SpecEnd diff --git a/ObjectiveGitTests/GTRepositoryTest.m b/ObjectiveGitTests/GTRepositoryTest.m deleted file mode 100644 index 4656ee0ca..000000000 --- a/ObjectiveGitTests/GTRepositoryTest.m +++ /dev/null @@ -1,223 +0,0 @@ -// -// GTRepositoryTest.m -// ObjectiveGitFramework -// -// Created by Timothy Clem on 2/21/11. -// -// The MIT License -// -// Copyright (c) 2011 Tim Clem -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// - -@interface GTRepositoryTest : GTTestCase { - - GTRepository *repo; - NSString *testContent; - GTObjectType testContentType; -} -@end - - -@implementation GTRepositoryTest - -- (void)setUp { - repo = self.bareFixtureRepository; - testContent = @"my test data\n"; - testContentType = GTObjectTypeBlob; -} - -- (void)removeDirectoryAtURL:(NSURL *)url { - NSFileManager *fm = [[NSFileManager alloc] init]; - NSError *error = nil; - - if([fm fileExistsAtPath:url.path]) { - STAssertTrue([fm removeItemAtPath:url.path error:&error], [error localizedDescription]); - } -} - -- (void)testFailsToOpenNonExistentRepo { - - NSError *error = nil; - GTRepository *badRepo = [GTRepository repositoryWithURL:[NSURL fileURLWithPath:@"fake/1235"] error:&error]; - - STAssertNil(badRepo, nil); - STAssertNotNil(error, nil); - NSLog(@"error = %@", [error localizedDescription]); -} - -- (void)testLookupHead { - - NSError *error = nil; - GTReference *head = [repo headReferenceWithError:&error]; - STAssertNil(error, [error localizedDescription]); - STAssertEqualObjects(head.targetSHA, @"36060c58702ed4c2a40832c51758d5344201d89a", nil); - STAssertEquals(head.referenceType, GTReferenceTypeOid, nil); -} - -- (void)testIsEmpty { - STAssertFalse([repo isEmpty], nil); -} - -- (void)testCanReset { - NSError *err = nil; - GTRepository *aRepo = self.bareFixtureRepository; - STAssertNotNil(aRepo, @"Repository failed to initialise"); - GTReference *originalHead = [aRepo headReferenceWithError:NULL]; - NSString *resetTargetSha = @"8496071c1b46c854b31185ea97743be6a8774479"; - - GTCommit *commit = (GTCommit *)[aRepo lookupObjectBySHA:resetTargetSha error:NULL]; - - BOOL success = [aRepo resetToCommit:commit withResetType:GTRepositoryResetTypeSoft error:&err]; - STAssertTrue(success, @"Failed to reset, error given: %@", err); - GTReference *head = [aRepo headReferenceWithError:&err]; - STAssertEqualObjects(head.targetSHA, resetTargetSha, @"Reset failed to move head to given commit"); - - GTCommit *originalHeadCommit = (GTCommit *)[aRepo lookupObjectBySHA:originalHead.targetSHA error:NULL]; - [aRepo resetToCommit:originalHeadCommit withResetType:GTRepositoryResetTypeSoft error:NULL]; - head = [aRepo headReferenceWithError:&err]; - STAssertEqualObjects(head.unresolvedTarget, originalHead.unresolvedTarget, @"Reset failed to move head back to the original position"); -} - -- (void)expectSHA:(NSString*)sha forRefspec:(NSString*)refspec { - NSError *err = nil; - GTObject *obj = [repo lookupObjectByRefspec:refspec error:&err]; - - if (sha != nil) { - STAssertEquals((NSInteger)GIT_OK, err.code, @"git_revparse_single didn't return 0: %d", err.code); - STAssertNotNil(obj, @"Couldn't find object for %@", refspec); - STAssertEqualObjects(sha, obj.SHA, @"Revparse '%@': expected %@, got %@", refspec, sha, obj.SHA); - } else { - STAssertTrue(err.code != (NSInteger)GIT_OK, @"Expected error code, got 0"); - STAssertNil(obj, @"Got object when expected none for %@", refspec); - } -} - -- (void)testCanRevparse { - [self expectSHA:@"36060c58702ed4c2a40832c51758d5344201d89a" forRefspec:@"master"]; - [self expectSHA:@"5b5b025afb0b4c913b4c338a42934a3863bf3644" forRefspec:@"master~"]; - [self expectSHA:@"8496071c1b46c854b31185ea97743be6a8774479" forRefspec:@"master@{2}"]; - [self expectSHA:nil forRefspec:@"master^2"]; - [self expectSHA:nil forRefspec:@""]; - [self expectSHA:@"0c37a5391bbff43c37f0d0371823a5509eed5b1d" forRefspec:@"v1.0"]; - - GTObject *obj = [repo lookupObjectByRefspec:@"master" error:nil]; - STAssertNotNil(obj, @"Call with nil error should still work"); -} - - -- (void)testCanClone { - __block BOOL transferProgressCalled = NO; - __block BOOL checkoutProgressCalled = NO; - void (^transferProgressBlock)(const git_transfer_progress *) = ^(const git_transfer_progress *progress) { - transferProgressCalled = YES; - }; - void (^checkoutProgressBlock)(NSString *, NSUInteger, NSUInteger) = ^(NSString *path, NSUInteger completedSteps, NSUInteger totalSteps) { - checkoutProgressCalled = YES; - }; - NSURL *originURL = self.bareFixtureRepository.fileURL; //[NSURL URLWithString: @"https://github.com/libgit2/TestGitRepository"]; - NSURL *workdirURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"unit_test"]]; - NSError *err; - - [self removeDirectoryAtURL:workdirURL]; - - repo = [GTRepository cloneFromURL:originURL toWorkingDirectory:workdirURL options:NULL error:&err transferProgressBlock:transferProgressBlock checkoutProgressBlock:checkoutProgressBlock]; - - STAssertNotNil(repo, err.localizedDescription); - STAssertFalse([repo isBare], @"Standard repo should not be bare"); - STAssertTrue(transferProgressCalled, @"Transfer progress handler never called"); - STAssertTrue(checkoutProgressCalled, @"checkout progress handler never called"); - - GTReference *head = [repo headReferenceWithError:&err]; - STAssertNotNil(head, err.localizedDescription); - STAssertEqualObjects(head.targetSHA, @"36060c58702ed4c2a40832c51758d5344201d89a", nil); - STAssertEquals(head.referenceType, GTReferenceTypeOid, nil); -} - -- (void)testCanCloneBarely { - __block BOOL transferProgressCalled = NO; - __block BOOL checkoutProgressCalled = NO; - void (^transferProgressBlock)(const git_transfer_progress *) = ^(const git_transfer_progress *progress) { - transferProgressCalled = YES; - }; - void (^checkoutProgressBlock)(NSString *, NSUInteger, NSUInteger) = ^(NSString *path, NSUInteger completedSteps, NSUInteger totalSteps) { - checkoutProgressCalled = YES; - }; - NSURL *originURL = self.bareFixtureRepository.fileURL; //[NSURL URLWithString: @"https://github.com/libgit2/TestGitRepository"]; - NSURL *workdirURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"unit_test"]]; - NSDictionary *options = @{ GTRepositoryCloneOptionsBare: @YES }; - NSError *err; - - [self removeDirectoryAtURL:workdirURL]; - - repo = [GTRepository cloneFromURL:originURL toWorkingDirectory:workdirURL options:options error:&err transferProgressBlock:transferProgressBlock checkoutProgressBlock:checkoutProgressBlock]; - - STAssertNotNil(repo, err.localizedDescription); - STAssertTrue([repo isBare], @"Bare repo should be bare"); - STAssertTrue(transferProgressCalled, @"Transfer progress handler never called"); - STAssertFalse(checkoutProgressCalled, @"Checkout progress handler was called for bare repo"); - - GTReference *head = [repo headReferenceWithError:&err]; - STAssertNotNil(head, err.localizedDescription); - STAssertEqualObjects(head.targetSHA, @"36060c58702ed4c2a40832c51758d5344201d89a", nil); - STAssertEquals(head.referenceType, GTReferenceTypeOid, nil); -} - -//- (void) testCanGetRemotes { -// NSArray* remotesArray = [repo remoteNames]; -// -// STAssertTrue( [remotesArray containsObject: @"github"], @"remotes name did not contain expected remote" ); -// STAssertTrue( [repo hasRemoteNamed: @"github"], @"remotes name was not found by query function" ); -// -//} - -// This messes other tests up b/c it writes a new HEAD, but doesn't set it back again -/* -- (void)testLookupHeadThenCommitAndThenLookupHeadAgain { - - NSError *error = nil; - GTReference *head = [repo headAndReturnError:&error]; - STAssertNil(error, [error localizedDescription]); - STAssertEqualObjects(head.target, @"36060c58702ed4c2a40832c51758d5344201d89a", nil); - STAssertEqualObjects(head.type, @"commit", nil); - - NSString *tsha = @"c4dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b"; - GTObject *aObj = [repo lookupBySha:tsha error:&error]; - - STAssertNotNil(aObj, [error localizedDescription]); - STAssertTrue([aObj isKindOfClass:[GTTree class]], nil); - GTTree *tree = (GTTree *)aObj; - GTSignature *person = [[[GTSignature alloc] - initWithName:@"Tim" - email:@"tclem@github.com" - time:[NSDate date]] autorelease]; - GTCommit *commit = [GTCommit commitInRepo:repo updateRefNamed:@"HEAD" author:person committer:person message:@"new message" tree:tree parents:nil error:&error]; - STAssertNotNil(commit, [error localizedDescription]); - NSLog(@"wrote sha %@", commit.sha); - - head = [repo headAndReturnError:&error]; - STAssertNotNil(head, [error localizedDescription]); - - STAssertEqualObjects(head.target, commit.sha, nil); - - rm_loose(commit.sha); -} -*/ -@end From f655dec66f61f1d4d3c512c5d303b7e0bc35544c Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Sat, 9 Nov 2013 11:52:41 +0100 Subject: [PATCH 09/38] Cleanup `GTBlob`'s header. --- Classes/GTBlob.h | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/Classes/GTBlob.h b/Classes/GTBlob.h index 42c350535..7e42beb44 100644 --- a/Classes/GTBlob.h +++ b/Classes/GTBlob.h @@ -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)); From 1ea8499b6b9240c805f15f93a8e8777b20a97175 Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Sat, 9 Nov 2013 11:57:45 +0100 Subject: [PATCH 10/38] Make `error` a local variable. --- ObjectiveGitTests/GTBlobSpec.m | 8 +++----- ObjectiveGitTests/GTCommitSpec.m | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/ObjectiveGitTests/GTBlobSpec.m b/ObjectiveGitTests/GTBlobSpec.m index 1344b6bf7..93d8e9e8e 100644 --- a/ObjectiveGitTests/GTBlobSpec.m +++ b/ObjectiveGitTests/GTBlobSpec.m @@ -13,11 +13,6 @@ __block GTRepository *repository; __block NSString *blobSHA; __block GTBlob *blob; -__block NSError *error; - -beforeEach(^{ - error = nil; -}); describe(@"blob properties can be accessed", ^{ beforeEach(^{ @@ -51,6 +46,7 @@ describe(@"+blobWithString:inRepository:error", ^{ it(@"works with valid parameters", ^{ + NSError *error = nil; blob = [GTBlob blobWithString:@"a new blob content" inRepository:repository error:&error]; expect(error).to.beNil(); expect(blob).notTo.beNil(); @@ -63,6 +59,7 @@ char bytes[] = "100644 example_helper.rb\00\xD3\xD5\xED\x9D A4_\x00 40000 examples"; NSData *content = [NSData dataWithBytes:bytes length:sizeof(bytes)]; + NSError *error = nil; blob = [GTBlob blobWithData:content inRepository:repository error:&error]; expect(error).to.beNil(); expect(blob).notTo.beNil(); @@ -76,6 +73,7 @@ NSString *fileName = @"myfile.txt"; NSURL *fileURL = [repository.fileURL URLByAppendingPathComponent:fileName]; + NSError *error = nil; BOOL success = [fileContent writeToURL:fileURL atomically:YES encoding:NSUTF8StringEncoding error:&error]; expect(success).to.beTruthy(); expect(error).to.beNil(); diff --git a/ObjectiveGitTests/GTCommitSpec.m b/ObjectiveGitTests/GTCommitSpec.m index 81013008e..9ead391be 100644 --- a/ObjectiveGitTests/GTCommitSpec.m +++ b/ObjectiveGitTests/GTCommitSpec.m @@ -11,14 +11,13 @@ SpecBegin(GTCommit) __block GTRepository *repository; -__block NSError *error; beforeEach(^{ repository = self.bareFixtureRepository; - error = nil; }); it(@"can read commit data", ^{ + NSError *error = nil; NSString *commitSHA = @"8496071c1b46c854b31185ea97743be6a8774479"; GTCommit *commit = [repository lookupObjectBySHA:commitSHA error:&error]; @@ -54,6 +53,7 @@ }); it(@"canHaveMultipleParents", ^{ + NSError *error = nil; NSString *commitSHA = @"a4a7dce85cf63874e984719f4fdd239f5145052f"; GTCommit *commit = [repository lookupObjectBySHA:commitSHA error:&error]; expect(commit).notTo.beNil(); From 49ed41f86b5abab8951658accb8932153e5e06dd Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Sat, 9 Nov 2013 11:58:01 +0100 Subject: [PATCH 11/38] Expect errors to be nil here. --- ObjectiveGitTests/GTBranchSpec.m | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ObjectiveGitTests/GTBranchSpec.m b/ObjectiveGitTests/GTBranchSpec.m index ed8c0a318..18aaa3f49 100644 --- a/ObjectiveGitTests/GTBranchSpec.m +++ b/ObjectiveGitTests/GTBranchSpec.m @@ -132,6 +132,7 @@ NSError *error = nil; NSUInteger commitCount = [masterBranch numberOfCommitsWithError:&error]; expect(commitCount).to.equal(164); + expect(error).to.beNil(); }); }); @@ -146,6 +147,7 @@ GTBranch *trackingBranch = [masterBranch trackingBranchWithError:&error success:&success]; expect(trackingBranch).notTo.beNil(); expect(success).to.beTruthy(); + expect(error).to.beNil(); }); it(@"should return nil for a local branch that doesn't track a remote branch", ^{ @@ -156,12 +158,12 @@ GTBranch *otherBranch = [GTBranch branchWithReference:otherRef repository:repository]; expect(otherBranch).notTo.beNil(); - expect(error).to.beNil(); BOOL success = NO; trackingBranch = [otherBranch trackingBranchWithError:&error success:&success]; expect(trackingBranch).to.beNil(); expect(success).to.beTruthy(); + expect(error).to.beNil(); }); it(@"should return itself for a remote branch", ^{ @@ -177,6 +179,7 @@ GTBranch *remoteTrackingBranch = [remoteBranch trackingBranchWithError:&error success:&success]; expect(remoteTrackingBranch).to.equal(remoteBranch); expect(success).to.beTruthy(); + expect(error).to.beNil(); }); }); From 9b1bd6ce911cb4f8607fd3d347115c259f669330 Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Sat, 9 Nov 2013 11:58:56 +0100 Subject: [PATCH 12/38] Reindent commented test. --- ObjectiveGitTests/GTBranchSpec.m | 44 +++++++++++++++----------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/ObjectiveGitTests/GTBranchSpec.m b/ObjectiveGitTests/GTBranchSpec.m index 18aaa3f49..e1ff7c0ac 100644 --- a/ObjectiveGitTests/GTBranchSpec.m +++ b/ObjectiveGitTests/GTBranchSpec.m @@ -184,28 +184,26 @@ }); // TODO: Test branch renaming, branch upstream -/* - - (void)testCanRenameBranch { - - NSError *error = nil; - GTRepository *repo = [GTRepository repoByOpeningRepositoryInDirectory:[NSURL URLWithString:TEST_REPO_PATH()] error:&error]; - STAssertNil(error, [error localizedDescription]); - - NSArray *branches = [GTBranch listAllLocalBranchesInRepository:repo error:&error]; - STAssertNotNil(branches, [error localizedDescription], nil); - STAssertEquals(2, (int)branches.count, nil); - - NSString *newBranchName = [NSString stringWithFormat:@"%@%@", [GTBranch localNamePrefix], @"this_is_the_renamed_branch"]; - GTBranch *firstBranch = [branches objectAtIndex:0]; - NSString *originalBranchName = firstBranch.name; - BOOL success = [firstBranch.reference setName:newBranchName error:&error]; - STAssertTrue(success, [error localizedDescription]); - STAssertEqualObjects(firstBranch.name, newBranchName, nil); - - success = [firstBranch.reference setName:originalBranchName error:&error]; - STAssertTrue(success, [error localizedDescription]); - STAssertEqualObjects(firstBranch.name, originalBranchName, nil); - } - */ +//- (void)testCanRenameBranch { +// +// NSError *error = nil; +// GTRepository *repo = [GTRepository repoByOpeningRepositoryInDirectory:[NSURL URLWithString:TEST_REPO_PATH()] error:&error]; +// STAssertNil(error, [error localizedDescription]); +// +// NSArray *branches = [GTBranch listAllLocalBranchesInRepository:repo error:&error]; +// STAssertNotNil(branches, [error localizedDescription], nil); +// STAssertEquals(2, (int)branches.count, nil); +// +// NSString *newBranchName = [NSString stringWithFormat:@"%@%@", [GTBranch localNamePrefix], @"this_is_the_renamed_branch"]; +// GTBranch *firstBranch = [branches objectAtIndex:0]; +// NSString *originalBranchName = firstBranch.name; +// BOOL success = [firstBranch.reference setName:newBranchName error:&error]; +// STAssertTrue(success, [error localizedDescription]); +// STAssertEqualObjects(firstBranch.name, newBranchName, nil); +// +// success = [firstBranch.reference setName:originalBranchName error:&error]; +// STAssertTrue(success, [error localizedDescription]); +// STAssertEqualObjects(firstBranch.name, originalBranchName, nil); +//} SpecEnd From 83469744d9294af7903c68ec7b98bd1f87ceee96 Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Sat, 9 Nov 2013 12:00:16 +0100 Subject: [PATCH 13/38] Rename test. --- ObjectiveGitTests/GTCommitSpec.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ObjectiveGitTests/GTCommitSpec.m b/ObjectiveGitTests/GTCommitSpec.m index 9ead391be..29c3ed3e5 100644 --- a/ObjectiveGitTests/GTCommitSpec.m +++ b/ObjectiveGitTests/GTCommitSpec.m @@ -52,7 +52,7 @@ expect(commit.parents.count).to.equal(0); }); -it(@"canHaveMultipleParents", ^{ +it(@"can have multiple parents", ^{ NSError *error = nil; NSString *commitSHA = @"a4a7dce85cf63874e984719f4fdd239f5145052f"; GTCommit *commit = [repository lookupObjectBySHA:commitSHA error:&error]; From bc98f3c8d59e9a5e700a78824485ceb4e2bbe12c Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Sat, 9 Nov 2013 12:00:25 +0100 Subject: [PATCH 14/38] Cruft--; --- ObjectiveGitTests/GTCommitSpec.m | 3 --- 1 file changed, 3 deletions(-) diff --git a/ObjectiveGitTests/GTCommitSpec.m b/ObjectiveGitTests/GTCommitSpec.m index 29c3ed3e5..a0f749e78 100644 --- a/ObjectiveGitTests/GTCommitSpec.m +++ b/ObjectiveGitTests/GTCommitSpec.m @@ -33,14 +33,11 @@ expect(commit.messageDetails).to.equal(@""); expect(commit.commitDate).to.equal([NSDate dateWithTimeIntervalSince1970:1273360386]); -// STAssertEquals((int)[commit.commitDate timeIntervalSince1970], 1273360386, nil); - GTSignature *author = commit.author; expect(author).notTo.beNil(); expect(author.name).to.equal(@"Scott Chacon"); expect(author.email).to.equal(@"schacon@gmail.com"); expect(author.time).to.equal([NSDate dateWithTimeIntervalSince1970:1273360386]); -// STAssertEquals((int)[author.time timeIntervalSince1970], 1273360386, nil); GTSignature *committer = commit.committer; expect(committer).notTo.beNil(); From 86d4f7b17f25bd509b3f4bbed8db5016f0d13172 Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Sat, 9 Nov 2013 12:01:02 +0100 Subject: [PATCH 15/38] Dot-syntaxify. --- ObjectiveGitTests/GTCommitSpec.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ObjectiveGitTests/GTCommitSpec.m b/ObjectiveGitTests/GTCommitSpec.m index a0f749e78..b304f6066 100644 --- a/ObjectiveGitTests/GTCommitSpec.m +++ b/ObjectiveGitTests/GTCommitSpec.m @@ -24,7 +24,7 @@ expect(commit).notTo.beNil(); expect(error).to.beNil(); - expect(commit).to.beInstanceOf([GTCommit class]); + expect(commit).to.beInstanceOf(GTCommit.class); expect(commit.type).to.equal(@"commit"); expect(commit.SHA).to.equal(commitSHA); From 173e1776de22990834ce5b0e441b83ab08347532 Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Sat, 9 Nov 2013 12:02:39 +0100 Subject: [PATCH 16/38] Rename `isValidReference` and define it at declaration time. --- ObjectiveGitTests/GTReferenceSpec.m | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/ObjectiveGitTests/GTReferenceSpec.m b/ObjectiveGitTests/GTReferenceSpec.m index ad6a52bcb..fc3bf472e 100644 --- a/ObjectiveGitTests/GTReferenceSpec.m +++ b/ObjectiveGitTests/GTReferenceSpec.m @@ -109,17 +109,17 @@ __block GTRepository *bareRepository; __block NSError *error; -__block void (^isValidReference)(GTReference *ref, NSString *SHA, GTReferenceType type, NSString *name); + +void (^expectValidReference)(GTReference *ref, NSString *SHA, GTReferenceType type, NSString *name) = ^(GTReference *ref, NSString *SHA, GTReferenceType type, NSString *name) { + expect(ref).notTo.beNil(); + expect(ref.targetSHA).to.equal(SHA); + expect(ref.referenceType).to.equal(type); + expect(ref.name).to.equal(name); +}; beforeEach(^{ bareRepository = self.bareFixtureRepository; error = nil; - isValidReference = ^(GTReference *ref, NSString *SHA, GTReferenceType type, NSString *name) { - expect(ref).notTo.beNil(); - expect(ref.targetSHA).to.equal(SHA); - expect(ref.referenceType).to.equal(type); - expect(ref.name).to.equal(name); - }; }); describe(@"+referenceByLookingUpReferenceNamed:inRepository:error:", ^{ @@ -128,7 +128,7 @@ expect(ref).notTo.beNil(); expect(error).to.beNil(); - isValidReference(ref, @"36060c58702ed4c2a40832c51758d5344201d89a", GTReferenceTypeOid, @"refs/heads/master"); + expectValidReference(ref, @"36060c58702ed4c2a40832c51758d5344201d89a", GTReferenceTypeOid, @"refs/heads/master"); }); it(@"should return a valid reference to a tag", ^{ @@ -136,7 +136,7 @@ expect(ref).notTo.beNil(); expect(error).to.beNil(); - isValidReference(ref, @"5b5b025afb0b4c913b4c338a42934a3863bf3644", GTReferenceTypeOid, @"refs/tags/v0.9"); + expectValidReference(ref, @"5b5b025afb0b4c913b4c338a42934a3863bf3644", GTReferenceTypeOid, @"refs/tags/v0.9"); }); }); @@ -146,7 +146,7 @@ expect(error).to.beNil(); expect(ref).notTo.beNil(); - isValidReference(ref, @"36060c58702ed4c2a40832c51758d5344201d89a", GTReferenceTypeSymbolic, @"refs/heads/unit_test"); + expectValidReference(ref, @"36060c58702ed4c2a40832c51758d5344201d89a", GTReferenceTypeSymbolic, @"refs/heads/unit_test"); expect(ref.resolvedReference.name).to.equal(@"refs/heads/master"); }); @@ -155,7 +155,7 @@ expect(error).to.beNil(); expect(ref).notTo.beNil(); - isValidReference(ref, @"36060c58702ed4c2a40832c51758d5344201d89a", GTReferenceTypeOid, @"refs/heads/unit_test"); + expectValidReference(ref, @"36060c58702ed4c2a40832c51758d5344201d89a", GTReferenceTypeOid, @"refs/heads/unit_test"); }); }); From 524653562eaa3f67450cc149703c9f27e1f6518c Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Sat, 9 Nov 2013 12:03:34 +0100 Subject: [PATCH 17/38] Make `error` a local variable. --- ObjectiveGitTests/GTReferenceSpec.m | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ObjectiveGitTests/GTReferenceSpec.m b/ObjectiveGitTests/GTReferenceSpec.m index fc3bf472e..dac0588b0 100644 --- a/ObjectiveGitTests/GTReferenceSpec.m +++ b/ObjectiveGitTests/GTReferenceSpec.m @@ -108,7 +108,6 @@ }); __block GTRepository *bareRepository; -__block NSError *error; void (^expectValidReference)(GTReference *ref, NSString *SHA, GTReferenceType type, NSString *name) = ^(GTReference *ref, NSString *SHA, GTReferenceType type, NSString *name) { expect(ref).notTo.beNil(); @@ -119,11 +118,11 @@ beforeEach(^{ bareRepository = self.bareFixtureRepository; - error = nil; }); describe(@"+referenceByLookingUpReferenceNamed:inRepository:error:", ^{ it(@"should return a valid reference to a branch", ^{ + NSError *error = nil; GTReference *ref = [GTReference referenceByLookingUpReferencedNamed:@"refs/heads/master" inRepository:bareRepository error:&error]; expect(ref).notTo.beNil(); expect(error).to.beNil(); @@ -132,6 +131,7 @@ }); it(@"should return a valid reference to a tag", ^{ + NSError *error = nil; GTReference *ref = [GTReference referenceByLookingUpReferencedNamed:@"refs/tags/v0.9" inRepository:bareRepository error:&error]; expect(ref).notTo.beNil(); expect(error).to.beNil(); @@ -142,6 +142,7 @@ describe(@"+referenceByCreatingReferenceNamed:fromReferenceTarget:inRepository:error:", ^{ it(@"can create a reference from a symbolic reference", ^{ + NSError *error = nil; GTReference *ref = [GTReference referenceByCreatingReferenceNamed:@"refs/heads/unit_test" fromReferenceTarget:@"refs/heads/master" inRepository:bareRepository error:&error]; expect(error).to.beNil(); expect(ref).notTo.beNil(); @@ -151,6 +152,7 @@ }); it(@"can create a reference from an SHA/OID", ^{ + NSError *error = nil; GTReference *ref = [GTReference referenceByCreatingReferenceNamed:@"refs/heads/unit_test" fromReferenceTarget:@"36060c58702ed4c2a40832c51758d5344201d89a" inRepository:bareRepository error:&error]; expect(error).to.beNil(); expect(ref).notTo.beNil(); @@ -161,6 +163,7 @@ describe(@"-deleteWithError:", ^{ it(@"can delete references", ^{ + NSError *error = nil; GTReference *ref = [GTReference referenceByCreatingReferenceNamed:@"refs/heads/unit_test" fromReferenceTarget:@"36060c58702ed4c2a40832c51758d5344201d89a" inRepository:bareRepository error:&error]; expect(error).to.beNil(); From 79fcc2d8bbfbc4651335c485ad5a26c86428f0f5 Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Sat, 9 Nov 2013 12:06:29 +0100 Subject: [PATCH 18/38] Fix the `lookupObjectByRefspec:error:` name. --- Classes/GTDiff.m | 2 +- Classes/GTRepository.h | 2 +- Classes/GTRepository.m | 2 +- ObjectiveGitTests/GTRepositorySpec.m | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Classes/GTDiff.m b/Classes/GTDiff.m index 10f763058..013244425 100644 --- a/Classes/GTDiff.m +++ b/Classes/GTDiff.m @@ -151,7 +151,7 @@ + (GTDiff *)diffWorkingDirectoryFromTree:(GTTree *)tree inRepository:(GTReposito + (GTDiff *)diffWorkingDirectoryToHEADInRepository:(GTRepository *)repository options:(NSDictionary *)options error:(NSError **)error { NSParameterAssert(repository != nil); - GTCommit *HEADCommit = [repository lookupObjectByRefspec:@"HEAD" error:NULL]; + GTCommit *HEADCommit = [repository lookupObjectByRevspec:@"HEAD" error:NULL]; GTDiff *HEADIndexDiff = [GTDiff diffIndexFromTree:HEADCommit.tree inRepository:repository options:options error:error]; if (HEADIndexDiff == nil) return nil; diff --git a/Classes/GTRepository.h b/Classes/GTRepository.h index 2cddad3cf..92abed5c1 100644 --- a/Classes/GTRepository.h +++ b/Classes/GTRepository.h @@ -176,7 +176,7 @@ extern NSString *const GTRepositoryCloneOptionsCredentialProvider; - (id)lookupObjectBySHA:(NSString *)sha error:(NSError **)error; // Lookup an object in the repo using a revparse spec -- (id)lookupObjectByRefspec:(NSString *)spec error:(NSError **)error; +- (id)lookupObjectByRevspec:(NSString *)spec error:(NSError **)error; // List all references in the repository // diff --git a/Classes/GTRepository.m b/Classes/GTRepository.m index 2b252151a..cbcc70749 100644 --- a/Classes/GTRepository.m +++ b/Classes/GTRepository.m @@ -269,7 +269,7 @@ - (id)lookupObjectBySHA:(NSString *)sha error:(NSError **)error { return [self lookupObjectBySHA:sha objectType:GTObjectTypeAny error:error]; } -- (id)lookupObjectByRefspec:(NSString *)spec error:(NSError **)error { +- (id)lookupObjectByRevspec:(NSString *)spec error:(NSError **)error { git_object *obj; int gitError = git_revparse_single(&obj, self.git_repository, spec.UTF8String); if (gitError < GIT_OK) { diff --git a/ObjectiveGitTests/GTRepositorySpec.m b/ObjectiveGitTests/GTRepositorySpec.m index 9387be9b0..6032e87b2 100644 --- a/ObjectiveGitTests/GTRepositorySpec.m +++ b/ObjectiveGitTests/GTRepositorySpec.m @@ -313,7 +313,7 @@ }); }); -describe(@"-lookupObjectByRefspec:error:", ^{ +describe(@"-lookupObjectByRevspec:error:", ^{ __block void (^expectSHAForRevspec)(NSString *SHA, NSString *revspec); beforeEach(^{ @@ -322,7 +322,7 @@ expectSHAForRevspec = ^(NSString *SHA, NSString *revspec) { error = nil; - GTObject *obj = [repository lookupObjectByRefspec:revspec error:&error]; + GTObject *obj = [repository lookupObjectByRevspec:revspec error:&error]; if (SHA != nil) { expect(error).to.beNil(); From d4a1ae8b995e268f8822534ecaa03e83dd0e2097 Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Sat, 9 Nov 2013 13:14:30 +0100 Subject: [PATCH 19/38] Whitespace. --- ObjectiveGitTests/GTRepositorySpec.m | 1 - 1 file changed, 1 deletion(-) diff --git a/ObjectiveGitTests/GTRepositorySpec.m b/ObjectiveGitTests/GTRepositorySpec.m index 6032e87b2..c897e6502 100644 --- a/ObjectiveGitTests/GTRepositorySpec.m +++ b/ObjectiveGitTests/GTRepositorySpec.m @@ -113,7 +113,6 @@ expect(error).to.beNil(); expect(head.targetSHA).to.equal(@"36060c58702ed4c2a40832c51758d5344201d89a"); expect(head.referenceType).to.equal(GTReferenceTypeOid); - }); }); From e09ebb5c5a7822d06f3698606df2564897c5e1b1 Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Sat, 9 Nov 2013 13:22:06 +0100 Subject: [PATCH 20/38] Test that the returned branches are the expected ones. --- ObjectiveGitTests/GTRepositorySpec.m | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ObjectiveGitTests/GTRepositorySpec.m b/ObjectiveGitTests/GTRepositorySpec.m index c897e6502..ed8de94e9 100644 --- a/ObjectiveGitTests/GTRepositorySpec.m +++ b/ObjectiveGitTests/GTRepositorySpec.m @@ -188,6 +188,7 @@ GTBranch *currentBranch = [repository currentBranchWithError:&error]; expect(currentBranch).notTo.beNil(); expect(error).to.beNil(); + expect(currentBranch.name).to.equal(@"refs/heads/master"); }); }); @@ -208,6 +209,8 @@ expect(branches).notTo.beNil(); expect(error).to.beNil(); expect(branches.count).to.equal(1); + GTBranch *remoteBranch = branches[0]; + expect(remoteBranch.name).to.equal(@"refs/remotes/origin/master"); }); }); From d07941e5d528caeeb3f547c4597fb18833a942fa Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Sat, 9 Nov 2013 13:25:20 +0100 Subject: [PATCH 21/38] Test the complete reference array in one step. --- ObjectiveGitTests/GTRepositorySpec.m | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ObjectiveGitTests/GTRepositorySpec.m b/ObjectiveGitTests/GTRepositorySpec.m index ed8de94e9..ff3be837b 100644 --- a/ObjectiveGitTests/GTRepositorySpec.m +++ b/ObjectiveGitTests/GTRepositorySpec.m @@ -222,10 +222,8 @@ expect(error).to.beNil(); expect(refs.count).to.equal(4); - expect(refs).to.contain(@"refs/heads/packed"); - expect(refs).to.contain(@"refs/heads/master"); - expect(refs).to.contain(@"refs/tags/v0.9"); - expect(refs).to.contain(@"refs/tags/v1.0"); + NSArray *expectedRefs = @[ @"refs/heads/master", @"refs/tags/v0.9", @"refs/tags/v1.0", @"refs/heads/packed" ]; + expect(refs).to.equal(expectedRefs); }); }); From 8f47b339636aee3d75dd3812365647b9d8b06138 Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Sat, 9 Nov 2013 13:27:10 +0100 Subject: [PATCH 22/38] Clarify comment. --- ObjectiveGitTests/GTRepositorySpec.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ObjectiveGitTests/GTRepositorySpec.m b/ObjectiveGitTests/GTRepositorySpec.m index ff3be837b..b1eced893 100644 --- a/ObjectiveGitTests/GTRepositorySpec.m +++ b/ObjectiveGitTests/GTRepositorySpec.m @@ -62,6 +62,8 @@ __block NSURL *originURL; __block NSURL *workdirURL; + // TODO: Make real remote tests using a repo somewhere + beforeEach(^{ error = nil; transferProgressCalled = NO; @@ -69,7 +71,7 @@ transferProgressBlock = ^(const git_transfer_progress *progress) { transferProgressCalled = YES; }; checkoutProgressBlock = ^(NSString *path, NSUInteger completedSteps, NSUInteger totalSteps) { checkoutProgressCalled = YES; }; - originURL = self.bareFixtureRepository.gitDirectoryURL; //[NSURL URLWithString: @"https://github.com/libgit2/TestGitRepository"]; + originURL = self.bareFixtureRepository.gitDirectoryURL; workdirURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"unit_test"]]; }); From 9bc13e26f008b02d62e6f5ef0797845f5d332cde Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Sat, 9 Nov 2013 13:29:36 +0100 Subject: [PATCH 23/38] Test the actual error domain & code. --- ObjectiveGitTests/GTRepositorySpec.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ObjectiveGitTests/GTRepositorySpec.m b/ObjectiveGitTests/GTRepositorySpec.m index b1eced893..54ef4e10b 100644 --- a/ObjectiveGitTests/GTRepositorySpec.m +++ b/ObjectiveGitTests/GTRepositorySpec.m @@ -51,6 +51,8 @@ GTRepository *badRepo = [GTRepository repositoryWithURL:[NSURL fileURLWithPath:@"fake/1235"] error:&error]; expect(badRepo).to.beNil(); expect(error).notTo.beNil(); + expect(error.domain).to.equal(GTGitErrorDomain); + expect(error.code).to.equal(GIT_ENOTFOUND); }); }); From b88903d17b98c317467a42a87aed884d316bc167 Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Thu, 24 Oct 2013 20:52:57 +0200 Subject: [PATCH 24/38] Convert local `file:` URLs to paths before handing over to `git_clone`. Fixes a bug where a locally-cloned remote would get a `file:` URL as it's origin URL, making the push machinery shrivel in fear. --- Classes/GTRepository.m | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Classes/GTRepository.m b/Classes/GTRepository.m index cbcc70749..50fff7263 100644 --- a/Classes/GTRepository.m +++ b/Classes/GTRepository.m @@ -218,8 +218,14 @@ + (id)cloneFromURL:(NSURL *)originURL toWorkingDirectory:(NSURL *)workdirURL opt cloneOptions.remote_callbacks.transfer_progress = transferProgressCallback; cloneOptions.remote_callbacks.payload = &payload; - const char *remoteURL = originURL.absoluteString.UTF8String; - const char *workingDirectoryPath = workdirURL.path.UTF8String; + // If our originURL is local, convert to a path before handing down. + const char *remoteURL = NULL; + if (originURL.isFileURL || originURL.isFileReferenceURL) { + remoteURL = originURL.filePathURL.path.fileSystemRepresentation; + } else { + remoteURL = originURL.absoluteString.UTF8String; + } + const char *workingDirectoryPath = workdirURL.path.fileSystemRepresentation; git_repository *repository; int gitError = git_clone(&repository, remoteURL, workingDirectoryPath, &cloneOptions); if (gitError < GIT_OK) { From 2b2be90ef782e9a5fafa9c2ba4e75e7706ab1825 Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Tue, 29 Oct 2013 18:37:53 +0100 Subject: [PATCH 25/38] Dot-syntaxify. --- Classes/GTRepository.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/GTRepository.m b/Classes/GTRepository.m index 50fff7263..681d87211 100644 --- a/Classes/GTRepository.m +++ b/Classes/GTRepository.m @@ -112,7 +112,7 @@ + (instancetype)initializeEmptyRepositoryAtFileURL:(NSURL *)localFileURL error:( } + (instancetype)initializeEmptyRepositoryAtFileURL:(NSURL *)localFileURL bare:(BOOL)bare error:(NSError **)error { - if (![localFileURL isFileURL] || localFileURL.path == nil) { + if (!localFileURL.isFileURL || localFileURL.path == nil) { if (error != NULL) *error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileWriteUnsupportedSchemeError userInfo:@{ NSLocalizedDescriptionKey: NSLocalizedString(@"Invalid file path URL to initialize repository.", @"") }]; return NO; } From 8265839fcde15333a40999763eb683f7f72b2fc4 Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Tue, 29 Oct 2013 18:38:09 +0100 Subject: [PATCH 26/38] Use `-fileSystemRepresentation` here. --- Classes/GTRepository.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/GTRepository.m b/Classes/GTRepository.m index 681d87211..bb15198e0 100644 --- a/Classes/GTRepository.m +++ b/Classes/GTRepository.m @@ -150,7 +150,7 @@ - (id)initWithURL:(NSURL *)localFileURL error:(NSError **)error { } git_repository *r; - int gitError = git_repository_open(&r, localFileURL.path.UTF8String); + int gitError = git_repository_open(&r, localFileURL.path.fileSystemRepresentation); if (gitError < GIT_OK) { if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Failed to open repository at URL %@.", localFileURL]; return nil; From bcdd9278e76e7b767d9f3214afe7a747a5baefad Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Tue, 29 Oct 2013 18:39:31 +0100 Subject: [PATCH 27/38] File reference URLs are file URLs; no need for a separate test. --- Classes/GTRepository.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/GTRepository.m b/Classes/GTRepository.m index bb15198e0..a0cb0ef04 100644 --- a/Classes/GTRepository.m +++ b/Classes/GTRepository.m @@ -220,7 +220,7 @@ + (id)cloneFromURL:(NSURL *)originURL toWorkingDirectory:(NSURL *)workdirURL opt // If our originURL is local, convert to a path before handing down. const char *remoteURL = NULL; - if (originURL.isFileURL || originURL.isFileReferenceURL) { + if (originURL.isFileURL) { remoteURL = originURL.filePathURL.path.fileSystemRepresentation; } else { remoteURL = originURL.absoluteString.UTF8String; From aa510a6a666e1d4228f4281263cf2d4ef48a36c3 Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Tue, 29 Oct 2013 18:40:19 +0100 Subject: [PATCH 28/38] Useless call; file reference URLs know how to path-ify themselves. --- Classes/GTRepository.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/GTRepository.m b/Classes/GTRepository.m index a0cb0ef04..324729f8b 100644 --- a/Classes/GTRepository.m +++ b/Classes/GTRepository.m @@ -221,7 +221,7 @@ + (id)cloneFromURL:(NSURL *)originURL toWorkingDirectory:(NSURL *)workdirURL opt // If our originURL is local, convert to a path before handing down. const char *remoteURL = NULL; if (originURL.isFileURL) { - remoteURL = originURL.filePathURL.path.fileSystemRepresentation; + remoteURL = originURL.path.fileSystemRepresentation; } else { remoteURL = originURL.absoluteString.UTF8String; } From 7f7cb21829049715a31a05887b6b56090ef4a036 Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Tue, 29 Oct 2013 19:01:33 +0100 Subject: [PATCH 29/38] =?UTF-8?q?Test=20that=20the=20remote=20set=20by=20`?= =?UTF-8?q?+clone=E2=80=A6`=20looks=20fine=20to=20libgit2.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ObjectiveGitTests/GTRepositorySpec.m | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/ObjectiveGitTests/GTRepositorySpec.m b/ObjectiveGitTests/GTRepositorySpec.m index 54ef4e10b..485d787d5 100644 --- a/ObjectiveGitTests/GTRepositorySpec.m +++ b/ObjectiveGitTests/GTRepositorySpec.m @@ -83,8 +83,8 @@ BOOL success = [NSFileManager.defaultManager removeItemAtURL:workdirURL error:&error]; expect(success).to.beTruthy(); expect(error).to.beNil(); - } - }); + } + }); it(@"should handle normal clones", ^{ repository = [GTRepository cloneFromURL:originURL toWorkingDirectory:workdirURL options:nil error:&error transferProgressBlock:transferProgressBlock checkoutProgressBlock:checkoutProgressBlock]; @@ -118,6 +118,20 @@ expect(head.targetSHA).to.equal(@"36060c58702ed4c2a40832c51758d5344201d89a"); expect(head.referenceType).to.equal(GTReferenceTypeOid); }); + + it(@"should have set a valid remote URL", ^{ + NSError *error = nil; + GTRepository *repo = [GTRepository cloneFromURL:originURL toWorkingDirectory:workdirURL options:nil error:&error transferProgressBlock:transferProgressBlock checkoutProgressBlock:checkoutProgressBlock]; + expect(repo).notTo.beNil(); + expect(error).to.beNil(); + + // FIXME: Move that to a method in GTRepository ? + // Or use the new initializers in GTRemote that are waiting in #224 + git_remote *remote; + git_remote_load(&remote, repo.git_repository, "origin"); + GTRemote *originRemote = [[GTRemote alloc] initWithGitRemote:remote]; + expect(originRemote.URLString).to.equal(originURL.path); + }); }); describe(@"-headReferenceWithError:", ^{ From 2986a6b99d6ffde59265cb70cdc4d263849a9959 Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Sat, 9 Nov 2013 13:53:33 +0100 Subject: [PATCH 30/38] De-oneline-ify. --- ObjectiveGitTests/GTRepositorySpec.m | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ObjectiveGitTests/GTRepositorySpec.m b/ObjectiveGitTests/GTRepositorySpec.m index 485d787d5..2a9ebedbb 100644 --- a/ObjectiveGitTests/GTRepositorySpec.m +++ b/ObjectiveGitTests/GTRepositorySpec.m @@ -70,8 +70,12 @@ error = nil; transferProgressCalled = NO; checkoutProgressCalled = NO; - transferProgressBlock = ^(const git_transfer_progress *progress) { transferProgressCalled = YES; }; - checkoutProgressBlock = ^(NSString *path, NSUInteger completedSteps, NSUInteger totalSteps) { checkoutProgressCalled = YES; }; + transferProgressBlock = ^(const git_transfer_progress *progress) { + transferProgressCalled = YES; + }; + checkoutProgressBlock = ^(NSString *path, NSUInteger completedSteps, NSUInteger totalSteps) { + checkoutProgressCalled = YES; + }; originURL = self.bareFixtureRepository.gitDirectoryURL; workdirURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"unit_test"]]; From cff180a6b61cfb4b8dd8b1633fc3720fb4a5d1aa Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Sat, 9 Nov 2013 14:15:49 +0100 Subject: [PATCH 31/38] Make `error` a local. --- ObjectiveGitTests/GTRepositorySpec.m | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/ObjectiveGitTests/GTRepositorySpec.m b/ObjectiveGitTests/GTRepositorySpec.m index 2a9ebedbb..30aa2c84a 100644 --- a/ObjectiveGitTests/GTRepositorySpec.m +++ b/ObjectiveGitTests/GTRepositorySpec.m @@ -12,12 +12,10 @@ SpecBegin(GTRepository) __block GTRepository *repository; -__block NSError *error = nil; beforeEach(^{ repository = self.testAppFixtureRepository; expect(repository).notTo.beNil(); - error = nil; }); describe(@"+initializeEmptyRepositoryAtFileURL:bare:error:", ^{ @@ -48,6 +46,7 @@ describe(@"+repositoryWithURL:error:", ^{ it(@"should fail to initialize non-existent repos", ^{ + NSError *error = nil; GTRepository *badRepo = [GTRepository repositoryWithURL:[NSURL fileURLWithPath:@"fake/1235"] error:&error]; expect(badRepo).to.beNil(); expect(error).notTo.beNil(); @@ -67,7 +66,6 @@ // TODO: Make real remote tests using a repo somewhere beforeEach(^{ - error = nil; transferProgressCalled = NO; checkoutProgressCalled = NO; transferProgressBlock = ^(const git_transfer_progress *progress) { @@ -91,6 +89,7 @@ }); it(@"should handle normal clones", ^{ + NSError *error = nil; repository = [GTRepository cloneFromURL:originURL toWorkingDirectory:workdirURL options:nil error:&error transferProgressBlock:transferProgressBlock checkoutProgressBlock:checkoutProgressBlock]; expect(repository).notTo.beNil(); expect(error).to.beNil(); @@ -107,6 +106,7 @@ }); it(@"should handle bare clones", ^{ + NSError *error = nil; NSDictionary *options = @{ GTRepositoryCloneOptionsBare: @YES }; repository = [GTRepository cloneFromURL:originURL toWorkingDirectory:workdirURL options:options error:&error transferProgressBlock:transferProgressBlock checkoutProgressBlock:checkoutProgressBlock]; expect(repository).notTo.beNil(); @@ -140,6 +140,7 @@ describe(@"-headReferenceWithError:", ^{ it(@"should allow HEAD to be looked up", ^{ + NSError *error = nil; GTReference *head = [self.bareFixtureRepository headReferenceWithError:&error]; expect(head).notTo.beNil(); expect(error).to.beNil(); @@ -154,6 +155,7 @@ }); it(@"should return YES for a new repository", ^{ + NSError *error = nil; NSURL *fileURL = [self.tempDirectoryFileURL URLByAppendingPathComponent:@"newrepo"]; GTRepository *newRepo = [GTRepository initializeEmptyRepositoryAtFileURL:fileURL error:&error]; expect(newRepo.isEmpty).to.beTruthy(); @@ -310,6 +312,7 @@ }); it(@"should move HEAD when used", ^{ + NSError *error = nil; GTReference *originalHead = [repository headReferenceWithError:NULL]; NSString *resetTargetSHA = @"8496071c1b46c854b31185ea97743be6a8774479"; @@ -340,10 +343,9 @@ beforeEach(^{ repository = self.bareFixtureRepository; - error = nil; expectSHAForRevspec = ^(NSString *SHA, NSString *revspec) { - error = nil; + NSError *error = nil; GTObject *obj = [repository lookupObjectByRevspec:revspec error:&error]; if (SHA != nil) { From cbe71f8bca3e5447ee9c7ce36de01525157afd82 Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Sat, 9 Nov 2013 14:24:53 +0100 Subject: [PATCH 32/38] Add methods to create new bare and non-bare repositories to `GTTestCase`. --- ObjectiveGitTests/GTRepositorySpec.m | 36 +++++++++------------------- ObjectiveGitTests/GTTestCase.h | 6 +++++ ObjectiveGitTests/GTTestCase.m | 16 +++++++++++++ 3 files changed, 33 insertions(+), 25 deletions(-) diff --git a/ObjectiveGitTests/GTRepositorySpec.m b/ObjectiveGitTests/GTRepositorySpec.m index 30aa2c84a..dd719fe23 100644 --- a/ObjectiveGitTests/GTRepositorySpec.m +++ b/ObjectiveGitTests/GTRepositorySpec.m @@ -19,27 +19,22 @@ }); describe(@"+initializeEmptyRepositoryAtFileURL:bare:error:", ^{ - __block GTRepository * (^createRepository)(BOOL bare); - - beforeEach(^{ - createRepository = ^(BOOL bare) { - NSURL *newRepoURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"unit_test"]]; - [NSFileManager.defaultManager removeItemAtURL:newRepoURL error:NULL]; - - GTRepository *repository = [GTRepository initializeEmptyRepositoryAtFileURL:newRepoURL bare:bare error:NULL]; - expect(repository).notTo.beNil(); - expect(repository.gitDirectoryURL).notTo.beNil(); - return repository; - }; - }); - it(@"should initialize a repository with a working directory by default", ^{ - GTRepository *repository = createRepository(NO); + NSURL *newRepoURL = [self.tempDirectoryFileURL URLByAppendingPathComponent:@"init-repo"]; + + GTRepository *repository = [GTRepository initializeEmptyRepositoryAtFileURL:newRepoURL bare:NO error:NULL]; + expect(repository).notTo.beNil(); + expect(repository.gitDirectoryURL).notTo.beNil(); expect(repository.bare).to.beFalsy(); }); it(@"should initialize a bare repository", ^{ - GTRepository *repository = createRepository(YES); + NSURL *newRepoURL = [self.tempDirectoryFileURL URLByAppendingPathComponent:@"init-repo.git"]; + + GTRepository *repository = [GTRepository initializeEmptyRepositoryAtFileURL:newRepoURL bare:YES error:NULL]; + expect(repository).notTo.beNil(); + expect(repository.gitDirectoryURL).notTo.beNil(); + return repository; expect(repository.bare).to.beTruthy(); }); }); @@ -79,15 +74,6 @@ workdirURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"unit_test"]]; }); - afterEach(^{ - if ([NSFileManager.defaultManager fileExistsAtPath:workdirURL.path isDirectory:NULL]) { - NSError *error = nil; - BOOL success = [NSFileManager.defaultManager removeItemAtURL:workdirURL error:&error]; - expect(success).to.beTruthy(); - expect(error).to.beNil(); - } - }); - it(@"should handle normal clones", ^{ NSError *error = nil; repository = [GTRepository cloneFromURL:originURL toWorkingDirectory:workdirURL options:nil error:&error transferProgressBlock:transferProgressBlock checkoutProgressBlock:checkoutProgressBlock]; diff --git a/ObjectiveGitTests/GTTestCase.h b/ObjectiveGitTests/GTTestCase.h index 2d67cc2d8..b29edee85 100644 --- a/ObjectiveGitTests/GTTestCase.h +++ b/ObjectiveGitTests/GTTestCase.h @@ -29,4 +29,10 @@ // A repository containing conflicts. - (GTRepository *)conflictedFixtureRepository; +// A pristine repository (bare). +- (GTRepository *)blankBareFixtureRepository; + +// A pristine repository. +- (GTRepository *)blankFixtureRepository; + @end diff --git a/ObjectiveGitTests/GTTestCase.m b/ObjectiveGitTests/GTTestCase.m index 14651cbc1..6b2b2cf2a 100644 --- a/ObjectiveGitTests/GTTestCase.m +++ b/ObjectiveGitTests/GTTestCase.m @@ -114,6 +114,22 @@ - (GTRepository *)conflictedFixtureRepository { return [self fixtureRepositoryNamed:@"conflicted-repo"]; } +- (GTRepository *)blankFixtureRepository { + NSURL *repoURL = [self.tempDirectoryFileURL URLByAppendingPathComponent:@"blank-repo"]; + + GTRepository *repository = [GTRepository initializeEmptyRepositoryAtFileURL:repoURL bare:NO error:NULL]; + STAssertNotNil(repository, @"Couldn't create a blank repository"); + return repository; +} + +- (GTRepository *)blankBareFixtureRepository { + NSURL *repoURL = [self.tempDirectoryFileURL URLByAppendingPathComponent:@"blank-repo.git"]; + + GTRepository *repository = [GTRepository initializeEmptyRepositoryAtFileURL:repoURL bare:YES error:NULL]; + STAssertNotNil(repository, @"Couldn't create a blank repository"); + return repository; +} + #pragma mark Properties - (NSBundle *)mainTestBundle { From c43cad57a8131bd395dc4f9064cf892c169dd528 Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Sat, 9 Nov 2013 13:56:40 +0100 Subject: [PATCH 33/38] Test that new repos have unborn HEADs. --- ObjectiveGitTests/GTRepositorySpec.m | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ObjectiveGitTests/GTRepositorySpec.m b/ObjectiveGitTests/GTRepositorySpec.m index dd719fe23..12034b488 100644 --- a/ObjectiveGitTests/GTRepositorySpec.m +++ b/ObjectiveGitTests/GTRepositorySpec.m @@ -133,6 +133,18 @@ expect(head.targetSHA).to.equal(@"36060c58702ed4c2a40832c51758d5344201d89a"); expect(head.referenceType).to.equal(GTReferenceTypeOid); }); + + it(@"should fail to return HEAD for an unborn repo", ^{ + GTRepository *repo = self.blankFixtureRepository; + expect(repo.isHEADUnborn).to.beTruthy(); + + NSError *error = nil; + GTReference *head = [repo headReferenceWithError:&error]; + expect(head).to.beNil(); + expect(error).notTo.beNil(); + expect(error.domain).to.equal(GTGitErrorDomain); + expect(error.code).to.equal(GIT_EUNBORNBRANCH); + }); }); describe(@"-isEmpty", ^{ From 3dd9c7027e58e9f0743fd53c7c2c32782141f18f Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Sat, 9 Nov 2013 14:16:15 +0100 Subject: [PATCH 34/38] Define `expectSHAForRevspec` inline. --- ObjectiveGitTests/GTRepositorySpec.m | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/ObjectiveGitTests/GTRepositorySpec.m b/ObjectiveGitTests/GTRepositorySpec.m index 12034b488..fe0010e5f 100644 --- a/ObjectiveGitTests/GTRepositorySpec.m +++ b/ObjectiveGitTests/GTRepositorySpec.m @@ -337,24 +337,22 @@ }); describe(@"-lookupObjectByRevspec:error:", ^{ - __block void (^expectSHAForRevspec)(NSString *SHA, NSString *revspec); + void (^expectSHAForRevspec)(NSString *SHA, NSString *revspec) = ^(NSString *SHA, NSString *revspec) { + NSError *error = nil; + GTObject *obj = [repository lookupObjectByRevspec:revspec error:&error]; + + if (SHA != nil) { + expect(error).to.beNil(); + expect(obj).notTo.beNil(); + expect(obj.SHA).to.equal(SHA); + } else { + expect(error).notTo.beNil(); + expect(obj).to.beNil(); + } + };; beforeEach(^{ repository = self.bareFixtureRepository; - - expectSHAForRevspec = ^(NSString *SHA, NSString *revspec) { - NSError *error = nil; - GTObject *obj = [repository lookupObjectByRevspec:revspec error:&error]; - - if (SHA != nil) { - expect(error).to.beNil(); - expect(obj).notTo.beNil(); - expect(obj.SHA).to.equal(SHA); - } else { - expect(error).notTo.beNil(); - expect(obj).to.beNil(); - } - }; }); it(@"should parse various revspecs", ^{ From 378b31d915f2797e21fd64391fcf2f51e95c41f8 Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Sat, 9 Nov 2013 14:36:07 +0100 Subject: [PATCH 35/38] Use the clone tests from #280. --- ObjectiveGitTests/GTRepositorySpec.m | 92 +++++++++++++++------------- 1 file changed, 49 insertions(+), 43 deletions(-) diff --git a/ObjectiveGitTests/GTRepositorySpec.m b/ObjectiveGitTests/GTRepositorySpec.m index fe0010e5f..5907cf064 100644 --- a/ObjectiveGitTests/GTRepositorySpec.m +++ b/ObjectiveGitTests/GTRepositorySpec.m @@ -50,7 +50,7 @@ }); }); -describe(@"+cloneFromURL:toWorkingDirectory:...", ^{ +describe(@"+cloneFromURL:toWorkingDirectory:options:error:transferProgressBlock:checkoutProgressBlock:", ^{ __block BOOL transferProgressCalled = NO; __block BOOL checkoutProgressCalled = NO; __block void (^transferProgressBlock)(const git_transfer_progress *); @@ -74,54 +74,60 @@ workdirURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"unit_test"]]; }); - it(@"should handle normal clones", ^{ - NSError *error = nil; - repository = [GTRepository cloneFromURL:originURL toWorkingDirectory:workdirURL options:nil error:&error transferProgressBlock:transferProgressBlock checkoutProgressBlock:checkoutProgressBlock]; - expect(repository).notTo.beNil(); - expect(error).to.beNil(); - expect(transferProgressCalled).to.beTruthy(); - expect(checkoutProgressCalled).to.beTruthy(); + describe(@"with local repositories", ^{ + beforeEach(^{ + originURL = self.bareFixtureRepository.gitDirectoryURL; + }); - expect(repository.isBare).to.beFalsy(); + it(@"should handle normal clones", ^{ + NSError *error = nil; + repository = [GTRepository cloneFromURL:originURL toWorkingDirectory:workdirURL options:nil error:&error transferProgressBlock:transferProgressBlock checkoutProgressBlock:checkoutProgressBlock]; + expect(repository).notTo.beNil(); + expect(error).to.beNil(); + expect(transferProgressCalled).to.beTruthy(); + expect(checkoutProgressCalled).to.beTruthy(); - GTReference *head = [repository headReferenceWithError:&error]; - expect(head).notTo.beNil(); - expect(error).to.beNil(); - expect(head.targetSHA).to.equal(@"36060c58702ed4c2a40832c51758d5344201d89a"); - expect(head.referenceType).to.equal(GTReferenceTypeOid); - }); + expect(repository.isBare).to.beFalsy(); - it(@"should handle bare clones", ^{ - NSError *error = nil; - NSDictionary *options = @{ GTRepositoryCloneOptionsBare: @YES }; - repository = [GTRepository cloneFromURL:originURL toWorkingDirectory:workdirURL options:options error:&error transferProgressBlock:transferProgressBlock checkoutProgressBlock:checkoutProgressBlock]; - expect(repository).notTo.beNil(); - expect(error).to.beNil(); - expect(transferProgressCalled).to.beTruthy(); - expect(checkoutProgressCalled).to.beTruthy(); + GTReference *head = [repository headReferenceWithError:&error]; + expect(head).notTo.beNil(); + expect(error).to.beNil(); + expect(head.targetSHA).to.equal(@"36060c58702ed4c2a40832c51758d5344201d89a"); + expect(head.referenceType).to.equal(GTReferenceTypeOid); + }); + + it(@"should handle bare clones", ^{ + NSError *error = nil; + NSDictionary *options = @{ GTRepositoryCloneOptionsBare: @YES }; + repository = [GTRepository cloneFromURL:originURL toWorkingDirectory:workdirURL options:options error:&error transferProgressBlock:transferProgressBlock checkoutProgressBlock:checkoutProgressBlock]; + expect(repository).notTo.beNil(); + expect(error).to.beNil(); + expect(transferProgressCalled).to.beTruthy(); + expect(checkoutProgressCalled).to.beTruthy(); - expect(repository.isBare).to.beTruthy(); + expect(repository.isBare).to.beTruthy(); - GTReference *head = [repository headReferenceWithError:&error]; - expect(head).notTo.beNil(); - expect(error).to.beNil(); - expect(head.targetSHA).to.equal(@"36060c58702ed4c2a40832c51758d5344201d89a"); - expect(head.referenceType).to.equal(GTReferenceTypeOid); - }); + GTReference *head = [repository headReferenceWithError:&error]; + expect(head).notTo.beNil(); + expect(error).to.beNil(); + expect(head.targetSHA).to.equal(@"36060c58702ed4c2a40832c51758d5344201d89a"); + expect(head.referenceType).to.equal(GTReferenceTypeOid); + }); + + it(@"should have set a valid remote URL", ^{ + NSError *error = nil; + GTRepository *repo = [GTRepository cloneFromURL:originURL toWorkingDirectory:workdirURL options:nil error:&error transferProgressBlock:transferProgressBlock checkoutProgressBlock:checkoutProgressBlock]; + expect(repo).notTo.beNil(); + expect(error).to.beNil(); - it(@"should have set a valid remote URL", ^{ - NSError *error = nil; - GTRepository *repo = [GTRepository cloneFromURL:originURL toWorkingDirectory:workdirURL options:nil error:&error transferProgressBlock:transferProgressBlock checkoutProgressBlock:checkoutProgressBlock]; - expect(repo).notTo.beNil(); - expect(error).to.beNil(); - - // FIXME: Move that to a method in GTRepository ? - // Or use the new initializers in GTRemote that are waiting in #224 - git_remote *remote; - git_remote_load(&remote, repo.git_repository, "origin"); - GTRemote *originRemote = [[GTRemote alloc] initWithGitRemote:remote]; - expect(originRemote.URLString).to.equal(originURL.path); - }); + // FIXME: Move that to a method in GTRepository ? + // Or use the new initializers in GTRemote that are waiting in #224 + git_remote *remote; + git_remote_load(&remote, repo.git_repository, "origin"); + GTRemote *originRemote = [[GTRemote alloc] initWithGitRemote:remote]; + expect(originRemote.URLString).to.equal(originURL.path); + }); + }); }); describe(@"-headReferenceWithError:", ^{ From 87efa7465ad142e793b3012537f3366720affc9c Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Sat, 9 Nov 2013 14:36:34 +0100 Subject: [PATCH 36/38] Put the newly-cloned repo in the test-case managed temporary directory. --- ObjectiveGitTests/GTRepositorySpec.m | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ObjectiveGitTests/GTRepositorySpec.m b/ObjectiveGitTests/GTRepositorySpec.m index 5907cf064..0e51e213c 100644 --- a/ObjectiveGitTests/GTRepositorySpec.m +++ b/ObjectiveGitTests/GTRepositorySpec.m @@ -70,8 +70,7 @@ checkoutProgressCalled = YES; }; - originURL = self.bareFixtureRepository.gitDirectoryURL; - workdirURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"unit_test"]]; + workdirURL = [self.tempDirectoryFileURL URLByAppendingPathComponent:@"temp-repo"]; }); describe(@"with local repositories", ^{ From 87fff3b27b354ee87f6cb6732b3cf465a74dfa40 Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Sat, 9 Nov 2013 14:39:34 +0100 Subject: [PATCH 37/38] Huh, bare clones don't checkout... --- ObjectiveGitTests/GTRepositorySpec.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ObjectiveGitTests/GTRepositorySpec.m b/ObjectiveGitTests/GTRepositorySpec.m index 0e51e213c..4d1ddee5a 100644 --- a/ObjectiveGitTests/GTRepositorySpec.m +++ b/ObjectiveGitTests/GTRepositorySpec.m @@ -102,7 +102,7 @@ expect(repository).notTo.beNil(); expect(error).to.beNil(); expect(transferProgressCalled).to.beTruthy(); - expect(checkoutProgressCalled).to.beTruthy(); + expect(checkoutProgressCalled).to.beFalsy(); expect(repository.isBare).to.beTruthy(); From 9936d06ab0cf1b46e81a1e880c43051b44dd2af1 Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Wed, 13 Nov 2013 12:41:16 +0100 Subject: [PATCH 38/38] =?UTF-8?q?Rename=20`=E2=80=A6Revspec:`=20=3D>=20`?= =?UTF-8?q?=E2=80=A6RevParse:`.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Classes/GTRepository.h | 2 +- Classes/GTRepository.m | 4 ++-- ObjectiveGitTests/GTRepositorySpec.m | 18 +++++++++--------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Classes/GTRepository.h b/Classes/GTRepository.h index 92abed5c1..cef74f095 100644 --- a/Classes/GTRepository.h +++ b/Classes/GTRepository.h @@ -176,7 +176,7 @@ extern NSString *const GTRepositoryCloneOptionsCredentialProvider; - (id)lookupObjectBySHA:(NSString *)sha error:(NSError **)error; // Lookup an object in the repo using a revparse spec -- (id)lookupObjectByRevspec:(NSString *)spec error:(NSError **)error; +- (id)lookupObjectByRevParse:(NSString *)spec error:(NSError **)error; // List all references in the repository // diff --git a/Classes/GTRepository.m b/Classes/GTRepository.m index 38ddd9475..070eec818 100644 --- a/Classes/GTRepository.m +++ b/Classes/GTRepository.m @@ -276,11 +276,11 @@ - (id)lookupObjectBySHA:(NSString *)sha error:(NSError **)error { return [self lookupObjectBySHA:sha objectType:GTObjectTypeAny error:error]; } -- (id)lookupObjectByRevspec:(NSString *)spec error:(NSError **)error { +- (id)lookupObjectByRevParse:(NSString *)spec error:(NSError **)error { git_object *obj; int gitError = git_revparse_single(&obj, self.git_repository, spec.UTF8String); if (gitError < GIT_OK) { - if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Failed to lookup object by refspec %@.", spec]; + if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Revision specifier lookup failed." failureReason:@"The revision specifier \"%@\" couldn't be parsed.", spec]; return nil; } return [GTObject objectWithObj:obj inRepository:self]; diff --git a/ObjectiveGitTests/GTRepositorySpec.m b/ObjectiveGitTests/GTRepositorySpec.m index 4d1ddee5a..3ecffb3b9 100644 --- a/ObjectiveGitTests/GTRepositorySpec.m +++ b/ObjectiveGitTests/GTRepositorySpec.m @@ -341,10 +341,10 @@ }); }); -describe(@"-lookupObjectByRevspec:error:", ^{ - void (^expectSHAForRevspec)(NSString *SHA, NSString *revspec) = ^(NSString *SHA, NSString *revspec) { +describe(@"-lookupObjectByRevParse:error:", ^{ + void (^expectSHAForRevParse)(NSString *, NSString *) = ^(NSString *SHA, NSString *spec) { NSError *error = nil; - GTObject *obj = [repository lookupObjectByRevspec:revspec error:&error]; + GTObject *obj = [repository lookupObjectByRevParse:spec error:&error]; if (SHA != nil) { expect(error).to.beNil(); @@ -361,12 +361,12 @@ }); it(@"should parse various revspecs", ^{ - expectSHAForRevspec(@"36060c58702ed4c2a40832c51758d5344201d89a", @"master"); - expectSHAForRevspec(@"5b5b025afb0b4c913b4c338a42934a3863bf3644", @"master~"); - expectSHAForRevspec(@"8496071c1b46c854b31185ea97743be6a8774479", @"master@{2}"); - expectSHAForRevspec(nil, @"master^2"); - expectSHAForRevspec(nil, @""); - expectSHAForRevspec(@"0c37a5391bbff43c37f0d0371823a5509eed5b1d", @"v1.0"); + expectSHAForRevParse(@"36060c58702ed4c2a40832c51758d5344201d89a", @"master"); + expectSHAForRevParse(@"5b5b025afb0b4c913b4c338a42934a3863bf3644", @"master~"); + expectSHAForRevParse(@"8496071c1b46c854b31185ea97743be6a8774479", @"master@{2}"); + expectSHAForRevParse(nil, @"master^2"); + expectSHAForRevParse(nil, @""); + expectSHAForRevParse(@"0c37a5391bbff43c37f0d0371823a5509eed5b1d", @"v1.0"); }); });