2 ///<script type="text/javascript">
6 * inotify hooks for ~/gitlive
7 * that commit and push any changes made.
8 * Bit like a revision controled backed up file system!?
12 GI = imports.gi.GIRepository;
14 GLib = imports.gi.GLib;
16 Notify = imports.gi.Notify;
18 Spawn = imports.Spawn;
20 StatusIcon = imports.StatusIcon.StatusIcon;
21 Monitor = imports.Monitor.Monitor;
24 //File = imports[__script_path__+'/../introspection-doc-generator/File.js'].File
25 Gtk.init (null, null);
27 var gitlive = GLib.get_home_dir() + "/gitlive";
29 if (!GLib.file_test(gitlive, GLib.FileTest.IS_DIR)) {
30 var msg = new Gtk.MessageDialog({message_type:
31 Gtk.MessageType.INFO, buttons : Gtk.ButtonsType.OK, text: "GIT Live - ~/gitlive does not exist."});
39 var monitor = new Monitor({
43 nqv : false, // temp var while I switch to queued version.
47 this.lastAdd = new Date();
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.
62 Monitor.prototype.start.call(this);
63 var notification = new Notify.Notification({
65 body : gitlive + "\nMonitoring " + this.monitors.length + " Directories"
68 notification.set_timeout(500);
74 * - pulls the items off the queue
75 * (as commands run concurrently and new items may get added while it's running)
76 * - runs the queue items
82 this.queueRunning = true;
84 this.queue.forEach(function (q) {
87 this.queue = []; // empty queue!
92 cmds.forEach(function(cmd) {
93 if (repos.indexOf(cmd[0]) < 0) {
96 var sp = Git.run.apply(Git,cmd);
98 success.push([cmd[1],cmd[2]].join(' '));
106 success.push(sp.args.join(' '));
107 success.push(sp.output);
110 failure.push(sp.args.join(' '));
111 failure.push(sp.output);
112 failure.push(sp.stderr);
119 repos.forEach(function(r) {
120 var sp = Git.run(r , 'push', { all: true } );
127 if (success.length) {
129 var notification = new Notify.Notification({
130 summary: "Git Live Commited",
131 body : success.join("\n")
135 notification.set_timeout(500);
138 if (failure.length) {
140 var notification = new Notify.Notification({
141 summary: "Git Live ERROR!!",
142 body : failure.join("\n")
146 notification.set_timeout(500);
149 this.queueRunning = false;
152 shouldIgnore: function(f)
154 if (f.name[0] == '.') {
156 if (f.name == '.htaccess') {
162 if (f.name.match(/~$/)) {
165 // ignore anything in top level!!!!
166 if (!f.vpath.length) {
174 parsePath: function(f) {
176 var vpath_ar = f.path.substring(gitlive.length +1).split('/');
178 f.gitpath = gitlive + '/' + vpath_ar.shift();
179 f.vpath = vpath_ar.join('/');
186 onChanged : function(src)
188 return; // always ignore this..?
189 //this.parsePath(src);
191 onChangesDoneHint : function(src)
194 if (this.shouldIgnore(src)) {
199 if (typeof(this.just_created[src.path]) !='undefined') {
200 delete this.just_created[src.path];
201 this.lastAdd = new Date();
203 [ src.gitpath, 'add', src.vpath ],
204 [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ]
209 Git.run(src.gitpath, 'add', src.vpath);
210 var sp = Git.run(src.gitpath, 'commit', { all: true, message: src.vpath});
211 Git.run(src.gitpath , 'push', { all: true } );
212 notify(src.name,"CHANGED", sp);
216 this.lastAdd = new Date();
218 [ src.gitpath, 'add', src.vpath ],
219 [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ]
224 var sp = Git.run(src.gitpath, 'commit', { all: true, message: src.vpath});
225 Git.run(src.gitpath , 'push', '--all' );
226 notify(src.name,"CHANGED", sp);
230 onDeleted : function(src)
233 if (this.shouldIgnore(src)) {
236 // should check if monitor needs removing..
237 // it should also check if it was a directory.. - so we dont have to commit all..
239 this.lastAdd = new Date();
241 [ src.gitpath, 'rm' , src.vpath ],
242 [ src.gitpath, 'commit', { all: true, message: src.vpath} ]
249 var sp = Git.run(src.gitpath,'rm' , src.vpath);
250 Git.run(src.gitpath , 'push', { all: true } );
252 notify(src.name,"DELETED", sp);
255 sp = Git.run(src.gitpath,'commit' ,{ all: true, message: src.vpath});
256 Git.run(src.gitpath , 'push',{ all: true });
257 notify(src.name,"DELETED", sp);
261 onCreated : function(src)
264 if (this.shouldIgnore(src)) {
268 if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
269 this.just_created[src.path] = true;
270 return; // we do not handle file create flags... - use done hint.
272 // director has bee created
273 this.monitor(src.path);
274 this.lastAdd = new Date();
276 [ src.gitpath, 'add' , src.vpath, { all: true } ],
277 [ src.gitpath, 'commit' , { all: true, message: src.vpath} ]
283 var sp = Git.run(src.gitpath, 'add', src.vpath);
284 Git.run(src.gitpath , 'push', { all: true } );
287 notify(src.path,"CREATED", sp);
290 //uh.call(fm,f,of, event_type);
291 sp = Git.run(src.gitpath,'commit' , { all: true, message: src.vpath});
292 Git.run(src.gitpath , 'push', { all: true } );
293 notify(src.path,"CREATED", sp);
297 onAttributeChanged : function(src) {
299 if (this.shouldIgnore(src)) {
302 this.lastAdd = new Date();
304 [ src.gitpath, 'commit' , src.vpath, { message: src.vpath} ]
309 var sp = Git.run(src.gitpath, 'commit',{ all: true, message: src.vpath});
310 Git.run(src.gitpath , 'push', { all: true } );
311 notify(src.path,"ATTRIBUTE_CHANGED", sp);
316 onMoved : function(src,dest)
319 this.parsePath(dest);
321 if (src.gitpath != dest.gitpath) {
323 this.onCreated(dest);
324 this.onChangedDoneHint(dest);
327 // needs to handle move to/from unsupported types..
329 if (this.shouldIgnore(src)) {
332 if (this.shouldIgnore(dest)) {
335 this.lastAdd = new Date();
337 [ src.gitpath, 'mv', '-k', src.vpath, dest.vpath ],
338 [ src.gitpath, 'commit' , src.vpath, dest.vpath ,
339 { message: 'MOVED ' + src.vpath +' to ' + dest.vpath} ]
346 var sp = Git.run(src.gitpath, 'mv', '-k', src.vpath, dest.vpath);
348 notify(dest.path,"MOVED", sp);
351 sp = Git.run(src.gitpath,'commit' , { all: true, message: 'MOVED ' + src.vpath +' to ' + dest.vpath} );
352 Git.run(src.gitpath , 'push', { all: true } );
353 notify(src.path,"MOVED", sp);
363 function notify(fn, act , sp)
365 var sum = act + " " + fn;
367 var notification = new Notify.Notification({
372 notification.set_timeout(500);
380 function errorDialog(data) {
381 var msg = new Gtk.MessageDialog({
382 message_type: Gtk.MessageType.ERROR,
383 buttons : Gtk.ButtonsType.OK,
395 // need a better icon...
398 Notify.init("gitlive");
399 monitor.add(GLib.get_home_dir() + "/gitlive");
402 //icon.signal["activate"].connect(on_left_click);