GitRepo.vala
[gitlive] / GitRepo.vala
1
2 /**
3  * @class Scm.Git.Repo
4  *
5  * @extends Scm.Repo
6  * 
7  *
8  *
9  */
10 static GitRepo  _GitRepo; 
11  
12 public class GitRepo : Object
13 {
14      
15     public Gee.ArrayList<GitMonitorQueue> cmds;
16
17     public string name;
18     public string gitdir;
19     public string git_working_dir;
20     public bool debug = false;
21     public bool has_local_changes = false;
22     public string git_status;    
23     public string git_diff;        
24     public string ahead_or_behind = "";
25     
26     public Gee.HashMap<string,bool> ignore_files;
27     public GitBranch currentBranch;
28     public Gee.HashMap<string,GitBranch> branches; // accessed in GitBranch..
29         public RooTicket? activeTicket;
30     public  Gee.HashMap<string,GitRepo> cache;
31     
32     
33     
34         public static GitRepo singleton()
35     {
36         if (_GitRepo == null) {
37             _GitRepo = new GitRepo.single();
38             _GitRepo.cache = new Gee.HashMap<string,GitRepo>();
39         }
40         return _GitRepo;
41     }
42  
43     /**
44     * index of.. matching gitpath..
45     */
46     public static int indexOf( Array<GitRepo> repos, string gitpath) {
47         // make a fake object to compare against..
48         var test_repo = GitRepo.get(gitpath);
49         
50         for(var i =0; i < repos.length; i++) {
51             if (repos.index(i).gitdir == test_repo.gitdir) {
52                 return i;
53             }
54         }
55         return -1;
56     
57     }
58     
59
60     
61     
62     
63     public static   Array<GitRepo> list()
64     {
65
66         //if (GitRepo.list_cache !=  null) {
67         //    unowned  Array<GitRepo>    ret = GitRepo.list_cache;
68          //   return ret;
69         //}
70         var cache = GitRepo.singleton().cache;
71         var list_cache = new Array<GitRepo>();
72         
73         var dir = Environment.get_home_dir() + "/gitlive";
74         
75         var f = File.new_for_path(dir);
76         FileEnumerator file_enum;
77         try {
78             file_enum = f.enumerate_children(
79                 FileAttribute.STANDARD_DISPLAY_NAME + ","+ 
80                 FileAttribute.STANDARD_TYPE,
81                 FileQueryInfoFlags.NONE,
82                 null);
83         } catch (Error e) {
84             
85             return list_cache;
86             
87         }
88         
89         FileInfo next_file; 
90         
91         while (true) {
92             
93             try {
94                 next_file = file_enum.next_file(null);
95                 if (next_file == null) {
96                     break;
97                 }
98                 
99             } catch (Error e) {
100                 GLib.debug("Error: %s",e.message);
101                 break;
102             }
103          
104             //print("got a file " + next_file.sudo () + '?=' + Gio.FileType.DIRECTORY);
105             
106             if (next_file.get_file_type() !=  FileType.DIRECTORY) {
107                 next_file = null;
108                 continue;
109             }
110             
111             if (next_file.get_file_type() ==  FileType.SYMBOLIC_LINK) {
112                 next_file = null;
113                 continue;
114             }
115             
116             if (next_file.get_display_name()[0] == '.') {
117                 next_file = null;
118                 continue;
119             }
120             var sp = dir+"/"+next_file.get_display_name();
121            
122             var gitdir = dir + "/" + next_file.get_display_name() + "/.git";
123             
124             if (!FileUtils.test(gitdir, FileTest.IS_DIR)) {
125                 continue;
126             }
127             
128                 var rep =  GitRepo.get(  sp );
129                 list_cache.append_val(rep);             
130             
131         }
132     
133         return list_cache;
134          
135         }
136         
137         public static GitRepo get(string path) 
138         {
139                 var cache = GitRepo.singleton().cache;
140                 if (cache.has_key(path)) {
141                         return cache.get(path);
142                 }
143                 return new GitRepo(path);
144         }
145         
146     private GitRepo.single() {
147                 // used to create the signleton
148         }
149     /**
150      * constructor:
151      * 
152      * @param {Object} cfg - Configuration
153      *     (basically repopath is currently only critical one.)
154      *
155      */
156      
157     private GitRepo(string path) {
158         // cal parent?
159         this.name =   File.new_for_path(path).get_basename();
160         this.ignore_files = new Gee.HashMap<string,bool>();
161         
162         this.git_working_dir = path;
163         this.gitdir = path + "/.git";
164         if (!FileUtils.test(this.gitdir , FileTest.IS_DIR)) {
165             this.gitdir = path; // naked...
166         }
167         this.cmds = new  Gee.ArrayList<GitMonitorQueue> ();
168         
169                 var cache = GitRepo.singleton().cache;
170         //Repo.superclass.constructor.call(this,cfg);
171                 if ( !cache.has_key(path) ) {
172                         cache.set( path, this);
173         }
174         this.loadBranches();
175         this.loadActiveTicket();
176         this.loadStatus();
177     } 
178     
179     public bool is_master_branch()
180     {
181         // special branches that do not allow autopushing now...
182         return this.currentBranch.name == "master" || this.currentBranch.name == "roojs";
183                 
184     }
185     
186     public bool is_managed()
187     {
188         // is it a roojs origin?
189         var r = this.git({ "remote" , "get-url" , "--push" , "origin"});
190         var uri = new Soup.URI(r);
191         if (uri.get_host() != "git.roojs.com") { // we can only push to this url. -- unless we have forced it to be managed.
192                 return FileUtils.test(this.gitdir + "/.gitlive-managed" , FileTest.EXISTS);
193         }
194         // otherwise see if unmanaged is set to disable it..
195         return !FileUtils.test(this.gitdir + "/.gitlive-unmanaged" , FileTest.EXISTS);  
196
197     }
198     
199     
200     public bool is_autocommit ()
201     {           
202         return !FileUtils.test(this.gitdir + "/.gitlive-disable-autocommit" , FileTest.EXISTS);
203     }
204     public void set_autocommit(bool val)
205     {
206
207                 var cur = this.is_autocommit();
208                 GLib.debug("SET auto commit : %s <= %s", val ? "ON" : "OFF",  cur  ? "ON" : "OFF");
209                 if (cur == val) {
210                         return; // no change..
211                 }
212                 if (!val) {
213                         FileUtils.set_contents(this.gitdir + "/.gitlive-disable-autocommit" , "x");
214                 } else {
215                         // it exists...
216                         FileUtils.remove(this.gitdir + "/.gitlive-disable-autocommit" ); 
217                 }
218     
219     }
220     
221     public bool is_auto_branch ()
222     {
223         if (this.name == "gitlog") {
224                 return false;
225                 }
226                 // check remote...
227         
228         return FileUtils.test(this.gitdir + "/.gitlive-enable-auto-branch" , FileTest.EXISTS);
229     }
230     
231     public void set_auto_branch(bool val)
232     {
233
234                 var cur = this.is_auto_branch();
235                 GLib.debug("SET auto branch : %s <= %s", val ? "ON" : "OFF",  cur  ? "ON" : "OFF");
236                 
237                 if (cur == val) {
238                         return; // no change..
239                 }
240                 if (val) {
241                         FileUtils.set_contents(this.gitdir + "/.gitlive-enable-auto-branch" , "x");
242                 } else {
243                         // it exists...
244                         FileUtils.remove(this.gitdir + "/.gitlive-enable-auto-branch" ); 
245                 }
246     
247     }
248     public bool is_autopush ()
249     {
250         return !FileUtils.test(this.gitdir + "/.gitlive-disable-autopush" , FileTest.EXISTS);
251     }
252     public void set_autopush(bool val)
253     {
254
255                 var cur = this.is_autopush();
256                 GLib.debug("SET auto push : %s <= %s", val ? "ON" : "OFF",  cur  ? "ON" : "OFF");
257                 if (cur == val) {
258                         return; // no change..
259                 }
260                 if (!val) {
261                         FileUtils.set_contents(this.gitdir + "/.gitlive-disable-autopush" , "");
262                 } else {
263                         // it exists...
264                         FileUtils.remove(this.gitdir + "/.gitlive-disable-autopush" ); 
265                 }
266     
267     }
268     
269     
270         public void loadStatus()
271         {
272                 var r = this.git({ "status" , "--porcelain" });
273                 this.git_status = r;
274                 this.has_local_changes = r.length > 0;
275                 
276                 var rs = this.git({ "status" , "-sb" });
277
278                 this.ahead_or_behind = rs.contains("[ahead") ? "A" : (rs.contains("[behind") ? "B" : "");
279                 
280                 
281                 this.git_diff  = this.git({ "diff" , "HEAD", "--no-color" });
282         }    
283
284     
285     public void loadBranches()
286     {
287
288         GitBranch.loadBranches(this);
289     }
290      
291     
292     
293     
294     public string branchesToString()
295     {
296         var ret = "";
297                 foreach( var br in this.branches.values) {
298                         if (br.name == "") {
299                                 continue; 
300                         }
301                         ret += ret.length > 0 ? "\n"  : "";
302                         ret += br.name;
303                 
304                 }
305                 return ret;
306         
307     }
308      public static void doMerges(string action, string ticket_id, string commit_message)
309     {
310        GitMonitor.gitmonitor.stop();
311        
312        var commitrevs = "";
313        var sucess = true;
314        foreach(var  repo in GitRepo.singleton().cache.values) {
315                if (repo.activeTicket != null && repo.activeTicket.id == ticket_id) {
316                        var res = repo.doMerge(action,ticket_id, commit_message);
317                        if (!res) {
318                                sucess = false;
319                                continue;
320                        }
321                        commitrevs += commitrevs.length > 0 ? " " : "";
322                        commitrevs += repo.currentBranch.lastrev;
323                }
324        }
325        if (sucess && action == "CLOSE") {
326                RooTicket.singleton().getById(ticket_id).close(commitrevs);
327        }
328        GitMonitor.gitmonitor.start();
329     }
330      
331
332     public bool doMerge(string action, string ticket_id, string commit_message)
333     {
334        // in theory we should check to see if other repo's have got the same branch and merge all them at the same time.
335        // also need to decide which branch we will merge into?
336                    var ret = "";
337                    if (action == "CLOSE" || action == "LEAVE") {
338                                    
339                try {
340                    var oldbranch = this.currentBranch.name;
341                    this.setActiveTicket(null, "master");
342                            string [] cmd = { "merge",   "--squash",  oldbranch };
343                            this.git( cmd );
344                            cmd = { "commit",   "-a" , "-m",  commit_message };
345                            this.git( cmd );
346                            this.push();
347                            this.loadBranches(); // updates lastrev..
348                
349                        var notification = new Notify.Notification(
350                                "Merged branch %s to master".printf(oldbranch),
351                                "",
352                                 "dialog-information"
353                                
354                        );
355
356                        notification.set_timeout(5);
357                        notification.show();   
358                
359                // close ticket..
360                return true; 
361                
362            } catch (Error e) {
363
364                GitMonitor.gitmonitor.pauseError(e.message);
365                return false;
366            }
367            // error~?? -- show the error dialog...
368                    return false;
369        }
370        if (action == "MASTER") {
371                // merge master into ours..
372                        try {
373                        string[] cmd = { "merge",  "master" };
374                        this.git( cmd );
375                        var notification = new Notify.Notification(
376                                        "Merged code from master to %s".printf(this.currentBranch.name),
377                                        "",
378                                         "dialog-information"
379                                        
380                                );
381                                notification.set_timeout(5);
382                                notification.show();   
383                       
384                        return true;
385                        } catch (Error e) {
386                        GitMonitor.gitmonitor.pauseError(e.message);
387                        return false;
388                    }
389            }
390        if (action == "EXIT") {
391                        try {
392                        var oldbranch  = this.currentBranch.name;
393                          this.setActiveTicket(null, "master");
394                        this.loadBranches();
395                        var notification = new Notify.Notification(
396                                        "Left branch %s".printf(oldbranch),
397                                        "",
398                                         "dialog-information"
399                                        
400                                );
401                                notification.set_timeout(5);
402                                notification.show();   
403                        
404                        return true;
405                    } catch (Error e) {
406                        GitMonitor.gitmonitor.pauseError(e.message);
407
408                        return false;                   
409                    }
410                    // error~?? -- show the error dialog...
411
412        }
413        return false;
414     }
415         
416     public void loadActiveTicket()
417     {
418         this.activeTicket = null;
419         if (!FileUtils.test(this.gitdir + "/.gitlive-active-ticket" , FileTest.EXISTS)) {
420                 return;
421         }
422         string ticket_id;
423         FileUtils.get_contents(this.gitdir + "/.gitlive-active-ticket" , out ticket_id);  
424         if (ticket_id.length < 1) {
425                 return;
426                 }
427                 this.activeTicket = RooTicket.singleton().getById(ticket_id.strip());
428         
429         
430     }
431     
432     
433     
434     public bool setActiveTicket(RooTicket? ticket, string branchname)
435     {
436         if (!this.createBranchNamed(branchname)) {
437                 return false;
438                 }
439                 if (ticket != null) {
440                 FileUtils.set_contents(this.gitdir + "/.gitlive-active-ticket" , ticket.id);
441         } else {
442                 FileUtils.remove(this.gitdir + "/.gitlive-active-ticket" );
443         }
444         this.activeTicket = ticket;
445         return true;
446     }
447     
448     public bool createBranchNamed(string branchname)
449     {   
450                 
451
452                      if (this.branches.has_key(branchname)) {
453                         this.switchToExistingBranchNamed(branchname);
454                     
455                     } else {
456                                  this.createNewBranchNamed(branchname); 
457                             
458                     }
459                        var notification = new Notify.Notification(
460                        "Changed to branch %s".printf(branchname),
461                        "",
462                         "dialog-information"
463                        
464                );
465
466                notification.set_timeout(5);
467                notification.show();   
468        
469          
470          this.loadBranches(); // update branch list...
471          //GitMonitor.gitmonitor.runQueue(); // no point - we have hidden the queue..
472          return true;
473     }
474      bool switchToExistingBranchNamed(string branchname)
475      {
476                 var stash = false;
477                                          // this is where it get's tricky...
478                 string files = "";
479                 try {                   
480                                 string[] cmd = { "ls-files" ,  "-m" };                   // list the modified files..
481                                 files = this.git(cmd);
482                                 stash = files.length> 1 ;
483                                 
484                                 
485                                 cmd = { "stash" };                      
486                                 if (stash) { this.git(cmd); }
487                                 
488                                 this.pull();
489                                 
490                                 cmd = { "checkout", branchname  };
491                                 this.git(cmd);
492                   } catch(Error e) {
493                                 GitMonitor.gitmonitor.pauseError(e.message);
494                                 return false;           
495                   }
496                 try {
497                    if (branchname != "master") {
498                        string[] cmd = { "merge", "master"  };
499                             this.git(cmd);
500                             this.push();
501                        
502                     }
503                     
504                 } catch(Error e) {
505                     string[] cmd = { "checkout", "master"  };
506                     this.git(cmd);
507                         GitMonitor.gitmonitor.pauseError(
508                                 "Use\n\na) git checkout %s\nb) git mergetool\nc) git commit\nd) git push\n d) stash pop \ne) start gitlive again\n".printf(
509                                         branchname)
510                                  + e.message
511                         );
512                         return false;           
513                  
514                 }
515                 try {                                   
516                     string[]  cmd = { "stash", "pop"  };
517                     if (stash) { 
518                         this.git(cmd); 
519                         var fl = files.split("\n");
520                         cmd = { "commit", "-m" , "Changed " + string.joinv("",fl) };
521                         foreach(var f in fl) {
522                                 if (f.length < 1) continue;
523                                 cmd += f;
524                         }
525                         this.git(cmd);                              
526                 }
527              
528
529                    
530                 } catch(Error ee) {
531                         GitMonitor.gitmonitor.pauseError(ee.message);
532                         return false;           
533                 }
534        this.push();
535        return true;                             
536                  
537      }
538     
539     
540     
541      bool createNewBranchNamed(string branchname)
542      {
543                 var stash = false;
544                  try {                                  
545                                 string[] cmd = { "ls-files" ,  "-m" };                   // list the modified files..
546                                 var files = this.git(cmd);
547                                 stash = files.length> 1 ;
548                         
549                          cmd = { "checkout", "-b" , branchname  };
550                         this.git(cmd);
551
552                cmd = { "push", "-u" , "origin" ,"HEAD"  };
553                         this.git(cmd);
554                                 if (stash) { 
555
556                                 var fl = files.split("\n");
557                                 cmd = { "commit", "-m" , "Changed " + string.joinv("",fl) };
558                                 foreach(var f in fl) {
559                                         if (f.length < 1) continue;
560                                         cmd += f;
561                                 }
562                                 this.git(cmd);  
563                                 this.push();                        
564                         }
565
566              
567                 } catch(Error ee) {
568                                 GitMonitor.gitmonitor.pauseError(ee.message);
569                                 return false;           
570                         }
571                         return true;
572      
573      }
574     
575     
576     
577     /**
578      * add:
579      * add files to track.
580      *
581      * @argument {Array} files the files to add.
582      */
583     public string add ( Gee.ArrayList<GitMonitorQueue> files ) throws Error, SpawnError
584     {
585         // should really find out if these are untracked files each..
586         // we run multiple versions to make sure that if one failes, it does not ignore the whole lot..
587         // not sure if that is how git works.. but just be certian.
588         var ret = "";
589         for (var i = 0; i < files.size;i++) {
590             var f = files.get(i).vname;
591             try {
592                 string[] cmd = { "add",    f  };
593                 this.git( cmd );
594             } catch (Error e) {
595                 ret += e.message  + "\n";
596             }        
597
598         }
599         return ret;
600     }
601         
602     public bool is_ignore(string fname) throws Error, SpawnError
603     {
604                 if (fname == ".gitignore") {
605                         this.ignore_files.clear();
606                 }
607                 
608                 if (this.ignore_files.has_key(fname)) {
609                         return this.ignore_files.get(fname);
610                 }
611                 
612                 try {
613                         var ret = this.git( { "check-ignore" , fname } );
614                         this.ignore_files.set(fname, ret.length >  0);
615                         return ret.length > 0;
616                 } catch (SpawnError e) {
617                         this.ignore_files.set(fname, false);
618                         return false;
619                 }
620                  
621     } 
622     
623     
624       /**
625      * remove:
626      * remove files to track.
627      *
628      * @argument {Array} files the files to add.
629      */
630     public string remove  ( Gee.ArrayList<GitMonitorQueue> files ) throws Error, SpawnError
631     {
632         // this may fail if files do not exist..
633         // should really find out if these are untracked files each..
634         // we run multiple versions to make sure that if one failes, it does not ignore the whole lot..
635         // not sure if that is how git works.. but just be certian.
636         var ret = "";
637
638         for (var i = 0; i < files.size;i++) {
639             var f = files.get(i).vname;
640             try {
641                 string[] cmd = { "rm",  "-f" ,  f  };
642                 this.git( cmd );
643             } catch (Error e) {
644                 ret += e.message  + "\n";
645             }        
646         }
647
648         return ret;
649
650     }
651     
652     
653     /**
654      * commit:
655      * perform a commit.
656      *
657      * @argument {Object} cfg commit configuration
658      * 
659      * @property {String} name (optional)
660      * @property {String} email (optional)
661      * @property {String} changed (date) (optional)
662      * @property {String} reason (optional)
663      * @property {Array} files - the files that have changed. 
664      * 
665      */
666      
667     public string commit ( string message, Gee.ArrayList<GitMonitorQueue> files  ) throws Error, SpawnError
668     {
669         
670
671         /*
672         var env = [];
673
674         if (typeof(cfg.name) != 'undefined') {
675             args.push( {
676                 'author' : cfg.name + ' <' + cfg.email + '>'
677             });
678             env.push(
679                 "GIT_COMMITTER_NAME" + cfg.name,
680                 "GIT_COMMITTER_EMAIL" + cfg.email
681             );
682         }
683
684         if (typeof(cfg.changed) != 'undefined') {
685             env.push("GIT_AUTHOR_DATE= " + cfg.changed )
686             
687         }
688         */
689         string[] args = { "commit", "-m" };
690         args +=  (message.length > 0  ? message : "Changed" );
691         for (var i = 0; i< files.size ; i++ ) {
692             args += files.get(i).vname; // full path?
693         }
694          
695         return this.git(args);
696     }
697     
698     /**
699      * pull:
700      * Fetch and merge remote repo changes into current branch..
701      *
702      * At present we just need this to update the current working branch..
703      * -- maybe later it will have a few options and do more stuff..
704      *
705      */
706     public string pull () throws Error, SpawnError
707     {
708         // should probably hand error conditions better... 
709         string[] cmd = { "pull" , "--no-edit" };
710         return this.git( cmd );
711
712         
713     }
714     
715     public delegate void GitAsyncCallback (GitRepo repo, int err, string str);
716     public void pull_async(GitAsyncCallback cb) 
717     {
718     
719          string[] cmd = { "pull" , "--no-edit" };
720          this.git_async( cmd , cb);
721          
722     
723     }
724     
725     /**
726      * push:
727      * Send local changes to remote repo(s)
728      *
729      * At present we just need this to push the current branch.
730      * -- maybe later it will have a few options and do more stuff..
731      *
732      */
733     public string push () throws Error, SpawnError
734     {
735         // should 
736         return this.git({ "push"  });
737         
738     }
739     
740     
741     
742      /**
743      * git:
744      * The meaty part.. run spawn.. with git..
745      *
746      *
747      */
748     
749     public string git(string[] args_in ) throws Error, SpawnError
750     {
751         // convert arguments.
752         
753         string[]  args = { "git" };
754         //args +=  "--git-dir";
755         //args +=  this.gitdir;
756         args +=  "--no-pager";
757  
758  
759         //if (this.gitdir != this.repopath) {
760         //    args +=   "--work-tree";
761          //   args += this.repopath; 
762         //}
763         for (var i = 0; i < args_in.length;i++) {
764             args += args_in[i];
765         }            
766
767         //this.lastCmd = args.join(" ");
768         //if(this.debug) {
769             GLib.debug( "CWD=%s",  this.git_working_dir ); 
770             GLib.debug( "cmd: %s", string.joinv (" ", args)); 
771         //}
772
773         string[]   env = {};
774         string  home = "HOME=" + Environment.get_home_dir() ;
775         env +=  home ;
776         // do not need to set gitpath..
777         //if (File.exists(this.repo + '/.git/config')) {
778             //env.push("GITPATH=" + this.repo );
779         //}
780           
781         var cfg = new SpawnConfig(this.git_working_dir , args , env);
782         //cfg.debug = true;
783
784        // may throw error...
785         var sp = new Spawn(cfg);
786       
787         // diff output is a bit big..
788                 if (args_in[0] != "diff") {
789                 GLib.debug( "GOT: %s" , sp.output);
790         }
791         // parse output for some commands ?
792         return sp.output;
793     }
794         
795    unowned GitAsyncCallback git_async_on_callback;
796         public void  git_async( string[] args_in,   GitAsyncCallback cb ) throws Error, SpawnError
797     {
798         // convert arguments.
799        this.git_async_on_callback = cb;
800         string[]  args = { "git" };
801         //args +=  "--git-dir";
802         //args +=  this.gitdir;
803         args +=  "--no-pager";
804  
805  
806         //if (this.gitdir != this.repopath) {
807         //    args +=   "--work-tree";
808          //   args += this.repopath; 
809         //}
810         for (var i = 0; i < args_in.length;i++) {
811             args += args_in[i];
812         }            
813
814         //this.lastCmd = args.join(" ");
815         //if(this.debug) {
816             GLib.debug( "CWD=%s",  this.git_working_dir ); 
817             //print( "cmd: %s\n", string.joinv (" ", args)); 
818         //}
819
820         string[]   env = {};
821         string  home = "HOME=" + Environment.get_home_dir() ;
822         env +=  home ;
823         // do not need to set gitpath..
824         //if (File.exists(this.repo + '/.git/config')) {
825             //env.push("GITPATH=" + this.repo );
826         //}
827         
828
829         var cfg = new SpawnConfig(this.git_working_dir , args , env);
830         cfg.async = true;
831        
832
833        // may throw error...
834         var sp = new Spawn(cfg);
835                 //sp.ref();
836         //this.ref();
837         sp.run(this.git_async_on_complete); 
838          
839     }
840     
841     void git_async_on_complete(int err, string output)
842     {
843                 GLib.debug("GOT %d : %s", err, output);
844                 this.git_async_on_callback(this, err, output);
845 //              this.unref();   
846         //      sp.unref();             
847     
848     
849     }
850     
851  
852          
853     
854  
855     public void update_async(GitAsyncCallback cb) 
856     {
857          string[] cmd = { "fetch" , "--all" };
858          this.git_async( cmd , cb);
859          
860     }
861     
862     
863     static uint update_all_total = 0;
864     static string update_all_after = "";
865      
866     public static void updateAll(string after)
867     {
868                 update_all_after = after;
869                 var tr =  GitRepo.singleton().cache;
870             
871         
872        update_all_total = tr.size;
873        foreach(var repo  in tr.values) {
874                 if (!repo.is_managed()) {
875                         update_all_total--;                     
876                         continue;
877                 }
878            repo.update_async(updateAllCallback); 
879         } 
880
881     }
882     public static void  updateAllCallback(GitRepo repo, int err, string res)
883     {
884         repo.loadBranches();
885         repo.loadStatus();
886         
887         update_all_total--;
888         if (update_all_total > 0 ) {
889                 return;
890                 }
891                 switch (update_all_after) {
892                         case "show_clones":
893                                 Clones.singleton().show();
894                                 break;
895                         default:
896                                 break;
897                 }
898                 return;
899     }
900     
901     
902     
903 }