Ggit.init();
var a = new GitLive.Repo("/home/alan/gitlive/gitlive");
+ a.is_managed();
+ a.is_autocommit();
a.loadLocalBranches();
+ a.loadRemoteHeads();
a.fetchAll();
//
/*
public Repo(string path)
{
+ this.name = GLib.Path.get_basename(path);
this.repo = Ggit.Repository.open(GLib.File.new_for_path(path));
this.callbacks = new Callbacks(this);
}
-
+ Ggit.Branch head = null;
Gee.ArrayList<Ggit.Branch> branches = null;
- public void loadLocalBranches()
+ Ggit.RemoteHead[] remote_heads = null;
+ public void loadLocalBranches(bool force = false)
{
+ if (!force && this.branches != null) {
+ return;
+ }
+
this.branches = new Gee.ArrayList<Ggit.Branch>();
var r = this.repo.enumerate_branches(Ggit.BranchType.LOCAL);
while (r.next()) {
// 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;
+ }
}
+
+
+ }
+
+ public bool is_managed()
+ {
+ GLib.debug("is_managed: %d", this.repo.get_config().get_int32("gitlive.managed"));
+ return this.repo.get_config().get_int32("gitlive.managed") == 1;
+ }
+
+
+ public bool is_autocommit ()
+ {
+ GLib.debug("is_autocommit: %d", this.repo.get_config().get_int32("gitlive.autocommit"));
+ return this.repo.get_config().get_int32("gitlive.autocommit") == 1;
+ }
+ public void set_autocommit(bool val)
+ {
+ this.repo.get_config().set_int32("gitlive.autocommit", val ? "1" : "0");
+
+ }
+
+ public bool doMergeClose(string commit_message)
+ {
+ this.loadLocalBranches(true);
+ var oldbranch = this.head.get_name();
+
+ string [] cmd = { "merge", "--squash", oldbranch };
+ this.git( cmd );
+ cmd = { "commit", "-a" , "-m", commit_message };
+ this.git( cmd );
+ this.push();
+ this.loadBranches(); // updates lastrev..
+
+ var notification = new Notify.Notification(
+ "Merged branch %s to %s".printf(oldbranch, master),
+ "",
+ "dialog-information"
+
+ );
+
+ notification.set_timeout(5);
+ notification.show();
+
+
+
+
+ public bool is_auto_branch ()
+ {
+ if (this.name == "gitlog") {
+ return false;
+ }
+ // check remote...
+ if (this.is_managed()) {
+ return true;
+ }
+ return false;
+
+
+ }
+
+ public void loadRemoteHeads(bool force = false)
+ {
+
+ 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();
+
}
+
+
Ggit.Branch? getBranch(string remote_name, string remote_branch_name)
{
//GLib.debug("bn=%s",remote_branch_name);
return null;
}
-
-
+
public void fetchAll()
{
this.loadLocalBranches();
+ this.loadRemoteHeads();
+
// remotes probably will not work with http auth..
- var ar = this.repo.list_remotes();
- foreach(var n in ar) {
+ //var ar = this.repo.list_remotes();
+ //foreach(var n in ar) {
+ var n = "origin";
+
GLib.debug("got remote '%s'", n);
var r = this.repo.lookup_remote(n);
GLib.debug("connecting '%s'", r.get_url());
return;
}
string[] far = {};
- var heads = r.list();
- foreach(var rh in heads) {
+
+ foreach(var rh in this.remote_heads) {
if (rh.get_name().has_prefix("refs/remotes/")) {
continue;
}
var br = this.getBranch(n, rh.get_name());
- GLib.debug("got heads: name=%s rev=%s localrev=%s",
+ /*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()
);
+ */
var loc_oid = this.repo.revparse(br.get_name() ).get_id();
size_t ahead, behind;
this.repo.get_ahead_behind(
if (far.length < 1) {
GLib.debug("no fetch required.. it's uptodate");
+ r.disconnect();
return;
}
r.disconnect();
//r.download(
- }
+
}
public void pushAll()
{
+
+ this.loadLocalBranches();
+ this.loadRemoteHeads();
// remotes probably will not work with http auth..
- var ar = this.repo.list_remotes();
- foreach(var n in ar) {
+ //var ar = this.repo.list_remotes();
+ var n = "origin";
+
GLib.debug("got remote '%s'", n);
var r = this.repo.lookup_remote(n);
GLib.debug("connecting '%s'", r.get_url());
- try {
- string[] h = { "a = 1" };
- r.connect(Ggit.Direction.PUSH, this.callbacks, null, null);
-
- } catch (Error e) {
- GLib.debug("Got Error Message: %s", e.message);
- return;
- }
+ r.connect(Ggit.Direction.PUSH, this.callbacks, null, null);
+
//GLib.debug("getting specs '%s'", n);
/*
}
var br = this.getBranch(n, 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()
- );
+ );*/
var loc_oid = this.repo.revparse(br.get_name() ).get_id();
size_t ahead, behind;
this.repo.get_ahead_behind(
if (far.length < 1) {
GLib.debug("no push required.. it's uptodate");
+ r.disconnect();
return;
}
//r.download(
- }
+
}
-
-
+
}
protected override void progress(string message)
{
- GLib.debug("progress");
+ GLib.debug("progress: %s", message);
if (d_proxy != null)
{
d_proxy.progress(message);