module.exports=[845427,a=>{"use strict";var b=a.i(233405),c=a.i(522734),d=a.i(924868),e=a.i(814747),f=a.i(446786),g=a.i(26683);function h(a){return a.startsWith("~/")||"~"===a?e.default.join(f.default.homedir(),a.slice(1)):a}async function i(a,f,i,k){let l=h(a),m=e.default.join(l,".worktrees","task-"+f),n="task/"+f;if(!(0,c.existsSync)(l))throw Error(`项目本地路径不存在：${l}`);try{(0,b.execFileSync)("git",["rev-parse","--is-inside-work-tree"],{cwd:l,encoding:"utf-8",timeout:5e3,stdio:["pipe","pipe","pipe"]})}catch{throw Error(`项目本地路径不是 Git 仓库，无法创建 worktree：${l}`)}await (0,d.mkdir)(e.default.join(l,".worktrees"),{recursive:!0});let o=(0,b.execFileSync)("git",["worktree","list","--porcelain"],{cwd:l,encoding:"utf-8",timeout:1e4}),p=e.default.normalize(m).replace(/\\/g,"/");if(o.split("\n").some(a=>a.startsWith("worktree ")&&a.slice(9).replace(/\\/g,"/")===p))return j(l,m,k),{worktreePath:m,worktreeBranch:n};if((0,c.existsSync)(m)&&(g.logger.warn(`[worktree] Directory exists but not tracked by git, removing: ${m}`),(0,b.execFileSync)("git",["worktree","remove",m,"--force"],{cwd:l,encoding:"utf-8",timeout:3e4})),(0,b.execFileSync)("git",["branch","--list",n],{cwd:l,encoding:"utf-8",timeout:5e3}).trim())(0,b.execFileSync)("git",["worktree","add",m,n],{cwd:l,encoding:"utf-8",timeout:3e4});else{let a=i;try{(0,b.execFileSync)("git",["rev-parse","--verify",i],{cwd:l,encoding:"utf-8",timeout:5e3,stdio:["pipe","pipe","pipe"]})}catch{try{(0,b.execFileSync)("git",["rev-parse","--verify",`origin/${i}`],{cwd:l,encoding:"utf-8",timeout:5e3,stdio:["pipe","pipe","pipe"]}),a=`origin/${i}`}catch{throw Error(`Base branch '${i}' does not exist locally or on remote. Available branches: `+(0,b.execFileSync)("git",["branch","-a","--format=%(refname:short)"],{cwd:l,encoding:"utf-8",timeout:5e3}).trim().split("\n").join(", "))}}(0,b.execFileSync)("git",["worktree","add","-b",n,m,a],{cwd:l,encoding:"utf-8",timeout:3e4})}return j(l,m,k),{worktreePath:m,worktreeBranch:n}}function j(a,b,d){let f=g.logger.create("worktree"),h=["node_modules",".next"];for(let g of d?["",d]:[""])if((0,c.existsSync)(e.default.join(a,g,"package.json")))for(let d of h){let h=g?e.default.join(g,d):d,i=e.default.join(a,h),j=e.default.join(b,h);if((0,c.existsSync)(i)){try{(0,c.lstatSync)(j);continue}catch{}try{(0,c.symlinkSync)(i,j,"junction"),f.info(`Symlinked ${h}`,{from:i,to:j})}catch(a){f.warn(`Failed to symlink ${h}`,{error:String(a)})}}}}async function k(a,d){let f=h(a),g=e.default.join(f,".worktrees","task-"+d),i="task/"+d;(0,c.existsSync)(g)&&(0,b.execFileSync)("git",["worktree","remove",g,"--force"],{cwd:f,encoding:"utf-8",timeout:3e4}),(0,b.execFileSync)("git",["branch","--list",i],{cwd:f,encoding:"utf-8",timeout:5e3}).trim()&&(0,b.execFileSync)("git",["branch","-D",i],{cwd:f,encoding:"utf-8",timeout:5e3})}a.s(["createWorktree",0,i,"removeWorktree",0,k])}];

//# sourceMappingURL=src_lib_worktree_ts_06cucy3._.js.map