test/index: add more tests
[GitX.git] / PBServicesController.m
blobdd1830b426176754bead1b17b19c750104358a80
1 //
2 //  PBServicesController.m
3 //  GitX
4 //
5 //  Created by Pieter de Bie on 10/24/08.
6 //  Copyright 2008 __MyCompanyName__. All rights reserved.
7 //
9 #import "PBServicesController.h"
10 #import "PBRepositoryDocumentController.h"
11 #import "PBGitRepository.h"
13 @implementation PBServicesController
15 - (NSString *)completeSHA1For:(NSString *)sha
17         NSArray *documents = [[NSApplication sharedApplication] orderedDocuments];
18         for (PBGitRepository *repo in documents)
19         {
20                 int ret = 1;
21                 NSString *s = [repo outputForArguments:[NSArray arrayWithObjects:@"log", @"-1", @"--pretty=format:%h (%s)", sha, nil] retValue:&ret];
22                 if (!ret)
23                         return s;
24         }
25         return @"Could not find SHA";
28 -(NSString *)runNameRevFor:(NSString *)s
30         NSArray *repositories = [[NSApplication sharedApplication] orderedDocuments];
31         if ([repositories count] == 0)
32                 return s;
33         PBGitRepository *repo = [repositories objectAtIndex:0];
34         int ret = 1;
35         NSString *returnString = [repo outputForArguments:[NSArray arrayWithObjects:@"name-rev", @"--stdin", nil] inputString:s retValue:&ret];
36         if (ret)
37                 return s;
38         return returnString;
41 -(void)completeSha:(NSPasteboard *)pboard userData:(NSString *)userData error:(NSString **)error
43         NSArray *types = [pboard types];
44         if (![types containsObject:NSStringPboardType])
45         {
46                 *error = @"Could not get data";
47                 return;
48         }
50         NSString *s = [pboard stringForType:NSStringPboardType];
51         if ([s rangeOfString:@" "].location == NSNotFound)
52                 s = [self completeSHA1For:s];
53         else
54                 s = [self runNameRevFor:s];
56         [pboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
57         [pboard setString:s forType:NSStringPboardType];
59 @end