import{a as m}from"./chunk-DLPEQYKV.mjs";import{b as d}from"./chunk-LVPDR3D2.mjs";import{a as p}from"./chunk-O53OUY2B.mjs";import{k as u}from"./chunk-QPV2G662.mjs";import h from"path";import g from"fs";import{execSync as C}from"child_process";import{pathToFileURL as w}from"url";var b="git-json-resolver.config.js",k=()=>{try{return C("git rev-parse --show-toplevel",{encoding:"utf8"}).trim()}catch{return process.cwd()}},x=async()=>{let t=[process.cwd(),k()],e=[b,"git-json-resolver.config.ts"];for(let o of t)for(let c of e){let i=h.join(o,c);if(g.existsSync(i)){let s=await import(w(i).href);return s.default||s}}return{}},y=t=>{let e=h.join(t,b);g.existsSync(e)&&(console.error(`Config file already exists: ${e}`),process.exit(1));let o=`/**
 * git-json-resolver configuration
 * Docs: https://github.com/react18-tools/git-json-resolver
 */
module.exports = ${JSON.stringify(p,null,2)};
`;g.writeFileSync(e,o,"utf8"),console.log(`Created starter config at ${e}`)},F=t=>{var a,l;let e={},o=!1,c,i,s=t.slice(2).filter(r=>!r.startsWith("--"));s.length===3&&(i=[s[0],s[1],s[2]]);for(let r=2;r<t.length;r++){let f=t[r],n=t[r+1];if(!(i&&!f.startsWith("--")))switch(f){case"--include":e.include=(a=n==null?void 0:n.split(","))!=null?a:[],r++;break;case"--exclude":e.exclude=(l=n==null?void 0:n.split(","))!=null?l:[],r++;break;case"--matcher":e.matcher=n,r++;break;case"--debug":e.debug=!0;break;case"--sidecar":e.writeConflictSidecar=!0;break;case"--init":o=!0;break;case"--restore":c=n,r++;break;default:f.startsWith("--")&&console.warn(`Unknown option: ${f}`)}}return{overrides:e,init:o,restore:c,gitMergeFiles:i}};(async()=>{try{let{overrides:t,init:e,restore:o,gitMergeFiles:c}=F(process.argv);e&&(y(process.cwd()),process.exit(0));let i=await x(),s={...i,...t};if(o&&(await u(o||i.backupDir||".merge-backups"),console.log(`Restored backups from ${o}`),process.exit(0)),c){let[a,l,r]=c;await d(a,l,r,s);return}await m(s)}catch(t){console.error("Failed:",t),process.exit(1)}})();export{k as a,x as b,y as c,F as d};
