Skip to content

Commit e5259af

Browse files
committed
fix: handle git-lfs with GIT_LFS_SKIP_SMUDGE
1 parent 91a94a1 commit e5259af

3 files changed

Lines changed: 15 additions & 4 deletions

File tree

packages/git/src/operation-manager.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,15 @@ import { AsyncReaderWriterLock } from "./rw-lock";
1212
* Chromium browser (GPU init → SIGTRAP crash). We strip most ELECTRON_/
1313
* CHROME_ vars but explicitly keep ELECTRON_RUN_AS_NODE=1 so any such
1414
* shim still behaves as plain Node.js.
15+
*
16+
* GIT_LFS_SKIP_SMUDGE=1 prevents the LFS filter from running during
17+
* checkout/clone/worktree operations. Users who don't have git-lfs
18+
* installed (but whose repo declares `filter=lfs` in .gitattributes)
19+
* would otherwise hit `git-lfs: command not found` and fail the op.
20+
* Pointer files are preserved; real LFS content can be fetched later
21+
* with `git lfs pull` if the user installs git-lfs.
1522
*/
16-
function getCleanEnv(): Record<string, string> {
23+
export function getCleanEnv(): Record<string, string> {
1724
const env: Record<string, string> = {};
1825
for (const [key, value] of Object.entries(process.env)) {
1926
if (value === undefined) continue;
@@ -22,6 +29,7 @@ function getCleanEnv(): Record<string, string> {
2229
env[key] = value;
2330
}
2431
env.ELECTRON_RUN_AS_NODE = "1";
32+
env.GIT_LFS_SKIP_SMUDGE = "1";
2533
return env;
2634
}
2735

packages/git/src/sagas/clone.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as fs from "node:fs/promises";
22
import { Saga } from "@posthog/shared";
33
import { createGitClient } from "../client";
4-
import { getGitOperationManager } from "../operation-manager";
4+
import { getCleanEnv, getGitOperationManager } from "../operation-manager";
55

66
export interface CloneInput {
77
repoUrl: string;
@@ -39,7 +39,9 @@ export class CloneSaga extends Saga<CloneInput, CloneOutput> {
3939
onProgress(stage, progress, processed, total)
4040
: undefined,
4141
});
42-
await git.clone(repoUrl, targetPath, ["--progress"]);
42+
await git
43+
.env(getCleanEnv())
44+
.clone(repoUrl, targetPath, ["--progress"]);
4345
},
4446
rollback: async () => {
4547
try {

packages/git/src/worktree.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { execFile, spawn } from "node:child_process";
22
import * as crypto from "node:crypto";
33
import * as fs from "node:fs/promises";
44
import * as path from "node:path";
5-
import { getGitOperationManager } from "./operation-manager";
5+
import { getCleanEnv, getGitOperationManager } from "./operation-manager";
66
import {
77
addToLocalExclude,
88
branchExists,
@@ -327,6 +327,7 @@ export class WorktreeManager {
327327
{
328328
cwd: this.mainRepoPath,
329329
stdio: ["ignore", "pipe", "pipe"],
330+
env: getCleanEnv(),
330331
},
331332
);
332333

0 commit comments

Comments
 (0)