Permalink
Browse files

PBGitIndex: post notifications when index stuff fails

We use notifications so that we can make all these methods async later on
  • Loading branch information...
1 parent 438a3f8 commit a2b3bf3d1e05c581468c32b41008223322f2a718 @pieter committed Sep 13, 2009
Showing with 33 additions and 9 deletions.
  1. +9 −0 PBGitCommitController.m
  2. +12 −1 PBGitIndex.h
  3. +12 −8 PBGitIndex.m
View
@@ -19,6 +19,7 @@ - (void)commitFinished:(NSNotification *)notification;
- (void)commitFailed:(NSNotification *)notification;
- (void)amendCommit:(NSNotification *)notification;
- (void)indexChanged:(NSNotification *)notification;
+- (void)indexOperationFailed:(NSNotification *)notification;
@end
@implementation PBGitCommitController
@@ -39,6 +40,7 @@ - (id)initWithRepository:(PBGitRepository *)theRepository superController:(PBGit
[[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 @@ - (IBAction) commit:(id) sender
}
+# pragma mark PBGitIndex Notification handling
- (void)refreshFinished:(NSNotification *)notification
{
self.busy = NO;
@@ -175,4 +178,10 @@ - (void)indexChanged:(NSNotification *)notification
[cachedFilesController rearrangeObjects];
[unstagedFilesController rearrangeObjects];
}
+
+- (void)indexOperationFailed:(NSNotification *)notification
+{
+ [[repository windowController] showMessageSheet:@"Index operation failed" infoText:[[notification userInfo] objectForKey:@"description"]];
+}
+
@end
View
@@ -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,
View
@@ -24,6 +24,7 @@
NSString *PBGitIndexFinishedCommit = @"PBGitIndexFinishedCommit";
NSString *PBGitIndexAmendMessageAvailable = @"PBGitIndexAmendMessageAvailable";
+NSString *PBGitIndexOperationFailed = @"PBGitIndexOperationFailed";
@interface PBGitIndex (IndexRefreshMethods)
@@ -48,6 +49,7 @@ - (NSString *) parentTree;
- (void)postCommitUpdate:(NSString *)update;
- (void)postCommitFailure:(NSString *)reason;
- (void)postIndexChange;
+- (void)postOperationFailed:(NSString *)description;
@end
@implementation PBGitIndex
@@ -237,6 +239,12 @@ - (void)postCommitFailure:(NSString *)reason
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 @@ - (BOOL)stageFiles:(NSArray *)stageFiles
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 @@ - (BOOL)unstageFiles:(NSArray *)unstageFiles
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 @@ - (void)discardChangesForFiles:(NSArray *)discardFiles
[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 @@ - (BOOL)applyPatch:(NSString *)hunk stage:(BOOL)stage reverse:(BOOL)reverse;
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;
}

0 comments on commit a2b3bf3

Please sign in to comment.