diff --git a/.changeset/fix-setup-branch-naming.md b/.changeset/fix-setup-branch-naming.md new file mode 100644 index 0000000..0772c6e --- /dev/null +++ b/.changeset/fix-setup-branch-naming.md @@ -0,0 +1,5 @@ +--- +"@fnebenfuehr/worktree-cli": patch +--- + +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 }); 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;