Skip to content

Commit 975abbc

Browse files
gfraiteurclaude
andcommitted
Use AppContext.BaseDirectory as fallback for repo directory lookup
Co-Authored-By: Claude <noreply@anthropic.com>
1 parent e420888 commit 975abbc

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/PostSharp.Engineering.BuildTools/Build/BuildContext.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,16 @@ public static bool TryCreate(
9797
buildContext = null;
9898

9999
// Use the repo directory from environment variable if provided, otherwise search from current directory
100-
var searchDirectory = Environment.GetEnvironmentVariable( EnvironmentVariableNames.RepoDirectory )
101-
?? Environment.CurrentDirectory;
100+
var repoDirectory = FindRepoDirectory( Environment.GetEnvironmentVariable( EnvironmentVariableNames.RepoDirectory ) )
101+
?? FindRepoDirectory( Environment.CurrentDirectory )
102+
?? FindRepoDirectory( AppContext.BaseDirectory );
102103

103-
var repoDirectory = FindRepoDirectory( searchDirectory );
104104
var console = new ConsoleHelper();
105105

106106
if ( repoDirectory == null )
107107
{
108-
console.WriteError( "This tool must be called from a git repository." );
108+
console.WriteError(
109+
"This tool must be called from a git repository, or the environment variable REPO_DIRECTORY must be set to the root directory of the repository." );
109110

110111
return false;
111112
}
@@ -128,8 +129,13 @@ public static bool TryCreate(
128129
return true;
129130
}
130131

131-
private static string? FindRepoDirectory( string directory )
132+
private static string? FindRepoDirectory( string? directory )
132133
{
134+
if ( string.IsNullOrEmpty( directory ) )
135+
{
136+
return null;
137+
}
138+
133139
if ( Directory.Exists( Path.Combine( directory, ".git" ) ) )
134140
{
135141
var gitIgnorePath = Path.Combine( directory, ".gitignore" );

0 commit comments

Comments
 (0)