@@ -33,11 +33,11 @@ public record GitCheckoutInformation
33
33
public string ? RepositoryName
34
34
{
35
35
get => _repositoryName ??= Remote . Split ( '/' ) . Last ( ) ;
36
- set => _repositoryName = value ;
36
+ init => _repositoryName = value ;
37
37
}
38
38
39
39
// manual read because libgit2sharp is not yet AOT ready
40
- public static GitCheckoutInformation Create ( IFileSystem fileSystem )
40
+ public static GitCheckoutInformation Create ( IDirectoryInfo source , IFileSystem fileSystem )
41
41
{
42
42
if ( fileSystem is not FileSystem )
43
43
{
@@ -51,18 +51,18 @@ public static GitCheckoutInformation Create(IFileSystem fileSystem)
51
51
}
52
52
53
53
var fakeRef = Guid . NewGuid ( ) . ToString ( ) [ ..16 ] ;
54
- var gitConfig = Git ( ".git/config" ) ;
54
+ var gitConfig = Git ( source , ".git/config" ) ;
55
55
if ( ! gitConfig . Exists )
56
56
return Unavailable ;
57
57
58
- var head = Read ( ".git/HEAD" ) ?? fakeRef ;
58
+ var head = Read ( source , ".git/HEAD" ) ?? fakeRef ;
59
59
var gitRef = head ;
60
60
var branch = head . Replace ( "refs/heads/" , string . Empty ) ;
61
61
//not detached HEAD
62
62
if ( head . StartsWith ( "ref:" ) )
63
63
{
64
64
head = head . Replace ( "ref: " , string . Empty ) ;
65
- gitRef = Read ( ".git/" + head ) ?? fakeRef ;
65
+ gitRef = Read ( source , ".git/" + head ) ?? fakeRef ;
66
66
branch = branch . Replace ( "ref: " , string . Empty ) ;
67
67
}
68
68
else
@@ -73,15 +73,17 @@ public static GitCheckoutInformation Create(IFileSystem fileSystem)
73
73
using var streamReader = new StreamReader ( stream ) ;
74
74
ini . Load ( streamReader ) ;
75
75
76
- var remote = BranchTrackingRemote ( branch , ini ) ;
76
+ var remote = Environment . GetEnvironmentVariable ( "GITHUB_REPOSITORY" ) ;
77
+ if ( string . IsNullOrEmpty ( remote ) )
78
+ remote = BranchTrackingRemote ( branch , ini ) ;
77
79
if ( string . IsNullOrEmpty ( remote ) )
78
80
remote = BranchTrackingRemote ( "main" , ini ) ;
79
81
if ( string . IsNullOrEmpty ( remote ) )
80
82
remote = BranchTrackingRemote ( "master" , ini ) ;
81
83
if ( string . IsNullOrEmpty ( remote ) )
82
- remote = Environment . GetEnvironmentVariable ( "GITHUB_REPOSITORY" ) ?? "elastic/docs-builder-unknown" ;
84
+ remote = "elastic/docs-builder-unknown" ;
83
85
84
- remote = remote . AsSpan ( ) . TrimEnd ( ". git" ) . ToString ( ) ;
86
+ remote = remote . AsSpan ( ) . TrimEnd ( "git" ) . TrimEnd ( '.' ) . ToString ( ) ;
85
87
86
88
return new GitCheckoutInformation
87
89
{
@@ -91,11 +93,12 @@ public static GitCheckoutInformation Create(IFileSystem fileSystem)
91
93
RepositoryName = remote . Split ( '/' ) . Last ( )
92
94
} ;
93
95
94
- IFileInfo Git ( string path ) => fileSystem . FileInfo . New ( Path . Combine ( Paths . Root . FullName , path ) ) ;
96
+ IFileInfo Git ( IDirectoryInfo directoryInfo , string path ) =>
97
+ fileSystem . FileInfo . New ( Path . Combine ( directoryInfo . FullName , path ) ) ;
95
98
96
- string ? Read ( string path )
99
+ string ? Read ( IDirectoryInfo directoryInfo , string path )
97
100
{
98
- var gitPath = Git ( path ) . FullName ;
101
+ var gitPath = Git ( directoryInfo , path ) . FullName ;
99
102
return ! fileSystem . File . Exists ( gitPath )
100
103
? null
101
104
: fileSystem . File . ReadAllText ( gitPath ) . Trim ( Environment . NewLine . ToCharArray ( ) ) ;
0 commit comments