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 print(["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]) < -1) {
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 Git.run(r , 'push', { all: true } )
123 if (success.length) {
125 var notification = new Notify.Notification({
126 summary: "Git Live Commited",
127 body : success.join("\n")
131 notification.set_timeout(500);
134 if (success.length) {
136 var notification = new Notify.Notification({
137 summary: "Git Live ERROR!!",
138 body : failure.join("\n")
142 notification.set_timeout(500);
145 this.queueRunning = false;
148 shouldIgnore: function(f)
150 if (f.name[0] == '.') {
152 if (f.name == '.htaccess') {
158 if (f.name.match(/~$/)) {
161 // ignore anything in top level!!!!
162 if (!f.vpath.length) {
170 parsePath: function(f) {
172 var vpath_ar = f.path.substring(gitlive.length +1).split('/');
174 f.gitpath = gitlive + '/' + vpath_ar.shift();
175 f.vpath = vpath_ar.join('/');
182 onChanged : function(src)
184 return; // always ignore this..?
185 //this.parsePath(src);
187 onChangesDoneHint : function(src)
190 if (this.shouldIgnore(src)) {
195 if (typeof(this.just_created[src.path]) !='undefined') {
196 delete this.just_created[src.path];
197 this.lastAdd = new Date();
199 [ src.gitpath, 'add', src.vpath ],
200 [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ]
205 Git.run(src.gitpath, 'add', src.vpath);
206 var sp = Git.run(src.gitpath, 'commit', { all: true, message: src.vpath});
207 Git.run(src.gitpath , 'push', { all: true } );
208 notify(src.name,"CHANGED", sp);
212 this.lastAdd = new Date();
214 [ src.gitpath, 'add', src.vpath ],
215 [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ]
220 var sp = Git.run(src.gitpath, 'commit', { all: true, message: src.vpath});
221 Git.run(src.gitpath , 'push', '--all' );
222 notify(src.name,"CHANGED", sp);
226 onDeleted : function(src)
229 if (this.shouldIgnore(src)) {
232 // should check if monitor needs removing..
233 // it should also check if it was a directory.. - so we dont have to commit all..
235 this.lastAdd = new Date();
237 [ src.gitpath, 'rm' , src.vpath ],
238 [ src.gitpath, 'commit', { all: true, message: src.vpath} ]
245 var sp = Git.run(src.gitpath,'rm' , src.vpath);
246 Git.run(src.gitpath , 'push', { all: true } );
248 notify(src.name,"DELETED", sp);
251 sp = Git.run(src.gitpath,'commit' ,{ all: true, message: src.vpath});
252 Git.run(src.gitpath , 'push',{ all: true });
253 notify(src.name,"DELETED", sp);
257 onCreated : function(src)
260 if (this.shouldIgnore(src)) {
264 if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
265 this.just_created[src.path] = true;
266 return; // we do not handle file create flags... - use done hint.
268 // director has bee created
269 this.monitor(src.path);
270 this.lastAdd = new Date();
272 [ src.gitpath, 'add' , src.vpath, { all: true } ],
273 [ src.gitpath, 'commit' , { all: true, message: src.vpath} ]
279 var sp = Git.run(src.gitpath, 'add', src.vpath);
280 Git.run(src.gitpath , 'push', { all: true } );
283 notify(src.path,"CREATED", sp);
286 //uh.call(fm,f,of, event_type);
287 sp = Git.run(src.gitpath,'commit' , { all: true, message: src.vpath});
288 Git.run(src.gitpath , 'push', { all: true } );
289 notify(src.path,"CREATED", sp);
293 onAttributeChanged : function(src) {
295 if (this.shouldIgnore(src)) {
298 this.lastAdd = new Date();
300 [ src.gitpath, 'commit' , src.vpath, { message: src.vpath} ]
305 var sp = Git.run(src.gitpath, 'commit',{ all: true, message: src.vpath});
306 Git.run(src.gitpath , 'push', { all: true } );
307 notify(src.path,"ATTRIBUTE_CHANGED", sp);
312 onMoved : function(src,dest)
315 this.parsePath(dest);
317 if (src.gitpath != dest.gitpath) {
319 this.onCreated(dest);
320 this.onChangedDoneHint(dest);
323 // needs to handle move to/from unsupported types..
325 if (this.shouldIgnore(src)) {
328 if (this.shouldIgnore(dest)) {
331 this.lastAdd = new Date();
333 [ src.gitpath, 'mv', '-k', src.vpath, dest.vpath ],
334 [ src.gitpath, 'commit' , src.vpath, dest.vpath ,
335 { message: 'MOVED ' + src.vpath +' to ' + dest.vpath} ]
342 var sp = Git.run(src.gitpath, 'mv', '-k', src.vpath, dest.vpath);
344 notify(dest.path,"MOVED", sp);
347 sp = Git.run(src.gitpath,'commit' , { all: true, message: 'MOVED ' + src.vpath +' to ' + dest.vpath} );
348 Git.run(src.gitpath , 'push', { all: true } );
349 notify(src.path,"MOVED", sp);
359 function notify(fn, act , sp)
361 var sum = act + " " + fn;
363 var notification = new Notify.Notification({
368 notification.set_timeout(500);
376 function errorDialog(data) {
377 var msg = new Gtk.MessageDialog({
378 message_type: Gtk.MessageType.ERROR,
379 buttons : Gtk.ButtonsType.OK,
391 // need a better icon...
394 Notify.init("gitlive");
395 monitor.add(GLib.get_home_dir() + "/gitlive");
398 //icon.signal["activate"].connect(on_left_click);