Skip to content

Commit 9f048f6

Browse files
committed
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)
1 parent 69c9c57 commit 9f048f6

12 files changed

+2223
-561
lines changed

English.lproj/PBCreateBranchSheet.xib

+1,052
Large diffs are not rendered by default.

GitX.xcodeproj/project.pbxproj

+28-2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
93CB42C20EAB7B2200530609 /* PBGitDefaults.m in Sources */ = {isa = PBXBuildFile; fileRef = 93CB42C10EAB7B2200530609 /* PBGitDefaults.m */; };
4545
93F7857F0EA3ABF100C1F443 /* PBCommitMessageView.m in Sources */ = {isa = PBXBuildFile; fileRef = 93F7857E0EA3ABF100C1F443 /* PBCommitMessageView.m */; };
4646
D26DC6450E782C9000C777B2 /* gitx.icns in Resources */ = {isa = PBXBuildFile; fileRef = D26DC6440E782C9000C777B2 /* gitx.icns */; };
47+
D854948610D5C01B0083B917 /* PBCreateBranchSheet.m in Sources */ = {isa = PBXBuildFile; fileRef = D854948510D5C01B0083B917 /* PBCreateBranchSheet.m */; };
48+
D85B939310E3D8B4007F3C28 /* PBCreateBranchSheet.xib in Resources */ = {isa = PBXBuildFile; fileRef = D85B939210E3D8B4007F3C28 /* PBCreateBranchSheet.xib */; };
4749
EB2A734A0FEE3F09006601CF /* PBCollapsibleSplitView.m in Sources */ = {isa = PBXBuildFile; fileRef = EB2A73490FEE3F09006601CF /* PBCollapsibleSplitView.m */; };
4850
F50A411F0EBB874C00208746 /* mainSplitterBar.tiff in Resources */ = {isa = PBXBuildFile; fileRef = F50A411D0EBB874C00208746 /* mainSplitterBar.tiff */; };
4951
F50A41200EBB874C00208746 /* mainSplitterDimple.tiff in Resources */ = {isa = PBXBuildFile; fileRef = F50A411E0EBB874C00208746 /* mainSplitterDimple.tiff */; };
@@ -208,7 +210,10 @@
208210
93F7857E0EA3ABF100C1F443 /* PBCommitMessageView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBCommitMessageView.m; sourceTree = "<group>"; };
209211
93FCCBA80EA8AF450061B02B /* PBGitConfig.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBGitConfig.m; sourceTree = "<group>"; };
210212
D26DC6440E782C9000C777B2 /* gitx.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = gitx.icns; sourceTree = "<group>"; };
211-
D85B94B710E576B4007F3C28 /* PBGitRefish.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBGitRefish.h; sourceTree = "<group>"; };
213+
D854948410D5C01B0083B917 /* PBCreateBranchSheet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBCreateBranchSheet.h; sourceTree = "<group>"; };
214+
D854948510D5C01B0083B917 /* PBCreateBranchSheet.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBCreateBranchSheet.m; sourceTree = "<group>"; };
215+
D854949310D5C3E20083B917 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/PBCreateBranchSheet.xib; sourceTree = "<group>"; };
216+
D85B93F610E51279007F3C28 /* PBGitRefish.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBGitRefish.h; sourceTree = "<group>"; };
212217
EB2A73480FEE3F09006601CF /* PBCollapsibleSplitView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBCollapsibleSplitView.h; sourceTree = "<group>"; };
213218
EB2A73490FEE3F09006601CF /* PBCollapsibleSplitView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBCollapsibleSplitView.m; sourceTree = "<group>"; };
214219
F50A411D0EBB874C00208746 /* mainSplitterBar.tiff */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; name = mainSplitterBar.tiff; path = Images/mainSplitterBar.tiff; sourceTree = "<group>"; };
@@ -445,6 +450,7 @@
445450
F5E424100EA3E4D60046E362 /* PBDiffWindow.xib */,
446451
F52BCE020E84208300AA3741 /* PBGitHistoryView.xib */,
447452
F59116E50E843BB50072CCB1 /* PBGitCommitView.xib */,
453+
D85B939210E3D8B4007F3C28 /* PBCreateBranchSheet.xib */,
448454
47DBDB680E94EF6500671A1E /* Preferences.xib */,
449455
F569AE920F2CBD7C00C2FFA7 /* Credits.html */,
450456
);
@@ -487,6 +493,15 @@
487493
name = cli;
488494
sourceTree = "<group>";
489495
};
496+
D82F435F111B9C6D00A25A39 /* Sheets */ = {
497+
isa = PBXGroup;
498+
children = (
499+
D854948410D5C01B0083B917 /* PBCreateBranchSheet.h */,
500+
D854948510D5C01B0083B917 /* PBCreateBranchSheet.m */,
501+
);
502+
name = Sheets;
503+
sourceTree = "<group>";
504+
};
490505
F50A41130EBB872D00208746 /* Widgets */ = {
491506
isa = PBXGroup;
492507
children = (
@@ -518,6 +533,7 @@
518533
F5B161BB0EAB6E0C005A1DE1 /* Diff */,
519534
F5EF8C880E9D498F0050906B /* History */,
520535
F5E927F90E883EF600056E75 /* Commit */,
536+
D82F435F111B9C6D00A25A39 /* Sheets */,
521537
77C8280B06725ACE000B614F /* ApplicationController.h */,
522538
77C8280C06725ACE000B614F /* ApplicationController.m */,
523539
93CB42C00EAB7B2200530609 /* PBGitDefaults.h */,
@@ -626,7 +642,7 @@
626642
F5AD56770E79B78100EDAAFE /* PBCommitList.h */,
627643
F5AD56780E79B78100EDAAFE /* PBCommitList.m */,
628644
F5C6F6750E65FE2B00478D97 /* Graphing */,
629-
D85B94B710E576B4007F3C28 /* PBGitRefish.h */,
645+
D85B93F610E51279007F3C28 /* PBGitRefish.h */,
630646
F56524EE0E02D45200F03B52 /* PBGitCommit.h */,
631647
F56524EF0E02D45200F03B52 /* PBGitCommit.m */,
632648
F5C007730E731B48007B84B2 /* PBGitRef.h */,
@@ -821,6 +837,7 @@
821837
47DBDB6A0E94EF6500671A1E /* Preferences.xib in Resources */,
822838
47DBDBB10E94F6CA00671A1E /* Updates.png in Resources */,
823839
F569AE930F2CBD7C00C2FFA7 /* Credits.html in Resources */,
840+
D85B939310E3D8B4007F3C28 /* PBCreateBranchSheet.xib in Resources */,
824841
);
825842
runOnlyForDeploymentPostprocessing = 0;
826843
};
@@ -940,6 +957,7 @@
940957
F562C8870FE1766C000EC528 /* NSString_RegEx.m in Sources */,
941958
EB2A734A0FEE3F09006601CF /* PBCollapsibleSplitView.m in Sources */,
942959
F59F1DD5105C4FF300115F88 /* PBGitIndex.m in Sources */,
960+
D854948610D5C01B0083B917 /* PBCreateBranchSheet.m in Sources */,
943961
);
944962
runOnlyForDeploymentPostprocessing = 0;
945963
};
@@ -1032,6 +1050,14 @@
10321050
name = RepositoryWindow.xib;
10331051
sourceTree = "<group>";
10341052
};
1053+
D85B939210E3D8B4007F3C28 /* PBCreateBranchSheet.xib */ = {
1054+
isa = PBXVariantGroup;
1055+
children = (
1056+
D854949310D5C3E20083B917 /* English */,
1057+
);
1058+
name = PBCreateBranchSheet.xib;
1059+
sourceTree = "<group>";
1060+
};
10351061
F5B721C20E05CF7E00AF29DC /* MainMenu.xib */ = {
10361062
isa = PBXVariantGroup;
10371063
children = (

PBCreateBranchSheet.h

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//
2+
// PBCreateBranchSheet.h
3+
// GitX
4+
//
5+
// Created by Nathan Kinsinger on 12/13/09.
6+
// Copyright 2009 Nathan Kinsinger. All rights reserved.
7+
//
8+
9+
#import <Cocoa/Cocoa.h>
10+
#import "PBGitRefish.h"
11+
12+
13+
@class PBGitRepository;
14+
15+
16+
@interface PBCreateBranchSheet : NSWindowController {
17+
PBGitRepository *repository;
18+
id <PBGitRefish> startRefish;
19+
20+
NSTextField *branchNameField;
21+
NSTextField *errorMessageField;
22+
}
23+
24+
+ (void) beginCreateBranchSheetAtRefish:(id <PBGitRefish>)ref inRepository:(PBGitRepository *)repo;
25+
26+
27+
- (IBAction) createBranch:(id)sender;
28+
- (IBAction) closeCreateBranchSheet:(id)sender;
29+
30+
31+
@property (retain) PBGitRepository *repository;
32+
@property (retain) id <PBGitRefish> startRefish;
33+
34+
@property (assign) IBOutlet NSTextField *branchNameField;
35+
@property (assign) IBOutlet NSTextField *errorMessageField;
36+
37+
@end

PBCreateBranchSheet.m

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
//
2+
// PBCreateBranchSheet.m
3+
// GitX
4+
//
5+
// Created by Nathan Kinsinger on 12/13/09.
6+
// Copyright 2009 Nathan Kinsinger. All rights reserved.
7+
//
8+
9+
#import "PBCreateBranchSheet.h"
10+
#import "PBGitRepository.h"
11+
#import "PBGitCommit.h"
12+
#import "PBGitRef.h"
13+
14+
@interface PBCreateBranchSheet ()
15+
16+
- (void) beginCreateBranchSheetAtRefish:(id <PBGitRefish>)ref inRepository:(PBGitRepository *)repo;
17+
18+
@end
19+
20+
21+
@implementation PBCreateBranchSheet
22+
23+
24+
@synthesize repository;
25+
@synthesize startRefish;
26+
27+
@synthesize branchNameField;
28+
@synthesize errorMessageField;
29+
30+
31+
32+
#pragma mark -
33+
#pragma mark PBCreateBranchSheet
34+
35+
+ (void) beginCreateBranchSheetAtRefish:(id <PBGitRefish>)ref inRepository:(PBGitRepository *)repo
36+
{
37+
PBCreateBranchSheet *sheet = [[self alloc] initWithWindowNibName:@"PBCreateBranchSheet"];
38+
[sheet beginCreateBranchSheetAtRefish:ref inRepository:repo];
39+
}
40+
41+
42+
- (void) beginCreateBranchSheetAtRefish:(id <PBGitRefish>)ref inRepository:(PBGitRepository *)repo
43+
{
44+
self.repository = repo;
45+
self.startRefish = ref;
46+
47+
[self window]; // loads the window (if it wasn't already)
48+
[self.errorMessageField setStringValue:@""];
49+
50+
[NSApp beginSheet:[self window] modalForWindow:[self.repository.windowController window] modalDelegate:self didEndSelector:nil contextInfo:NULL];
51+
}
52+
53+
54+
55+
#pragma mark IBActions
56+
57+
- (IBAction) createBranch:(id)sender
58+
{
59+
NSString *name = [self.branchNameField stringValue];
60+
PBGitRef *ref = [PBGitRef refFromString:[@"refs/heads/" stringByAppendingString:name]];
61+
62+
if (![self.repository checkRefFormat:[ref ref]]) {
63+
[self.errorMessageField setStringValue:@"Invalid name"];
64+
[self.errorMessageField setHidden:NO];
65+
return;
66+
}
67+
68+
if ([self.repository refExists:ref]) {
69+
[self.errorMessageField setStringValue:@"Branch already exists"];
70+
[self.errorMessageField setHidden:NO];
71+
return;
72+
}
73+
74+
[self closeCreateBranchSheet:self];
75+
76+
[self.repository createBranch:name atRefish:self.startRefish];
77+
}
78+
79+
80+
- (IBAction) closeCreateBranchSheet:(id)sender
81+
{
82+
[NSApp endSheet:[self window]];
83+
[[self window] orderOut:self];
84+
}
85+
86+
87+
88+
@end

PBGitHistoryController.h

+3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@
5151
- (void)showInFinderAction:(id)sender;
5252
- (void)openFilesAction:(id)sender;
5353

54+
// Repository Methods
55+
- (IBAction) createBranch:(id)sender;
56+
5457
- (void) copyCommitInfo;
5558

5659
- (BOOL) hasNonlinearPath;

PBGitHistoryController.m

+14
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#import "PBGitGrapher.h"
1212
#import "PBGitRevisionCell.h"
1313
#import "PBCommitList.h"
14+
#import "PBCreateBranchSheet.h"
1415
#define QLPreviewPanel NSClassFromString(@"QLPreviewPanel")
1516

1617

@@ -321,4 +322,17 @@ - (CGFloat)splitView:(NSSplitView *)sender constrainMaxCoordinate:(CGFloat)propo
321322
return [sender frame].size.height;
322323
}
323324

325+
326+
#pragma mark Repository Methods
327+
328+
- (IBAction) createBranch:(id)sender
329+
{
330+
PBGitRef *currentRef = [repository.currentBranch ref];
331+
332+
if (!realCommit || [realCommit hasRef:currentRef])
333+
[PBCreateBranchSheet beginCreateBranchSheetAtRefish:currentRef inRepository:self.repository];
334+
else
335+
[PBCreateBranchSheet beginCreateBranchSheetAtRefish:realCommit inRepository:self.repository];
336+
}
337+
324338
@end

0 commit comments

Comments
 (0)