Skip to content

Commit 92960f1

Browse files
authored
Fix some “Stage All” special cases (#1037)
* syncIndexWithWorkingDirectory: Fix failure to stage deletions of conflicting files * syncIndexWithWorkingDirectory: Fix failure to stage unadded submodules (Not always but) repository folders that weren't registered in .gitmodules would cause the method to fail: “libgit2 error (-4): submodule 'submodules/transfer-photo-albums/' has not been added yet” * Properly propagate staging errors in -addFilesToIndex:error: When addFileInWorkingDirectory encountered an error, it would return YES regardless. * addFilesToIndex: Don't give up after failing to stage a file Also, rename `shouldWriteRepository` to the more appropriate `needsToWriteIndex`. * syncIndexWithWorkingDirectory: Fix crash when called with no error pointer
1 parent 42b8a55 commit 92960f1

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

GitUpKit/Extensions/GCRepository+Index.m

+9-7
Original file line numberDiff line numberDiff line change
@@ -69,24 +69,26 @@ - (BOOL)addFilesToIndex:(NSArray<NSString*>*)paths error:(NSError**)error {
6969
}
7070

7171
BOOL failed = NO;
72-
BOOL shouldWriteRepository = NO;
72+
BOOL needsToWriteIndex = NO;
7373
for (NSString* path in paths) {
7474
if (![self addFileInWorkingDirectory:path toIndex:index error:error] || (error && *error != nil)) {
7575
failed = YES;
76-
break;
76+
continue;
7777
}
7878

79-
shouldWriteRepository = YES;
79+
needsToWriteIndex = YES;
8080
}
8181

82-
if (failed && shouldWriteRepository) {
83-
if (shouldWriteRepository) {
82+
if (needsToWriteIndex) {
83+
if (failed) {
8484
[self writeRepositoryIndex:index error:NULL];
85+
return NO;
8586
}
86-
return NO;
87+
88+
return [self writeRepositoryIndex:index error:error];
8789
}
8890

89-
return [self writeRepositoryIndex:index error:error];
91+
return !failed;
9092
}
9193

9294
- (BOOL)resetFileInIndexToHEAD:(NSString*)path error:(NSError**)error {

GitUpKit/Extensions/GCRepository+Utilities.m

+12-2
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,21 @@ - (BOOL)syncIndexWithWorkingDirectory:(NSError**)error {
205205
if (delta.submodule) {
206206
GCSubmodule* submodule = [self lookupSubmoduleWithName:delta.canonicalPath error:error];
207207
if (!submodule || ![self addSubmoduleToRepositoryIndex:submodule error:error]) {
208-
return NO;
208+
BOOL wasJustTryingToStageAnUntrackedSubmodule = error && [[*error localizedDescription] hasSuffix:@"' has not been added yet"];
209+
210+
if (!wasJustTryingToStageAnUntrackedSubmodule) {
211+
return NO;
212+
}
209213
}
210214
} else {
211215
if (![self addFileInWorkingDirectory:delta.canonicalPath toIndex:index error:error]) {
212-
return NO;
216+
BOOL wasJustTryingToStageADeletedConflictingFile =
217+
delta.change == kGCFileDiffChange_Conflicted
218+
&& (error && [[*error localizedDescription] isEqualToString:@"No such file or directory"]);
219+
220+
if (!wasJustTryingToStageADeletedConflictingFile) {
221+
return NO;
222+
}
213223
}
214224
}
215225
break;

0 commit comments

Comments
 (0)