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."});
40 var monitor = new Monitor({
43 nqv : true, // temp var while I switch to queued version.
47 this.lastAdd = new Date();
49 Glib.idle_add(PRIORITY_LOW, function() {
50 if (!_this.queue.length) {
53 var last = Math.floor(((new Date()) - this.lastAdd) / 100);
54 if (last < 5) { // wait 1/2 a seconnd before running.
60 Monitor.prototype.start.call(this);
61 var notification = new Notify.Notification({
63 body : gitlive + "\nMonitoring " + this.monitors.length + " Directories"
66 notification.set_timeout(500);
76 cmd = array_shift(this.queue);
77 var sp = Git.run.call(cmd);
81 success.push(sp.args.join(' '));
82 success.push(sp.output);
85 failure.push(sp.args.join(' '));
86 failure.push(sp.output);
87 failure.push(sp.stderr);
92 if (!this.queue.length) {
99 var notification = new Notify.Notification({
100 summary: "Git Live Commited",
101 body : success.join("\n")
105 notification.set_timeout(500);
110 shouldIgnore: function(f)
112 if (f.name[0] == '.') {
114 if (f.name == '.htaccess') {
120 if (f.name.match(/~$/)) {
123 // ignore anything in top level!!!!
124 if (!f.vpath.length) {
132 parsePath: function(f) {
134 var vpath_ar = f.path.substring(gitlive.length +1).split('/');
136 f.gitpath = gitlive + '/' + vpath_ar.shift();
137 f.vpath = vpath_ar.join('/');
144 onChanged : function(src)
146 return; // always ignore this..?
147 //this.parsePath(src);
149 onChangesDoneHint : function(src)
152 if (this.shouldIgnore(src)) {
157 if (typeof(this.just_created[src.path]) !='undefined') {
158 delete this.just_created[src.path];
159 this.lastAdd = new Date();
161 [ src.gitpath, 'add', src.vpath ],
162 [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ],
163 [ src.gitpath , 'push', { all: true } ]
168 Git.run(src.gitpath, 'add', src.vpath);
169 var sp = Git.run(src.gitpath, 'commit', { all: true, message: src.vpath});
170 Git.run(src.gitpath , 'push', { all: true } );
171 notify(src.name,"CHANGED", sp);
175 this.lastAdd = new Date();
177 [ src.gitpath, 'add', src.vpath ],
178 [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ],
179 [ src.gitpath , 'push', { all: true } ]
183 var sp = Git.run(src.gitpath, 'commit', { all: true, message: src.vpath});
184 Git.run(src.gitpath , 'push', '--all' );
185 notify(src.name,"CHANGED", sp);
189 onDeleted : function(src)
192 if (this.shouldIgnore(src)) {
195 // should check if monitor needs removing..
196 // it should also check if it was a directory.. - so we dont have to commit all..
198 this.lastAdd = new Date();
200 [ src.gitpath, 'rm' , src.vpath ],
201 [ src.gitpath, 'commit', { all: true, message: src.vpath} ],
202 [ src.gitpath, 'push', { all: true } ]
208 var sp = Git.run(src.gitpath,'rm' , src.vpath);
209 Git.run(src.gitpath , 'push', { all: true } );
211 notify(src.name,"DELETED", sp);
214 sp = Git.run(src.gitpath,'commit' ,{ all: true, message: src.vpath});
215 Git.run(src.gitpath , 'push',{ all: true });
216 notify(src.name,"DELETED", sp);
220 onCreated : function(src)
223 if (this.shouldIgnore(src)) {
227 if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
228 this.just_created[src.path] = true;
229 return; // we do not handle file create flags... - use done hint.
231 // director has bee created
232 this.monitor(src.path);
233 this.lastAdd = new Date();
235 [ src.gitpath, 'add' , src.vpath, { all: true } ],
236 [ src.gitpath, 'commit' , { all: true, message: src.vpath} ],
237 [ src.gitpath, 'push', { all: true } ]
242 var sp = Git.run(src.gitpath, 'add', src.vpath);
243 Git.run(src.gitpath , 'push', { all: true } );
246 notify(src.path,"CREATED", sp);
249 //uh.call(fm,f,of, event_type);
250 sp = Git.run(src.gitpath,'commit' , { all: true, message: src.vpath});
251 Git.run(src.gitpath , 'push', { all: true } );
252 notify(src.path,"CREATED", sp);
256 onAttributeChanged : function(src) {
258 if (this.shouldIgnore(src)) {
261 this.lastAdd = new Date();
263 [ src.gitpath, 'commit' , src.vpath, { message: src.vpath} ],
264 [ src.gitpath, 'push', { all: true } ]
269 var sp = Git.run(src.gitpath, 'commit',{ all: true, message: src.vpath});
270 Git.run(src.gitpath , 'push', { all: true } );
271 notify(src.path,"ATTRIBUTE_CHANGED", sp);
276 onMoved : function(src,dest)
279 this.parsePath(dest);
281 if (src.gitpath != dest.gitpath) {
283 this.onCreated(dest);
284 this.onChangedDoneHint(dest);
287 // needs to handle move to/from unsupported types..
289 if (this.shouldIgnore(src)) {
292 if (this.shouldIgnore(dest)) {
295 this.lastAdd = new Date();
297 [ src.gitpath, 'mv', '-k', src.vpath, dest.vpath ],
298 [ src.gitpath, 'commit' , src.vpath, dest.vpath ,
299 { message: 'MOVED ' + src.vpath +' to ' + dest.vpath} ],
300 [ src.gitpath, 'push', { all: true } ]
307 var sp = Git.run(src.gitpath, 'mv', '-k', src.vpath, dest.vpath);
309 notify(dest.path,"MOVED", sp);
312 sp = Git.run(src.gitpath,'commit' , { all: true, message: 'MOVED ' + src.vpath +' to ' + dest.vpath} );
313 Git.run(src.gitpath , 'push', { all: true } );
314 notify(src.path,"MOVED", sp);
324 function notify(fn, act , sp)
326 var sum = act + " " + fn;
328 var notification = new Notify.Notification({
333 notification.set_timeout(500);
341 function errorDialog(data) {
342 var msg = new Gtk.MessageDialog({
343 message_type: Gtk.MessageType.ERROR,
344 buttons : Gtk.ButtonsType.OK,
356 // need a better icon...
359 Notify.init("gitlive");
360 monitor.add(GLib.get_home_dir() + "/gitlive");
363 //icon.signal["activate"].connect(on_left_click);