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!?
13 GI = imports.gi.GIRepository
14 GLib = imports.gi.GLib;
16 // we add this in, as it appears to get lost sometimes if we set it using the ENV. variable in builder.sh
17 GI.IRepository.prepend_search_path(GLib.get_home_dir() + '/.Builder/girepository-1.1');
21 Notify = imports.gi.Notify;
23 Spawn = imports.Spawn;
25 StatusIcon = imports.StatusIcon.StatusIcon;
26 Monitor = imports.Monitor.Monitor;
29 //File = imports[__script_path__+'/../introspection-doc-generator/File.js'].File
30 Gtk.init (null, null);
32 var gitlive = GLib.get_home_dir() + "/gitlive";
34 if (!GLib.file_test(gitlive, GLib.FileTest.IS_DIR)) {
35 var msg = new Gtk.MessageDialog({message_type:
36 Gtk.MessageType.INFO, buttons : Gtk.ButtonsType.OK, text: "GIT Live - ~/gitlive does not exist."});
44 var monitor = new Monitor({
51 this.lastAdd = new Date();
53 GLib.timeout_add(GLib.PRIORITY_LOW, 500, function() {
54 //TIMEOUT", _this.queue.length , _this.queueRunning].join(', '));
55 if (!_this.queue.length || _this.queueRunning) {
58 var last = Math.floor(((new Date()) - this.lastAdd) / 100);
59 if (last < 4) { // wait 1/2 a seconnd before running.
66 Monitor.prototype.start.call(this);
67 var notification = new Notify.Notification({
69 body : gitlive + "\nMonitoring " + this.monitors.length + " Directories"
72 notification.set_timeout(2000);
77 * - pulls the items off the queue
78 * (as commands run concurrently and new items may get added while it's running)
79 * - runs the queue items
85 this.queueRunning = true;
87 this.queue.forEach(function (q) {
90 this.queue = []; // empty queue!
96 cmds.forEach(function(cmd) {
97 // prevent duplicate calls..
98 if (done.indexOf(cmd.join(',')) > -1) {
101 done.push(cmd.join(','));
103 if (repos.indexOf(cmd[0]) < 0) {
105 Git.run(cmd[0] , 'pull'); // pull before we push!
107 var sp = Git.run.apply(Git,cmd);
109 switch (sp.result * 1) {
111 success.push(sp.args.join(' '));
112 if (sp.output.length) success.push(sp.output + '');
113 // if (sp.stderr.length) success.push(sp.stderr + '');
116 failure.push(sp.args.join(' '));
117 if (sp.output.length) failure.push(sp.output);
118 if (sp.stderr.length) failure.push(sp.stderr);
125 repos.forEach(function(r) {
126 var sp = Git.run(r , 'push', { all: true } );
133 if (success.length) {
134 print(success.join("\n"));
135 var notification = new Notify.Notification({
136 summary: "Git Live Commited",
137 body : success.join("\n")
141 notification.set_timeout(2000);
144 if (failure.length) {
146 var notification = new Notify.Notification({
147 summary: "Git Live ERROR!!",
148 body : failure.join("\n")
152 notification.set_timeout(5000); // show errros for longer
155 this.queueRunning = false;
158 shouldIgnore: function(f)
160 if (f.name[0] == '.') {
162 if (f.name == '.htaccess') {
168 if (f.name.match(/~$/)) {
171 // ignore anything in top level!!!!
172 if (!f.vpath.length) {
180 parsePath: function(f) {
182 var vpath_ar = f.path.substring(gitlive.length +1).split('/');
184 f.gitpath = gitlive + '/' + vpath_ar.shift();
185 f.vpath = vpath_ar.join('/');
192 onChanged : function(src)
194 return; // always ignore this..?
195 //this.parsePath(src);
197 onChangesDoneHint : function(src)
200 if (this.shouldIgnore(src)) {
205 if (typeof(this.just_created[src.path]) !='undefined') {
206 delete this.just_created[src.path];
207 this.lastAdd = new Date();
209 [ src.gitpath, 'add', src.vpath ],
210 [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ]
216 this.lastAdd = new Date();
218 [ src.gitpath, 'add', src.vpath ],
219 [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ]
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} ]
244 onCreated : function(src)
247 if (this.shouldIgnore(src)) {
251 if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
252 this.just_created[src.path] = true;
253 return; // we do not handle file create flags... - use done hint.
255 // director has bee created
256 this.monitor(src.path);
257 this.lastAdd = new Date();
259 [ src.gitpath, 'add' , src.vpath, { all: true } ],
260 [ src.gitpath, 'commit' , { all: true, message: src.vpath} ]
266 onAttributeChanged : function(src) {
268 if (this.shouldIgnore(src)) {
271 this.lastAdd = new Date();
273 [ src.gitpath, 'commit' , src.vpath, { message: src.vpath} ]
279 onMoved : function(src,dest)
282 this.parsePath(dest);
284 if (src.gitpath != dest.gitpath) {
286 this.onCreated(dest);
287 this.onChangedDoneHint(dest);
290 // needs to handle move to/from unsupported types..
292 if (this.shouldIgnore(src)) {
295 if (this.shouldIgnore(dest)) {
298 this.lastAdd = new Date();
300 [ src.gitpath, 'mv', '-k', src.vpath, dest.vpath ],
301 [ src.gitpath, 'commit' , src.vpath, dest.vpath ,
302 { message: 'MOVED ' + src.vpath +' to ' + dest.vpath} ]
313 function errorDialog(data) {
314 var msg = new Gtk.MessageDialog({
315 message_type: Gtk.MessageType.ERROR,
316 buttons : Gtk.ButtonsType.OK,
328 // need a better icon...
334 Notify.init("gitlive");
336 monitor.add(GLib.get_home_dir() + "/gitlive");
339 //icon.signal["activate"].connect(on_left_click);