Skip to content

Commit 0f3a06e

Browse files
committed
fix(worktree): treat missing trusted git binary as recursive submodule config enabled
When no trusted git binary is found, assume recursive submodule config is enabled rather than disabled, so commands are allowed by default instead of incorrectly blocked. Export effectiveGitConfigEnablesRecursiveSubmodules for testing.
1 parent 66d1956 commit 0f3a06e

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

src/core/rules-git.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -608,15 +608,17 @@ function getEnvConfigValue(
608608
return envAssignments?.get(name) ?? process.env[name];
609609
}
610610

611-
function effectiveGitConfigEnablesRecursiveSubmodules(cwd: string): boolean {
611+
function effectiveGitConfigEnablesRecursiveSubmodules(
612+
cwd: string,
613+
gitBinary: string | null = getTrustedGitBinary(),
614+
): boolean {
612615
const localConfigResult = localGitConfigEnablesRecursiveSubmodules(cwd);
613616
if (localConfigResult === null || localConfigResult) {
614617
return true;
615618
}
616619

617-
const gitBinary = getTrustedGitBinary();
618620
if (gitBinary === null) {
619-
return false;
621+
return true;
620622
}
621623

622624
try {
@@ -958,6 +960,7 @@ function analyzeGitWorktree(tokens: readonly string[]): string | null {
958960

959961
/** @internal Exported for testing */
960962
export {
963+
effectiveGitConfigEnablesRecursiveSubmodules as _effectiveGitConfigEnablesRecursiveSubmodules,
961964
extractGitSubcommandAndRest as _extractGitSubcommandAndRest,
962965
getCheckoutPositionalArgs as _getCheckoutPositionalArgs,
963966
TRUSTED_GIT_BINARIES as _TRUSTED_GIT_BINARIES,

tests/core/rules-git.test.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import { describe, expect, test } from 'bun:test';
22
import { execFileSync } from 'node:child_process';
33
import { chmodSync, existsSync, mkdirSync, symlinkSync, writeFileSync } from 'node:fs';
44
import { join } from 'node:path';
5-
import { _TRUSTED_GIT_BINARIES, analyzeGit } from '@/core/rules-git';
5+
import {
6+
_effectiveGitConfigEnablesRecursiveSubmodules,
7+
_TRUSTED_GIT_BINARIES,
8+
analyzeGit,
9+
} from '@/core/rules-git';
610
import {
711
assertAllowed,
812
assertBlocked,
@@ -22,6 +26,8 @@ describe('analyzeGit direct', () => {
2226
expect(_TRUSTED_GIT_BINARIES).toContain('/usr/bin/git');
2327
expect(_TRUSTED_GIT_BINARIES).toContain('/usr/local/bin/git');
2428
expect(_TRUSTED_GIT_BINARIES).toContain('/opt/homebrew/bin/git');
29+
expect(_TRUSTED_GIT_BINARIES).toContain('C:\\Program Files\\Git\\cmd\\git.exe');
30+
expect(_TRUSTED_GIT_BINARIES).toContain('C:\\Program Files\\Git\\bin\\git.exe');
2531
});
2632
});
2733

@@ -1325,6 +1331,17 @@ describe('git linked worktree mode', () => {
13251331
}
13261332
});
13271333

1334+
test('SAFETY_NET_WORKTREE treats missing trusted git binary as recursive submodule config', () => {
1335+
const fixture = createLinkedWorktreeFixture();
1336+
try {
1337+
expect(_effectiveGitConfigEnablesRecursiveSubmodules(fixture.linkedWorktree, null)).toBe(
1338+
true,
1339+
);
1340+
} finally {
1341+
fixture.cleanup();
1342+
}
1343+
});
1344+
13281345
test('SAFETY_NET_WORKTREE keeps configured recursive submodule discards blocked', () => {
13291346
const fixture = createLinkedWorktreeFixture();
13301347
try {

0 commit comments

Comments
 (0)