mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
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:
+10
-3
@@ -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:@""];
|
||||
|
||||
Reference in New Issue
Block a user