diff --git a/.githooks/pre-commit b/.githooks/pre-commit index a488a8455c9..dc884b5fac0 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -1,13 +1,24 @@ #!/usr/bin/env sh -":" //; if command -v pwsh >/dev/null 2>&1; then pwsh -ExecutionPolicy Bypass -File .githooks/pre-commit.ps1; else sh .githooks/pre-commit.sh; fi; exit $? # Try PowerShell Core first, then sh on Unix -":" //; exit # Skip rest on Unix -@echo off -powershell -NoProfile -Command "if (Get-Command powershell -ErrorAction SilentlyContinue) { exit 0 } else { exit 1 }" -if %errorlevel% equ 0 ( - powershell -ExecutionPolicy Bypass -File .githooks\pre-commit.ps1 -) else ( - echo Error: PowerShell is not available. Please install PowerShell. - exit /b 1 -) -exit /b %errorlevel% +# Check if running in Windows +if [ -n "$COMSPEC" ]; then + # Windows section - Execute directly with PowerShell + powershell -NoProfile -Command " + if (Get-Command powershell -ErrorAction SilentlyContinue) { + Write-Host 'PowerShell found, executing pre-commit.ps1...' + powershell -ExecutionPolicy Bypass -File '.githooks\pre-commit.ps1' + exit $LASTEXITCODE + } else { + Write-Host 'Error: PowerShell is not available. Please install PowerShell.' + exit 1 + } + " + echo "Exiting with status $?" + exit $? +else + # Unix-like system section + echo "Unix-like system found, executing pre-commit.sh..." + sh .githooks/pre-commit.sh + echo "Exiting with status $?" + exit $? +fi diff --git a/.githooks/pre-push b/.githooks/pre-push index 7cc1783291a..4b6950da260 100755 --- a/.githooks/pre-push +++ b/.githooks/pre-push @@ -1,13 +1,24 @@ #!/usr/bin/env sh -":" //; if command -v pwsh >/dev/null 2>&1; then pwsh -ExecutionPolicy Bypass -File .githooks/pre-push.ps1; else sh .githooks/pre-push.sh; fi; exit $? # Try PowerShell Core first, then sh on Unix -":" //; exit # Skip rest on Unix -@echo off -powershell -NoProfile -Command "if (Get-Command powershell -ErrorAction SilentlyContinue) { exit 0 } else { exit 1 }" -if %errorlevel% equ 0 ( - powershell -ExecutionPolicy Bypass -File .githooks\pre-push.ps1 -) else ( - echo Error: PowerShell is not available. Please install PowerShell. - exit /b 1 -) -exit /b %errorlevel% +# Check if running in Windows +if [ -n "$COMSPEC" ]; then + # Windows section - Execute directly with PowerShell + powershell -NoProfile -Command " + if (Get-Command powershell -ErrorAction SilentlyContinue) { + Write-Host 'PowerShell found, executing pre-push.ps1...' + powershell -ExecutionPolicy Bypass -File '.githooks\pre-push.ps1' + exit $LASTEXITCODE + } else { + Write-Host 'Error: PowerShell is not available. Please install PowerShell.' + exit 1 + } + " + echo "Exiting with status $?" + exit $? +else + # Unix-like system section + echo "Unix-like system found, executing pre-push.sh..." + sh .githooks/pre-push.sh + echo "Exiting with status $?" + exit $? +fi diff --git a/.githooks/pre-push.ps1 b/.githooks/pre-push.ps1 index ba0fc23d76a..f771706808c 100644 --- a/.githooks/pre-push.ps1 +++ b/.githooks/pre-push.ps1 @@ -45,8 +45,10 @@ if ($mergeBase -ne $upstreamHead) { Write-Host "Would you like to automatically rebase and setup? [Y/n]" -ForegroundColor Yellow try { - $reader = [System.IO.StreamReader]::new("CON") - $input = $reader.ReadLine() + $input = Read-Host + if ([string]::IsNullOrEmpty($input)) { + $input = "Y" + } } catch { Write-Host "Error reading input. Aborting push..." -ForegroundColor Red exit 1