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..
48 imports.StatusIcon.StatusIcon.el.set_from_stock( Gtk.STOCK_REFRESH );
50 this.lastAdd = new Date();
52 this.top.forEach(this.monitor, this);
54 GLib.timeout_add(GLib.PRIORITY_LOW, 500, function() {
55 //TIMEOUT", _this.queue.length , _this.queueRunning].join(', '));
56 if (!_this.queue.length || _this.queueRunning) {
59 var last = Math.floor(((new Date()) - _this.lastAdd) / 100);
61 //print("LAST RUN?" + last);
63 if (last < 5) { // wait 1/2 a seconnd before running.
66 //_this.lastAdd = new Date();
74 var notification = new Notify.Notification({
76 body : this.gitlive + "\nMonitoring " + this.monitors.length + " Directories",
80 notification.set_timeout(5);
85 imports.StatusIcon.StatusIcon.el.set_from_stock( Gtk.STOCK_MEDIA_PLAY );
89 monitor : function(path, fn, depth)
91 depth = typeof(depth) == 'number' ? depth *1 : 0;
94 // if we are not at top level.. and there is a .git directory (it's a submodule .. ignore)
95 if (depth > 1 && GLib.file_test(path + '/.git' , GLib.FileTest.IS_DIR)) {
100 var repo = imports.Scm.Repo.Repo.get(path);
101 if (!repo || !repo.autocommit()) {
107 // check if the repo is to be monitored.
108 //print("PATH : " + path);
111 Monitor.prototype.monitor.call(this, path,fn, depth);
116 * - pulls the items off the queue
117 * (as commands run concurrently and new items may get added while it's running)
118 * - runs the queue items
128 this.queueRunning = true;
130 this.queue.forEach(function (q) {
133 this.queue = []; // empty queue!
140 // first build a array of repo's to work with
145 //print(JSON.stringify(cmds));
147 cmds.forEach(function(cmd) {
148 var gitpath = cmd.shift();
149 if (typeof(repo_list[gitpath]) == 'undefined') {
150 repo_list[gitpath] = new imports.Scm.Git.Repo.Repo( { repopath : gitpath });
151 repo_list[gitpath].cmds = [];
152 repo_list[gitpath].pull();
154 repo_list[gitpath].cmds.push(cmd);
157 // build add, remove and commit message list..
161 for (var gitpath in repo_list) {
162 var repo = repo_list[gitpath];
164 var remove_files = [];
166 //print(JSON.stringify(repo.cmds,null,4));
168 repo.cmds.forEach(function(cmd) {
170 var name = cmd.shift();
171 var arg = cmd.shift();
176 if (add_files.indexOf(arg) > -1) {
180 // if file does not exist.. s,ip
182 //if (!GLib.file_test(arg, GLib.FileTest.EXISTS)) {
193 if (add_files.indexOf(arg) > -1) {
197 // if file exists, do not try and delete it.
198 if (GLib.file_test(arg, GLib.FileTest.EXISTS)) {
202 remove_files.push(arg);
207 if (messages.indexOf(arg.message) < 0) {
208 messages.push(arg.message);
215 // these can fail... at present... as we wildcard stuff.
216 print("ADD : " + JSON.stringify(add_files));
218 // make sure added files do not get removed..
219 remove_files = remove_files.filter(function(v) {
220 return add_files.indexOf(v) < 0;
222 print("REMOVE : " + JSON.stringify(remove_files));
225 // make sure monitoring is paused so it does not recursively pick up
232 repo.remove(remove_files);
237 success.push(repo.commit({
238 reason : messages.join("\n"),
241 success.push(repo.push());
244 failure.push(e.message);
249 // finally merge all the commit messages.
252 // catch notification failures.. so we can carry on..
253 if (success.length) {
254 print(success.join("\n"));
256 var notification = new Notify.Notification({
257 summary: "Git Live Commited",
258 body : success.join("\n"),
263 notification.set_timeout(5);
267 if (failure.length) {
269 var notification = new Notify.Notification({
270 summary: "Git Live ERROR!!",
271 body : failure.join("\n"),
276 notification.set_timeout(5); // show errros for longer
283 this.queueRunning = false;
286 shouldIgnore: function(f)
294 // vim.. what a seriously brain dead program..
295 if (f.name == '4913') {
299 if (f.name[0] == '.') {
301 if (f.name == '.htaccess') {
307 if (f.name.match(/~$/)) {
310 if (f.name.match(/^nbproject/)) {
313 // ignore anything in top level!!!!
314 if (!f.vpath.length) {
323 * Fill in gitlive, vpath and repo
326 parsePath: function(f)
329 var vpath_ar = f.path.substring(this.gitlive.length +1).split('/');
331 f.gitpath = this.gitlive + '/' + vpath_ar.shift();
332 f.vpath = vpath_ar.join('/');
333 //f.repo = new imports.Scm.Git.Repo({ repopath: f.gitpath })
340 onChanged : function(src)
342 return; // always ignore this..?
343 //this.parsePath(src);
350 * results in git add + git commit..
353 onChangesDoneHint : function(src)
355 this.lastAdd = new Date();
357 if (this.shouldIgnore(src)) {
363 if (typeof(this.just_created[src.path]) !='undefined') {
364 delete this.just_created[src.path];
367 [ src.gitpath, 'add', src.vpath ],
368 [ src.gitpath, 'commit', { message: src.vpath} ]
376 [ src.gitpath, 'add', src.vpath ],
377 [ src.gitpath, 'commit', { message: src.vpath} ]
382 onDeleted : function(src)
384 this.lastAdd = new Date();
386 if (this.shouldIgnore(src)) {
389 // should check if monitor needs removing..
390 // it should also check if it was a directory.. - so we dont have to commit all..
394 [ src.gitpath, 'rm' , src.vpath ],
395 [ src.gitpath, 'commit', { all: true, message: src.vpath} ]
401 onCreated : function(src)
403 this.lastAdd = new Date();
405 if (this.shouldIgnore(src)) {
409 if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
410 this.just_created[src.path] = true;
411 return; // we do not handle file create flags... - use done hint.
413 // director has bee created
414 this.monitor(src.path);
417 [ src.gitpath, 'add' , src.vpath, { all: true } ],
418 [ src.gitpath, 'commit' , { all: true, message: src.vpath} ]
424 onAttributeChanged : function(src)
426 this.lastAdd = new Date();
428 if (this.shouldIgnore(src)) {
434 //[ src.gitpath, 'commit' , src.vpath, { message: src.vpath} ]
435 [ src.gitpath, 'add' , src.vpath ],
436 [ src.gitpath, 'commit' , { message: "Attribute Changed :" + src.vpath} ]
442 onMoved : function(src,dest)
444 this.lastAdd = new Date();
446 this.parsePath(dest);
448 if (src.gitpath != dest.gitpath) {
450 this.onCreated(dest);
451 this.onChangedDoneHint(dest);
454 // needs to handle move to/from unsupported types..
456 if (this.shouldIgnore(src)) {
459 if (this.shouldIgnore(dest)) {
464 // [ src.gitpath, 'mv', '-k', src.vpath, dest.vpath ],
465 [ src.gitpath, 'add', dest.vpath ],
466 [ src.gitpath, 'rm', src.vpath ],
468 [ src.gitpath, 'commit' ,
469 { message: 'MOVED ' + src.vpath +' to ' + dest.vpath}