@@ -26,7 +26,8 @@ namespace Scratch.FolderManager {
2626
2727 private static Icon added_icon;
2828 private static Icon modified_icon;
29- private SimpleAction change_branch_action;
29+ private SimpleAction checkout_local_branch_action;
30+ private SimpleAction checkout_remote_branch_action;
3031
3132 public signal void closed ();
3233
@@ -68,16 +69,21 @@ namespace Scratch.FolderManager {
6869 );
6970 }
7071
71- change_branch_action . set_state (monitored_repo. branch_name);
72+ checkout_local_branch_action . set_state (monitored_repo. branch_name);
7273 }
7374 }
7475
7576 construct {
7677 monitored_repo = Scratch . Services . GitManager . get_instance (). add_project (this );
7778 notify[" name" ]. connect (branch_or_name_changed);
7879 if (monitored_repo != null ) {
79- change_branch_action = new SimpleAction .stateful (
80- FileView . ACTION_CHANGE_BRANCH ,
80+ checkout_local_branch_action = new SimpleAction .stateful (
81+ FileView . ACTION_CHECKOUT_LOCAL_BRANCH ,
82+ GLib . VariantType . STRING ,
83+ " "
84+ );
85+ checkout_remote_branch_action = new SimpleAction .stateful (
86+ FileView . ACTION_CHECKOUT_REMOTE_BRANCH ,
8187 GLib . VariantType . STRING ,
8288 " "
8389 );
@@ -86,7 +92,8 @@ namespace Scratch.FolderManager {
8692 monitored_repo. file_status_change. connect (() = > update_item_status (null ));
8793 monitored_repo. update_status_map ();
8894 monitored_repo. branch_changed ();
89- change_branch_action. activate. connect (handle_change_branch_action);
95+ checkout_local_branch_action. activate. connect (handle_checkout_local_branch_action);
96+ checkout_remote_branch_action. activate. connect (handle_checkout_remote_branch_action);
9097 }
9198 }
9299
@@ -315,20 +322,44 @@ namespace Scratch.FolderManager {
315322
316323 protected GLib .MenuItem create_submenu_for_branch () {
317324 // Ensures that action for relevant project is being used
318- view. actions. add_action (change_branch_action);
319-
320- GLib . Menu branch_selection_menu = new GLib .Menu ();
321- foreach (unowned var branch_name in monitored_repo. get_local_branches ()) {
322- branch_selection_menu. append (
323- branch_name,
324- GLib . Action . print_detailed_name (
325- FileView . ACTION_PREFIX + FileView . ACTION_CHANGE_BRANCH ,
326- branch_name
327- )
328- );
325+ view. actions. add_action (checkout_local_branch_action);
326+ view. actions. add_action (checkout_remote_branch_action);
327+
328+ unowned var local_branches = monitored_repo. get_local_branches ();
329+ var local_branch_submenu = new Menu ();
330+ var local_branch_menu = new Menu ();
331+ if (local_branches. length () > 0 ) {
332+ local_branch_submenu. append_submenu (_(" Local" ), local_branch_menu);
333+ foreach (unowned var branch_name in local_branches) {
334+ local_branch_menu. append (
335+ branch_name,
336+ GLib . Action . print_detailed_name (
337+ FileView . ACTION_PREFIX + FileView . ACTION_CHECKOUT_LOCAL_BRANCH ,
338+ branch_name
339+ )
340+ );
341+ }
329342 }
330343
331344
345+ unowned var remote_branches = monitored_repo. get_remote_branches ();
346+ var remote_branch_submenu = new Menu ();
347+ var remote_branch_menu = new Menu ();
348+ if (remote_branches. length () > 0 ) {
349+ remote_branch_submenu. append_submenu (_(" Remote" ), remote_branch_menu);
350+ foreach (unowned var branch_name in remote_branches) {
351+ remote_branch_menu. append (
352+ branch_name,
353+ GLib . Action . print_detailed_name (
354+ FileView . ACTION_PREFIX + FileView . ACTION_CHECKOUT_REMOTE_BRANCH ,
355+ branch_name
356+ )
357+ );
358+ }
359+
360+
361+ }
362+
332363 var new_branch_item = new GLib .MenuItem (
333364 _(" New Branch…" ),
334365 GLib . Action . print_detailed_name (
@@ -351,22 +382,36 @@ namespace Scratch.FolderManager {
351382 bottom_section. append_item (new_branch_item);
352383
353384 var menu = new GLib .Menu ();
354- menu. append_section (null , branch_selection_menu);
385+ menu. append_section (null , local_branch_submenu);
386+ menu. append_section (null , remote_branch_submenu);
355387 menu. append_section (null , bottom_section);
356388
357389 var menu_item = new GLib .MenuItem .submenu (_(" Branch" ), menu);
358390 return menu_item;
359391 }
360392
361- private void handle_change_branch_action (GLib .Variant ? parameter ) {
362- var branch_name = parameter . get_string ();
393+ private void handle_checkout_local_branch_action (GLib .Variant ? param ) {
394+ var branch_name = param != null ? param . get_string () : " " ;
363395 try {
364396 monitored_repo. change_local_branch (branch_name);
365397 } catch (GLib . Error e) {
366398 warning (" Failed to change branch to %s. %s " , branch_name, e. message);
367399 }
368400 }
369401
402+ private void handle_checkout_remote_branch_action (GLib .Variant ? param ) {
403+ var branch_name = param != null ? param. get_string () : " " ;
404+ if (branch_name == " " ) {
405+ return ;
406+ }
407+
408+ try {
409+ monitored_repo. checkout_remote_branch (branch_name);
410+ } catch (GLib . Error e) {
411+ warning (" Failed to change branch to %s. %s " , branch_name, e. message);
412+ }
413+ }
414+
370415 public void update_item_status (FolderItem ? start_folder ) {
371416 if (monitored_repo == null ) {
372417 debug (" Ignore non-git folders" );
0 commit comments