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
33 GI = imports.gi.GIRepository
34 GLib = imports.gi.GLib;
36 // we add this in, as it appears to get lost sometimes if we set it using the ENV. variable in builder.sh
37 GI.IRepository.prepend_search_path(GLib.get_home_dir() + '/.Builder/girepository-1.1');
41 Notify = imports.gi.Notify;
43 Spawn = imports.Spawn;
45 StatusIcon = imports.StatusIcon.StatusIcon;
46 Monitor = imports.Monitor.Monitor;
49 //File = imports[__script_path__+'/../introspection-doc-generator/File.js'].File
50 Gtk.init (null, null);
52 var gitlive = GLib.get_home_dir() + "/gitlive";
54 if (!GLib.file_test(gitlive, GLib.FileTest.IS_DIR)) {
55 var msg = new Gtk.MessageDialog({message_type:
56 Gtk.MessageType.INFO, buttons : Gtk.ButtonsType.OK, text: "GIT Live - ~/gitlive does not exist."});
64 var monitor = new Monitor({
68 * action: 'add' | rm | update
81 this.lastAdd = new Date();
83 GLib.timeout_add(GLib.PRIORITY_LOW, 500, function() {
84 //TIMEOUT", _this.queue.length , _this.queueRunning].join(', '));
85 if (!_this.queue.length || _this.queueRunning) {
88 var last = Math.floor(((new Date()) - this.lastAdd) / 100);
89 if (last < 4) { // wait 1/2 a seconnd before running.
96 Monitor.prototype.start.call(this);
97 var notification = new Notify.Notification({
99 body : gitlive + "\nMonitoring " + this.monitors.length + " Directories"
102 notification.set_timeout(2000);
107 * - pulls the items off the queue
108 * (as commands run concurrently and new items may get added while it's running)
109 * - runs the queue items
115 this.queueRunning = true;
117 //this.queue.forEach(function (q) {
121 this.action_queue.forEach(function (q) {
124 //this.queue = []; // empty queue!
125 this.action_queue = [];
131 function readResult(sp) {
132 switch (sp.result * 1) {
134 success.push(sp.args.join(' '));
135 if (sp.output.length) success.push(sp.output + '');
136 // if (sp.stderr.length) success.push(sp.stderr + '');
139 failure.push(sp.args.join(' '));
140 if (sp.output.length) failure.push(sp.output);
141 if (sp.stderr.length) failure.push(sp.stderr);
146 cmds.forEach(function(cmd) {
147 // prevent duplicate calls..
148 if (done.indexOf(JSON.stringify(cmd)) > -1) {
151 done.push(JSON.stringify(cmd));
152 // --- we keep a list of repositories that will be pushed to at the end..
154 if (repos.indexOf(cmd.repos) < 0) {
155 repos.push(cmd.repos);
156 // Git.run(cmd.repos , 'pull'); // pull before we push!
159 var gp = gitlive + '/' + cmd.repo;
161 switch( cmd.action ) {
163 readResult(Git.run(gp, 'add', cmd.file ));
164 readResult(Git.run(gp, 'commit', src.file, { message: cmd.file} ));
168 readResult(Git.run(gp, 'rm', cmd.file ));
169 readResult(Git.run(gp, 'commit', { all: true, message: cmd.file} ));
173 readResult(Git.run(gp, 'commit', cmd.file , { message: cmd.file} ));
177 readResult(Git.run(gp, 'mv', cmd.file , cmd.target));
178 readResult(Git.run(gp, 'commit', cmd.file , cmd.target,
179 { message: 'MOVED ' + src.file +' to ' + dest.target } ));
188 repos.forEach(function(r) {
189 var sp = Git.run(gitlive + '/' +r , 'push', { all: true } );
196 if (success.length) {
197 print(success.join("\n"));
198 var notification = new Notify.Notification({
199 summary: "Git Live Commited",
200 body : success.join("\n")
204 notification.set_timeout(2000);
207 if (failure.length) {
209 var notification = new Notify.Notification({
210 summary: "Git Live ERROR!!",
211 body : failure.join("\n")
215 notification.set_timeout(5000); // show errros for longer
218 this.queueRunning = false;
221 shouldIgnore: function(f)
223 if (f.name[0] == '.') {
225 if (f.name == '.htaccess') {
231 if (f.name.match(/~$/)) {
234 // ignore anything in top level!!!!
235 if (!f.vpath.length) {
244 * set gitpath and vpath
249 parsePath: function(f)
252 var vpath_ar = f.path.substring(gitlive.length +1).split('/');
253 f.repo = vpath_ar.shift();
254 f.gitpath = gitlive + '/' + f.repo;
255 f.vpath = vpath_ar.join('/');
262 onChanged : function(src)
264 return; // always ignore this..?
265 //this.parsePath(src);
269 * results in git add + git commit..
275 onChangesDoneHint : function(src)
278 if (this.shouldIgnore(src)) {
283 if (typeof(this.just_created[src.path]) !='undefined') {
284 delete this.just_created[src.path];
285 this.lastAdd = new Date();
287 // [ src.gitpath, 'add', src.vpath ],
288 // [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ]
291 this.action_queue.push({
301 this.lastAdd = new Date();
303 // [ src.gitpath, 'add', src.vpath ],
304 // [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ]
308 this.action_queue.push({
316 onDeleted : function(src)
319 if (this.shouldIgnore(src)) {
322 // should check if monitor needs removing..
323 // it should also check if it was a directory.. - so we dont have to commit all..
325 this.lastAdd = new Date();
327 // [ src.gitpath, 'rm' , src.vpath ],
328 // [ src.gitpath, 'commit', { all: true, message: src.vpath} ]
331 this.action_queue.push({
338 onCreated : function(src)
341 if (this.shouldIgnore(src)) {
345 if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
346 this.just_created[src.path] = true;
347 return; // we do not handle file create flags... - use done hint.
349 // director has bee created
350 this.monitor(src.path);
353 since git does not really handle directory adds...
355 this.lastAdd = new Date();
356 this.action_queue.push({
363 [ src.gitpath, 'add' , src.vpath, { all: true } ],
364 [ src.gitpath, 'commit' , { all: true, message: src.vpath} ]
371 onAttributeChanged : function(src) {
373 if (this.shouldIgnore(src)) {
376 this.lastAdd = new Date();
380 // [ src.gitpath, 'commit' , src.vpath, { message: src.vpath} ]
382 this.action_queue.push({
391 onMoved : function(src,dest)
394 this.parsePath(dest);
396 if (src.gitpath != dest.gitpath) {
398 this.onCreated(dest);
399 this.onChangedDoneHint(dest);
402 // needs to handle move to/from unsupported types..
404 if (this.shouldIgnore(src)) {
407 if (this.shouldIgnore(dest)) {
410 this.lastAdd = new Date();
412 // [ src.gitpath, 'mv', '-k', src.vpath, dest.vpath ],
413 // [ src.gitpath, 'commit' , src.vpath, dest.vpath ,
414 // { message: 'MOVED ' + src.vpath +' to ' + dest.vpath} ]
417 this.action_queue.push({
433 function errorDialog(data) {
434 var msg = new Gtk.MessageDialog({
435 message_type: Gtk.MessageType.ERROR,
436 buttons : Gtk.ButtonsType.OK,
448 // need a better icon...
454 Notify.init("gitlive");
456 monitor.add(GLib.get_home_dir() + "/gitlive");
459 //icon.signal["activate"].connect(on_left_click);