PBGitIndex: post notifications when index stuff fails

We use notifications so that we can make all these methods async later on
This commit is contained in:
Pieter de Bie
2009-09-13 16:47:30 +02:00
parent 438a3f808d
commit a2b3bf3d1e
3 changed files with 33 additions and 9 deletions
+9
View File
@@ -19,6 +19,7 @@
- (void)commitFailed:(NSNotification *)notification;
- (void)amendCommit:(NSNotification *)notification;
- (void)indexChanged:(NSNotification *)notification;
- (void)indexOperationFailed:(NSNotification *)notification;
@end
@implementation PBGitCommitController
@@ -39,6 +40,7 @@
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(commitFailed:) name:PBGitIndexCommitFailed object:index];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(amendCommit:) name:PBGitIndexAmendMessageAvailable object:index];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(indexChanged:) name:PBGitIndexIndexUpdated object:index];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(indexOperationFailed:) name:PBGitIndexOperationFailed object:index];
return self;
}
@@ -132,6 +134,7 @@
}
# pragma mark PBGitIndex Notification handling
- (void)refreshFinished:(NSNotification *)notification
{
self.busy = NO;
@@ -175,4 +178,10 @@
[cachedFilesController rearrangeObjects];
[unstagedFilesController rearrangeObjects];
}
- (void)indexOperationFailed:(NSNotification *)notification
{
[[repository windowController] showMessageSheet:@"Index operation failed" infoText:[[notification userInfo] objectForKey:@"description"]];
}
@end
+12 -1
View File
@@ -11,19 +11,30 @@
@class PBGitRepository;
@class PBChangedFile;
/*
* Notifications this class will send
*/
// Refreshing index
extern NSString *PBGitIndexIndexRefreshStatus;
extern NSString *PBGitIndexIndexRefreshFailed;
extern NSString *PBGitIndexFinishedIndexRefresh;
// The "Files" array has changed
// The "indexChanges" array has changed
extern NSString *PBGitIndexIndexUpdated;
// Committing files
extern NSString *PBGitIndexCommitStatus;
extern NSString *PBGitIndexCommitFailed;
extern NSString *PBGitIndexFinishedCommit;
// Changing to amend
extern NSString *PBGitIndexAmendMessageAvailable;
// This is for general operations, like applying a patch
extern NSString *PBGitIndexOperationFailed;
// Represents a git index for a given work tree.
// As a single git repository can have multiple trees,
+12 -8
View File
@@ -24,6 +24,7 @@ NSString *PBGitIndexCommitFailed = @"PBGitIndexCommitFailed";
NSString *PBGitIndexFinishedCommit = @"PBGitIndexFinishedCommit";
NSString *PBGitIndexAmendMessageAvailable = @"PBGitIndexAmendMessageAvailable";
NSString *PBGitIndexOperationFailed = @"PBGitIndexOperationFailed";
@interface PBGitIndex (IndexRefreshMethods)
@@ -48,6 +49,7 @@ NSString *PBGitIndexAmendMessageAvailable = @"PBGitIndexAmendMessageAvailable";
- (void)postCommitUpdate:(NSString *)update;
- (void)postCommitFailure:(NSString *)reason;
- (void)postIndexChange;
- (void)postOperationFailed:(NSString *)description;
@end
@implementation PBGitIndex
@@ -237,6 +239,12 @@ NSString *PBGitIndexAmendMessageAvailable = @"PBGitIndexAmendMessageAvailable";
userInfo:[NSDictionary dictionaryWithObject:reason forKey:@"description"]];
}
- (void)postOperationFailed:(NSString *)description
{
[[NSNotificationCenter defaultCenter] postNotificationName:PBGitIndexOperationFailed
object:self
userInfo:[NSDictionary dictionaryWithObject:description forKey:@"description"]];
}
- (BOOL)stageFiles:(NSArray *)stageFiles
{
@@ -256,8 +264,7 @@ NSString *PBGitIndexAmendMessageAvailable = @"PBGitIndexAmendMessageAvailable";
retValue:&ret];
if (ret) {
// FIXME: failed notification?
NSLog(@"Error when updating index. Retvalue: %i", ret);
[self postOperationFailed:[NSString stringWithFormat:@"Error in staging files. Return value: %i", ret]];
return NO;
}
@@ -287,8 +294,7 @@ NSString *PBGitIndexAmendMessageAvailable = @"PBGitIndexAmendMessageAvailable";
if (ret)
{
// FIXME: Failed notification
NSLog(@"Error when updating index. Retvalue: %i", ret);
[self postOperationFailed:[NSString stringWithFormat:@"Error in unstaging files. Return value: %i", ret]];
return NO;
}
@@ -313,8 +319,7 @@ NSString *PBGitIndexAmendMessageAvailable = @"PBGitIndexAmendMessageAvailable";
[PBEasyPipe outputForCommand:[PBGitBinary path] withArgs:arguments inDir:[workingDirectory path] inputString:input retValue:&ret];
if (ret) {
// TODO: Post failed notification
// [[commitController.repository windowController] showMessageSheet:@"Discarding changes failed" infoText:[NSString stringWithFormat:@"Discarding changes failed with error code %i", ret]];
[self postOperationFailed:[NSString stringWithFormat:@"Discarding changes failed with return value %i", ret]];
return;
}
@@ -337,9 +342,8 @@ NSString *PBGitIndexAmendMessageAvailable = @"PBGitIndexAmendMessageAvailable";
inputString:hunk
retValue:&ret];
// FIXME: show this error, rather than just logging it
if (ret) {
NSLog(@"Error: %@", error);
[self postOperationFailed:[NSString stringWithFormat:@"Applying patch failed with return value %i. Error: %@", ret, error]];
return NO;
}