Skip to content

Commit 1e1a476

Browse files
elitanclaude
andcommitted
Match branch delete output format to project delete
Changes: - Show count: "Branch 'X' has N child branch(es):" - Display parent branch in tree with 2-space indent - Use same tree rendering logic as project delete - Use process.exit(1) for consistency (with test mode fallback) Output now matches: Branch 'mala/dev2' has 1 child branch(es): mala/dev2 ↳ mala/dev4 Use --force to delete branch and all child branches 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 9bdee76 commit 1e1a476

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

src/commands/branch/delete.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ export async function branchDeleteCommand(name: string, options: { force?: boole
5656
// Check for child branches
5757
const descendants = collectDescendants(branch, project.branches);
5858
if (descendants.length > 0 && !options.force) {
59+
console.log(`Branch '${chalk.bold(name)}' has ${descendants.length} child branch(es):`);
60+
5961
// Build tree structure for display
6062
interface BranchNode {
6163
branch: any;
@@ -81,29 +83,27 @@ export async function branchDeleteCommand(name: string, options: { force?: boole
8183
}
8284
}
8385

84-
// Render tree
85-
function renderBranch(node: BranchNode, depth: number = 0): string[] {
86-
const lines: string[] = [];
87-
if (depth > 0) {
88-
const indent = ' '.repeat(depth - 1) + '↳ ';
89-
lines.push(chalk.dim(`${indent}${node.branch.name}`));
90-
}
86+
// Render tree (same logic as project delete)
87+
function renderBranch(node: BranchNode, depth: number = 0) {
88+
const indent = depth > 0 ? ' '.repeat(depth) + '↳ ' : ' ';
89+
console.log(chalk.dim(`${indent}${node.branch.name}`));
9190
for (const child of node.children) {
92-
lines.push(...renderBranch(child, depth + 1));
91+
renderBranch(child, depth + 1);
9392
}
94-
return lines;
9593
}
9694

9795
const rootNode = branchMap.get(branch.id)!;
98-
const treeLines = renderBranch(rootNode, 0);
96+
renderBranch(rootNode, 0);
97+
98+
console.log();
99+
console.log(`Use ${chalk.bold('--force')} to delete branch and all child branches`);
99100

100-
let errorMessage = `Cannot delete branch '${name}' because it has child branches:\n\n`;
101-
for (const line of treeLines) {
102-
errorMessage += line + '\n';
101+
// In test mode, throw error instead of exiting for test compatibility
102+
if (process.env.NODE_ENV === 'test') {
103+
throw new UserError(`Branch has ${descendants.length} child branch(es). Use --force to delete.`);
103104
}
104-
errorMessage += `\nTo delete this branch and all its children, use:\n ${CLI_NAME} branch delete ${name} --force`;
105105

106-
throw new UserError(errorMessage);
106+
process.exit(1);
107107
}
108108

109109
// Get ZFS config from state

tests/branch-delete-force.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ describe('Branch Delete with --force', () => {
2222
if (setupDone) return;
2323
setupDone = true;
2424

25+
// Set test mode for proper error handling
26+
process.env.NODE_ENV = 'test';
27+
2528
silenceConsole();
2629
await cleanup.beforeAll();
2730

0 commit comments

Comments
 (0)