Skip to content

Commit a2b3bf3

Browse files
committed
PBGitIndex: post notifications when index stuff fails
We use notifications so that we can make all these methods async later on
1 parent 438a3f8 commit a2b3bf3

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

PBGitCommitController.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ - (void)commitFinished:(NSNotification *)notification;
1919
- (void)commitFailed:(NSNotification *)notification;
2020
- (void)amendCommit:(NSNotification *)notification;
2121
- (void)indexChanged:(NSNotification *)notification;
22+
- (void)indexOperationFailed:(NSNotification *)notification;
2223
@end
2324

2425
@implementation PBGitCommitController
@@ -39,6 +40,7 @@ - (id)initWithRepository:(PBGitRepository *)theRepository superController:(PBGit
3940
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(commitFailed:) name:PBGitIndexCommitFailed object:index];
4041
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(amendCommit:) name:PBGitIndexAmendMessageAvailable object:index];
4142
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(indexChanged:) name:PBGitIndexIndexUpdated object:index];
43+
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(indexOperationFailed:) name:PBGitIndexOperationFailed object:index];
4244

4345
return self;
4446
}
@@ -132,6 +134,7 @@ - (IBAction) commit:(id) sender
132134
}
133135

134136

137+
# pragma mark PBGitIndex Notification handling
135138
- (void)refreshFinished:(NSNotification *)notification
136139
{
137140
self.busy = NO;
@@ -175,4 +178,10 @@ - (void)indexChanged:(NSNotification *)notification
175178
[cachedFilesController rearrangeObjects];
176179
[unstagedFilesController rearrangeObjects];
177180
}
181+
182+
- (void)indexOperationFailed:(NSNotification *)notification
183+
{
184+
[[repository windowController] showMessageSheet:@"Index operation failed" infoText:[[notification userInfo] objectForKey:@"description"]];
185+
}
186+
178187
@end

PBGitIndex.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,30 @@
1111
@class PBGitRepository;
1212
@class PBChangedFile;
1313

14+
/*
15+
* Notifications this class will send
16+
*/
17+
18+
// Refreshing index
1419
extern NSString *PBGitIndexIndexRefreshStatus;
1520
extern NSString *PBGitIndexIndexRefreshFailed;
1621
extern NSString *PBGitIndexFinishedIndexRefresh;
1722

18-
// The "Files" array has changed
23+
// The "indexChanges" array has changed
1924
extern NSString *PBGitIndexIndexUpdated;
2025

26+
// Committing files
2127
extern NSString *PBGitIndexCommitStatus;
2228
extern NSString *PBGitIndexCommitFailed;
2329
extern NSString *PBGitIndexFinishedCommit;
2430

31+
// Changing to amend
2532
extern NSString *PBGitIndexAmendMessageAvailable;
2633

34+
// This is for general operations, like applying a patch
35+
extern NSString *PBGitIndexOperationFailed;
36+
37+
2738

2839
// Represents a git index for a given work tree.
2940
// As a single git repository can have multiple trees,

PBGitIndex.m

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
NSString *PBGitIndexFinishedCommit = @"PBGitIndexFinishedCommit";
2525

2626
NSString *PBGitIndexAmendMessageAvailable = @"PBGitIndexAmendMessageAvailable";
27+
NSString *PBGitIndexOperationFailed = @"PBGitIndexOperationFailed";
2728

2829
@interface PBGitIndex (IndexRefreshMethods)
2930

@@ -48,6 +49,7 @@ - (NSString *) parentTree;
4849
- (void)postCommitUpdate:(NSString *)update;
4950
- (void)postCommitFailure:(NSString *)reason;
5051
- (void)postIndexChange;
52+
- (void)postOperationFailed:(NSString *)description;
5153
@end
5254

5355
@implementation PBGitIndex
@@ -237,6 +239,12 @@ - (void)postCommitFailure:(NSString *)reason
237239
userInfo:[NSDictionary dictionaryWithObject:reason forKey:@"description"]];
238240
}
239241

242+
- (void)postOperationFailed:(NSString *)description
243+
{
244+
[[NSNotificationCenter defaultCenter] postNotificationName:PBGitIndexOperationFailed
245+
object:self
246+
userInfo:[NSDictionary dictionaryWithObject:description forKey:@"description"]];
247+
}
240248

241249
- (BOOL)stageFiles:(NSArray *)stageFiles
242250
{
@@ -256,8 +264,7 @@ - (BOOL)stageFiles:(NSArray *)stageFiles
256264
retValue:&ret];
257265

258266
if (ret) {
259-
// FIXME: failed notification?
260-
NSLog(@"Error when updating index. Retvalue: %i", ret);
267+
[self postOperationFailed:[NSString stringWithFormat:@"Error in staging files. Return value: %i", ret]];
261268
return NO;
262269
}
263270

@@ -287,8 +294,7 @@ - (BOOL)unstageFiles:(NSArray *)unstageFiles
287294

288295
if (ret)
289296
{
290-
// FIXME: Failed notification
291-
NSLog(@"Error when updating index. Retvalue: %i", ret);
297+
[self postOperationFailed:[NSString stringWithFormat:@"Error in unstaging files. Return value: %i", ret]];
292298
return NO;
293299
}
294300

@@ -313,8 +319,7 @@ - (void)discardChangesForFiles:(NSArray *)discardFiles
313319
[PBEasyPipe outputForCommand:[PBGitBinary path] withArgs:arguments inDir:[workingDirectory path] inputString:input retValue:&ret];
314320

315321
if (ret) {
316-
// TODO: Post failed notification
317-
// [[commitController.repository windowController] showMessageSheet:@"Discarding changes failed" infoText:[NSString stringWithFormat:@"Discarding changes failed with error code %i", ret]];
322+
[self postOperationFailed:[NSString stringWithFormat:@"Discarding changes failed with return value %i", ret]];
318323
return;
319324
}
320325

@@ -337,9 +342,8 @@ - (BOOL)applyPatch:(NSString *)hunk stage:(BOOL)stage reverse:(BOOL)reverse;
337342
inputString:hunk
338343
retValue:&ret];
339344

340-
// FIXME: show this error, rather than just logging it
341345
if (ret) {
342-
NSLog(@"Error: %@", error);
346+
[self postOperationFailed:[NSString stringWithFormat:@"Applying patch failed with return value %i. Error: %@", ret, error]];
343347
return NO;
344348
}
345349

0 commit comments

Comments
 (0)