@@ -289,7 +289,13 @@ - (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
+ }
298
+ tree = [tree stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet ]];
293
299
if ([tree length ] != 40 )
294
300
return [self postCommitFailure: @" Creating tree failed" ];
295
301
@@ -302,7 +308,6 @@ - (void)commitWithMessage:(NSString *)commitMessage andVerify:(BOOL) doVerify
302
308
}
303
309
304
310
[self postCommitUpdate: @" Creating commit" ];
305
- int ret = 1 ;
306
311
307
312
if (doVerify) {
308
313
[self postCommitUpdate: @" Running hooks" ];
@@ -332,24 +337,28 @@ - (void)commitWithMessage:(NSString *)commitMessage andVerify:(BOOL) doVerify
332
337
}
333
338
334
339
commitMessage = [NSString stringWithContentsOfFile: commitMessageFile encoding: NSUTF8StringEncoding error: nil ];
335
-
336
- NSString *commit = [self .repository outputForArguments: arguments
337
- inputString: commitMessage
338
- byExtendingEnvironment: self .amendEnvironment
339
- retValue: &ret];
340
-
341
- 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);
342
349
return [self postCommitFailure: @" Could not create a commit object" ];
350
+ }
343
351
344
352
[self postCommitUpdate: @" Updating HEAD" ];
345
- [self .repository outputForArguments: [ NSArray arrayWithObjects: @" update-ref" , @" -m" , commitSubject, @" HEAD" , commit, nil ]
346
- retValue: &ret];
347
- if (ret)
353
+ success = [self .repository launchTaskWithArguments: @[ @" update-ref" , @" -m" , commitSubject, @" HEAD" , commit] error: &error];
354
+ if (!success) {
355
+ PBLogError (error);
348
356
return [self postCommitFailure: @" Could not update HEAD" ];
357
+ }
349
358
350
359
[self postCommitUpdate: @" Running post-commit hook" ];
351
360
352
- BOOL success = [self .repository executeHook: @" post-commit" error: NULL ];
361
+ success = [self .repository executeHook: @" post-commit" error: NULL ];
353
362
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithObject: [NSNumber numberWithBool: success] forKey: @" success" ];
354
363
NSString *description;
355
364
if (success)
@@ -445,19 +454,19 @@ - (BOOL)performStageOrUnstage:(BOOL)stage withFiles:(NSArray *)files
445
454
}
446
455
}
447
456
448
- int ret = 1 ;
457
+ NSArray *arguments = nil ;
449
458
if (stage) {
450
- [self .repository outputForArguments: [NSArray arrayWithObjects: @" update-index" , @" --add" , @" --remove" , @" -z" , @" --stdin" , nil ]
451
- inputString: input
452
- retValue: &ret];
459
+ arguments = @[@" update-index" , @" --add" , @" --remove" , @" -z" , @" --stdin" ];
453
460
} else {
454
- [self .repository outputForArguments: [NSArray arrayWithObjects: @" update-index" , @" -z" , @" --index-info" , nil ]
455
- inputString: input
456
- retValue: &ret];
461
+ arguments = @[@" update-index" , @" -z" , @" --index-info" ];
457
462
}
458
463
459
- if (ret) {
460
- [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]]];
461
470
return NO ;
462
471
}
463
472
@@ -523,13 +532,14 @@ - (BOOL)applyPatch:(NSString *)hunk stage:(BOOL)stage reverse:(BOOL)reverse;
523
532
if (reverse)
524
533
[array addObject: @" --reverse" ];
525
534
526
- int ret = 1 ;
527
- NSString *error = [self .repository outputForArguments : array
528
- inputString : hunk
529
- retValue: &ret ];
535
+ NSError *error = nil ;
536
+ NSString *output = [self .repository outputOfTaskWithArguments : array
537
+ input : hunk
538
+ error: &error ];
530
539
531
- if (ret) {
532
- [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];
533
543
return NO ;
534
544
}
535
545
@@ -543,12 +553,20 @@ - (NSString *)diffForFile:(PBChangedFile *)file staged:(BOOL)staged contextLines
543
553
{
544
554
NSString *parameter = [NSString stringWithFormat: @" -U%lu " , context];
545
555
if (staged) {
546
- NSString *indexPath = [@" :0:" stringByAppendingString: file.path];
547
-
548
- if (file.status == NEW)
549
- 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
+ }
550
563
551
- 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;
552
570
}
553
571
554
572
// unstaged
@@ -562,7 +580,13 @@ - (NSString *)diffForFile:(PBChangedFile *)file staged:(BOOL)staged contextLines
562
580
return contents;
563
581
}
564
582
565
- 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;
566
590
}
567
591
568
592
# pragma mark WebKit Accessibility
0 commit comments