mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
69d67820f6
Checkout:
- PBGitRepository: add checkoutRefish:
- PBRefController: renamed checkoutRef: to checkout: and use new method in PBGitRepository
- add to the contextual menus for commits (it was already in the menu for refs)
- add "Checkout branch" checkbox to the Create Branch sheet
- store the state in the defaults
- tell the commitController to rearrangeObjects so that the refs highlight correctly (seems to only be a problem when going from a branch to a detached HEAD at the same commit)
98 lines
2.3 KiB
Objective-C
98 lines
2.3 KiB
Objective-C
//
|
|
// PBCreateBranchSheet.m
|
|
// GitX
|
|
//
|
|
// Created by Nathan Kinsinger on 12/13/09.
|
|
// Copyright 2009 Nathan Kinsinger. All rights reserved.
|
|
//
|
|
|
|
#import "PBCreateBranchSheet.h"
|
|
#import "PBGitRepository.h"
|
|
#import "PBGitDefaults.h"
|
|
#import "PBGitCommit.h"
|
|
#import "PBGitRef.h"
|
|
|
|
@interface PBCreateBranchSheet ()
|
|
|
|
- (void) beginCreateBranchSheetAtRefish:(id <PBGitRefish>)ref inRepository:(PBGitRepository *)repo;
|
|
|
|
@end
|
|
|
|
|
|
@implementation PBCreateBranchSheet
|
|
|
|
|
|
@synthesize repository;
|
|
@synthesize startRefish;
|
|
|
|
@synthesize shouldCheckoutBranch;
|
|
|
|
@synthesize branchNameField;
|
|
@synthesize errorMessageField;
|
|
|
|
|
|
|
|
#pragma mark -
|
|
#pragma mark PBCreateBranchSheet
|
|
|
|
+ (void) beginCreateBranchSheetAtRefish:(id <PBGitRefish>)ref inRepository:(PBGitRepository *)repo
|
|
{
|
|
PBCreateBranchSheet *sheet = [[self alloc] initWithWindowNibName:@"PBCreateBranchSheet"];
|
|
[sheet beginCreateBranchSheetAtRefish:ref inRepository:repo];
|
|
}
|
|
|
|
|
|
- (void) beginCreateBranchSheetAtRefish:(id <PBGitRefish>)ref inRepository:(PBGitRepository *)repo
|
|
{
|
|
self.repository = repo;
|
|
self.startRefish = ref;
|
|
|
|
[self window]; // loads the window (if it wasn't already)
|
|
[self.errorMessageField setStringValue:@""];
|
|
self.shouldCheckoutBranch = [PBGitDefaults shouldCheckoutBranch];
|
|
|
|
[NSApp beginSheet:[self window] modalForWindow:[self.repository.windowController window] modalDelegate:self didEndSelector:nil contextInfo:NULL];
|
|
}
|
|
|
|
|
|
|
|
#pragma mark IBActions
|
|
|
|
- (IBAction) createBranch:(id)sender
|
|
{
|
|
NSString *name = [self.branchNameField stringValue];
|
|
PBGitRef *ref = [PBGitRef refFromString:[kGitXBranchRefPrefix stringByAppendingString:name]];
|
|
|
|
if (![self.repository checkRefFormat:[ref ref]]) {
|
|
[self.errorMessageField setStringValue:@"Invalid name"];
|
|
[self.errorMessageField setHidden:NO];
|
|
return;
|
|
}
|
|
|
|
if ([self.repository refExists:ref]) {
|
|
[self.errorMessageField setStringValue:@"Branch already exists"];
|
|
[self.errorMessageField setHidden:NO];
|
|
return;
|
|
}
|
|
|
|
[self closeCreateBranchSheet:self];
|
|
|
|
[self.repository createBranch:name atRefish:self.startRefish];
|
|
|
|
[PBGitDefaults setShouldCheckoutBranch:self.shouldCheckoutBranch];
|
|
|
|
if (self.shouldCheckoutBranch)
|
|
[self.repository checkoutRefish:ref];
|
|
}
|
|
|
|
|
|
- (IBAction) closeCreateBranchSheet:(id)sender
|
|
{
|
|
[NSApp endSheet:[self window]];
|
|
[[self window] orderOut:self];
|
|
}
|
|
|
|
|
|
|
|
@end
|