MCPcopy
hub / github.com/21st-dev/1code / getCheckedOutBranches

Function getCheckedOutBranches

src/main/lib/git/branches.ts:318–342  ·  view source on GitHub ↗
(
	git: ReturnType<typeof simpleGit>,
	currentWorktreePath: string,
)

Source from the content-addressed store, hash-verified

316}
317
318async function getCheckedOutBranches(
319 git: ReturnType<typeof simpleGit>,
320 currentWorktreePath: string,
321): Promise<Record<string, string>> {
322 const checkedOutBranches: Record<string, string> = {};
323
324 try {
325 const worktreeList = await git.raw(["worktree", "list", "--porcelain"]);
326 const lines = worktreeList.split("\n");
327 let currentPath: string | null = null;
328
329 for (const line of lines) {
330 if (line.startsWith("worktree ")) {
331 currentPath = line.substring(9).trim();
332 } else if (line.startsWith("branch ")) {
333 const branch = line.substring(7).trim().replace("refs/heads/", "");
334 if (currentPath && currentPath !== currentWorktreePath) {
335 checkedOutBranches[branch] = currentPath;
336 }
337 }
338 }
339 } catch {}
340
341 return checkedOutBranches;
342}

Callers 1

createBranchesRouterFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected