1818#import " PBCloneRepositoryPanel.h"
1919#import " Sparkle/SUUpdater.h"
2020#import " AIURLAdditions.h"
21+ #import " PBGitRepository.h"
22+
23+ @interface ApplicationController ()
24+ - (void ) cleanUpRemotesOnError ;
25+ @end
26+
2127
2228@implementation ApplicationController
2329
@@ -72,7 +78,10 @@ - (void)applicationWillFinishLaunching:(NSNotification*)notification
7278
7379- (void )applicationDidFinishLaunching : (NSNotification *)notification
7480{
75- [[SUUpdater sharedUpdater ] setSendsSystemProfile: YES ];
81+ [[NSNotificationCenter defaultCenter ] addObserver: self selector: @selector (getArguments: ) name: @" GitCommandSent" object: Nil ];
82+ [[NSNotificationCenter defaultCenter ] addObserver: self selector: @selector (cleanGitAfterErrorMessage: ) name: @" ErrorMessageDidEnd" object: Nil ];
83+
84+ [[SUUpdater sharedUpdater ] setSendsSystemProfile: YES ];
7685 [[SUUpdater sharedUpdater ] setDelegate: self ];
7786
7887 if ([PBGitDefaults useAskPasswd ]) {
@@ -245,7 +254,7 @@ - (NSManagedObjectModel *)managedObjectModel {
245254 return managedObjectModel;
246255 }
247256
248- managedObjectModel = [[ NSManagedObjectModel mergedModelFromBundles: nil ] retain ];
257+ managedObjectModel = [NSManagedObjectModel mergedModelFromBundles: nil ];
249258 return managedObjectModel;
250259}
251260
@@ -392,6 +401,8 @@ - (void)applicationWillTerminate:(NSNotification *)aNotification
392401 [PBGitDefaults setPreviousDocumentPaths: paths];
393402 }
394403 }
404+
405+ [[NSNotificationCenter defaultCenter ] removeObserver: self ];
395406}
396407
397408/* *
@@ -400,10 +411,9 @@ - (void)applicationWillTerminate:(NSNotification *)aNotification
400411
401412- (void ) dealloc {
402413
403- [managedObjectContext release ], managedObjectContext = nil ;
404- [persistentStoreCoordinator release ], persistentStoreCoordinator = nil ;
405- [managedObjectModel release ], managedObjectModel = nil ;
406- [super dealloc ];
414+ managedObjectContext = nil ;
415+ persistentStoreCoordinator = nil ;
416+ managedObjectModel = nil ;
407417}
408418
409419
@@ -444,5 +454,35 @@ - (IBAction)reportAProblem:(id)sender
444454}
445455
446456
457+ #pragma mark - Observer methods
458+
459+ - (void )getArguments : (NSNotification *)notification
460+ {
461+ notificationUserInfo = [notification userInfo ];
462+ }
463+
464+
465+ - (void )cleanGitAfterErrorMessage : (NSNotification *)notification
466+ {
467+ // When adding a remote occurs an error the remote
468+ // will be set on git and has to be removed to clean the remotes list
469+ [self cleanUpRemotesOnError ];
470+
471+
472+
473+ }
474+
475+ #pragma mark - Extensions
476+ - (void ) cleanUpRemotesOnError
477+ {
478+ // check, if arguments was to add a remote
479+ if ( ([(NSString *)[notificationUserInfo valueForKey: @" Arg0" ] compare: @" remote" ] == NSOrderedSame) &&
480+ ([(NSString *)[notificationUserInfo valueForKey: @" Arg1" ] compare: @" add" ] == NSOrderedSame)
481+ )
482+ {
483+ PBGitRef *remoteRef = [PBGitRef refFromString: [NSString stringWithFormat: @" %@%@ " , kGitXRemoteRefPrefix ,[notificationUserInfo valueForKey: @" Arg3" ]]];
484+ [[notificationUserInfo valueForKey: @" Repository" ] deleteRemote: remoteRef];
485+ }
486+ }
447487
448488@end
0 commit comments