Open History to see the last commit
1/**
2 * A tracked repository the Git sheets act on instead of the thread's own folder. The thread still
3 * owns the work, but its branch and worktree never follow this folder.
4 */
5export interface GitRepositoryTarget {
6 /** Tells the folder from the others shown beside it; the repository's path. */
7 readonly key: string;
8 readonly cwd: string;
9 readonly name: string;
10}
11
12// A type alias, not an interface: route params need an implicit index signature.
13export type GitRepositoryRouteParams = {
14 readonly repositoryCwd?: string;
15 readonly repositoryName?: string;
16};
17
18function folderName(cwd: string): string {
19 return cwd.replaceAll("\\", "/").split("/").findLast(Boolean) ?? cwd;
20}
21
22/** Undefined when the route acts on the thread's own folder. */
23export function gitRepositoryTargetFromRoute(
24 params: GitRepositoryRouteParams,
25): GitRepositoryTarget | undefined {
26 const cwd = params.repositoryCwd?.trim() ?? "";
27 if (cwd.length === 0) return undefined;
28 const name = params.repositoryName?.trim() ?? "";
29 return { key: cwd, cwd, name: name.length > 0 ? name : folderName(cwd) };
30}
31
32export function gitRepositoryRouteParams(
33 repository: GitRepositoryTarget | undefined,
34): GitRepositoryRouteParams {
35 return repository === undefined
36 ? {}
37 : { repositoryCwd: repository.cwd, repositoryName: repository.name };
38}