"use strict";var C=Object.create;var h=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var M=Object.getPrototypeOf,_=Object.prototype.hasOwnProperty;var $=(t,s)=>{for(var e in s)h(t,e,{get:s[e],enumerable:!0})},S=(t,s,e,r)=>{if(s&&typeof s=="object"||typeof s=="function")for(let i of E(s))!_.call(t,i)&&i!==e&&h(t,i,{get:()=>s[i],enumerable:!(r=D(s,i))||r.enumerable});return t};var P=(t,s,e)=>(e=t!=null?C(M(t)):{},S(s||!t||!t.__esModule?h(e,"default",{value:t,enumerable:!0}):e,t)),v=t=>S(h({},"__esModule",{value:!0}),t);var A={};$(A,{DEFAULT_BACKUP_DIR:()=>m,DROP:()=>N,StrategyStatus_CONTINUE:()=>O,StrategyStatus_FAIL:()=>z,StrategyStatus_OK:()=>j,StrategyStatus_SKIP:()=>I,backupFile:()=>T,createSkipDirectoryMatcher:()=>b,hasConflict:()=>x,listMatchingFiles:()=>R,restoreBackups:()=>U});module.exports=v(A);var l=P(require("fs/promises")),a=P(require("path")),N=Symbol("MERGE_DROP"),m=".merge-backups",j=0,O=1,z=2,I=3,x=t=>t.includes("<<<<<<<")&&t.includes("=======")&&t.includes(">>>>>>>"),R=async({root:t=process.cwd(),include:s,exclude:e,matcher:r,includeNonConflicted:i,debug:o,backupDir:n=m})=>{for(let c of[...s,...e]){if(c.startsWith("!"))throw new Error(`Negation not allowed in include/exclude: ${c}`);c.includes("\\")&&console.warn(`Use '/' as path separator: ${c}`)}e.push(n);let f=c=>{let g=c.replace(/\\/g,"/");return r.isMatch(g,s)&&!r.isMatch(g,e)},d=b(s,n?[...e,n]:e,r),u=[],F=async c=>{let g=await l.default.readdir(c,{withFileTypes:!0});for(let y of g){let p=a.default.join(c,y.name),w=a.default.relative(t,p).replace(/\\+/g,"/");if(y.isDirectory())!/node_modules|\.git/.test(y.name)&&!d(w)&&await F(p);else if(f(w))try{let k=await l.default.readFile(p,"utf8");i||x(k)?u.push({filePath:w,content:k}):o&&console.info(`Skipped (no conflicts): ${p}`)}catch{console.warn(`Skipped (unreadable): ${p}`)}}};return await F(t),u},b=(t,s,e)=>{if(t.length>0&&t.every(o=>!o.includes("/")&&!o.includes("**")))return()=>!1;let r=new Set,i=new Set;for(let o of t)if(o.includes("/")){let n=o.split("/").slice(0,-1).join("/");n&&r.add(n)}r.has("**")&&r.clear();for(let o of s)if(o.endsWith("/**")){let n=o.slice(0,-3);n&&i.add(n)}return o=>e.isMatch(o,[...i])||r.size>0&&!e.isMatch(o,[...r])},T=async(t,s=m)=>{let e=a.default.relative(process.cwd(),t),r=a.default.join(s,e);return await l.default.mkdir(a.default.dirname(r),{recursive:!0}),await l.default.copyFile(t,r),r},U=async(t=".merge-backups")=>{let s=async(e,r="")=>{try{let i=await l.default.readdir(e,{withFileTypes:!0});for(let o of i){let n=a.default.join(e,o.name),f=a.default.join(r,o.name),d=a.default.join(process.cwd(),f);if(o.isDirectory())await s(n,f);else try{await l.default.mkdir(a.default.dirname(d),{recursive:!0}),await l.default.copyFile(n,d)}catch(u){console.warn(`Failed to restore ${n.replace(/[\r\n\t]/g,"")}: ${u}`)}}}catch(i){console.warn(`Failed to read backup directory ${e}: ${i}`)}};await s(t)};0&&(module.exports={DEFAULT_BACKUP_DIR,DROP,StrategyStatus_CONTINUE,StrategyStatus_FAIL,StrategyStatus_OK,StrategyStatus_SKIP,backupFile,createSkipDirectoryMatcher,hasConflict,listMatchingFiles,restoreBackups});
