Replace spawn with execFile for memory-safe command execution (#1068)

This commit is contained in:
tanzhenxin
2025-11-20 15:04:00 +08:00
committed by GitHub
parent a15b84e2a1
commit 442a9aed58
20 changed files with 620 additions and 969 deletions

View File

@@ -5,7 +5,7 @@
*/
import { useState, useEffect, useCallback } from 'react';
import { spawnAsync } from '@qwen-code/qwen-code-core';
import { isCommandAvailable, execCommand } from '@qwen-code/qwen-code-core';
import fs from 'node:fs';
import fsPromises from 'node:fs/promises';
import path from 'node:path';
@@ -15,7 +15,11 @@ export function useGitBranchName(cwd: string): string | undefined {
const fetchBranchName = useCallback(async () => {
try {
const { stdout } = await spawnAsync(
if (!isCommandAvailable('git').available) {
return;
}
const { stdout } = await execCommand(
'git',
['rev-parse', '--abbrev-ref', 'HEAD'],
{ cwd },
@@ -24,7 +28,7 @@ export function useGitBranchName(cwd: string): string | undefined {
if (branch && branch !== 'HEAD') {
setBranchName(branch);
} else {
const { stdout: hashStdout } = await spawnAsync(
const { stdout: hashStdout } = await execCommand(
'git',
['rev-parse', '--short', 'HEAD'],
{ cwd },