Permalink
Browse files

Tickets #151 and #155: check for illegal branch names before creating.

  • Loading branch information...
1 parent 2d0bbec commit 353d1053b081f882d05e7eef57fc46965265c759 @charlesorourke charlesorourke committed with May 28, 2009
Showing with 67 additions and 9 deletions.
  1. +53 −5 PBGitHistoryView.xib
  2. +1 −0 PBRefController.h
  3. +13 −4 PBRefController.m
View
@@ -8,7 +8,7 @@
<string key="IBDocument.HIToolboxVersion">353.00</string>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
- <integer value="236"/>
+ <integer value="237"/>
<integer value="27"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
@@ -1117,6 +1117,25 @@
<int key="NSPeriodicInterval">25</int>
</object>
</object>
+ <object class="NSTextField" id="27300806">
+ <reference key="NSNextResponder" ref="562356688"/>
+ <int key="NSvFlags">268</int>
+ <string key="NSFrame">{{251, 62}, {85, 17}}</string>
+ <reference key="NSSuperview" ref="562356688"/>
+ <bool key="NSEnabled">YES</bool>
+ <object class="NSTextFieldCell" key="NSCell" id="217429948">
+ <int key="NSCellFlags">68288064</int>
+ <int key="NSCellFlags2">272630784</int>
+ <string key="NSContents">Invalid name</string>
+ <reference key="NSSupport" ref="924107556"/>
+ <reference key="NSControlView" ref="27300806"/>
+ <reference key="NSBackgroundColor" ref="457244339"/>
+ <object class="NSColor" key="NSTextColor">
+ <int key="NSColorSpace">1</int>
+ <bytes key="NSRGB">MSAwIDAAA</bytes>
+ </object>
+ </object>
+ </object>
</object>
<string key="NSFrameSize">{346, 133}</string>
<reference key="NSSuperview"/>
@@ -2075,6 +2094,14 @@
</object>
<int key="connectionID">271</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">errorMessage</string>
+ <reference key="source" ref="892732705"/>
+ <reference key="destination" ref="27300806"/>
+ </object>
+ <int key="connectionID">274</int>
+ </object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@@ -2389,6 +2416,7 @@
<reference ref="383988892"/>
<reference ref="60467344"/>
<reference ref="657747237"/>
+ <reference ref="27300806"/>
</object>
<reference key="parent" ref="296392339"/>
</object>
@@ -2690,6 +2718,20 @@
<reference key="object" ref="496187369"/>
<reference key="parent" ref="604026377"/>
</object>
+ <object class="IBObjectRecord">
+ <int key="objectID">272</int>
+ <reference key="object" ref="27300806"/>
+ <object class="NSMutableArray" key="children">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference ref="217429948"/>
+ </object>
+ <reference key="parent" ref="562356688"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">273</int>
+ <reference key="object" ref="217429948"/>
+ <reference key="parent" ref="27300806"/>
+ </object>
</object>
</object>
<object class="NSMutableDictionary" key="flattenedProperties">
@@ -2767,6 +2809,8 @@
<string>27.IBViewIntegration.shadowOffsetHeight</string>
<string>27.IBViewIntegration.shadowOffsetWidth</string>
<string>27.ImportedFromIB2</string>
+ <string>272.IBPluginDependency</string>
+ <string>273.IBPluginDependency</string>
<string>28.IBPluginDependency</string>
<string>28.IBShouldRemoveOnLegacySave</string>
<string>29.IBPluginDependency</string>
@@ -2859,8 +2903,8 @@
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>{{521, 623}, {346, 133}}</string>
- <string>{{521, 623}, {346, 133}}</string>
+ <string>{{504, 581}, {346, 133}}</string>
+ <string>{{504, 581}, {346, 133}}</string>
<reference ref="8"/>
<string>{3.40282e+38, 3.40282e+38}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -2896,6 +2940,8 @@
<reference ref="8"/>
<reference ref="9"/>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
@@ -2929,7 +2975,7 @@
</object>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>{{312, 79}, {852, 432}}</string>
+ <string>{{189, 79}, {852, 432}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -2964,7 +3010,7 @@
</object>
</object>
<nil key="sourceID"/>
- <int key="maxID">271</int>
+ <int key="maxID">274</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -3120,6 +3166,7 @@
<string>branchPopUp</string>
<string>commitController</string>
<string>commitList</string>
+ <string>errorMessage</string>
<string>historyController</string>
<string>newBranchName</string>
<string>newBranchSheet</string>
@@ -3129,6 +3176,7 @@
<string>NSPopUpButton</string>
<string>NSArrayController</string>
<string>PBCommitList</string>
+ <string>NSTextField</string>
<string>PBGitHistoryController</string>
<string>NSTextField</string>
<string>NSWindow</string>
View
@@ -20,6 +20,7 @@
IBOutlet NSWindow *newBranchSheet;
IBOutlet NSTextField *newBranchName;
+ IBOutlet NSTextField *errorMessage;
IBOutlet NSPopUpButton *branchPopUp;
}
View
@@ -160,6 +160,7 @@ - (BOOL)tableView:(NSTableView *)aTableView
# pragma mark Add ref methods
-(void)addRef:(id)sender
{
+ [errorMessage setStringValue:@""];
[NSApp beginSheet:newBranchSheet
modalForWindow:[[historyController view] window]
modalDelegate:NULL
@@ -170,20 +171,28 @@ -(void)addRef:(id)sender
-(void)saveSheet:(id) sender
{
NSString *branchName = [@"refs/heads/" stringByAppendingString:[newBranchName stringValue]];
- [self closeSheet:sender];
if ([[commitController selectedObjects] count] == 0)
return;
-
+
PBGitCommit *commit = [[commitController selectedObjects] objectAtIndex:0];
+
int retValue = 1;
- [historyController.repository outputForArguments:[NSArray arrayWithObjects:@"update-ref", @"-mCreate branch from GitX", branchName, [commit realSha], NULL] retValue:&retValue];
+ [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)
{
- NSLog(@"Creating ref failed!");
+ [errorMessage setStringValue:@"Branch exists"];
return;
}
+ [self closeSheet:sender];
[commit addRef:[PBGitRef refFromString:branchName]];
[commitController rearrangeObjects];
}

0 comments on commit 353d105

Please sign in to comment.