MCPcopy
hub / github.com/Dimillian/CodexMonitor / useGitRepoScan

Function useGitRepoScan

src/features/git/hooks/useGitRepoScan.ts:15–109  ·  view source on GitHub ↗
(activeWorkspace: WorkspaceInfo | null)

Source from the content-addressed store, hash-verified

13const DEFAULT_DEPTH = 2;
14
15export function useGitRepoScan(activeWorkspace: WorkspaceInfo | null) {
16 const [state, setState] = useState<GitRepoScanState>({
17 repos: [],
18 isLoading: false,
19 error: null,
20 depth: DEFAULT_DEPTH,
21 hasScanned: false,
22 });
23 const requestIdRef = useRef(0);
24 const workspaceIdRef = useRef<string | null>(activeWorkspace?.id ?? null);
25
26 const scan = useCallback(async () => {
27 if (!activeWorkspace) {
28 setState((prev) => ({ ...prev, repos: [], isLoading: false }));
29 return;
30 }
31 const workspaceId = activeWorkspace.id;
32 const requestId = requestIdRef.current + 1;
33 requestIdRef.current = requestId;
34 setState((prev) => ({
35 ...prev,
36 isLoading: true,
37 error: null,
38 hasScanned: true,
39 }));
40 try {
41 const repos = await listGitRoots(workspaceId, state.depth);
42 if (
43 requestIdRef.current !== requestId ||
44 workspaceIdRef.current !== workspaceId
45 ) {
46 return;
47 }
48 setState((prev) => ({
49 ...prev,
50 repos,
51 isLoading: false,
52 error: null,
53 }));
54 } catch (error) {
55 if (
56 requestIdRef.current !== requestId ||
57 workspaceIdRef.current !== workspaceId
58 ) {
59 return;
60 }
61 setState((prev) => ({
62 ...prev,
63 repos: [],
64 isLoading: false,
65 error: error instanceof Error ? error.message : String(error),
66 }));
67 }
68 }, [activeWorkspace, state.depth]);
69
70 const setDepth = useCallback((depth: number) => {
71 const clamped = Math.min(6, Math.max(1, depth));
72 setState((prev) => ({ ...prev, depth: clamped }));

Callers 1

useMainAppGitStateFunction · 0.90

Calls 1

listGitRootsFunction · 0.90

Tested by

no test coverage detected