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.action_queue.length , _this.queueRunning].join(', '));
126 if (!_this.action_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.repo) < 0) {
196 repos.push(cmd.repo);
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', cmd.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 ' + cmd.file +' to ' + dest.target } ));
228 repos.forEach(function(r) {
229 var sp = Git.run(gitlive + '/' +r , 'push', { all: true } );
236 if (success.length) {
237 print(success.join("\n"));
238 var notification = new Notify.Notification({
239 summary: "Git Live Commited",
240 body : success.join("\n")
244 notification.set_timeout(2000);
247 if (failure.length) {
249 var notification = new Notify.Notification({
250 summary: "Git Live ERROR!!",
251 body : failure.join("\n")
255 notification.set_timeout(5000); // show errros for longer
258 this.queueRunning = false;
261 shouldIgnore: function(f)
263 if (f.name[0] == '.') {
265 if (f.name == '.htaccess') {
271 if (f.name.match(/~$/)) {
274 // ignore anything in top level!!!!
275 if (!f.vpath.length) {
284 * set gitpath and vpath
289 parsePath: function(f)
292 var vpath_ar = f.path.substring(gitlive.length +1).split('/');
293 f.repo = vpath_ar.shift();
294 f.gitpath = gitlive + '/' + f.repo;
295 f.vpath = vpath_ar.join('/');
302 onChanged : function(src)
304 return; // always ignore this..?
305 //this.parsePath(src);
309 * results in git add + git commit..
315 onChangesDoneHint : function(src)
318 if (this.shouldIgnore(src)) {
323 if (typeof(this.just_created[src.path]) !='undefined') {
324 delete this.just_created[src.path];
325 this.lastAdd = new Date();
327 // [ src.gitpath, 'add', src.vpath ],
328 // [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ]
331 this.action_queue.push({
341 this.lastAdd = new Date();
343 // [ src.gitpath, 'add', src.vpath ],
344 // [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ]
348 this.action_queue.push({
356 onDeleted : function(src)
359 if (this.shouldIgnore(src)) {
362 // should check if monitor needs removing..
363 // it should also check if it was a directory.. - so we dont have to commit all..
365 this.lastAdd = new Date();
367 // [ src.gitpath, 'rm' , src.vpath ],
368 // [ src.gitpath, 'commit', { all: true, message: src.vpath} ]
371 this.action_queue.push({
378 onCreated : function(src)
381 if (this.shouldIgnore(src)) {
385 if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
386 this.just_created[src.path] = true;
387 return; // we do not handle file create flags... - use done hint.
389 // director has bee created
390 this.monitor(src.path);
393 since git does not really handle directory adds...
395 this.lastAdd = new Date();
396 this.action_queue.push({
403 [ src.gitpath, 'add' , src.vpath, { all: true } ],
404 [ src.gitpath, 'commit' , { all: true, message: src.vpath} ]
411 onAttributeChanged : function(src) {
413 if (this.shouldIgnore(src)) {
416 this.lastAdd = new Date();
420 // [ src.gitpath, 'commit' , src.vpath, { message: src.vpath} ]
422 this.action_queue.push({
431 onMoved : function(src,dest)
434 this.parsePath(dest);
436 if (src.gitpath != dest.gitpath) {
438 this.onCreated(dest);
439 this.onChangedDoneHint(dest);
442 // needs to handle move to/from unsupported types..
444 if (this.shouldIgnore(src)) {
447 if (this.shouldIgnore(dest)) {
450 this.lastAdd = new Date();
452 // [ src.gitpath, 'mv', '-k', src.vpath, dest.vpath ],
453 // [ src.gitpath, 'commit' , src.vpath, dest.vpath ,
454 // { message: 'MOVED ' + src.vpath +' to ' + dest.vpath} ]
457 this.action_queue.push({
473 function errorDialog(data) {
474 var msg = new Gtk.MessageDialog({
475 message_type: Gtk.MessageType.ERROR,
476 buttons : Gtk.ButtonsType.OK,
488 // need a better icon...
494 Notify.init("gitlive");
496 monitor.add(GLib.get_home_dir() + "/gitlive");
499 //icon.signal["activate"].connect(on_left_click);