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 GLib.timeout_add(GLib.PRIORITY_LOW, 500, function() {
53 _this.top.forEach(_this.monitor, _this);
54 imports.StatusIcon.StatusIcon.el.set_from_stock( Gtk.STOCK_MEDIA_PLAY );
58 GLib.timeout_add(GLib.PRIORITY_LOW, 1000, function() {
59 //TIMEOUT", _this.queue.length , _this.queueRunning].join(', '));
60 if (!_this.queue.length || _this.queueRunning) {
63 var last = Math.floor(((new Date()) - _this.lastAdd) / 100);
65 //print("LAST RUN?" + last);
67 if (last < 5) { // wait 1/2 a seconnd before running.
70 //_this.lastAdd = new Date();
78 var notification = new Notify.Notification({
80 body : this.gitlive + "\nMonitoring " + this.monitors.length + " Directories",
84 notification.set_timeout(5);
93 imports.StatusIcon.StatusIcon.el.set_from_stock( Gtk.STOCK_MEDIA_PAUSE );
94 Monitor.prototype.stop.call(this);
98 monitor : function(path, fn, depth)
100 depth = typeof(depth) == 'number' ? depth *1 : 0;
103 // if we are not at top level.. and there is a .git directory (it's a submodule .. ignore)
104 if (depth > 1 && GLib.file_test(path + '/.git' , GLib.FileTest.IS_DIR)) {
109 var repo = imports.Scm.Repo.Repo.get(path);
110 if (!repo || !repo.autocommit()) {
116 // check if the repo is to be monitored.
117 //print("PATH : " + path);
120 Monitor.prototype.monitor.call(this, path,fn, depth);
125 * - pulls the items off the queue
126 * (as commands run concurrently and new items may get added while it's running)
127 * - runs the queue items
137 this.queueRunning = true;
139 this.queue.forEach(function (q) {
142 this.queue = []; // empty queue!
149 // first build a array of repo's to work with
154 //print(JSON.stringify(cmds));
156 cmds.forEach(function(cmd) {
157 var gitpath = cmd.shift();
158 if (typeof(repo_list[gitpath]) == 'undefined') {
159 repo_list[gitpath] = new imports.Scm.Git.Repo.Repo( { repopath : gitpath });
160 repo_list[gitpath].cmds = [];
161 repo_list[gitpath].pull();
163 repo_list[gitpath].cmds.push(cmd);
166 // build add, remove and commit message list..
170 for (var gitpath in repo_list) {
171 var repo = repo_list[gitpath];
173 var remove_files = [];
175 //print(JSON.stringify(repo.cmds,null,4));
177 repo.cmds.forEach(function(cmd) {
179 var name = cmd.shift();
180 var arg = cmd.shift();
185 if (add_files.indexOf(arg) > -1) {
189 // if file does not exist.. s,ip
191 //if (!GLib.file_test(arg, GLib.FileTest.EXISTS)) {
202 if (add_files.indexOf(arg) > -1) {
206 // if file exists, do not try and delete it.
207 if (GLib.file_test(arg, GLib.FileTest.EXISTS)) {
211 remove_files.push(arg);
216 if (messages.indexOf(arg.message) < 0) {
217 messages.push(arg.message);
224 // these can fail... at present... as we wildcard stuff.
225 print("ADD : " + JSON.stringify(add_files));
227 // make sure added files do not get removed..
228 remove_files = remove_files.filter(function(v) {
229 return add_files.indexOf(v) < 0;
231 print("REMOVE : " + JSON.stringify(remove_files));
234 // make sure monitoring is paused so it does not recursively pick up
241 repo.remove(remove_files);
246 success.push(repo.commit({
247 reason : messages.join("\n"),
250 success.push(repo.push());
253 failure.push(e.message);
258 // finally merge all the commit messages.
261 // catch notification failures.. so we can carry on..
262 if (success.length) {
263 print(success.join("\n"));
265 var notification = new Notify.Notification({
266 summary: "Git Live Commited",
267 body : success.join("\n"),
272 notification.set_timeout(5);
276 if (failure.length) {
278 var notification = new Notify.Notification({
279 summary: "Git Live ERROR!!",
280 body : failure.join("\n"),
285 notification.set_timeout(5); // show errros for longer
292 this.queueRunning = false;
295 shouldIgnore: function(f)
303 // vim.. what a seriously brain dead program..
304 if (f.name == '4913') {
308 if (f.name[0] == '.') {
310 if (f.name == '.htaccess') {
316 if (f.name.match(/~$/)) {
319 if (f.name.match(/^nbproject/)) {
322 // ignore anything in top level!!!!
323 if (!f.vpath.length) {
332 * Fill in gitlive, vpath and repo
335 parsePath: function(f)
338 var vpath_ar = f.path.substring(this.gitlive.length +1).split('/');
340 f.gitpath = this.gitlive + '/' + vpath_ar.shift();
341 f.vpath = vpath_ar.join('/');
342 //f.repo = new imports.Scm.Git.Repo({ repopath: f.gitpath })
349 onChanged : function(src)
351 return; // always ignore this..?
352 //this.parsePath(src);
359 * results in git add + git commit..
362 onChangesDoneHint : function(src)
364 this.lastAdd = new Date();
366 if (this.shouldIgnore(src)) {
372 if (typeof(this.just_created[src.path]) !='undefined') {
373 delete this.just_created[src.path];
376 [ src.gitpath, 'add', src.vpath ],
377 [ src.gitpath, 'commit', { message: src.vpath} ]
385 [ src.gitpath, 'add', src.vpath ],
386 [ src.gitpath, 'commit', { message: src.vpath} ]
391 onDeleted : function(src)
393 this.lastAdd = new Date();
395 if (this.shouldIgnore(src)) {
398 // should check if monitor needs removing..
399 // it should also check if it was a directory.. - so we dont have to commit all..
403 [ src.gitpath, 'rm' , src.vpath ],
404 [ src.gitpath, 'commit', { all: true, message: src.vpath} ]
410 onCreated : function(src)
412 this.lastAdd = new Date();
414 if (this.shouldIgnore(src)) {
418 if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
419 this.just_created[src.path] = true;
420 return; // we do not handle file create flags... - use done hint.
422 // director has bee created
423 this.monitor(src.path);
426 [ src.gitpath, 'add' , src.vpath, { all: true } ],
427 [ src.gitpath, 'commit' , { all: true, message: src.vpath} ]
433 onAttributeChanged : function(src)
435 this.lastAdd = new Date();
437 if (this.shouldIgnore(src)) {
443 //[ src.gitpath, 'commit' , src.vpath, { message: src.vpath} ]
444 [ src.gitpath, 'add' , src.vpath ],
445 [ src.gitpath, 'commit' , { message: "Attribute Changed :" + src.vpath} ]
451 onMoved : function(src,dest)
453 this.lastAdd = new Date();
455 this.parsePath(dest);
457 if (src.gitpath != dest.gitpath) {
459 this.onCreated(dest);
460 this.onChangedDoneHint(dest);
463 // needs to handle move to/from unsupported types..
465 if (this.shouldIgnore(src)) {
468 if (this.shouldIgnore(dest)) {
473 // [ src.gitpath, 'mv', '-k', src.vpath, dest.vpath ],
474 [ src.gitpath, 'add', dest.vpath ],
475 [ src.gitpath, 'rm', src.vpath ],
477 [ src.gitpath, 'commit' ,
478 { message: 'MOVED ' + src.vpath +' to ' + dest.vpath}