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

Method getProtectedBranches

src/node/worktree/WorktreeManager.ts:811–846  ·  view source on GitHub ↗
(
    projectPath: string,
    localBranches: string[],
    noHooksEnv: GitExecOptions
  )

Source from the content-addressed store, hash-verified

809 }
810
811 private async getProtectedBranches(
812 projectPath: string,
813 localBranches: string[],
814 noHooksEnv: GitExecOptions
815 ): Promise<Set<string>> {
816 const protectedBranches = new Set<string>(PROTECTED_BRANCH_NAMES);
817
818 // If there's only one local branch, treat it as protected (likely trunk).
819 if (localBranches.length === 1) {
820 protectedBranches.add(localBranches[0]);
821 }
822
823 const currentBranch = await getCurrentBranch(projectPath);
824 if (currentBranch) {
825 protectedBranches.add(currentBranch);
826 }
827
828 // If origin/HEAD points at a local branch, also treat it as protected.
829 try {
830 using originHeadProc = execFileAsync(
831 "git",
832 ["-C", projectPath, "symbolic-ref", "refs/remotes/origin/HEAD"],
833 noHooksEnv
834 );
835 const { stdout } = await originHeadProc.result;
836 const ref = stdout.trim();
837 const prefix = "refs/remotes/origin/";
838 if (ref.startsWith(prefix)) {
839 protectedBranches.add(ref.slice(prefix.length));
840 }
841 } catch {
842 // No origin/HEAD (or not a git repo) - ignore.
843 }
844
845 return protectedBranches;
846 }
847
848 private async isBranchCheckedOutByWorktree(
849 projectPath: string,

Callers 1

Calls 3

getCurrentBranchFunction · 0.90
execFileAsyncFunction · 0.90
addMethod · 0.80

Tested by

no test coverage detected