From 162236f46366fc2fd6c32f6a3dd5c0f0aa7f8ba2 Mon Sep 17 00:00:00 2001 From: Affaan Mustafa Date: Fri, 20 Mar 2026 03:29:45 -0700 Subject: [PATCH] fix: normalize bash metadata paths on windows --- tests/hooks/hooks.test.js | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/tests/hooks/hooks.test.js b/tests/hooks/hooks.test.js index bd3440f1..b2919a03 100644 --- a/tests/hooks/hooks.test.js +++ b/tests/hooks/hooks.test.js @@ -8,7 +8,7 @@ const assert = require('assert'); const path = require('path'); const fs = require('fs'); const os = require('os'); -const { spawn, spawnSync } = require('child_process'); +const { execFileSync, spawn, spawnSync } = require('child_process'); function toBashPath(filePath) { if (process.platform !== 'win32') { @@ -25,12 +25,34 @@ function fromBashPath(filePath) { return filePath; } - const match = String(filePath).match(/^\/([A-Za-z])\/(.*)$/); - if (!match) { - return filePath; + const rawPath = String(filePath || ''); + if (!rawPath) { + return rawPath; } - return `${match[1].toUpperCase()}:\\${match[2].replace(/\//g, '\\')}`; + try { + return execFileSync( + 'bash', + ['-lc', 'cygpath -w -- "$1"', 'bash', rawPath], + { stdio: ['ignore', 'pipe', 'ignore'] } + ) + .toString() + .trim(); + } catch { + // Fall back to common Git Bash path shapes when cygpath is unavailable. + } + + const match = rawPath.match(/^\/(?:cygdrive\/)?([A-Za-z])\/(.*)$/) + || rawPath.match(/^\/\/([A-Za-z])\/(.*)$/); + if (match) { + return `${match[1].toUpperCase()}:\\${match[2].replace(/\//g, '\\')}`; + } + + if (/^[A-Za-z]:\//.test(rawPath)) { + return rawPath.replace(/\//g, '\\'); + } + + return rawPath; } function sleepMs(ms) {