GitMonitor.vala
[gitlive] / GitMonitor.vala
index a2ec6e8..a3d0ad7 100644 (file)
@@ -39,6 +39,8 @@ public class GitMonitorQueue : MonitorNamePathDir {
                        this.vdir =  string.joinv("/", vpath);
 
                        this.vname =  this.vdir + (this.vdir.length > 0 ? "/" : "") + this.name;
+                       
+                        
 /*
                        stdout.printf(
                                        "NEW GitMonitorQueue\nname: %s\npath: %s\ndir: %s\n" + 
@@ -56,7 +58,7 @@ public class GitMonitorQueue : MonitorNamePathDir {
                public bool shouldIgnore()
                {
                        
-                        
+                
                        // vim.. what a seriously brain dead program..
                        if (this.name == "4913") {
                                return true;
@@ -67,10 +69,13 @@ public class GitMonitorQueue : MonitorNamePathDir {
                                if (this.name == ".htaccess") {
                                        return false;
                                }
-                               
+                               if (this.name == ".gitignore") {
+                                       return false;
+                               }
                                return true;
                        }
                        
+                       
                        if (this.name[this.name.length -1] == '~') {
                                return true;
                        }
@@ -177,6 +182,32 @@ public class GitMonitor : Monitor
        public GitMonitor () {
                this.queue = new Array<GitMonitorQueue>();
                GitMonitor.gitmonitor = this;
+               
+               Timeout.add_full(Priority.LOW, 1000, () => {
+                       
+                       //print("TIMEOUT queue length = %d, is_runing = %s\n", (int)this.queue.length , this.queueRunning ? "Y" : "N");
+
+                       //stdout.printf("QL %u: QR: %d\n", this.queue.length, this.queueRunning ? 1 : 0);
+                       if (this.queue.length < 1  || this.queueRunning) {
+                               return true;
+                       }
+                       
+                       var last = -1 * this.lastAdd.difference(new DateTime.now(new TimeZone.local()));
+                       // stdout.printf("LAST RUN: %s (expect %s) \n" ,
+                       //         last.to_string(),   (5 * TimeSpan.SECOND).to_string() );
+                       if (last < 5 * TimeSpan.SECOND) { // wait 5 seconds before running. ????
+                               return true;
+                       }
+                       //_this.lastAdd = new Date();
+                       //return 1;
+               
+                       this.runQueue();
+                       return true; //
+               });
+               
+               
        }
 
        public new void pauseError(string failure) 
@@ -191,13 +222,30 @@ public class GitMonitor : Monitor
                        
                notification.set_timeout(60); // show errros for longer
                notification.show();
-                               
+               
+               
+
+                       
        
                this.paused = true;
+               this.queueRunning = false;
                // what does this do to the old one...
                this.queue = new Array<GitMonitorQueue> ();
                this.stop();
                StatusIconA.statusicon.pauseError();
+               
+               var m = new Gtk.MessageDialog(null, Gtk.DialogFlags.MODAL,Gtk.MessageType.ERROR,Gtk.ButtonsType.CLOSE,
+                       "A Serious problem occured running git, you will probably have to resolve this manually\n" + 
+                       "Committing is paused now, so fix the problem, close this window, then press start again\n\n\n" + 
+                       failure
+               );
+               m.set_keep_above(true);
+               m.show();
+               m.set_position(Gtk.WindowPosition.CENTER);
+               m.response.connect( (id_pressed) => {
+                       m.hide();
+               });
+               
        }
  
        public new void pause() {
@@ -259,28 +307,7 @@ public class GitMonitor : Monitor
                });
                
 
-               Timeout.add_full(Priority.LOW, 1000, () => {
-                       //TIMEOUT", _this.queue.length , _this.queueRunning].join(', '));
-
-                       //stdout.printf("QL %u: QR: %d\n", this.queue.length, this.queueRunning ? 1 : 0);
-                       if (this.queue.length < 1  || this.queueRunning) {
-                               return true;
-                       }
-                       
-                       var last = -1 * this.lastAdd.difference(new DateTime.now(new TimeZone.local()));
-                       // stdout.printf("LAST RUN: %s (expect %s) \n" ,
-                       //         last.to_string(),   (5 * TimeSpan.SECOND).to_string() );
-                       if (last < 5 * TimeSpan.SECOND) { // wait 5 seconds before running. ????
-                               return true;
-                       }
-                       //_this.lastAdd = new Date();
-                       //return 1;
                
-                       this.runQueue();
-                       return true; //
-               });
                 
        }
 
@@ -404,6 +431,10 @@ public class GitMonitor : Monitor
                        for(var ii = 0;ii < repo.cmds.length;ii++) {
                                var cmd = repo.cmds.index(ii);
        
+                               if (repo.is_ignore(cmd.vname)) {
+                                       continue;
+                               }
+       
                                
                                switch(cmd.action) {
                                        case "add" :
@@ -488,11 +519,18 @@ public class GitMonitor : Monitor
                        
                        print( "ADD : %s\n", GitMonitorQueue.queueArrayToString(add_files_f));
                        print( "REMOVE FILES: %s\n", GitMonitorQueue.queueArrayToString(remove_files_f));
-                  
-                       
+                   
+                   if (add_files_f.length < 1 && remove_files_f.length < 1) {
+                               continue;
+                   }
+                   
                        // make sure monitoring is paused so it does not recursively pick up
                        // deletions
+                       this.paused = true; 
+                         
+                         
                        try {
+                               
                                repo.pull();
                        } catch(Error e) {
                                this.pauseError(e.message);
@@ -500,8 +538,7 @@ public class GitMonitor : Monitor
                                //print("Pull failed:\n");
                                return;
                        }
-                       
-                       
+                                                                       
                        // -- DO STUFF..            
                        try {
                                repo.add(add_files_f);
@@ -520,9 +557,7 @@ public class GitMonitor : Monitor
                                print("Remove failed:\n");
                        }  
 
-                       this.paused = false;
-                       
-                       
+
                        try { 
                                success += repo.commit(
                                        GitMonitorQueue.messageToString(messages),
@@ -531,12 +566,27 @@ public class GitMonitor : Monitor
                                success += repo.push();
 
                        } catch(Error e) {
+                       
+                               // if the error is 'nothing to commit, working tree clean'
+                               // then it's not an error, - just continue;
+                               
+                               if (/nothing to commit, working tree clean/.match(e.message)) {
+                                       success += e.message;
+                                       this.paused = false; 
+                                       continue;
+                               }
+                               
+                       
+                       
+                               this.paused = false;                    
                                this.pauseError(e.message);
+                               
                                return;
-                               failure += e.message;
-                               print("Push failed:\n");
+                               //failure += e.message;
+                               //print("Push failed:\n");
                                
                        }   
+                       this.paused = false;                                            
                }
                
                
@@ -585,7 +635,7 @@ public class GitMonitor : Monitor
 
        public override  void onChanged(MonitorNamePathDir src) 
        { 
-               print("GitMonitor.onChanged\n");        
+               //print("GitMonitor.onChanged\n");        
                return; // always ignore this..?
                //this.parsePath(src);
        }
@@ -598,11 +648,11 @@ public class GitMonitor : Monitor
         */
        public override void onChangesDoneHint(MonitorNamePathDir src)  
        { 
-               print("GitMonitor.onChangedHint\n");        
+
                if (this.paused) {
                        return;
                }
-                       
+               print("GitMonitor.onChangedHint\n");                            
 
                this.lastAdd = new DateTime.now(new TimeZone.local()); 
                var cmd = new GitMonitorQueue(src);
@@ -639,10 +689,11 @@ public class GitMonitor : Monitor
        }
        public override  void onDeleted(MonitorNamePathDir src) 
    { 
-               print("GitMonitor.onDeleted\n");        
+
                if (this.paused) {
                        return;
                }
+               print("GitMonitor.onDeleted\n");                        
                this.lastAdd = new DateTime.now(new TimeZone.local()); 
                var cmd = new GitMonitorQueue(src);
                if (cmd.shouldIgnore()) {
@@ -662,10 +713,11 @@ public class GitMonitor : Monitor
  
        }
        public override  void onCreated(MonitorNamePathDir src) {
-               print("GitMonitor.onCreated\n");        
+
                if (this.paused) {
                        return;
                }
+               print("GitMonitor.onCreated\n");                        
                this.lastAdd = new DateTime.now(new TimeZone.local()); 
                var cmd = new GitMonitorQueue(src);
                if (cmd.shouldIgnore()) {
@@ -692,10 +744,11 @@ public class GitMonitor : Monitor
        }
 
        public  override void onAttributeChanged(MonitorNamePathDir src) { 
-               print("GitMonitor.onAttributeChanged\n");        
+
                if (this.paused) {
                        return;
                }
+               print("GitMonitor.onAttributeChanged\n");                       
                if (src.dir == GitMonitor.gitlive) {
                   return; // attribute on top level..
                }
@@ -716,10 +769,11 @@ public class GitMonitor : Monitor
  
    public  override void onMoved(MonitorNamePathDir src,MonitorNamePathDir dest)  
        { 
-               print("GitMonitor.onMoved\n");        
+
                if (this.paused) {
                        return;
                }
+               print("GitMonitor.onMoved\n");                  
                this.lastAdd = new DateTime.now(new TimeZone.local()); 
                var cmd_s = new GitMonitorQueue(src);