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
13 changes: 9 additions & 4 deletions src/core/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ const CLONE_TIMEOUT_MS = (() => {
return Number.isFinite(parsed) && parsed > 0 ? parsed : DEFAULT_CLONE_TIMEOUT_MS;
})();

export function createGitEnv(): NodeJS.ProcessEnv {
return {
...process.env,
GIT_TERMINAL_PROMPT: '0',
GIT_LFS_SKIP_SMUDGE: '1',
};
}

function createGit(baseDir?: string) {
return simpleGit(baseDir, {
timeout: { block: CLONE_TIMEOUT_MS },
Expand All @@ -23,10 +31,7 @@ function createGit(baseDir?: string) {
'filter.lfs.clean=',
'filter.lfs.process=',
],
}).env({
GIT_TERMINAL_PROMPT: '0',
GIT_LFS_SKIP_SMUDGE: '1',
});
}).env(createGitEnv());
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/core/managed-repos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { dirname, resolve } from 'node:path';
import simpleGit from 'simple-git';
import type { Repository, ManagedMode } from '../models/workspace-config.js';
import { getHomeDir } from '../constants.js';
import { createGitEnv } from './git.js';

const CLONE_TIMEOUT_MS = 120_000; // 2 minutes for full clone

Expand Down Expand Up @@ -80,7 +81,7 @@ export function buildCloneUrl(source: string, repo: string): string {
*/
async function cloneRepo(url: string, dest: string, branch?: string): Promise<void> {
await mkdir(dirname(dest), { recursive: true });
const git = simpleGit({ timeout: { block: CLONE_TIMEOUT_MS } });
const git = simpleGit({ timeout: { block: CLONE_TIMEOUT_MS } }).env(createGitEnv());
const cloneOptions = branch ? ['--branch', branch] : [];
await git.clone(url, dest, cloneOptions);
}
Expand All @@ -90,7 +91,7 @@ async function cloneRepo(url: string, dest: string, branch?: string): Promise<vo
* Returns a skip reason if pull is unsafe, or undefined on success.
*/
async function pullRepo(repoPath: string, branch?: string): Promise<string | undefined> {
const git = simpleGit(repoPath, { timeout: { block: CLONE_TIMEOUT_MS } });
const git = simpleGit(repoPath, { timeout: { block: CLONE_TIMEOUT_MS } }).env(createGitEnv());

// Check for uncommitted changes
const status = await git.status();
Expand Down
34 changes: 34 additions & 0 deletions tests/unit/core/git.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { afterEach, beforeEach, describe, expect, it } from 'bun:test';
import { createGitEnv } from '../../../src/core/git.js';

describe('createGitEnv', () => {
const originalHome = process.env.HOME;
const originalPath = process.env.PATH;
const originalPrompt = process.env.GIT_TERMINAL_PROMPT;
const originalSkipSmudge = process.env.GIT_LFS_SKIP_SMUDGE;

beforeEach(() => {
process.env.HOME = '/tmp/test-home';
process.env.PATH = '/tmp/test-path';
process.env.GIT_TERMINAL_PROMPT = '1';
process.env.GIT_LFS_SKIP_SMUDGE = '0';
});

afterEach(() => {
process.env.HOME = originalHome;
process.env.PATH = originalPath;
process.env.GIT_TERMINAL_PROMPT = originalPrompt;
process.env.GIT_LFS_SKIP_SMUDGE = originalSkipSmudge;
});

it('preserves inherited git environment while applying allagents overrides', () => {
const gitEnv = createGitEnv();

expect(gitEnv).toMatchObject({
HOME: '/tmp/test-home',
PATH: '/tmp/test-path',
GIT_TERMINAL_PROMPT: '0',
GIT_LFS_SKIP_SMUDGE: '1',
});
});
});