@@ -37,7 +37,7 @@ internal LibGit2VersionFile(LibGit2Context context)
3737 /// <returns>The version information read from the file.</returns>
3838 internal VersionOptions ? GetVersion ( Commit commit , string repoRelativeProjectDirectory , Dictionary < ObjectId , VersionOptions ? > ? blobVersionCache , VersionFileRequirements requirements , out VersionFileLocations locations )
3939 {
40- repoRelativeProjectDirectory = TrimTrailingPathSeparator ( repoRelativeProjectDirectory ) ;
40+ repoRelativeProjectDirectory = this . NormalizeTreeDirectoryPath ( commit , TrimTrailingPathSeparator ( repoRelativeProjectDirectory ) ) ;
4141 locations = default ;
4242
4343 string ? searchDirectory = repoRelativeProjectDirectory ?? string . Empty ;
@@ -153,4 +153,36 @@ internal LibGit2VersionFile(LibGit2Context context)
153153
154154 /// <inheritdoc/>
155155 protected override VersionOptions ? GetVersionCore ( VersionFileRequirements requirements , out VersionFileLocations locations ) => this . GetVersion ( this . Context . Commit ! , this . Context . RepoRelativeProjectDirectory , null , requirements , out locations ) ;
156+
157+ private string NormalizeTreeDirectoryPath ( Commit commit , string repoRelativeProjectDirectory )
158+ {
159+ if ( string . IsNullOrEmpty ( repoRelativeProjectDirectory ) || ! this . IsIgnoreCaseEnabled ( ) )
160+ {
161+ return repoRelativeProjectDirectory ;
162+ }
163+
164+ Tree currentTree = commit . Tree ;
165+ string [ ] pathSegments = repoRelativeProjectDirectory . Split ( new [ ] { '/' , '\\ ' } , StringSplitOptions . RemoveEmptyEntries ) ;
166+ var resolvedSegments = new List < string > ( pathSegments . Length ) ;
167+
168+ foreach ( string segment in pathSegments )
169+ {
170+ TreeEntry ? entry = currentTree [ segment ] ?? currentTree . FirstOrDefault ( candidate => string . Equals ( candidate . Name , segment , StringComparison . OrdinalIgnoreCase ) ) ;
171+ if ( entry ? . TargetType != TreeEntryTargetType . Tree || entry . Target is not Tree childTree )
172+ {
173+ return repoRelativeProjectDirectory ;
174+ }
175+
176+ resolvedSegments . Add ( entry . Name ) ;
177+ currentTree = childTree ;
178+ }
179+
180+ return string . Join ( "/" , resolvedSegments ) ;
181+ }
182+
183+ private bool IsIgnoreCaseEnabled ( )
184+ {
185+ ConfigurationEntry < bool > ? ignoreCaseSetting = this . Context . Repository . Config . Get < bool > ( "core.ignorecase" ) ;
186+ return ignoreCaseSetting ? . Value ?? false ;
187+ }
156188}
0 commit comments