MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / handRefsCheck

Function handRefsCheck

packages/plugins/apps/src/git-client/hand.ts:95–135  ·  view source on GitHub ↗
(
  url: string,
  ref?: string,
  opts: { token?: string; fetchImpl?: typeof fetch; allowPrivateHosts?: boolean } = {},
)

Source from the content-addressed store, hash-verified

93
94// refs-only cheap check
95export async function handRefsCheck(
96 url: string,
97 ref?: string,
98 opts: { token?: string; fetchImpl?: typeof fetch; allowPrivateHosts?: boolean } = {},
99): Promise<{
100 ok: boolean;
101 refCount?: number;
102 headSha?: string;
103 head?: string;
104 sha?: string;
105 resolvedRef?: string;
106 wallMs?: number;
107 error?: string;
108}> {
109 const t0 = Date.now();
110 try {
111 const host = new URL(url).host;
112 const auth = authForHost(host, opts.token);
113 const refs = await checkRefs(url, auth, opts.fetchImpl, {
114 allowPrivateHosts: opts.allowPrivateHosts,
115 });
116 const head = refs.adv.headTarget;
117 const headSha = head ? refs.adv.refs.get(head) : refs.adv.refs.get("HEAD");
118 const wanted = resolveWant(refs.adv, ref);
119 return {
120 ok: true,
121 refCount: refs.adv.refs.size,
122 head,
123 headSha,
124 sha: wanted.sha,
125 resolvedRef: wanted.resolvedRef,
126 wallMs: Date.now() - t0,
127 };
128 } catch (e) {
129 return {
130 ok: false,
131 error: String(e instanceof Error ? e.message : e),
132 wallMs: Date.now() - t0,
133 };
134 }
135}

Callers 1

checkGitAppSourceRefsFunction · 0.90

Calls 4

authForHostFunction · 0.90
checkRefsFunction · 0.90
resolveWantFunction · 0.90
getMethod · 0.65

Tested by

no test coverage detected