Monitor.js
[gitlive] / gitlive.js
index 487b28d..0d567db 100644 (file)
@@ -9,21 +9,33 @@
 * 
 * 
 */
-GI      = imports.gi.GIRepository;
+<<<<<<< HEAD
+GI      = imports.gi.GIRepository
+GLib        = imports.gi.GLib;
+
+// we add this in, as it appears to get lost sometimes if we set it using the ENV. variable in builder.sh
+GI.IRepository.prepend_search_path(GLib.get_home_dir() + '/.Builder/girepository-1.1');
+
 Gio      = imports.gi.Gio;
-GLib      = imports.gi.GLib;
 Gtk      = imports.gi.Gtk;
 Notify = imports.gi.Notify;
+=======
+var GI      = imports.gi.GIRepository;
+var Gio      = imports.gi.Gio;
+var GLib      = imports.gi.GLib;
+var Gtk      = imports.gi.Gtk;
+var Notify = imports.gi.Notify;
+>>>>>>> e9aa44647c32a34dfa368f7594ed72579c912bc3
 
-Spawn = imports.Spawn;
-Git = imports.Git;
-StatusIcon = imports.StatusIcon.StatusIcon;
-Monitor = imports.Monitor.Monitor;
+var Spawn = imports.Spawn;
+var Git = imports.Git;
+var StatusIcon = imports.StatusIcon.StatusIcon;
+var Monitor = imports.Monitor.Monitor;
 
 
 //File = imports[__script_path__+'/../introspection-doc-generator/File.js'].File
 Gtk.init (null, null);
+
 var gitlive = GLib.get_home_dir() + "/gitlive";
 
 if (!GLib.file_test(gitlive, GLib.FileTest.IS_DIR)) {
@@ -40,8 +52,7 @@ var monitor = new Monitor({
     
     queue : [],
     queueRunning : false,
-    nqv : false, // temp var while I switch to queued version.
-    
+     
     start: function() {
         var _this = this;
         this.lastAdd = new Date();
@@ -65,7 +76,7 @@ var monitor = new Monitor({
             body : gitlive + "\nMonitoring " + this.monitors.length + " Directories"
         });
 
-        notification.set_timeout(500);
+        notification.set_timeout(2000);
         notification.show();   
     },
     /**
@@ -88,9 +99,17 @@ var monitor = new Monitor({
         var success = [];
         var failure = [];
         var repos = [];
+        var done = [];
         cmds.forEach(function(cmd) {
+            // prevent duplicate calls..
+            if (done.indexOf(cmd.join(',')) > -1) {
+                return;
+            }
+            done.push(cmd.join(','));
+            
             if (repos.indexOf(cmd[0]) < 0) {
                 repos.push(cmd[0]);
+                Git.run(cmd[0] , 'pull'); // pull before we push!
             }
             var sp = Git.run.apply(Git,cmd);
              
@@ -109,7 +128,6 @@ var monitor = new Monitor({
             
         });
          
-         
         // push upstream.
         repos.forEach(function(r) {
             var sp = Git.run(r , 'push', { all: true } );
@@ -127,7 +145,7 @@ var monitor = new Monitor({
                 
             });
 
-            notification.set_timeout(500);
+            notification.set_timeout(2000);
             notification.show();   
         }
         if (failure.length) {
@@ -138,7 +156,7 @@ var monitor = new Monitor({
                 
             });
 
-            notification.set_timeout(500);
+            notification.set_timeout(5000); // show errros for longer
             notification.show();   
         }
         this.queueRunning = false;
@@ -199,13 +217,7 @@ var monitor = new Monitor({
                 [ src.gitpath,  'commit',  src.vpath, { message: src.vpath} ] 
                 
             );
-            if (this.nqv) {
-                
-                Git.run(src.gitpath, 'add', src.vpath);
-                var sp = Git.run(src.gitpath, 'commit', { all: true, message: src.vpath});
-                Git.run(src.gitpath , 'push', { all: true } );
-                notify(src.name,"CHANGED", sp);
-            }
+         
             return;
         }
         this.lastAdd = new Date();
@@ -215,11 +227,7 @@ var monitor = new Monitor({
 
             
         );
-        if (this.nqv) {
-            var sp = Git.run(src.gitpath, 'commit', { all: true, message: src.vpath});
-            Git.run(src.gitpath , 'push', '--all' );
-            notify(src.name,"CHANGED", sp);
-        }
+       
 
     },
     onDeleted : function(src) 
@@ -237,20 +245,7 @@ var monitor = new Monitor({
             [ src.gitpath, 'commit', { all: true, message: src.vpath} ]
             
         );
-        if (!this.nqv) {
-            return;
-        }
-        
-        var sp = Git.run(src.gitpath,'rm' , src.vpath);
-        Git.run(src.gitpath , 'push', { all: true } );
-        if (sp.status !=0) {
-            notify(src.name,"DELETED", sp);
-            return;
-        }
-        sp = Git.run(src.gitpath,'commit' ,{ all: true, message: src.vpath});
-        Git.run(src.gitpath , 'push',{ all: true });
-        notify(src.name,"DELETED", sp);
-        return;
+    
         
     },
     onCreated : function(src) 
@@ -272,21 +267,7 @@ var monitor = new Monitor({
             [ src.gitpath, 'commit' , { all: true, message: src.vpath} ]
             
         );
-        if (!this.nqv) {
-            return;
-        }
-        var sp = Git.run(src.gitpath, 'add', src.vpath);
-        Git.run(src.gitpath , 'push', { all: true } );
-
-        if (sp.status !=0) {
-            notify(src.path,"CREATED", sp);
-            return;
-        }
-        //uh.call(fm,f,of, event_type);
-        sp = Git.run(src.gitpath,'commit' , { all: true, message: src.vpath});
-        Git.run(src.gitpath , 'push', { all: true } );
-        notify(src.path,"CREATED", sp);
-        return;
+        
         
     },
     onAttributeChanged : function(src) { 
@@ -298,13 +279,7 @@ var monitor = new Monitor({
         this.queue.push( 
             [ src.gitpath, 'commit' ,  src.vpath, { message: src.vpath} ]
         );
-        if (!this.nqv) {
-            return;
-        }
-        var sp = Git.run(src.gitpath, 'commit',{ all: true, message: src.vpath});
-        Git.run(src.gitpath , 'push', { all: true } );
-        notify(src.path,"ATTRIBUTE_CHANGED", sp);
-        return;
     
     },
     
@@ -333,43 +308,13 @@ var monitor = new Monitor({
             [ src.gitpath, 'commit' ,  src.vpath, dest.vpath ,
                 { message:   'MOVED ' + src.vpath +' to ' + dest.vpath} ]
         );
-        
-        if (!this.nqv) {
-            return;
-        }
-        
-        var sp = Git.run(src.gitpath,  'mv',  '-k', src.vpath, dest.vpath);
-        if (sp.status !=0) {
-            notify(dest.path,"MOVED", sp);
-            return;
-        }
-        sp = Git.run(src.gitpath,'commit' , { all: true, message:   'MOVED ' + src.vpath +' to ' + dest.vpath} );
-        Git.run(src.gitpath , 'push', { all: true } );
-        notify(src.path,"MOVED", sp);
-        
+         
     }
           
     
 });
  
  
-
-function notify(fn, act , sp)
-{
-    var sum = act + " " + fn;
-    
-    var notification = new Notify.Notification({
-       summary: sum,
-               body : sp
-       });
-
-    notification.set_timeout(500);
-    notification.show();
-}
-
-
-
   
 
 function errorDialog(data) {
@@ -389,8 +334,12 @@ function errorDialog(data) {
 //
 // need a better icon...
 
-StatusIcon.init(); 
+
+StatusIcon.init();   
+
+
 Notify.init("gitlive");
+
 monitor.add(GLib.get_home_dir() + "/gitlive");
 monitor.start();
 Gtk.main();