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

Function useGitRootSelection

src/features/app/hooks/useGitRootSelection.ts:19–72  ·  view source on GitHub ↗
({
  activeWorkspace,
  updateWorkspaceSettings,
  clearGitRootCandidates,
  refreshGitStatus,
}: UseGitRootSelectionOptions)

Source from the content-addressed store, hash-verified

17}
18
19export function useGitRootSelection({
20 activeWorkspace,
21 updateWorkspaceSettings,
22 clearGitRootCandidates,
23 refreshGitStatus,
24}: UseGitRootSelectionOptions) {
25 const activeGitRoot = activeWorkspace?.settings.gitRoot ?? null;
26
27 const handleSetGitRoot = useCallback(
28 async (path: string | null) => {
29 if (!activeWorkspace) {
30 return;
31 }
32 await updateWorkspaceSettings(activeWorkspace.id, {
33 gitRoot: path,
34 });
35 clearGitRootCandidates();
36 refreshGitStatus();
37 },
38 [
39 activeWorkspace,
40 clearGitRootCandidates,
41 refreshGitStatus,
42 updateWorkspaceSettings,
43 ],
44 );
45
46 const handlePickGitRoot = useCallback(async () => {
47 if (!activeWorkspace) {
48 return;
49 }
50 const selection = await pickWorkspacePath();
51 if (!selection) {
52 return;
53 }
54 const workspacePath = normalizePath(activeWorkspace.path);
55 const selectedPath = normalizePath(selection);
56 let nextRoot: string | null = null;
57 if (selectedPath === workspacePath) {
58 nextRoot = null;
59 } else if (selectedPath.startsWith(`${workspacePath}/`)) {
60 nextRoot = selectedPath.slice(workspacePath.length + 1);
61 } else {
62 nextRoot = selectedPath;
63 }
64 await handleSetGitRoot(nextRoot);
65 }, [activeWorkspace, handleSetGitRoot]);
66
67 return {
68 activeGitRoot,
69 handleSetGitRoot,
70 handlePickGitRoot,
71 };
72}

Callers 1

useMainAppGitStateFunction · 0.90

Calls 3

pickWorkspacePathFunction · 0.90
updateWorkspaceSettingsFunction · 0.85
normalizePathFunction · 0.70

Tested by

no test coverage detected