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