5 // Created by CiarĂ¡n Walsh on 15/08/2008.
6 // Copyright 2008 __MyCompanyName__. All rights reserved.
10 #import "PBGitBinary.h"
12 NSDistantObject* connect()
14 id proxy = [NSConnection rootProxyForConnectionWithRegisteredName:ConnectionName host:nil];
15 [proxy setProtocolForProxy:@protocol(GitXCliToolProtocol)];
19 void usage(char const *programName)
22 printf("Usage: %s --help\n", programName);
23 printf(" or: %s (--commit|-h)\n", programName);
24 printf(" or: %s <revlist options>\n", programName);
26 printf("\t-h, --help print this help\n");
27 printf("\t--commit, -c start GitX in commit mode\n");
29 printf("RevList options\n");
30 printf("\tSee 'man git-log' and 'man git-rev-list' for options you can pass to gitx\n");
32 printf("\t--all show all branches\n");
33 printf("\t<branch> show specific branch\n");
34 printf("\t -- <path> show commits touching paths\n");
38 int main(int argc, const char** argv)
40 if (argc >= 2 && (!strcmp(argv[1], "--help") || !strcmp(argv[1], "-h")))
43 if (![PBGitBinary path]) {
44 printf("%s\n", [[PBGitBinary notFoundError] cStringUsingEncoding:NSUTF8StringEncoding]);
48 // Attempt to connect to the app
52 // If the connection failed, try to launch the app
53 [[NSWorkspace sharedWorkspace] launchAppWithBundleIdentifier: @"nl.frim.GitX"
54 options: NSWorkspaceLaunchWithoutActivation
55 additionalEventParamDescriptor: nil
56 launchIdentifier: nil];
58 // Now attempt to connect, allowing the app time to startup
59 for (int attempt = 0; proxy == nil && attempt < 50; ++attempt){
60 if (proxy = connect())
66 fprintf(stderr, "Couldn't connect to app server!\n");
70 if ([[[NSProcessInfo processInfo] environment] objectForKey:@"PWD"]) {
73 NSURL* url = [NSURL fileURLWithPath:[[[NSProcessInfo processInfo] environment] objectForKey:@"PWD"]];
75 NSMutableArray* arguments = [NSMutableArray arrayWithCapacity:argc];
76 for (i = 0; i < argc; i++)
77 [arguments addObject: [NSString stringWithCString:argv[i]]];
80 if (![proxy openRepository:url arguments: arguments error:&error]) {
81 fprintf(stderr, "Error opening repository at %s", [[url path] UTF8String]);
83 fprintf(stderr, ": %s", [[error localizedFailureReason] UTF8String]);
85 fprintf(stderr, "\n");