Add Checkout Files to file browser contextual menu

Allows checking out the state of a file from any commit to the working directory.
This commit is contained in:
Nathan Kinsinger
2010-02-06 19:07:22 -07:00
parent 859f77e718
commit dceabb6702
3 changed files with 39 additions and 2 deletions
+14 -2
View File
@@ -266,6 +266,15 @@
}
}
- (void) checkoutFiles:(id)sender
{
NSMutableArray *files = [NSMutableArray array];
for (NSString *filePath in [sender representedObject])
[files addObject:[filePath stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]];
[repository checkoutFiles:files fromRefish:realCommit];
}
- (NSMenu *)contextMenuForTreeView
{
@@ -286,7 +295,10 @@
BOOL multiple = [filePaths count] != 1;
NSMenuItem *historyItem = [[NSMenuItem alloc] initWithTitle:multiple? @"Show history of files" : @"Show history of file"
action:@selector(showCommitsFromTree:)
keyEquivalent:@""];
keyEquivalent:@""];
NSMenuItem *checkoutItem = [[NSMenuItem alloc] initWithTitle:multiple ? @"Checkout files" : @"Checkout file"
action:@selector(checkoutFiles:)
keyEquivalent:@""];
NSMenuItem *finderItem = [[NSMenuItem alloc] initWithTitle:@"Show in Finder"
action:@selector(showInFinderAction:)
keyEquivalent:@""];
@@ -294,7 +306,7 @@
action:@selector(openFilesAction:)
keyEquivalent:@""];
NSArray *menuItems = [NSArray arrayWithObjects:historyItem, finderItem, openFilesItem, nil];
NSArray *menuItems = [NSArray arrayWithObjects:historyItem, checkoutItem, finderItem, openFilesItem, nil];
for (NSMenuItem *item in menuItems) {
[item setTarget:self];
[item setRepresentedObject:filePaths];
+1
View File
@@ -30,6 +30,7 @@ extern NSString* PBGitRepositoryErrorDomain;
}
- (BOOL) checkoutRefish:(id <PBGitRefish>)ref;
- (BOOL) checkoutFiles:(NSArray *)files fromRefish:(id <PBGitRefish>)ref;
- (BOOL) createBranch:(NSString *)branchName atRefish:(id <PBGitRefish>)ref;
- (BOOL) createTag:(NSString *)tagName message:(NSString *)message atRefish:(id <PBGitRefish>)commitSHA;
+24
View File
@@ -450,6 +450,30 @@ NSString* PBGitRepositoryErrorDomain = @"GitXErrorDomain";
return YES;
}
- (BOOL) checkoutFiles:(NSArray *)files fromRefish:(id <PBGitRefish>)ref
{
if (!files || ([files count] == 0))
return NO;
NSString *refName = nil;
if ([ref refishType] == kGitXBranchType)
refName = [ref shortName];
else
refName = [ref refishName];
int retValue = 1;
NSMutableArray *arguments = [NSMutableArray arrayWithObjects:@"checkout", refName, @"--", nil];
[arguments addObjectsFromArray:files];
NSString *output = [self outputInWorkdirForArguments:arguments retValue:&retValue];
if (retValue) {
NSString *message = [NSString stringWithFormat:@"There was an error checking out the file(s) from the %@ '%@'.\n\nPerhaps your working directory is not clean?", [ref refishType], [ref shortName]];
[self.windowController showErrorSheetTitle:@"Checkout failed!" message:message arguments:arguments output:output];
return NO;
}
return YES;
}
- (BOOL) createBranch:(NSString *)branchName atRefish:(id <PBGitRefish>)ref
{
if (!branchName || !ref)