Open History to see the last commit
1import type {
2 EnvironmentId,
3 VcsListRefsResult,
4 VcsRef as ContractVcsRef,
5} from "@t3tools/contracts";
6
7export interface VcsRefTarget {
8 readonly environmentId: EnvironmentId | null;
9 readonly cwd: string | null;
10 readonly query?: string | null;
11}
12
13export type VcsRef = ContractVcsRef;
14
15export function mergeBranchRefPages(pages: ReadonlyArray<VcsListRefsResult>) {
16 const refs = new Map<string, VcsRef>();
17 for (const page of pages) {
18 for (const ref of page.refs) {
19 const previous = refs.get(ref.name);
20 // Older servers can return both refs for a short name that checks out the local branch.
21 if (!ref.isRemote || previous === undefined || previous.isRemote) {
22 refs.set(ref.name, ref);
23 }
24 }
25 }
26 return [...refs.values()];
27}