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(' '));
105 success.push(sp.args.join(' '));
106 success.push(sp.output);
109 failure.push(sp.args.join(' '));
110 failure.push(sp.output);
111 failure.push(sp.stderr);
117 repos.forEach(function(r) {
118 var sp = Git.run(r , 'push', { all: true } );
125 if (success.length) {
127 var notification = new Notify.Notification({
128 summary: "Git Live Commited",
129 body : success.join("\n")
133 notification.set_timeout(500);
136 if (failure.length) {
138 var notification = new Notify.Notification({
139 summary: "Git Live ERROR!!",
140 body : failure.join("\n")
144 notification.set_timeout(500);
147 this.queueRunning = false;
150 shouldIgnore: function(f)
152 if (f.name[0] == '.') {
154 if (f.name == '.htaccess') {
160 if (f.name.match(/~$/)) {
163 // ignore anything in top level!!!!
164 if (!f.vpath.length) {
172 parsePath: function(f) {
174 var vpath_ar = f.path.substring(gitlive.length +1).split('/');
176 f.gitpath = gitlive + '/' + vpath_ar.shift();
177 f.vpath = vpath_ar.join('/');
184 onChanged : function(src)
186 return; // always ignore this..?
187 //this.parsePath(src);
189 onChangesDoneHint : function(src)
192 if (this.shouldIgnore(src)) {
197 if (typeof(this.just_created[src.path]) !='undefined') {
198 delete this.just_created[src.path];
199 this.lastAdd = new Date();
201 [ src.gitpath, 'add', src.vpath ],
202 [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ]
207 Git.run(src.gitpath, 'add', src.vpath);
208 var sp = Git.run(src.gitpath, 'commit', { all: true, message: src.vpath});
209 Git.run(src.gitpath , 'push', { all: true } );
210 notify(src.name,"CHANGED", sp);
214 this.lastAdd = new Date();
216 [ src.gitpath, 'add', src.vpath ],
217 [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ]
222 var sp = Git.run(src.gitpath, 'commit', { all: true, message: src.vpath});
223 Git.run(src.gitpath , 'push', '--all' );
224 notify(src.name,"CHANGED", sp);
228 onDeleted : function(src)
231 if (this.shouldIgnore(src)) {
234 // should check if monitor needs removing..
235 // it should also check if it was a directory.. - so we dont have to commit all..
237 this.lastAdd = new Date();
239 [ src.gitpath, 'rm' , src.vpath ],
240 [ src.gitpath, 'commit', { all: true, message: src.vpath} ]
247 var sp = Git.run(src.gitpath,'rm' , src.vpath);
248 Git.run(src.gitpath , 'push', { all: true } );
250 notify(src.name,"DELETED", sp);
253 sp = Git.run(src.gitpath,'commit' ,{ all: true, message: src.vpath});
254 Git.run(src.gitpath , 'push',{ all: true });
255 notify(src.name,"DELETED", sp);
259 onCreated : function(src)
262 if (this.shouldIgnore(src)) {
266 if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
267 this.just_created[src.path] = true;
268 return; // we do not handle file create flags... - use done hint.
270 // director has bee created
271 this.monitor(src.path);
272 this.lastAdd = new Date();
274 [ src.gitpath, 'add' , src.vpath, { all: true } ],
275 [ src.gitpath, 'commit' , { all: true, message: src.vpath} ]
281 var sp = Git.run(src.gitpath, 'add', src.vpath);
282 Git.run(src.gitpath , 'push', { all: true } );
285 notify(src.path,"CREATED", sp);
288 //uh.call(fm,f,of, event_type);
289 sp = Git.run(src.gitpath,'commit' , { all: true, message: src.vpath});
290 Git.run(src.gitpath , 'push', { all: true } );
291 notify(src.path,"CREATED", sp);
295 onAttributeChanged : function(src) {
297 if (this.shouldIgnore(src)) {
300 this.lastAdd = new Date();
302 [ src.gitpath, 'commit' , src.vpath, { message: src.vpath} ]
307 var sp = Git.run(src.gitpath, 'commit',{ all: true, message: src.vpath});
308 Git.run(src.gitpath , 'push', { all: true } );
309 notify(src.path,"ATTRIBUTE_CHANGED", sp);
314 onMoved : function(src,dest)
317 this.parsePath(dest);
319 if (src.gitpath != dest.gitpath) {
321 this.onCreated(dest);
322 this.onChangedDoneHint(dest);
325 // needs to handle move to/from unsupported types..
327 if (this.shouldIgnore(src)) {
330 if (this.shouldIgnore(dest)) {
333 this.lastAdd = new Date();
335 [ src.gitpath, 'mv', '-k', src.vpath, dest.vpath ],
336 [ src.gitpath, 'commit' , src.vpath, dest.vpath ,
337 { message: 'MOVED ' + src.vpath +' to ' + dest.vpath} ]
344 var sp = Git.run(src.gitpath, 'mv', '-k', src.vpath, dest.vpath);
346 notify(dest.path,"MOVED", sp);
349 sp = Git.run(src.gitpath,'commit' , { all: true, message: 'MOVED ' + src.vpath +' to ' + dest.vpath} );
350 Git.run(src.gitpath , 'push', { all: true } );
351 notify(src.path,"MOVED", sp);
361 function notify(fn, act , sp)
363 var sum = act + " " + fn;
365 var notification = new Notify.Notification({
370 notification.set_timeout(500);
378 function errorDialog(data) {
379 var msg = new Gtk.MessageDialog({
380 message_type: Gtk.MessageType.ERROR,
381 buttons : Gtk.ButtonsType.OK,
393 // need a better icon...
396 Notify.init("gitlive");
397 monitor.add(GLib.get_home_dir() + "/gitlive");
400 //icon.signal["activate"].connect(on_left_click);