Files
stack/packages/cli/src/tui/hooks/use-git-info.ts
Jason Woltje 82c10a7b33
All checks were successful
ci/woodpecker/push/ci Pipeline was successful
feat(cli): TUI complete overhaul — components, sidebar, search, branding (#157)
Co-authored-by: Jason Woltje <jason@diversecanvas.com>
Co-committed-by: Jason Woltje <jason@diversecanvas.com>
2026-03-15 22:17:19 +00:00

30 lines
651 B
TypeScript

import { useState, useEffect } from 'react';
import { execSync } from 'node:child_process';
export interface GitInfo {
branch: string | null;
cwd: string;
}
export function useGitInfo(): GitInfo {
const [info, setInfo] = useState<GitInfo>({
branch: null,
cwd: process.cwd(),
});
useEffect(() => {
try {
const branch = execSync('git rev-parse --abbrev-ref HEAD', {
encoding: 'utf-8',
timeout: 3000,
stdio: ['pipe', 'pipe', 'pipe'],
}).trim();
setInfo({ branch, cwd: process.cwd() });
} catch {
setInfo({ branch: null, cwd: process.cwd() });
}
}, []);
return info;
}