2 var Gio = imports.gi.Gio;
3 var Gtk = imports.gi.Gtk;
4 var Notify = imports.gi.Notify;
5 var GLib = imports.gi.GLib;
7 var Spawn = imports.Spawn;
8 var StatusIcon = imports.StatusIcon.StatusIcon;
9 var Monitor = imports.Monitor.Monitor;
13 var GitMonitor = new Monitor({
16 * @property {String} the "gitlive" directory, normally ~/gitlive
17 * dset by OWNER... - we should do this as a CTOR.
31 imports.StatusIcon.StatusIcon.el.set_from_stock( Gtk.STOCK_MEDIA_PAUSE );
37 imports.StatusIcon.StatusIcon.el.set_from_stock( Gtk.STOCK_MEDIA_PLAY );
43 * Start the monitoring
44 * and run the queue every 500 milliseconds..
49 this.lastAdd = new Date();
51 this.top.forEach(this.monitor, this);
53 GLib.timeout_add(GLib.PRIORITY_LOW, 500, function() {
54 //TIMEOUT", _this.queue.length , _this.queueRunning].join(', '));
55 if (!_this.queue.length || _this.queueRunning) {
58 var last = Math.floor(((new Date()) - _this.lastAdd) / 100);
60 //print("LAST RUN?" + last);
62 if (last < 5) { // wait 1/2 a seconnd before running.
65 //_this.lastAdd = new Date();
73 var notification = new Notify.Notification({
75 body : this.gitlive + "\nMonitoring " + this.monitors.length + " Directories",
79 notification.set_timeout(5);
89 * - pulls the items off the queue
90 * (as commands run concurrently and new items may get added while it's running)
91 * - runs the queue items
101 this.queueRunning = true;
103 this.queue.forEach(function (q) {
106 this.queue = []; // empty queue!
113 // first build a array of repo's to work with
118 //print(JSON.stringify(cmds));
120 cmds.forEach(function(cmd) {
121 var gitpath = cmd.shift();
122 if (typeof(repo_list[gitpath]) == 'undefined') {
123 repo_list[gitpath] = new imports.Scm.Git.Repo.Repo( { repopath : gitpath });
124 repo_list[gitpath].cmds = [];
125 repo_list[gitpath].pull();
127 repo_list[gitpath].cmds.push(cmd);
130 // build add, remove and commit message list..
134 for (var gitpath in repo_list) {
135 var repo = repo_list[gitpath];
137 var remove_files = [];
139 //print(JSON.stringify(repo.cmds,null,4));
141 repo.cmds.forEach(function(cmd) {
143 var name = cmd.shift();
144 var arg = cmd.shift();
149 if (add_files.indexOf(arg) > -1) {
153 // if file does not exist.. s,ip
155 //if (!GLib.file_test(arg, GLib.FileTest.EXISTS)) {
166 if (add_files.indexOf(arg) > -1) {
170 // if file exists, do not try and delete it.
171 if (GLib.file_test(arg, GLib.FileTest.EXISTS)) {
175 remove_files.push(arg);
180 if (messages.indexOf(arg.message) < 0) {
181 messages.push(arg.message);
188 // these can fail... at present... as we wildcard stuff.
189 print("ADD : " + JSON.stringify(add_files));
191 // make sure added files do not get removed..
192 remove_files = remove_files.filter(function(v) {
193 return add_files.indexOf(v) < 0;
195 print("REMOVE : " + JSON.stringify(remove_files));
198 // make sure monitoring is paused so it does not recursively pick up
205 repo.remove(remove_files);
210 success.push(repo.commit({
211 reason : messages.join("\n"),
214 success.push(repo.push());
217 failure.push(e.message);
222 // finally merge all the commit messages.
225 // catch notification failures.. so we can carry on..
226 if (success.length) {
227 print(success.join("\n"));
229 var notification = new Notify.Notification({
230 summary: "Git Live Commited",
231 body : success.join("\n"),
236 notification.set_timeout(5);
240 if (failure.length) {
242 var notification = new Notify.Notification({
243 summary: "Git Live ERROR!!",
244 body : failure.join("\n"),
249 notification.set_timeout(5); // show errros for longer
256 this.queueRunning = false;
259 shouldIgnore: function(f)
265 // vim.. what a seriously brain dead program..
266 if (f.name == '4913') {
270 if (f.name[0] == '.') {
272 if (f.name == '.htaccess') {
278 if (f.name.match(/~$/)) {
281 if (f.name.match(/^nbproject/)) {
284 // ignore anything in top level!!!!
285 if (!f.vpath.length) {
294 * Fill in gitlive, vpath and repo
297 parsePath: function(f)
300 var vpath_ar = f.path.substring(this.gitlive.length +1).split('/');
302 f.gitpath = this.gitlive + '/' + vpath_ar.shift();
303 f.vpath = vpath_ar.join('/');
304 //f.repo = new imports.Scm.Git.Repo({ repopath: f.gitpath })
311 onChanged : function(src)
313 return; // always ignore this..?
314 //this.parsePath(src);
321 * results in git add + git commit..
324 onChangesDoneHint : function(src)
326 this.lastAdd = new Date();
328 if (this.shouldIgnore(src)) {
334 if (typeof(this.just_created[src.path]) !='undefined') {
335 delete this.just_created[src.path];
338 [ src.gitpath, 'add', src.vpath ],
339 [ src.gitpath, 'commit', { message: src.vpath} ]
347 [ src.gitpath, 'add', src.vpath ],
348 [ src.gitpath, 'commit', { message: src.vpath} ]
353 onDeleted : function(src)
355 this.lastAdd = new Date();
357 if (this.shouldIgnore(src)) {
360 // should check if monitor needs removing..
361 // it should also check if it was a directory.. - so we dont have to commit all..
365 [ src.gitpath, 'rm' , src.vpath ],
366 [ src.gitpath, 'commit', { all: true, message: src.vpath} ]
372 onCreated : function(src)
374 this.lastAdd = new Date();
376 if (this.shouldIgnore(src)) {
380 if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
381 this.just_created[src.path] = true;
382 return; // we do not handle file create flags... - use done hint.
384 // director has bee created
385 this.monitor(src.path);
388 [ src.gitpath, 'add' , src.vpath, { all: true } ],
389 [ src.gitpath, 'commit' , { all: true, message: src.vpath} ]
395 onAttributeChanged : function(src)
397 this.lastAdd = new Date();
399 if (this.shouldIgnore(src)) {
405 //[ src.gitpath, 'commit' , src.vpath, { message: src.vpath} ]
406 [ src.gitpath, 'add' , src.vpath ],
407 [ src.gitpath, 'commit' , { message: "Attribute Changed :" + src.vpath} ]
413 onMoved : function(src,dest)
415 this.lastAdd = new Date();
417 this.parsePath(dest);
419 if (src.gitpath != dest.gitpath) {
421 this.onCreated(dest);
422 this.onChangedDoneHint(dest);
425 // needs to handle move to/from unsupported types..
427 if (this.shouldIgnore(src)) {
430 if (this.shouldIgnore(dest)) {
435 // [ src.gitpath, 'mv', '-k', src.vpath, dest.vpath ],
436 [ src.gitpath, 'add', dest.vpath ],
437 [ src.gitpath, 'rm', src.vpath ],
439 [ src.gitpath, 'commit' ,
440 { message: 'MOVED ' + src.vpath +' to ' + dest.vpath}