From 1431028bcf73c30c42dda5cf01294a2e472a44b2 Mon Sep 17 00:00:00 2001 From: Florin Nebenfuehr Date: Sun, 14 Dec 2025 13:25:20 +0100 Subject: [PATCH 1/2] fix: setup command uses correct branch-to-dir naming and handles errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Use branchToDirName() to convert slashes to dashes (e.g. chore/foo -> chore-foo) - Stop spinner and show error message on setup failure - Update prompt to show correct target directory name 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .changeset/fix-setup-branch-naming.md | 5 +++++ src/commands/setup.ts | 15 ++++++++++++--- src/lib/worktree.ts | 2 +- 3 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 .changeset/fix-setup-branch-naming.md diff --git a/.changeset/fix-setup-branch-naming.md b/.changeset/fix-setup-branch-naming.md new file mode 100644 index 0000000..b1631f9 --- /dev/null +++ b/.changeset/fix-setup-branch-naming.md @@ -0,0 +1,5 @@ +--- +"@fnebenfuehr/worktree-cli": patch +--- + +Fix setup command: use correct branch-to-directory naming (slashes to dashes) and properly stop spinner on error diff --git a/src/commands/setup.ts b/src/commands/setup.ts index 564e8bb..b5c481d 100644 --- a/src/commands/setup.ts +++ b/src/commands/setup.ts @@ -1,15 +1,18 @@ import * as worktree from '@/lib/worktree'; import { gitGetCurrentBranch } from '@/utils/git'; -import { cancel, intro, isInteractive, outro, promptConfirm, spinner } from '@/utils/prompts'; +import { branchToDirName } from '@/utils/naming'; +import { cancel, intro, isInteractive, log, outro, promptConfirm, spinner } from '@/utils/prompts'; +import { tryCatch } from '@/utils/try-catch'; export async function setupCommand(): Promise { const currentBranch = await gitGetCurrentBranch(); + const targetDirName = branchToDirName(currentBranch); if (isInteractive()) { intro('Setup Worktree Structure'); const confirmed = await promptConfirm( - `Convert repository to worktree structure? Current branch '${currentBranch}' will be moved to ./${currentBranch}/`, + `Convert repository to worktree structure? Current branch '${currentBranch}' will be moved to ./${targetDirName}/`, true ); @@ -22,7 +25,13 @@ export async function setupCommand(): Promise { const s = spinner(); s.start('Converting repository structure'); - const result = await worktree.setup(); + const { error, data: result } = await tryCatch(worktree.setup()); + + if (error) { + s.stop('Setup failed'); + log.error(error.message); + return 1; + } s.stop('Repository converted successfully'); outro(`cd ${result.worktreePath}\nworktree create feature/`); diff --git a/src/lib/worktree.ts b/src/lib/worktree.ts index 9cadb87..42c0841 100644 --- a/src/lib/worktree.ts +++ b/src/lib/worktree.ts @@ -376,7 +376,7 @@ export async function setup(targetDir?: string): Promise { } const tempDir = `.tmp-worktree-setup-${process.pid}`; - const targetDirName = targetDir || currentBranch; + const targetDirName = targetDir || branchToDirName(currentBranch); const itemsToRollback: string[] = []; let interrupted = false; From 039c91ba14dde83ce6de3afd36f1c8896b84a114 Mon Sep 17 00:00:00 2001 From: Florin Nebenfuehr Date: Sun, 14 Dec 2025 16:00:56 +0100 Subject: [PATCH 2/2] fix: add branchToDirName to clone command for consistency MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .changeset/fix-setup-branch-naming.md | 2 +- src/commands/clone.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.changeset/fix-setup-branch-naming.md b/.changeset/fix-setup-branch-naming.md index b1631f9..0772c6e 100644 --- a/.changeset/fix-setup-branch-naming.md +++ b/.changeset/fix-setup-branch-naming.md @@ -2,4 +2,4 @@ "@fnebenfuehr/worktree-cli": patch --- -Fix setup command: use correct branch-to-directory naming (slashes to dashes) and properly stop spinner on error +Fix setup and clone commands: use correct branch-to-directory naming (slashes to dashes) and properly stop spinner on setup error diff --git a/src/commands/clone.ts b/src/commands/clone.ts index 6c2ff1a..415ab38 100644 --- a/src/commands/clone.ts +++ b/src/commands/clone.ts @@ -4,7 +4,7 @@ import { writeConfig } from '@/lib/config'; import { FileSystemError, GitError, ValidationError, WorktreeError } from '@/utils/errors'; import { move } from '@/utils/fs'; import { gitGetCurrentBranch } from '@/utils/git'; -import { extractRepoName } from '@/utils/naming'; +import { branchToDirName, extractRepoName } from '@/utils/naming'; import { intro, isInteractive, outro, promptGitUrl, spinner } from '@/utils/prompts'; import { tryCatch } from '@/utils/try-catch'; import { isValidGitUrl, VALIDATION_ERRORS } from '@/utils/validation'; @@ -65,7 +65,7 @@ export async function cloneCommand(gitUrl?: string): Promise { ); } - const targetDir = `${repoName}/${defaultBranch}`; + const targetDir = `${repoName}/${branchToDirName(defaultBranch)}`; await move(tempClone, targetDir); await writeConfig(targetDir, { defaultBranch });