Skip to content

Commit

Permalink
PBGitIndex: post notifications when index stuff fails
Browse files Browse the repository at this point in the history
We use notifications so that we can make all these methods async later on
  • Loading branch information
pieter committed Sep 13, 2009
1 parent 438a3f8 commit a2b3bf3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
9 changes: 9 additions & 0 deletions PBGitCommitController.m
Expand Up @@ -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
Expand All @@ -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;
}
Expand Down Expand Up @@ -132,6 +134,7 @@ - (IBAction) commit:(id) sender
}


# pragma mark PBGitIndex Notification handling
- (void)refreshFinished:(NSNotification *)notification
{
self.busy = NO;
Expand Down Expand Up @@ -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
13 changes: 12 additions & 1 deletion PBGitIndex.h
Expand Up @@ -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,
Expand Down
20 changes: 12 additions & 8 deletions PBGitIndex.m
Expand Up @@ -24,6 +24,7 @@
NSString *PBGitIndexFinishedCommit = @"PBGitIndexFinishedCommit";

NSString *PBGitIndexAmendMessageAvailable = @"PBGitIndexAmendMessageAvailable";
NSString *PBGitIndexOperationFailed = @"PBGitIndexOperationFailed";

@interface PBGitIndex (IndexRefreshMethods)

Expand All @@ -48,6 +49,7 @@ - (NSString *) parentTree;
- (void)postCommitUpdate:(NSString *)update;
- (void)postCommitFailure:(NSString *)reason;
- (void)postIndexChange;
- (void)postOperationFailed:(NSString *)description;
@end

@implementation PBGitIndex
Expand Down Expand Up @@ -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
{
Expand All @@ -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;
}

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

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down

0 comments on commit a2b3bf3

Please sign in to comment.