- /**
- * @property {String} the "gitlive" directory, normally ~/gitlive
- * dset by OWNER... - we should do this as a CTOR.
- *
- */
- public string gitlive = '';
-
-
- public Array<GtkMonitorQueuequeue>;
- public bool queueRunning = false;
-
- public DateTime lastAdd;
-
-
- public void pause() {
- this.paused = true;
- // what does this do to the old one...
- this.queue = new Array<FileMonitor> ();
- StatusIcon.statusicon.set_from_stock( Gtk.Stock.MEDIA_PAUSE );
-
- }
-
- public void resume () {
- this.paused = false;
- this.queue = new Array<FileMonitor> ();
- StatusIcon.statusicon.set_from_stock( Gtk.Stock.MEDIA_PLAY );
-
-
- }
- /**
- * Start the monitoring
- * and run the queue every 500 milliseconds..
- *
- */
- public void start() {
- StatusIcon.statusicon.set_from_stock( Gtk.Stock.MEDIA_REFRESH );
-
-
- this.lastAdd = new DateTime.now();
-
- Timeout.add_full(GLib.PRIORITY_LOW, 500, () => {
-
- // call this.monitor on each of 'top'
- for(int i = 0; i < this.top.length ; i++) {
- this.monitor(this.top.index(i) );
- }
- StatusIcon.statusicon.set_from_stock( Gtk.Stock.MEDIA_PLAY );
-
-
-
- try {
- var notification = new Notify.Notification({
- "Git Live",
- this.gitlive + "\nMonitoring " + _this.monitors.length + " Directories",
- "dialog-information"
- });
-
- notification.set_timeout(5);
- notification.show();
- } catch(Error e) {
- print(e.toString());
- }
-
- });
-
- Timeout.add_full(GLib.PRIORITY_LOW, 1000, () => {
- //TIMEOUT", _this.queue.length , _this.queueRunning].join(', '));
- if (!_this.queue.length || _this.queueRunning) {
- return true;
- }
-
- var last = this.lastAdd.difference(new DateTime.now());
-
-
- //print("LAST RUN?" + last);
-
- if (last < 5 * Timespan.SECOND) { // wait 1/2 a seconnd before running.
- return 1;
- }
- //_this.lastAdd = new Date();
- //return 1;
-
- this.runQueue();
- return true;
- },null,null);
-
-
- }
-
-
- public void stop() {
- StatusIcon.statusicon.set_from_stock( Gtk.Stock.MEDIA_PAUSE );;
- base.stop();
- }
-
-
- public void monitor (string path, int depth = 0)
- {
-
- //var depth = typeof(depth) == 'number' ? depth *1 : 0;
-
-
- // if we are not at top level.. and there is a .git directory (it's a submodule .. ignore)
- if (depth > 1 && GLib.file_test(path + '/.git' , GLib.FileTest.IS_DIR)) {
- return;
- }
-
- if (depth == 1) {
- // FIXME - check if repo is flagged as not autocommit..
- //var repo = imports.Scm.Repo.Repo.get(path);
- //if (!repo || !repo.autocommit()) {
- // return;
- //}
- }
-
-
- // check if the repo is to be monitored.
- //print("PATH : " + path);
-
-
- base.monitor(path, depth);
- }
-
-
-
- /**
- * run the queue.
- * - pulls the items off the queue
- * (as commands run concurrently and new items may get added while it's running)
- * - runs the queue items
- * - pushes upstream.
- *
- */
- public void runQueue()
- {
-
- if (this.paused) {
- return;
- }
- this.queueRunning = true;
-
- var cmds = new Array<GitMontitorQueue>();
- for(var i = 0; i < this.queue.length; i++) {
- cmds.append_val(this.queue.item(i));
- }
-
- this.queue = new Array<GitMontitorQueue>();// empty queue!
-
-
- var success = new Array<String>();
- var failure = new Array<GitMontitorQueue>();
- var repos = new Array<GitRepo>(); //??
- var done = new Array<GitMontitorQueue>();
-
- // first build a array of repo's to work with
- var repo_list = new Array<GitRepo>();
-
- // pull and group.
-
- //print(JSON.stringify(cmds));
- this.paused = true;
-
- for(var i = 0; i < cmds.length; i++) {
-
-
- var gitpath = cmd.gitpath;
- var ix = GitMontitorRepo.indexOf(this.repos, cmd.gitpath);
- if (ix < 0) {
- repo_list.append_val(new GitRepo( gitpath ));
- ix = GitRepo.indexOf(this.repos, cmd.gitpath);
- }
-
-
- //if (typeof(repo_list[gitpath]) == 'undefined') {
- // repo_list[gitpath] = new imports.Scm.Git.Repo.Repo( { repopath : gitpath });
- // repo_list[gitpath].cmds = [];
- // repo_list[gitpath].pull();
- //}
- repo_list.item(ix).append_val(cmd);
-
- }
- this.paused = false;
- // build add, remove and commit message list..
-
- for(var i = 0;i < repo_list.length;i++) {
-
-
- var repo = repo_list.item(i);
-
- var add_files = new Array<GitMontitorQueue>();
- var remove_files = new Array<GitMontitorQueue>();
- var messages = new Array<GitMontitorQueue>();
- //print(JSON.stringify(repo.cmds,null,4));
-
- for(var ii = 0;ii < repo.length;ii++) {
- var cmd = repo.item(ii);
-
-
- switch(cmd.name) {
- case "add" :
-
- if (GitMontitorQueue.indexOfAdd(add_files, cmd.add) > -1) {
- break;
- }
-
-
- add_files.append_val(cmd);
- break;
-
- case 'rm':
- if (GitMontitorQueue.indexOfAdd(add_files, cmd.rm) > -1 ) {
- break;
- }
-
- // if file exists, do not try and delete it.
- if (GLib.file_test(cmd.rm, GLib.FileTest.EXISTS)) {
- break;
- }
-
- remove_files.append_val(cmd);
- break;
-
- case 'commit' :
- if (GitMontitorQueue.indexOfMessage(messages, cmd.message) > -1 ) {
- break;
- }
-
- messages.append_val(cmd);
-
- break;
- }
- }
-
- //repo.debug = 1;
- // these can fail... at present... as we wildcard stuff.
- stdout.printf("ADD : %d files" , add_files.length);
-
- // make sure added files do not get removed..
-
- var remove_files_f = new Array<GitMontitorQueue>();
- for(var ii = 0;ii < remove_files.length;ii++) {
- if (GitMontitorQueue.indexOfAdd(add_files, remove_files.item(ii).rm) > -1 ) {
- continue;
- }
- remove_files_f.append_val(remove_files.item(ii));
- };
- stdout.printf("REMOVE : %d files" , remove_files.length);
-
- // make sure monitoring is paused so it does not recursively pick up
- // deletions
-
- // -- DO STUFF..
-
- repo.add(add_files);
- repo.remove(remove_files);
- this.paused = false;
-
-
- try {
- success.append_val(repo.commit(
- GitMontitorQueue.messageToString(messages)
- add_files
- ));
- success.push(repo.push());
-
- } catch(Error e) {
- failure.append_val(e.message);
-
- }
- }
-
- // finally merge all the commit messages.
-
- try {
- // catch notification failures.. so we can carry on..
- if (success.length) {
- var success_str = "";
- for(var ii = 0;ii < success.length;ii++) {
- success_str+= success.item(ii) + "\n";
- }
-
- var notification = new Notify.Notification(
- "Git Live Commited",
- success_str,
- "dialog-information"
-
- );
-
- notification.set_timeout(5);
- notification.show();
- }
-
- if (failure.length) {
- var failure_str = "";
- for(var ii = 0;ii < failure.length;ii++) {
- failure_str+= failure.item(ii) + "\n";
- }
- var notification = new Notify.Notification({
- summary: "Git Live ERROR!!",
- failure_str,
- "dialog-information"
-
- });
-
- notification.set_timeout(5); // show errros for longer
- notification.show();
- }
- } catch(Error e) {
- print(e.message);
-
- }
- this.queueRunning = false;
- }
-
-
-
-
-
- //string[] just_created;
+ string[] success = {};
+ string[] failure = {};
+ //var repos = new Array<GitRepo>(); //??
+ //var done = new Array<GitMonitorQueue>();
+
+ // first build a array of repo's to work with
+ var repo_list = new Array<GitRepo>();
+
+ // pull and group.
+
+ //print(JSON.stringify(cmds));
+ // make sure nothing get's added to the queue where we are doing this..
+
+ this.paused = true;
+
+ var leave_queued = new Gee.ArrayList<GitMonitorQueue>();
+ GLib.debug("GitMonitor.runQueue - creating repos");
+
+ for(var i = 0; i < cmds.size; i++) {
+
+ var cmd = cmds.get(i);
+
+ var gitpath = cmd.gitpath;
+
+ var repo = GitRepo.get_sync( gitpath );
+ if ( repo.is_master_branch() && repo.is_auto_branch()) {
+ leave_queued.add(cmd);
+ continue;
+ }
+
+ GLib.debug("GitMonitor.runQueue - finding %s", cmd.gitpath);
+
+ var ix = GitRepo.indexOf(repo_list, gitpath);
+ if (ix < 0) {
+ repo_list.append_val( GitRepo.get_sync( gitpath ));
+ ix = GitRepo.indexOf(repo_list, cmd.gitpath);
+ }
+ GLib.debug("GitMonitor.runQueue - adding to repolist %d", ix);
+
+ //if (typeof(repo_list[gitpath]) == 'undefined') {
+ // repo_list[gitpath] = new imports.Scm.Git.Repo.Repo( { repopath : gitpath });
+ // repo_list[gitpath].cmds = [];
+ // repo_list[gitpath].pull();
+ //}
+ repo_list.index(ix).cmds.add(cmd);
+
+ }
+ this.queue = leave_queued;
+
+ this.paused = false;
+ // build add, remove and commit message list..
+
+ GLib.debug("GitMonitor.runQueue - creating actions");
+
+ for(var i = 0;i < repo_list.length;i++) {
+
+ var repo = repo_list.index(i);
+
+ 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.size;ii++) {
+ var cmd = repo.cmds.get(ii);
+
+ if (repo.is_ignore(cmd.vname)) {
+ continue;
+ }
+
+
+ switch(cmd.action) {
+ case "add" :
+
+ if (GitMonitorQueue.indexOfAdd(add_files, cmd.vname) > -1) {
+ break;
+ }
+
+ add_files.add(cmd);
+ break;
+
+ case "rm":
+ if (GitMonitorQueue.indexOfAdd(remove_files, cmd.vname) > -1 ) {
+ break;
+ }
+
+ // if file exists, do not try and delete it.
+ if (FileUtils.test(cmd.fullpath(), FileTest.EXISTS)) {
+ break;
+ }
+
+ remove_files.add(cmd);
+ break;
+
+ case "commit" :
+ if (GitMonitorQueue.indexOfMessage(messages, cmd.message) > -1 ) {
+ break;
+ }
+ messages.add(cmd);
+
+ break;
+ default:
+ stdout.printf("Opps unmatched action %s\n", cmd.action);
+ break;
+ }
+ }
+
+ repo.cmds.clear(); // reset the repo's command list..
+
+ GLib.debug( "ADD : %s", GitMonitorQueue.queueArrayToString(add_files));
+ GLib.debug( "REMOVE FILES: %s", GitMonitorQueue.queueArrayToString(remove_files));
+
+ //repo.debug = 1;
+ // these can fail... at present... as we wildcard stuff.
+
+ // make sure added files do not get removed.. ??
+ /*
+ var remove_files_f = new Array<GitMonitorQueue>();
+ for(var ii = 0;ii < remove_files.length;ii++) {
+ if (GitMonitorQueue.indexOfAdd(add_files, remove_files.index(ii).vname) > -1 ) {
+ continue;
+ }
+ remove_files_f.append_val(remove_files.index(ii));
+ };
+ stdout.printf("REMOVE : %u files\n" , remove_files_f.length);
+ */
+
+ // if file was added, then removed,
+ var remove_files_f = new Gee.ArrayList<GitMonitorQueue>();
+ for(var ii = 0;ii < remove_files.size;ii++) {
+
+
+
+ if (GitMonitorQueue.indexOfAdd(add_files, remove_files.get(ii).vname) > -1 ) {
+ // in add and remove - do not remvove
+ continue;
+ }
+ remove_files_f.add(remove_files.get(ii));
+ };
+ 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.get(ii).fullpath());
+
+ if (!FileUtils.test(add_files.get(ii).fullpath(), FileTest.EXISTS)) {
+ continue;
+ }
+
+ }
+
+ 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.size < 1 && remove_files_f.size < 1) {
+ continue;
+ }
+
+ // make sure monitoring is paused so it does not recursively pick up
+ // deletions
+ this.paused = true;
+
+
+ try {
+
+ repo.pull();
+ } catch(Error e) {
+ this.pauseError(e.message);
+ //failure += e.message;
+ //print("Pull failed:\n");
+ return;
+ }
+
+ // -- DO STUFF..
+ try {
+ repo.add(add_files_f);
+ } catch(Error e) {
+ this.pauseError(e.message);
+ return;
+ failure += e.message;
+ GLib.debug("Add failed:");
+ }
+ try {
+ repo.remove(remove_files_f);
+ } catch(Error e) {
+ this.pauseError(e.message);
+ return;
+ failure += e.message;
+ GLib.debug("Remove failed:");
+ }
+
+ try {
+ success += repo.commit(
+ GitMonitorQueue.messageToString(messages),
+ add_files_f
+ );
+ success += repo.push();
+
+
+ } catch(Error e) {
+
+ // if the error is 'nothing to commit, working tree clean'
+ // then it's not an error, - just continue;
+ if (/nothing to commit, working tree clean/.match(e.message)) {
+ GLib.debug("%s",e.message);
+ success += e.message;
+ this.paused = false;
+ continue;
+ }
+
+
+
+ this.paused = false;
+ this.pauseError(e.message);
+
+ return;
+ //failure += e.message;
+ //print("Push failed:\n");
+
+ }
+ this.paused = false;
+ }
+
+
+ // finally merge all the commit messages.
+
+ try {
+ // catch notification failures.. so we can carry on..
+ if (success.length > 0) {
+
+
+ var notification = new Notify.Notification(
+ "Git Live Commited",
+ string.joinv("\n",success),
+ "dialog-information"
+
+ );
+
+ notification.set_timeout(5);
+ notification.show();
+ }
+
+ //if (failure.length > 0) {
+
+ // should never get this far...
+ // this.pauseError();
+ //}
+ } catch(Error e) {
+ GLib.debug(e.message);
+
+ }
+ this.queueRunning = false;
+ }
+
+
+
+
+
+ //string[] just_created;