Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/git/src/operation-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> {
export function getCleanEnv(): Record<string, string> {
const env: Record<string, string> = {};
for (const [key, value] of Object.entries(process.env)) {
if (value === undefined) continue;
Expand All @@ -22,6 +29,7 @@ function getCleanEnv(): Record<string, string> {
env[key] = value;
}
env.ELECTRON_RUN_AS_NODE = "1";
env.GIT_LFS_SKIP_SMUDGE = "1";
return env;
}

Expand Down
6 changes: 4 additions & 2 deletions packages/git/src/sagas/clone.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -39,7 +39,9 @@ export class CloneSaga extends Saga<CloneInput, CloneOutput> {
onProgress(stage, progress, processed, total)
: undefined,
});
await git.clone(repoUrl, targetPath, ["--progress"]);
await git
.env(getCleanEnv())
.clone(repoUrl, targetPath, ["--progress"]);
},
rollback: async () => {
try {
Expand Down
3 changes: 2 additions & 1 deletion packages/git/src/worktree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -327,6 +327,7 @@ export class WorktreeManager {
{
cwd: this.mainRepoPath,
stdio: ["ignore", "pipe", "pipe"],
env: getCleanEnv(),
},
);

Expand Down
Loading