Skip to content

Commit

Permalink
Add failed commit notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
pieter committed Sep 13, 2009
1 parent 4192d6a commit 5323b91
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
24 changes: 12 additions & 12 deletions PBGitCommitController.m
Expand Up @@ -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
Expand All @@ -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;
}
Expand Down Expand Up @@ -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"]]) {
Expand Down Expand Up @@ -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
20 changes: 14 additions & 6 deletions PBGitIndex.m
Expand Up @@ -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
Expand Down Expand Up @@ -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];
Expand All @@ -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"];

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5323b91

Please sign in to comment.