@@ -10,11 +10,14 @@ namespace Elastic.Markdown.IO.Discovery;
1010
1111public record GitCheckoutInformation
1212{
13+ private string ? _repositoryName ;
14+
1315 private static GitCheckoutInformation Unavailable { get ; } = new ( )
1416 {
1517 Branch = "unavailable" ,
1618 Remote = "unavailable" ,
17- Ref = "unavailable"
19+ Ref = "unavailable" ,
20+ RepositoryName = "unavailable"
1821 } ;
1922
2023 [ JsonPropertyName ( "branch" ) ]
@@ -26,14 +29,27 @@ public record GitCheckoutInformation
2629 [ JsonPropertyName ( "ref" ) ]
2730 public required string Ref { get ; init ; }
2831
32+ [ JsonIgnore ]
33+ public string ? RepositoryName
34+ {
35+ get => _repositoryName ??= Remote . Split ( '/' ) . Last ( ) ;
36+ set => _repositoryName = value ;
37+ }
38+
2939 // manual read because libgit2sharp is not yet AOT ready
3040 public static GitCheckoutInformation Create ( IFileSystem fileSystem )
3141 {
3242 // filesystem is not real so return a dummy
3343 if ( fileSystem is not FileSystem )
3444 {
3545 var fakeRef = Guid . NewGuid ( ) . ToString ( ) . Substring ( 0 , 16 ) ;
36- return new GitCheckoutInformation { Branch = $ "test-{ fakeRef } ", Remote = "elastic/docs-builder" , Ref = fakeRef , } ;
46+ return new GitCheckoutInformation
47+ {
48+ Branch = $ "test-{ fakeRef } ",
49+ Remote = "elastic/docs-builder" ,
50+ Ref = fakeRef ,
51+ RepositoryName = "docs-builder"
52+ } ;
3753 }
3854
3955 var gitConfig = Git ( ".git/config" ) ;
@@ -66,7 +82,15 @@ public static GitCheckoutInformation Create(IFileSystem fileSystem)
6682 if ( string . IsNullOrEmpty ( remote ) )
6783 remote = Environment . GetEnvironmentVariable ( "GITHUB_REPOSITORY" ) ?? "elastic/docs-builder-unknown" ;
6884
69- return new GitCheckoutInformation { Ref = gitRef , Branch = branch , Remote = remote } ;
85+ remote = remote . AsSpan ( ) . TrimEnd ( ".git" ) . ToString ( ) ;
86+
87+ return new GitCheckoutInformation
88+ {
89+ Ref = gitRef ,
90+ Branch = branch ,
91+ Remote = remote ,
92+ RepositoryName = remote . Split ( '/' ) . Last ( )
93+ } ;
7094
7195 IFileInfo Git ( string path ) => fileSystem . FileInfo . New ( Path . Combine ( Paths . Root . FullName , path ) ) ;
7296
@@ -80,7 +104,7 @@ string BranchTrackingRemote(string b, IniFile c)
80104 if ( ! sections . Contains ( branchSection ) )
81105 return string . Empty ;
82106
83- var remoteName = ini . GetSetting ( branchSection , "remote" ) ;
107+ var remoteName = ini . GetSetting ( branchSection , "remote" ) ? . Trim ( ) ;
84108
85109 var remoteSection = $ "remote \" { remoteName } \" ";
86110
0 commit comments