Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

RefController: Allow checking out branches

  • Loading branch information...
commit 00e44b35d07645ece95bec588c459a21dac5834a 1 parent 058fbcf
@pieter authored
View
1  PBGitRepository.h
@@ -34,6 +34,7 @@ extern NSString* PBGitRepositoryErrorDomain;
- (NSString*) outputForArguments:(NSArray*) args;
- (NSString*) outputForArguments:(NSArray*) args retValue:(int *)ret;
- (NSString *)outputInWorkdirForArguments:(NSArray*) arguments;
+- (NSString *)outputInWorkdirForArguments:(NSArray*) arguments retValue:(int *)ret;
- (NSString *)workingDirectory;
View
6 PBGitRepository.m
@@ -353,8 +353,12 @@ - (NSString*) outputInWorkdirForArguments:(NSArray*) arguments
return [PBEasyPipe outputForCommand:[PBGitBinary path] withArgs:arguments inDir: [self workingDirectory]];
}
+- (NSString*) outputInWorkdirForArguments:(NSArray *)arguments retValue:(int *)ret
+{
+ return [PBEasyPipe outputForCommand:[PBGitBinary path] withArgs:arguments inDir:[self workingDirectory] retValue: ret];
+}
-- (NSString*) outputForArguments:(NSArray *)arguments retValue:(int *)ret;
+- (NSString*) outputForArguments:(NSArray *)arguments retValue:(int *)ret
{
return [PBEasyPipe outputForCommand:[PBGitBinary path] withArgs:arguments inDir: self.fileURL.path retValue: ret];
}
View
15 PBRefController.m
@@ -30,6 +30,21 @@ - (void) removeRef:(PBRefMenuItem *) sender
[commitController rearrangeObjects];
}
+- (void) checkoutRef:(PBRefMenuItem *)sender
+{
+ int ret = 1;
+ [historyController.repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"checkout", [[sender ref] shortName], nil] retValue: &ret];
+ if (ret) {
+ [[NSAlert alertWithMessageText:@"Checking out branch failed"
+ defaultButton:@"OK"
+ alternateButton:nil
+ otherButton:nil
+ informativeTextWithFormat:@"There was an error checking out the branch. Perhaps your working directory is not clean?"] runModal];
+ return;
+ }
+ [historyController.repository reloadRefs];
+}
+
- (NSArray *) menuItemsForRef:(PBGitRef *)ref commit:(PBGitCommit *)commit
{
return [PBRefMenuItem defaultMenuItemsForRef:ref commit:commit target:self];
View
8 PBRefMenuItem.m
@@ -24,10 +24,10 @@ + (NSArray *)defaultMenuItemsForRef:(PBGitRef *)ref commit:(PBGitCommit *)commit
[array addObject:[[PBRefMenuItem alloc] initWithTitle:[@"Delete " stringByAppendingString:type]
action:@selector(removeRef:)
keyEquivalent: @""]];
-
- [array addObject:[[PBRefMenuItem alloc] initWithTitle:[@"Checkout " stringByAppendingString:type]
- action:@selector(checkoutRef:)
- keyEquivalent: @""]];
+ if ([type isEqualToString:@"branch"])
+ [array addObject:[[PBRefMenuItem alloc] initWithTitle:@"Checkout branch"
+ action:@selector(checkoutRef:)
+ keyEquivalent: @""]];
for (PBRefMenuItem *item in array)
{
Please sign in to comment.
Something went wrong with that request. Please try again.