[gitg/remote-operations: 4/4] Manage invalid remotes




commit f8ba0050e4ffbabca4caf7b9bd2896e7ae921fa7
Author: Alberto Fanjul <albertofanjul gmail com>
Date:   Fri Jan 28 23:45:57 2022 +0100

    Manage invalid remotes
    
    List invalid remotes only present in config
    Edit/Remove remotes from header

 ...it-remote.vala => gitg-edit-remote-action.vala} | 46 +++++++-------------
 gitg/gitg-ref-action-fetch.vala                    | 41 +++++++++++-------
 ...-remote.vala => gitg-remove-remote-action.vala} | 49 +++++++---------------
 gitg/history/gitg-history-refs-list.vala           | 23 ++++++++--
 gitg/history/gitg-history.vala                     | 20 +--------
 gitg/meson.build                                   |  4 +-
 6 files changed, 76 insertions(+), 107 deletions(-)
---
diff --git a/gitg/gitg-ref-action-edit-remote.vala b/gitg/gitg-edit-remote-action.vala
similarity index 68%
rename from gitg/gitg-ref-action-edit-remote.vala
rename to gitg/gitg-edit-remote-action.vala
index 0c7adbaf..a3bc810f 100644
--- a/gitg/gitg-ref-action-edit-remote.vala
+++ b/gitg/gitg-edit-remote-action.vala
@@ -20,43 +20,25 @@
 namespace Gitg
 {
 
-class RefActionEditRemote : GitgExt.UIElement, GitgExt.Action, GitgExt.RefAction, Object
+class EditRemoteAction : GitgExt.UIElement, GitgExt.Action, Object
 {
        // Do this to pull in config.h before glib.h (for gettext...)
        private const string version = Gitg.Config.VERSION;
 
        public GitgExt.Application? application { owned get; construct set; }
        public GitgExt.RefActionInterface action_interface { get; construct set; }
-       public Gitg.Ref reference { get; construct set; }
-       Gitg.Ref? d_remote_ref;
+       string remote_name;
        Gitg.Remote? d_remote;
 
-       public RefActionEditRemote(GitgExt.Application        application,
-                                                          GitgExt.RefActionInterface action_interface,
-                                                          Gitg.Ref                   reference)
+       public EditRemoteAction(GitgExt.Application        application,
+                               GitgExt.RefActionInterface action_interface,
+                               string                     remote_name)
        {
                Object(application:      application,
-                      action_interface: action_interface,
-                          reference:        reference);
+                      action_interface: action_interface);
+               this.remote_name = remote_name;
 
-               var branch = reference as Ggit.Branch;
-
-               if (branch != null)
-               {
-                       try
-                       {
-                               d_remote_ref = branch.get_upstream() as Gitg.Ref;
-                       } catch {}
-               }
-               else if (reference.parsed_name.remote_name != null)
-               {
-                       d_remote_ref = reference;
-               }
-
-               if (d_remote_ref != null)
-               {
-                       d_remote = application.remote_lookup.lookup(d_remote_ref.parsed_name.remote_name);
-               }
+               d_remote = application.remote_lookup.lookup(remote_name);
        }
 
        public string id
@@ -74,17 +56,17 @@ class RefActionEditRemote : GitgExt.UIElement, GitgExt.Action, GitgExt.RefAction
                owned get { return _("Edits the remote from the remotes list"); }
        }
 
-       public bool available
-       {
-               get { return d_remote != null; }
-       }
+       //public bool available
+       //{
+       //      get { return d_remote != null; }
+       //}
 
        public void activate()
        {
                var dlg = new EditRemoteDialog((Gtk.Window)application);
 
-               dlg.new_remote_name = d_remote_ref.parsed_name.remote_name;
-               var old_name = d_remote_ref.parsed_name.remote_name;
+               dlg.new_remote_name = remote_name;
+               var old_name = remote_name;
                dlg.new_remote_url = d_remote.get_url();
 
                dlg.response.connect((d, resp) => {
diff --git a/gitg/gitg-ref-action-fetch.vala b/gitg/gitg-ref-action-fetch.vala
index f0af2363..da3a26a1 100644
--- a/gitg/gitg-ref-action-fetch.vala
+++ b/gitg/gitg-ref-action-fetch.vala
@@ -31,33 +31,42 @@ class RefActionFetch : GitgExt.UIElement, GitgExt.Action, GitgExt.RefAction, Obj
 
        private Gitg.Ref? d_remote_ref;
        private Gitg.Remote? d_remote;
+       string remote_name;
 
        public RefActionFetch(GitgExt.Application        application,
                              GitgExt.RefActionInterface action_interface,
-                             Gitg.Ref                   reference)
+                             Gitg.Ref?                   reference, string? remote_name = null)
        {
                Object(application:      application,
                       action_interface: action_interface,
                       reference:        reference);
 
-               var branch = reference as Ggit.Branch;
-
-               if (branch != null)
+               if (reference != null)
                {
-                       try
+                       var branch = reference as Ggit.Branch;
+
+                       if (branch != null)
                        {
-                               d_remote_ref = branch.get_upstream() as Gitg.Ref;
-                       } catch {}
-               }
-               else if (reference.parsed_name.remote_name != null)
-               {
-                       d_remote_ref = reference;
-               }
+                               try
+                               {
+                                       d_remote_ref = branch.get_upstream() as Gitg.Ref;
+                               } catch {}
+                       }
+                       else if (reference.parsed_name.remote_name != null)
+                       {
+                               d_remote_ref = reference;
+                       }
 
-               if (d_remote_ref != null)
+                       if (d_remote_ref != null)
+                       {
+                               this.remote_name = d_remote_ref.parsed_name.remote_name;
+                       }
+               }
+               else
                {
-                       d_remote = application.remote_lookup.lookup(d_remote_ref.parsed_name.remote_name);
+                       this.remote_name = remote_name;
                }
+               d_remote = application.remote_lookup.lookup(this.remote_name);
        }
 
        public string id
@@ -71,7 +80,7 @@ class RefActionFetch : GitgExt.UIElement, GitgExt.Action, GitgExt.RefAction, Obj
                {
                        if (d_remote != null)
                        {
-                               return _("Fetch from %s").printf(d_remote_ref.parsed_name.remote_name);
+                               return _("Fetch from %s").printf(remote_name);
                        }
                        else
                        {
@@ -82,7 +91,7 @@ class RefActionFetch : GitgExt.UIElement, GitgExt.Action, GitgExt.RefAction, Obj
 
        public string description
        {
-               owned get { return _("Fetch remote objects from 
%s").printf(d_remote_ref.parsed_name.remote_name); }
+               owned get { return _("Fetch remote objects from %s").printf(remote_name); }
        }
 
        public bool available
diff --git a/gitg/gitg-ref-action-remove-remote.vala b/gitg/gitg-remove-remote-action.vala
similarity index 71%
rename from gitg/gitg-ref-action-remove-remote.vala
rename to gitg/gitg-remove-remote-action.vala
index 764d924e..ace0994f 100644
--- a/gitg/gitg-ref-action-remove-remote.vala
+++ b/gitg/gitg-remove-remote-action.vala
@@ -20,43 +20,24 @@
 namespace Gitg
 {
 
-class RefActionRemoveRemote : GitgExt.UIElement, GitgExt.Action, GitgExt.RefAction, Object
+class RemoveRemoteAction : GitgExt.UIElement, GitgExt.Action, Object
 {
        // Do this to pull in config.h before glib.h (for gettext...)
        private const string version = Gitg.Config.VERSION;
 
        public GitgExt.Application? application { owned get; construct set; }
        public GitgExt.RefActionInterface action_interface { get; construct set; }
-       public Gitg.Ref reference { get; construct set; }
-       Gitg.Ref? d_remote_ref;
+       string remote_name;
        Gitg.Remote? d_remote;
 
-       public RefActionRemoveRemote(GitgExt.Application        application,
-                                                                GitgExt.RefActionInterface action_interface,
-                                                                Gitg.Ref                   reference)
+       public RemoveRemoteAction(GitgExt.Application        application,
+                                 GitgExt.RefActionInterface action_interface,
+                                 string                     remote_name)
        {
                Object(application:      application,
-                      action_interface: action_interface,
-                          reference:        reference);
-
-               var branch = reference as Ggit.Branch;
-
-               if (branch != null)
-               {
-                       try
-                       {
-                               d_remote_ref = branch.get_upstream() as Gitg.Ref;
-                       } catch {}
-               }
-               else if (reference.parsed_name.remote_name != null)
-               {
-                       d_remote_ref = reference;
-               }
-
-               if (d_remote_ref != null)
-               {
-                       d_remote = application.remote_lookup.lookup(d_remote_ref.parsed_name.remote_name);
-               }
+                      action_interface: action_interface);
+                this.remote_name = remote_name;
+               d_remote = application.remote_lookup.lookup(remote_name);
        }
 
        public string id
@@ -74,17 +55,15 @@ class RefActionRemoveRemote : GitgExt.UIElement, GitgExt.Action, GitgExt.RefActi
                owned get { return _("Removes remote from the remotes list"); }
        }
 
-       public bool available
-       {
-               get { return d_remote != null; }
-       }
+       //public bool available
+       //{
+       //      get { return true/*d_remote != null*/; }
+       //}
 
        public void activate()
        {
         var query = new GitgExt.UserQuery();
 
-               var remote_name = d_remote_ref.parsed_name.remote_name;
-
                query.title = (_("Delete remote %s")).printf(remote_name);
                query.message = (_("Are you sure that you want to remove the remote 
%s?")).printf(remote_name);
 
@@ -110,7 +89,7 @@ class RefActionRemoveRemote : GitgExt.UIElement, GitgExt.Action, GitgExt.RefActi
 
                try
                {
-                       repo.remove_remote(d_remote.get_name());
+                       repo.remove_remote(remote_name);
                }
                catch (Error e)
                {
@@ -122,7 +101,7 @@ class RefActionRemoveRemote : GitgExt.UIElement, GitgExt.Action, GitgExt.RefActi
                ((Gtk.ApplicationWindow)application).activate_action("reload", null);
                return true;
        }
-}
+    }
 
 }
 
diff --git a/gitg/history/gitg-history-refs-list.vala b/gitg/history/gitg-history-refs-list.vala
index de411efc..32c67bd9 100644
--- a/gitg/history/gitg-history-refs-list.vala
+++ b/gitg/history/gitg-history-refs-list.vala
@@ -563,7 +563,7 @@ public class RefsList : Gtk.ListBox
 
        private Gee.HashMap<string, RemoteHeader> d_header_map;
 
-       public GitgExt.RemoteLookup? remote_lookup { get; set; }
+       public GitgExt.Application? application { get; set; }
 
        public Gitg.Repository? repository
        {
@@ -937,9 +937,9 @@ public class RefsList : Gtk.ListBox
        {
                Gitg.Remote? remote = null;
 
-               if (remote_lookup != null)
+               if (application.remote_lookup != null)
                {
-                       remote = remote_lookup.lookup(name);
+                       remote = application.remote_lookup.lookup(name);
                }
 
                if (remote != null)
@@ -950,6 +950,13 @@ public class RefsList : Gtk.ListBox
 
                var header = new RefHeader.remote(name, remote);
                init_header(header);
+               var actions = new Gee.LinkedList<GitgExt.Action>();
+               var af = new ActionInterface(application, this);
+               actions.add(new Gitg.RefActionFetch(application, af, null, name));
+               actions.add(new Gitg.EditRemoteAction(application, af, name));
+               actions.add(new Gitg.RemoveRemoteAction(application, af, name));
+               header.actions = actions;
+
 
                d_header_map[name] = new RemoteHeader(header);
                add(header);
@@ -1227,6 +1234,16 @@ public class RefsList : Gtk.ListBox
                                }
                                return 0;
                        });
+
+                       var r = new Regex("remote\\.(.*)\\.url");
+
+                       //remotes not valid but existing in git config
+                       d_repository.get_config().snapshot().match_foreach(r, (info, value) => {
+                               var name = info.fetch(1);
+                               if (!d_header_map.has_key(name))
+                                 add_remote_header(name);
+                               return 0;
+                       });
                } catch {}
 
                d_selected_row = null;
diff --git a/gitg/history/gitg-history.vala b/gitg/history/gitg-history.vala
index f2c25828..e8933f67 100644
--- a/gitg/history/gitg-history.vala
+++ b/gitg/history/gitg-history.vala
@@ -578,7 +578,7 @@ namespace GitgHistory
                {
                        d_main = new Paned();
 
-                       d_main.refs_list.remote_lookup = application.remote_lookup;
+                       d_main.refs_list.application = application;
 
                        d_main.commit_list_view.model = d_commit_list_model;
 
@@ -871,24 +871,6 @@ namespace GitgHistory
                        add_ref_action(actions, new Gitg.RefActionDelete(application, af, reference));
                        add_ref_action(actions, new Gitg.RefActionCopyName(application, af, reference));
 
-                       var remove_remote = new Gitg.RefActionRemoveRemote(application, af, reference);
-
-                       if (remove_remote.available)
-                       {
-                               actions.add(null);
-                       }
-
-                       add_ref_action(actions, remove_remote);
-
-                       var edit_remote = new Gitg.RefActionEditRemote(application, af, reference);
-
-                       if (edit_remote.available)
-                       {
-                               actions.add(null);
-                       }
-
-                       add_ref_action(actions, edit_remote);
-
                        var fetch = new Gitg.RefActionFetch(application, af, reference);
 
                        if (fetch.available)
diff --git a/gitg/meson.build b/gitg/meson.build
index e4d77807..8ebe490d 100644
--- a/gitg/meson.build
+++ b/gitg/meson.build
@@ -37,6 +37,7 @@ sources = gitg_sources + files(
   'gitg-checkout-remote-branch-dialog.vala',
   'gitg-dash-view.vala',
   'gitg-dirs.vala',
+  'gitg-edit-remote-action.vala',
   'gitg-notifications.vala',
   'gitg-plugins-engine.vala',
   'gitg-popup-menu.vala',
@@ -44,11 +45,10 @@ sources = gitg_sources + files(
   'gitg-recursive-scanner.vala',
   'gitg-ref-action-copy-name.vala',
   'gitg-ref-action-delete.vala',
-  'gitg-ref-action-edit-remote.vala',
   'gitg-ref-action-fetch.vala',
   'gitg-ref-action-push.vala',
-  'gitg-ref-action-remove-remote.vala',
   'gitg-ref-action-rename.vala',
+  'gitg-remove-remote-action.vala',
   'gitg-add-remote-action-dialog.vala',
   'gitg-add-remote-action.vala',
   'gitg-remote-manager.vala',


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]