@@ -18,6 +18,8 @@ public class GitStatusPanel : EditorWindow
1818
1919 private string _branch ;
2020
21+ private string [ ] _branches ;
22+
2123 private string [ ] _changedFiles ;
2224
2325 private string [ ] _untrackedFiles ;
@@ -53,7 +55,36 @@ private void Update()
5355 private void OnGUI ( )
5456 {
5557
56- GUILayout . Label ( $ "Current Branch: { _branch } ") ;
58+ GUILayout . Space ( 5 ) ;
59+
60+ var selectedBranch = Array . IndexOf ( _branches , _branch ) ;
61+
62+ selectedBranch = EditorGUILayout . Popup ( "Branch:" , selectedBranch , _branches ) ;
63+
64+ if ( ! _branches [ selectedBranch ] . Equals ( _branch ) )
65+ {
66+
67+ if ( _changedFiles ? . Length > 0 )
68+ {
69+
70+ EditorUtility . DisplayDialog (
71+ $ "Unable to checkout branch",
72+ $ "Unable to checkout { _branches [ selectedBranch ] } as with { _changedFiles ? . Length } changes. " +
73+ "Commit, discard or stash before checking out a different branch." ,
74+ "Ok" ) ;
75+
76+ }
77+ else
78+ {
79+
80+ Git . CheckoutBranch ( _branches [ selectedBranch ] ) ;
81+
82+ _branch = _branches [ selectedBranch ] ;
83+
84+ }
85+
86+ }
87+
5788 GUILayout . Label ( $ "Number of Changes: { _changedFiles ? . Length } ") ;
5889 GUILayout . Label ( $ "Untracked Files: { _untrackedFiles ? . Length } ") ;
5990 GUILayout . Label ( $ "Last Updated: { _lastUpdated } ") ;
@@ -72,6 +103,8 @@ private void UpdateData()
72103
73104 _branch = Git . Branch ( ) ;
74105
106+ _branches = Git . Branches ( ) ;
107+
75108 _changedFiles = Git . ChangedFiles ( ) ;
76109
77110 _untrackedFiles = Git . UntrackedFiles ( ) ;
0 commit comments