Skip to content

Commit 1722a2d

Browse files
committed
Report actual hook output
1 parent 225fbd5 commit 1722a2d

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

Classes/git/PBGitIndex.m

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -307,21 +307,27 @@ - (void)commitWithMessage:(NSString *)commitMessage andVerify:(BOOL) doVerify
307307
if (doVerify) {
308308
[self postCommitUpdate:@"Running hooks"];
309309
NSString *hookFailureMessage = nil;
310-
NSString *hookOutput = nil;
311-
if (![self.repository executeHook:@"pre-commit" output:&hookOutput]) {
310+
NSError *error = nil;
311+
BOOL success = [self.repository executeHook:@"pre-commit" error:&error];
312+
if (!success) {
313+
NSError *taskError = error.userInfo[NSUnderlyingErrorKey];
314+
NSString *hookOutput = taskError.userInfo[PBTaskTerminationOutputKey];
312315
hookFailureMessage = [NSString stringWithFormat:@"Pre-commit hook failed%@%@",
313-
[hookOutput length] > 0 ? @":\n" : @"",
314-
hookOutput];
316+
hookOutput && [hookOutput length] > 0 ? @":\n" : @"",
317+
hookOutput];
318+
[self postCommitHookFailure:hookFailureMessage];
319+
return;
315320
}
316321

317-
if (![self.repository executeHook:@"commit-msg" withArgs:[NSArray arrayWithObject:commitMessageFile] output:nil]) {
322+
success = [self.repository executeHook:@"commit-msg" arguments:@[commitMessageFile] error:&error];
323+
if (!success) {
324+
NSError *taskError = error.userInfo[NSUnderlyingErrorKey];
325+
NSString *hookOutput = taskError.userInfo[PBTaskTerminationOutputKey];
318326
hookFailureMessage = [NSString stringWithFormat:@"Commit-msg hook failed%@%@",
319-
[hookOutput length] > 0 ? @":\n" : @"",
320-
hookOutput];
321-
}
322-
323-
if (hookFailureMessage != nil) {
324-
return [self postCommitHookFailure:hookFailureMessage];
327+
hookOutput && [hookOutput length] > 0 ? @":\n" : @"",
328+
hookOutput];
329+
[self postCommitHookFailure:hookFailureMessage];
330+
return;
325331
}
326332
}
327333

@@ -343,7 +349,7 @@ - (void)commitWithMessage:(NSString *)commitMessage andVerify:(BOOL) doVerify
343349

344350
[self postCommitUpdate:@"Running post-commit hook"];
345351

346-
BOOL success = [self.repository executeHook:@"post-commit" output:nil];
352+
BOOL success = [self.repository executeHook:@"post-commit" error:NULL];
347353
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithObject:[NSNumber numberWithBool:success] forKey:@"success"];
348354
NSString *description;
349355
if (success)

0 commit comments

Comments
 (0)