handling of old branches
authorAlan Knowles <alan@roojs.com>
Mon, 5 Nov 2018 07:28:53 +0000 (15:28 +0800)
committerAlan Knowles <alan@roojs.com>
Mon, 5 Nov 2018 07:28:53 +0000 (15:28 +0800)
GitMonitor.vala
GitMonitorQueue.vala
GitRepo.vala
Makefile.am
MergeBranch.bjs
NewBranch.bjs
NewBranch.vala
RooTicket.vala
StatusIcon.vala
config1.builder

index 7866310..543ba58 100644 (file)
@@ -594,10 +594,8 @@ public class GitMonitor : Monitor
                cmd = new GitMonitorQueue(src);
                cmd.action = "commit";
                cmd.message = cmd.vname;
-               this.queue.add(cmd);
-               
-               
-                 
+               this.queue.append_val(cmd);
                 
        }
        public override  void onDeleted(MonitorNamePathDir src) 
@@ -622,10 +620,7 @@ public class GitMonitor : Monitor
                cmd.message = cmd.vname;
                cmd.commit_all = true;
 
-               this.queue.add(cmd);
-               
-                
-               
+               this.queue.append_val(cmd);
  
        }
        public override  void onCreated(MonitorNamePathDir src) {
@@ -681,9 +676,7 @@ public class GitMonitor : Monitor
                cmd = new GitMonitorQueue(src);
                cmd.action = "commit";
                cmd.message = "Attribute changed " + cmd.vname;
-               this.queue.add(cmd);
-               
-        
+               this.queue.append_val(cmd);
        }
  
    public  override void onMoved(MonitorNamePathDir src,MonitorNamePathDir dest)  
@@ -737,14 +730,9 @@ public class GitMonitor : Monitor
                        cmd.message = cmd_d.vname;
                }
                
-               
-               this.queue.add(cmd);
-        // this is where it get's complicated...
-        // as we might be moving across repo's...
-        
-        
-        
+               this.queue.append_val(cmd);
+
+
                 
        }
           
index 00ab465..1988d4f 100644 (file)
@@ -119,8 +119,8 @@ public class GitMonitorQueue : MonitorNamePathDir {
                }
                public static string messageToString(Gee.ArrayList<GitMonitorQueue> messages ) {
                        string[] ret = {};
-                       for(var i =0; i < messages.size; i++) {
-                               ret+= messages.get(i).message;
+                       for(var i =0; i < messages.length; i++) {
+                               ret+= messages.index(i).message;
                        }
                        return string.joinv("\n",ret);
                }
index b1bb25f..17556ae 100644 (file)
@@ -347,33 +347,60 @@ public class GitRepo : Object
     }
     
     public bool createBranchNamed(string branchname)
-    {
-               
-               try {
+    {  
+               
+
                     if (this.branches.has_key(branchname)) {
                        // this is where it get's tricky...
-                       
-                       string[] cmd = { "ls-files" ,  "-m" };                   // list the modified files..
-                   var ret = this.git(cmd);
-                   var stash = ret.length> 1 ;
-                   
-                       
-                   cmd = { "stash" };                  
-                   if (stash) { this.git(cmd); }
-                   
-                   cmd = { "checkout", branchname  };
-                   this.git(cmd);
-                   
-                   cmd = { "merge", "master"  };
-                   this.git(cmd);
-                   
-                   cmd = { "stash", "pop"  };
-                   if (stash) { this.git(cmd); }
-                   
+                               try {                   
+                                               string[] cmd = { "ls-files" ,  "-m" };                   // list the modified files..
+                                           var ret = this.git(cmd);
+                                           var stash = ret.length> 1 ;
+                                           
+                                               
+                                           cmd = { "stash" };                  
+                                           if (stash) { this.git(cmd); }
+                                           
+                                           cmd = { "checkout", branchname  };
+                                           this.git(cmd);
+                                 } catch(Error e) {
+                                               GitMonitor.gitmonitor.pauseError(e.message);
+                                               return false;           
+                               
+                                 }
+                                 try {
+                                    cmd = { "merge", "master"  };
+                                           this.git(cmd);
+                                  } catch(Error e) {
+                                               try {
+                                                   cmd = { "mergetool" };
+                                                       this.git(cmd);
+                                                   cmd = { "commit" "-m" "Fix merge conflicts from master" };
+                                                       this.git(cmd);
+                                               } catch(Error ee) {
+                                                       GitMonitor.gitmonitor.pauseError(ee.message);
+                                                       return false;           
+                                               }
+                                       }
+                                 try {                                 
+                                           cmd = { "stash", "pop"  };
+                                           if (stash) { this.git(cmd); }
+                                       } catch(Error ee) {
+                                               GitMonitor.gitmonitor.pauseError(ee.message);
+                                               return false;           
+                                       }
+                                   
                    
                    } else {
-                           string[] cmd = { "checkout", "-b" , branchname  };
-                           this.git(cmd);
+                                   try {                                       
+                                          
+                                       string[] cmd = { "checkout", "-b" , branchname  };
+                                       this.git(cmd);
+                                       } catch(Error ee) {
+                                               GitMonitor.gitmonitor.pauseError(ee.message);
+                                               return false;           
+                                       }
+                           
                    }
                       var notification = new Notify.Notification(
                        "Changed to branch %s".printf(branchname),
index 6cc2b4a..0137963 100644 (file)
@@ -30,7 +30,8 @@ Gitlive_SOURCES = \
           c/xorg_idletime.c \
           WindowLog.vala \
           Clones.vala \
-          NewBranch.vala 
+          NewBranch.vala \
+          MergeBranch.vala
 
           
 
index f57dd66..2fa6f41 100644 (file)
    ]
   }
  ]
-}
\ No newline at end of file
+}
index 6af4ae2..958fd87 100644 (file)
@@ -9,8 +9,8 @@
  "items" : [
   {
    "listeners" : {
-    "delete_event" : "(self, event) => {\n    this.el.hide();\n    this.running = false;\n    return true; \n    //test  \n}\n ",
-    "response" : " (self, response_id) =>  { \n  \n\tGLib.debug(\"got %d\", (int) response_id);\n\tif (response_id == 0) {\n\t    _this.el.hide();\t\n\t    this.running = false; \n\t\tGitMonitor.gitmonitor.start();\t    \n\t \treturn;\n\t}\n\t \n\t// have they selected a ticket..\n\t// make that the current active ticket?\n\t// we really need to store locally what ticket is being worked on..\n\t// in theory we could be working on multiple project and not merging..\n\t// -- each repo would have their active ticket (only one per repo)\n\t// -- so we could just store that in there\n\t// -- initial load can check the contents of the ticket files on first scan.\n\tvar ticket_id = _this.ticketsel.selectedTicketId();\n\t\n\tvar success = true;\n    if (this.repo != null) {\n    \tvar bn = _this.name.el.get_text();\n    \tif (ticket_id != \"\" ) {\n\t\t\tsuccess = this.repo.setActiveTicket( RooTicket.singleton().getById(ticket_id), bn);\n\t\t} else {\n\t\t\tsuccess = this.repo.createBranchNamed(bn);\n\t\t}\n    }\n    if (success) {\n\t\tGitMonitor.gitmonitor.restoreQueue( this.queue );\n\t\tGitMonitor.gitmonitor.runQueue();    \n\t\tGitMonitor.gitmonitor.start();\n\t}\n    this.running = false; \t \n\t_this.el.hide();\n\t \n\t  \n}",
+    "delete_event" : "(self, event) => {\n    this.el.hide();\n    return true; \n    //test  \n}\n ",
+    "response" : " (self, response_id) =>  { \n  \n\tGLib.debug(\"got %d\", (int) response_id);\n\tif (response_id == 0) {\n\t    _this.el.hide();\t\n\t    this.running = false; \n\t \treturn;\n\t}\n\t \n\t// have they selected a ticket..\n\t// make that the current active ticket?\n\t// we really need to store locally what ticket is being worked on..\n\t// in theory we could be working on multiple project and not merging..\n\t// -- each repo would have their active ticket (only one per repo)\n\t// -- so we could just store that in there\n\t// -- initial load can check the contents of the ticket files on first scan.\n\tvar ticket_id = _this.ticketsel.selectedTicketId();\n\t\n    if (this.repo != null) {\n    \tvar bn = _this.name.el.get_text();\n    \tif (ticket_id != \"\" ) {\n\t\t\tthis.repo.setActiveTicket( RooTicket.singleton().getById(ticket_id), bn);\n\t\t} else {\n\t\t\tthis.repo.createBranchNamed(bn);\n\t\t}\n    }\n\n\t\t    this.running = false; \n\n\t \n\t \n\t \n\n\t \n}",
     "show" : "(self)  => {\n \n\n  //test\n}"
    },
    "default_width" : 500,
    ]
   }
  ]
-}
\ No newline at end of file
+}
index 99733f4..1ec03ee 100644 (file)
@@ -84,15 +84,14 @@ public class NewBranch : Object
                                success = this.repo.createBranchNamed(bn);
                        }
             }
-            if (success) {
-                       GitMonitor.gitmonitor.restoreQueue( this.queue );
-                       GitMonitor.gitmonitor.runQueue();    
-                       GitMonitor.gitmonitor.start();
-               }
-            this.running = false;       
-               _this.el.hide();
+        
+                           this.running = false; 
+        
+                
+                
+                
+        
                 
-                 
         });
         this.el.show.connect( (self)  => {
          
index 5ddbeae..604d435 100644 (file)
@@ -253,4 +253,4 @@ public class RooTicket : Object
 
        
        
- }
\ No newline at end of file
+ }
index 6419910..137d750 100644 (file)
@@ -53,11 +53,11 @@ public class StatusIconA : StatusIcon {
         this.set_name("gitlive");
         this.set_visible(true);      
         
-        var menu = new MenuA();
+        var menu = new GitliveMenu();
         menu.ref();       
                this.button_press_event.connect( ( ev ) =>{
              print("button press event called\n");
+                       menu.updateMerges();
             menu.show_all();
             
             if (this.paused) {
@@ -86,6 +86,7 @@ public class StatusIconA : StatusIcon {
  
             //print(Array.prototype.slice.call(arguments).join(','));
             print("menu activiate called\n");
+                       menu.updateMerges();
             //var menu = this.get('menu');
             
             menu.show_all();
@@ -157,31 +158,85 @@ public class StatusIconA : StatusIcon {
                 
     }
     
-    class MenuA : Gtk.Menu
+    class GitliveMenu : Gtk.Menu
     {
         public ImageMenuItem pause;
         public ImageMenuItem resume;
+        public Gtk.MenuItem before_seperator;
+        public Gtk.MenuItem after_seperator;        
+        
         
-        public MenuA()
+        public GitliveMenu()
         {
-            this.pause = new ImageMenuItemA();
+            this.pause = new MenuItemPause();
             this.append(this.pause);
-            this.resume = new ImageMenuItemB();
+            this.resume = new MenuItemStartCommits();
             this.append(this.resume);
-            this.append(new ImageMenuItemC());
-            this.append(new ImageMenuItemD());
-            this.append(new ImageMenuItemE());
-            this.append(new ImageMenuItemF());
-            this.append(new ImageMenuItemG());
-            
-            
-            
+            this.append(new MenuItemPullAll());
+            this.before_seperator = new Gtk.SeparatorMenuItem();
+            this.append(this.before_seperator);
+
+            this.after_seperator = new Gtk.SeparatorMenuItem();
+            this.append(this.after_seperator);
+            //this.append(new MenuItemUpdateTimesheet());            
+            this.append(new MenuItemManageClones());
+            this.append(new MenuItemAbout());
+            this.append(new MenuItemQuit());
+            this.merge_items = new  Gee.ArrayList<Gtk.MenuItem>();
         }
+        public Gee.ArrayList<Gtk.MenuItem> merge_items;
         
         
-        class ImageMenuItemA : ImageMenuItem {
+        public void updateMerges()
+        {
+               // show a list of possible merges on the menu.
+               foreach (var m in this.merge_items) {
+                       this.remove(m);
+               }
+               foreach(var r in GitRepo.singleton().cache.values ) {
+                       GLib.debug("checking %s for branch = %s", r.name, r.currentBranch.name);
+                       if (!r.is_wip_branch()) {
+                               continue;
+                               }
+                       GLib.debug("checking  for activeTicket");                               
+                               var t = r.activeTicket;
+                               if (t == null) { 
+                                       continue;
+                               }
+                               var mi = new MergeMenuItem(r,t);
+                               this.insert (mi,4); //backwards.
+                               this.merge_items.add(mi);                       
+                                
+               }
+               
+        }
+        
+       
+        class MergeMenuItem : Gtk.MenuItem {        
+        
+               GitRepo repo;
+               RooTicket ticket;
+        
+               public MergeMenuItem(GitRepo r, RooTicket t)
+               {
+                       this.repo = r;
+                       this.ticket = t;
+                       
+                       this.label = ("Merge [%s] #%s %s".printf(r.name, t.id , t.summary));
+
+                               this.activate.connect(() => {
+                                       MergeBranch.singleton().show(this.ticket);
+                                       // show merge dialog..
+                               });
+               
+               }
+               
+       }
+        
+        
+        class MenuItemPause : ImageMenuItem {
             
-            public ImageMenuItemA()
+            public MenuItemPause()
             {
                 //this.set_from_stock( Gtk.Stock.MEDIA_PAUSE );
                 
@@ -207,9 +262,9 @@ public class StatusIconA : StatusIcon {
             
             
         }
-        class ImageMenuItemB : ImageMenuItem {
+        class MenuItemStartCommits : ImageMenuItem {
             
-            public ImageMenuItemB()
+            public MenuItemStartCommits()
             {
                 
                 var  image = new Gtk.Image();
@@ -235,9 +290,9 @@ public class StatusIconA : StatusIcon {
         }
         
         
-        class ImageMenuItemC : ImageMenuItem {
+        class MenuItemPullAll : ImageMenuItem {
             
-            public ImageMenuItemC()
+            public MenuItemPullAll()
             {
                 
                 var  image = new Gtk.Image();
@@ -371,14 +426,14 @@ public class StatusIconA : StatusIcon {
         }
         
         
-        class ImageMenuItemD : ImageMenuItem {
+        class MenuItemUpdateTimesheet : ImageMenuItem {
             
-            public ImageMenuItemD()
+            public MenuItemUpdateTimesheet()
             {
                 
                 var  image = new Gtk.Image();
                 image.set_from_stock(Gtk.Stock.SAVE,Gtk.IconSize.MENU );
-               this.set_image (image);
+                               this.set_image (image);
                 this.label= "Update Timesheet";
                 this.always_show_image = true;
                 this.accel_group = null;
@@ -391,9 +446,9 @@ public class StatusIconA : StatusIcon {
             
         }
         
-        class ImageMenuItemE : ImageMenuItem {
+        class MenuItemManageClones : ImageMenuItem {
             
-            public ImageMenuItemE()
+            public MenuItemManageClones()
             {
                 
                 var  image = new Gtk.Image();
@@ -411,9 +466,9 @@ public class StatusIconA : StatusIcon {
             
         }
         
-        class ImageMenuItemF : ImageMenuItem {
+        class MenuItemAbout : ImageMenuItem {
             
-            public ImageMenuItemF()
+            public MenuItemAbout()
             {
                 
                 var  image = new Gtk.Image();
@@ -441,9 +496,9 @@ public class StatusIconA : StatusIcon {
             
         }
         
-         class ImageMenuItemG : ImageMenuItem {
+         class MenuItemQuit : ImageMenuItem {
             
-            public ImageMenuItemG()
+            public MenuItemQuit()
             {
                 
                 var  image = new Gtk.Image();
index c5e4bc9..55088b0 100644 (file)
@@ -17,7 +17,8 @@
             "..//gitlive/GitBranch.vala",
             "..//gitlive/NewBranch.vala",
             "..//gitlive/GitMonitorQueue.vala",
-            "..//gitlive/RooTicket.vala"
+            "..//gitlive/RooTicket.vala",
+            "..//gitlive/MergeBranch.vala"
         ],
         "packages" : [
         ]