mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
Update Create Branch
Update the methods for creating a branch.
- create new class and xib PBCreateBranchSheet
- remove old addRef: methods and iVars from PBRefController
- remove old sheet from PBHistoryView.xib
- put the implementation method in PBGitRepository
- add a contextual menu item for commits
- shows an error sheet
- ask the commitController to rearrangeObjects to make sure the new branch is shown
- switch from using "update-ref" to "branch" so that branches starting at a remote branch will track automatically (or not depending on the repo's settings)
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -44,6 +44,8 @@
|
||||
93CB42C20EAB7B2200530609 /* PBGitDefaults.m in Sources */ = {isa = PBXBuildFile; fileRef = 93CB42C10EAB7B2200530609 /* PBGitDefaults.m */; };
|
||||
93F7857F0EA3ABF100C1F443 /* PBCommitMessageView.m in Sources */ = {isa = PBXBuildFile; fileRef = 93F7857E0EA3ABF100C1F443 /* PBCommitMessageView.m */; };
|
||||
D26DC6450E782C9000C777B2 /* gitx.icns in Resources */ = {isa = PBXBuildFile; fileRef = D26DC6440E782C9000C777B2 /* gitx.icns */; };
|
||||
D854948610D5C01B0083B917 /* PBCreateBranchSheet.m in Sources */ = {isa = PBXBuildFile; fileRef = D854948510D5C01B0083B917 /* PBCreateBranchSheet.m */; };
|
||||
D85B939310E3D8B4007F3C28 /* PBCreateBranchSheet.xib in Resources */ = {isa = PBXBuildFile; fileRef = D85B939210E3D8B4007F3C28 /* PBCreateBranchSheet.xib */; };
|
||||
EB2A734A0FEE3F09006601CF /* PBCollapsibleSplitView.m in Sources */ = {isa = PBXBuildFile; fileRef = EB2A73490FEE3F09006601CF /* PBCollapsibleSplitView.m */; };
|
||||
F50A411F0EBB874C00208746 /* mainSplitterBar.tiff in Resources */ = {isa = PBXBuildFile; fileRef = F50A411D0EBB874C00208746 /* mainSplitterBar.tiff */; };
|
||||
F50A41200EBB874C00208746 /* mainSplitterDimple.tiff in Resources */ = {isa = PBXBuildFile; fileRef = F50A411E0EBB874C00208746 /* mainSplitterDimple.tiff */; };
|
||||
@@ -208,7 +210,10 @@
|
||||
93F7857E0EA3ABF100C1F443 /* PBCommitMessageView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBCommitMessageView.m; sourceTree = "<group>"; };
|
||||
93FCCBA80EA8AF450061B02B /* PBGitConfig.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBGitConfig.m; sourceTree = "<group>"; };
|
||||
D26DC6440E782C9000C777B2 /* gitx.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = gitx.icns; sourceTree = "<group>"; };
|
||||
D85B94B710E576B4007F3C28 /* PBGitRefish.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBGitRefish.h; sourceTree = "<group>"; };
|
||||
D854948410D5C01B0083B917 /* PBCreateBranchSheet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBCreateBranchSheet.h; sourceTree = "<group>"; };
|
||||
D854948510D5C01B0083B917 /* PBCreateBranchSheet.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBCreateBranchSheet.m; sourceTree = "<group>"; };
|
||||
D854949310D5C3E20083B917 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/PBCreateBranchSheet.xib; sourceTree = "<group>"; };
|
||||
D85B93F610E51279007F3C28 /* PBGitRefish.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBGitRefish.h; sourceTree = "<group>"; };
|
||||
EB2A73480FEE3F09006601CF /* PBCollapsibleSplitView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBCollapsibleSplitView.h; sourceTree = "<group>"; };
|
||||
EB2A73490FEE3F09006601CF /* PBCollapsibleSplitView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBCollapsibleSplitView.m; sourceTree = "<group>"; };
|
||||
F50A411D0EBB874C00208746 /* mainSplitterBar.tiff */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; name = mainSplitterBar.tiff; path = Images/mainSplitterBar.tiff; sourceTree = "<group>"; };
|
||||
@@ -445,6 +450,7 @@
|
||||
F5E424100EA3E4D60046E362 /* PBDiffWindow.xib */,
|
||||
F52BCE020E84208300AA3741 /* PBGitHistoryView.xib */,
|
||||
F59116E50E843BB50072CCB1 /* PBGitCommitView.xib */,
|
||||
D85B939210E3D8B4007F3C28 /* PBCreateBranchSheet.xib */,
|
||||
47DBDB680E94EF6500671A1E /* Preferences.xib */,
|
||||
F569AE920F2CBD7C00C2FFA7 /* Credits.html */,
|
||||
);
|
||||
@@ -487,6 +493,15 @@
|
||||
name = cli;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
D82F435F111B9C6D00A25A39 /* Sheets */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
D854948410D5C01B0083B917 /* PBCreateBranchSheet.h */,
|
||||
D854948510D5C01B0083B917 /* PBCreateBranchSheet.m */,
|
||||
);
|
||||
name = Sheets;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
F50A41130EBB872D00208746 /* Widgets */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
@@ -518,6 +533,7 @@
|
||||
F5B161BB0EAB6E0C005A1DE1 /* Diff */,
|
||||
F5EF8C880E9D498F0050906B /* History */,
|
||||
F5E927F90E883EF600056E75 /* Commit */,
|
||||
D82F435F111B9C6D00A25A39 /* Sheets */,
|
||||
77C8280B06725ACE000B614F /* ApplicationController.h */,
|
||||
77C8280C06725ACE000B614F /* ApplicationController.m */,
|
||||
93CB42C00EAB7B2200530609 /* PBGitDefaults.h */,
|
||||
@@ -626,7 +642,7 @@
|
||||
F5AD56770E79B78100EDAAFE /* PBCommitList.h */,
|
||||
F5AD56780E79B78100EDAAFE /* PBCommitList.m */,
|
||||
F5C6F6750E65FE2B00478D97 /* Graphing */,
|
||||
D85B94B710E576B4007F3C28 /* PBGitRefish.h */,
|
||||
D85B93F610E51279007F3C28 /* PBGitRefish.h */,
|
||||
F56524EE0E02D45200F03B52 /* PBGitCommit.h */,
|
||||
F56524EF0E02D45200F03B52 /* PBGitCommit.m */,
|
||||
F5C007730E731B48007B84B2 /* PBGitRef.h */,
|
||||
@@ -821,6 +837,7 @@
|
||||
47DBDB6A0E94EF6500671A1E /* Preferences.xib in Resources */,
|
||||
47DBDBB10E94F6CA00671A1E /* Updates.png in Resources */,
|
||||
F569AE930F2CBD7C00C2FFA7 /* Credits.html in Resources */,
|
||||
D85B939310E3D8B4007F3C28 /* PBCreateBranchSheet.xib in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -940,6 +957,7 @@
|
||||
F562C8870FE1766C000EC528 /* NSString_RegEx.m in Sources */,
|
||||
EB2A734A0FEE3F09006601CF /* PBCollapsibleSplitView.m in Sources */,
|
||||
F59F1DD5105C4FF300115F88 /* PBGitIndex.m in Sources */,
|
||||
D854948610D5C01B0083B917 /* PBCreateBranchSheet.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -1032,6 +1050,14 @@
|
||||
name = RepositoryWindow.xib;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
D85B939210E3D8B4007F3C28 /* PBCreateBranchSheet.xib */ = {
|
||||
isa = PBXVariantGroup;
|
||||
children = (
|
||||
D854949310D5C3E20083B917 /* English */,
|
||||
);
|
||||
name = PBCreateBranchSheet.xib;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
F5B721C20E05CF7E00AF29DC /* MainMenu.xib */ = {
|
||||
isa = PBXVariantGroup;
|
||||
children = (
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
//
|
||||
// PBCreateBranchSheet.h
|
||||
// GitX
|
||||
//
|
||||
// Created by Nathan Kinsinger on 12/13/09.
|
||||
// Copyright 2009 Nathan Kinsinger. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "PBGitRefish.h"
|
||||
|
||||
|
||||
@class PBGitRepository;
|
||||
|
||||
|
||||
@interface PBCreateBranchSheet : NSWindowController {
|
||||
PBGitRepository *repository;
|
||||
id <PBGitRefish> startRefish;
|
||||
|
||||
NSTextField *branchNameField;
|
||||
NSTextField *errorMessageField;
|
||||
}
|
||||
|
||||
+ (void) beginCreateBranchSheetAtRefish:(id <PBGitRefish>)ref inRepository:(PBGitRepository *)repo;
|
||||
|
||||
|
||||
- (IBAction) createBranch:(id)sender;
|
||||
- (IBAction) closeCreateBranchSheet:(id)sender;
|
||||
|
||||
|
||||
@property (retain) PBGitRepository *repository;
|
||||
@property (retain) id <PBGitRefish> startRefish;
|
||||
|
||||
@property (assign) IBOutlet NSTextField *branchNameField;
|
||||
@property (assign) IBOutlet NSTextField *errorMessageField;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,88 @@
|
||||
//
|
||||
// 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 "PBGitCommit.h"
|
||||
#import "PBGitRef.h"
|
||||
|
||||
@interface PBCreateBranchSheet ()
|
||||
|
||||
- (void) beginCreateBranchSheetAtRefish:(id <PBGitRefish>)ref inRepository:(PBGitRepository *)repo;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation PBCreateBranchSheet
|
||||
|
||||
|
||||
@synthesize repository;
|
||||
@synthesize startRefish;
|
||||
|
||||
@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:@""];
|
||||
|
||||
[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:[@"refs/heads/" 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];
|
||||
}
|
||||
|
||||
|
||||
- (IBAction) closeCreateBranchSheet:(id)sender
|
||||
{
|
||||
[NSApp endSheet:[self window]];
|
||||
[[self window] orderOut:self];
|
||||
}
|
||||
|
||||
|
||||
|
||||
@end
|
||||
@@ -51,6 +51,9 @@
|
||||
- (void)showInFinderAction:(id)sender;
|
||||
- (void)openFilesAction:(id)sender;
|
||||
|
||||
// Repository Methods
|
||||
- (IBAction) createBranch:(id)sender;
|
||||
|
||||
- (void) copyCommitInfo;
|
||||
|
||||
- (BOOL) hasNonlinearPath;
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#import "PBGitGrapher.h"
|
||||
#import "PBGitRevisionCell.h"
|
||||
#import "PBCommitList.h"
|
||||
#import "PBCreateBranchSheet.h"
|
||||
#define QLPreviewPanel NSClassFromString(@"QLPreviewPanel")
|
||||
|
||||
|
||||
@@ -321,4 +322,17 @@
|
||||
return [sender frame].size.height;
|
||||
}
|
||||
|
||||
|
||||
#pragma mark Repository Methods
|
||||
|
||||
- (IBAction) createBranch:(id)sender
|
||||
{
|
||||
PBGitRef *currentRef = [repository.currentBranch ref];
|
||||
|
||||
if (!realCommit || [realCommit hasRef:currentRef])
|
||||
[PBCreateBranchSheet beginCreateBranchSheetAtRefish:currentRef inRepository:self.repository];
|
||||
else
|
||||
[PBCreateBranchSheet beginCreateBranchSheetAtRefish:realCommit inRepository:self.repository];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
+955
-503
File diff suppressed because it is too large
Load Diff
@@ -10,6 +10,7 @@
|
||||
#import "PBGitRevList.h"
|
||||
#import "PBGitRevSpecifier.h"
|
||||
#import "PBGitConfig.h"
|
||||
#import "PBGitRefish.h"
|
||||
|
||||
extern NSString* PBGitRepositoryErrorDomain;
|
||||
|
||||
@@ -28,6 +29,8 @@ extern NSString* PBGitRepositoryErrorDomain;
|
||||
PBGitRevSpecifier *_headRef; // Caching
|
||||
}
|
||||
|
||||
- (BOOL) createBranch:(NSString *)branchName atRefish:(id <PBGitRefish>)ref;
|
||||
|
||||
- (NSFileHandle*) handleForCommand:(NSString*) cmd;
|
||||
- (NSFileHandle*) handleForArguments:(NSArray*) args;
|
||||
- (NSFileHandle *) handleInWorkDirForArguments:(NSArray *)args;
|
||||
|
||||
+23
-1
@@ -424,7 +424,29 @@ NSString* PBGitRepositoryErrorDomain = @"GitXErrorDomain";
|
||||
return [PBGitBinary path];
|
||||
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark Repository commands
|
||||
|
||||
- (BOOL) createBranch:(NSString *)branchName atRefish:(id <PBGitRefish>)ref
|
||||
{
|
||||
if (!branchName || !ref)
|
||||
return NO;
|
||||
|
||||
int retValue = 1;
|
||||
NSArray *arguments = [NSArray arrayWithObjects:@"branch", branchName, [ref refishName], nil];
|
||||
NSString *output = [self outputInWorkdirForArguments:arguments retValue:&retValue];
|
||||
if (retValue) {
|
||||
NSString *message = [NSString stringWithFormat:@"There was an error creating the branch '%@' at %@ '%@'.", branchName, [ref refishType], [ref shortName]];
|
||||
[self.windowController showErrorSheetTitle:@"Create Branch failed!" message:message arguments:arguments output:output];
|
||||
return NO;
|
||||
}
|
||||
|
||||
[self reloadRefs];
|
||||
return YES;
|
||||
}
|
||||
|
||||
#pragma mark low level
|
||||
|
||||
- (int) returnValueForCommand:(NSString *)cmd
|
||||
{
|
||||
|
||||
+1
-7
@@ -20,16 +20,10 @@
|
||||
IBOutlet NSArrayController *commitController;
|
||||
IBOutlet PBCommitList *commitList;
|
||||
|
||||
IBOutlet NSWindow *newBranchSheet;
|
||||
IBOutlet NSTextField *newBranchName;
|
||||
IBOutlet NSTextField *errorMessage;
|
||||
|
||||
IBOutlet NSPopUpButton *branchPopUp;
|
||||
}
|
||||
|
||||
- (IBAction)addRef:(id)sender;
|
||||
- (IBAction)closeSheet:(id) sender;
|
||||
- (IBAction)saveSheet:(id) sender;
|
||||
- (void) createBranch:(PBRefMenuItem *)sender;
|
||||
|
||||
- (NSArray *) menuItemsForRef:(PBGitRef *)ref;
|
||||
- (NSArray *) menuItemsForCommit:(PBGitCommit *)commit;
|
||||
|
||||
+12
-47
@@ -9,6 +9,7 @@
|
||||
#import "PBRefController.h"
|
||||
#import "PBGitRevisionCell.h"
|
||||
#import "PBRefMenuItem.h"
|
||||
#import "PBCreateBranchSheet.h"
|
||||
|
||||
@implementation PBRefController
|
||||
|
||||
@@ -24,6 +25,7 @@
|
||||
- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
|
||||
{
|
||||
if ([(NSString *)context isEqualToString: @"branchChange"]) {
|
||||
[commitController rearrangeObjects];
|
||||
[self updateBranchMenu];
|
||||
}
|
||||
else if ([(NSString *)context isEqualToString:@"currentBranchChange"]) {
|
||||
@@ -34,6 +36,16 @@
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#pragma mark Create Branch
|
||||
|
||||
- (void) createBranch:(PBRefMenuItem *)sender
|
||||
{
|
||||
id <PBGitRefish> refish = [sender refish];
|
||||
[PBCreateBranchSheet beginCreateBranchSheetAtRefish:refish inRepository:historyController.repository];
|
||||
}
|
||||
|
||||
|
||||
- (void) removeRefSheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
|
||||
{
|
||||
if (returnCode == NSAlertDefaultReturn) {
|
||||
@@ -179,53 +191,6 @@
|
||||
return YES;
|
||||
}
|
||||
|
||||
# pragma mark Add ref methods
|
||||
-(void)addRef:(id)sender
|
||||
{
|
||||
[errorMessage setStringValue:@""];
|
||||
[NSApp beginSheet:newBranchSheet
|
||||
modalForWindow:[[historyController view] window]
|
||||
modalDelegate:NULL
|
||||
didEndSelector:NULL
|
||||
contextInfo:NULL];
|
||||
}
|
||||
|
||||
-(void)saveSheet:(id) sender
|
||||
{
|
||||
NSString *branchName = [@"refs/heads/" stringByAppendingString:[newBranchName stringValue]];
|
||||
|
||||
if ([[commitController selectedObjects] count] == 0)
|
||||
return;
|
||||
|
||||
PBGitCommit *commit = [[commitController selectedObjects] objectAtIndex:0];
|
||||
|
||||
int retValue = 1;
|
||||
[historyController.repository outputForArguments:[NSArray arrayWithObjects:@"check-ref-format", branchName, nil] retValue:&retValue];
|
||||
if (retValue != 0) {
|
||||
[errorMessage setStringValue:@"Invalid name"];
|
||||
return;
|
||||
}
|
||||
|
||||
retValue = 1;
|
||||
[historyController.repository outputForArguments:[NSArray arrayWithObjects:@"update-ref", @"-mCreate branch from GitX", branchName, [commit realSha], @"0000000000000000000000000000000000000000", NULL] retValue:&retValue];
|
||||
if (retValue)
|
||||
{
|
||||
[errorMessage setStringValue:@"Branch exists"];
|
||||
return;
|
||||
}
|
||||
[historyController.repository addBranch:[[PBGitRevSpecifier alloc] initWithRef:[PBGitRef refFromString:branchName]]];
|
||||
[self closeSheet:sender];
|
||||
[commit addRef:[PBGitRef refFromString:branchName]];
|
||||
[commitController rearrangeObjects];
|
||||
}
|
||||
|
||||
-(void)closeSheet:(id) sender
|
||||
{
|
||||
[NSApp endSheet:newBranchSheet];
|
||||
[newBranchName setStringValue:@""];
|
||||
[newBranchSheet orderOut:self];
|
||||
}
|
||||
|
||||
# pragma mark Branches menu
|
||||
|
||||
- (void) updateBranchMenu
|
||||
|
||||
@@ -46,6 +46,10 @@
|
||||
// checkout ref
|
||||
NSString *checkoutTitle = [@"Checkout " stringByAppendingString:targetRefName];
|
||||
[items addObject:[PBRefMenuItem itemWithTitle:checkoutTitle action:@selector(checkoutRef:) enabled:!isHead]];
|
||||
[items addObject:[PBRefMenuItem separatorItem]];
|
||||
|
||||
// create branch
|
||||
[items addObject:[PBRefMenuItem itemWithTitle:@"Create branch…" action:@selector(createBranch:) enabled:YES]];
|
||||
|
||||
// view tag info
|
||||
if ([ref isTag])
|
||||
@@ -69,6 +73,8 @@
|
||||
{
|
||||
NSMutableArray *items = [NSMutableArray array];
|
||||
|
||||
[items addObject:[PBRefMenuItem itemWithTitle:@"Create Branch…" action:@selector(createBranch:) enabled:YES]];
|
||||
|
||||
for (PBRefMenuItem *item in items) {
|
||||
[item setTarget:target];
|
||||
[item setRefish:commit];
|
||||
|
||||
Reference in New Issue
Block a user