GitRepo.vala
[gitlive] / GitRepo.vala
index 330a493..60f33e6 100644 (file)
 public class GitRepo : Object
 {
     
+    public Array<GitMonitorQueue> cmds;
 
 
+    public string gitdir;
+    public bool debug = false;
+
     /**
     * index of.. matching gitpath..
     */
      public static int indexOfAdd( Array<GitRepo> repos, string gitpath) {
         for(var i =0; i < repos.length; i++) {
-            if (reos.index(i).gitdir == gitpath) {
+            if (repos.index(i).gitdir == gitpath) {
                 return i;
             }
         }
@@ -27,10 +31,7 @@ public class GitRepo : Object
 
 
 
-     public Array<GitMonitorQueue> cmds;
-
-
-     public string gitdir;
+   
     /**
      * constructor:
      * 
@@ -56,20 +57,23 @@ public class GitRepo : Object
      *
      * @argument {Array} files the files to add.
      */
-    public string add ( Array<GitMonitorQueue> files )
+    public string add ( Array<GitMonitorQueue> files ) throws Error, SpawnError
     {
         // should really find out if these are untracked files each..
         // we run multiple versions to make sure that if one failes, it does not ignore the whole lot..
         // not sure if that is how git works.. but just be certian.
+        var ret = "";
         for (var i = 0; i < files.length;i++) {
-            var f = files.item(i).vname;
+            var f = files.index(i).vname;
             try {
-                this.git( { "add",   f });
+                string[] cmd = { "add",    f  };
+                this.git( cmd );
             } catch (Error e) {
                 ret += e.message  + "\n";
             }        
 
         }
+        return ret;
     }
     
       /**
@@ -78,7 +82,7 @@ public class GitRepo : Object
      *
      * @argument {Array} files the files to add.
      */
-    public string remove  ( Array<GitMonitorQueue> files )
+    public string remove  ( Array<GitMonitorQueue> files ) throws Error, SpawnError
     {
         // this may fail if files do not exist..
         // should really find out if these are untracked files each..
@@ -87,9 +91,10 @@ public class GitRepo : Object
         var ret = "";
 
         for (var i = 0; i < files.length;i++) {
-            var f = files.item(i).vname;
+            var f = files.index(i).vname;
             try {
-                this.git( { "rm",  "-f" ,  f });
+                string[] cmd = { "rm",  "-f" ,  f  };
+                this.git( cmd );
             } catch (Error e) {
                 ret += e.message  + "\n";
             }        
@@ -113,7 +118,7 @@ public class GitRepo : Object
      * 
      */
      
-    public string commit ( string message, Array<GitMonitorQueue> files  )
+    public string commit ( string message, Array<GitMonitorQueue> files  ) throws Error, SpawnError
     {
         
 
@@ -135,12 +140,13 @@ public class GitRepo : Object
             
         }
         */
-        var args = { "commit", "-m", message.length > 0  ? message : "Changed" };
+        string[] args = { "commit", "-m", };
+        args +=  (message.length > 0  ? message : "Changed" );
         for (var i = 0; i< files.length ; i++ ) {
-            args += files.items(i).vname; // full path?
+            args += files.index(i).vname; // full path?
         }
          
-        return this.git(args, env);
+        return this.git(args);
     }
     
     /**
@@ -151,10 +157,12 @@ public class GitRepo : Object
      * -- maybe later it will have a few options and do more stuff..
      *
      */
-    public string pull ()
+    public string pull () throws Error, SpawnError
     {
         // should probably hand error conditions better... 
-        return this.git({ "pull" });
+        string[] cmd = { "pull" };
+        return this.git( cmd );
+
         
         
     }
@@ -166,7 +174,7 @@ public class GitRepo : Object
      * -- maybe later it will have a few options and do more stuff..
      *
      */
-    public string push ()
+    public string push () throws Error, SpawnError
     {
         // should 
         return this.git({ "push" });
@@ -179,40 +187,43 @@ public class GitRepo : Object
      *
      */
     
-    public string git(string[] args_in, string[] env = {})
+    public string git(string[] args_in ) throws Error, SpawnError
     {
         // convert arguments.
         
 
-        var args = {
-           "git", 
-            "--git-dir", this.gitdir,
-            "--no-pager",
-        }; 
+        string[]  args = { "git" };
+        args +=  "--git-dir";
+        args +=  this.gitdir;
+        args +=  "--no-pager";
 
+         
 
-        if (this.gitdir != this.repopath) {
-            args +=   "--work-tree";
-            args += this.repopath; 
-        }
-        for (var i = i; i < args_in.length;i++) {
+        
+
+        //if (this.gitdir != this.repopath) {
+        //    args +=   "--work-tree";
+         //   args += this.repopath; 
+        //}
+        for (var i = 0; i < args_in.length;i++) {
             args += args_in[i];
         }            
 
         //this.lastCmd = args.join(" ");
         if(this.debug) {
          
-            print(  string.joinv (", ", args_list)); 
+            print(  string.joinv (", ", args)); 
         }
-        
-        env +=  ("HOME=" + GLib.get_home_dir() );
+        string[]   env = {};
+        string  home = "HOME=" + Environment.get_home_dir() ;
+        env +=  home ;
         // do not need to set gitpath..
         //if (File.exists(this.repo + '/.git/config')) {
             //env.push("GITPATH=" + this.repo );
         //}
         
 
-        var cfg = new SpawnConfig(this.repopath, args , env);
+        var cfg = new SpawnConfig(this.gitdir, args , env);
         
 
        // may throw error...