Sync upstream Gemini-CLI v0.8.2 (#838)

This commit is contained in:
tanzhenxin
2025-10-23 09:27:04 +08:00
committed by GitHub
parent 096fabb5d6
commit eb95c131be
644 changed files with 70389 additions and 23709 deletions

View File

@@ -5,7 +5,7 @@
*/
import { useState, useEffect, useCallback } from 'react';
import { exec } from 'node:child_process';
import { spawnAsync } from '@qwen-code/qwen-code-core';
import fs from 'node:fs';
import fsPromises from 'node:fs/promises';
import path from 'node:path';
@@ -13,36 +13,28 @@ import path from 'node:path';
export function useGitBranchName(cwd: string): string | undefined {
const [branchName, setBranchName] = useState<string | undefined>(undefined);
const fetchBranchName = useCallback(
() =>
exec(
'git rev-parse --abbrev-ref HEAD',
const fetchBranchName = useCallback(async () => {
try {
const { stdout } = await spawnAsync(
'git',
['rev-parse', '--abbrev-ref', 'HEAD'],
{ cwd },
(error, stdout, _stderr) => {
if (error) {
setBranchName(undefined);
return;
}
const branch = stdout.toString().trim();
if (branch && branch !== 'HEAD') {
setBranchName(branch);
} else {
exec(
'git rev-parse --short HEAD',
{ cwd },
(error, stdout, _stderr) => {
if (error) {
setBranchName(undefined);
return;
}
setBranchName(stdout.toString().trim());
},
);
}
},
),
[cwd, setBranchName],
);
);
const branch = stdout.toString().trim();
if (branch && branch !== 'HEAD') {
setBranchName(branch);
} else {
const { stdout: hashStdout } = await spawnAsync(
'git',
['rev-parse', '--short', 'HEAD'],
{ cwd },
);
setBranchName(hashStdout.toString().trim());
}
} catch (_error) {
setBranchName(undefined);
}
}, [cwd, setBranchName]);
useEffect(() => {
fetchBranchName(); // Initial fetch