diff --git a/src/commands/helpers.ts b/src/commands/helpers.ts index af8262c..8c92ef5 100644 --- a/src/commands/helpers.ts +++ b/src/commands/helpers.ts @@ -128,7 +128,7 @@ export async function resolveConflicts( ) if (resolved.exitCode !== 0) { - const stderr = resolved.stderr.toString().trim() + const stderr = resolved.stderr.trim() throw new Error(`Claude failed to resolve ${file}: ${stderr || "(no output)"}`) } diff --git a/src/git.ts b/src/git.ts index de40efc..1871287 100644 --- a/src/git.ts +++ b/src/git.ts @@ -72,7 +72,8 @@ export async function createWorktree(branch: string, worktreePath: string, cwd: } if (result.exitCode !== 0) { if (switchedFromBranch) await checkout(branch, cwd).catch(() => {}) - throw new Error(`Failed to create worktree for "${branch}": ${result.stderr.toString().trim()}`) + const stderr = result.stderr.toString().trim() + throw new Error(`Failed to create worktree for "${branch}": ${stderr || "(no output)"}`) } return { branchCreated: exists !== "local" } } @@ -98,7 +99,8 @@ export async function deleteLocalBranch(branch: string, cwd: string): Promise { const result = await $`git checkout ${branch}`.cwd(cwd).nothrow().quiet() if (result.exitCode !== 0) { - throw new Error(`Failed to checkout branch "${branch}": ${result.stderr.toString().trim()}`) + const stderr = result.stderr.toString().trim() + throw new Error(`Failed to checkout branch "${branch}": ${stderr || "(no output)"}`) } } @@ -117,7 +119,8 @@ export async function merge(branch: string, cwd: string, opts?: { squash?: boole // Not a conflict — some other merge failure const label = opts?.squash ? "squash-merge" : "merge" - throw new Error(`Failed to ${label} branch "${branch}": ${result.stderr.toString().trim()}`) + const stderr = result.stderr.toString().trim() + throw new Error(`Failed to ${label} branch "${branch}": ${stderr || "(no output)"}`) } /** Return the staged diff as text. */ @@ -129,7 +132,8 @@ export async function diffStaged(cwd: string): Promise { export async function commit(message: string, cwd: string): Promise { const result = await $`git commit -m ${message}`.cwd(cwd).nothrow().quiet() if (result.exitCode !== 0) { - throw new Error(`Failed to commit: ${result.stderr.toString().trim()}`) + const stderr = result.stderr.toString().trim() + throw new Error(`Failed to commit: ${stderr || "(no output)"}`) } } @@ -155,7 +159,8 @@ export async function stageFile(file: string, cwd: string): Promise { export async function commitMerge(cwd: string): Promise { const result = await $`git commit --no-edit`.cwd(cwd).nothrow().quiet() if (result.exitCode !== 0) { - throw new Error(`Failed to commit merge: ${result.stderr.toString().trim()}`) + const stderr = result.stderr.toString().trim() + throw new Error(`Failed to commit merge: ${stderr || "(no output)"}`) } } @@ -193,7 +198,8 @@ export async function rebaseContinue(cwd: string): Promise { const files = unmerged.trim().split("\n").filter(Boolean) if (files.length > 0) return files - throw new Error(`Rebase --continue failed: ${result.stderr.toString().trim()}`) + const stderr = result.stderr.toString().trim() + throw new Error(`Rebase --continue failed: ${stderr || "(no output)"}`) } /** Abort an in-progress rebase. */