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();
136 if (add_files.indexOf(arg) > -1) {
140 // if file does not exist.. s,ip
141 if (!GLib.file_test(arg, GLib.FileTest.EXISTS)) {
150 // if file exists, do not try and delete it.
151 if (GLib.file_test(arg, GLib.FileTest.EXISTS)) {
155 remove_files.push(arg);
161 messages.push(arg.message);
166 // these can fail... at present... as we wildcard stuff.
167 print("ADD : " + JSON.stringify(add_files));
169 // make sure added files do not get removed..
170 remove_files = remove_files.filter(function(v) {
171 return add_files.indexOf(v) < 0;
173 print("REMOVE : " + JSON.stringify(remove_files));
177 repo.remove(remove_files);
180 success.push(repo.commit({
181 reason : messages.join("\n"),
184 success.push(repo.push());
187 failure.push(e.message);
192 // finally merge all the commit messages.
195 // catch notification failures.. so we can carry on..
196 if (success.length) {
197 print(success.join("\n"));
199 var notification = new Notify.Notification({
200 summary: "Git Live Commited",
201 body : success.join("\n"),
206 notification.set_timeout(5);
210 if (failure.length) {
212 var notification = new Notify.Notification({
213 summary: "Git Live ERROR!!",
214 body : failure.join("\n"),
219 notification.set_timeout(5); // show errros for longer
226 this.queueRunning = false;
229 shouldIgnore: function(f)
235 // vim.. what a seriously brain dead program..
236 if (f.name == '4913') {
240 if (f.name[0] == '.') {
242 if (f.name == '.htaccess') {
248 if (f.name.match(/~$/)) {
251 // ignore anything in top level!!!!
252 if (!f.vpath.length) {
261 * Fill in gitlive, vpath and repo
264 parsePath: function(f)
267 var vpath_ar = f.path.substring(this.gitlive.length +1).split('/');
269 f.gitpath = this.gitlive + '/' + vpath_ar.shift();
270 f.vpath = vpath_ar.join('/');
271 //f.repo = new imports.Scm.Git.Repo({ repopath: f.gitpath })
278 onChanged : function(src)
280 return; // always ignore this..?
281 //this.parsePath(src);
288 * results in git add + git commit..
291 onChangesDoneHint : function(src)
294 if (this.shouldIgnore(src)) {
300 if (typeof(this.just_created[src.path]) !='undefined') {
301 delete this.just_created[src.path];
302 this.lastAdd = new Date();
304 [ src.gitpath, 'add', src.vpath ],
305 [ src.gitpath, 'commit', { message: src.vpath} ]
311 this.lastAdd = new Date();
313 [ src.gitpath, 'add', src.vpath ],
314 [ src.gitpath, 'commit', { message: src.vpath} ]
319 onDeleted : function(src)
322 if (this.shouldIgnore(src)) {
325 // should check if monitor needs removing..
326 // it should also check if it was a directory.. - so we dont have to commit all..
328 this.lastAdd = new Date();
330 [ src.gitpath, 'rm' , src.vpath ],
331 [ src.gitpath, 'commit', { all: true, message: src.vpath} ]
337 onCreated : function(src)
340 if (this.shouldIgnore(src)) {
344 if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
345 this.just_created[src.path] = true;
346 return; // we do not handle file create flags... - use done hint.
348 // director has bee created
349 this.monitor(src.path);
350 this.lastAdd = new Date();
352 [ src.gitpath, 'add' , src.vpath, { all: true } ],
353 [ src.gitpath, 'commit' , { all: true, message: src.vpath} ]
359 onAttributeChanged : function(src) {
361 if (this.shouldIgnore(src)) {
364 this.lastAdd = new Date();
367 //[ src.gitpath, 'commit' , src.vpath, { message: src.vpath} ]
368 [ src.gitpath, 'add' , src.vpath ],
369 [ src.gitpath, 'commit' , { message: "Attribute Changed :" + src.vpath} ]
375 onMoved : function(src,dest)
378 this.parsePath(dest);
380 if (src.gitpath != dest.gitpath) {
382 this.onCreated(dest);
383 this.onChangedDoneHint(dest);
386 // needs to handle move to/from unsupported types..
388 if (this.shouldIgnore(src)) {
391 if (this.shouldIgnore(dest)) {
394 this.lastAdd = new Date();
396 // [ src.gitpath, 'mv', '-k', src.vpath, dest.vpath ],
397 [ src.gitpath, 'add', dest.vpath ],
398 [ src.gitpath, 'rm', src.vpath ],
400 [ src.gitpath, 'commit' ,
401 { message: 'MOVED ' + src.vpath +' to ' + dest.vpath}