diff --git a/packages/git/src/operation-manager.ts b/packages/git/src/operation-manager.ts index fc54bb286..404ced127 100644 --- a/packages/git/src/operation-manager.ts +++ b/packages/git/src/operation-manager.ts @@ -12,8 +12,15 @@ import { AsyncReaderWriterLock } from "./rw-lock"; * Chromium browser (GPU init → SIGTRAP crash). We strip most ELECTRON_/ * CHROME_ vars but explicitly keep ELECTRON_RUN_AS_NODE=1 so any such * shim still behaves as plain Node.js. + * + * GIT_LFS_SKIP_SMUDGE=1 prevents the LFS filter from running during + * checkout/clone/worktree operations. Users who don't have git-lfs + * installed (but whose repo declares `filter=lfs` in .gitattributes) + * would otherwise hit `git-lfs: command not found` and fail the op. + * Pointer files are preserved; real LFS content can be fetched later + * with `git lfs pull` if the user installs git-lfs. */ -function getCleanEnv(): Record { +export function getCleanEnv(): Record { const env: Record = {}; for (const [key, value] of Object.entries(process.env)) { if (value === undefined) continue; @@ -22,6 +29,7 @@ function getCleanEnv(): Record { env[key] = value; } env.ELECTRON_RUN_AS_NODE = "1"; + env.GIT_LFS_SKIP_SMUDGE = "1"; return env; } diff --git a/packages/git/src/sagas/clone.ts b/packages/git/src/sagas/clone.ts index a0570c530..08df9bbf2 100644 --- a/packages/git/src/sagas/clone.ts +++ b/packages/git/src/sagas/clone.ts @@ -1,7 +1,7 @@ import * as fs from "node:fs/promises"; import { Saga } from "@posthog/shared"; import { createGitClient } from "../client"; -import { getGitOperationManager } from "../operation-manager"; +import { getCleanEnv, getGitOperationManager } from "../operation-manager"; export interface CloneInput { repoUrl: string; @@ -39,7 +39,9 @@ export class CloneSaga extends Saga { onProgress(stage, progress, processed, total) : undefined, }); - await git.clone(repoUrl, targetPath, ["--progress"]); + await git + .env(getCleanEnv()) + .clone(repoUrl, targetPath, ["--progress"]); }, rollback: async () => { try { diff --git a/packages/git/src/worktree.ts b/packages/git/src/worktree.ts index 65e57da89..4eb299fa8 100644 --- a/packages/git/src/worktree.ts +++ b/packages/git/src/worktree.ts @@ -2,7 +2,7 @@ import { execFile, spawn } from "node:child_process"; import * as crypto from "node:crypto"; import * as fs from "node:fs/promises"; import * as path from "node:path"; -import { getGitOperationManager } from "./operation-manager"; +import { getCleanEnv, getGitOperationManager } from "./operation-manager"; import { addToLocalExclude, branchExists, @@ -327,6 +327,7 @@ export class WorktreeManager { { cwd: this.mainRepoPath, stdio: ["ignore", "pipe", "pipe"], + env: getCleanEnv(), }, );