mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
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:
@@ -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];
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user