MCPcopy
hub / github.com/coder/mux / detectDefaultTrunkBranch

Function detectDefaultTrunkBranch

src/node/git.ts:82–106  ·  view source on GitHub ↗
(
  projectPath: string,
  branches?: string[]
)

Source from the content-addressed store, hash-verified

80const FALLBACK_TRUNK_CANDIDATES = ["main", "master", "trunk", "develop", "default"];
81
82export async function detectDefaultTrunkBranch(
83 projectPath: string,
84 branches?: string[]
85): Promise<string> {
86 const branchList = branches ?? (await listLocalBranches(projectPath));
87
88 if (branchList.length === 0) {
89 throw new Error(`No branches available in repository ${projectPath}`);
90 }
91
92 const branchSet = new Set(branchList);
93 const currentBranch = await getCurrentBranch(projectPath);
94
95 if (currentBranch && branchSet.has(currentBranch)) {
96 return currentBranch;
97 }
98
99 for (const candidate of FALLBACK_TRUNK_CANDIDATES) {
100 if (branchSet.has(candidate)) {
101 return candidate;
102 }
103 }
104
105 return branchList[0];
106}
107
108export async function createWorktree(
109 config: Config,

Callers 15

git.test.tsFile · 0.90
listBranchesMethod · 0.90
resolveTrunkBranchMethod · 0.90
resolveTrunkBranchFunction · 0.90
lifecycle.test.tsFile · 0.90

Calls 3

listLocalBranchesFunction · 0.85
getCurrentBranchFunction · 0.85
hasMethod · 0.45