Merge branch 'pu/pb/index_quick_fix' into stable
[GitX.git] / PBCLIProxy.m
blob1ac0e03e4279dafb8a70d0aec84edde0be5cadc2
1 //
2 //  PBCLIProxy.m
3 //  GitX
4 //
5 //  Created by CiarĂ¡n Walsh on 15/08/2008.
6 //  Copyright 2008 __MyCompanyName__. All rights reserved.
7 //
9 #import "PBCLIProxy.h"
10 #import "PBRepositoryDocumentController.h"
11 #import "PBGitRevSpecifier.h"
12 #import "PBGitRepository.h"
13 #import "PBGitWindowController.h"
14 #import "PBGitBinary.h"
15 #import "PBDiffWindowController.h"
17 @implementation PBCLIProxy
18 @synthesize connection;
20 - (id)init
22         if (self = [super init]) {
23                 self.connection = [NSConnection new];
24                 [self.connection setRootObject:self];
26                 if ([self.connection registerName:ConnectionName] == NO)
27                         NSBeep();
29         }
30         return self;
33 - (BOOL)openRepository:(NSURL*)repositoryPath arguments: (NSArray*) args error:(NSError**)error;
35         // FIXME I found that creating this redundant NSURL reference was necessary to
36         // work around an apparent bug with GC and Distributed Objects
37         // I am not familiar with GC though, so perhaps I was doing something wrong.
38         NSURL* url = [NSURL fileURLWithPath:[repositoryPath path]];
39         NSArray* arguments = [NSArray arrayWithArray:args];
41         PBGitRepository *document = [[PBRepositoryDocumentController sharedDocumentController] documentForLocation:url];
42         if (!document) {
43                 if (error) {
44                         NSString *suggestion = [PBGitBinary path] ? @"this isn't a git repository" : @"GitX can't find your git binary";
46                         NSDictionary *userInfo = [NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Could not create document. Perhaps %@", suggestion]
47                                                                                                                                  forKey:NSLocalizedFailureReasonErrorKey];
49                         *error = [NSError errorWithDomain:PBGitRepositoryErrorDomain code:2 userInfo:userInfo];
50                 }
51                 return NO;
52         }
54         if ([arguments count] > 0 && ([[arguments objectAtIndex:0] isEqualToString:@"--commit"] ||
55                 [[arguments objectAtIndex:0] isEqualToString:@"-c"]))
56                 [document.windowController showCommitView:self];
57         else {
58                 PBGitRevSpecifier* rev = [[PBGitRevSpecifier alloc] initWithParameters:arguments];
59                 document.currentBranch = [document addBranch: rev];
60                 [document.windowController showHistoryView:self];
61         }
62         [NSApp activateIgnoringOtherApps:YES];
64         return YES;
67 - (void)openDiffWindowWithDiff:(NSString *)diff
69         PBDiffWindowController *diffController = [[PBDiffWindowController alloc] initWithDiff:[diff copy]];
70         [diffController showWindow:nil];
71         [[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
73 @end