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 * --pretty=format:%H BRANCHNAME
22 * Notes on feature branch implementation
23 * We need to add a gitlive branch on the remote server..
24 * git push origin origin:refs/heads/gitlive
25 * git checkout --track -b gitlive origin/gitlive << means pull will use both branches..
28 * On our feature tree..
29 * git push origin origin:refs/heads/feature_2
31 * we clone directory into gitlive_feature/XXXXX
32 * git branch issue_XXX
33 * git checkout issue_XXX
35 * run this on the feature branch it merges and commits..
36 * git pull origin master << or gitlive..
39 * Standard change file (same bug as before..)
41 * commit etc.. (with bug no..)
43 * git pull origin gitlive
48 * Change to new bug number..
50 * git push origin origin:refs/heads/feature_XXX
51 * git checkout feature_XXX
53 * commit etc. (with new bug number)
55 * git pull origin gitlive
62 GI = imports.gi.GIRepository
63 GLib = imports.gi.GLib;
65 // we add this in, as it appears to get lost sometimes if we set it using the ENV. variable in builder.sh
66 GI.IRepository.prepend_search_path(GLib.get_home_dir() + '/.Builder/girepository-1.1');
70 Notify = imports.gi.Notify;
72 Spawn = imports.Spawn;
74 StatusIcon = imports.StatusIcon.StatusIcon;
75 Monitor = imports.Monitor.Monitor;
78 //File = imports[__script_path__+'/../introspection-doc-generator/File.js'].File
79 Gtk.init (null, null);
81 var gitlive = GLib.get_home_dir() + "/gitlive";
83 if (!GLib.file_test(gitlive, GLib.FileTest.IS_DIR)) {
84 var msg = new Gtk.MessageDialog({message_type:
85 Gtk.MessageType.INFO, buttons : Gtk.ButtonsType.OK, text: "GIT Live - ~/gitlive does not exist."});
93 var monitor = new Monitor({
97 * action: 'add' | rm | update
105 queueRunning : false,
110 this.lastAdd = new Date();
112 // start monitoring first..
113 Monitor.prototype.start.call(this);
115 // then start our queue runner..
116 GLib.timeout_add(GLib.PRIORITY_LOW, 500, function() {
117 //TIMEOUT", _this.queue.length , _this.queueRunning].join(', '));
118 if (!_this.queue.length || _this.queueRunning) {
121 var last = Math.floor(((new Date()) - this.lastAdd) / 100);
122 if (last < 4) { // wait 1/2 a seconnd before running.
130 var notification = new Notify.Notification({
132 body : gitlive + "\nMonitoring " + this.monitors.length + " Directories"
135 notification.set_timeout(2000);
140 * - pulls the items off the queue
141 * (as commands run concurrently and new items may get added while it's running)
142 * - runs the queue items
148 this.queueRunning = true;
150 //this.queue.forEach(function (q) {
154 this.action_queue.forEach(function (q) {
157 //this.queue = []; // empty queue!
158 this.action_queue = [];
164 function readResult(sp) {
165 switch (sp.result * 1) {
167 success.push(sp.args.join(' '));
168 if (sp.output.length) success.push(sp.output + '');
169 // if (sp.stderr.length) success.push(sp.stderr + '');
172 failure.push(sp.args.join(' '));
173 if (sp.output.length) failure.push(sp.output);
174 if (sp.stderr.length) failure.push(sp.stderr);
179 cmds.forEach(function(cmd) {
180 // prevent duplicate calls..
181 if (done.indexOf(JSON.stringify(cmd)) > -1) {
184 done.push(JSON.stringify(cmd));
185 // --- we keep a list of repositories that will be pushed to at the end..
187 if (repos.indexOf(cmd.repos) < 0) {
188 repos.push(cmd.repos);
189 // Git.run(cmd.repos , 'pull'); // pull before we push!
192 var gp = gitlive + '/' + cmd.repo;
194 switch( cmd.action ) {
196 readResult(Git.run(gp, 'add', cmd.file ));
197 readResult(Git.run(gp, 'commit', src.file, { message: cmd.file} ));
201 readResult(Git.run(gp, 'rm', cmd.file ));
202 readResult(Git.run(gp, 'commit', { all: true, message: cmd.file} ));
206 readResult(Git.run(gp, 'commit', cmd.file , { message: cmd.file} ));
210 readResult(Git.run(gp, 'mv', cmd.file , cmd.target));
211 readResult(Git.run(gp, 'commit', cmd.file , cmd.target,
212 { message: 'MOVED ' + src.file +' to ' + dest.target } ));
221 repos.forEach(function(r) {
222 var sp = Git.run(gitlive + '/' +r , 'push', { all: true } );
229 if (success.length) {
230 print(success.join("\n"));
231 var notification = new Notify.Notification({
232 summary: "Git Live Commited",
233 body : success.join("\n")
237 notification.set_timeout(2000);
240 if (failure.length) {
242 var notification = new Notify.Notification({
243 summary: "Git Live ERROR!!",
244 body : failure.join("\n")
248 notification.set_timeout(5000); // show errros for longer
251 this.queueRunning = false;
254 shouldIgnore: function(f)
256 if (f.name[0] == '.') {
258 if (f.name == '.htaccess') {
264 if (f.name.match(/~$/)) {
267 // ignore anything in top level!!!!
268 if (!f.vpath.length) {
277 * set gitpath and vpath
282 parsePath: function(f)
285 var vpath_ar = f.path.substring(gitlive.length +1).split('/');
286 f.repo = vpath_ar.shift();
287 f.gitpath = gitlive + '/' + f.repo;
288 f.vpath = vpath_ar.join('/');
295 onChanged : function(src)
297 return; // always ignore this..?
298 //this.parsePath(src);
302 * results in git add + git commit..
308 onChangesDoneHint : function(src)
311 if (this.shouldIgnore(src)) {
316 if (typeof(this.just_created[src.path]) !='undefined') {
317 delete this.just_created[src.path];
318 this.lastAdd = new Date();
320 // [ src.gitpath, 'add', src.vpath ],
321 // [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ]
324 this.action_queue.push({
334 this.lastAdd = new Date();
336 // [ src.gitpath, 'add', src.vpath ],
337 // [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ]
341 this.action_queue.push({
349 onDeleted : function(src)
352 if (this.shouldIgnore(src)) {
355 // should check if monitor needs removing..
356 // it should also check if it was a directory.. - so we dont have to commit all..
358 this.lastAdd = new Date();
360 // [ src.gitpath, 'rm' , src.vpath ],
361 // [ src.gitpath, 'commit', { all: true, message: src.vpath} ]
364 this.action_queue.push({
371 onCreated : function(src)
374 if (this.shouldIgnore(src)) {
378 if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
379 this.just_created[src.path] = true;
380 return; // we do not handle file create flags... - use done hint.
382 // director has bee created
383 this.monitor(src.path);
386 since git does not really handle directory adds...
388 this.lastAdd = new Date();
389 this.action_queue.push({
396 [ src.gitpath, 'add' , src.vpath, { all: true } ],
397 [ src.gitpath, 'commit' , { all: true, message: src.vpath} ]
404 onAttributeChanged : function(src) {
406 if (this.shouldIgnore(src)) {
409 this.lastAdd = new Date();
413 // [ src.gitpath, 'commit' , src.vpath, { message: src.vpath} ]
415 this.action_queue.push({
424 onMoved : function(src,dest)
427 this.parsePath(dest);
429 if (src.gitpath != dest.gitpath) {
431 this.onCreated(dest);
432 this.onChangedDoneHint(dest);
435 // needs to handle move to/from unsupported types..
437 if (this.shouldIgnore(src)) {
440 if (this.shouldIgnore(dest)) {
443 this.lastAdd = new Date();
445 // [ src.gitpath, 'mv', '-k', src.vpath, dest.vpath ],
446 // [ src.gitpath, 'commit' , src.vpath, dest.vpath ,
447 // { message: 'MOVED ' + src.vpath +' to ' + dest.vpath} ]
450 this.action_queue.push({
466 function errorDialog(data) {
467 var msg = new Gtk.MessageDialog({
468 message_type: Gtk.MessageType.ERROR,
469 buttons : Gtk.ButtonsType.OK,
481 // need a better icon...
487 Notify.init("gitlive");
489 monitor.add(GLib.get_home_dir() + "/gitlive");
492 //icon.signal["activate"].connect(on_left_click);