Testing: add missing file
[GitX.git] / PBCLIProxy.m
blob83507d270d9c29525a65b4f00d3997539f183d40
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                 rev.workingDirectory = repositoryPath;
60                 document.currentBranch = [document addBranch: rev];
61                 [document.windowController showHistoryView:self];
62         }
63         [NSApp activateIgnoringOtherApps:YES];
65         return YES;
68 - (void)openDiffWindowWithDiff:(NSString *)diff
70         PBDiffWindowController *diffController = [[PBDiffWindowController alloc] initWithDiff:[diff copy]];
71         [diffController showWindow:nil];
72         [[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
74 @end