From 4dfcc4d45d6fcf6e167d7c1ad1f1a8192e4e0c5c Mon Sep 17 00:00:00 2001 From: Pieter de Bie Date: Mon, 18 May 2009 23:06:50 +0100 Subject: [PATCH] Trigger pre and post-commit hooks when committing Based on a patch by Faustino Osuna A failure of the pre-commit hook (a non-zero result from the hook) will cause the commit to abort. A failure of the post-commit hook has no effect of the rest of the operation, however, it is noted in the user interface. This fixes Lighthouse#50 --- PBGitCommitController.m | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/PBGitCommitController.m b/PBGitCommitController.m index 03b6a76..7905a11 100644 --- a/PBGitCommitController.m +++ b/PBGitCommitController.m @@ -309,14 +309,21 @@ if (ret || [commit length] != 40) return [self commitFailedBecause:@"Could not create a commit object"]; - + + if (![repository executeHook:@"pre-commit" output:nil]) + return [self commitFailedBecause:@"Pre-commit hook failed"]; + [repository outputForArguments:[NSArray arrayWithObjects:@"update-ref", @"-m", commitSubject, @"HEAD", commit, nil] retValue: &ret]; if (ret) return [self commitFailedBecause:@"Could not update HEAD"]; - [webController setStateMessage:[NSString stringWithFormat:@"Successfully created commit %@", commit]]; - + + if (![repository executeHook:@"post-commit" output:nil]) + [webController setStateMessage:[NSString stringWithFormat:@"Post-commit hook failed, however, successfully created commit %@", commit]]; + else + [webController setStateMessage:[NSString stringWithFormat:@"Successfully created commit %@", commit]]; + repository.hasChanged = YES; self.busy--; [commitMessageView setString:@""];