-
Notifications
You must be signed in to change notification settings - Fork 0
Create src/git.ts safe git wrapper module to eliminate try/catch chains #175
Copy link
Copy link
Closed
Description
Problem
The codebase has 92 try blocks, 95 catch blocks across 2298 lines. Most exist because raw execSync throws on any git failure. Instead of try/catch everywhere, we need a safe abstraction layer.
What to do
Create src/git.ts with these safe wrapper functions that never throw:
Core helper
function gitExec(cmd: string, cwd: string): { ok: boolean; output: string }Runs execSync, catches internally, returns result object. All other helpers build on this.
State query functions (check before act)
function branchExists(cwd: string, branch: string): boolean
function worktreeExists(cwd: string, path: string): boolean
function isGitRepo(dir: string): boolean // move from worktree.ts
function hasUncommittedChanges(cwd: string): boolean
function getCurrentBranch(cwd: string): string | null
function hasConflicts(cwd: string): booleanSafe action functions
function checkout(cwd: string, branch: string): boolean
function deleteBranch(cwd: string, branch: string): boolean // checks existence first
function pull(cwd: string, remote?: string, branch?: string): { ok: boolean; output: string }
function push(cwd: string, remote?: string): { ok: boolean; output: string }
function merge(cwd: string, branch: string): { ok: boolean; hasConflicts: boolean; output: string }
function stash(cwd: string): boolean // returns true if something was stashed
function stashPop(cwd: string): boolean
function mergeAbort(cwd: string): void
function rebase(cwd: string, onto: string): { ok: boolean; output: string }
function rebaseAbort(cwd: string): voidDesign principles
- No function throws — all return result objects or booleans
- Check state before acting —
deleteBranchchecksbranchExistsfirst - Log at dim() level when operations fail silently (not
/* ignore */) - Import
dimfrom./logging.jsfor diagnostic output - Export everything for use in worktree.ts and process.ts
Files
src/git.ts— NEW file
Acceptance
- All git operations wrapped safely
- No function throws exceptions
- Failed operations logged at dim() level
- Exported and ready for worktree.ts and process.ts refactors
Reactions are currently unavailable