11// See https://aka.ms/new-console-template for more information
22
3+ using System . Collections . Concurrent ;
34using System . Diagnostics ;
45using ConsoleAppFramework ;
56using Documentation . Assembler . Cli ;
2021app . Add ( "clone-all" , async Task ( CancellationToken ctx ) =>
2122{
2223 Console . WriteLine ( config . Repositories . Count ) ;
24+ var dict = new ConcurrentDictionary < string , Stopwatch > ( ) ;
2325 await Parallel . ForEachAsync ( config . Repositories , new ParallelOptions
2426 {
2527 CancellationToken = ctx ,
@@ -33,14 +35,43 @@ await Task.Run(() =>
3335 var checkoutFolder = Path . Combine ( Paths . Root . FullName , $ ".artifacts/assembly/{ name } ") ;
3436
3537 var sw = Stopwatch . StartNew ( ) ;
38+ dict . AddOrUpdate ( name , sw , ( _ , _ ) => sw ) ;
3639 Console . WriteLine ( $ "Checkout: { name } \t { repository } \t { checkoutFolder } ") ;
37- //, "--single-branch", "--branch", "main"
38- var args = new StartArguments ( "git" , "clone" , repository , checkoutFolder , "--depth" , "1" ) ;
40+ var branch = repository . Branch ?? "main" ;
41+ var args = new StartArguments (
42+ "git" , "clone" , repository . Origin , checkoutFolder , "--depth" , "1"
43+ , "--single-branch" , "--branch" , branch
44+ ) ;
3945 Proc . StartRedirected ( args , new ConsoleLineHandler ( name ) ) ;
4046 sw . Stop ( ) ;
41- Console . WriteLine ( $ "-> { name } \t took: { sw . Elapsed } ") ;
4247 } , c ) ;
4348 } ) . ConfigureAwait ( false ) ;
49+
50+ foreach ( var kv in dict . OrderBy ( kv => kv . Value . Elapsed ) )
51+ Console . WriteLine ( $ "-> { kv . Key } \t took: { kv . Value . Elapsed } ") ;
52+ } ) ;
53+ app . Add ( "list" , async Task ( CancellationToken ctx ) => {
54+
55+ var assemblyPath = Path . Combine ( Paths . Root . FullName , $ ".artifacts/assembly") ;
56+ var dir = new DirectoryInfo ( assemblyPath ) ;
57+ var dictionary = new Dictionary < string , string > ( ) ;
58+ foreach ( var d in dir . GetDirectories ( ) )
59+ {
60+ var checkoutFolder = Path . Combine ( assemblyPath , d . Name ) ;
61+
62+ var consoleOut = new NoopConsoleLineHandler ( ) ;
63+ var capture = Proc . StartRedirected (
64+ new StartArguments ( "git" , "rev-parse" , "--abbrev-ref" , "HEAD" )
65+ {
66+ WorkingDirectory = checkoutFolder
67+ }
68+ , consoleOut ) ;
69+ dictionary . Add ( d . Name , consoleOut . Lines . FirstOrDefault ( ) ? . Line ?? "unknown" ) ;
70+ }
71+ foreach ( var kv in dictionary . OrderBy ( kv => kv . Value ) )
72+ Console . WriteLine ( $ "-> { kv . Key } \t branch: { kv . Value } ") ;
73+
74+ await Task . CompletedTask ;
4475} ) ;
4576
4677await app . RunAsync ( args ) ;
@@ -54,3 +85,11 @@ public void Handle(LineOut lineOut) => lineOut.CharsOrString(
5485 public void Handle ( Exception e ) { }
5586}
5687
88+ public class NoopConsoleLineHandler : IConsoleLineHandler
89+ {
90+ public List < LineOut > Lines { get ; } = new ( ) ;
91+
92+ public void Handle ( LineOut lineOut ) => Lines . Add ( lineOut ) ;
93+
94+ public void Handle ( Exception e ) { }
95+ }
0 commit comments