Trigger pre and post-commit hooks when committing

Based on a patch by Faustino Osuna <enrique.osuna@gmail.com>

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
This commit is contained in:
Pieter de Bie
2009-05-18 23:06:50 +01:00
parent b896ac0d56
commit 4dfcc4d45d
+10 -3
View File
@@ -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:@""];