GitRepo.vala
[gitlive] / GitRepo.vala
index fa51175..ea4d1e0 100644 (file)
@@ -61,7 +61,7 @@ public class GitRepo : Object
             return list_cache;
             
         }
-         
+        
         FileInfo next_file; 
         
         while (true) {
@@ -163,14 +163,18 @@ public class GitRepo : Object
         
     public bool is_ignore(string fname) throws Error, SpawnError
     {
+               if (fname == ".gitignore") {
+                       this.ignore_files.clear();
+               }
+               
                if (this.ignore_files.has_key(fname)) {
                        return this.ignore_files.get(fname);
                }
                
                try {
                        var ret = this.git( { "check-ignore" , fname } );
-                       this.ignore_files.set(fname, ret == fname);
-                       return ret == fname;
+                       this.ignore_files.set(fname, ret.length >  0);
+                       return ret.length > 0;
                } catch (SpawnError e) {
                        this.ignore_files.set(fname, false);
                        return false;
@@ -207,6 +211,7 @@ public class GitRepo : Object
 
     }
     
+    
     /**
      * commit:
      * perform a commit.
@@ -267,8 +272,17 @@ public class GitRepo : Object
         return this.git( cmd );
 
         
-        
     }
+    
+    public delegate void GitAsyncCallback (string str);
+    public string pull_async(GitAsyncCallback cb) 
+    {
+    
+        string[] cmd = { "pull" , "--no-edit" };
+        return this.git_async( cmd , cb);
+    
+    }
+    
     /**
      * push:
      * Send local changes to remote repo(s)
@@ -337,5 +351,50 @@ public class GitRepo : Object
         // parse output for some commands ?
         return sp.output;
     }
+       
+       
+       public   git_async( string[] args_in,   GitAsyncCallback cb ) throws Error, SpawnError
+    {
+        // convert arguments.
+        
+        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 = 0; i < args_in.length;i++) {
+            args += args_in[i];
+        }            
 
+        //this.lastCmd = args.join(" ");
+        //if(this.debug) {
+            stdout.printf( "CWD=%s\n",  this.git_working_dir ); 
+            print( "cmd: %s\n", string.joinv (" ", args)); 
+        //}
+
+        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.git_working_dir , args , env);
+        cfg.async = true;
+       
+
+       // may throw error...
+        var sp = new Spawn(cfg);
+        sp.run((err, output) => {
+               cb(output);
+        });
+         
+    }
 }