"use strict";exports.id=126,exports.ids=[126],exports.modules={60126:(a,b,c)=>{c.a(a,async(a,d)=>{try{c.d(b,{O:()=>l,createWorktree:()=>o,hasGhCli:()=>n,hasRemote:()=>m,isGitRepo:()=>k,listWorktrees:()=>s,mergeWorktree:()=>p,removeWorktree:()=>r});var e=c(7206),f=c(73024),g=c(76760),h=c.n(g),i=a([e]);e=(i.then?(await i)():i)[0];let w=h().join(".reflex","worktrees"),x=".reflex/worktrees/";async function j(a,b){let c=await (0,e.execa)("git",b,{cwd:a,timeout:3e4,reject:!1});return{stdout:"string"==typeof c.stdout?c.stdout:"",stderr:"string"==typeof c.stderr?c.stderr:"",code:"number"==typeof c.exitCode?c.exitCode:1}}async function k(a){let b=await j(a,["rev-parse","--is-inside-work-tree"]);return 0===b.code&&"true"===b.stdout.trim()}async function l(a){let b=await j(a,["symbolic-ref","--short","refs/remotes/origin/HEAD"]);return 0===b.code&&b.stdout.trim()?b.stdout.trim().replace(/^origin\//,""):(await j(a,["rev-parse","--abbrev-ref","HEAD"])).stdout.trim()||"main"}async function m(a){let b=await j(a,["remote"]);return 0===b.code&&b.stdout.trim().length>0}async function n(){let a=await (0,e.execa)("gh",["--version"],{timeout:5e3,reject:!1});return"number"==typeof a.exitCode&&0===a.exitCode}async function o(a){if(!await k(a.rootPath))throw Error("createWorktree: project root is not a git repo");let b=h().join(a.rootPath,w,a.slug),c=a.baseRef??await l(a.rootPath);try{throw await f.promises.stat(b),Error(`createWorktree: ${b} already exists`)}catch(a){if("ENOENT"!==a.code)throw a}let d=await j(a.rootPath,["rev-parse","--verify",`refs/heads/${a.branch}`]);if(0===d.code)throw Error(`createWorktree: branch ${a.branch} already exists; remove it first`);await f.promises.mkdir(h().dirname(b),{recursive:!0});let e=await j(a.rootPath,["worktree","add","-b",a.branch,b,c]);if(0!==e.code)throw Error(`git worktree add failed (${e.code}): ${e.stderr.trim()||e.stdout.trim()}`);return await u(a.rootPath,b),await v(a.rootPath),{dir:b,branch:a.branch,baseRef:c}}async function p(a){let b=a.intoRef??await l(a.rootPath),c=(await j(a.rootPath,["rev-parse","--abbrev-ref","HEAD"])).stdout.trim(),d=await j(a.rootPath,["checkout",b]);if(0!==d.code)return{ok:!1,conflicts:[],error:`checkout ${b} failed: ${d.stderr.trim()}`};let e=!1===a.noFf?[]:["--no-ff"],f=await j(a.rootPath,["merge",...e,a.branch]);if(0!==f.code){let b=await q(a.rootPath);return{ok:!1,conflicts:b,error:f.stderr.trim()||f.stdout.trim()||"merge failed"}}return c&&c!==b&&await j(a.rootPath,["checkout",c]),{ok:!0,mergedInto:b}}async function q(a){let b=await j(a,["diff","--name-only","--diff-filter=U"]);return 0!==b.code?[]:b.stdout.split("\n").map(a=>a.trim()).filter(Boolean)}async function r(a){let b=h().join(a.rootPath,w,a.slug),c=a.force?["--force"]:[],d=await j(a.rootPath,["worktree","remove",...c,b]);if(0!==d.code)try{return await f.promises.stat(b),{ok:!1,error:d.stderr.trim()||d.stdout.trim()||"worktree remove failed"}}catch{}if(a.deleteBranch??!0){let b=a.force?"-D":"-d";await j(a.rootPath,["branch",b,a.branch])}return await j(a.rootPath,["worktree","prune"]),{ok:!0}}async function s(a){let b=await j(a,["worktree","list","--porcelain"]);if(0!==b.code)return[];let c=[],d=null;for(let e of b.stdout.split("\n")){let b=e.trimEnd();if(!b){d?.dir&&c.push(t(d,a)),d=null;continue}b.startsWith("worktree ")?(d?.dir&&c.push(t(d,a)),d={dir:b.slice(9)}):d&&(b.startsWith("HEAD ")?d.head=b.slice(5):b.startsWith("branch refs/heads/")?d.branch=b.slice(18):"detached"===b?d.detached=!0:"bare"===b&&(d.bare=!0))}return d?.dir&&c.push(t(d,a)),c}function t(a,b){return{dir:a.dir,...a.branch?{branch:a.branch}:{},head:a.head??"",detached:!!a.detached,bare:!!a.bare,isMain:h().resolve(a.dir)===h().resolve(b)}}async function u(a,b){let c=h().join(a,".reflex","memory");await f.promises.mkdir(h().dirname(c),{recursive:!0}),await f.promises.mkdir(h().join(b,".reflex"),{recursive:!0});let d=h().join(b,".reflex","memory");try{if((await f.promises.lstat(d)).isSymbolicLink()&&await f.promises.readlink(d)===c)return;await f.promises.rm(d,{recursive:!0,force:!0})}catch(a){if("ENOENT"!==a.code)throw a}await f.promises.symlink(c,d,"dir")}async function v(a){let b=h().join(a,".reflexignore"),c="";try{c=await f.promises.readFile(b,"utf8")}catch{}if(c.split("\n").map(a=>a.trim()).filter(Boolean).includes(x))return;let d=c?`${c.replace(/\n*$/,"")}
${x}
`:`${x}
`;await f.promises.writeFile(b,d,"utf8")}d()}catch(a){d(a)}})}};