import{a as i,b as u}from"./chunk-74CEPOFO.js";import"./chunk-DXB73IDG.js";var w={name:"ag-worktree",summary:"manage isolated virtual worktrees",usage:"ag-worktree <enter|exit|list|delete> [args]",options:["  enter   <name> [--branch <branch>]  create (if needed) and enter a worktree","  exit                                 leave the active worktree, restore cwd","  list                                 show all worktrees with active indicator","  delete  <name>                       remove a worktree","  --help                               display this help and exit"],examples:["ag-worktree enter my-feature","ag-worktree enter hotfix --branch fix/login-bug","ag-worktree list","ag-worktree exit","ag-worktree delete my-feature"]},g={name:"ag-worktree",async execute(a,s){if(u(a))return i(w);let r=s.bash?.services?.worktreeManager;if(!r)return{stdout:"",stderr:`ag-worktree: worktree manager not available
`,exitCode:1};let d=a[0];if(!d)return i(w);switch(d){case"enter":{let e=a[1];if(!e)return{stdout:"",stderr:`ag-worktree: missing worktree name
Usage: ag-worktree enter <name> [--branch <branch>]
`,exitCode:1};let o=a.indexOf("--branch"),n=o!==-1?a[o+1]:void 0;if(o!==-1&&!n)return{stdout:"",stderr:`ag-worktree: --branch requires a value
`,exitCode:1};try{let t=r.getWorktree(e);return t||(t=r.createWorktree({name:e,branch:n,originalCwd:s.cwd})),await s.fs.mkdir(t.path,{recursive:!0}),r.enterWorktree(t.id),{stdout:`Entered worktree "${t.name}" (${t.id})
  path:   ${t.path}
  branch: ${t.branch}
`,stderr:"",exitCode:0}}catch(t){return{stdout:"",stderr:`ag-worktree: ${t instanceof Error?t.message:String(t)}
`,exitCode:1}}}case"exit":try{let e=r.exitWorktree();return e?{stdout:`Exited worktree. Restored cwd: ${e.originalCwd}
`,stderr:"",exitCode:0}:{stdout:"",stderr:`ag-worktree: no active worktree to exit
`,exitCode:1}}catch(e){return{stdout:"",stderr:`ag-worktree: ${e instanceof Error?e.message:String(e)}
`,exitCode:1}}case"list":{let e=r.listWorktrees();if(e.length===0)return{stdout:`No worktrees.
`,stderr:"",exitCode:0};let o=r.getActive(),n=`Worktrees:
`;for(let t of e){let c=o&&o.id===t.id?" *":"";n+=`  ${t.name} (${t.id})${c}
`,n+=`    path:   ${t.path}
`,n+=`    branch: ${t.branch}
`}return{stdout:n,stderr:"",exitCode:0}}case"delete":{let e=a[1];return e?r.deleteWorktree(e)?{stdout:`Deleted worktree "${e}"
`,stderr:"",exitCode:0}:{stdout:"",stderr:`ag-worktree: worktree "${e}" not found
`,exitCode:1}:{stdout:"",stderr:`ag-worktree: missing worktree name
Usage: ag-worktree delete <name>
`,exitCode:1}}default:return{stdout:"",stderr:`ag-worktree: unknown subcommand: ${d}
`,exitCode:1}}}};export{g as agWorktreeCommand};
