Permalink
Browse files

Merge from master.

  • Loading branch information...
2 parents a969ffb + 3e69046 commit 6d84b1ba527eb40ccb0bd8155f1287554aa03d1e Danny Greg committed Mar 28, 2013
View
8 Classes/GTConfiguration+Private.h
@@ -14,4 +14,12 @@
@property (nonatomic, readwrite, unsafe_unretained) GTRepository *repository;
+// Initializes the receiver.
+//
+// config - The libgit2 config. Cannot be NULL.
+// repository - The repository in which the config resides. May be nil.
+//
+// Returns the initialized object.
+- (id)initWithGitConfig:(git_config *)config repository:(GTRepository *)repository;
+
@end
View
7 Classes/GTConfiguration.h
@@ -16,10 +16,13 @@
@property (nonatomic, readonly, unsafe_unretained) GTRepository *repository;
@property (nonatomic, readonly, copy) NSArray *configurationKeys;
-// The GTRemotes in the config.
+// The GTRemotes in the config. If the configuration isn't associated with any
+// repository, this will always be nil.
@property (nonatomic, readonly, copy) NSArray *remotes;
-- (id)initWithGitConfig:(git_config *)config repository:(GTRepository *)repository;
+// Creates and returns a configuration which includes the global, XDG, and
+// system configurations.
++ (instancetype)defaultConfiguration;
- (void)setString:(NSString *)s forKey:(NSString *)key;
- (NSString *)stringForKey:(NSString *)key;
View
24 Classes/GTConfiguration.m
@@ -14,13 +14,15 @@
@implementation GTConfiguration
+#pragma mark Lifecycle
+
- (void)dealloc {
git_config_free(self.git_config);
}
-#pragma mark API
-
- (id)initWithGitConfig:(git_config *)config repository:(GTRepository *)repository {
+ NSParameterAssert(config != NULL);
+
self = [super init];
if (self == nil) return nil;
@@ -30,6 +32,16 @@ - (id)initWithGitConfig:(git_config *)config repository:(GTRepository *)reposito
return self;
}
++ (instancetype)defaultConfiguration {
+ git_config *config = NULL;
+ int error = git_config_open_default(&config);
+ if (error != GIT_OK || config == NULL) return nil;
+
+ return [[self alloc] initWithGitConfig:config repository:nil];
+}
+
+#pragma mark Read/Write
+
- (void)setString:(NSString *)s forKey:(NSString *)key {
git_config_set_string(self.git_config, key.UTF8String, s.UTF8String);
}
@@ -97,6 +109,8 @@ - (NSArray *)configurationKeys {
}
- (NSArray *)remotes {
+ if (self.repository == NULL) return nil;
+
git_strarray names;
git_remote_list(&names, self.repository.git_repository);
NSMutableArray *remotes = [NSMutableArray arrayWithCapacity:names.count];
@@ -114,10 +128,12 @@ - (NSArray *)remotes {
return remotes;
}
+#pragma mark Refresh
+
- (BOOL)refresh:(NSError **)error {
int success = git_config_refresh(self.git_config);
- if (success != 0) {
- if (error != NULL) *error = [NSError git_errorFor:success withAdditionalDescription:@"Couldn't reload the repository configuration from disk."];
+ if (success != GIT_OK) {
+ if (error != NULL) *error = [NSError git_errorFor:success withAdditionalDescription:@"Couldn't reload the configuration from disk."];
return NO;
}
View
4 ObjectiveGitFramework.xcodeproj/project.pbxproj
@@ -113,6 +113,7 @@
887DAFFD15CB1CE200F30D0D /* libssl.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 887DAFF915CB1C9F00F30D0D /* libssl.dylib */; };
88A994BA16FCE7D400402C7B /* GTBranchSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 88A994B916FCE7D400402C7B /* GTBranchSpec.m */; };
88A994CB16FCED1D00402C7B /* GTTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = 88A994CA16FCED1D00402C7B /* GTTestCase.m */; };
+ 88C0BC5917038CF3009E99AA /* GTConfigurationSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 88C0BC5817038CF3009E99AA /* GTConfigurationSpec.m */; };
88EB7E4D14AEBA600046FEA4 /* GTConfiguration.h in Headers */ = {isa = PBXBuildFile; fileRef = 88EB7E4B14AEBA600046FEA4 /* GTConfiguration.h */; settings = {ATTRIBUTES = (Public, ); }; };
88EB7E4E14AEBA600046FEA4 /* GTConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = 88EB7E4C14AEBA600046FEA4 /* GTConfiguration.m */; };
88F05A9D16011F6A00B7AD1D /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 88F05A9C16011F6A00B7AD1D /* SenTestingKit.framework */; };
@@ -324,6 +325,7 @@
88A994B916FCE7D400402C7B /* GTBranchSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTBranchSpec.m; sourceTree = "<group>"; };
88A994C916FCED1D00402C7B /* GTTestCase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GTTestCase.h; sourceTree = "<group>"; };
88A994CA16FCED1D00402C7B /* GTTestCase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTTestCase.m; sourceTree = "<group>"; };
+ 88C0BC5817038CF3009E99AA /* GTConfigurationSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTConfigurationSpec.m; sourceTree = "<group>"; };
88EB7E4B14AEBA600046FEA4 /* GTConfiguration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GTConfiguration.h; sourceTree = "<group>"; };
88EB7E4C14AEBA600046FEA4 /* GTConfiguration.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTConfiguration.m; sourceTree = "<group>"; };
88F05A6B16011E5400B7AD1D /* ObjectiveGitTests.octest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ObjectiveGitTests.octest; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -543,6 +545,7 @@
30865A90167F503400B1AB6E /* GTDiffSpec.m */,
88A994B916FCE7D400402C7B /* GTBranchSpec.m */,
30B1E7FF1703871900D0814D /* GTTimeAdditionsSpec.m */,
+ 88C0BC5817038CF3009E99AA /* GTConfigurationSpec.m */,
88F05AAF16011FFD00B7AD1D /* ObjectiveGitTests-Info.plist */,
88F05AB016011FFD00B7AD1D /* ObjectiveGitTests-Prefix.pch */,
88F05A7616011E5400B7AD1D /* Supporting Files */,
@@ -1020,6 +1023,7 @@
88A994BA16FCE7D400402C7B /* GTBranchSpec.m in Sources */,
88A994CB16FCED1D00402C7B /* GTTestCase.m in Sources */,
30B1E8001703871900D0814D /* GTTimeAdditionsSpec.m in Sources */,
+ 88C0BC5917038CF3009E99AA /* GTConfigurationSpec.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
50 ObjectiveGitTests/GTConfigurationSpec.m
@@ -0,0 +1,50 @@
+//
+// GTConfigurationSpec.m
+// ObjectiveGitFramework
+//
+// Created by Josh Abernathy on 3/27/13.
+// Copyright (c) 2013 GitHub, Inc. All rights reserved.
+//
+
+#import "GTConfiguration.h"
+
+SpecBegin(GTConfiguration)
+
+describe(@"+defaultConfiguration", ^{
+ static NSString * const testKey = @"universe.answer";
+ static NSString * const testValue = @"42, probably";
+
+ __block GTConfiguration *config;
+
+ beforeEach(^{
+ config = [GTConfiguration defaultConfiguration];
+ expect(config).notTo.beNil();
+ });
+
+ it(@"should return nil for -remotes", ^{
+ expect(config.remotes).to.beNil();
+ });
+
+ it(@"should support reading and writing", ^{
+ id value = [config stringForKey:testKey];
+ expect(value).to.beNil();
+
+ [config setString:testValue forKey:testKey];
+ value = [config stringForKey:testKey];
+ expect(value).to.equal(testValue);
+ });
+
+ it(@"should support deletion", ^{
+ [config setString:testValue forKey:testKey];
+ id value = [config stringForKey:testKey];
+ expect(value).notTo.beNil();
+
+ BOOL success = [config deleteValueForKey:testKey error:NULL];
+ expect(success).to.beTruthy();
+
+ value = [config stringForKey:testKey];
+ expect(value).to.beNil();
+ });
+});
+
+SpecEnd

0 comments on commit 6d84b1b

Please sign in to comment.