Git.vala
[gitlive] / Git.vala
index 45110d2..3fb3db9 100644 (file)
--- a/Git.vala
+++ b/Git.vala
@@ -1,5 +1,5 @@
 
-// valac -o /tmp/ggit Git.vala --pkg libgit2-glib-1.0 --pkg libsoup-2.4 -g
+// valac -o /tmp/ggit Git.vala --pkg libgit2-glib-1.0 --pkg libsoup-2.4 -pkg gee-0.8 -g
 
 
 
@@ -19,6 +19,11 @@ void main()
 
        Ggit.init();
        
+       var a = new GitLive.Repo("/home/alan/gitlive/gitlive");
+       a.loadBranches();
+       a.fetchAll();
+       //
+       /*
        var a = new GitLive.Repo("/home/alan/git/test1-clone");
        //a.fetchAll();
        var str = (new GLib.DateTime.now_utc()).format("%Y-%m-%d %H:%M:%S");
@@ -39,7 +44,7 @@ void main()
        
        var sig = new Ggit.Signature.now("Alan Knowles", "alan@roojs.com");
        a.repo.create_commit("HEAD", sig, sig, null, "test commit " + str, tree, parents);
-       
+       */
        // mmh.. no git add/commit in library...
 //     string[] spawn_args = {"git", "commit", "-m", "test", "-a"};
        //string[] spawn_env = Environ.get ();
@@ -62,6 +67,46 @@ namespace  GitLive {
                        this.callbacks = new Callbacks(this);
                
                }
+               
+           Gee.ArrayList<Ggit.Branch>          branches = null;
+               public void loadBranches()
+               {
+                       this.branches =  new Gee.ArrayList<Ggit.Branch>();
+                       var r = this.repo.enumerate_branches(Ggit.BranchType.LOCAL);
+                       
+                       
+                       
+                       
+                       while (r.next()) {
+                               var br = r.get() as Ggit.Branch;
+                               var head = this.repo.revparse("refs/heads/" + br.get_name() ).get_id();
+                               var rhead = this.repo.revparse(br.get_upstream().get_name() ).get_id();
+                               GLib.debug("got branch: name = %s upstream = %s oid = %s ", 
+                                               br.get_name(), br.get_upstream().get_name(), 
+                                               head.to_string());
+                               this.branches.add(br);
+                               
+                       }
+                       
+                       
+               
+               }
+               Ggit.Branch? getBranch(string remote_name)
+               {
+                       foreach(var br in this.branches) {
+                               if (br.get_upstream().get_name() == remote_name ||
+                                       "refs/heads/" + br.get_upstream().get_name() == remote_name
+                               ) {
+                                       return br;
+                               }
+                               
+                       }
+                       return null;
+               
+               }
+               
+               
+               
                public void fetchAll()
                {
                        // remotes probably will not work with http auth..
@@ -79,6 +124,21 @@ namespace  GitLive {
                                        GLib.debug("Got Error Message: %s", e.message);
                                        return;
                                }
+                               
+                               var heads = r.list();
+                               foreach(var rh in heads) {
+                                       var br = this.getBranch(rh.get_name());
+                               
+                                       GLib.debug("got heads: name=%s   rev=%s  localrev=%s",
+                                               rh.get_name(), 
+                                               rh.get_oid().to_string(),
+                                               br == null ? "?": this.repo.revparse(br.get_name() ).get_id().to_string()
+                                       );
+                               
+                               }
+                               
+                               
+                               
                                GLib.debug("getting specs '%s'", n);
 
 
@@ -114,7 +174,7 @@ namespace  GitLive {
                                 
                                try {
                                        string[] h = { "a = 1" };
-                                       r.connect(Ggit.Direction.PUSH, this.callbacks, null, null);
+                                        r.connect(Ggit.Direction.PUSH, this.callbacks, null, null);
                                        
                                } catch (Error e) {
                                        GLib.debug("Got Error Message: %s", e.message);
@@ -122,14 +182,15 @@ namespace  GitLive {
                                }
                                //GLib.debug("getting specs '%s'", n);
                                /* 
-                               var head = this.repo.get_head();
+                               
                                this.repo.add_remote_push(
                                        "origin",
                                        "+%s:%s".printf(head.get_shorthand(),head.get_name())
                                );
  */
+                               var head = this.repo.get_head();
                                string[] far = {};
-                               far += "+%s:%s".printf(head.get_shorthand(),head.get_name());
+                               far += "+%s:%s".printf(head.get_name(),head.get_name());
                                
                                foreach(var rs in far) {
                                        GLib.debug("got remote spec: %s", rs);
@@ -137,7 +198,7 @@ namespace  GitLive {
                                }
                                        
                                var popts = new Ggit.PushOptions();
-                               //popts.callbacks = this.callbacks;
+                                popts.callbacks = this.callbacks;
                                GLib.debug("Push?");
                                r.upload(far,popts);
                                GLib.debug("Push done?");