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({
52 this.lastAdd = new Date();
54 GLib.timeout_add(GLib.PRIORITY_LOW, 500, function() {
55 //TIMEOUT", _this.queue.length , _this.queueRunning].join(', '));
56 if (!_this.queue.length || _this.queueRunning) {
59 var last = Math.floor(((new Date()) - this.lastAdd) / 100);
60 if (last < 4) { // wait 1/2 a seconnd before running.
67 Monitor.prototype.start.call(this);
68 var notification = new Notify.Notification({
70 body : gitlive + "\nMonitoring " + this.monitors.length + " Directories"
73 notification.set_timeout(2000);
78 * - pulls the items off the queue
79 * (as commands run concurrently and new items may get added while it's running)
80 * - runs the queue items
86 this.queueRunning = true;
88 this.queue.forEach(function (q) {
91 this.queue = []; // empty queue!
97 cmds.forEach(function(cmd) {
98 // prevent duplicate calls..
99 if (done.indexOf(cmd.join(',')) > -1) {
102 done.push(cmd.join(','));
104 if (repos.indexOf(cmd[0]) < 0) {
106 Git.run(cmd[0] , 'pull'); // pull before we push!
108 var sp = Git.run.apply(Git,cmd);
110 switch (sp.result * 1) {
112 success.push(sp.args.join(' '));
113 if (sp.output.length) success.push(sp.output + '');
114 // if (sp.stderr.length) success.push(sp.stderr + '');
117 failure.push(sp.args.join(' '));
118 if (sp.output.length) failure.push(sp.output);
119 if (sp.stderr.length) failure.push(sp.stderr);
126 repos.forEach(function(r) {
127 var sp = Git.run(r , 'push', { all: true } );
134 if (success.length) {
135 print(success.join("\n"));
136 var notification = new Notify.Notification({
137 summary: "Git Live Commited",
138 body : success.join("\n")
142 notification.set_timeout(2000);
145 if (failure.length) {
147 var notification = new Notify.Notification({
148 summary: "Git Live ERROR!!",
149 body : failure.join("\n")
153 notification.set_timeout(5000); // show errros for longer
156 this.queueRunning = false;
159 shouldIgnore: function(f)
161 if (f.name[0] == '.') {
163 if (f.name == '.htaccess') {
169 if (f.name.match(/~$/)) {
172 // ignore anything in top level!!!!
173 if (!f.vpath.length) {
182 * set gitpath and vpath
187 parsePath: function(f)
190 var vpath_ar = f.path.substring(gitlive.length +1).split('/');
192 f.gitpath = gitlive + '/' + vpath_ar.shift();
193 f.vpath = vpath_ar.join('/');
200 onChanged : function(src)
202 return; // always ignore this..?
203 //this.parsePath(src);
205 onChangesDoneHint : function(src)
208 if (this.shouldIgnore(src)) {
213 if (typeof(this.just_created[src.path]) !='undefined') {
214 delete this.just_created[src.path];
215 this.lastAdd = new Date();
217 [ src.gitpath, 'add', src.vpath ],
218 [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ]
224 this.lastAdd = new Date();
226 [ src.gitpath, 'add', src.vpath ],
227 [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ]
234 onDeleted : function(src)
237 if (this.shouldIgnore(src)) {
240 // should check if monitor needs removing..
241 // it should also check if it was a directory.. - so we dont have to commit all..
243 this.lastAdd = new Date();
245 [ src.gitpath, 'rm' , src.vpath ],
246 [ src.gitpath, 'commit', { all: true, message: src.vpath} ]
252 onCreated : function(src)
255 if (this.shouldIgnore(src)) {
259 if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
260 this.just_created[src.path] = true;
261 return; // we do not handle file create flags... - use done hint.
263 // director has bee created
264 this.monitor(src.path);
265 this.lastAdd = new Date();
267 [ src.gitpath, 'add' , src.vpath, { all: true } ],
268 [ src.gitpath, 'commit' , { all: true, message: src.vpath} ]
274 onAttributeChanged : function(src) {
276 if (this.shouldIgnore(src)) {
279 this.lastAdd = new Date();
281 [ src.gitpath, 'commit' , src.vpath, { message: src.vpath} ]
287 onMoved : function(src,dest)
290 this.parsePath(dest);
292 if (src.gitpath != dest.gitpath) {
294 this.onCreated(dest);
295 this.onChangedDoneHint(dest);
298 // needs to handle move to/from unsupported types..
300 if (this.shouldIgnore(src)) {
303 if (this.shouldIgnore(dest)) {
306 this.lastAdd = new Date();
308 [ src.gitpath, 'mv', '-k', src.vpath, dest.vpath ],
309 [ src.gitpath, 'commit' , src.vpath, dest.vpath ,
310 { message: 'MOVED ' + src.vpath +' to ' + dest.vpath} ]
321 function errorDialog(data) {
322 var msg = new Gtk.MessageDialog({
323 message_type: Gtk.MessageType.ERROR,
324 buttons : Gtk.ButtonsType.OK,
336 // need a better icon...
342 Notify.init("gitlive");
344 monitor.add(GLib.get_home_dir() + "/gitlive");
347 //icon.signal["activate"].connect(on_left_click);