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 GIRepository = 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.Repository.prepend_search_path(GLib.get_home_dir() + '/.Builder/girepository-1.1');
76 GIRepository.Repository.prepend_search_path(GLib.get_home_dir() + '/.Builder/girepository-1.2');
80 Notify = imports.gi.Notify;
82 Spawn = imports.Spawn;
84 StatusIcon = imports.StatusIcon.StatusIcon;
85 Monitor = imports.Monitor.Monitor;
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,
120 this.lastAdd = new Date();
122 // start monitoring first..
123 Monitor.prototype.start.call(this);
125 // then start our queue runner..
126 GLib.timeout_add(GLib.PRIORITY_LOW, 500, function() {
127 //TIMEOUT", _this.action_queue.length , _this.queueRunning].join(', '));
128 if (!_this.action_queue.length || _this.queueRunning) {
131 var last = Math.floor(((new Date()) - this.lastAdd) / 100);
132 if (last < 4) { // wait 1/2 a seconnd before running.
140 var notification = new Notify.Notification({
142 body : gitlive + "\nMonitoring " + this.monitors.length + " Directories",
146 notification.set_timeout(5);
151 * - pulls the items off the queue
152 * (as commands run concurrently and new items may get added while it's running)
153 * - runs the queue items
159 this.queueRunning = true;
161 //this.queue.forEach(function (q) {
165 this.action_queue.forEach(function (q) {
168 //this.queue = []; // empty queue!
169 this.action_queue = [];
175 function readResult(sp) {
176 switch (sp.result * 1) {
178 success.push(sp.args.join(' '));
179 if (sp.output.length) success.push(sp.output + '');
180 // if (sp.stderr.length) success.push(sp.stderr + '');
183 failure.push(sp.args.join(' '));
184 if (sp.output.length) failure.push(sp.output);
185 if (sp.stderr.length) failure.push(sp.stderr);
190 cmds.forEach(function(cmd) {
191 // prevent duplicate calls..
192 if (done.indexOf(JSON.stringify(cmd)) > -1) {
195 done.push(JSON.stringify(cmd));
196 // --- we keep a list of repositories that will be pushed to at the end..
198 if (repos.indexOf(cmd.repo) < 0) {
199 repos.push(cmd.repo);
200 // Git.run(cmd.repos , 'pull'); // pull before we push!
203 var gp = gitlive + '/' + cmd.repo;
205 switch( cmd.action ) {
207 readResult(Git.run(gp, 'add', cmd.file ));
208 readResult(Git.run(gp, 'commit', cmd.file, { message: cmd.file} ));
212 readResult(Git.run(gp, 'rm', cmd.file ));
213 readResult(Git.run(gp, 'commit', { all: true, message: cmd.file} ));
217 readResult(Git.run(gp, 'commit', cmd.file , { message: cmd.file} ));
221 readResult(Git.run(gp, 'mv', cmd.file , cmd.target));
222 readResult(Git.run(gp, 'commit', cmd.file , cmd.target,
223 { message: 'MOVED ' + cmd.file +' to ' + cmd.target } ));
232 repos.forEach(function(r) {
233 var sp = Git.run(gitlive + '/' +r , 'push', { all: true } );
240 if (success.length) {
241 print(success.join("\n"));
242 var notification = new Notify.Notification({
243 summary: "Git Live Commited",
244 body : success.join("\n"),
249 notification.set_timeout(5);
252 if (failure.length) {
254 var notification = new Notify.Notification({
255 summary: "Git Live ERROR!!",
256 body : failure.join("\n"),
261 notification.set_timeout(5); // show errros for longer
264 this.queueRunning = false;
267 shouldIgnore: function(f)
269 if (f.name[0] == '.') {
271 if (f.name == '.htaccess') {
277 if (f.name.match(/~$/)) {
280 // ignore anything in top level!!!!
281 if (!f.vpath.length) {
290 * set gitpath and vpath
295 parsePath: function(f)
298 var vpath_ar = f.path.substring(gitlive.length +1).split('/');
299 f.repo = vpath_ar.shift();
300 f.gitpath = gitlive + '/' + f.repo;
301 f.vpath = vpath_ar.join('/');
308 onChanged : function(src)
310 return; // always ignore this..?
311 //this.parsePath(src);
315 * results in git add + git commit..
319 onChangesDoneHint : function(src)
322 if (this.shouldIgnore(src)) {
337 if (typeof(this.just_created[src.path]) !='undefined') {
338 delete this.just_created[src.path];
339 this.lastAdd = new Date();
341 // [ src.gitpath, 'add', src.vpath ],
342 // [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ]
345 this.action_queue.push({
355 this.lastAdd = new Date();
357 // [ src.gitpath, 'add', src.vpath ],
358 // [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ]
362 this.action_queue.push({
370 onDeleted : function(src)
373 if (this.shouldIgnore(src)) {
376 // should check if monitor needs removing..
377 // it should also check if it was a directory.. - so we dont have to commit all..
379 this.lastAdd = new Date();
381 // [ src.gitpath, 'rm' , src.vpath ],
382 // [ src.gitpath, 'commit', { all: true, message: src.vpath} ]
385 this.action_queue.push({
392 onCreated : function(src)
395 if (this.shouldIgnore(src)) {
399 if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
400 this.just_created[src.path] = true;
401 return; // we do not handle file create flags... - use done hint.
403 // director has bee created
404 this.monitor(src.path);
407 since git does not really handle directory adds...
409 this.lastAdd = new Date();
410 this.action_queue.push({
417 [ src.gitpath, 'add' , src.vpath, { all: true } ],
418 [ src.gitpath, 'commit' , { all: true, message: src.vpath} ]
425 onAttributeChanged : function(src) {
427 if (this.shouldIgnore(src)) {
430 this.lastAdd = new Date();
434 // [ src.gitpath, 'commit' , src.vpath, { message: src.vpath} ]
436 this.action_queue.push({
445 onMoved : function(src,dest)
448 this.parsePath(dest);
450 if (src.gitpath != dest.gitpath) {
452 this.onCreated(dest);
453 this.onChangedDoneHint(dest);
456 // needs to handle move to/from unsupported types..
458 if (this.shouldIgnore(src)) {
461 if (this.shouldIgnore(dest)) {
464 this.lastAdd = new Date();
466 // [ src.gitpath, 'mv', '-k', src.vpath, dest.vpath ],
467 // [ src.gitpath, 'commit' , src.vpath, dest.vpath ,
468 // { message: 'MOVED ' + src.vpath +' to ' + dest.vpath} ]
471 this.action_queue.push({
487 function errorDialog(data) {
488 var msg = new Gtk.MessageDialog({
489 message_type: Gtk.MessageType.ERROR,
490 buttons : Gtk.ButtonsType.OK,
502 // need a better icon...
508 Notify.init("gitlive");
510 monitor.add(GLib.get_home_dir() + "/gitlive");
513 //icon.signal["activate"].connect(on_left_click);