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 var GI = imports.gi.GIRepository;
24 var Gio = imports.gi.Gio;
25 var GLib = imports.gi.GLib;
26 var Gtk = imports.gi.Gtk;
27 var Notify = imports.gi.Notify;
28 >>>>>>> e9aa44647c32a34dfa368f7594ed72579c912bc3
30 var Spawn = imports.Spawn;
31 var Git = imports.Git;
32 var StatusIcon = imports.StatusIcon.StatusIcon;
33 var Monitor = imports.Monitor.Monitor;
36 //File = imports[__script_path__+'/../introspection-doc-generator/File.js'].File
37 Gtk.init (null, null);
39 var gitlive = GLib.get_home_dir() + "/gitlive";
41 if (!GLib.file_test(gitlive, GLib.FileTest.IS_DIR)) {
42 var msg = new Gtk.MessageDialog({message_type:
43 Gtk.MessageType.INFO, buttons : Gtk.ButtonsType.OK, text: "GIT Live - ~/gitlive does not exist."});
51 var monitor = new Monitor({
58 this.lastAdd = new Date();
60 GLib.timeout_add(GLib.PRIORITY_LOW, 500, function() {
61 //TIMEOUT", _this.queue.length , _this.queueRunning].join(', '));
62 if (!_this.queue.length || _this.queueRunning) {
65 var last = Math.floor(((new Date()) - this.lastAdd) / 100);
66 if (last < 4) { // wait 1/2 a seconnd before running.
73 Monitor.prototype.start.call(this);
74 var notification = new Notify.Notification({
76 body : gitlive + "\nMonitoring " + this.monitors.length + " Directories"
79 notification.set_timeout(2000);
84 * - pulls the items off the queue
85 * (as commands run concurrently and new items may get added while it's running)
86 * - runs the queue items
92 this.queueRunning = true;
94 this.queue.forEach(function (q) {
97 this.queue = []; // empty queue!
103 cmds.forEach(function(cmd) {
104 // prevent duplicate calls..
105 if (done.indexOf(cmd.join(',')) > -1) {
108 done.push(cmd.join(','));
110 if (repos.indexOf(cmd[0]) < 0) {
112 Git.run(cmd[0] , 'pull'); // pull before we push!
114 var sp = Git.run.apply(Git,cmd);
116 switch (sp.result * 1) {
118 success.push(sp.args.join(' '));
119 if (sp.output.length) success.push(sp.output + '');
120 // if (sp.stderr.length) success.push(sp.stderr + '');
123 failure.push(sp.args.join(' '));
124 if (sp.output.length) failure.push(sp.output);
125 if (sp.stderr.length) failure.push(sp.stderr);
132 repos.forEach(function(r) {
133 var sp = Git.run(r , 'push', { all: true } );
140 if (success.length) {
141 print(success.join("\n"));
142 var notification = new Notify.Notification({
143 summary: "Git Live Commited",
144 body : success.join("\n")
148 notification.set_timeout(2000);
151 if (failure.length) {
153 var notification = new Notify.Notification({
154 summary: "Git Live ERROR!!",
155 body : failure.join("\n")
159 notification.set_timeout(5000); // show errros for longer
162 this.queueRunning = false;
165 shouldIgnore: function(f)
167 if (f.name[0] == '.') {
169 if (f.name == '.htaccess') {
175 if (f.name.match(/~$/)) {
178 // ignore anything in top level!!!!
179 if (!f.vpath.length) {
187 parsePath: function(f) {
189 var vpath_ar = f.path.substring(gitlive.length +1).split('/');
191 f.gitpath = gitlive + '/' + vpath_ar.shift();
192 f.vpath = vpath_ar.join('/');
199 onChanged : function(src)
201 return; // always ignore this..?
202 //this.parsePath(src);
204 onChangesDoneHint : function(src)
207 if (this.shouldIgnore(src)) {
212 if (typeof(this.just_created[src.path]) !='undefined') {
213 delete this.just_created[src.path];
214 this.lastAdd = new Date();
216 [ src.gitpath, 'add', src.vpath ],
217 [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ]
223 this.lastAdd = new Date();
225 [ src.gitpath, 'add', src.vpath ],
226 [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ]
233 onDeleted : function(src)
236 if (this.shouldIgnore(src)) {
239 // should check if monitor needs removing..
240 // it should also check if it was a directory.. - so we dont have to commit all..
242 this.lastAdd = new Date();
244 [ src.gitpath, 'rm' , src.vpath ],
245 [ src.gitpath, 'commit', { all: true, message: src.vpath} ]
251 onCreated : function(src)
254 if (this.shouldIgnore(src)) {
258 if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
259 this.just_created[src.path] = true;
260 return; // we do not handle file create flags... - use done hint.
262 // director has bee created
263 this.monitor(src.path);
264 this.lastAdd = new Date();
266 [ src.gitpath, 'add' , src.vpath, { all: true } ],
267 [ src.gitpath, 'commit' , { all: true, message: src.vpath} ]
273 onAttributeChanged : function(src) {
275 if (this.shouldIgnore(src)) {
278 this.lastAdd = new Date();
280 [ src.gitpath, 'commit' , src.vpath, { message: src.vpath} ]
286 onMoved : function(src,dest)
289 this.parsePath(dest);
291 if (src.gitpath != dest.gitpath) {
293 this.onCreated(dest);
294 this.onChangedDoneHint(dest);
297 // needs to handle move to/from unsupported types..
299 if (this.shouldIgnore(src)) {
302 if (this.shouldIgnore(dest)) {
305 this.lastAdd = new Date();
307 [ src.gitpath, 'mv', '-k', src.vpath, dest.vpath ],
308 [ src.gitpath, 'commit' , src.vpath, dest.vpath ,
309 { message: 'MOVED ' + src.vpath +' to ' + dest.vpath} ]
320 function errorDialog(data) {
321 var msg = new Gtk.MessageDialog({
322 message_type: Gtk.MessageType.ERROR,
323 buttons : Gtk.ButtonsType.OK,
335 // need a better icon...
341 Notify.init("gitlive");
343 monitor.add(GLib.get_home_dir() + "/gitlive");
346 //icon.signal["activate"].connect(on_left_click);