From 1900e5238b3e3dd2e868c8da9ee3448b77ae68b5 Mon Sep 17 00:00:00 2001 From: teknium1 Date: Mon, 2 Mar 2026 22:39:57 -0800 Subject: [PATCH] fix: git clone fails on Windows with 'copy-fd: Invalid argument' Git for Windows can fail during clone when copying hook template files from the system templates directory. The error: fatal: cannot copy '.../templates/hooks/fsmonitor-watchman.sample' to '.git/hooks/...': Invalid argument The script already set windows.appendAtomically=false but only AFTER clone, which is too late since clone itself triggers the error. Fix: - Set git config --global windows.appendAtomically false BEFORE clone - Add a third fallback: clone with --template='' to skip hook template copying entirely (they're optional .sample files) --- scripts/install.ps1 | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/scripts/install.ps1 b/scripts/install.ps1 index 320824eb7..aec1b5e69 100644 --- a/scripts/install.ps1 +++ b/scripts/install.ps1 @@ -426,6 +426,12 @@ function Install-Repository { throw "Directory exists but is not a git repository: $InstallDir" } } else { + # Fix Windows git "copy-fd: write returned: Invalid argument" error. + # Must be set BEFORE clone, otherwise git fails copying hook templates. + # Also fixes "unable to write loose object file" for later operations. + Write-Info "Configuring git for Windows compatibility..." + git config --global windows.appendAtomically false + # Try SSH first (for private repo access), fall back to HTTPS. # GIT_SSH_COMMAND with BatchMode=yes prevents SSH from hanging # when no key is configured (fails immediately instead of prompting). @@ -456,14 +462,22 @@ function Install-Repository { if ($LASTEXITCODE -eq 0) { Write-Success "Cloned via HTTPS" } else { - Write-Err "Failed to clone repository" - throw "Failed to clone repository" + # Last resort: skip hook templates entirely (they're optional sample files) + if (Test-Path $InstallDir) { Remove-Item -Recurse -Force $InstallDir -ErrorAction SilentlyContinue } + Write-Warn "Standard clone failed, retrying without hook templates..." + git clone --branch $Branch --recurse-submodules --template="" $RepoUrlHttps $InstallDir + + if ($LASTEXITCODE -eq 0) { + Write-Success "Cloned via HTTPS (no templates)" + } else { + Write-Err "Failed to clone repository" + throw "Failed to clone repository" + } } } } - # Fix Windows git "unable to write loose object file" error. - # Must be set before any git operations that write objects. + # Also set per-repo (in case global wasn't persisted) Push-Location $InstallDir git config windows.appendAtomically false