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);
55 if (last < 4) { // wait 1/2 a seconnd before running.
63 var notification = new Notify.Notification({
65 body : this.gitlive + "\nMonitoring " + this.monitors.length + " Directories",
69 notification.set_timeout(5);
79 * - pulls the items off the queue
80 * (as commands run concurrently and new items may get added while it's running)
81 * - runs the queue items
91 this.queueRunning = true;
93 this.queue.forEach(function (q) {
96 this.queue = []; // empty queue!
103 // first build a array of repo's to work with
108 //print(JSON.stringify(cmds));
110 cmds.forEach(function(cmd) {
111 var gitpath = cmd.shift();
112 if (typeof(repo_list[gitpath]) == 'undefined') {
113 repo_list[gitpath] = new imports.Scm.Git.Repo.Repo( { repopath : gitpath });
114 repo_list[gitpath].cmds = [];
115 repo_list[gitpath].pull();
117 repo_list[gitpath].cmds.push(cmd);
120 // build add, remove and commit message list..
123 for (var gitpath in repo_list) {
124 var repo = repo_list[gitpath];
126 var remove_files = [];
128 repo.cmds.forEach(function(cmd) {
129 //print(JSON.stringify(cmd));
130 var name = cmd.shift();
131 var arg = cmd.shift();
135 if (add_files.indexOf(arg) > -1) break;
140 remove_files.push(arg);
144 messages.push(arg.message);
149 // these can fail... at present... as we wildcard stuff.
151 repo.remove(remove_files);
154 success.push(repo.commit({
155 reason : messages.join("\n"),
158 success.push(repo.push());
161 failure.push(e.message);
166 // finally merge all the commit messages.
169 // catch notification failures.. so we can carry on..
170 if (success.length) {
171 print(success.join("\n"));
173 var notification = new Notify.Notification({
174 summary: "Git Live Commited",
175 body : success.join("\n"),
180 notification.set_timeout(5);
184 if (failure.length) {
186 var notification = new Notify.Notification({
187 summary: "Git Live ERROR!!",
188 body : failure.join("\n"),
193 notification.set_timeout(5); // show errros for longer
200 this.queueRunning = false;
203 shouldIgnore: function(f)
209 if (f.name[0] == '.') {
211 if (f.name == '.htaccess') {
217 if (f.name.match(/~$/)) {
220 // ignore anything in top level!!!!
221 if (!f.vpath.length) {
230 * Fill in gitlive, vpath and repo
233 parsePath: function(f)
236 var vpath_ar = f.path.substring(this.gitlive.length +1).split('/');
238 f.gitpath = this.gitlive + '/' + vpath_ar.shift();
239 f.vpath = vpath_ar.join('/');
240 //f.repo = new imports.Scm.Git.Repo({ repopath: f.gitpath })
247 onChanged : function(src)
249 return; // always ignore this..?
250 //this.parsePath(src);
257 * results in git add + git commit..
260 onChangesDoneHint : function(src)
263 if (this.shouldIgnore(src)) {
269 if (typeof(this.just_created[src.path]) !='undefined') {
270 delete this.just_created[src.path];
271 this.lastAdd = new Date();
273 [ src.gitpath, 'add', src.vpath ],
274 [ src.gitpath, 'commit', { message: src.vpath} ]
280 this.lastAdd = new Date();
282 [ src.gitpath, 'add', src.vpath ],
283 [ src.gitpath, 'commit', { message: src.vpath} ]
288 onDeleted : function(src)
291 if (this.shouldIgnore(src)) {
294 // should check if monitor needs removing..
295 // it should also check if it was a directory.. - so we dont have to commit all..
297 this.lastAdd = new Date();
299 [ src.gitpath, 'rm' , src.vpath ],
300 [ src.gitpath, 'commit', { all: true, message: src.vpath} ]
306 onCreated : function(src)
309 if (this.shouldIgnore(src)) {
313 if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
314 this.just_created[src.path] = true;
315 return; // we do not handle file create flags... - use done hint.
317 // director has bee created
318 this.monitor(src.path);
319 this.lastAdd = new Date();
321 [ src.gitpath, 'add' , src.vpath, { all: true } ],
322 [ src.gitpath, 'commit' , { all: true, message: src.vpath} ]
328 onAttributeChanged : function(src) {
330 if (this.shouldIgnore(src)) {
333 this.lastAdd = new Date();
336 //[ src.gitpath, 'commit' , src.vpath, { message: src.vpath} ]
337 [ src.gitpath, 'add' , src.vpath ],
338 [ src.gitpath, 'commit' , { message: "Attribute Changed :" + src.vpath} ]
344 onMoved : function(src,dest)
347 this.parsePath(dest);
349 if (src.gitpath != dest.gitpath) {
351 this.onCreated(dest);
352 this.onChangedDoneHint(dest);
355 // needs to handle move to/from unsupported types..
357 if (this.shouldIgnore(src)) {
360 if (this.shouldIgnore(dest)) {
363 this.lastAdd = new Date();
365 // [ src.gitpath, 'mv', '-k', src.vpath, dest.vpath ],
366 [ src.gitpath, 'add', dest.vpath ],
367 [ src.gitpath, 'rm', src.vpath ],
369 [ src.gitpath, 'commit' ,
370 { message: 'MOVED ' + src.vpath +' to ' + dest.vpath}