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

Function useBranchSwitcher

src/features/git/hooks/useBranchSwitcher.ts:14–54  ·  view source on GitHub ↗
({
  activeWorkspace,
  checkoutBranch,
  setActiveWorkspaceId,
}: UseBranchSwitcherOptions)

Source from the content-addressed store, hash-verified

12} | null;
13
14export function useBranchSwitcher({
15 activeWorkspace,
16 checkoutBranch,
17 setActiveWorkspaceId,
18}: UseBranchSwitcherOptions) {
19 const [branchSwitcher, setBranchSwitcher] = useState<BranchSwitcherState>(null);
20
21 const openBranchSwitcher = useCallback(() => {
22 if (
23 !activeWorkspace ||
24 !activeWorkspace.connected ||
25 activeWorkspace.kind === "worktree"
26 ) {
27 return;
28 }
29 setBranchSwitcher({ isOpen: true });
30 }, [activeWorkspace]);
31
32 const closeBranchSwitcher = useCallback(() => {
33 setBranchSwitcher(null);
34 }, []);
35
36 const handleBranchSelect = useCallback(
37 async (branchName: string, worktreeWorkspace: WorkspaceInfo | null) => {
38 closeBranchSwitcher();
39 if (worktreeWorkspace) {
40 setActiveWorkspaceId(worktreeWorkspace.id);
41 } else {
42 await checkoutBranch(branchName);
43 }
44 },
45 [checkoutBranch, closeBranchSwitcher, setActiveWorkspaceId],
46 );
47
48 return {
49 branchSwitcher,
50 openBranchSwitcher,
51 closeBranchSwitcher,
52 handleBranchSelect,
53 };
54}

Callers 1

useMainAppModalsFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected