Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

useWorkspaceRepositories.ts

26 lines951 Bytes

1import type { EnvironmentId, VcsRepository } from "@t3tools/contracts";
2​
3import { useEnvironmentQuery } from "../state/query";
4import { vcsEnvironment } from "../state/vcs";
5​
6const NO_REPOSITORIES: ReadonlyArray<VcsRepository> = [];
7​
8/**
9 * Repositories a multi-repo workspace folder holds. Asked only once Git status reports that
10 * `cwd` is not itself a repository, so ordinary checkouts never make the request.
11 */
12export function useWorkspaceRepositories(input: {
13 readonly environmentId: EnvironmentId | null;
14 readonly cwd: string | null;
15 readonly isRepo: boolean | undefined;
16}): ReadonlyArray<VcsRepository> {
17 const query = useEnvironmentQuery(
18 input.environmentId !== null && input.cwd !== null && input.isRepo === false
19 ? vcsEnvironment.listRepositories({
20 environmentId: input.environmentId,
21 input: { cwd: input.cwd },
22 })
23 : null,
24 );
25 return query.data?.repositories ?? NO_REPOSITORIES;