Skip to content

Commit 2314def

Browse files
committed
Rewire the index tasking through the non-deprecated methods
1 parent bee661a commit 2314def

File tree

1 file changed

+57
-34
lines changed

1 file changed

+57
-34
lines changed

Classes/git/PBGitIndex.m

Lines changed: 57 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,12 @@ - (void)commitWithMessage:(NSString *)commitMessage andVerify:(BOOL) doVerify
289289

290290

291291
[self postCommitUpdate:@"Creating tree"];
292-
NSString *tree = [self.repository outputForCommand:@"write-tree"];
292+
NSError *error = nil;
293+
NSString *tree = [self.repository outputOfTaskWithArguments:@[@"write-tree"] error:&error];
294+
if (!tree) {
295+
PBLogError(error);
296+
return [self postCommitFailure:@"Failed to lookup tree"];
297+
}
293298
tree = [tree stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
294299
if ([tree length] != 40)
295300
return [self postCommitFailure:@"Creating tree failed"];
@@ -303,7 +308,6 @@ - (void)commitWithMessage:(NSString *)commitMessage andVerify:(BOOL) doVerify
303308
}
304309

305310
[self postCommitUpdate:@"Creating commit"];
306-
int ret = 1;
307311

308312
if (doVerify) {
309313
[self postCommitUpdate:@"Running hooks"];
@@ -333,24 +337,28 @@ - (void)commitWithMessage:(NSString *)commitMessage andVerify:(BOOL) doVerify
333337
}
334338

335339
commitMessage = [NSString stringWithContentsOfFile:commitMessageFile encoding:NSUTF8StringEncoding error:nil];
336-
337-
NSString *commit = [self.repository outputForArguments:arguments
338-
inputString:commitMessage
339-
byExtendingEnvironment:self.amendEnvironment
340-
retValue: &ret];
341-
commit = [commit stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
342-
if (ret || [commit length] != 40)
340+
341+
PBTask *task = [self.repository taskWithArguments:arguments];
342+
task.additionalEnvironment = self.amendEnvironment;
343+
task.standardInputData = [commitMessage dataUsingEncoding:NSUTF8StringEncoding];
344+
345+
BOOL success = [task launchTask:&error];
346+
NSString *commit = [[task standardOutputString] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
347+
if (!success || commit.length != 40) {
348+
PBLogError(error);
343349
return [self postCommitFailure:@"Could not create a commit object"];
350+
}
344351

345352
[self postCommitUpdate:@"Updating HEAD"];
346-
[self.repository outputForArguments:[NSArray arrayWithObjects:@"update-ref", @"-m", commitSubject, @"HEAD", commit, nil]
347-
retValue: &ret];
348-
if (ret)
353+
success = [self.repository launchTaskWithArguments:@[@"update-ref", @"-m", commitSubject, @"HEAD", commit] error:&error];
354+
if (!success) {
355+
PBLogError(error);
349356
return [self postCommitFailure:@"Could not update HEAD"];
357+
}
350358

351359
[self postCommitUpdate:@"Running post-commit hook"];
352360

353-
BOOL success = [self.repository executeHook:@"post-commit" error:NULL];
361+
success = [self.repository executeHook:@"post-commit" error:NULL];
354362
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithObject:[NSNumber numberWithBool:success] forKey:@"success"];
355363
NSString *description;
356364
if (success)
@@ -446,19 +454,19 @@ - (BOOL)performStageOrUnstage:(BOOL)stage withFiles:(NSArray *)files
446454
}
447455
}
448456

449-
int ret = 1;
457+
NSArray *arguments = nil;
450458
if (stage) {
451-
[self.repository outputForArguments:[NSArray arrayWithObjects:@"update-index", @"--add", @"--remove", @"-z", @"--stdin", nil]
452-
inputString:input
453-
retValue:&ret];
459+
arguments = @[@"update-index", @"--add", @"--remove", @"-z", @"--stdin"];
454460
} else {
455-
[self.repository outputForArguments:[NSArray arrayWithObjects:@"update-index", @"-z", @"--index-info", nil]
456-
inputString:input
457-
retValue:&ret];
461+
arguments = @[@"update-index", @"-z", @"--index-info"];
458462
}
459463

460-
if (ret) {
461-
[self postOperationFailed:[NSString stringWithFormat:@"Error in %@ files. Return value: %i", (stage ? @"staging" : @"unstaging"), ret]];
464+
NSError *error = nil;
465+
BOOL success = [self.repository launchTaskWithArguments:arguments
466+
input:input
467+
error:&error];
468+
if (!success) {
469+
[self postOperationFailed:[NSString stringWithFormat:@"Error in %@ files. Return value: %@", (stage ? @"staging" : @"unstaging"), error.userInfo[PBTaskTerminationStatusKey]]];
462470
return NO;
463471
}
464472

@@ -524,13 +532,14 @@ - (BOOL)applyPatch:(NSString *)hunk stage:(BOOL)stage reverse:(BOOL)reverse;
524532
if (reverse)
525533
[array addObject:@"--reverse"];
526534

527-
int ret = 1;
528-
NSString *error = [self.repository outputForArguments:array
529-
inputString:hunk
530-
retValue:&ret];
535+
NSError *error = nil;
536+
NSString *output = [self.repository outputOfTaskWithArguments:array
537+
input:hunk
538+
error:&error];
531539

532-
if (ret) {
533-
[self postOperationFailed:[NSString stringWithFormat:@"Applying patch failed with return value %i. Error: %@", ret, error]];
540+
if (!output) {
541+
NSString *message = [NSString stringWithFormat:@"Applying patch failed with return value %@. Error: %@", error.userInfo[PBTaskTerminationStatusKey], error.userInfo[PBTaskTerminationOutputKey]];
542+
[self postOperationFailed:message];
534543
return NO;
535544
}
536545

@@ -544,12 +553,20 @@ - (NSString *)diffForFile:(PBChangedFile *)file staged:(BOOL)staged contextLines
544553
{
545554
NSString *parameter = [NSString stringWithFormat:@"-U%lu", context];
546555
if (staged) {
547-
NSString *indexPath = [@":0:" stringByAppendingString:file.path];
548-
549-
if (file.status == NEW)
550-
return [self.repository outputForArguments:[NSArray arrayWithObjects:@"show", indexPath, nil]];
556+
NSArray *arguments = nil;
557+
if (file.status == NEW) {
558+
NSString *indexPath = [@":0:" stringByAppendingString:file.path];
559+
arguments = @[@"show", indexPath];
560+
} else {
561+
arguments = @[@"diff-index", parameter, @"--cached", self.parentTree, @"--", file.path];
562+
}
551563

552-
return [self.repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"diff-index", parameter, @"--cached", [self parentTree], @"--", file.path, nil]];
564+
NSError *error = nil;
565+
NSString *output = [self.repository outputOfTaskWithArguments:arguments error:&error];
566+
if (!output) {
567+
PBLogError(error);
568+
}
569+
return output;
553570
}
554571

555572
// unstaged
@@ -563,7 +580,13 @@ - (NSString *)diffForFile:(PBChangedFile *)file staged:(BOOL)staged contextLines
563580
return contents;
564581
}
565582

566-
return [self.repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"diff-files", parameter, @"--", file.path, nil]];
583+
NSError *error = nil;
584+
NSString *output = [self.repository outputOfTaskWithArguments:@[@"diff-files", parameter, @"--", file.path]
585+
error:&error];
586+
if (!output) {
587+
PBLogError(error);
588+
}
589+
return output;
567590
}
568591

569592
# pragma mark WebKit Accessibility

0 commit comments

Comments
 (0)