diff --git a/PBGitCommitController.m b/PBGitCommitController.m index a6200dc71..6a773481a 100644 --- a/PBGitCommitController.m +++ b/PBGitCommitController.m @@ -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 diff --git a/PBGitIndex.h b/PBGitIndex.h index 67a474ac9..7ca1db78b 100644 --- a/PBGitIndex.h +++ b/PBGitIndex.h @@ -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, diff --git a/PBGitIndex.m b/PBGitIndex.m index d3d026398..4174d49af 100644 --- a/PBGitIndex.m +++ b/PBGitIndex.m @@ -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; }