public static string gitlive;
- public Array<GitMonitorQueue> queue ;
+ private Gee.ArrayList<GitMonitorQueue> queue ;
public bool queueRunning = false;
public DateTime lastAdd;
public GitMonitor ()
{
- this.queue = new Array<GitMonitorQueue>();
+ this.queue = new Gee.ArrayList<GitMonitorQueue>();
GitMonitor.gitmonitor = this;
Timeout.add_full(Priority.LOW, 500, () => {
//GLib.debug("TIMEOUT queue length = %d, is_runing = %s\n", (int)this.queue.length , this.queueRunning ? "Y" : "N");
//stdout.printf("QL %u: QR: %d\n", this.queue.length, this.queueRunning ? 1 : 0);
- if (this.queue.length < 1 || this.queueRunning) {
+ if (this.queue.size < 1 || this.queueRunning) {
return true;
}
this.paused = true;
this.queueRunning = false;
// what does this do to the old one...
- this.queue = new Array<GitMonitorQueue> ();
+ //this.queue = new Gee.ArrayList<GitMonitorQueue> ();
this.stop();
StatusIconA.statusicon.pauseError();
public new void pause() {
this.paused = true;
// what does this do to the old one...
- this.queue = new Array<GitMonitorQueue> ();
+ //this.queue = new Gee.ArrayList<GitMonitorQueue> ();
StatusIconA.statusicon.pause();
}
}
- public new void monitor (string path, int depth = 0)
+ public override void monitor (string path, int depth = 0)
{
+ //GLib.debug("GitMonitor : monitor %d %s", depth, path);
//var depth = typeof(depth) == 'number' ? depth *1 : 0;
}
if (depth == 1) {
+
+ if (!FileUtils.test(path + "/.git" , FileTest.IS_DIR)) {
+ return; // skip non-git directories..
+ }
+
+ GitRepo.get(path);
+
// FIXME - check if repo is flagged as not autocommit..
//var repo = imports.Scm.Repo.Repo.get(path);
//if (!repo || !repo.autocommit()) {
public void runQueue()
{
- if (this.paused) {
+ if (this.paused || this.queue.size < 1 ) {
return;
}
GLib.debug("GitMonitor.runQueue\n");
this.queueRunning = true;
- var cmds = new Array<GitMonitorQueue>();
+ var cmds = new Gee.ArrayList<GitMonitorQueue>();
- for(var i = 0; i < this.queue.length; i++) {
- cmds.append_val(this.queue.index(i));
+ for(var i = 0; i < this.queue.size; i++) {
+ cmds.add(this.queue.get(i));
}
- this.queue = new Array<GitMonitorQueue>();// empty queue!
-
-
+ this.queue = new Gee.ArrayList<GitMonitorQueue>();// empty queue!
+
string[] success = {};
string[] failure = {};
//var repos = new Array<GitRepo>(); //??
var leave_queued = new Gee.ArrayList<GitMonitorQueue>();
GLib.debug("GitMonitor.runQueue - creating repos");
- for(var i = 0; i < cmds.length; i++) {
+ for(var i = 0; i < cmds.size; i++) {
- var cmd = cmds.index(i);
+ var cmd = cmds.get(i);
var gitpath = cmd.gitpath;
// repo_list[gitpath].cmds = [];
// repo_list[gitpath].pull();
//}
- repo_list.index(ix).cmds.append_val(cmd);
+ repo_list.index(ix).cmds.add(cmd);
}
+ this.queue = leave_queued;
+
this.paused = false;
// build add, remove and commit message list..
var repo = repo_list.index(i);
- var add_files = new Array<GitMonitorQueue>();
- var add_files_f = new Array<GitMonitorQueue>();
- var remove_files = new Array<GitMonitorQueue>();
- var messages = new Array<GitMonitorQueue>();
+ var add_files = new Gee.ArrayList<GitMonitorQueue>();
+ var add_files_f = new Gee.ArrayList<GitMonitorQueue>();
+ var remove_files = new Gee.ArrayList<GitMonitorQueue>();
+ var messages = new Gee.ArrayList<GitMonitorQueue>();
//print(JSON.stringify(repo.cmds,null,4));
- for(var ii = 0;ii < repo.cmds.length;ii++) {
- var cmd = repo.cmds.index(ii);
+ for(var ii = 0;ii < repo.cmds.size;ii++) {
+ var cmd = repo.cmds.get(ii);
if (repo.is_ignore(cmd.vname)) {
continue;
break;
}
- add_files.append_val(cmd);
+ add_files.add(cmd);
break;
case "rm":
break;
}
- remove_files.append_val(cmd);
+ remove_files.add(cmd);
break;
case "commit" :
if (GitMonitorQueue.indexOfMessage(messages, cmd.message) > -1 ) {
break;
}
- messages.append_val(cmd);
+ messages.add(cmd);
break;
default:
*/
// if file was added, then removed,
- var remove_files_f = new Array<GitMonitorQueue>();
- for(var ii = 0;ii < remove_files.length;ii++) {
+ var remove_files_f = new Gee.ArrayList<GitMonitorQueue>();
+ for(var ii = 0;ii < remove_files.size;ii++) {
- if (GitMonitorQueue.indexOfAdd(add_files, remove_files.index(ii).vname) > -1 ) {
+ if (GitMonitorQueue.indexOfAdd(add_files, remove_files.get(ii).vname) > -1 ) {
// in add and remove - do not remvove
continue;
}
- remove_files_f.append_val(remove_files.index(ii));
+ remove_files_f.add(remove_files.get(ii));
};
- for(var ii = 0;ii < add_files.length;ii++) {
- if (GitMonitorQueue.indexOfAdd(remove_files, add_files.index(ii).vname) > -1 ) {
+ for(var ii = 0;ii < add_files.size;ii++) {
+ if (GitMonitorQueue.indexOfAdd(remove_files, add_files.get(ii).vname) > -1 ) {
// the add file is in the remove list, and it does not exist - do not add it..
- print("check exists ? %s\n",add_files.index(ii).fullpath());
+ print("check exists ? %s\n",add_files.get(ii).fullpath());
- if (!FileUtils.test(add_files.index(ii).fullpath(), FileTest.EXISTS)) {
+ if (!FileUtils.test(add_files.get(ii).fullpath(), FileTest.EXISTS)) {
continue;
}
- }
-
-
+ }
- add_files_f.append_val(add_files.index(ii));
+ add_files_f.add(add_files.get(ii));
};
GLib.debug( "ADD : %s", GitMonitorQueue.queueArrayToString(add_files_f));
GLib.debug( "REMOVE FILES: %s", GitMonitorQueue.queueArrayToString(remove_files_f));
- if (add_files_f.length < 1 && remove_files_f.length < 1) {
+ if (add_files_f.size < 1 && remove_files_f.size < 1) {
continue;
}
failure += e.message;
GLib.debug("Remove failed:");
}
-
-
+
try {
success += repo.commit(
GitMonitorQueue.messageToString(messages),
);
success += repo.push();
+
} catch(Error e) {
// if the error is 'nothing to commit, working tree clean'
}
*/
cmd.action = "add";
- this.queue.append_val(cmd);
+ this.queue.add(cmd);
cmd = new GitMonitorQueue(src);
cmd.action = "commit";
cmd.message = cmd.vname;
- this.queue.append_val(cmd);
+ this.queue.add(cmd);
+
+
+ if (!cmd.shouldIgnore() && !cmd.repo.is_wip_branch()) {
+ NewBranch.singleton().show(cmd.repo);
+ }
}
// should check if monitor needs removing..
// it should also check if it was a directory.. - so we dont have to commit all..
cmd.action = "rm";
- this.queue.append_val(cmd);
+ this.queue.add(cmd);
cmd = new GitMonitorQueue(src);
cmd.action = "commit";
cmd.message = cmd.vname;
cmd.commit_all = true;
- this.queue.append_val(cmd);
+ this.queue.add(cmd);
+
+ if (!cmd.shouldIgnore() && !cmd.repo.is_wip_branch()) {
+ NewBranch.singleton().show(cmd.repo);
+ }
+
}
public override void onCreated(MonitorNamePathDir src) {
}
- public override void onAttributeChanged(MonitorNamePathDir src) {
+ public override void onAttributeChanged(MonitorNamePathDir src)
+ {
if (this.paused) {
return;
return;
}
cmd.action = "add";
- this.queue.append_val(cmd);
+ this.queue.add(cmd);
cmd = new GitMonitorQueue(src);
cmd.action = "commit";
cmd.message = "Attribute changed " + cmd.vname;
- this.queue.append_val(cmd);
+ this.queue.add(cmd);
+
+ if (!cmd.shouldIgnore() && !cmd.repo.is_wip_branch()) {
+ NewBranch.singleton().show(cmd.repo);
+ }
}
public override void onMoved(MonitorNamePathDir src,MonitorNamePathDir dest)
GLib.debug("RM: %s", cmd_s.vname);
cmd_s.action = "rm";
- this.queue.append_val(cmd_s);
+ this.queue.add(cmd_s);
GLib.debug("ADD: %s", cmd_d.vname);
cmd_d.action = "add";
- this.queue.append_val(cmd_d);
+ this.queue.add(cmd_d);
var cmd = new GitMonitorQueue(dest);
cmd.message = cmd_d.vname;
}
- this.queue.append_val(cmd);
-
+
+ this.queue.add(cmd);
+ if (!cmd.shouldIgnore() && !cmd.repo.is_wip_branch()) {
+ NewBranch.singleton().show(cmd.repo);
+ }
+ // this is where it get's complicated...
+ // as we might be moving across repo's...
+
+
+
}
this.vname = "";
return;
}
-
+
this.gitpath = GitMonitor.gitlive + "/" + vpath_ar[0];
/** -- statics --*/
- public static int indexOfAdd( Array<GitMonitorQueue> add_files, string add)
+ public static int indexOfAdd( Gee.ArrayList<GitMonitorQueue> add_files, string add)
{
- for(var i =0; i < add_files.length; i++) {
- if (add_files.index(i).vname == add) {
+ for(var i =0; i < add_files.size; i++) {
+ if (add_files.get(i).vname == add) {
return i;
}
}
return -1;
}
- public static int indexOfMessage(Array<GitMonitorQueue> messages, string message) {
- for(var i =0; i < messages.length; i++) {
- if (messages.index(i).message == message) {
+ public static int indexOfMessage(Gee.ArrayList<GitMonitorQueue> messages, string message) {
+ for(var i =0; i < messages.size; i++) {
+ if (messages.get(i).message == message) {
return i;
}
}
return -1;
}
- public static string messageToString(Array<GitMonitorQueue> messages ) {
+ public static string messageToString(Gee.ArrayList<GitMonitorQueue> messages ) {
string[] ret = {};
- for(var i =0; i < messages.length; i++) {
- ret+= messages.index(i).message;
+ for(var i =0; i < messages.size; i++) {
+ ret+= messages.get(i).message;
}
return string.joinv("\n",ret);
}
- public static string queueArrayToString(Array<GitMonitorQueue> list) {
+ public static string queueArrayToString(Gee.ArrayList<GitMonitorQueue> list) {
var ret = "";
- for(var i =0; i < list.length; i++) {
+ for(var i =0; i < list.size; i++) {
- ret += (ret.length > 0 ? ", " : "") + list.index(i).vname;
+ ret += (ret.length > 0 ? ", " : "") + list.get(i).vname;
}
return ret;
}
- public static bool queueHas(Array<GitMonitorQueue> list , GitMonitorQueue cmd_s, string action) {
- for(var i =0; i < list.length; i++) {
- var test = list.index(i);
- if (list.index(i).gitpath != cmd_s.gitpath) {
+ public static bool queueHas(Gee.ArrayList<GitMonitorQueue> list , GitMonitorQueue cmd_s, string action) {
+ for(var i =0; i < list.size; i++) {
+ var test = list.get(i);
+ if (list.get(i).gitpath != cmd_s.gitpath) {
continue;
}
- if (list.index(i).vname != cmd_s.vname) {
+ if (list.get(i).vname != cmd_s.vname) {
continue;
}
- if (list.index(i).action != action) {
+ if (list.get(i).action != action) {
continue;
}
return true;
public class GitRepo : Object
{
- public Array<GitMonitorQueue> cmds;
+ public Gee.ArrayList<GitMonitorQueue> cmds;
public string name;
public string gitdir;
public bool is_wip_branch()
{
- return this.currentBranch.name.has_prefix("wip_")
+ return this.currentBranch.name.has_prefix("wip_");
}
return ret;
}
- RooTicket? ticket = null;
+ public static void doMerges(string action, string ticket_id, string commit_message)
+ {
+ GitMonitor.gitmonitor.stop();
+
+ var commitrevs = "";
+ var sucess = true;
+ foreach(var repo in GitRepo.singleton().cache.values) {
+ if (repo.activeTicket != null && repo.activeTicket.id == ticket_id) {
+ var res = repo.doMerge(action,ticket_id, commit_message);
+ if (!res) {
+ sucess = false;
+ continue;
+ }
+ commitrevs += commitrevs.length > 0 ? " " : "";
+ commitrevs += repo.currentBranch.lastrev;
+ }
+ }
+ if (sucess && action == "CLOSE") {
+ RooTicket.singleton().getById(ticket_id).close(commitrevs);
+ }
+ GitMonitor.gitmonitor.start();
+ }
+
+
+
+
+ public bool doMerge(string action, string ticket_id, string commit_message)
+ {
+ // in theory we should check to see if other repo's have got the same branch and merge all them at the same time.
+ // also need to decide which branch we will merge into?
+ var ret = "";
+ if (action == "CLOSE" || action == "LEAVE") {
+
+
+ try {
+ var oldbranch = this.currentBranch.name;
+ this.setActiveTicket(null, "master");
+ string [] cmd = { "merge", "--squash", oldbranch };
+ this.git( cmd );
+ cmd = { "commit", "--m", commit_message };
+ this.git( cmd );
+ this.loadBranches(); // updates lastrev..
+
+ var notification = new Notify.Notification(
+ "Merged branch %s to master".printf(oldbranch),
+ "",
+ "dialog-information"
+
+ );
+
+ notification.set_timeout(5);
+ notification.show();
+
+ // close ticket..
+ return true;
+
+ } catch (Error e) {
+
+ GitMonitor.gitmonitor.pauseError(e.message);
+ return false;
+ }
+ // error~?? -- show the error dialog...
+ return false;
+ }
+ if (action == "MASTER") {
+ // merge master into ours..
+ try {
+ string[] cmd = { "merge", "master" };
+ this.git( cmd );
+ var notification = new Notify.Notification(
+ "Merged code from master to %s".printf(this.currentBranch.name),
+ "",
+ "dialog-information"
+
+ );
+ notification.set_timeout(5);
+ notification.show();
+
+ return true;
+ } catch (Error e) {
+ GitMonitor.gitmonitor.pauseError(e.message);
+ return false;
+ }
+ }
+ if (action == "EXIT") {
+ try {
+ var oldbranch = this.currentBranch.name;
+ this.setActiveTicket(null, "master");
+ this.loadBranches();
+ var notification = new Notify.Notification(
+ "Left branch %s".printf(oldbranch),
+ "",
+ "dialog-information"
+
+ );
+ notification.set_timeout(5);
+ notification.show();
+
+ return true;
+ } catch (Error e) {
+ GitMonitor.gitmonitor.pauseError(e.message);
+
+ return false;
+ }
+ // error~?? -- show the error dialog...
+
+ }
+ return false;
+ }
- public void setActiveTicket(RooTicket ticket, string branchname)
+
+ public void setActiveTicket(RooTicket ticket, string branchname)
{
this.createBranchNamed(branchname);
FileUtils.set_contents(this.gitdir + "/.gitlive-active-ticket" , ticket.id);
public void createBranchNamed(string branchname)
{
- string[] cmd = { "checkout", "-b" , branchname };
- this.git(cmd);
+ if (this.branches.has_key(branchname)) {
+ string[] cmd = { "checkout", branchname };
+ this.git(cmd);
+ } else {
+ string[] cmd = { "checkout", "-b" , branchname };
+ this.git(cmd);
+ }
this.loadBranches(); // update branch list...
GitMonitor.gitmonitor.runQueue(); // commit any outstanding...
}
*
* @argument {Array} files the files to add.
*/
- public string add ( Array<GitMonitorQueue> files ) throws Error, SpawnError
+ public string add ( Gee.ArrayList<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.index(i).vname;
+ for (var i = 0; i < files.size;i++) {
+ var f = files.get(i).vname;
try {
string[] cmd = { "add", f };
this.git( cmd );
*
*/
- public string commit ( string message, Array<GitMonitorQueue> files ) throws Error, SpawnError
+ public string commit ( string message, Gee.ArrayList<GitMonitorQueue> files ) throws Error, SpawnError
{
*/
string[] args = { "commit", "-m" };
args += (message.length > 0 ? message : "Changed" );
- for (var i = 0; i< files.length ; i++ ) {
- args += files.index(i).vname; // full path?
+ for (var i = 0; i< files.size ; i++ ) {
+ args += files.get(i).vname; // full path?
}
return this.git(args);
{
"listeners" : {
"delete_event" : "(self, event) => {\n this.el.hide();\n return true; \n //test \n}\n ",
- "response" : " (self, response_id) => { \n \n\tGLib.debug(\"got %d\", (int) response_id);\n\tif (response_id == 0) {\n\t _this.el.hide();\t\n\t this.running = false; \n\t \treturn;\n\t}\n\t \n\t// have they selected a ticket..\n\t// make that the current active ticket?\n\t// we really need to store locally what ticket is being worked on..\n\t// in theory we could be working on multiple project and not merging..\n\t// -- each repo would have their active ticket (only one per repo)\n\t// -- so we could just store that in there\n\t// -- initial load can check the contents of the ticket files on first scan.\n\tvar ticket_id = _this.ticketsel.selectedTicketId();\n\t\n if (this.repo != null) {\n \tvar bn = _this.name.el.get_text();\n \tif (ticket_id != \"\" ) {\n\t\t\tthis.repo.setActiveTicket( RooTicket.singleton().getById(ticket_id), bn);\n\t\t} else {\n\t\t\tthis.repo.createBranchNamed(bn);\n\t\t}\n }\n\n\t\t this.running = false; \n\n\t \n\t \n\t \n\n\t \n}",
+ "response" : " (self, response_id) => { \n \n\tGLib.debug(\"got %d\", (int) response_id);\n\tif (response_id == 0) {\n\t _this.el.hide();\t\n\t this.running = false; \n\t\tGitMonitor.gitmonitor.start();\t \n\t \treturn;\n\t}\n\t \n\t// have they selected a ticket..\n\t// make that the current active ticket?\n\t// we really need to store locally what ticket is being worked on..\n\t// in theory we could be working on multiple project and not merging..\n\t// -- each repo would have their active ticket (only one per repo)\n\t// -- so we could just store that in there\n\t// -- initial load can check the contents of the ticket files on first scan.\n\tvar ticket_id = _this.ticketsel.selectedTicketId();\n\t\n if (this.repo != null) {\n \tvar bn = _this.name.el.get_text();\n \tif (ticket_id != \"\" ) {\n\t\t\tthis.repo.setActiveTicket( RooTicket.singleton().getById(ticket_id), bn);\n\t\t} else {\n\t\t\tthis.repo.createBranchNamed(bn);\n\t\t}\n }\n\tGitMonitor.gitmonitor.start();\n\t\t this.running = false; \n\n\t \n\t \n\t \n\n\t \n}",
"show" : "(self) => {\n \n\n //test\n}"
},
"default_width" : 500,
"title" : "Create a working branch ",
"xtype" : "Dialog",
"# GitRepo? repo" : "null",
- "| void show" : "( GitRepo repo ) \n{\n // this.el.set_gravity(Gdk.Gravity.NORTH);\n if (this.running) {\n \treturn;\n\t}\n this.repo = repo;\n \n\tthis.el.move((Gdk.Screen.width() / 2)- 250 ,0);\n \tGLib.debug(\"Loading tickets\"); \n\n\n this.el.show_all();\n \t_this.dbmodel.loadTickets();\n\n}",
+ "| void show" : "( GitRepo repo ) \n{\n // this.el.set_gravity(Gdk.Gravity.NORTH);\n if (this.running) {\n \treturn;\n\t}\n\t\tGitMonitor.gitmonitor.stop();\n\t\n this.repo = repo;\n \n\tthis.el.move((Gdk.Screen.width() / 2)- 250 ,0);\n \tGLib.debug(\"Loading tickets\"); \n\n\n this.el.show_all();\n \t_this.dbmodel.loadTickets();\n\n}",
"default_height" : 200,
"$ xns" : "Gtk",
"# bool running" : false,
"items" : [
{
"bool homogeneous" : false,
- "* pack" : "pack_start,false,false,0",
"xtype" : "Table",
+ "* pack" : "pack_start,false,false,0",
"uint column_spacing" : 2,
"n_columns" : 2,
"$ xns" : "Gtk",
"items" : [
{
"id" : "dbcellrenderer",
- "xtype" : "CellRendererText",
"* pack" : "pack_start,true",
+ "xtype" : "CellRendererText",
"$ xns" : "Gtk"
},
{
"id" : "dbmodel",
- "xtype" : "ListStore",
"* pack" : "set_model",
+ "xtype" : "ListStore",
"| void loadTickets" : " () {\n\n RooTicket.singleton().loadTickets();\n \n _this.ticketsel.loading = true;\n\n this.el.clear(); \n Gtk.TreeIter iter;\n var el = this.el;\n \n el.append(out iter);\n\n \n el.set_value(iter, 0, \"\");\n el.set_value(iter, 1, \"-- select a ticket --\");\n \n _this.ticketsel.el.set_active_iter(iter);\n var tickets = RooTicket.singleton().tickets;\n foreach(var ticket in tickets) {\n \n el.append(out iter);\n \n el.set_value(iter, 0, ticket.id);\n el.set_value(iter, 1, \"#%s [%s] %s\".printf( ticket.id, ticket.project_id_name , ticket.summary));\n \n //if (data.get(i) == cur) {\n // _this.build_module.el.set_active_iter(iter);\n // }\n \n }\n \n _this.ticketsel.loading = false;\n //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING); \n \n}\n",
"$ columns" : "typeof(string),typeof(string)",
"n_columns" : 2,
},
{
"label" : "Do not create Branch",
- "xtype" : "Button",
"* pack" : "add_action_widget,0",
+ "xtype" : "Button",
"Gtk.ReliefStyle relief" : "Gtk.ReliefStyle.NONE",
"$ xns" : "Gtk"
},
{
"label" : "Create Branch",
- "xtype" : "Button",
"* pack" : "add_action_widget,1",
+ "xtype" : "Button",
"$ xns" : "Gtk"
}
]
if (response_id == 0) {
_this.el.hide();
this.running = false;
+ GitMonitor.gitmonitor.start();
return;
}
this.repo.createBranchNamed(bn);
}
}
-
+ GitMonitor.gitmonitor.start();
this.running = false;
if (this.running) {
return;
}
+ GitMonitor.gitmonitor.stop();
+
this.repo = repo;
this.el.move((Gdk.Screen.width() / 2)- 250 ,0);