@@ -15,6 +15,13 @@ class BranchesView : Subview
15
15
private const string ConfirmSwitchMessage = "Switch branch to {0}?" ;
16
16
private const string ConfirmSwitchOK = "Switch" ;
17
17
private const string ConfirmSwitchCancel = "Cancel" ;
18
+ private const string ConfirmCheckoutBranchTitle = "Confirm branch checkout" ;
19
+ private const string ConfirmCheckoutBranchMessage = "Checkout branch {0} from {1}?" ;
20
+ private const string ConfirmCheckoutBranchOK = "Checkout" ;
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" ;
18
25
private const string NewBranchCancelButton = "x" ;
19
26
private const string NewBranchConfirmButton = "Create" ;
20
27
private const string FavoritesSetting = "Favorites" ;
@@ -656,37 +663,62 @@ private void OnTreeNodeGUI(BranchTreeNode node)
656
663
657
664
if ( Event . current . clickCount > 1 && mode == BranchesMode . Default )
658
665
{
659
- if ( node . Type == NodeType . LocalBranch &&
660
- EditorUtility . DisplayDialog ( ConfirmSwitchTitle , String . Format ( ConfirmSwitchMessage , node . Name ) , ConfirmSwitchOK ,
661
- ConfirmSwitchCancel ) )
666
+ if ( node . Type == NodeType . LocalBranch )
662
667
{
663
- GitClient . SwitchBranch ( node . Name )
664
- . FinallyInUI ( ( success , e ) =>
665
- {
666
- if ( success )
667
- Refresh ( ) ;
668
- else
668
+ if ( EditorUtility . DisplayDialog ( ConfirmSwitchTitle , String . Format ( ConfirmSwitchMessage , node . Name ) , ConfirmSwitchOK , ConfirmSwitchCancel ) )
669
+ {
670
+ GitClient . SwitchBranch ( node . Name )
671
+ . FinallyInUI ( ( success , e ) =>
669
672
{
670
- EditorUtility . DisplayDialog ( Localization . SwitchBranchTitle ,
671
- String . Format ( Localization . SwitchBranchFailedDescription , node . Name ) ,
672
- Localization . Ok ) ;
673
- }
674
- } ) . Start ( ) ;
673
+ if ( success )
674
+ {
675
+ Refresh ( ) ;
676
+ }
677
+ else
678
+ {
679
+ EditorUtility . DisplayDialog ( Localization . SwitchBranchTitle ,
680
+ String . Format ( Localization . SwitchBranchFailedDescription , node . Name ) ,
681
+ Localization . Ok ) ;
682
+ }
683
+ } ) . Start ( ) ;
684
+ }
675
685
}
676
686
else if ( node . Type == NodeType . RemoteBranch )
677
687
{
678
- GitClient . CreateBranch ( selectedNode . Name . Substring ( selectedNode . Name . IndexOf ( '/' ) + 1 ) , selectedNode . Name )
679
- . FinallyInUI ( ( success , e ) =>
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 ) )
693
+ {
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 )
680
705
{
681
- if ( success )
682
- Refresh ( ) ;
683
- else
684
- {
685
- EditorUtility . DisplayDialog ( Localization . SwitchBranchTitle ,
686
- String . Format ( Localization . SwitchBranchFailedDescription , node . Name ) ,
687
- Localization . Ok ) ;
688
- }
689
- } ) . Start ( ) ;
706
+ GitClient . CreateBranch ( branchName , selectedNode . Name )
707
+ . FinallyInUI ( ( success , e ) =>
708
+ {
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
+ }
721
+ }
690
722
}
691
723
}
692
724
}
0 commit comments