sync new version
authorAlan Knowles <alan@akkbhome.com>
Thu, 31 Mar 2011 23:26:31 +0000 (07:26 +0800)
committerAlan Knowles <alan@akkbhome.com>
Thu, 31 Mar 2011 23:26:31 +0000 (07:26 +0800)
Git.js
gitlive2.js

diff --git a/Git.js b/Git.js
index 385f056..99538a0 100644 (file)
--- a/Git.js
+++ b/Git.js
@@ -3,7 +3,8 @@
 Gio      = imports.gi.Gio;
 GLib      = imports.gi.GLib;
 
-Spawn = imports.Spawn.Spawn;
+Spawn   = imports.Spawn.Spawn;
+File    = imports.File.File;
 /**
  * @namespace Git
  * 
@@ -54,15 +55,17 @@ Git.prototype = {
     repo : '',
     /**
      * @method run
-     * 
      * @arg command {String} command to run
      * @arg arguments.... {String|Object}  arguments to send to command
-     * 
+     * { xxxx : yyyy} -> --xxxx YYYYY
+     * { x : yyyy} -> -x  yyyy
      * 
      */
     run : function() {
+        //print("GIT RUN");
         var args = ['git'];
         
+        
         for (var i=0;i< arguments.length;i++) {
             if (typeof(arguments[i]) == 'string') {
                 args.push(arguments[i]);
@@ -71,7 +74,9 @@ Git.prototype = {
             if (typeof(arguments[i]) == 'object') {
                 for(var k in arguments[i]) {
                     var v = arguments[i][k];
-                    args.push('--' + k);
+                    
+                    args.push(k.length > 1 ? ('--' + k) : ('-' + k));
+                    
                     if (v === true) {
                         continue;
                     }
@@ -80,9 +85,17 @@ Git.prototype = {
             }
              
         }
+        var env =  [  "HOME=" + GLib.get_home_dir() ];
         
+        if (File.exists(this.repo + '/.git/config')) {
+            env.push("GITPATH=" + this.repo );
+        }
+        
+        
+        //print(args.join( ' '));
         var sp = new Spawn({
-            env : [ "GITPATH=" + this.repo , "HOME=" + GLib.get_home_dir() ],
+            //env : [ "GITPATH=" + this.repo , "HOME=" + GLib.get_home_dir() ],
+            env : env,
             cwd : this.repo,
             args: args,
             debug: true,
@@ -105,11 +118,12 @@ Git.prototype = {
  */
 
 function run() {
+    //print("Git.run()");
     var args = Array.prototype.slice.call(arguments);
-  
+    //print(JSON.stringify(args));
     var repo = args.shift(args);
     var x = new Git(repo);
-    
+    //print(JSON.stringify(args));
     return x.run.apply(x, args);
     
 }
index b02d7f8..90007cf 100644 (file)
@@ -81,6 +81,8 @@ Spawn       = imports.Spawn;
 Git         = imports.Git;
 StatusIcon  = imports.StatusIcon.StatusIcon;
 Monitor     = imports.Monitor.Monitor;
+File        = imports.File.File;
+
 
 
 //File = imports[__script_path__+'/../introspection-doc-generator/File.js'].File
@@ -114,6 +116,15 @@ var monitor = new Monitor({
      
     start: function()
     {
+        
+        
+        
+        this.dot_gitlive = GLib.get_home_dir() + "/.gitlive";
+        if (!File.exists(this.dot_gitlive)) {
+            File.mkdir(this.dot_gitlive);
+        }
+        
+        
         var _this = this;
         this.lastAdd = new Date();
          
@@ -144,8 +155,49 @@ var monitor = new Monitor({
         notification.show();   
     },
     
-    initRepo : function(src) {
-        print("INIT REPO " + src);  
+    initRepo : function(src)
+    {
+        print("INIT REPO " + src);
+        
+        function logrun(sp) {
+            print("LOGRUN?" + typeof(sp));
+            switch (sp.result * 1) {
+                case 0: // success:
+                    print(sp.args.join(' '));
+                    if (sp.output.length) print(sp.output + '');
+                  // if (sp.stderr.length) success.push(sp.stderr + '');
+                    break;
+                default: 
+                    print(sp.args.join(' '));
+                    if (sp.output.length) print(sp.output);
+                    if (sp.stderr.length) print(sp.stderr);
+                    break;
+            }
+        }
+        
+        // make hour mirrored directory
+        var rname = src.split('/').pop();
+        var dotdir = this.dot_gitlive + '/' + rname;
+        
+        print("CHECK WORKING CACHE " + dotdir);
+
+        if (!File.isDirectory(dotdir)) {
+           // print("Not a dir?");
+            logrun(Git.run(this.dot_gitlive, 'clone', src  , {   shared :  true }  ));
+        }
+        // refresh - always..
+        logrun(Git.run(src, 'pull'));
+        
+        // create and checkout gitlive branch.
+        logrun(Git.run(src, 'push', 'origin', 'origin:refs/heads/gitlive'));
+        logrun(Git.run(src, 'checkout', { track : true ,  'b'  : 'gitlive' } , 'origin/gitlive'));
+        
+        
+        
+         
+        
+        
+        
         
     },