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 * Notes on feature branch implementation
20 * we clone directory into gitlive_feature/XXXXX
21 * git branch issue_XXX
22 * git checkout issue_XXX
24 * run this on the feature branch
25 * git pull origin master << or gitlive..
31 GI = imports.gi.GIRepository
32 GLib = imports.gi.GLib;
34 // we add this in, as it appears to get lost sometimes if we set it using the ENV. variable in builder.sh
35 GI.IRepository.prepend_search_path(GLib.get_home_dir() + '/.Builder/girepository-1.1');
39 Notify = imports.gi.Notify;
41 Spawn = imports.Spawn;
43 StatusIcon = imports.StatusIcon.StatusIcon;
44 Monitor = imports.Monitor.Monitor;
47 //File = imports[__script_path__+'/../introspection-doc-generator/File.js'].File
48 Gtk.init (null, null);
50 var gitlive = GLib.get_home_dir() + "/gitlive";
52 if (!GLib.file_test(gitlive, GLib.FileTest.IS_DIR)) {
53 var msg = new Gtk.MessageDialog({message_type:
54 Gtk.MessageType.INFO, buttons : Gtk.ButtonsType.OK, text: "GIT Live - ~/gitlive does not exist."});
62 var monitor = new Monitor({
66 * action: 'add' | rm | update
79 this.lastAdd = new Date();
81 GLib.timeout_add(GLib.PRIORITY_LOW, 500, function() {
82 //TIMEOUT", _this.queue.length , _this.queueRunning].join(', '));
83 if (!_this.queue.length || _this.queueRunning) {
86 var last = Math.floor(((new Date()) - this.lastAdd) / 100);
87 if (last < 4) { // wait 1/2 a seconnd before running.
94 Monitor.prototype.start.call(this);
95 var notification = new Notify.Notification({
97 body : gitlive + "\nMonitoring " + this.monitors.length + " Directories"
100 notification.set_timeout(2000);
105 * - pulls the items off the queue
106 * (as commands run concurrently and new items may get added while it's running)
107 * - runs the queue items
113 this.queueRunning = true;
115 //this.queue.forEach(function (q) {
119 this.action_queue.forEach(function (q) {
122 //this.queue = []; // empty queue!
123 this.action_queue = [];
129 function readResult(sp) {
130 switch (sp.result * 1) {
132 success.push(sp.args.join(' '));
133 if (sp.output.length) success.push(sp.output + '');
134 // if (sp.stderr.length) success.push(sp.stderr + '');
137 failure.push(sp.args.join(' '));
138 if (sp.output.length) failure.push(sp.output);
139 if (sp.stderr.length) failure.push(sp.stderr);
144 cmds.forEach(function(cmd) {
145 // prevent duplicate calls..
146 if (done.indexOf(JSON.stringify(cmd)) > -1) {
149 done.push(JSON.stringify(cmd));
150 // --- we keep a list of repositories that will be pushed to at the end..
152 if (repos.indexOf(cmd.repos) < 0) {
153 repos.push(cmd.repos);
154 // Git.run(cmd.repos , 'pull'); // pull before we push!
157 var gp = gitlive + '/' + cmd.repo;
159 switch( cmd.action ) {
161 readResult(Git.run(gp, 'add', cmd.file ));
162 readResult(Git.run(gp, 'commit', src.file, { message: cmd.file} ));
166 readResult(Git.run(gp, 'rm', cmd.file ));
167 readResult(Git.run(gp, 'commit', { all: true, message: cmd.file} ));
171 readResult(Git.run(gp, 'commit', cmd.file , { message: cmd.file} ));
175 readResult(Git.run(gp, 'mv', cmd.file , cmd.target));
176 readResult(Git.run(gp, 'commit', cmd.file , cmd.target,
177 { message: 'MOVED ' + src.file +' to ' + dest.target } ));
186 repos.forEach(function(r) {
187 var sp = Git.run(gitlive + '/' +r , 'push', { all: true } );
194 if (success.length) {
195 print(success.join("\n"));
196 var notification = new Notify.Notification({
197 summary: "Git Live Commited",
198 body : success.join("\n")
202 notification.set_timeout(2000);
205 if (failure.length) {
207 var notification = new Notify.Notification({
208 summary: "Git Live ERROR!!",
209 body : failure.join("\n")
213 notification.set_timeout(5000); // show errros for longer
216 this.queueRunning = false;
219 shouldIgnore: function(f)
221 if (f.name[0] == '.') {
223 if (f.name == '.htaccess') {
229 if (f.name.match(/~$/)) {
232 // ignore anything in top level!!!!
233 if (!f.vpath.length) {
242 * set gitpath and vpath
247 parsePath: function(f)
250 var vpath_ar = f.path.substring(gitlive.length +1).split('/');
251 f.repo = vpath_ar.shift();
252 f.gitpath = gitlive + '/' + f.repo;
253 f.vpath = vpath_ar.join('/');
260 onChanged : function(src)
262 return; // always ignore this..?
263 //this.parsePath(src);
267 * results in git add + git commit..
273 onChangesDoneHint : function(src)
276 if (this.shouldIgnore(src)) {
281 if (typeof(this.just_created[src.path]) !='undefined') {
282 delete this.just_created[src.path];
283 this.lastAdd = new Date();
285 // [ src.gitpath, 'add', src.vpath ],
286 // [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ]
289 this.action_queue.push({
299 this.lastAdd = new Date();
301 // [ src.gitpath, 'add', src.vpath ],
302 // [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ]
306 this.action_queue.push({
314 onDeleted : function(src)
317 if (this.shouldIgnore(src)) {
320 // should check if monitor needs removing..
321 // it should also check if it was a directory.. - so we dont have to commit all..
323 this.lastAdd = new Date();
325 // [ src.gitpath, 'rm' , src.vpath ],
326 // [ src.gitpath, 'commit', { all: true, message: src.vpath} ]
329 this.action_queue.push({
336 onCreated : function(src)
339 if (this.shouldIgnore(src)) {
343 if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
344 this.just_created[src.path] = true;
345 return; // we do not handle file create flags... - use done hint.
347 // director has bee created
348 this.monitor(src.path);
351 since git does not really handle directory adds...
353 this.lastAdd = new Date();
354 this.action_queue.push({
361 [ src.gitpath, 'add' , src.vpath, { all: true } ],
362 [ src.gitpath, 'commit' , { all: true, message: src.vpath} ]
369 onAttributeChanged : function(src) {
371 if (this.shouldIgnore(src)) {
374 this.lastAdd = new Date();
378 // [ src.gitpath, 'commit' , src.vpath, { message: src.vpath} ]
380 this.action_queue.push({
389 onMoved : function(src,dest)
392 this.parsePath(dest);
394 if (src.gitpath != dest.gitpath) {
396 this.onCreated(dest);
397 this.onChangedDoneHint(dest);
400 // needs to handle move to/from unsupported types..
402 if (this.shouldIgnore(src)) {
405 if (this.shouldIgnore(dest)) {
408 this.lastAdd = new Date();
410 // [ src.gitpath, 'mv', '-k', src.vpath, dest.vpath ],
411 // [ src.gitpath, 'commit' , src.vpath, dest.vpath ,
412 // { message: 'MOVED ' + src.vpath +' to ' + dest.vpath} ]
415 this.action_queue.push({
431 function errorDialog(data) {
432 var msg = new Gtk.MessageDialog({
433 message_type: Gtk.MessageType.ERROR,
434 buttons : Gtk.ButtonsType.OK,
446 // need a better icon...
452 Notify.init("gitlive");
454 monitor.add(GLib.get_home_dir() + "/gitlive");
457 //icon.signal["activate"].connect(on_left_click);