mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-21 09:17:53 +00:00
Sync upstream Gemini-CLI v0.8.2 (#838)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user