@@ -17,6 +17,7 @@ public class ChangelogBuilder
17
17
private readonly BuildContext context ;
18
18
private readonly bool preview ;
19
19
private readonly string depth ;
20
+ private readonly bool forceClone ;
20
21
21
22
/// <summary>
22
23
/// Directory with original changelog part files from branch 'docs-changelog'
@@ -33,6 +34,7 @@ public ChangelogBuilder(BuildContext context)
33
34
this . context = context ;
34
35
preview = KnownOptions . DocsPreview . Resolve ( context ) ;
35
36
depth = KnownOptions . DocsDepth . Resolve ( context ) ;
37
+ forceClone = KnownOptions . ForceClone . Resolve ( context ) ;
36
38
37
39
var docsDirectory = context . RootDirectory . Combine ( "docs" ) ;
38
40
SrcDirectory = docsDirectory . Combine ( "_changelog" ) ;
@@ -43,7 +45,7 @@ public void Fetch()
43
45
{
44
46
EnvVar . GitHubToken . AssertHasValue ( ) ;
45
47
46
- EnsureSrcDirectoryExist ( ) ;
48
+ EnsureSrcDirectoryExist ( forceClone ) ;
47
49
48
50
var history = context . VersionHistory ;
49
51
var stableVersionCount = history . StableVersions . Length ;
@@ -224,14 +226,31 @@ private void GenerateToc()
224
226
context . GenerateFile ( DocfxDirectory . CombineWithFilePath ( "toc.yml" ) , content ) ;
225
227
}
226
228
227
- private void EnsureSrcDirectoryExist ( bool forceClean = false )
229
+ private void EnsureSrcDirectoryExist ( bool forceClone = false )
228
230
{
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...") ;
230
239
context . DeleteDirectory (
231
240
SrcDirectory ,
232
241
new DeleteDirectorySettings { Force = true , Recursive = true } ) ;
242
+ Log ( $ "Directory '{ SrcDirectory } ' deleted successfully.") ;
243
+ }
233
244
234
245
if ( ! context . DirectoryExists ( SrcDirectory ) )
246
+ {
247
+ Log ( $ "Cloning branch '{ Repo . ChangelogBranch } ' from '{ Repo . HttpsGitUrl } ' to '{ SrcDirectory } '.") ;
235
248
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
+ }
236
255
}
237
256
}
0 commit comments