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;
86 //File = imports[__script_path__+'/../introspection-doc-generator/File.js'].File
87 Gtk.init (null, null);
89 var gitlive = GLib.get_home_dir() + "/gitlive";
91 if (!GLib.file_test(gitlive, GLib.FileTest.IS_DIR)) {
92 var msg = new Gtk.MessageDialog({message_type:
93 Gtk.MessageType.INFO, buttons : Gtk.ButtonsType.OK, text: "GIT Live - ~/gitlive does not exist."});
101 var monitor = new Monitor({
105 * action: 'add' | rm | update
113 queueRunning : false,
118 this.lastAdd = new Date();
120 // start monitoring first..
121 Monitor.prototype.start.call(this);
123 // then start our queue runner..
124 GLib.timeout_add(GLib.PRIORITY_LOW, 500, function() {
125 //TIMEOUT", _this.queue.length , _this.queueRunning].join(', '));
126 if (!_this.queue.length || _this.queueRunning) {
129 var last = Math.floor(((new Date()) - this.lastAdd) / 100);
130 if (last < 4) { // wait 1/2 a seconnd before running.
138 var notification = new Notify.Notification({
140 body : gitlive + "\nMonitoring " + this.monitors.length + " Directories"
143 notification.set_timeout(2000);
147 initRepo : function(src) {
148 print("INIT REPO " + src);
155 * - pulls the items off the queue
156 * (as commands run concurrently and new items may get added while it's running)
157 * - runs the queue items
163 this.queueRunning = true;
165 //this.queue.forEach(function (q) {
169 this.action_queue.forEach(function (q) {
172 //this.queue = []; // empty queue!
173 this.action_queue = [];
179 function readResult(sp) {
180 switch (sp.result * 1) {
182 success.push(sp.args.join(' '));
183 if (sp.output.length) success.push(sp.output + '');
184 // if (sp.stderr.length) success.push(sp.stderr + '');
187 failure.push(sp.args.join(' '));
188 if (sp.output.length) failure.push(sp.output);
189 if (sp.stderr.length) failure.push(sp.stderr);
194 cmds.forEach(function(cmd) {
195 // prevent duplicate calls..
196 if (done.indexOf(JSON.stringify(cmd)) > -1) {
199 done.push(JSON.stringify(cmd));
200 // --- we keep a list of repositories that will be pushed to at the end..
202 if (repos.indexOf(cmd.repos) < 0) {
203 repos.push(cmd.repos);
204 // Git.run(cmd.repos , 'pull'); // pull before we push!
207 var gp = gitlive + '/' + cmd.repo;
209 switch( cmd.action ) {
211 readResult(Git.run(gp, 'add', cmd.file ));
212 readResult(Git.run(gp, 'commit', src.file, { message: cmd.file} ));
216 readResult(Git.run(gp, 'rm', cmd.file ));
217 readResult(Git.run(gp, 'commit', { all: true, message: cmd.file} ));
221 readResult(Git.run(gp, 'commit', cmd.file , { message: cmd.file} ));
225 readResult(Git.run(gp, 'mv', cmd.file , cmd.target));
226 readResult(Git.run(gp, 'commit', cmd.file , cmd.target,
227 { message: 'MOVED ' + src.file +' to ' + dest.target } ));
236 repos.forEach(function(r) {
237 var sp = Git.run(gitlive + '/' +r , 'push', { all: true } );
244 if (success.length) {
245 print(success.join("\n"));
246 var notification = new Notify.Notification({
247 summary: "Git Live Commited",
248 body : success.join("\n")
252 notification.set_timeout(2000);
255 if (failure.length) {
257 var notification = new Notify.Notification({
258 summary: "Git Live ERROR!!",
259 body : failure.join("\n")
263 notification.set_timeout(5000); // show errros for longer
266 this.queueRunning = false;
269 shouldIgnore: function(f)
271 if (f.name[0] == '.') {
273 if (f.name == '.htaccess') {
279 if (f.name.match(/~$/)) {
282 // ignore anything in top level!!!!
283 if (!f.vpath.length) {
292 * set gitpath and vpath
297 parsePath: function(f)
300 var vpath_ar = f.path.substring(gitlive.length +1).split('/');
301 f.repo = vpath_ar.shift();
302 f.gitpath = gitlive + '/' + f.repo;
303 f.vpath = vpath_ar.join('/');
310 onChanged : function(src)
312 return; // always ignore this..?
313 //this.parsePath(src);
317 * results in git add + git commit..
323 onChangesDoneHint : function(src)
326 if (this.shouldIgnore(src)) {
331 if (typeof(this.just_created[src.path]) !='undefined') {
332 delete this.just_created[src.path];
333 this.lastAdd = new Date();
335 // [ src.gitpath, 'add', src.vpath ],
336 // [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ]
339 this.action_queue.push({
349 this.lastAdd = new Date();
351 // [ src.gitpath, 'add', src.vpath ],
352 // [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ]
356 this.action_queue.push({
364 onDeleted : function(src)
367 if (this.shouldIgnore(src)) {
370 // should check if monitor needs removing..
371 // it should also check if it was a directory.. - so we dont have to commit all..
373 this.lastAdd = new Date();
375 // [ src.gitpath, 'rm' , src.vpath ],
376 // [ src.gitpath, 'commit', { all: true, message: src.vpath} ]
379 this.action_queue.push({
386 onCreated : function(src)
389 if (this.shouldIgnore(src)) {
393 if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
394 this.just_created[src.path] = true;
395 return; // we do not handle file create flags... - use done hint.
397 // director has bee created
398 this.monitor(src.path);
401 since git does not really handle directory adds...
403 this.lastAdd = new Date();
404 this.action_queue.push({
411 [ src.gitpath, 'add' , src.vpath, { all: true } ],
412 [ src.gitpath, 'commit' , { all: true, message: src.vpath} ]
419 onAttributeChanged : function(src) {
421 if (this.shouldIgnore(src)) {
424 this.lastAdd = new Date();
428 // [ src.gitpath, 'commit' , src.vpath, { message: src.vpath} ]
430 this.action_queue.push({
439 onMoved : function(src,dest)
442 this.parsePath(dest);
444 if (src.gitpath != dest.gitpath) {
446 this.onCreated(dest);
447 this.onChangedDoneHint(dest);
450 // needs to handle move to/from unsupported types..
452 if (this.shouldIgnore(src)) {
455 if (this.shouldIgnore(dest)) {
458 this.lastAdd = new Date();
460 // [ src.gitpath, 'mv', '-k', src.vpath, dest.vpath ],
461 // [ src.gitpath, 'commit' , src.vpath, dest.vpath ,
462 // { message: 'MOVED ' + src.vpath +' to ' + dest.vpath} ]
465 this.action_queue.push({
481 function errorDialog(data) {
482 var msg = new Gtk.MessageDialog({
483 message_type: Gtk.MessageType.ERROR,
484 buttons : Gtk.ButtonsType.OK,
496 // need a better icon...
502 Notify.init("gitlive");
504 monitor.add(GLib.get_home_dir() + "/gitlive");
507 //icon.signal["activate"].connect(on_left_click);