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 need to add a gitlive branch on the remote server..
21 * git branch gitlive (in the repo..)
23 * we clone directory into gitlive_feature/XXXXX
24 * git branch issue_XXX
25 * git checkout issue_XXX
27 * run this on the feature branch it merges and commits..
28 * git pull origin master << or gitlive..
34 GI = imports.gi.GIRepository
35 GLib = imports.gi.GLib;
37 // we add this in, as it appears to get lost sometimes if we set it using the ENV. variable in builder.sh
38 GI.IRepository.prepend_search_path(GLib.get_home_dir() + '/.Builder/girepository-1.1');
42 Notify = imports.gi.Notify;
44 Spawn = imports.Spawn;
46 StatusIcon = imports.StatusIcon.StatusIcon;
47 Monitor = imports.Monitor.Monitor;
50 //File = imports[__script_path__+'/../introspection-doc-generator/File.js'].File
51 Gtk.init (null, null);
53 var gitlive = GLib.get_home_dir() + "/gitlive";
55 if (!GLib.file_test(gitlive, GLib.FileTest.IS_DIR)) {
56 var msg = new Gtk.MessageDialog({message_type:
57 Gtk.MessageType.INFO, buttons : Gtk.ButtonsType.OK, text: "GIT Live - ~/gitlive does not exist."});
65 var monitor = new Monitor({
69 * action: 'add' | rm | update
82 this.lastAdd = new Date();
84 GLib.timeout_add(GLib.PRIORITY_LOW, 500, function() {
85 //TIMEOUT", _this.queue.length , _this.queueRunning].join(', '));
86 if (!_this.queue.length || _this.queueRunning) {
89 var last = Math.floor(((new Date()) - this.lastAdd) / 100);
90 if (last < 4) { // wait 1/2 a seconnd before running.
97 Monitor.prototype.start.call(this);
98 var notification = new Notify.Notification({
100 body : gitlive + "\nMonitoring " + this.monitors.length + " Directories"
103 notification.set_timeout(2000);
108 * - pulls the items off the queue
109 * (as commands run concurrently and new items may get added while it's running)
110 * - runs the queue items
116 this.queueRunning = true;
118 //this.queue.forEach(function (q) {
122 this.action_queue.forEach(function (q) {
125 //this.queue = []; // empty queue!
126 this.action_queue = [];
132 function readResult(sp) {
133 switch (sp.result * 1) {
135 success.push(sp.args.join(' '));
136 if (sp.output.length) success.push(sp.output + '');
137 // if (sp.stderr.length) success.push(sp.stderr + '');
140 failure.push(sp.args.join(' '));
141 if (sp.output.length) failure.push(sp.output);
142 if (sp.stderr.length) failure.push(sp.stderr);
147 cmds.forEach(function(cmd) {
148 // prevent duplicate calls..
149 if (done.indexOf(JSON.stringify(cmd)) > -1) {
152 done.push(JSON.stringify(cmd));
153 // --- we keep a list of repositories that will be pushed to at the end..
155 if (repos.indexOf(cmd.repos) < 0) {
156 repos.push(cmd.repos);
157 // Git.run(cmd.repos , 'pull'); // pull before we push!
160 var gp = gitlive + '/' + cmd.repo;
162 switch( cmd.action ) {
164 readResult(Git.run(gp, 'add', cmd.file ));
165 readResult(Git.run(gp, 'commit', src.file, { message: cmd.file} ));
169 readResult(Git.run(gp, 'rm', cmd.file ));
170 readResult(Git.run(gp, 'commit', { all: true, message: cmd.file} ));
174 readResult(Git.run(gp, 'commit', cmd.file , { message: cmd.file} ));
178 readResult(Git.run(gp, 'mv', cmd.file , cmd.target));
179 readResult(Git.run(gp, 'commit', cmd.file , cmd.target,
180 { message: 'MOVED ' + src.file +' to ' + dest.target } ));
189 repos.forEach(function(r) {
190 var sp = Git.run(gitlive + '/' +r , 'push', { all: true } );
197 if (success.length) {
198 print(success.join("\n"));
199 var notification = new Notify.Notification({
200 summary: "Git Live Commited",
201 body : success.join("\n")
205 notification.set_timeout(2000);
208 if (failure.length) {
210 var notification = new Notify.Notification({
211 summary: "Git Live ERROR!!",
212 body : failure.join("\n")
216 notification.set_timeout(5000); // show errros for longer
219 this.queueRunning = false;
222 shouldIgnore: function(f)
224 if (f.name[0] == '.') {
226 if (f.name == '.htaccess') {
232 if (f.name.match(/~$/)) {
235 // ignore anything in top level!!!!
236 if (!f.vpath.length) {
245 * set gitpath and vpath
250 parsePath: function(f)
253 var vpath_ar = f.path.substring(gitlive.length +1).split('/');
254 f.repo = vpath_ar.shift();
255 f.gitpath = gitlive + '/' + f.repo;
256 f.vpath = vpath_ar.join('/');
263 onChanged : function(src)
265 return; // always ignore this..?
266 //this.parsePath(src);
270 * results in git add + git commit..
276 onChangesDoneHint : function(src)
279 if (this.shouldIgnore(src)) {
284 if (typeof(this.just_created[src.path]) !='undefined') {
285 delete this.just_created[src.path];
286 this.lastAdd = new Date();
288 // [ src.gitpath, 'add', src.vpath ],
289 // [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ]
292 this.action_queue.push({
302 this.lastAdd = new Date();
304 // [ src.gitpath, 'add', src.vpath ],
305 // [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ]
309 this.action_queue.push({
317 onDeleted : function(src)
320 if (this.shouldIgnore(src)) {
323 // should check if monitor needs removing..
324 // it should also check if it was a directory.. - so we dont have to commit all..
326 this.lastAdd = new Date();
328 // [ src.gitpath, 'rm' , src.vpath ],
329 // [ src.gitpath, 'commit', { all: true, message: src.vpath} ]
332 this.action_queue.push({
339 onCreated : function(src)
342 if (this.shouldIgnore(src)) {
346 if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
347 this.just_created[src.path] = true;
348 return; // we do not handle file create flags... - use done hint.
350 // director has bee created
351 this.monitor(src.path);
354 since git does not really handle directory adds...
356 this.lastAdd = new Date();
357 this.action_queue.push({
364 [ src.gitpath, 'add' , src.vpath, { all: true } ],
365 [ src.gitpath, 'commit' , { all: true, message: src.vpath} ]
372 onAttributeChanged : function(src) {
374 if (this.shouldIgnore(src)) {
377 this.lastAdd = new Date();
381 // [ src.gitpath, 'commit' , src.vpath, { message: src.vpath} ]
383 this.action_queue.push({
392 onMoved : function(src,dest)
395 this.parsePath(dest);
397 if (src.gitpath != dest.gitpath) {
399 this.onCreated(dest);
400 this.onChangedDoneHint(dest);
403 // needs to handle move to/from unsupported types..
405 if (this.shouldIgnore(src)) {
408 if (this.shouldIgnore(dest)) {
411 this.lastAdd = new Date();
413 // [ src.gitpath, 'mv', '-k', src.vpath, dest.vpath ],
414 // [ src.gitpath, 'commit' , src.vpath, dest.vpath ,
415 // { message: 'MOVED ' + src.vpath +' to ' + dest.vpath} ]
418 this.action_queue.push({
434 function errorDialog(data) {
435 var msg = new Gtk.MessageDialog({
436 message_type: Gtk.MessageType.ERROR,
437 buttons : Gtk.ButtonsType.OK,
449 // need a better icon...
455 Notify.init("gitlive");
457 monitor.add(GLib.get_home_dir() + "/gitlive");
460 //icon.signal["activate"].connect(on_left_click);