"use strict";(()=>{var e={};e.id=3546,e.ids=[3546],e.modules={85890:e=>{e.exports=require("better-sqlite3")},20399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},30517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},61282:e=>{e.exports=require("child_process")},84770:e=>{e.exports=require("crypto")},92048:e=>{e.exports=require("fs")},19801:e=>{e.exports=require("os")},55315:e=>{e.exports=require("path")},21764:e=>{e.exports=require("util")},98165:(e,r,t)=>{t.r(r),t.d(r,{originalPathname:()=>m,patchFetch:()=>g,requestAsyncStorage:()=>h,routeModule:()=>c,serverHooks:()=>d,staticGenerationAsyncStorage:()=>f});var o={};t.r(o),t.d(o,{POST:()=>u});var s=t(49303),n=t(88716),i=t(60670),a=t(87070),p=t(97425),l=t(67722);async function u(){try{let e=(0,l.a$)();if(0===e.length)return a.NextResponse.json({error:"No repositories configured. Please set WORKTREE_REPOS or CM_ROOT_DIR environment variable."},{status:400});let r=await (0,l.Lj)(e),t=(0,p.n)();(0,l.h2)(t,r);let o=new Set(r.map(e=>e.repositoryPath));return a.NextResponse.json({success:!0,message:`Successfully synced ${r.length} worktree(s) from ${o.size} repository/repositories`,worktreeCount:r.length,repositoryCount:o.size,repositories:Array.from(o)},{status:200})}catch(r){console.error("Error syncing repositories:",r);let e=r instanceof Error?r.message:"Failed to sync repositories";return a.NextResponse.json({error:e},{status:500})}}let c=new s.AppRouteRouteModule({definition:{kind:n.x.APP_ROUTE,page:"/api/repositories/sync/route",pathname:"/api/repositories/sync",filename:"route",bundlePath:"app/api/repositories/sync/route"},resolvedPagePath:"/home/runner/work/CommandMate/CommandMate/src/app/api/repositories/sync/route.ts",nextConfigOutput:"",userland:o}),{requestAsyncStorage:h,staticGenerationAsyncStorage:f,serverHooks:d}=c,m="/api/repositories/sync/route";function g(){return(0,i.patchFetch)({serverHooks:d,staticGenerationAsyncStorage:f})}},67722:(e,r,t)=>{t.d(r,{Lj:()=>c,a$:()=>l,e9:()=>u,h2:()=>h});var o=t(61282),s=t(21764),n=t(55315),i=t.n(n),a=t(75748),p=t(93346);function l(){let e=process.env.WORKTREE_REPOS;if(e&&e.trim())return e.split(",").map(e=>e.trim()).filter(e=>e.length>0);let r=(0,p.Hb)("CM_ROOT_DIR");return r&&r.trim()?[r.trim()]:[]}async function u(e){let r=(0,s.promisify)(o.exec);try{let{stdout:t}=await r("git worktree list",{cwd:e}),o=function(e){if(!e||""===e.trim())return[];let r=e.trim().split("\n"),t=[];for(let e of r){let r=e.trim();if(!r)continue;let o=r.match(/^(.+?)\s+([a-z0-9]+)\s+(?:\[(.+?)\]|\(detached HEAD\))/);if(o){let[,e,r,s]=o;t.push({path:e.trim(),branch:s||`detached-${r}`,commit:r})}}return t}(t),s=i().resolve(e),n=i().basename(s);return o.map(e=>({id:function(e,r){if(!e)return"";let t=e=>e.toLowerCase().replace(/[^a-z0-9-]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,""),o=t(e);if(r){let e=t(r);return`${e}-${o}`}return o}(e.branch,n),name:e.branch,path:i().resolve(e.path),repositoryPath:s,repositoryName:n})).filter(e=>["/etc","/root","/sys","/proc","/dev","/boot","/bin","/sbin","/usr/bin","/usr/sbin"].some(r=>e.path.startsWith(r))?(console.warn(`Skipping potentially unsafe worktree path: ${e.path}`),!1):!(e.path.includes("\0")||e.path.includes(".."))||(console.warn(`Skipping path with potentially malicious characters: ${e.path}`),!1))}catch(t){let e=t instanceof Error?t.message:String(t),r=t.code;if(e?.includes("not a git repository")||128===r)return[];throw t}}async function c(e){let r=[];for(let t of e)try{console.log(`Scanning repository: ${t}`);let e=await u(t);r.push(...e),console.log(`  Found ${e.length} worktree(s)`)}catch(e){console.error(`Error scanning repository ${t}:`,e)}return r}function h(e,r){if(0===r.length)return;let t=new Map;for(let e of r){let r=e.repositoryPath||"";t.has(r)||t.set(r,[]),t.get(r).push(e)}for(let[r,o]of t){if(!r)continue;let t=(0,a.Pv)(e,r),s=new Set(o.map(e=>e.id)),n=t.filter(e=>!s.has(e));if(n.length>0){let t=(0,a.pM)(e,n);console.log(`Removed ${t.deletedCount} deleted worktree(s) from ${r}`)}for(let r of o)(0,a.ly)(e,r)}}}};var r=require("../../../../webpack-runtime.js");r.C(e);var t=e=>r(r.s=e),o=r.X(0,[8948,5972,7425],()=>t(98165));module.exports=o})();