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 pull origin gitlive
56 * git push origin origin:refs/heads/feature_XXX
57 * git checkout feature_XXX
59 * commit etc. (with new bug number)
61 * git pull origin gitlive
68 GI = imports.gi.GIRepository
69 GLib = imports.gi.GLib;
71 // we add this in, as it appears to get lost sometimes if we set it using the ENV. variable in builder.sh
72 GI.IRepository.prepend_search_path(GLib.get_home_dir() + '/.Builder/girepository-1.1');
76 Notify = imports.gi.Notify;
78 Spawn = imports.Spawn;
80 StatusIcon = imports.StatusIcon.StatusIcon;
81 Monitor = imports.Monitor.Monitor;
84 //File = imports[__script_path__+'/../introspection-doc-generator/File.js'].File
85 Gtk.init (null, null);
87 var gitlive = GLib.get_home_dir() + "/gitlive";
89 if (!GLib.file_test(gitlive, GLib.FileTest.IS_DIR)) {
90 var msg = new Gtk.MessageDialog({message_type:
91 Gtk.MessageType.INFO, buttons : Gtk.ButtonsType.OK, text: "GIT Live - ~/gitlive does not exist."});
99 var monitor = new Monitor({
103 * action: 'add' | rm | update
111 queueRunning : false,
116 this.lastAdd = new Date();
118 // start monitoring first..
119 Monitor.prototype.start.call(this);
121 // then start our queue runner..
122 GLib.timeout_add(GLib.PRIORITY_LOW, 500, function() {
123 //TIMEOUT", _this.queue.length , _this.queueRunning].join(', '));
124 if (!_this.queue.length || _this.queueRunning) {
127 var last = Math.floor(((new Date()) - this.lastAdd) / 100);
128 if (last < 4) { // wait 1/2 a seconnd before running.
136 var notification = new Notify.Notification({
138 body : gitlive + "\nMonitoring " + this.monitors.length + " Directories"
141 notification.set_timeout(2000);
146 * - pulls the items off the queue
147 * (as commands run concurrently and new items may get added while it's running)
148 * - runs the queue items
154 this.queueRunning = true;
156 //this.queue.forEach(function (q) {
160 this.action_queue.forEach(function (q) {
163 //this.queue = []; // empty queue!
164 this.action_queue = [];
170 function readResult(sp) {
171 switch (sp.result * 1) {
173 success.push(sp.args.join(' '));
174 if (sp.output.length) success.push(sp.output + '');
175 // if (sp.stderr.length) success.push(sp.stderr + '');
178 failure.push(sp.args.join(' '));
179 if (sp.output.length) failure.push(sp.output);
180 if (sp.stderr.length) failure.push(sp.stderr);
185 cmds.forEach(function(cmd) {
186 // prevent duplicate calls..
187 if (done.indexOf(JSON.stringify(cmd)) > -1) {
190 done.push(JSON.stringify(cmd));
191 // --- we keep a list of repositories that will be pushed to at the end..
193 if (repos.indexOf(cmd.repos) < 0) {
194 repos.push(cmd.repos);
195 // Git.run(cmd.repos , 'pull'); // pull before we push!
198 var gp = gitlive + '/' + cmd.repo;
200 switch( cmd.action ) {
202 readResult(Git.run(gp, 'add', cmd.file ));
203 readResult(Git.run(gp, 'commit', src.file, { message: cmd.file} ));
207 readResult(Git.run(gp, 'rm', cmd.file ));
208 readResult(Git.run(gp, 'commit', { all: true, message: cmd.file} ));
212 readResult(Git.run(gp, 'commit', cmd.file , { message: cmd.file} ));
216 readResult(Git.run(gp, 'mv', cmd.file , cmd.target));
217 readResult(Git.run(gp, 'commit', cmd.file , cmd.target,
218 { message: 'MOVED ' + src.file +' to ' + dest.target } ));
227 repos.forEach(function(r) {
228 var sp = Git.run(gitlive + '/' +r , 'push', { all: true } );
235 if (success.length) {
236 print(success.join("\n"));
237 var notification = new Notify.Notification({
238 summary: "Git Live Commited",
239 body : success.join("\n")
243 notification.set_timeout(2000);
246 if (failure.length) {
248 var notification = new Notify.Notification({
249 summary: "Git Live ERROR!!",
250 body : failure.join("\n")
254 notification.set_timeout(5000); // show errros for longer
257 this.queueRunning = false;
260 shouldIgnore: function(f)
262 if (f.name[0] == '.') {
264 if (f.name == '.htaccess') {
270 if (f.name.match(/~$/)) {
273 // ignore anything in top level!!!!
274 if (!f.vpath.length) {
283 * set gitpath and vpath
288 parsePath: function(f)
291 var vpath_ar = f.path.substring(gitlive.length +1).split('/');
292 f.repo = vpath_ar.shift();
293 f.gitpath = gitlive + '/' + f.repo;
294 f.vpath = vpath_ar.join('/');
301 onChanged : function(src)
303 return; // always ignore this..?
304 //this.parsePath(src);
308 * results in git add + git commit..
314 onChangesDoneHint : function(src)
317 if (this.shouldIgnore(src)) {
322 if (typeof(this.just_created[src.path]) !='undefined') {
323 delete this.just_created[src.path];
324 this.lastAdd = new Date();
326 // [ src.gitpath, 'add', src.vpath ],
327 // [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ]
330 this.action_queue.push({
340 this.lastAdd = new Date();
342 // [ src.gitpath, 'add', src.vpath ],
343 // [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ]
347 this.action_queue.push({
355 onDeleted : function(src)
358 if (this.shouldIgnore(src)) {
361 // should check if monitor needs removing..
362 // it should also check if it was a directory.. - so we dont have to commit all..
364 this.lastAdd = new Date();
366 // [ src.gitpath, 'rm' , src.vpath ],
367 // [ src.gitpath, 'commit', { all: true, message: src.vpath} ]
370 this.action_queue.push({
377 onCreated : function(src)
380 if (this.shouldIgnore(src)) {
384 if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
385 this.just_created[src.path] = true;
386 return; // we do not handle file create flags... - use done hint.
388 // director has bee created
389 this.monitor(src.path);
392 since git does not really handle directory adds...
394 this.lastAdd = new Date();
395 this.action_queue.push({
402 [ src.gitpath, 'add' , src.vpath, { all: true } ],
403 [ src.gitpath, 'commit' , { all: true, message: src.vpath} ]
410 onAttributeChanged : function(src) {
412 if (this.shouldIgnore(src)) {
415 this.lastAdd = new Date();
419 // [ src.gitpath, 'commit' , src.vpath, { message: src.vpath} ]
421 this.action_queue.push({
430 onMoved : function(src,dest)
433 this.parsePath(dest);
435 if (src.gitpath != dest.gitpath) {
437 this.onCreated(dest);
438 this.onChangedDoneHint(dest);
441 // needs to handle move to/from unsupported types..
443 if (this.shouldIgnore(src)) {
446 if (this.shouldIgnore(dest)) {
449 this.lastAdd = new Date();
451 // [ src.gitpath, 'mv', '-k', src.vpath, dest.vpath ],
452 // [ src.gitpath, 'commit' , src.vpath, dest.vpath ,
453 // { message: 'MOVED ' + src.vpath +' to ' + dest.vpath} ]
456 this.action_queue.push({
472 function errorDialog(data) {
473 var msg = new Gtk.MessageDialog({
474 message_type: Gtk.MessageType.ERROR,
475 buttons : Gtk.ButtonsType.OK,
487 // need a better icon...
493 Notify.init("gitlive");
495 monitor.add(GLib.get_home_dir() + "/gitlive");
498 //icon.signal["activate"].connect(on_left_click);