-// valac -o /tmp/ggit Git.vala --pkg libgit2-glib-1.0 --pkg libsoup-2.4 -pkg gee-0.8 -g
-
-
+// valac -o /tmp/ggit Git.vala --pkg libgit2-glib-1.0 --pkg libsoup-2.4 --pkg gee-0.8 -g
+
void main()
{
}
);
- Ggit.init();
- var a = new GitLive.Repo("/home/alan/gitlive/gitlive");
- a.walkDiff();
- return;
- a.is_managed();
- a.is_autocommit();
- a.loadLocalBranches();
- a.loadRemoteHeads();
+ Ggit.init();
+ var a = new GitLive.Repo("/home/alan/gitlive/web.Texon");
a.fetchAll();
+ return;
+ /*
+ GLib.Timeout.add (1, () => {
+ GLib.debug("Meanwhile");
+ return true;
+ }, GLib.Priority.HIGH);
+
+ var loop = new MainLoop();
+
+ var a = new GitLive.Repo("/home/alan/gitlive/web.coba");
+ GLib.debug("Starting");
+ a.loadRemoteHeads.begin(true, (obj,res) => {
+ a.loadRemoteHeads.end(res);
+ GLib.debug("got results");
+ a.loadLocalBranches();
+ loop.quit();
+ });
+ loop.run();
+ //a.mergeMasterIntoHead();
+ //a.walkDiff();
+ //return;
+ //a.is_managed();
+ //a.is_autocommit();
+
+
+ //a.fetchAll();
//
/*
var a = new GitLive.Repo("/home/alan/git/test1-clone");
//string[] spawn_env = Environ.get ();
// Process.spawn_sync ("/home/alan/git/test1-clone", spawn_args, spawn_env, SpawnFlags.SEARCH_PATH, null);
- a.pushAll();
+ //a.pushAll();
}
var r = this.repo.enumerate_branches(Ggit.BranchType.LOCAL);
while (r.next()) {
var br = r.get() as Ggit.Branch;
+ if (br == null) {
+ continue;
+ }
+ if (br.is_tag()) {
+ continue;
+ }
+
//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);
- if (br.is_head()) {
- GLib.debug("HEAD= %s", br.get_name());
- this.head = br;
+ try {
+ GLib.debug("got branch: N=%s", br.get_name() );
+ GLib.debug("is_head %s", br.is_head() ? "Y" : "n");
+
+ GLib.debug("upstream = %s", br.get_upstream() == null ? "??" : br.get_upstream().get_name().substring(20));
+ GLib.debug("oid = %s",br.get_target().to_string());
+ this.branches.add(br);
+ if (br.is_head()) {
+ GLib.debug("HEAD= %s", br.get_name());
+ this.head = br;
+ }
+ } catch (Error e) {
+ GLib.debug("Skip branch");
}
-
}
{
this.loadLocalBranches();
+
+
var oid = this.repo.revparse(this.head.get_name() ).get_id() ;
var moid = this.repo.revparse("refs/heads/master" ).get_id() ;
// let's try a merge..
var mo = new Ggit.MergeOptions();
mo.set_file_favor(Ggit.MergeFileFavor.THEIRS);
- var ix = this.repo.merge_trees(null, master_tree, head_tree, mo);
+ var ix = this.repo.merge_trees(master_tree, master_tree, head_tree, mo);
if (ix.has_conflicts()) {
GLib.debug("merge has conflicts");
this.repo.get_config().get_string("user.name"),
this.repo.get_config().get_string("user.email")
);
- this.repo.create_commit("HEAD", sig, sig, null, "test commit " + str, new_tree, parents);
-
+ this.repo.create_commit("HEAD", sig, sig, null, "Test Merge", new_tree, parents);
+
+
+
+ }
+
+ public void diffhead()
+ {
+ var r = this.repo.enumerate_branches(Ggit.BranchType.LOCAL);
+ GitBranch head;
+ while (r.next()) {
+ var gbr = r.get() as Ggit.Branch;
+ if (gbr.is_head()) {
+ head = gbr;
+ }
+ }
}
+
+ public void mergeMasterIntoHead()
+ {
+ // assumes head is not master...
+ this.loadLocalBranches();
+ GLib.debug("head rev = %s", this.head.get_name());
+ var head_oid = this.repo.revparse(this.head.get_name() ).get_id() ;
+ //var master_oid = this.repo.revparse("refs/heads/master" ).get_id() ;
+ var master_oid = this.repo.revparse("HEAD" ).get_id() ;
+
+ var master_commit = this.repo.lookup_commit(master_oid);;
+ var head_commit = this.repo.lookup_commit(head_oid);
+
+
+ var anc_oid = this.repo.merge_base(master_commit.get_id(), head_commit.get_id());
+
+ var anc_commit = this.repo.lookup_commit(anc_oid);
+ var anc_tree = anc_commit.get_tree();
+
+ var mo = new Ggit.MergeOptions();
+ var co = new Ggit.CheckoutOptions();
+ var the_ref = this.repo.lookup_reference_dwim("refs/heads/master");
+
+ var ac = new Ggit.AnnotatedCommit.from_ref(this.repo, the_ref);
+
+ var commits = new Ggit.AnnotatedCommit[] { ac };
+
+ this.repo.merge(commits, mo, co);
+
+ var cfg = this.repo.get_config().snapshot();
+
+ var sig = new Ggit.Signature.now(
+ cfg.get_string("user.name"),
+ cfg.get_string("user.email")
+ );
+ var new_head = this.repo.get_head();
+ var oid = new_head.get_target();
+
+ var ix = this.repo.get_index();
+
+ ix.write();
+ var treeoid = ix.write_tree();
+
+ var new_tree = this.repo.lookup(treeoid,typeof (Ggit.Tree)) as Ggit.Tree;
+
+ var parent = new_head.lookup() as Ggit.Commit;
+ Ggit.Commit[] parents = new Ggit.Commit[] { parent };
+
+ this.repo.create_commit("refs/heads/" + this.head.get_name(), sig, sig, null, "Test Merge", new_tree, parents);
+
+ }
+
+
+
+
+
/*
public bool doMergeClose(string commit_message)
{
}
- public void loadRemoteHeads(bool force = false)
+ public async void loadRemoteHeads(bool force = false)
{
+ SourceFunc callback = loadRemoteHeads.callback;
- if (!force && this.remote_heads != null) {
- return;
- }
- var r = this.repo.lookup_remote("origin");
- r.connect(Ggit.Direction.FETCH, this.callbacks, null, null);
- this.remote_heads = r.list();
-
+ ThreadFunc<bool> run = () => {
+
+ if (!force && this.remote_heads != null) {
+ return true;;
+ }
+ var r = this.repo.lookup_remote("origin");
+ r.connect(Ggit.Direction.FETCH, this.callbacks, null, null);
+ yield;
+ this.remote_heads = r.list();
+
+ foreach(var br in this.remote_heads) {
+ if (!br.get_name().has_prefix("refs/heads/")) {
+ continue;
+ }
+
+ GLib.debug("Remote: name=%s oid=%s local_oid=%s is_local=%s",
+ br.get_name(),
+ br.get_oid().to_string(),
+ br.get_local_oid().to_string(),
+ br.is_local() ? "Y" : "n"
+ );
+ }
+ Idle.add((owned) callback);
+ return true;;
+ };
+ new Thread<bool>("loadRemoteHeads-" , run);
+ yield;
+
+
}
-
-
+
Ggit.Branch? getBranch(string remote_name, string remote_branch_name)
{
br == null ? "?": this.repo.revparse(br.get_name() ).get_id().to_string()
);
*/
- var loc_oid = this.repo.revparse(br.get_name() ).get_id();
+ //var loc_oid = this.repo.revparse(br.get_name() ).get_id();
+
+ var loc_oid = br.get_target();
+
size_t ahead, behind;
this.repo.get_ahead_behind(
loc_oid,