Skip to content

Commit 12f37e7

Browse files
committed
Augment process.env.PATH at activation instead of per-call env override
- Fixes VSCode's built-in git extension failing to stage git-crypt files (clean filter couldn't find git-crypt binary) - Remove getEnv(), augmentedPath, and EXTRA_PATH_DIRS from git.ts - Move EXTRA_PATH_DIRS to extension.ts; apply once at activate()
1 parent fea9cd4 commit 12f37e7

2 files changed

Lines changed: 13 additions & 22 deletions

File tree

src/extension.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,19 @@ class GitCryptDecorationProvider implements vscode.FileDecorationProvider {
2929
}
3030
}
3131

32+
// Dirs to append to PATH so git-crypt is discoverable by all extensions
33+
const EXTRA_PATH_DIRS = ['/opt/homebrew/bin', '/usr/local/bin', '/usr/bin'];
34+
3235
export async function activate(context: vscode.ExtensionContext): Promise<void> {
3336
log.appendLine('Activating git-crypt-vscode...');
3437

38+
// Augment process PATH before any git operations -- this also fixes the
39+
// built-in git extension's child processes (e.g. git add triggering the
40+
// git-crypt clean filter)
41+
const currentPath = process.env.PATH ?? '';
42+
const missing = EXTRA_PATH_DIRS.filter(d => !currentPath.split(':').includes(d));
43+
if (missing.length) process.env.PATH = `${currentPath}:${missing.join(':')}`;
44+
3545
const gitCryptAvailable = await isGitCryptAvailable();
3646
log.appendLine(`git-crypt available: ${gitCryptAvailable}`);
3747
if (!gitCryptAvailable) {

src/git.ts

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,9 @@ export interface GitResult {
1010

1111
const DEFAULT_TIMEOUT = 5000;
1212

13-
// Extra dirs to search for git-crypt (extension host PATH is often minimal)
14-
const EXTRA_PATH_DIRS = [
15-
'/opt/homebrew/bin',
16-
'/usr/local/bin',
17-
'/usr/bin',
18-
];
19-
20-
// Augmented PATH for all child processes
21-
let augmentedPath: string | undefined;
22-
23-
function getEnv(): NodeJS.ProcessEnv {
24-
if (!augmentedPath) {
25-
const existing = process.env.PATH ?? '';
26-
const dirs = EXTRA_PATH_DIRS.filter(d => !existing.split(':').includes(d));
27-
augmentedPath = dirs.length ? `${existing}:${dirs.join(':')}` : existing;
28-
}
29-
return { ...process.env, PATH: augmentedPath };
30-
}
31-
3213
export function gitExec(cwd: string, args: string[], timeout = DEFAULT_TIMEOUT): Promise<GitResult> {
3314
return new Promise(resolve => {
34-
execFile('git', args, { cwd, timeout, maxBuffer: 10 * 1024 * 1024, env: getEnv() }, (error, stdout, stderr) => {
15+
execFile('git', args, { cwd, timeout, maxBuffer: 10 * 1024 * 1024 }, (error, stdout, stderr) => {
3516
resolve({
3617
stdout: stdout ?? '',
3718
stderr: stderr ?? '',
@@ -43,7 +24,7 @@ export function gitExec(cwd: string, args: string[], timeout = DEFAULT_TIMEOUT):
4324

4425
export async function isGitCryptAvailable(): Promise<boolean> {
4526
return new Promise(resolve => {
46-
execFile('git-crypt', ['--version'], { timeout: 3000, env: getEnv() }, error => {
27+
execFile('git-crypt', ['--version'], { timeout: 3000 }, error => {
4728
resolve(!error);
4829
});
4930
});
@@ -71,7 +52,7 @@ export async function getGitCryptFiles(repoRoot: string): Promise<Set<string>> {
7152
const proc = execFile(
7253
'git',
7354
['check-attr', 'filter', '--stdin'],
74-
{ cwd: repoRoot, timeout: DEFAULT_TIMEOUT, maxBuffer: 10 * 1024 * 1024, env: getEnv() },
55+
{ cwd: repoRoot, timeout: DEFAULT_TIMEOUT, maxBuffer: 10 * 1024 * 1024 },
7556
(error, stdout, stderr) => {
7657
resolve({
7758
stdout: stdout ?? '',

0 commit comments

Comments
 (0)