File tree Expand file tree Collapse file tree 1 file changed +7
-8
lines changed
src/NerdBank.GitVersioning Expand file tree Collapse file tree 1 file changed +7
-8
lines changed Original file line number Diff line number Diff line change @@ -280,7 +280,7 @@ private static string FindGitDir(string startingDir)
280280 else if ( File . Exists ( dirOrFilePath ) )
281281 {
282282 var relativeGitDirPath = ReadGitDirFromFile ( dirOrFilePath ) ;
283- if ( ! String . IsNullOrWhiteSpace ( relativeGitDirPath ) )
283+ if ( ! string . IsNullOrWhiteSpace ( relativeGitDirPath ) )
284284 {
285285 var fullGitDirPath = Path . GetFullPath ( Path . Combine ( startingDir , relativeGitDirPath ) ) ;
286286 if ( Directory . Exists ( fullGitDirPath ) )
@@ -298,15 +298,14 @@ private static string FindGitDir(string startingDir)
298298
299299 private static string ReadGitDirFromFile ( string fileName )
300300 {
301- try
301+ const string expectedPrefix = "gitdir: " ;
302+ var firstLineOfFile = File . ReadLines ( fileName ) . FirstOrDefault ( ) ;
303+ if ( firstLineOfFile ? . StartsWith ( expectedPrefix ) ?? false )
302304 {
303- var firstLineOfFile = File . ReadLines ( fileName ) . FirstOrDefault ( ) ;
304- return Regex . Replace ( firstLineOfFile , "^gitdir: *" , String . Empty ) ;
305- }
306- catch
307- {
308- return String . Empty ;
305+ return firstLineOfFile . Substring ( expectedPrefix . Length ) ; // strip off the prefix, leaving just the path
309306 }
307+
308+ return null ;
310309 }
311310
312311 private static Version GetAssemblyVersion ( Version version , VersionOptions versionOptions )
You can’t perform that action at this time.
0 commit comments