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 * A) have a gitlive branch - where all our commits go.. - so they can be replicated on the server
13 * B) HEAD branch - where things get merged to..
14 * -- eventually on closing issues..
15 * -- currently when we switch from one feature to another..
19 * Notes on feature branch implementation
20 * we clone directory into gitlive_feature/XXXXX
21 * git branch issue_XXX
22 * git checkout issue_XXX
29 GI = imports.gi.GIRepository
30 GLib = imports.gi.GLib;
32 // we add this in, as it appears to get lost sometimes if we set it using the ENV. variable in builder.sh
33 GI.IRepository.prepend_search_path(GLib.get_home_dir() + '/.Builder/girepository-1.1');
37 Notify = imports.gi.Notify;
39 Spawn = imports.Spawn;
41 StatusIcon = imports.StatusIcon.StatusIcon;
42 Monitor = imports.Monitor.Monitor;
45 //File = imports[__script_path__+'/../introspection-doc-generator/File.js'].File
46 Gtk.init (null, null);
48 var gitlive = GLib.get_home_dir() + "/gitlive";
50 if (!GLib.file_test(gitlive, GLib.FileTest.IS_DIR)) {
51 var msg = new Gtk.MessageDialog({message_type:
52 Gtk.MessageType.INFO, buttons : Gtk.ButtonsType.OK, text: "GIT Live - ~/gitlive does not exist."});
60 var monitor = new Monitor({
64 * action: 'add' | rm | update
77 this.lastAdd = new Date();
79 GLib.timeout_add(GLib.PRIORITY_LOW, 500, function() {
80 //TIMEOUT", _this.queue.length , _this.queueRunning].join(', '));
81 if (!_this.queue.length || _this.queueRunning) {
84 var last = Math.floor(((new Date()) - this.lastAdd) / 100);
85 if (last < 4) { // wait 1/2 a seconnd before running.
92 Monitor.prototype.start.call(this);
93 var notification = new Notify.Notification({
95 body : gitlive + "\nMonitoring " + this.monitors.length + " Directories"
98 notification.set_timeout(2000);
103 * - pulls the items off the queue
104 * (as commands run concurrently and new items may get added while it's running)
105 * - runs the queue items
111 this.queueRunning = true;
113 //this.queue.forEach(function (q) {
117 this.action_queue.forEach(function (q) {
120 //this.queue = []; // empty queue!
121 this.action_queue = [];
127 function readResult(sp) {
128 switch (sp.result * 1) {
130 success.push(sp.args.join(' '));
131 if (sp.output.length) success.push(sp.output + '');
132 // if (sp.stderr.length) success.push(sp.stderr + '');
135 failure.push(sp.args.join(' '));
136 if (sp.output.length) failure.push(sp.output);
137 if (sp.stderr.length) failure.push(sp.stderr);
142 cmds.forEach(function(cmd) {
143 // prevent duplicate calls..
144 if (done.indexOf(JSON.stringify(cmd)) > -1) {
147 done.push(JSON.stringify(cmd));
148 // --- we keep a list of repositories that will be pushed to at the end..
150 if (repos.indexOf(cmd.repos) < 0) {
151 repos.push(cmd.repos);
152 // Git.run(cmd.repos , 'pull'); // pull before we push!
155 var gp = gitlive + '/' + cmd.repo;
157 switch( cmd.action ) {
159 readResult(Git.run(gp, 'add', cmd.file ));
160 readResult(Git.run(gp, 'commit', src.file, { message: cmd.file} ));
164 readResult(Git.run(gp, 'rm', cmd.file ));
165 readResult(Git.run(gp, 'commit', { all: true, message: cmd.file} ));
169 readResult(Git.run(gp, 'commit', cmd.file , { message: cmd.file} ));
173 readResult(Git.run(gp, 'mv', cmd.file , cmd.target));
174 readResult(Git.run(gp, 'commit', cmd.file , cmd.target,
175 { message: 'MOVED ' + src.file +' to ' + dest.target } ));
184 repos.forEach(function(r) {
185 var sp = Git.run(gitlive + '/' +r , 'push', { all: true } );
192 if (success.length) {
193 print(success.join("\n"));
194 var notification = new Notify.Notification({
195 summary: "Git Live Commited",
196 body : success.join("\n")
200 notification.set_timeout(2000);
203 if (failure.length) {
205 var notification = new Notify.Notification({
206 summary: "Git Live ERROR!!",
207 body : failure.join("\n")
211 notification.set_timeout(5000); // show errros for longer
214 this.queueRunning = false;
217 shouldIgnore: function(f)
219 if (f.name[0] == '.') {
221 if (f.name == '.htaccess') {
227 if (f.name.match(/~$/)) {
230 // ignore anything in top level!!!!
231 if (!f.vpath.length) {
240 * set gitpath and vpath
245 parsePath: function(f)
248 var vpath_ar = f.path.substring(gitlive.length +1).split('/');
249 f.repo = vpath_ar.shift();
250 f.gitpath = gitlive + '/' + f.repo;
251 f.vpath = vpath_ar.join('/');
258 onChanged : function(src)
260 return; // always ignore this..?
261 //this.parsePath(src);
265 * results in git add + git commit..
271 onChangesDoneHint : function(src)
274 if (this.shouldIgnore(src)) {
279 if (typeof(this.just_created[src.path]) !='undefined') {
280 delete this.just_created[src.path];
281 this.lastAdd = new Date();
283 // [ src.gitpath, 'add', src.vpath ],
284 // [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ]
287 this.action_queue.push({
297 this.lastAdd = new Date();
299 // [ src.gitpath, 'add', src.vpath ],
300 // [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ]
304 this.action_queue.push({
312 onDeleted : function(src)
315 if (this.shouldIgnore(src)) {
318 // should check if monitor needs removing..
319 // it should also check if it was a directory.. - so we dont have to commit all..
321 this.lastAdd = new Date();
323 // [ src.gitpath, 'rm' , src.vpath ],
324 // [ src.gitpath, 'commit', { all: true, message: src.vpath} ]
327 this.action_queue.push({
334 onCreated : function(src)
337 if (this.shouldIgnore(src)) {
341 if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
342 this.just_created[src.path] = true;
343 return; // we do not handle file create flags... - use done hint.
345 // director has bee created
346 this.monitor(src.path);
349 since git does not really handle directory adds...
351 this.lastAdd = new Date();
352 this.action_queue.push({
359 [ src.gitpath, 'add' , src.vpath, { all: true } ],
360 [ src.gitpath, 'commit' , { all: true, message: src.vpath} ]
367 onAttributeChanged : function(src) {
369 if (this.shouldIgnore(src)) {
372 this.lastAdd = new Date();
376 // [ src.gitpath, 'commit' , src.vpath, { message: src.vpath} ]
378 this.action_queue.push({
387 onMoved : function(src,dest)
390 this.parsePath(dest);
392 if (src.gitpath != dest.gitpath) {
394 this.onCreated(dest);
395 this.onChangedDoneHint(dest);
398 // needs to handle move to/from unsupported types..
400 if (this.shouldIgnore(src)) {
403 if (this.shouldIgnore(dest)) {
406 this.lastAdd = new Date();
408 // [ src.gitpath, 'mv', '-k', src.vpath, dest.vpath ],
409 // [ src.gitpath, 'commit' , src.vpath, dest.vpath ,
410 // { message: 'MOVED ' + src.vpath +' to ' + dest.vpath} ]
413 this.action_queue.push({
429 function errorDialog(data) {
430 var msg = new Gtk.MessageDialog({
431 message_type: Gtk.MessageType.ERROR,
432 buttons : Gtk.ButtonsType.OK,
444 // need a better icon...
450 Notify.init("gitlive");
452 monitor.add(GLib.get_home_dir() + "/gitlive");
455 //icon.signal["activate"].connect(on_left_click);