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 // 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);
148 * - pulls the items off the queue
149 * (as commands run concurrently and new items may get added while it's running)
150 * - runs the queue items
156 this.queueRunning = true;
158 //this.queue.forEach(function (q) {
162 this.action_queue.forEach(function (q) {
165 //this.queue = []; // empty queue!
166 this.action_queue = [];
172 function readResult(sp) {
173 switch (sp.result * 1) {
175 success.push(sp.args.join(' '));
176 if (sp.output.length) success.push(sp.output + '');
177 // if (sp.stderr.length) success.push(sp.stderr + '');
180 failure.push(sp.args.join(' '));
181 if (sp.output.length) failure.push(sp.output);
182 if (sp.stderr.length) failure.push(sp.stderr);
187 cmds.forEach(function(cmd) {
188 // prevent duplicate calls..
189 if (done.indexOf(JSON.stringify(cmd)) > -1) {
192 done.push(JSON.stringify(cmd));
193 // --- we keep a list of repositories that will be pushed to at the end..
195 if (repos.indexOf(cmd.repos) < 0) {
196 repos.push(cmd.repos);
197 // Git.run(cmd.repos , 'pull'); // pull before we push!
200 var gp = gitlive + '/' + cmd.repo;
202 switch( cmd.action ) {
204 readResult(Git.run(gp, 'add', cmd.file ));
205 readResult(Git.run(gp, 'commit', src.file, { message: cmd.file} ));
209 readResult(Git.run(gp, 'rm', cmd.file ));
210 readResult(Git.run(gp, 'commit', { all: true, message: cmd.file} ));
214 readResult(Git.run(gp, 'commit', cmd.file , { message: cmd.file} ));
218 readResult(Git.run(gp, 'mv', cmd.file , cmd.target));
219 readResult(Git.run(gp, 'commit', cmd.file , cmd.target,
220 { message: 'MOVED ' + src.file +' to ' + dest.target } ));
229 repos.forEach(function(r) {
230 var sp = Git.run(gitlive + '/' +r , 'push', { all: true } );
237 if (success.length) {
238 print(success.join("\n"));
239 var notification = new Notify.Notification({
240 summary: "Git Live Commited",
241 body : success.join("\n")
245 notification.set_timeout(2000);
248 if (failure.length) {
250 var notification = new Notify.Notification({
251 summary: "Git Live ERROR!!",
252 body : failure.join("\n")
256 notification.set_timeout(5000); // show errros for longer
259 this.queueRunning = false;
262 shouldIgnore: function(f)
264 if (f.name[0] == '.') {
266 if (f.name == '.htaccess') {
272 if (f.name.match(/~$/)) {
275 // ignore anything in top level!!!!
276 if (!f.vpath.length) {
285 * set gitpath and vpath
290 parsePath: function(f)
293 var vpath_ar = f.path.substring(gitlive.length +1).split('/');
294 f.repo = vpath_ar.shift();
295 f.gitpath = gitlive + '/' + f.repo;
296 f.vpath = vpath_ar.join('/');
303 onChanged : function(src)
305 return; // always ignore this..?
306 //this.parsePath(src);
310 * results in git add + git commit..
316 onChangesDoneHint : function(src)
319 if (this.shouldIgnore(src)) {
324 if (typeof(this.just_created[src.path]) !='undefined') {
325 delete this.just_created[src.path];
326 this.lastAdd = new Date();
328 // [ src.gitpath, 'add', src.vpath ],
329 // [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ]
332 this.action_queue.push({
342 this.lastAdd = new Date();
344 // [ src.gitpath, 'add', src.vpath ],
345 // [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ]
349 this.action_queue.push({
357 onDeleted : function(src)
360 if (this.shouldIgnore(src)) {
363 // should check if monitor needs removing..
364 // it should also check if it was a directory.. - so we dont have to commit all..
366 this.lastAdd = new Date();
368 // [ src.gitpath, 'rm' , src.vpath ],
369 // [ src.gitpath, 'commit', { all: true, message: src.vpath} ]
372 this.action_queue.push({
379 onCreated : function(src)
382 if (this.shouldIgnore(src)) {
386 if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
387 this.just_created[src.path] = true;
388 return; // we do not handle file create flags... - use done hint.
390 // director has bee created
391 this.monitor(src.path);
394 since git does not really handle directory adds...
396 this.lastAdd = new Date();
397 this.action_queue.push({
404 [ src.gitpath, 'add' , src.vpath, { all: true } ],
405 [ src.gitpath, 'commit' , { all: true, message: src.vpath} ]
412 onAttributeChanged : function(src) {
414 if (this.shouldIgnore(src)) {
417 this.lastAdd = new Date();
421 // [ src.gitpath, 'commit' , src.vpath, { message: src.vpath} ]
423 this.action_queue.push({
432 onMoved : function(src,dest)
435 this.parsePath(dest);
437 if (src.gitpath != dest.gitpath) {
439 this.onCreated(dest);
440 this.onChangedDoneHint(dest);
443 // needs to handle move to/from unsupported types..
445 if (this.shouldIgnore(src)) {
448 if (this.shouldIgnore(dest)) {
451 this.lastAdd = new Date();
453 // [ src.gitpath, 'mv', '-k', src.vpath, dest.vpath ],
454 // [ src.gitpath, 'commit' , src.vpath, dest.vpath ,
455 // { message: 'MOVED ' + src.vpath +' to ' + dest.vpath} ]
458 this.action_queue.push({
474 function errorDialog(data) {
475 var msg = new Gtk.MessageDialog({
476 message_type: Gtk.MessageType.ERROR,
477 buttons : Gtk.ButtonsType.OK,
489 // need a better icon...
495 Notify.init("gitlive");
497 monitor.add(GLib.get_home_dir() + "/gitlive");
500 //icon.signal["activate"].connect(on_left_click);