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 checkout -b master origin/master
51 * git checkout master <<< make sure
52 * git pull --squash origin gitlive
53 * git commit -m 'done with old bug number'
58 * git push origin origin:refs/heads/feature_XXX
59 * git checkout feature_XXX
61 * commit etc. (with new bug number)
63 * git pull origin gitlive
70 GI = imports.gi.GIRepository
71 GLib = imports.gi.GLib;
73 print(JSON.stringify(GI, null,4));
74 // we add this in, as it appears to get lost sometimes if we set it using the ENV. variable in builder.sh
75 GI.IRepository.prepend_search_path(GLib.get_home_dir() + '/.Builder/girepository-1.1');
79 Notify = imports.gi.Notify;
81 Spawn = imports.Spawn;
83 StatusIcon = imports.StatusIcon.StatusIcon;
84 Monitor = imports.Monitor.Monitor;
87 //File = imports[__script_path__+'/../introspection-doc-generator/File.js'].File
88 Gtk.init (null, null);
90 var gitlive = GLib.get_home_dir() + "/gitlive";
92 if (!GLib.file_test(gitlive, GLib.FileTest.IS_DIR)) {
93 var msg = new Gtk.MessageDialog({message_type:
94 Gtk.MessageType.INFO, buttons : Gtk.ButtonsType.OK, text: "GIT Live - ~/gitlive does not exist."});
102 var monitor = new Monitor({
106 * action: 'add' | rm | update
114 queueRunning : false,
119 this.lastAdd = new Date();
121 // start monitoring first..
122 Monitor.prototype.start.call(this);
124 // then start our queue runner..
125 GLib.timeout_add(GLib.PRIORITY_LOW, 500, function() {
126 //TIMEOUT", _this.action_queue.length , _this.queueRunning].join(', '));
127 if (!_this.action_queue.length || _this.queueRunning) {
130 var last = Math.floor(((new Date()) - this.lastAdd) / 100);
131 if (last < 4) { // wait 1/2 a seconnd before running.
139 var notification = new Notify.Notification({
141 body : gitlive + "\nMonitoring " + this.monitors.length + " Directories"
144 notification.set_timeout(2000);
149 * - pulls the items off the queue
150 * (as commands run concurrently and new items may get added while it's running)
151 * - runs the queue items
157 this.queueRunning = true;
159 //this.queue.forEach(function (q) {
163 this.action_queue.forEach(function (q) {
166 //this.queue = []; // empty queue!
167 this.action_queue = [];
173 function readResult(sp) {
174 switch (sp.result * 1) {
176 success.push(sp.args.join(' '));
177 if (sp.output.length) success.push(sp.output + '');
178 // if (sp.stderr.length) success.push(sp.stderr + '');
181 failure.push(sp.args.join(' '));
182 if (sp.output.length) failure.push(sp.output);
183 if (sp.stderr.length) failure.push(sp.stderr);
188 cmds.forEach(function(cmd) {
189 // prevent duplicate calls..
190 if (done.indexOf(JSON.stringify(cmd)) > -1) {
193 done.push(JSON.stringify(cmd));
194 // --- we keep a list of repositories that will be pushed to at the end..
196 if (repos.indexOf(cmd.repo) < 0) {
197 repos.push(cmd.repo);
198 // Git.run(cmd.repos , 'pull'); // pull before we push!
201 var gp = gitlive + '/' + cmd.repo;
203 switch( cmd.action ) {
205 readResult(Git.run(gp, 'add', cmd.file ));
206 readResult(Git.run(gp, 'commit', cmd.file, { message: cmd.file} ));
210 readResult(Git.run(gp, 'rm', cmd.file ));
211 readResult(Git.run(gp, 'commit', { all: true, message: cmd.file} ));
215 readResult(Git.run(gp, 'commit', cmd.file , { message: cmd.file} ));
219 readResult(Git.run(gp, 'mv', cmd.file , cmd.target));
220 readResult(Git.run(gp, 'commit', cmd.file , cmd.target,
221 { message: 'MOVED ' + cmd.file +' to ' + cmd.target } ));
230 repos.forEach(function(r) {
231 var sp = Git.run(gitlive + '/' +r , 'push', { all: true } );
238 if (success.length) {
239 print(success.join("\n"));
240 var notification = new Notify.Notification({
241 summary: "Git Live Commited",
242 body : success.join("\n")
246 notification.set_timeout(2000);
249 if (failure.length) {
251 var notification = new Notify.Notification({
252 summary: "Git Live ERROR!!",
253 body : failure.join("\n")
257 notification.set_timeout(5000); // show errros for longer
260 this.queueRunning = false;
263 shouldIgnore: function(f)
265 if (f.name[0] == '.') {
267 if (f.name == '.htaccess') {
273 if (f.name.match(/~$/)) {
276 // ignore anything in top level!!!!
277 if (!f.vpath.length) {
286 * set gitpath and vpath
291 parsePath: function(f)
294 var vpath_ar = f.path.substring(gitlive.length +1).split('/');
295 f.repo = vpath_ar.shift();
296 f.gitpath = gitlive + '/' + f.repo;
297 f.vpath = vpath_ar.join('/');
304 onChanged : function(src)
306 return; // always ignore this..?
307 //this.parsePath(src);
311 * results in git add + git commit..
317 onChangesDoneHint : function(src)
320 if (this.shouldIgnore(src)) {
325 if (typeof(this.just_created[src.path]) !='undefined') {
326 delete this.just_created[src.path];
327 this.lastAdd = new Date();
329 // [ src.gitpath, 'add', src.vpath ],
330 // [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ]
333 this.action_queue.push({
343 this.lastAdd = new Date();
345 // [ src.gitpath, 'add', src.vpath ],
346 // [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ]
350 this.action_queue.push({
358 onDeleted : function(src)
361 if (this.shouldIgnore(src)) {
364 // should check if monitor needs removing..
365 // it should also check if it was a directory.. - so we dont have to commit all..
367 this.lastAdd = new Date();
369 // [ src.gitpath, 'rm' , src.vpath ],
370 // [ src.gitpath, 'commit', { all: true, message: src.vpath} ]
373 this.action_queue.push({
380 onCreated : function(src)
383 if (this.shouldIgnore(src)) {
387 if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
388 this.just_created[src.path] = true;
389 return; // we do not handle file create flags... - use done hint.
391 // director has bee created
392 this.monitor(src.path);
395 since git does not really handle directory adds...
397 this.lastAdd = new Date();
398 this.action_queue.push({
405 [ src.gitpath, 'add' , src.vpath, { all: true } ],
406 [ src.gitpath, 'commit' , { all: true, message: src.vpath} ]
413 onAttributeChanged : function(src) {
415 if (this.shouldIgnore(src)) {
418 this.lastAdd = new Date();
422 // [ src.gitpath, 'commit' , src.vpath, { message: src.vpath} ]
424 this.action_queue.push({
433 onMoved : function(src,dest)
436 this.parsePath(dest);
438 if (src.gitpath != dest.gitpath) {
440 this.onCreated(dest);
441 this.onChangedDoneHint(dest);
444 // needs to handle move to/from unsupported types..
446 if (this.shouldIgnore(src)) {
449 if (this.shouldIgnore(dest)) {
452 this.lastAdd = new Date();
454 // [ src.gitpath, 'mv', '-k', src.vpath, dest.vpath ],
455 // [ src.gitpath, 'commit' , src.vpath, dest.vpath ,
456 // { message: 'MOVED ' + src.vpath +' to ' + dest.vpath} ]
459 this.action_queue.push({
475 function errorDialog(data) {
476 var msg = new Gtk.MessageDialog({
477 message_type: Gtk.MessageType.ERROR,
478 buttons : Gtk.ButtonsType.OK,
490 // need a better icon...
496 Notify.init("gitlive");
498 monitor.add(GLib.get_home_dir() + "/gitlive");
501 //icon.signal["activate"].connect(on_left_click);