@@ -17,6 +17,7 @@ public class ChangelogBuilder
1717 private readonly BuildContext context ;
1818 private readonly bool preview ;
1919 private readonly string depth ;
20+ private readonly bool forceClone ;
2021
2122 /// <summary>
2223 /// Directory with original changelog part files from branch 'docs-changelog'
@@ -33,6 +34,7 @@ public ChangelogBuilder(BuildContext context)
3334 this . context = context ;
3435 preview = KnownOptions . DocsPreview . Resolve ( context ) ;
3536 depth = KnownOptions . DocsDepth . Resolve ( context ) ;
37+ forceClone = KnownOptions . ForceClone . Resolve ( context ) ;
3638
3739 var docsDirectory = context . RootDirectory . Combine ( "docs" ) ;
3840 SrcDirectory = docsDirectory . Combine ( "_changelog" ) ;
@@ -43,7 +45,7 @@ public void Fetch()
4345 {
4446 EnvVar . GitHubToken . AssertHasValue ( ) ;
4547
46- EnsureSrcDirectoryExist ( ) ;
48+ EnsureSrcDirectoryExist ( forceClone ) ;
4749
4850 var history = context . VersionHistory ;
4951 var stableVersionCount = history . StableVersions . Length ;
@@ -224,14 +226,31 @@ private void GenerateToc()
224226 context . GenerateFile ( DocfxDirectory . CombineWithFilePath ( "toc.yml" ) , content ) ;
225227 }
226228
227- private void EnsureSrcDirectoryExist ( bool forceClean = false )
229+ private void EnsureSrcDirectoryExist ( bool forceClone = false )
228230 {
229- if ( context . DirectoryExists ( SrcDirectory ) && forceClean )
231+ void Log ( string message ) => context . Information ( $ "[Changelog] { message } ") ;
232+
233+ Log ( $ "Preparing git sub-repository for changelog branch '{ Repo . ChangelogBranch } '. " +
234+ $ "Target directory: '{ SrcDirectory } '.") ;
235+ if ( context . DirectoryExists ( SrcDirectory ) && forceClone )
236+ {
237+ Log ( $ "Directory '{ SrcDirectory } ' already exists and forceClean is specified. " +
238+ $ "Deleting the current directory...") ;
230239 context . DeleteDirectory (
231240 SrcDirectory ,
232241 new DeleteDirectorySettings { Force = true , Recursive = true } ) ;
242+ Log ( $ "Directory '{ SrcDirectory } ' deleted successfully.") ;
243+ }
233244
234245 if ( ! context . DirectoryExists ( SrcDirectory ) )
246+ {
247+ Log ( $ "Cloning branch '{ Repo . ChangelogBranch } ' from '{ Repo . HttpsGitUrl } ' to '{ SrcDirectory } '.") ;
235248 context . GitRunner . Clone ( SrcDirectory , Repo . HttpsGitUrl , Repo . ChangelogBranch ) ;
249+ Log ( $ "Clone completed: '{ Repo . ChangelogBranch } ' -> '{ SrcDirectory } '.") ;
250+ }
251+ else
252+ {
253+ Log ( $ "Directory '{ SrcDirectory } ' already exists. Skipping clone.") ;
254+ }
236255 }
237256}
0 commit comments