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
13 GLib = imports.gi.GLib;
15 // we add this in, as it appears to get lost sometimes if we set it using the ENV. variable in builder.sh
16 GI.IRepository.prepend_search_path(GLib.get_home_dir() + '/.Builder/girepository-1.1');
20 Notify = imports.gi.Notify;
22 Spawn = imports.Spawn;
24 StatusIcon = imports.StatusIcon.StatusIcon;
25 Monitor = imports.Monitor.Monitor;
28 //File = imports[__script_path__+'/../introspection-doc-generator/File.js'].File
29 Gtk.init (null, null);
31 var gitlive = GLib.get_home_dir() + "/gitlive";
33 if (!GLib.file_test(gitlive, GLib.FileTest.IS_DIR)) {
34 var msg = new Gtk.MessageDialog({message_type:
35 Gtk.MessageType.INFO, buttons : Gtk.ButtonsType.OK, text: "GIT Live - ~/gitlive does not exist."});
43 var monitor = new Monitor({
50 this.lastAdd = new Date();
52 GLib.timeout_add(GLib.PRIORITY_LOW, 500, function() {
53 //TIMEOUT", _this.queue.length , _this.queueRunning].join(', '));
54 if (!_this.queue.length || _this.queueRunning) {
57 var last = Math.floor(((new Date()) - this.lastAdd) / 100);
58 if (last < 4) { // wait 1/2 a seconnd before running.
65 Monitor.prototype.start.call(this);
66 var notification = new Notify.Notification({
68 body : gitlive + "\nMonitoring " + this.monitors.length + " Directories"
71 notification.set_timeout(2000);
76 * - pulls the items off the queue
77 * (as commands run concurrently and new items may get added while it's running)
78 * - runs the queue items
84 this.queueRunning = true;
86 this.queue.forEach(function (q) {
89 this.queue = []; // empty queue!
95 cmds.forEach(function(cmd) {
96 // prevent duplicate calls..
97 if (done.indexOf(cmd.join(',')) > -1) {
100 done.push(cmd.join(','));
102 if (repos.indexOf(cmd[0]) < 0) {
104 Git.run(cmd[0] , 'pull'); // pull before we push!
106 var sp = Git.run.apply(Git,cmd);
108 switch (sp.result * 1) {
110 success.push(sp.args.join(' '));
111 if (sp.output.length) success.push(sp.output + '');
112 // if (sp.stderr.length) success.push(sp.stderr + '');
115 failure.push(sp.args.join(' '));
116 if (sp.output.length) failure.push(sp.output);
117 if (sp.stderr.length) failure.push(sp.stderr);
124 repos.forEach(function(r) {
125 var sp = Git.run(r , 'push', { all: true } );
132 if (success.length) {
133 print(success.join("\n"));
134 var notification = new Notify.Notification({
135 summary: "Git Live Commited",
136 body : success.join("\n")
140 notification.set_timeout(2000);
143 if (failure.length) {
145 var notification = new Notify.Notification({
146 summary: "Git Live ERROR!!",
147 body : failure.join("\n")
151 notification.set_timeout(5000); // show errros for longer
154 this.queueRunning = false;
157 shouldIgnore: function(f)
159 if (f.name[0] == '.') {
161 if (f.name == '.htaccess') {
167 if (f.name.match(/~$/)) {
170 // ignore anything in top level!!!!
171 if (!f.vpath.length) {
179 parsePath: function(f) {
181 var vpath_ar = f.path.substring(gitlive.length +1).split('/');
183 f.gitpath = gitlive + '/' + vpath_ar.shift();
184 f.vpath = vpath_ar.join('/');
191 onChanged : function(src)
193 return; // always ignore this..?
194 //this.parsePath(src);
196 onChangesDoneHint : function(src)
199 if (this.shouldIgnore(src)) {
204 if (typeof(this.just_created[src.path]) !='undefined') {
205 delete this.just_created[src.path];
206 this.lastAdd = new Date();
208 [ src.gitpath, 'add', src.vpath ],
209 [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ]
215 this.lastAdd = new Date();
217 [ src.gitpath, 'add', src.vpath ],
218 [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ]
225 onDeleted : function(src)
228 if (this.shouldIgnore(src)) {
231 // should check if monitor needs removing..
232 // it should also check if it was a directory.. - so we dont have to commit all..
234 this.lastAdd = new Date();
236 [ src.gitpath, 'rm' , src.vpath ],
237 [ src.gitpath, 'commit', { all: true, message: src.vpath} ]
243 onCreated : function(src)
246 if (this.shouldIgnore(src)) {
250 if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
251 this.just_created[src.path] = true;
252 return; // we do not handle file create flags... - use done hint.
254 // director has bee created
255 this.monitor(src.path);
256 this.lastAdd = new Date();
258 [ src.gitpath, 'add' , src.vpath, { all: true } ],
259 [ src.gitpath, 'commit' , { all: true, message: src.vpath} ]
265 onAttributeChanged : function(src) {
267 if (this.shouldIgnore(src)) {
270 this.lastAdd = new Date();
272 [ src.gitpath, 'commit' , src.vpath, { message: src.vpath} ]
278 onMoved : function(src,dest)
281 this.parsePath(dest);
283 if (src.gitpath != dest.gitpath) {
285 this.onCreated(dest);
286 this.onChangedDoneHint(dest);
289 // needs to handle move to/from unsupported types..
291 if (this.shouldIgnore(src)) {
294 if (this.shouldIgnore(dest)) {
297 this.lastAdd = new Date();
299 [ src.gitpath, 'mv', '-k', src.vpath, dest.vpath ],
300 [ src.gitpath, 'commit' , src.vpath, dest.vpath ,
301 { message: 'MOVED ' + src.vpath +' to ' + dest.vpath} ]
312 function errorDialog(data) {
313 var msg = new Gtk.MessageDialog({
314 message_type: Gtk.MessageType.ERROR,
315 buttons : Gtk.ButtonsType.OK,
327 // need a better icon...
333 Notify.init("gitlive");
335 monitor.add(GLib.get_home_dir() + "/gitlive");
338 //icon.signal["activate"].connect(on_left_click);