5257dfbaab
Co-authored-by: Kandev Agent <agent@kandev.dev> Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
33 lines
1023 B
TypeScript
33 lines
1023 B
TypeScript
import type { Worktree } from "@/lib/state/slices/session/types";
|
|
import type { Repository } from "@/lib/types/http";
|
|
import { t } from "@/lib/i18n";
|
|
|
|
export type WorktreeOption = {
|
|
worktreeId: string;
|
|
label: string;
|
|
branch?: string;
|
|
};
|
|
|
|
function worktreePathBasename(path: string | undefined): string | undefined {
|
|
if (!path) return undefined;
|
|
return path.split(/[\\/]/).filter(Boolean).pop();
|
|
}
|
|
|
|
/**
|
|
* Builds display options for a session's worktrees: labeled by repository name
|
|
* when known, otherwise by the worktree folder name.
|
|
*/
|
|
export function buildWorktreeOptions(
|
|
worktrees: Worktree[],
|
|
repositories: Repository[],
|
|
): WorktreeOption[] {
|
|
return worktrees.map((worktree, index) => {
|
|
const repository = repositories.find((repo) => repo.id === worktree.repositoryId);
|
|
const label =
|
|
repository?.name ??
|
|
worktreePathBasename(worktree.path) ??
|
|
t("task:worktreeNumbered", { index: index + 1 });
|
|
return { worktreeId: worktree.id, label, branch: worktree.branch };
|
|
});
|
|
}
|