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

Method deleteWorkspaceBranchIfSafe

src/node/worktree/WorktreeManager.ts:725–809  ·  view source on GitHub ↗
(args: {
    projectPath: string;
    workspaceName: string;
    branchName: string | null;
    force: boolean;
    isInPlace: boolean;
    noHooksEnv: GitExecOptions;
    allowWorkspaceNameFallback: boolean;
  })

Source from the content-addressed store, hash-verified

723 }
724
725 private async deleteWorkspaceBranchIfSafe(args: {
726 projectPath: string;
727 workspaceName: string;
728 branchName: string | null;
729 force: boolean;
730 isInPlace: boolean;
731 noHooksEnv: GitExecOptions;
732 allowWorkspaceNameFallback: boolean;
733 }): Promise<void> {
734 // For git worktree workspaces, workspaceName is the branch name.
735 // Now that archiving exists, deleting a workspace should also delete its local branch by default.
736 if (args.isInPlace) {
737 return;
738 }
739
740 const branchToDelete =
741 args.branchName?.trim() ?? (args.allowWorkspaceNameFallback ? args.workspaceName.trim() : "");
742 if (!branchToDelete) {
743 log.debug("Skipping git branch deletion: workspace branch is unknown", {
744 projectPath: args.projectPath,
745 workspaceName: args.workspaceName,
746 });
747 return;
748 }
749
750 let localBranches: string[];
751 try {
752 localBranches = await listLocalBranches(args.projectPath);
753 } catch (error) {
754 log.debug("Failed to list local branches; skipping branch deletion", {
755 projectPath: args.projectPath,
756 workspaceName: branchToDelete,
757 error: getErrorMessage(error),
758 });
759 return;
760 }
761
762 if (!localBranches.includes(branchToDelete)) {
763 log.debug("Skipping git branch deletion: branch does not exist locally", {
764 projectPath: args.projectPath,
765 workspaceName: branchToDelete,
766 });
767 return;
768 }
769
770 const protectedBranches = await this.getProtectedBranches(
771 args.projectPath,
772 localBranches,
773 args.noHooksEnv
774 );
775 if (protectedBranches.has(branchToDelete)) {
776 log.debug("Skipping git branch deletion: protected branch", {
777 projectPath: args.projectPath,
778 workspaceName: branchToDelete,
779 });
780 return;
781 }
782

Callers 1

Calls 7

getProtectedBranchesMethod · 0.95
listLocalBranchesFunction · 0.90
getErrorMessageFunction · 0.90
execFileAsyncFunction · 0.90
debugMethod · 0.80
hasMethod · 0.45

Tested by

no test coverage detected