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

Function resolveWant

packages/plugins/apps/src/git-client/pktline.ts:113–138  ·  view source on GitHub ↗
(
  adv: RefAdvertisement,
  ref?: string,
)

Source from the content-addressed store, hash-verified

111
112// Resolve which sha a caller wants given a ref advertisement + optional ref name.
113export function resolveWant(
114 adv: RefAdvertisement,
115 ref?: string,
116): { sha: string; resolvedRef: string } {
117 if (ref) {
118 // try exact, then heads/, then tags/
119 const candidates = [ref, `refs/heads/${ref}`, `refs/tags/${ref}`, `refs/${ref}`];
120 for (const c of candidates) {
121 const sha = adv.refs.get(c);
122 if (sha) return { sha, resolvedRef: c };
123 }
124 // maybe they passed a sha directly
125 if (/^[0-9a-f]{40,64}$/.test(ref)) return { sha: ref, resolvedRef: ref };
126 throw new Error(`ref not found: ${ref}`);
127 }
128 // default: HEAD symref target, else HEAD ref, else first
129 if (adv.headTarget) {
130 const sha = adv.refs.get(adv.headTarget);
131 if (sha) return { sha, resolvedRef: adv.headTarget };
132 }
133 const head = adv.refs.get("HEAD");
134 if (head) return { sha: head, resolvedRef: "HEAD" };
135 const first = adv.refs.entries().next();
136 if (!first.done) return { sha: first.value[1], resolvedRef: first.value[0] };
137 throw new Error("no refs advertised");
138}
139
140export { td, te };

Callers 3

app-source.test.tsFile · 0.90
handFetchFunction · 0.90
handRefsCheckFunction · 0.90

Calls 1

getMethod · 0.65

Tested by

no test coverage detected