Permalink
Browse files

Add Checkout

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)
  • Loading branch information...
1 parent aa4a24a commit 69d67820f62a15d5899c82b17f40958c76315e19 @brotherbard committed Feb 20, 2010
Showing with 134 additions and 29 deletions.
  1. +65 −13 English.lproj/PBCreateBranchSheet.xib
  2. +4 −0 PBCreateBranchSheet.h
  3. +12 −3 PBCreateBranchSheet.m
  4. +2 −0 PBGitDefaults.h
  5. +13 −0 PBGitDefaults.m
  6. +1 −0 PBGitRepository.h
  7. +22 −0 PBGitRepository.m
  8. +1 −0 PBRefController.h
  9. +10 −12 PBRefController.m
  10. +4 −1 PBRefMenuItem.m
@@ -198,6 +198,33 @@
</object>
</object>
</object>
+ <object class="NSButton" id="502264956">
+ <reference key="NSNextResponder" ref="1006"/>
+ <int key="NSvFlags">268</int>
+ <string key="NSFrame">{{122, 58}, {129, 18}}</string>
+ <reference key="NSSuperview" ref="1006"/>
+ <bool key="NSEnabled">YES</bool>
+ <object class="NSButtonCell" key="NSCell" id="742397723">
+ <int key="NSCellFlags">-2080244224</int>
+ <int key="NSCellFlags2">0</int>
+ <string key="NSContents">Checkout branch</string>
+ <reference key="NSSupport" ref="850782281"/>
+ <reference key="NSControlView" ref="502264956"/>
+ <int key="NSButtonFlags">1211912703</int>
+ <int key="NSButtonFlags2">2</int>
+ <object class="NSCustomResource" key="NSNormalImage">
+ <string key="NSClassName">NSImage</string>
+ <string key="NSResourceName">NSSwitch</string>
+ </object>
+ <object class="NSButtonImageSource" key="NSAlternateImage">
+ <string key="NSImageName">NSSwitch</string>
+ </object>
+ <string key="NSAlternateContents"/>
+ <string key="NSKeyEquivalent"/>
+ <int key="NSPeriodicDelay">200</int>
+ <int key="NSPeriodicInterval">25</int>
+ </object>
+ </object>
</object>
<string key="NSFrameSize">{480, 167}</string>
<reference key="NSSuperview"/>
@@ -258,6 +285,22 @@
</object>
<int key="connectionID">47</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBBindingConnection" key="connection">
+ <string key="label">value: shouldCheckoutBranch</string>
+ <reference key="source" ref="502264956"/>
+ <reference key="destination" ref="1001"/>
+ <object class="NSNibBindingConnector" key="connector">
+ <reference key="NSSource" ref="502264956"/>
+ <reference key="NSDestination" ref="1001"/>
+ <string key="NSLabel">value: shouldCheckoutBranch</string>
+ <string key="NSBinding">value</string>
+ <string key="NSKeyPath">shouldCheckoutBranch</string>
+ <int key="NSNibBindingConnectorVersion">2</int>
+ </object>
+ </object>
+ <int key="connectionID">59</int>
+ </object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@@ -306,6 +349,7 @@
<reference ref="616021219"/>
<reference ref="900626215"/>
<reference ref="599625527"/>
+ <reference ref="502264956"/>
</object>
<reference key="parent" ref="1005"/>
</object>
@@ -393,6 +437,20 @@
<reference key="object" ref="296663936"/>
<reference key="parent" ref="900626215"/>
</object>
+ <object class="IBObjectRecord">
+ <int key="objectID">56</int>
+ <reference key="object" ref="502264956"/>
+ <object class="NSMutableArray" key="children">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference ref="742397723"/>
+ </object>
+ <reference key="parent" ref="1006"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">57</int>
+ <reference key="object" ref="742397723"/>
+ <reference key="parent" ref="502264956"/>
+ </object>
</object>
</object>
<object class="NSMutableDictionary" key="flattenedProperties">
@@ -417,6 +475,8 @@
<string>3.IBPluginDependency</string>
<string>4.IBPluginDependency</string>
<string>5.IBPluginDependency</string>
+ <string>56.IBPluginDependency</string>
+ <string>57.IBPluginDependency</string>
<string>6.IBPluginDependency</string>
<string>7.IBPluginDependency</string>
<string>8.IBPluginDependency</string>
@@ -444,6 +504,8 @@
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
</object>
</object>
<object class="NSMutableDictionary" key="unlocalizedProperties">
@@ -462,7 +524,7 @@
</object>
</object>
<nil key="sourceID"/>
- <int key="maxID">55</int>
+ <int key="maxID">59</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -489,15 +551,13 @@
<bool key="EncodedWithXMLCoder">YES</bool>
<string>branchNameField</string>
<string>errorMessageField</string>
- <string>startingAtMenu</string>
- <string>startingAtPopup</string>
+ <string>startRefish</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>NSTextField</string>
<string>NSTextField</string>
- <string>NSMenu</string>
- <string>NSPopUpButton</string>
+ <string>id</string>
</object>
</object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
@@ -936,14 +996,6 @@
</object>
</object>
<object class="IBPartialClassDescription">
- <string key="className">NSPopUpButton</string>
- <string key="superclassName">NSButton</string>
- <object class="IBClassDescriptionSource" key="sourceIdentifier">
- <string key="majorKey">IBFrameworkSource</string>
- <string key="minorKey">AppKit.framework/Headers/NSPopUpButton.h</string>
- </object>
- </object>
- <object class="IBPartialClassDescription">
<string key="className">NSResponder</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBFrameworkSource</string>
View
@@ -17,6 +17,8 @@
PBGitRepository *repository;
id <PBGitRefish> startRefish;
+ BOOL shouldCheckoutBranch;
+
NSTextField *branchNameField;
NSTextField *errorMessageField;
}
@@ -31,6 +33,8 @@
@property (retain) PBGitRepository *repository;
@property (retain) id <PBGitRefish> startRefish;
+@property (assign) BOOL shouldCheckoutBranch;
+
@property (assign) IBOutlet NSTextField *branchNameField;
@property (assign) IBOutlet NSTextField *errorMessageField;
View
@@ -8,6 +8,7 @@
#import "PBCreateBranchSheet.h"
#import "PBGitRepository.h"
+#import "PBGitDefaults.h"
#import "PBGitCommit.h"
#import "PBGitRef.h"
@@ -24,6 +25,8 @@ @implementation PBCreateBranchSheet
@synthesize repository;
@synthesize startRefish;
+@synthesize shouldCheckoutBranch;
+
@synthesize branchNameField;
@synthesize errorMessageField;
@@ -42,10 +45,11 @@ + (void) beginCreateBranchSheetAtRefish:(id <PBGitRefish>)ref inRepository:(PBGi
- (void) beginCreateBranchSheetAtRefish:(id <PBGitRefish>)ref inRepository:(PBGitRepository *)repo
{
self.repository = repo;
- self.startRefish = ref;
+ 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];
}
@@ -57,14 +61,14 @@ - (void) beginCreateBranchSheetAtRefish:(id <PBGitRefish>)ref inRepository:(PBGi
- (IBAction) createBranch:(id)sender
{
NSString *name = [self.branchNameField stringValue];
- PBGitRef *ref = [PBGitRef refFromString:[@"refs/heads/" stringByAppendingString:name]];
+ 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];
@@ -74,6 +78,11 @@ - (IBAction) createBranch:(id)sender
[self closeCreateBranchSheet:self];
[self.repository createBranch:name atRefish:self.startRefish];
+
+ [PBGitDefaults setShouldCheckoutBranch:self.shouldCheckoutBranch];
+
+ if (self.shouldCheckoutBranch)
+ [self.repository checkoutRefish:ref];
}
View
@@ -19,5 +19,7 @@
+ (BOOL)showWhitespaceDifferences;
+ (BOOL)openCurDirOnLaunch;
+ (BOOL)showOpenPanelOnLaunch;
++ (BOOL) shouldCheckoutBranch;
++ (void) setShouldCheckoutBranch:(BOOL)shouldCheckout;
@end
View
@@ -17,6 +17,7 @@
#define kShowWhitespaceDifferences @"PBShowWhitespaceDifferences"
#define kOpenCurDirOnLaunch @"PBOpenCurDirOnLaunch"
#define kShowOpenPanelOnLaunch @"PBShowOpenPanelOnLaunch"
+#define kShouldCheckoutBranch @"PBShouldCheckoutBranch"
@implementation PBGitDefaults
@@ -39,6 +40,8 @@ + (void)initialize
forKey:kOpenCurDirOnLaunch];
[defaultValues setObject:[NSNumber numberWithBool:YES]
forKey:kShowOpenPanelOnLaunch];
+ [defaultValues setObject:[NSNumber numberWithBool:YES]
+ forKey:kShouldCheckoutBranch];
[[NSUserDefaults standardUserDefaults] registerDefaults:defaultValues];
}
@@ -82,4 +85,14 @@ + (BOOL)showOpenPanelOnLaunch
return [[NSUserDefaults standardUserDefaults] boolForKey:kShowOpenPanelOnLaunch];
}
++ (BOOL) shouldCheckoutBranch
+{
+ return [[NSUserDefaults standardUserDefaults] boolForKey:kShouldCheckoutBranch];
+}
+
++ (void) setShouldCheckoutBranch:(BOOL)shouldCheckout
+{
+ [[NSUserDefaults standardUserDefaults] setBool:shouldCheckout forKey:kShouldCheckoutBranch];
+}
+
@end
View
@@ -29,6 +29,7 @@ extern NSString* PBGitRepositoryErrorDomain;
PBGitRevSpecifier *_headRef; // Caching
}
+- (BOOL) checkoutRefish:(id <PBGitRefish>)ref;
- (BOOL) createBranch:(NSString *)branchName atRefish:(id <PBGitRefish>)ref;
- (BOOL) createTag:(NSString *)tagName message:(NSString *)message atRefish:(id <PBGitRefish>)commitSHA;
View
@@ -428,6 +428,28 @@ - (NSString *) workingDirectory
#pragma mark Repository commands
+- (BOOL) checkoutRefish:(id <PBGitRefish>)ref
+{
+ NSString *refName = nil;
+ if ([ref refishType] == kGitXBranchType)
+ refName = [ref shortName];
+ else
+ refName = [ref refishName];
+
+ int retValue = 1;
+ NSArray *arguments = [NSArray arrayWithObjects:@"checkout", refName, nil];
+ NSString *output = [self outputInWorkdirForArguments:arguments retValue:&retValue];
+ if (retValue) {
+ NSString *message = [NSString stringWithFormat:@"There was an error checking out 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;
+ }
+
+ [self reloadRefs];
+ [self readCurrentBranch];
+ return YES;
+}
+
- (BOOL) createBranch:(NSString *)branchName atRefish:(id <PBGitRefish>)ref
{
if (!branchName || !ref)
View
@@ -23,6 +23,7 @@
IBOutlet NSPopUpButton *branchPopUp;
}
+- (void) checkout:(PBRefMenuItem *)sender;
- (void) createBranch:(PBRefMenuItem *)sender;
- (void) copySHA:(PBRefMenuItem *)sender;
- (void) copyPatch:(PBRefMenuItem *)sender;
View
@@ -31,13 +31,23 @@ - (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(
}
else if ([(NSString *)context isEqualToString:@"currentBranchChange"]) {
[self selectCurrentBranch];
+ [commitController rearrangeObjects];
}
else {
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
}
+#pragma mark Checkout
+
+- (void) checkout:(PBRefMenuItem *)sender
+{
+ id <PBGitRefish> refish = [sender refish];
+ [historyController.repository checkoutRefish:refish];
+}
+
+
#pragma mark Create Branch
- (void) createBranch:(PBRefMenuItem *)sender
@@ -125,18 +135,6 @@ - (void) removeRef:(PBRefMenuItem *)sender
NSBeginAlertSheet([NSString stringWithFormat:@"Delete %@?", ref_desc], @"Delete", @"Cancel", nil, [[historyController view] window], self, @selector(removeRefSheetDidEnd:returnCode:contextInfo:), NULL, sender, question);
}
-- (void) checkoutRef:(PBRefMenuItem *)sender
-{
- int ret = 1;
- [historyController.repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"checkout", [[sender refish] shortName], nil] retValue: &ret];
- if (ret) {
- [[historyController.repository windowController] showMessageSheet:@"Checking out branch failed" infoText:@"There was an error checking out the branch. Perhaps your working directory is not clean?"];
- return;
- }
- [historyController.repository reloadRefs];
- [commitController rearrangeObjects];
-}
-
#pragma mark Contextual menus
View
@@ -45,7 +45,7 @@ + (NSArray *) defaultMenuItemsForRef:(PBGitRef *)ref inRepository:(PBGitReposito
// checkout ref
NSString *checkoutTitle = [@"Checkout " stringByAppendingString:targetRefName];
- [items addObject:[PBRefMenuItem itemWithTitle:checkoutTitle action:@selector(checkoutRef:) enabled:!isHead]];
+ [items addObject:[PBRefMenuItem itemWithTitle:checkoutTitle action:@selector(checkout:) enabled:!isHead]];
[items addObject:[PBRefMenuItem separatorItem]];
// create branch
@@ -76,6 +76,9 @@ + (NSArray *) defaultMenuItemsForCommit:(PBGitCommit *)commit target:(id)target
{
NSMutableArray *items = [NSMutableArray array];
+ [items addObject:[PBRefMenuItem itemWithTitle:@"Checkout Commit" action:@selector(checkout:) enabled:YES]];
+ [items addObject:[PBRefMenuItem separatorItem]];
+
[items addObject:[PBRefMenuItem itemWithTitle:@"Create Branch…" action:@selector(createBranch:) enabled:YES]];
[items addObject:[PBRefMenuItem itemWithTitle:@"Create Tag…" action:@selector(createTag:) enabled:YES]];
[items addObject:[PBRefMenuItem separatorItem]];

0 comments on commit 69d6782

Please sign in to comment.