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..
18 * git log -n 1 --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 // we add this in, as it appears to get lost sometimes if we set it using the ENV. variable in builder.sh
74 GI.IRepository.prepend_search_path(GLib.get_home_dir() + '/.Builder/girepository-1.1');
78 Notify = imports.gi.Notify;
80 Spawn = imports.Spawn;
82 StatusIcon = imports.StatusIcon.StatusIcon;
83 Monitor = imports.Monitor.Monitor;
84 File = imports.File.File;
88 //File = imports[__script_path__+'/../introspection-doc-generator/File.js'].File
89 Gtk.init (null, null);
91 var gitlive = GLib.get_home_dir() + "/gitlive";
93 if (!GLib.file_test(gitlive, GLib.FileTest.IS_DIR)) {
94 var msg = new Gtk.MessageDialog({message_type:
95 Gtk.MessageType.INFO, buttons : Gtk.ButtonsType.OK, text: "GIT Live - ~/gitlive does not exist."});
103 var monitor = new Monitor({
107 * action: 'add' | rm | update
115 queueRunning : false,
122 this.dot_gitlive = GLib.get_home_dir() + "/.gitlive";
123 if (!File.exists(this.dot_gitlive)) {
124 File.mkdir(this.dot_gitlive);
129 this.lastAdd = new Date();
131 // start monitoring first..
132 Monitor.prototype.start.call(this);
134 // then start our queue runner..
135 GLib.timeout_add(GLib.PRIORITY_LOW, 500, function() {
136 //TIMEOUT", _this.queue.length , _this.queueRunning].join(', '));
137 if (!_this.queue.length || _this.queueRunning) {
140 var last = Math.floor(((new Date()) - this.lastAdd) / 100);
141 if (last < 4) { // wait 1/2 a seconnd before running.
149 var notification = new Notify.Notification({
151 body : gitlive + "\nMonitoring " + this.monitors.length + " Directories"
154 notification.set_timeout(2000);
158 initRepo : function(src)
160 print("INIT REPO " + src);
162 function logrun(sp) {
163 print("LOGRUN?" + typeof(sp));
164 switch (sp.result * 1) {
166 print(sp.args.join(' '));
167 if (sp.output.length) print(sp.output + '');
168 // if (sp.stderr.length) success.push(sp.stderr + '');
171 print(sp.args.join(' '));
172 if (sp.output.length) print(sp.output);
173 if (sp.stderr.length) print(sp.stderr);
178 // make hour mirrored directory
179 var rname = src.split('/').pop();
180 var dotdir = this.dot_gitlive + '/' + rname;
182 print("CHECK WORKING CACHE " + dotdir);
184 if (!File.isDirectory(dotdir)) {
185 // print("Not a dir?");
186 logrun(Git.run(this.dot_gitlive, 'clone', src , { shared : true } ));
188 // refresh - always..
189 logrun(Git.run(src, 'pull'));
191 // create and checkout gitlive branch.
192 logrun(Git.run(src, 'push', 'origin', 'origin:refs/heads/gitlive'));
193 logrun(Git.run(src, 'checkout', { track : true , 'b' : 'gitlive' } , 'origin/gitlive'));
207 * - pulls the items off the queue
208 * (as commands run concurrently and new items may get added while it's running)
209 * - runs the queue items
215 this.queueRunning = true;
217 //this.queue.forEach(function (q) {
221 this.action_queue.forEach(function (q) {
224 //this.queue = []; // empty queue!
225 this.action_queue = [];
231 function readResult(sp) {
232 switch (sp.result * 1) {
234 success.push(sp.args.join(' '));
235 if (sp.output.length) success.push(sp.output + '');
236 // if (sp.stderr.length) success.push(sp.stderr + '');
239 failure.push(sp.args.join(' '));
240 if (sp.output.length) failure.push(sp.output);
241 if (sp.stderr.length) failure.push(sp.stderr);
246 cmds.forEach(function(cmd) {
247 // prevent duplicate calls..
248 if (done.indexOf(JSON.stringify(cmd)) > -1) {
251 done.push(JSON.stringify(cmd));
252 // --- we keep a list of repositories that will be pushed to at the end..
254 if (repos.indexOf(cmd.repos) < 0) {
255 repos.push(cmd.repos);
256 // Git.run(cmd.repos , 'pull'); // pull before we push!
259 var gp = gitlive + '/' + cmd.repo;
261 switch( cmd.action ) {
263 readResult(Git.run(gp, 'add', cmd.file ));
264 readResult(Git.run(gp, 'commit', src.file, { message: cmd.file} ));
268 readResult(Git.run(gp, 'rm', cmd.file ));
269 readResult(Git.run(gp, 'commit', { all: true, message: cmd.file} ));
273 readResult(Git.run(gp, 'commit', cmd.file , { message: cmd.file} ));
277 readResult(Git.run(gp, 'mv', cmd.file , cmd.target));
278 readResult(Git.run(gp, 'commit', cmd.file , cmd.target,
279 { message: 'MOVED ' + src.file +' to ' + dest.target } ));
288 repos.forEach(function(r) {
289 var sp = Git.run(gitlive + '/' +r , 'push', { all: true } );
296 if (success.length) {
297 print(success.join("\n"));
298 var notification = new Notify.Notification({
299 summary: "Git Live Commited",
300 body : success.join("\n")
304 notification.set_timeout(2000);
307 if (failure.length) {
309 var notification = new Notify.Notification({
310 summary: "Git Live ERROR!!",
311 body : failure.join("\n")
315 notification.set_timeout(5000); // show errros for longer
318 this.queueRunning = false;
321 shouldIgnore: function(f)
323 if (f.name[0] == '.') {
325 if (f.name == '.htaccess') {
331 if (f.name.match(/~$/)) {
334 // ignore anything in top level!!!!
335 if (!f.vpath.length) {
344 * set gitpath and vpath
349 parsePath: function(f)
352 var vpath_ar = f.path.substring(gitlive.length +1).split('/');
353 f.repo = vpath_ar.shift();
354 f.gitpath = gitlive + '/' + f.repo;
355 f.vpath = vpath_ar.join('/');
362 onChanged : function(src)
364 return; // always ignore this..?
365 //this.parsePath(src);
369 * results in git add + git commit..
375 onChangesDoneHint : function(src)
378 if (this.shouldIgnore(src)) {
383 if (typeof(this.just_created[src.path]) !='undefined') {
384 delete this.just_created[src.path];
385 this.lastAdd = new Date();
387 // [ src.gitpath, 'add', src.vpath ],
388 // [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ]
391 this.action_queue.push({
401 this.lastAdd = new Date();
403 // [ src.gitpath, 'add', src.vpath ],
404 // [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ]
408 this.action_queue.push({
416 onDeleted : function(src)
419 if (this.shouldIgnore(src)) {
422 // should check if monitor needs removing..
423 // it should also check if it was a directory.. - so we dont have to commit all..
425 this.lastAdd = new Date();
427 // [ src.gitpath, 'rm' , src.vpath ],
428 // [ src.gitpath, 'commit', { all: true, message: src.vpath} ]
431 this.action_queue.push({
438 onCreated : function(src)
441 if (this.shouldIgnore(src)) {
445 if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
446 this.just_created[src.path] = true;
447 return; // we do not handle file create flags... - use done hint.
449 // director has bee created
450 this.monitor(src.path);
453 since git does not really handle directory adds...
455 this.lastAdd = new Date();
456 this.action_queue.push({
463 [ src.gitpath, 'add' , src.vpath, { all: true } ],
464 [ src.gitpath, 'commit' , { all: true, message: src.vpath} ]
471 onAttributeChanged : function(src) {
473 if (this.shouldIgnore(src)) {
476 this.lastAdd = new Date();
480 // [ src.gitpath, 'commit' , src.vpath, { message: src.vpath} ]
482 this.action_queue.push({
491 onMoved : function(src,dest)
494 this.parsePath(dest);
496 if (src.gitpath != dest.gitpath) {
498 this.onCreated(dest);
499 this.onChangedDoneHint(dest);
502 // needs to handle move to/from unsupported types..
504 if (this.shouldIgnore(src)) {
507 if (this.shouldIgnore(dest)) {
510 this.lastAdd = new Date();
512 // [ src.gitpath, 'mv', '-k', src.vpath, dest.vpath ],
513 // [ src.gitpath, 'commit' , src.vpath, dest.vpath ,
514 // { message: 'MOVED ' + src.vpath +' to ' + dest.vpath} ]
517 this.action_queue.push({
533 function errorDialog(data) {
534 var msg = new Gtk.MessageDialog({
535 message_type: Gtk.MessageType.ERROR,
536 buttons : Gtk.ButtonsType.OK,
548 // need a better icon...
554 Notify.init("gitlive");
556 monitor.add(GLib.get_home_dir() + "/gitlive");
559 //icon.signal["activate"].connect(on_left_click);