@@ -289,7 +289,12 @@ - (void)commitWithMessage:(NSString *)commitMessage andVerify:(BOOL) doVerify
289
289
290
290
291
291
[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
+ }
293
298
tree = [tree stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet ]];
294
299
if ([tree length ] != 40 )
295
300
return [self postCommitFailure: @" Creating tree failed" ];
@@ -303,7 +308,6 @@ - (void)commitWithMessage:(NSString *)commitMessage andVerify:(BOOL) doVerify
303
308
}
304
309
305
310
[self postCommitUpdate: @" Creating commit" ];
306
- int ret = 1 ;
307
311
308
312
if (doVerify) {
309
313
[self postCommitUpdate: @" Running hooks" ];
@@ -333,24 +337,28 @@ - (void)commitWithMessage:(NSString *)commitMessage andVerify:(BOOL) doVerify
333
337
}
334
338
335
339
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);
343
349
return [self postCommitFailure: @" Could not create a commit object" ];
350
+ }
344
351
345
352
[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);
349
356
return [self postCommitFailure: @" Could not update HEAD" ];
357
+ }
350
358
351
359
[self postCommitUpdate: @" Running post-commit hook" ];
352
360
353
- BOOL success = [self .repository executeHook: @" post-commit" error: NULL ];
361
+ success = [self .repository executeHook: @" post-commit" error: NULL ];
354
362
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithObject: [NSNumber numberWithBool: success] forKey: @" success" ];
355
363
NSString *description;
356
364
if (success)
@@ -446,19 +454,19 @@ - (BOOL)performStageOrUnstage:(BOOL)stage withFiles:(NSArray *)files
446
454
}
447
455
}
448
456
449
- int ret = 1 ;
457
+ NSArray *arguments = nil ;
450
458
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" ];
454
460
} 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" ];
458
462
}
459
463
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]]];
462
470
return NO ;
463
471
}
464
472
@@ -524,13 +532,14 @@ - (BOOL)applyPatch:(NSString *)hunk stage:(BOOL)stage reverse:(BOOL)reverse;
524
532
if (reverse)
525
533
[array addObject: @" --reverse" ];
526
534
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 ];
531
539
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];
534
543
return NO ;
535
544
}
536
545
@@ -544,12 +553,20 @@ - (NSString *)diffForFile:(PBChangedFile *)file staged:(BOOL)staged contextLines
544
553
{
545
554
NSString *parameter = [NSString stringWithFormat: @" -U%lu " , context];
546
555
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
+ }
551
563
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;
553
570
}
554
571
555
572
// unstaged
@@ -563,7 +580,13 @@ - (NSString *)diffForFile:(PBChangedFile *)file staged:(BOOL)staged contextLines
563
580
return contents;
564
581
}
565
582
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;
567
590
}
568
591
569
592
# pragma mark WebKit Accessibility
0 commit comments