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);
88 monitor : function(path, fn, depth)
92 Monitor.prototype.monitor.call(this, path,fn, depth);
97 * - pulls the items off the queue
98 * (as commands run concurrently and new items may get added while it's running)
99 * - runs the queue items
109 this.queueRunning = true;
111 this.queue.forEach(function (q) {
114 this.queue = []; // empty queue!
121 // first build a array of repo's to work with
126 //print(JSON.stringify(cmds));
128 cmds.forEach(function(cmd) {
129 var gitpath = cmd.shift();
130 if (typeof(repo_list[gitpath]) == 'undefined') {
131 repo_list[gitpath] = new imports.Scm.Git.Repo.Repo( { repopath : gitpath });
132 repo_list[gitpath].cmds = [];
133 repo_list[gitpath].pull();
135 repo_list[gitpath].cmds.push(cmd);
138 // build add, remove and commit message list..
142 for (var gitpath in repo_list) {
143 var repo = repo_list[gitpath];
145 var remove_files = [];
147 //print(JSON.stringify(repo.cmds,null,4));
149 repo.cmds.forEach(function(cmd) {
151 var name = cmd.shift();
152 var arg = cmd.shift();
157 if (add_files.indexOf(arg) > -1) {
161 // if file does not exist.. s,ip
163 //if (!GLib.file_test(arg, GLib.FileTest.EXISTS)) {
174 if (add_files.indexOf(arg) > -1) {
178 // if file exists, do not try and delete it.
179 if (GLib.file_test(arg, GLib.FileTest.EXISTS)) {
183 remove_files.push(arg);
188 if (messages.indexOf(arg.message) < 0) {
189 messages.push(arg.message);
196 // these can fail... at present... as we wildcard stuff.
197 print("ADD : " + JSON.stringify(add_files));
199 // make sure added files do not get removed..
200 remove_files = remove_files.filter(function(v) {
201 return add_files.indexOf(v) < 0;
203 print("REMOVE : " + JSON.stringify(remove_files));
206 // make sure monitoring is paused so it does not recursively pick up
213 repo.remove(remove_files);
218 success.push(repo.commit({
219 reason : messages.join("\n"),
222 success.push(repo.push());
225 failure.push(e.message);
230 // finally merge all the commit messages.
233 // catch notification failures.. so we can carry on..
234 if (success.length) {
235 print(success.join("\n"));
237 var notification = new Notify.Notification({
238 summary: "Git Live Commited",
239 body : success.join("\n"),
244 notification.set_timeout(5);
248 if (failure.length) {
250 var notification = new Notify.Notification({
251 summary: "Git Live ERROR!!",
252 body : failure.join("\n"),
257 notification.set_timeout(5); // show errros for longer
264 this.queueRunning = false;
267 shouldIgnore: function(f)
273 // vim.. what a seriously brain dead program..
274 if (f.name == '4913') {
278 if (f.name[0] == '.') {
280 if (f.name == '.htaccess') {
286 if (f.name.match(/~$/)) {
289 if (f.name.match(/^nbproject/)) {
292 // ignore anything in top level!!!!
293 if (!f.vpath.length) {
302 * Fill in gitlive, vpath and repo
305 parsePath: function(f)
308 var vpath_ar = f.path.substring(this.gitlive.length +1).split('/');
310 f.gitpath = this.gitlive + '/' + vpath_ar.shift();
311 f.vpath = vpath_ar.join('/');
312 //f.repo = new imports.Scm.Git.Repo({ repopath: f.gitpath })
319 onChanged : function(src)
321 return; // always ignore this..?
322 //this.parsePath(src);
329 * results in git add + git commit..
332 onChangesDoneHint : function(src)
334 this.lastAdd = new Date();
336 if (this.shouldIgnore(src)) {
342 if (typeof(this.just_created[src.path]) !='undefined') {
343 delete this.just_created[src.path];
346 [ src.gitpath, 'add', src.vpath ],
347 [ src.gitpath, 'commit', { message: src.vpath} ]
355 [ src.gitpath, 'add', src.vpath ],
356 [ src.gitpath, 'commit', { message: src.vpath} ]
361 onDeleted : function(src)
363 this.lastAdd = new Date();
365 if (this.shouldIgnore(src)) {
368 // should check if monitor needs removing..
369 // it should also check if it was a directory.. - so we dont have to commit all..
373 [ src.gitpath, 'rm' , src.vpath ],
374 [ src.gitpath, 'commit', { all: true, message: src.vpath} ]
380 onCreated : function(src)
382 this.lastAdd = new Date();
384 if (this.shouldIgnore(src)) {
388 if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
389 this.just_created[src.path] = true;
390 return; // we do not handle file create flags... - use done hint.
392 // director has bee created
393 this.monitor(src.path);
396 [ src.gitpath, 'add' , src.vpath, { all: true } ],
397 [ src.gitpath, 'commit' , { all: true, message: src.vpath} ]
403 onAttributeChanged : function(src)
405 this.lastAdd = new Date();
407 if (this.shouldIgnore(src)) {
413 //[ src.gitpath, 'commit' , src.vpath, { message: src.vpath} ]
414 [ src.gitpath, 'add' , src.vpath ],
415 [ src.gitpath, 'commit' , { message: "Attribute Changed :" + src.vpath} ]
421 onMoved : function(src,dest)
423 this.lastAdd = new Date();
425 this.parsePath(dest);
427 if (src.gitpath != dest.gitpath) {
429 this.onCreated(dest);
430 this.onChangedDoneHint(dest);
433 // needs to handle move to/from unsupported types..
435 if (this.shouldIgnore(src)) {
438 if (this.shouldIgnore(dest)) {
443 // [ src.gitpath, 'mv', '-k', src.vpath, dest.vpath ],
444 [ src.gitpath, 'add', dest.vpath ],
445 [ src.gitpath, 'rm', src.vpath ],
447 [ src.gitpath, 'commit' ,
448 { message: 'MOVED ' + src.vpath +' to ' + dest.vpath}