Skip to content

Commit cfb487c

Browse files
committed
Fix nullability warnings introduced in Xcode 10
1 parent 8927e23 commit cfb487c

12 files changed

+70
-28
lines changed

ObjectiveGit/GTBlameHunk.m

+3-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ - (GTSignature *)finalSignature {
3939
}
4040

4141
- (NSString *)originalPath {
42-
return @(self.git_blame_hunk.orig_path);
42+
NSString *path = @(self.git_blame_hunk.orig_path);
43+
NSAssert(path, @"string was nil");
44+
return path;
4345
}
4446

4547
- (BOOL)isBoundary {

ObjectiveGit/GTConfiguration.m

+4-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@ - (BOOL)deleteValueForKey:(NSString *)key error:(NSError **)error {
112112
static int configCallback(const git_config_entry *entry, void *payload) {
113113
NSMutableArray *configurationKeysArray = (__bridge NSMutableArray *)payload;
114114

115-
[configurationKeysArray addObject:@(entry->name)];
115+
NSString *name = @(entry->name);
116+
NSCAssert(name, @"string was nil");
117+
118+
[configurationKeysArray addObject:name];
116119

117120
return 0;
118121
}

ObjectiveGit/GTDiffFile.m

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ - (instancetype)initWithGitDiffFile:(git_diff_file)file {
2222
self = [super init];
2323
if (self == nil) return nil;
2424

25-
_path = @(file.path);
26-
if (_path == nil) return nil;
25+
NSString *path = @(file.path);
26+
if (path == nil) return nil;
27+
_path = path;
2728

2829
_git_diff_file = file;
2930
_size = (NSUInteger)file.size;

ObjectiveGit/GTFilterSource.m

+7-4
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,13 @@ - (instancetype)initWithGitFilterSource:(const git_filter_source *)source {
2727
self = [super init];
2828
if (self == nil) return nil;
2929

30-
const char *path = git_repository_workdir(git_filter_source_repo(source));
31-
_repositoryURL = [NSURL fileURLWithPath:@(path)];
32-
33-
_path = @(git_filter_source_path(source));
30+
NSString *path = @(git_repository_workdir(git_filter_source_repo(source)));
31+
NSAssert(path, @"workdir was nil");
32+
_repositoryURL = [NSURL fileURLWithPath:path];
33+
34+
path = @(git_filter_source_path(source));
35+
NSAssert(path, @"path was nil");
36+
_path = path;
3437

3538
const git_oid *gitOid = git_filter_source_id(source);
3639
if (gitOid != NULL) _OID = [[GTOID alloc] initWithGitOid:gitOid];

ObjectiveGit/GTIndexEntry.m

+3-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ - (instancetype)initWithGitIndexEntry:(const git_index_entry *)entry {
7474
#pragma mark Properties
7575

7676
- (NSString *)path {
77-
return @(self.git_index_entry->path);
77+
NSString *path = @(self.git_index_entry->path);
78+
NSAssert(path, @"path is nil");
79+
return path;
7880
}
7981

8082
- (int)flags {

ObjectiveGit/GTNote.m

+3-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ - (git_note *)git_note {
4242
}
4343

4444
- (NSString *)note {
45-
return @(git_note_message(self.git_note));
45+
NSString *message = @(git_note_message(self.git_note));
46+
NSAssert(message, @"message is nil");
47+
return message;
4648
}
4749

4850
- (GTSignature *)author {

ObjectiveGit/GTReference.m

+5-3
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,12 @@ - (BOOL)isNote {
118118
}
119119

120120
- (NSString *)name {
121-
const char *refName = git_reference_name(self.git_reference);
122-
NSAssert(refName != nil, @"Unexpected nil name");
121+
const char *cRefName = git_reference_name(self.git_reference);
122+
NSAssert(cRefName != nil, @"Unexpected nil name");
123123

124-
return @(refName);
124+
NSString *refName = @(cRefName);
125+
NSAssert(refName, @"refname is nil");
126+
return refName;
125127
}
126128

127129
- (GTReference *)referenceByRenaming:(NSString *)newName error:(NSError **)error {

ObjectiveGit/GTRepository+RemoteOperations.m

+8-2
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,15 @@ int GTFetchHeadEntriesCallback(const char *ref_name, const char *remote_url, con
126126
GTRepository *repository = entriesPayload->repository;
127127
GTRemoteEnumerateFetchHeadEntryBlock enumerationBlock = entriesPayload->enumerationBlock;
128128

129-
GTReference *reference = [repository lookUpReferenceWithName:@(ref_name) error:NULL];
129+
NSString *refName = @(ref_name);
130+
NSCAssert(refName, @"refName is nil");
130131

131-
GTFetchHeadEntry *entry = [[GTFetchHeadEntry alloc] initWithReference:reference remoteURLString:@(remote_url) targetOID:[GTOID oidWithGitOid:oid] isMerge:(BOOL)is_merge];
132+
NSString *remoteURL = @(remote_url);
133+
NSCAssert(remote_url, @"remoteURL is nil");
134+
135+
GTReference *reference = [repository lookUpReferenceWithName:refName error:NULL];
136+
137+
GTFetchHeadEntry *entry = [[GTFetchHeadEntry alloc] initWithReference:reference remoteURLString:remoteURL targetOID:[GTOID oidWithGitOid:oid] isMerge:(BOOL)is_merge];
132138

133139
BOOL stop = NO;
134140

ObjectiveGit/GTRepository.m

+13-7
Original file line numberDiff line numberDiff line change
@@ -637,18 +637,22 @@ - (NSArray *)referenceNamesWithError:(NSError **)error {
637637
}
638638

639639
- (NSURL *)fileURL {
640-
const char *path = git_repository_workdir(self.git_repository);
640+
const char *cPath = git_repository_workdir(self.git_repository);
641641
// bare repository, you may be looking for gitDirectoryURL
642-
if (path == NULL) return nil;
642+
if (cPath == NULL) return nil;
643643

644-
return [NSURL fileURLWithPath:@(path) isDirectory:YES];
644+
NSString *path = @(cPath);
645+
NSAssert(path, @"workdir is nil");
646+
return [NSURL fileURLWithPath:path isDirectory:YES];
645647
}
646648

647649
- (NSURL *)gitDirectoryURL {
648-
const char *path = git_repository_path(self.git_repository);
649-
if (path == NULL) return nil;
650+
const char *cPath = git_repository_path(self.git_repository);
651+
if (cPath == NULL) return nil;
650652

651-
return [NSURL fileURLWithPath:@(path) isDirectory:YES];
653+
NSString *path = @(cPath);
654+
NSAssert(path, @"gitdirectory is nil");
655+
return [NSURL fileURLWithPath:path isDirectory:YES];
652656
}
653657

654658
- (BOOL)isBare {
@@ -737,7 +741,9 @@ static int submoduleEnumerationCallback(git_submodule *git_submodule, const char
737741

738742
NSError *error;
739743
// Use -submoduleWithName:error: so that we get a git_submodule that we own.
740-
GTSubmodule *submodule = [info->parentRepository submoduleWithName:@(name) error:&error];
744+
NSString *submoduleName = @(name);
745+
NSCAssert(submoduleName, @"submodule name is nil");
746+
GTSubmodule *submodule = [info->parentRepository submoduleWithName:submoduleName error:&error];
741747

742748
BOOL stop = NO;
743749
info->block(submodule, error, &stop);

ObjectiveGit/GTSubmodule.m

+12-3
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,30 @@ - (NSString *)name {
6262
const char *cName = git_submodule_name(self.git_submodule);
6363
NSAssert(cName != NULL, @"Unexpected nil submodule name");
6464

65-
return @(cName);
65+
NSString *name = @(cName);
66+
NSAssert(name, @"name is nil");
67+
68+
return name;
6669
}
6770

6871
- (NSString *)path {
6972
const char *cPath = git_submodule_path(self.git_submodule);
7073
NSAssert(cPath != NULL, @"Unexpected nil submodule path");
7174

72-
return @(cPath);
75+
NSString *path = @(cPath);
76+
NSAssert(path, @"message is nil");
77+
78+
return path;
7379
}
7480

7581
- (NSString *)URLString {
7682
const char *cURL = git_submodule_url(self.git_submodule);
7783
NSAssert(cURL != NULL, @"Unexpected nil submodule URL");
7884

79-
return @(cURL);
85+
NSString *URL = @(cURL);
86+
NSAssert(URL, @"URL is nil");
87+
88+
return URL;
8089
}
8190

8291
#pragma mark Lifecycle

ObjectiveGit/GTTag.m

+6-2
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,15 @@ - (NSString *)description {
4747
#pragma mark API
4848

4949
- (NSString *)message {
50-
return @(git_tag_message(self.git_tag));
50+
NSString *message = @(git_tag_message(self.git_tag));
51+
NSAssert(message, @"message is nil");
52+
return message;
5153
}
5254

5355
- (NSString *)name {
54-
return @(git_tag_name(self.git_tag));
56+
NSString *name = @(git_tag_name(self.git_tag));
57+
NSAssert(name, @"message is nil");
58+
return name;
5559
}
5660

5761
- (GTObject *)target {

ObjectiveGit/GTTreeEntry.m

+3-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ + (instancetype)entryWithEntry:(const git_tree_entry *)theEntry parentTree:(GTTr
9494
}
9595

9696
- (NSString *)name {
97-
return @(git_tree_entry_name(self.git_tree_entry));
97+
NSString *name = @(git_tree_entry_name(self.git_tree_entry));
98+
NSAssert(name, @"name was nil");
99+
return name;
98100
}
99101

100102
- (NSInteger)attributes {

0 commit comments

Comments
 (0)