Permalink
Browse files

Add failed commit notifications

  • Loading branch information...
pieter committed Sep 13, 2009
1 parent 4192d6a commit 5323b9159686b2d40f5a50077e704f6880b3aff3
Showing with 26 additions and 18 deletions.
  1. +12 −12 PBGitCommitController.m
  2. +14 −6 PBGitIndex.m
View
@@ -18,6 +18,7 @@ @interface PBGitCommitController ()
- (void)refreshFinished:(NSNotification *)notification;
- (void)commitStatusUpdated:(NSNotification *)notification;
- (void)commitFinished:(NSNotification *)notification;
+- (void)commitFailed:(NSNotification *)notification;
@end
@implementation PBGitCommitController
@@ -35,6 +36,7 @@ - (id)initWithRepository:(PBGitRepository *)theRepository superController:(PBGit
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshFinished:) name:PBGitIndexFinishedIndexRefresh object:index];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(commitStatusUpdated:) name:PBGitIndexCommitStatus object:index];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(commitFinished:) name:PBGitIndexFinishedCommit object:index];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(commitFailed:) name:PBGitIndexCommitFailed object:index];
return self;
}
@@ -95,14 +97,6 @@ - (void) updateView
[self refresh:nil];
}
-- (void) commitFailedBecause:(NSString *)reason
-{
- //self.busy--;
- self.status = [@"Commit failed: " stringByAppendingString:reason];
- [[repository windowController] showMessageSheet:@"Commit failed" infoText:reason];
- return;
-}
-
- (IBAction) commit:(id) sender
{
if ([[NSFileManager defaultManager] fileExistsAtPath:[repository.fileURL.path stringByAppendingPathComponent:@"MERGE_HEAD"]]) {
@@ -145,10 +139,16 @@ - (void)commitStatusUpdated:(NSNotification *)notification
- (void)commitFinished:(NSNotification *)notification
{
[webController setStateMessage:[NSString stringWithFormat:[[notification userInfo] objectForKey:@"description"]]];
-
- BOOL success = [[[notification userInfo] objectForKey:@"success"] boolValue];
- if (success)
- [commitMessageView setString:@""];
[commitMessageView setEditable:YES];
}
+
+- (void)commitFailed:(NSNotification *)notification
+{
+ self.busy = NO;
+ NSString *reason = [[notification userInfo] objectForKey:@"description"];
+ self.status = [@"Commit failed: " stringByAppendingString:reason];
+ [[repository windowController] showMessageSheet:@"Commit failed" infoText:reason];
+}
+
+
@end
View
@@ -43,7 +43,7 @@ @interface PBGitIndex ()
// on whether amend is set or not.
- (NSString *) parentTree;
- (void)postCommitUpdate:(NSString *)update;
-
+- (void)postCommitFailure:(NSString *)reason;
@end
@implementation PBGitIndex
@@ -146,7 +146,7 @@ - (void)commitWithMessage:(NSString *)commitMessage
[self postCommitUpdate:@"Creating tree"];
NSString *tree = [repository outputForCommand:@"write-tree"];
if ([tree length] != 40)
- return; //TODO: commitFailedBecause:@"Could not create a tree";
+ return [self postCommitFailure:@"Creating tree failed"];
NSMutableArray *arguments = [NSMutableArray arrayWithObjects:@"commit-tree", tree, nil];
@@ -164,20 +164,20 @@ - (void)commitWithMessage:(NSString *)commitMessage
retValue: &ret];
if (ret || [commit length] != 40)
- return; // TODO: [self commitFailedBecause:@"Could not create a commit object"];
+ return [self postCommitFailure:@"Could not create a commit object"];
[self postCommitUpdate:@"Running hooks"];
if (![repository executeHook:@"pre-commit" output:nil])
- return; // TODO: [self commitFailedBecause:@"Pre-commit hook failed"];
+ return [self postCommitFailure:@"Pre-commit hook failed"];
if (![repository executeHook:@"commit-msg" withArgs:[NSArray arrayWithObject:commitMessageFile] output:nil])
- return; // TODO: [self commitFailedBecause:@"Commit-msg hook failed"];
+ return [self postCommitFailure:@"Commit-msg hook failed"];
[self postCommitUpdate:@"Updating HEAD"];
[repository outputForArguments:[NSArray arrayWithObjects:@"update-ref", @"-m", commitSubject, @"HEAD", commit, nil]
retValue: &ret];
if (ret)
- return; // TODO: [self commitFailedBecause:@"Could not update HEAD"];
+ return [self postCommitFailure:@"Could not update HEAD"];
[self postCommitUpdate:@"Running post-commit hook"];
@@ -215,6 +215,14 @@ - (void)postCommitUpdate:(NSString *)update
userInfo:[NSDictionary dictionaryWithObject:update forKey:@"description"]];
}
+- (void)postCommitFailure:(NSString *)reason
+{
+ [[NSNotificationCenter defaultCenter] postNotificationName:PBGitIndexCommitFailed
+ object:self
+ userInfo:[NSDictionary dictionaryWithObject:reason forKey:@"description"]];
+}
+
+
- (BOOL)stageFiles:(NSArray *)stageFiles
{
// Input string for update-index

0 comments on commit 5323b91

Please sign in to comment.