|
| 1 | +// |
| 2 | +// PBRemoteCommandFactory.m |
| 3 | +// GitX |
| 4 | +// |
| 5 | +// Created by Tomasz Krasnyk on 10-11-07. |
| 6 | +// Copyright 2010 __MyCompanyName__. All rights reserved. |
| 7 | +// |
| 8 | + |
| 9 | +#import "PBRemoteCommandFactory.h" |
| 10 | +#import "PBOpenDocumentCommand.h" |
| 11 | +#import "PBGitSubmodule.h" |
| 12 | +#import "PBRevealWithFinderCommand.h" |
| 13 | + |
| 14 | + |
| 15 | +@implementation PBRemoteCommandFactory |
| 16 | + |
| 17 | ++ (NSArray *) commandsForSubmodule:(PBGitSubmodule *) submodule inRepository:(PBGitRepository *) repository { |
| 18 | + NSMutableArray *commands = [[NSMutableArray alloc] init]; |
| 19 | + |
| 20 | + NSString *repoPath = [repository workingDirectory]; |
| 21 | + NSString *path = [repoPath stringByAppendingPathComponent:[submodule path]]; |
| 22 | + NSString *submodulePath = [submodule path]; |
| 23 | + |
| 24 | + if ([submodule submoduleState] == PBGitSubmoduleStateNotInitialized) { |
| 25 | + NSArray *params = [NSArray arrayWithObjects:@"submodule", @"init", submodulePath, nil]; |
| 26 | + PBCommand *initCmd = [[PBCommand alloc] initWithDisplayName:@"Init" parameters:params repository:repository]; |
| 27 | + initCmd.commandTitle = initCmd.displayName; |
| 28 | + initCmd.commandDescription = [NSString stringWithFormat:@"Initializing submodule %@", submodulePath]; |
| 29 | + [commands addObject:initCmd]; |
| 30 | + } |
| 31 | + |
| 32 | + // update |
| 33 | + NSArray *params = [NSArray arrayWithObjects:@"submodule", @"update", submodulePath, nil]; |
| 34 | + PBCommand *updateCmd = [[PBCommand alloc] initWithDisplayName:@"Update" parameters:params repository:repository]; |
| 35 | + updateCmd.commandTitle = updateCmd.displayName; |
| 36 | + updateCmd.commandDescription = [NSString stringWithFormat:@"Updating submodule %@", submodulePath]; |
| 37 | + [commands addObject:updateCmd]; |
| 38 | + |
| 39 | + if ([[submodule submodules] count] > 0) { |
| 40 | + // update recursively |
| 41 | + NSArray *recursiveUpdate = [NSArray arrayWithObjects:@"submodule", @"update", @"--recursive", submodulePath, nil]; |
| 42 | + PBCommand *updateRecursively = [[PBCommand alloc] initWithDisplayName:@"Update recursively" parameters:recursiveUpdate repository:repository]; |
| 43 | + updateRecursively.commandTitle = updateRecursively.displayName; |
| 44 | + updateRecursively.commandDescription = [NSString stringWithFormat:@"Updating submodule %@ (recursively)", submodulePath]; |
| 45 | + [commands addObject:updateRecursively]; |
| 46 | + } |
| 47 | + |
| 48 | + if ([submodule submoduleState] != PBGitSubmoduleStateNotInitialized) { |
| 49 | + // open |
| 50 | + PBOpenDocumentCommand *command = [[PBOpenDocumentCommand alloc] initWithDocumentAbsolutePath:path]; |
| 51 | + command.commandTitle = command.displayName; |
| 52 | + command.commandDescription = @"Opening document"; |
| 53 | + [commands addObject:command]; |
| 54 | + |
| 55 | + [commands addObject:[[PBRevealWithFinderCommand alloc] initWithDocumentAbsolutePath:path]]; |
| 56 | + } |
| 57 | + |
| 58 | + return commands; |
| 59 | +} |
| 60 | + |
| 61 | ++ (NSArray *) commandsForObject:(NSObject *) object repository:(PBGitRepository *) repository { |
| 62 | + if ([object isKindOfClass:[PBGitSubmodule class]]) { |
| 63 | + return [PBRemoteCommandFactory commandsForSubmodule:(id)object inRepository:repository]; |
| 64 | + } |
| 65 | + return nil; |
| 66 | +} |
| 67 | + |
| 68 | +@end |
0 commit comments