Partial Fix #5560 - Gitlive - branching wip
[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_wip_branch()
180     {
181         return this.currentBranch.name.has_prefix("wip_");
182                 
183     }
184     
185     public bool is_managed()
186     {
187         // is it a roojs origin?
188         var r = this.git({ "remote" , "get-url" , "--push" , "origin"});
189         var uri = new Soup.URI(r);
190         if (uri.get_host() != "git.roojs.com") { // we can only push to this url. -- unless we have forced it to be managed.
191                 return FileUtils.test(this.gitdir + "/.gitlive-managed" , FileTest.EXISTS);
192         }
193         // otherwise see if unmanaged is set to disable it..
194         return !FileUtils.test(this.gitdir + "/.gitlive-unmanaged" , FileTest.EXISTS);  
195
196     }
197     
198     
199     public bool is_autocommit ()
200     {
201         return !FileUtils.test(this.gitdir + "/.gitlive-disable-autocommit" , FileTest.EXISTS);
202     }
203     public void set_autocommit(bool val)
204     {
205
206                 var cur = this.is_autocommit();
207                 GLib.debug("SET auto commit : %s <= %s", val ? "ON" : "OFF",  cur  ? "ON" : "OFF");
208                 if (cur == val) {
209                         return; // no change..
210                 }
211                 if (!val) {
212                         FileUtils.set_contents(this.gitdir + "/.gitlive-disable-autocommit" , "x");
213                 } else {
214                         // it exists...
215                         FileUtils.remove(this.gitdir + "/.gitlive-disable-autocommit" ); 
216                 }
217     
218     }
219     
220     public bool is_auto_branch ()
221     {
222         return FileUtils.test(this.gitdir + "/.gitlive-enable-auto-branch" , FileTest.EXISTS);
223     }
224     
225     public void set_auto_branch(bool val)
226     {
227
228                 var cur = this.is_auto_branch();
229                 GLib.debug("SET auto branch : %s <= %s", val ? "ON" : "OFF",  cur  ? "ON" : "OFF");
230                 
231                 if (cur == val) {
232                         return; // no change..
233                 }
234                 if (val) {
235                         FileUtils.set_contents(this.gitdir + "/.gitlive-enable-auto-branch" , "x");
236                 } else {
237                         // it exists...
238                         FileUtils.remove(this.gitdir + "/.gitlive-enable-auto-branch" ); 
239                 }
240     
241     }
242     public bool is_autopush ()
243     {
244         return !FileUtils.test(this.gitdir + "/.gitlive-disable-autopush" , FileTest.EXISTS);
245     }
246     public void set_autopush(bool val)
247     {
248
249                 var cur = this.is_autopush();
250                 GLib.debug("SET auto push : %s <= %s", val ? "ON" : "OFF",  cur  ? "ON" : "OFF");
251                 if (cur == val) {
252                         return; // no change..
253                 }
254                 if (!val) {
255                         FileUtils.set_contents(this.gitdir + "/.gitlive-disable-autopush" , "");
256                 } else {
257                         // it exists...
258                         FileUtils.remove(this.gitdir + "/.gitlive-disable-autopush" ); 
259                 }
260     
261     }
262     
263     
264         public void loadStatus()
265         {
266                 var r = this.git({ "status" , "--porcelain" });
267                 this.git_status = r;
268                 this.has_local_changes = r.length > 0;
269                 
270                 var rs = this.git({ "status" , "-sb" });
271
272                 this.ahead_or_behind = rs.contains("[ahead") ? "A" : (rs.contains("[behind") ? "B" : "");
273                 
274                 
275                 this.git_diff  = this.git({ "diff" , "HEAD", "--no-color" });
276         }    
277
278     
279     public void loadBranches()
280     {
281
282         GitBranch.loadBranches(this);
283     }
284      
285     
286     
287     
288     public string branchesToString()
289     {
290         var ret = "";
291                 foreach( var br in this.branches.values) {
292                         if (br.name == "") {
293                                 continue; 
294                         }
295                         ret += ret.length > 0 ? "\n"  : "";
296                         ret += br.name;
297                 
298                 }
299                 return ret;
300         
301     }
302      public static void doMerges(string action, string ticket_id, string commit_message)
303     {
304        GitMonitor.gitmonitor.stop();
305        
306        var commitrevs = "";
307        var sucess = true;
308        foreach(var  repo in GitRepo.singleton().cache.values) {
309                if (repo.activeTicket != null && repo.activeTicket.id == ticket_id) {
310                        var res = repo.doMerge(action,ticket_id, commit_message);
311                        if (!res) {
312                                sucess = false;
313                                continue;
314                        }
315                        commitrevs += commitrevs.length > 0 ? " " : "";
316                        commitrevs += repo.currentBranch.lastrev;
317                }
318        }
319        if (sucess && action == "CLOSE") {
320                RooTicket.singleton().getById(ticket_id).close(commitrevs);
321        }
322        GitMonitor.gitmonitor.start();
323     }
324      
325
326     public bool doMerge(string action, string ticket_id, string commit_message)
327     {
328        // in theory we should check to see if other repo's have got the same branch and merge all them at the same time.
329        // also need to decide which branch we will merge into?
330                    var ret = "";
331                    if (action == "CLOSE" || action == "LEAVE") {
332                                    
333                try {
334                    var oldbranch = this.currentBranch.name;
335                    this.setActiveTicket(null, "master");
336                            string [] cmd = { "merge",   "--squash",  oldbranch };
337                            this.git( cmd );
338                            cmd = { "commit",   "-a" , "-m",  commit_message };
339                            this.git( cmd );
340                            this.push();
341                            this.loadBranches(); // updates lastrev..
342                
343                        var notification = new Notify.Notification(
344                                "Merged branch %s to master".printf(oldbranch),
345                                "",
346                                 "dialog-information"
347                                
348                        );
349
350                        notification.set_timeout(5);
351                        notification.show();   
352                
353                // close ticket..
354                return true; 
355                
356            } catch (Error e) {
357
358                GitMonitor.gitmonitor.pauseError(e.message);
359                return false;
360            }
361            // error~?? -- show the error dialog...
362                    return false;
363        }
364        if (action == "MASTER") {
365                // merge master into ours..
366                        try {
367                        string[] cmd = { "merge",  "master" };
368                        this.git( cmd );
369                        var notification = new Notify.Notification(
370                                        "Merged code from master to %s".printf(this.currentBranch.name),
371                                        "",
372                                         "dialog-information"
373                                        
374                                );
375                                notification.set_timeout(5);
376                                notification.show();   
377                       
378                        return true;
379                        } catch (Error e) {
380                        GitMonitor.gitmonitor.pauseError(e.message);
381                        return false;
382                    }
383            }
384        if (action == "EXIT") {
385                        try {
386                        var oldbranch  = this.currentBranch.name;
387                          this.setActiveTicket(null, "master");
388                        this.loadBranches();
389                        var notification = new Notify.Notification(
390                                        "Left branch %s".printf(oldbranch),
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
402                        return false;                   
403                    }
404                    // error~?? -- show the error dialog...
405
406        }
407        return false;
408     }
409         
410     public void loadActiveTicket()
411     {
412         this.activeTicket = null;
413         if (!FileUtils.test(this.gitdir + "/.gitlive-active-ticket" , FileTest.EXISTS)) {
414                 return;
415         }
416         string ticket_id;
417         FileUtils.get_contents(this.gitdir + "/.gitlive-active-ticket" , out ticket_id);  
418         if (ticket_id.length < 1) {
419                 return;
420                 }
421                 this.activeTicket = RooTicket.singleton().getById(ticket_id.strip());
422         
423         
424     }
425     
426     
427     
428     public bool setActiveTicket(RooTicket? ticket, string branchname)
429     {
430         if (!this.createBranchNamed(branchname)) {
431                 return false;
432                 }
433                 if (ticket != null) {
434                 FileUtils.set_contents(this.gitdir + "/.gitlive-active-ticket" , ticket.id);
435         } else {
436                 FileUtils.remove(this.gitdir + "/.gitlive-active-ticket" );
437         }
438         this.activeTicket = ticket;
439         return true;
440     }
441     
442     public bool createBranchNamed(string branchname)
443     {   
444                 
445
446                      if (this.branches.has_key(branchname)) {
447                         this.switchToExistingBranchNamed(branchname);
448                     
449                     } else {
450                                  this.createNewBranchNamed(branchname); 
451                             
452                     }
453                        var notification = new Notify.Notification(
454                        "Changed to branch %s".printf(branchname),
455                        "",
456                         "dialog-information"
457                        
458                );
459
460                notification.set_timeout(5);
461                notification.show();   
462        
463          
464          this.loadBranches(); // update branch list...
465          //GitMonitor.gitmonitor.runQueue(); // no point - we have hidden the queue..
466          return true;
467     }
468      bool switchToExistingBranchNamed(string branchname)
469      {
470                 var stash = false;
471                                          // this is where it get's tricky...
472                 string files = "";
473                 try {                   
474                                 string[] cmd = { "ls-files" ,  "-m" };                   // list the modified files..
475                                 files = this.git(cmd);
476                                 stash = files.length> 1 ;
477                                 
478                                 
479                                 cmd = { "stash" };                      
480                                 if (stash) { this.git(cmd); }
481                                 
482                                 this.pull();
483                                 
484                                 cmd = { "checkout", branchname  };
485                                 this.git(cmd);
486                   } catch(Error e) {
487                                 GitMonitor.gitmonitor.pauseError(e.message);
488                                 return false;           
489                   }
490                 try {
491                    if (branchname != "master") {
492                        string[] cmd = { "merge", "master"  };
493                             this.git(cmd);
494                             this.push();
495                        
496                     }
497                     
498                 } catch(Error e) {
499                     string[] cmd = { "checkout", "master"  };
500                     this.git(cmd);
501                         GitMonitor.gitmonitor.pauseError(
502                                 "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(
503                                         branchname)
504                                  + e.message
505                         );
506                         return false;           
507                  
508                 }
509                 try {                                   
510                     string[]  cmd = { "stash", "pop"  };
511                     if (stash) { 
512                         this.git(cmd); 
513                         var fl = files.split("\n");
514                         cmd = { "commit", "-m" , "Changed " + string.joinv("",fl) };
515                         foreach(var f in fl) {
516                                 if (f.length < 1) continue;
517                                 cmd += f;
518                         }
519                         this.git(cmd);                              
520                 }
521              
522
523                    
524                 } catch(Error ee) {
525                         GitMonitor.gitmonitor.pauseError(ee.message);
526                         return false;           
527                 }
528        this.push();
529        return true;                             
530                  
531      }
532     
533     
534     
535      bool createNewBranchNamed(string branchname)
536      {
537                 var stash = false;
538                  try {                                  
539                                 string[] cmd = { "ls-files" ,  "-m" };                   // list the modified files..
540                                 var files = this.git(cmd);
541                                 stash = files.length> 1 ;
542                         
543                          cmd = { "checkout", "-b" , branchname  };
544                         this.git(cmd);
545
546                cmd = { "push", "-u" , "origin" ,"HEAD"  };
547                         this.git(cmd);
548                                 if (stash) { 
549
550                                 var fl = files.split("\n");
551                                 cmd = { "commit", "-m" , "Changed " + string.joinv("",fl) };
552                                 foreach(var f in fl) {
553                                         if (f.length < 1) continue;
554                                         cmd += f;
555                                 }
556                                 this.git(cmd);  
557                                 this.push();                        
558                         }
559
560              
561                 } catch(Error ee) {
562                                 GitMonitor.gitmonitor.pauseError(ee.message);
563                                 return false;           
564                         }
565                         return true;
566      
567      }
568     
569     
570     
571     /**
572      * add:
573      * add files to track.
574      *
575      * @argument {Array} files the files to add.
576      */
577     public string add ( Gee.ArrayList<GitMonitorQueue> files ) throws Error, SpawnError
578     {
579         // should really find out if these are untracked files each..
580         // we run multiple versions to make sure that if one failes, it does not ignore the whole lot..
581         // not sure if that is how git works.. but just be certian.
582         var ret = "";
583         for (var i = 0; i < files.size;i++) {
584             var f = files.get(i).vname;
585             try {
586                 string[] cmd = { "add",    f  };
587                 this.git( cmd );
588             } catch (Error e) {
589                 ret += e.message  + "\n";
590             }        
591
592         }
593         return ret;
594     }
595         
596     public bool is_ignore(string fname) throws Error, SpawnError
597     {
598                 if (fname == ".gitignore") {
599                         this.ignore_files.clear();
600                 }
601                 
602                 if (this.ignore_files.has_key(fname)) {
603                         return this.ignore_files.get(fname);
604                 }
605                 
606                 try {
607                         var ret = this.git( { "check-ignore" , fname } );
608                         this.ignore_files.set(fname, ret.length >  0);
609                         return ret.length > 0;
610                 } catch (SpawnError e) {
611                         this.ignore_files.set(fname, false);
612                         return false;
613                 }
614                  
615     } 
616     
617     
618       /**
619      * remove:
620      * remove files to track.
621      *
622      * @argument {Array} files the files to add.
623      */
624     public string remove  ( Gee.ArrayList<GitMonitorQueue> files ) throws Error, SpawnError
625     {
626         // this may fail if files do not exist..
627         // should really find out if these are untracked files each..
628         // we run multiple versions to make sure that if one failes, it does not ignore the whole lot..
629         // not sure if that is how git works.. but just be certian.
630         var ret = "";
631
632         for (var i = 0; i < files.size;i++) {
633             var f = files.get(i).vname;
634             try {
635                 string[] cmd = { "rm",  "-f" ,  f  };
636                 this.git( cmd );
637             } catch (Error e) {
638                 ret += e.message  + "\n";
639             }        
640         }
641
642         return ret;
643
644     }
645     
646     
647     /**
648      * commit:
649      * perform a commit.
650      *
651      * @argument {Object} cfg commit configuration
652      * 
653      * @property {String} name (optional)
654      * @property {String} email (optional)
655      * @property {String} changed (date) (optional)
656      * @property {String} reason (optional)
657      * @property {Array} files - the files that have changed. 
658      * 
659      */
660      
661     public string commit ( string message, Gee.ArrayList<GitMonitorQueue> files  ) throws Error, SpawnError
662     {
663         
664
665         /*
666         var env = [];
667
668         if (typeof(cfg.name) != 'undefined') {
669             args.push( {
670                 'author' : cfg.name + ' <' + cfg.email + '>'
671             });
672             env.push(
673                 "GIT_COMMITTER_NAME" + cfg.name,
674                 "GIT_COMMITTER_EMAIL" + cfg.email
675             );
676         }
677
678         if (typeof(cfg.changed) != 'undefined') {
679             env.push("GIT_AUTHOR_DATE= " + cfg.changed )
680             
681         }
682         */
683         string[] args = { "commit", "-m" };
684         args +=  (message.length > 0  ? message : "Changed" );
685         for (var i = 0; i< files.size ; i++ ) {
686             args += files.get(i).vname; // full path?
687         }
688          
689         return this.git(args);
690     }
691     
692     /**
693      * pull:
694      * Fetch and merge remote repo changes into current branch..
695      *
696      * At present we just need this to update the current working branch..
697      * -- maybe later it will have a few options and do more stuff..
698      *
699      */
700     public string pull () throws Error, SpawnError
701     {
702         // should probably hand error conditions better... 
703         string[] cmd = { "pull" , "--no-edit" };
704         return this.git( cmd );
705
706         
707     }
708     
709     public delegate void GitAsyncCallback (GitRepo repo, int err, string str);
710     public void pull_async(GitAsyncCallback cb) 
711     {
712     
713          string[] cmd = { "pull" , "--no-edit" };
714          this.git_async( cmd , cb);
715          
716     
717     }
718     
719     /**
720      * push:
721      * Send local changes to remote repo(s)
722      *
723      * At present we just need this to push the current branch.
724      * -- maybe later it will have a few options and do more stuff..
725      *
726      */
727     public string push () throws Error, SpawnError
728     {
729         // should 
730         return this.git({ "push"  });
731         
732     }
733     
734     
735     
736      /**
737      * git:
738      * The meaty part.. run spawn.. with git..
739      *
740      *
741      */
742     
743     public string git(string[] args_in ) throws Error, SpawnError
744     {
745         // convert arguments.
746         
747         string[]  args = { "git" };
748         //args +=  "--git-dir";
749         //args +=  this.gitdir;
750         args +=  "--no-pager";
751  
752  
753         //if (this.gitdir != this.repopath) {
754         //    args +=   "--work-tree";
755          //   args += this.repopath; 
756         //}
757         for (var i = 0; i < args_in.length;i++) {
758             args += args_in[i];
759         }            
760
761         //this.lastCmd = args.join(" ");
762         //if(this.debug) {
763             GLib.debug( "CWD=%s",  this.git_working_dir ); 
764             GLib.debug( "cmd: %s", string.joinv (" ", args)); 
765         //}
766
767         string[]   env = {};
768         string  home = "HOME=" + Environment.get_home_dir() ;
769         env +=  home ;
770         // do not need to set gitpath..
771         //if (File.exists(this.repo + '/.git/config')) {
772             //env.push("GITPATH=" + this.repo );
773         //}
774           
775         var cfg = new SpawnConfig(this.git_working_dir , args , env);
776         //cfg.debug = true;
777
778        // may throw error...
779         var sp = new Spawn(cfg);
780       
781         // diff output is a bit big..
782                 if (args_in[0] != "diff") {
783                 GLib.debug( "GOT: %s" , sp.output);
784         }
785         // parse output for some commands ?
786         return sp.output;
787     }
788         
789    unowned GitAsyncCallback git_async_on_callback;
790         public void  git_async( string[] args_in,   GitAsyncCallback cb ) throws Error, SpawnError
791     {
792         // convert arguments.
793        this.git_async_on_callback = cb;
794         string[]  args = { "git" };
795         //args +=  "--git-dir";
796         //args +=  this.gitdir;
797         args +=  "--no-pager";
798  
799  
800         //if (this.gitdir != this.repopath) {
801         //    args +=   "--work-tree";
802          //   args += this.repopath; 
803         //}
804         for (var i = 0; i < args_in.length;i++) {
805             args += args_in[i];
806         }            
807
808         //this.lastCmd = args.join(" ");
809         //if(this.debug) {
810             GLib.debug( "CWD=%s",  this.git_working_dir ); 
811             //print( "cmd: %s\n", string.joinv (" ", args)); 
812         //}
813
814         string[]   env = {};
815         string  home = "HOME=" + Environment.get_home_dir() ;
816         env +=  home ;
817         // do not need to set gitpath..
818         //if (File.exists(this.repo + '/.git/config')) {
819             //env.push("GITPATH=" + this.repo );
820         //}
821         
822
823         var cfg = new SpawnConfig(this.git_working_dir , args , env);
824         cfg.async = true;
825        
826
827        // may throw error...
828         var sp = new Spawn(cfg);
829                 //sp.ref();
830         //this.ref();
831         sp.run(this.git_async_on_complete); 
832          
833     }
834     
835     void git_async_on_complete(int err, string output)
836     {
837                 GLib.debug("GOT %d : %s", err, output);
838                 this.git_async_on_callback(this, err, output);
839 //              this.unref();   
840         //      sp.unref();             
841     
842     
843     }
844     
845  
846          
847     
848  
849     public void update_async(GitAsyncCallback cb) 
850     {
851          string[] cmd = { "fetch" , "--all" };
852          this.git_async( cmd , cb);
853          
854     }
855     
856     
857     static uint update_all_total = 0;
858     static string update_all_after = "";
859      
860     public static void updateAll(string after)
861     {
862                 update_all_after = after;
863                 var tr =  GitRepo.singleton().cache;
864             
865         
866        update_all_total = tr.size;
867        foreach(var repo  in tr.values) {
868                 if (!repo.is_managed()) {
869                         update_all_total--;                     
870                         continue;
871                 }
872            repo.update_async(updateAllCallback); 
873         } 
874
875     }
876     public static void  updateAllCallback(GitRepo repo, int err, string res)
877     {
878         repo.loadBranches();
879         repo.loadStatus();
880         
881         update_all_total--;
882         if (update_all_total > 0 ) {
883                 return;
884                 }
885                 switch (update_all_after) {
886                         case "show_clones":
887                                 Clones.singleton().show();
888                                 break;
889                         default:
890                                 break;
891                 }
892                 return;
893     }
894     
895     
896     
897 }