MCPcopy Create free account
hub / github.com/pingdotgg/t3code / parseRemoteRefWithRemoteNames

Function parseRemoteRefWithRemoteNames

apps/server/src/git/remoteRefs.ts:16–42  ·  view source on GitHub ↗
(
  ref: string,
  remoteNames: ReadonlyArray<string>,
)

Source from the content-addressed store, hash-verified

14}
15
16export function parseRemoteRefWithRemoteNames(
17 ref: string,
18 remoteNames: ReadonlyArray<string>,
19): { remoteRef: string; remoteName: string; branchName: string } | null {
20 const trimmedRef = ref.trim();
21 if (trimmedRef.length === 0) {
22 return null;
23 }
24
25 for (const remoteName of remoteNames) {
26 const remotePrefix = `${remoteName}/`;
27 if (!trimmedRef.startsWith(remotePrefix)) {
28 continue;
29 }
30 const branchName = trimmedRef.slice(remotePrefix.length).trim();
31 if (branchName.length === 0) {
32 return null;
33 }
34 return {
35 remoteRef: trimmedRef,
36 remoteName,
37 branchName,
38 };
39 }
40
41 return null;
42}
43
44export function extractBranchNameFromRemoteRef(
45 ref: string,

Calls

no outgoing calls

Tested by

no test coverage detected