Fix Windows git command console flashing (#897)

This commit is contained in:
Mohamed Boudra
2026-05-10 19:46:25 +08:00
committed by GitHub
parent d75d2d857d
commit 3b7971a463
5 changed files with 47 additions and 0 deletions
+1
View File
@@ -62,6 +62,7 @@ function resolveShellEnv(): Record<string, string> | undefined {
const result = spawnSync(shell, [...shellArgs, command], {
encoding: "utf8",
timeout: RESOLVE_TIMEOUT_MS,
windowsHide: true,
env: {
...shellEnv,
ELECTRON_RUN_AS_NODE: "1",
+2
View File
@@ -191,6 +191,7 @@ if (forcedUserDataDir) {
const topLevel = execFileSync("git", ["rev-parse", "--show-toplevel"], {
encoding: "utf-8",
timeout: 3000,
windowsHide: true,
}).trim();
devWorktreeName = path.basename(topLevel);
// Main checkout (e.g. "paseo") gets default userData — only worktrees diverge.
@@ -200,6 +201,7 @@ if (forcedUserDataDir) {
cwd: topLevel,
encoding: "utf-8",
timeout: 3000,
windowsHide: true,
}).trim(),
);
const isWorktree = path.resolve(topLevel, ".git") !== commonDir;
@@ -230,6 +230,7 @@ export function findExecutable(name: string): string | null {
const result = execFileSync(cmd, [trimmed], {
encoding: "utf8",
env: createProviderEnv({ baseEnv: process.env }),
windowsHide: true,
}).trim();
const lines = result.split(/\r?\n/).filter((l: string) => l.trim());
const candidate = lines.at(-1)?.trim() ?? null;
@@ -54,6 +54,7 @@ export function runGitCommand(
const child = spawnProcess("git", args, {
cwd: options.cwd,
envOverlay: mergeEnvOverlays(options.env, options.envOverlay),
shell: false,
stdio: ["ignore", "pipe", "pipe"],
});
@@ -0,0 +1,42 @@
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import path from "node:path";
import { afterEach, describe, expect, it } from "vitest";
import { runGitCommand } from "./run-git-command.js";
const tempDirs: string[] = [];
function makeTempRepo(): string {
const repo = mkdtempSync(path.join(tmpdir(), "paseo-git-shell-"));
tempDirs.push(repo);
return repo;
}
afterEach(() => {
for (const dir of tempDirs.splice(0)) {
rmSync(dir, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
}
});
describe("runGitCommand shell behavior", () => {
it("passes git arguments directly instead of through the platform shell", async () => {
const repo = makeTempRepo();
const literalName = "%PASEO_GIT_SHELL_SENTINEL%";
const expandedName = "expanded-by-cmd";
await runGitCommand(["init"], { cwd: repo });
writeFileSync(path.join(repo, literalName), "literal\n");
writeFileSync(path.join(repo, expandedName), "expanded\n");
await runGitCommand(["add", literalName, expandedName], { cwd: repo });
const result = await runGitCommand(["ls-files", "--error-unmatch", literalName], {
cwd: repo,
envOverlay: {
PASEO_GIT_SHELL_SENTINEL: expandedName,
},
});
expect(result.stdout.trim()).toBe(literalName);
});
});