2 var Gio = imports.gi.Gio;
3 var Gtk = imports.gi.Gtk;
4 var Notify = imports.gi.Notify;
5 var GLib = imports.gi.GLib;
7 var Spawn = imports.Spawn;
8 var StatusIcon = imports.StatusIcon.StatusIcon;
9 var Monitor = imports.Monitor.Monitor;
13 var GitMonitor = new Monitor({
16 * @property {String} the "gitlive" directory, normally ~/gitlive
17 * dset by OWNER... - we should do this as a CTOR.
28 this.lastAdd = new Date();
30 this.top.forEach(this.monitor, this);
32 GLib.timeout_add(GLib.PRIORITY_LOW, 500, function() {
33 //TIMEOUT", _this.queue.length , _this.queueRunning].join(', '));
34 if (!_this.queue.length || _this.queueRunning) {
37 var last = Math.floor(((new Date()) - this.lastAdd) / 100);
38 if (last < 4) { // wait 1/2 a seconnd before running.
46 var notification = new Notify.Notification({
48 body : this.gitlive + "\nMonitoring " + this.monitors.length + " Directories",
52 notification.set_timeout(5);
62 * - pulls the items off the queue
63 * (as commands run concurrently and new items may get added while it's running)
64 * - runs the queue items
70 this.queueRunning = true;
72 this.queue.forEach(function (q) {
75 this.queue = []; // empty queue!
82 // first build a array of repo's to work with
87 //print(JSON.stringify(cmds));
89 cmds.forEach(function(cmd) {
90 var gitpath = cmd.shift();
91 if (typeof(repo_list[gitpath]) == 'undefined') {
92 repo_list[gitpath] = new imports.Scm.Git.Repo.Repo( { repopath : gitpath });
93 repo_list[gitpath].cmds = [];
94 repo_list[gitpath].pull();
96 repo_list[gitpath].cmds.push(cmd);
99 // build add, remove and commit message list..
102 for (var gitpath in repo_list) {
103 var repo = repo_list[gitpath];
105 var remove_files = [];
107 repo.cmds.forEach(function(cmd) {
108 //print(JSON.stringify(cmd));
109 var name = cmd.shift();
110 var arg = cmd.shift();
114 if (add_files.indexOf(arg) > -1) break;
119 remove_files.push(arg);
123 messages.push(arg.message);
128 // these can fail... at present... as we wildcard stuff.
130 repo.remove(remove_files);
133 success.push(repo.commit({
134 reason : messages.join("\n"),
137 success.push(repo.push());
140 failure.push(e.message);
145 // finally merge all the commit messages.
148 // catch notification failures.. so we can carry on..
149 if (success.length) {
150 print(success.join("\n"));
152 var notification = new Notify.Notification({
153 summary: "Git Live Commited",
154 body : success.join("\n"),
159 notification.set_timeout(5);
163 if (failure.length) {
165 var notification = new Notify.Notification({
166 summary: "Git Live ERROR!!",
167 body : failure.join("\n"),
172 notification.set_timeout(5); // show errros for longer
179 this.queueRunning = false;
182 shouldIgnore: function(f)
184 if (f.name[0] == '.') {
186 if (f.name == '.htaccess') {
192 if (f.name.match(/~$/)) {
195 // ignore anything in top level!!!!
196 if (!f.vpath.length) {
205 * Fill in gitlive, vpath and repo
208 parsePath: function(f)
211 var vpath_ar = f.path.substring(this.gitlive.length +1).split('/');
213 f.gitpath = this.gitlive + '/' + vpath_ar.shift();
214 f.vpath = vpath_ar.join('/');
215 //f.repo = new imports.Scm.Git.Repo({ repopath: f.gitpath })
222 onChanged : function(src)
224 return; // always ignore this..?
225 //this.parsePath(src);
232 * results in git add + git commit..
235 onChangesDoneHint : function(src)
238 if (this.shouldIgnore(src)) {
244 if (typeof(this.just_created[src.path]) !='undefined') {
245 delete this.just_created[src.path];
246 this.lastAdd = new Date();
248 [ src.gitpath, 'add', src.vpath ],
249 [ src.gitpath, 'commit', { message: src.vpath} ]
255 this.lastAdd = new Date();
257 [ src.gitpath, 'add', src.vpath ],
258 [ src.gitpath, 'commit', { message: src.vpath} ]
263 onDeleted : function(src)
266 if (this.shouldIgnore(src)) {
269 // should check if monitor needs removing..
270 // it should also check if it was a directory.. - so we dont have to commit all..
272 this.lastAdd = new Date();
274 [ src.gitpath, 'rm' , src.vpath ],
275 [ src.gitpath, 'commit', { all: true, message: src.vpath} ]
281 onCreated : function(src)
284 if (this.shouldIgnore(src)) {
288 if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
289 this.just_created[src.path] = true;
290 return; // we do not handle file create flags... - use done hint.
292 // director has bee created
293 this.monitor(src.path);
294 this.lastAdd = new Date();
296 [ src.gitpath, 'add' , src.vpath, { all: true } ],
297 [ src.gitpath, 'commit' , { all: true, message: src.vpath} ]
303 onAttributeChanged : function(src) {
305 if (this.shouldIgnore(src)) {
308 this.lastAdd = new Date();
311 //[ src.gitpath, 'commit' , src.vpath, { message: src.vpath} ]
312 [ src.gitpath, 'add' , src.vpath ],
313 [ src.gitpath, 'commit' , { message: "Attribute Changed :" + src.vpath} ]
319 onMoved : function(src,dest)
322 this.parsePath(dest);
324 if (src.gitpath != dest.gitpath) {
326 this.onCreated(dest);
327 this.onChangedDoneHint(dest);
330 // needs to handle move to/from unsupported types..
332 if (this.shouldIgnore(src)) {
335 if (this.shouldIgnore(dest)) {
338 this.lastAdd = new Date();
340 // [ src.gitpath, 'mv', '-k', src.vpath, dest.vpath ],
341 [ src.gitpath, 'add', dest.vpath ],
342 [ src.gitpath, 'rm', src.vpath ],
344 [ src.gitpath, 'commit' ,
345 { message: 'MOVED ' + src.vpath +' to ' + dest.vpath}