Skip to content

Commit 353d105

Browse files
charlesorourkepieter
authored andcommitted
Tickets #151 and #155: check for illegal branch names before creating.
1 parent 2d0bbec commit 353d105

File tree

3 files changed

+67
-9
lines changed

3 files changed

+67
-9
lines changed

PBGitHistoryView.xib

+53-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<string key="IBDocument.HIToolboxVersion">353.00</string>
99
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
1010
<bool key="EncodedWithXMLCoder">YES</bool>
11-
<integer value="236"/>
11+
<integer value="237"/>
1212
<integer value="27"/>
1313
</object>
1414
<object class="NSArray" key="IBDocument.PluginDependencies">
@@ -1117,6 +1117,25 @@
11171117
<int key="NSPeriodicInterval">25</int>
11181118
</object>
11191119
</object>
1120+
<object class="NSTextField" id="27300806">
1121+
<reference key="NSNextResponder" ref="562356688"/>
1122+
<int key="NSvFlags">268</int>
1123+
<string key="NSFrame">{{251, 62}, {85, 17}}</string>
1124+
<reference key="NSSuperview" ref="562356688"/>
1125+
<bool key="NSEnabled">YES</bool>
1126+
<object class="NSTextFieldCell" key="NSCell" id="217429948">
1127+
<int key="NSCellFlags">68288064</int>
1128+
<int key="NSCellFlags2">272630784</int>
1129+
<string key="NSContents">Invalid name</string>
1130+
<reference key="NSSupport" ref="924107556"/>
1131+
<reference key="NSControlView" ref="27300806"/>
1132+
<reference key="NSBackgroundColor" ref="457244339"/>
1133+
<object class="NSColor" key="NSTextColor">
1134+
<int key="NSColorSpace">1</int>
1135+
<bytes key="NSRGB">MSAwIDAAA</bytes>
1136+
</object>
1137+
</object>
1138+
</object>
11201139
</object>
11211140
<string key="NSFrameSize">{346, 133}</string>
11221141
<reference key="NSSuperview"/>
@@ -2075,6 +2094,14 @@
20752094
</object>
20762095
<int key="connectionID">271</int>
20772096
</object>
2097+
<object class="IBConnectionRecord">
2098+
<object class="IBOutletConnection" key="connection">
2099+
<string key="label">errorMessage</string>
2100+
<reference key="source" ref="892732705"/>
2101+
<reference key="destination" ref="27300806"/>
2102+
</object>
2103+
<int key="connectionID">274</int>
2104+
</object>
20782105
</object>
20792106
<object class="IBMutableOrderedSet" key="objectRecords">
20802107
<object class="NSArray" key="orderedObjects">
@@ -2389,6 +2416,7 @@
23892416
<reference ref="383988892"/>
23902417
<reference ref="60467344"/>
23912418
<reference ref="657747237"/>
2419+
<reference ref="27300806"/>
23922420
</object>
23932421
<reference key="parent" ref="296392339"/>
23942422
</object>
@@ -2690,6 +2718,20 @@
26902718
<reference key="object" ref="496187369"/>
26912719
<reference key="parent" ref="604026377"/>
26922720
</object>
2721+
<object class="IBObjectRecord">
2722+
<int key="objectID">272</int>
2723+
<reference key="object" ref="27300806"/>
2724+
<object class="NSMutableArray" key="children">
2725+
<bool key="EncodedWithXMLCoder">YES</bool>
2726+
<reference ref="217429948"/>
2727+
</object>
2728+
<reference key="parent" ref="562356688"/>
2729+
</object>
2730+
<object class="IBObjectRecord">
2731+
<int key="objectID">273</int>
2732+
<reference key="object" ref="217429948"/>
2733+
<reference key="parent" ref="27300806"/>
2734+
</object>
26932735
</object>
26942736
</object>
26952737
<object class="NSMutableDictionary" key="flattenedProperties">
@@ -2767,6 +2809,8 @@
27672809
<string>27.IBViewIntegration.shadowOffsetHeight</string>
27682810
<string>27.IBViewIntegration.shadowOffsetWidth</string>
27692811
<string>27.ImportedFromIB2</string>
2812+
<string>272.IBPluginDependency</string>
2813+
<string>273.IBPluginDependency</string>
27702814
<string>28.IBPluginDependency</string>
27712815
<string>28.IBShouldRemoveOnLegacySave</string>
27722816
<string>29.IBPluginDependency</string>
@@ -2859,8 +2903,8 @@
28592903
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
28602904
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
28612905
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
2862-
<string>{{521, 623}, {346, 133}}</string>
2863-
<string>{{521, 623}, {346, 133}}</string>
2906+
<string>{{504, 581}, {346, 133}}</string>
2907+
<string>{{504, 581}, {346, 133}}</string>
28642908
<reference ref="8"/>
28652909
<string>{3.40282e+38, 3.40282e+38}</string>
28662910
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -2896,6 +2940,8 @@
28962940
<reference ref="8"/>
28972941
<reference ref="9"/>
28982942
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
2943+
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
2944+
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
28992945
<reference ref="9"/>
29002946
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
29012947
<reference ref="9"/>
@@ -2929,7 +2975,7 @@
29292975
</object>
29302976
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
29312977
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
2932-
<string>{{312, 79}, {852, 432}}</string>
2978+
<string>{{189, 79}, {852, 432}}</string>
29332979
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
29342980
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
29352981
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -2964,7 +3010,7 @@
29643010
</object>
29653011
</object>
29663012
<nil key="sourceID"/>
2967-
<int key="maxID">271</int>
3013+
<int key="maxID">274</int>
29683014
</object>
29693015
<object class="IBClassDescriber" key="IBDocument.Classes">
29703016
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -3120,6 +3166,7 @@
31203166
<string>branchPopUp</string>
31213167
<string>commitController</string>
31223168
<string>commitList</string>
3169+
<string>errorMessage</string>
31233170
<string>historyController</string>
31243171
<string>newBranchName</string>
31253172
<string>newBranchSheet</string>
@@ -3129,6 +3176,7 @@
31293176
<string>NSPopUpButton</string>
31303177
<string>NSArrayController</string>
31313178
<string>PBCommitList</string>
3179+
<string>NSTextField</string>
31323180
<string>PBGitHistoryController</string>
31333181
<string>NSTextField</string>
31343182
<string>NSWindow</string>

PBRefController.h

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
IBOutlet NSWindow *newBranchSheet;
2222
IBOutlet NSTextField *newBranchName;
23+
IBOutlet NSTextField *errorMessage;
2324

2425
IBOutlet NSPopUpButton *branchPopUp;
2526
}

PBRefController.m

+13-4
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ - (BOOL)tableView:(NSTableView *)aTableView
160160
# pragma mark Add ref methods
161161
-(void)addRef:(id)sender
162162
{
163+
[errorMessage setStringValue:@""];
163164
[NSApp beginSheet:newBranchSheet
164165
modalForWindow:[[historyController view] window]
165166
modalDelegate:NULL
@@ -170,20 +171,28 @@ -(void)addRef:(id)sender
170171
-(void)saveSheet:(id) sender
171172
{
172173
NSString *branchName = [@"refs/heads/" stringByAppendingString:[newBranchName stringValue]];
173-
[self closeSheet:sender];
174174

175175
if ([[commitController selectedObjects] count] == 0)
176176
return;
177-
177+
178178
PBGitCommit *commit = [[commitController selectedObjects] objectAtIndex:0];
179+
179180
int retValue = 1;
180-
[historyController.repository outputForArguments:[NSArray arrayWithObjects:@"update-ref", @"-mCreate branch from GitX", branchName, [commit realSha], NULL] retValue:&retValue];
181+
[historyController.repository outputForArguments:[NSArray arrayWithObjects:@"check-ref-format", branchName, nil] retValue:&retValue];
182+
if (retValue != 0) {
183+
[errorMessage setStringValue:@"Invalid name"];
184+
return;
185+
}
186+
187+
retValue = 1;
188+
[historyController.repository outputForArguments:[NSArray arrayWithObjects:@"update-ref", @"-mCreate branch from GitX", branchName, [commit realSha], @"0000000000000000000000000000000000000000", NULL] retValue:&retValue];
181189
if (retValue)
182190
{
183-
NSLog(@"Creating ref failed!");
191+
[errorMessage setStringValue:@"Branch exists"];
184192
return;
185193
}
186194

195+
[self closeSheet:sender];
187196
[commit addRef:[PBGitRef refFromString:branchName]];
188197
[commitController rearrangeObjects];
189198
}

0 commit comments

Comments
 (0)