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 );
45 this.lastAdd = new Date();
47 this.top.forEach(this.monitor, this);
49 GLib.timeout_add(GLib.PRIORITY_LOW, 500, function() {
50 //TIMEOUT", _this.queue.length , _this.queueRunning].join(', '));
51 if (!_this.queue.length || _this.queueRunning) {
54 var last = Math.floor(((new Date()) - _this.lastAdd) / 100);
56 //print("LAST RUN?" + last);
58 if (last < 15) { // wait 1/2 a seconnd before running.
61 //_this.lastAdd = new Date();
69 var notification = new Notify.Notification({
71 body : this.gitlive + "\nMonitoring " + this.monitors.length + " Directories",
75 notification.set_timeout(5);
85 * - pulls the items off the queue
86 * (as commands run concurrently and new items may get added while it's running)
87 * - runs the queue items
97 this.queueRunning = true;
99 this.queue.forEach(function (q) {
102 this.queue = []; // empty queue!
109 // first build a array of repo's to work with
114 //print(JSON.stringify(cmds));
116 cmds.forEach(function(cmd) {
117 var gitpath = cmd.shift();
118 if (typeof(repo_list[gitpath]) == 'undefined') {
119 repo_list[gitpath] = new imports.Scm.Git.Repo.Repo( { repopath : gitpath });
120 repo_list[gitpath].cmds = [];
121 repo_list[gitpath].pull();
123 repo_list[gitpath].cmds.push(cmd);
126 // build add, remove and commit message list..
130 for (var gitpath in repo_list) {
131 var repo = repo_list[gitpath];
133 var remove_files = [];
135 //print(JSON.stringify(repo.cmds,null,4));
137 repo.cmds.forEach(function(cmd) {
139 var name = cmd.shift();
140 var arg = cmd.shift();
145 if (add_files.indexOf(arg) > -1) {
149 // if file does not exist.. s,ip
151 //if (!GLib.file_test(arg, GLib.FileTest.EXISTS)) {
162 if (add_files.indexOf(arg) > -1) {
166 // if file exists, do not try and delete it.
167 if (GLib.file_test(arg, GLib.FileTest.EXISTS)) {
171 remove_files.push(arg);
176 if (messages.indexOf(arg.message) < 0) {
177 messages.push(arg.message);
184 // these can fail... at present... as we wildcard stuff.
185 print("ADD : " + JSON.stringify(add_files));
187 // make sure added files do not get removed..
188 remove_files = remove_files.filter(function(v) {
189 return add_files.indexOf(v) < 0;
191 print("REMOVE : " + JSON.stringify(remove_files));
194 // make sure monitoring is paused so it does not recursively pick up
201 repo.remove(remove_files);
206 success.push(repo.commit({
207 reason : messages.join("\n"),
210 success.push(repo.push());
213 failure.push(e.message);
218 // finally merge all the commit messages.
221 // catch notification failures.. so we can carry on..
222 if (success.length) {
223 print(success.join("\n"));
225 var notification = new Notify.Notification({
226 summary: "Git Live Commited",
227 body : success.join("\n"),
232 notification.set_timeout(5);
236 if (failure.length) {
238 var notification = new Notify.Notification({
239 summary: "Git Live ERROR!!",
240 body : failure.join("\n"),
245 notification.set_timeout(5); // show errros for longer
252 this.queueRunning = false;
255 shouldIgnore: function(f)
261 // vim.. what a seriously brain dead program..
262 if (f.name == '4913') {
266 if (f.name[0] == '.') {
268 if (f.name == '.htaccess') {
274 if (f.name.match(/~$/)) {
277 // ignore anything in top level!!!!
278 if (!f.vpath.length) {
287 * Fill in gitlive, vpath and repo
290 parsePath: function(f)
293 var vpath_ar = f.path.substring(this.gitlive.length +1).split('/');
295 f.gitpath = this.gitlive + '/' + vpath_ar.shift();
296 f.vpath = vpath_ar.join('/');
297 //f.repo = new imports.Scm.Git.Repo({ repopath: f.gitpath })
304 onChanged : function(src)
306 return; // always ignore this..?
307 //this.parsePath(src);
314 * results in git add + git commit..
317 onChangesDoneHint : function(src)
319 this.lastAdd = new Date();
321 if (this.shouldIgnore(src)) {
327 if (typeof(this.just_created[src.path]) !='undefined') {
328 delete this.just_created[src.path];
331 [ src.gitpath, 'add', src.vpath ],
332 [ src.gitpath, 'commit', { message: src.vpath} ]
340 [ src.gitpath, 'add', src.vpath ],
341 [ src.gitpath, 'commit', { message: src.vpath} ]
346 onDeleted : function(src)
348 this.lastAdd = new Date();
350 if (this.shouldIgnore(src)) {
353 // should check if monitor needs removing..
354 // it should also check if it was a directory.. - so we dont have to commit all..
358 [ src.gitpath, 'rm' , src.vpath ],
359 [ src.gitpath, 'commit', { all: true, message: src.vpath} ]
365 onCreated : function(src)
367 this.lastAdd = new Date();
369 if (this.shouldIgnore(src)) {
373 if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
374 this.just_created[src.path] = true;
375 return; // we do not handle file create flags... - use done hint.
377 // director has bee created
378 this.monitor(src.path);
381 [ src.gitpath, 'add' , src.vpath, { all: true } ],
382 [ src.gitpath, 'commit' , { all: true, message: src.vpath} ]
388 onAttributeChanged : function(src)
390 this.lastAdd = new Date();
392 if (this.shouldIgnore(src)) {
398 //[ src.gitpath, 'commit' , src.vpath, { message: src.vpath} ]
399 [ src.gitpath, 'add' , src.vpath ],
400 [ src.gitpath, 'commit' , { message: "Attribute Changed :" + src.vpath} ]
406 onMoved : function(src,dest)
408 this.lastAdd = new Date();
410 this.parsePath(dest);
412 if (src.gitpath != dest.gitpath) {
414 this.onCreated(dest);
415 this.onChangedDoneHint(dest);
418 // needs to handle move to/from unsupported types..
420 if (this.shouldIgnore(src)) {
423 if (this.shouldIgnore(dest)) {
428 // [ src.gitpath, 'mv', '-k', src.vpath, dest.vpath ],
429 [ src.gitpath, 'add', dest.vpath ],
430 [ src.gitpath, 'rm', src.vpath ],
432 [ src.gitpath, 'commit' ,
433 { message: 'MOVED ' + src.vpath +' to ' + dest.vpath}