@@ -81,6 +81,7 @@ function pathsAreEqual (pathA, pathB, caseInsensitive = false, useRealpath = tru
8181}
8282
8383function pathStartsWith ( pathA , pathB , caseInsensitive = false , useRealpath = true ) {
84+ console . log ( 'pathStartsWith:' , pathA , pathB , caseInsensitive , useRealpath ) ;
8485 if ( IS_WINDOWS ) {
8586 pathA = normalizePath ( pathA , useRealpath )
8687 pathB = normalizePath ( pathB , useRealpath )
@@ -224,7 +225,7 @@ Repository.prototype.checkoutReference = function (branch, create) {
224225Repository . prototype . relativize = function ( filePath ) {
225226 let workingDirectory
226227 if ( ! filePath ) return filePath
227- console . log ( 'started with' ) ;
228+ console . log ( 'Real recursive path for:' , filePath , 'is' , realpathRecursive ( filePath ) ) ;
228229 filePath = normalizePath ( filePath , true )
229230 console . log ( 'normalized to' , filePath ) ;
230231
@@ -235,18 +236,14 @@ Repository.prototype.relativize = function (filePath) {
235236 workingDirectory = this . getWorkingDirectory ( )
236237 console . log ( 'WORKING DIR IS' , workingDirectory ) ;
237238 if ( workingDirectory ) {
238- console . log ( 'comparing' , filePath , 'to' , workingDirectory ) ;
239- console . log ( 'realpath of workingDirectory is' , realpath ( workingDirectory ) ) ;
240- console . log ( 'realpath of filePath is' , realpath ( filePath ) ) ;
241- if ( pathStartsWith ( filePath , workingDirectory , this . caseInsensitiveFs , true ) ) {
239+ if ( pathStartsWith ( filePath , workingDirectory , this . caseInsensitiveFs , false ) ) {
242240 return filePath . substring ( workingDirectory . length + 1 )
243- } else if ( pathsAreEqual ( filePath , workingDirectory , this . caseInsensitiveFs , true ) ) {
241+ } else if ( pathsAreEqual ( filePath , workingDirectory , this . caseInsensitiveFs , false ) ) {
244242 return ''
245243 }
246244 }
247245
248246 if ( this . openedWorkingDirectory ) {
249- console . log ( 'comparing' , filePath , 'to' , this . openedWorkingDirectory ) ;
250247 workingDirectory = this . openedWorkingDirectory
251248 if ( pathStartsWith ( filePath , workingDirectory , this . caseInsensitiveFs , false ) ) {
252249 return filePath . substring ( workingDirectory . length + 1 )
@@ -367,8 +364,47 @@ function promisify (fn) {
367364 )
368365}
369366
370- function realpath ( unrealPath ) {
367+ function realpathRecursive ( unrealPath ) {
368+ console . log ( 'realpathRecursive:' , unrealPath ) ;
369+ let currentPath = unrealPath
370+ let result = unrealPath
371+ let remainder = ''
372+ if ( ! path . isAbsolute ( unrealPath ) ) {
373+ return realpath ( unrealPath , true )
374+ }
375+ while ( ! isRootPath ( currentPath ) ) {
376+ try {
377+ result = fs . realpathSync . native ( unrealPath )
378+ break
379+ } catch ( e ) {
380+ if ( e . message . includes ( 'ENOENT' ) ) {
381+ currentPath = path . resolve ( currentPath , '..' )
382+ remainder = path . relative ( currentPath , unrealPath )
383+ } else {
384+ return unrealPath
385+ }
386+ }
387+ }
388+ if ( isRootPath ( currentPath ) ) {
389+ return unrealPath
390+ }
391+ let finalResult = trimPath ( `${ result } /${ remainder } ` )
392+ console . log ( ' @@@ returning' , finalResult ) ;
393+ return finalResult
394+ }
395+
396+ function trimPath ( filePath ) {
397+ if ( ! filePath . endsWith ( '/' ) ) return filePath
398+ return filePath . replace ( / \/ $ / , '' )
399+ }
400+
401+ function realpath ( unrealPath , force = false ) {
402+ if ( ! force ) {
403+ return realpathRecursive ( unrealPath )
404+ }
371405 try {
406+ // `fs.realpathSync.native` somehow is the only thing that can consistently
407+ // normalize 8.3 "short names" in Windows to their long equivalents.
372408 if ( typeof fs . realpathSync . native === 'function' ) {
373409 return fs . realpathSync . native ( unrealPath )
374410 }
@@ -397,7 +433,6 @@ function openRepository (repositoryPath, search) {
397433 if ( repository . exists ( ) ) {
398434 repository . caseInsensitiveFs = fs . isCaseInsensitive ( )
399435 if ( symlink ) {
400- repository . _symlinkDirectory = repositoryPath
401436 const workingDirectory = repository . getWorkingDirectory ( )
402437 // On Windows, normalize both sides through realpath so that 8.3 short
403438 // names (e.g., RUNNER~1) and path separator differences don't prevent
0 commit comments