(
projectPath: string,
localBranches: string[],
noHooksEnv: GitExecOptions
)
| 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, |
no test coverage detected