fix(git): hide spawned git windows on Windows (#301)

This commit is contained in:
Xinchen Lee
2026-08-22 23:11:27 +08:00
committed by GitHub
parent e867e27106
commit 71c5413e5c
2 changed files with 42 additions and 0 deletions
+1
View File
@@ -96,6 +96,7 @@ function runGit(cwd: string, args: string[], timeoutMs = 30_000): Promise<string
return new Promise<string>((resolvePromise, reject) => {
const child = spawn('git', full, {
stdio: ['ignore', 'pipe', 'pipe'],
windowsHide: true,
env: { ...process.env, GIT_OPTIONAL_LOCKS: '0' },
})
let stdout = ''
+41
View File
@@ -0,0 +1,41 @@
import { EventEmitter } from 'node:events'
import { PassThrough } from 'node:stream'
import { afterEach, describe, expect, it, vi } from 'vitest'
const { spawnMock } = vi.hoisted(() => ({ spawnMock: vi.fn() }))
vi.mock('node:child_process', () => ({ spawn: spawnMock }))
import { isGitRepo } from '../src/git.ts'
afterEach(() => {
spawnMock.mockReset()
})
describe('git subprocess spawning', () => {
it('hides spawned git windows', async () => {
spawnMock.mockImplementation(() => {
const child = new EventEmitter()
const stdout = new PassThrough()
const stderr = new PassThrough()
Object.assign(child, { stdout, stderr, kill: vi.fn() })
queueMicrotask(() => {
stdout.end('true\n')
stderr.end()
child.emit('close', 0)
})
return child
})
await expect(isGitRepo('C:\\repo')).resolves.toBe(true)
expect(spawnMock).toHaveBeenCalledTimes(1)
expect(spawnMock).toHaveBeenCalledWith(
'git',
['-C', 'C:\\repo', '--no-pager', '-c', 'color.ui=false', 'rev-parse', '--is-inside-work-tree'],
expect.objectContaining({ windowsHide: true }),
)
})
})