@@ -16,9 +16,12 @@ class BranchesView : Subview
16
16
private const string ConfirmSwitchOK = "Switch" ;
17
17
private const string ConfirmSwitchCancel = "Cancel" ;
18
18
private const string ConfirmCheckoutBranchTitle = "Confirm branch checkout" ;
19
- private const string ConfirmCheckoutBranchMessage = "Checkout branch {0}?" ;
19
+ private const string ConfirmCheckoutBranchMessage = "Checkout branch {0} from {1} ?" ;
20
20
private const string ConfirmCheckoutBranchOK = "Checkout" ;
21
21
private const string ConfirmCheckoutBranchCancel = "Cancel" ;
22
+ private const string WarningCheckoutBranchExistsTitle = "Branch already exists" ;
23
+ private const string WarningCheckoutBranchExistsMessage = "Branch {0} already exists" ;
24
+ private const string WarningCheckoutBranchExistsOK = "Ok" ;
22
25
private const string NewBranchCancelButton = "x" ;
23
26
private const string NewBranchConfirmButton = "Create" ;
24
27
private const string FavoritesSetting = "Favorites" ;
@@ -668,32 +671,53 @@ private void OnTreeNodeGUI(BranchTreeNode node)
668
671
. FinallyInUI ( ( success , e ) =>
669
672
{
670
673
if ( success )
674
+ {
671
675
Refresh ( ) ;
676
+ }
672
677
else
673
678
{
674
679
EditorUtility . DisplayDialog ( Localization . SwitchBranchTitle ,
675
680
String . Format ( Localization . SwitchBranchFailedDescription , node . Name ) ,
676
- Localization . Ok ) ;
681
+ Localization . Ok ) ;
677
682
}
678
683
} ) . Start ( ) ;
679
684
}
680
685
}
681
686
else if ( node . Type == NodeType . RemoteBranch )
682
687
{
683
- if ( EditorUtility . DisplayDialog ( ConfirmCheckoutBranchTitle , String . Format ( ConfirmCheckoutBranchMessage , node . Name ) , ConfirmCheckoutBranchOK , ConfirmCheckoutBranchCancel ) )
688
+ var indexOfFirstSlash = selectedNode . Name . IndexOf ( '/' ) ;
689
+ var originName = selectedNode . Name . Substring ( 0 , indexOfFirstSlash ) ;
690
+ var branchName = selectedNode . Name . Substring ( indexOfFirstSlash + 1 ) ;
691
+
692
+ if ( Repository . LocalBranches . Any ( localBranch => localBranch . Name == branchName ) )
684
693
{
685
- GitClient . CreateBranch ( selectedNode . Name . Substring ( selectedNode . Name . IndexOf ( '/' ) + 1 ) , selectedNode . Name )
686
- . FinallyInUI ( ( success , e ) =>
687
- {
688
- if ( success )
689
- Refresh ( ) ;
690
- else
694
+ EditorUtility . DisplayDialog ( WarningCheckoutBranchExistsTitle ,
695
+ String . Format ( WarningCheckoutBranchExistsMessage , branchName ) ,
696
+ WarningCheckoutBranchExistsOK ) ;
697
+ }
698
+ else
699
+ {
700
+ var confirmCheckout = EditorUtility . DisplayDialog ( ConfirmCheckoutBranchTitle ,
701
+ String . Format ( ConfirmCheckoutBranchMessage , node . Name , originName ) ,
702
+ ConfirmCheckoutBranchOK , ConfirmCheckoutBranchCancel ) ;
703
+
704
+ if ( confirmCheckout )
705
+ {
706
+ GitClient . CreateBranch ( branchName , selectedNode . Name )
707
+ . FinallyInUI ( ( success , e ) =>
691
708
{
692
- EditorUtility . DisplayDialog ( Localization . SwitchBranchTitle ,
693
- String . Format ( Localization . SwitchBranchFailedDescription , node . Name ) ,
694
- Localization . Ok ) ;
695
- }
696
- } ) . Start ( ) ;
709
+ if ( success )
710
+ {
711
+ Refresh ( ) ;
712
+ }
713
+ else
714
+ {
715
+ EditorUtility . DisplayDialog ( Localization . SwitchBranchTitle ,
716
+ String . Format ( Localization . SwitchBranchFailedDescription , node . Name ) ,
717
+ Localization . Ok ) ;
718
+ }
719
+ } ) . Start ( ) ;
720
+ }
697
721
}
698
722
}
699
723
}
0 commit comments