diff --git a/.changeset/just-git-mode-and-ls-tree.md b/.changeset/just-git-mode-and-ls-tree.md new file mode 100644 index 00000000..36b2a830 --- /dev/null +++ b/.changeset/just-git-mode-and-ls-tree.md @@ -0,0 +1,5 @@ +--- +"sql-fs-api": patch +--- + +Patch just-git 1.9.1 with four unreleased upstream fixes. `git status` and `git diff` now report a chmod-only change. Switching to a branch where a file differs only in its exec bit now applies that mode, and a local chmod-only change blocks the switch as it does in git. A merge keeps a mode change made on either side. `git ls-tree` works, and `git show`, `git log` and `git diff` accept `--summary`. diff --git a/AGENTS.md b/AGENTS.md index cf33f5e2..a7441b0c 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -66,6 +66,8 @@ Migrations are handwritten numbered SQL files. Add the next migration without ed `just-bash@3.6.0` has a substantial checked-in patch. Dependabot may open upgrade PRs for this package; maintainers review the upgrade and patch before merging. Read `scripts/build-just-bash-patch.mjs` and `patches/` before upgrading it. Regenerate the patch and run the full unit suite and `pnpm verify:local`; do not drop it to make an install pass. +`just-git@1.9.1` is patched with the built `dist/index.js` and `dist/repo/index.js` of four unreleased upstream PRs merged onto the `v1.9.1` commit: blindmansion/just-git#14 (`git ls-tree`), #15 (exec bit on checkout, mode-only changes in status, diff and branch switches), #20 (merge keeps a one-sided mode change) and #21 (`--summary` in `show`, `log` and `diff`). #20 and #21 both edit `src/lib/commit-summary.ts`; the build takes #21's version, which includes #20's output changes. Drop the patch when a just-git release contains all four, then remove the mode repair in `src/api/commands/git-command.ts` and keep `src/api/tests/unit/git-command.just-git-patch.test.ts`. + ## Completion and boundaries Work autonomously on local implementation and reversible verification. Use a separate checkout for concurrent writers. Do not overwrite another agent's changes. Keep secrets out of commits and evidence. Use the disposable verification stack for tests that create databases or inject faults. diff --git a/patches/just-git@1.9.1.patch b/patches/just-git@1.9.1.patch new file mode 100644 index 00000000..e620c8d2 --- /dev/null +++ b/patches/just-git@1.9.1.patch @@ -0,0 +1,1474 @@ +diff --git a/dist/index.js b/dist/index.js +index aa4d521a7d0e0a1573784876ec7aef7a293f4af5..b7445ea99e8da3d1cd6d73ebd1970bd738d8b9b7 100644 +--- a/dist/index.js ++++ b/dist/index.js +@@ -1,21 +1,21 @@ +-var eh=Object.defineProperty;var go=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,n)=>(typeof require<"u"?require:t)[n]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var pe=(e,t)=>()=>(e&&(t=e(e=0)),t);var th=(e,t)=>{for(var n in t)eh(e,n,{get:t[n],enumerable:!0})};function ef(e){return new Yi({_kind:"arg",type:e,required:!0})}function tf(){return ef("string")}function nf(){return ef("number")}var Yi,rf=pe(()=>{"use strict";Yi=class e{_def;constructor(t){this._def=t}name(t){return new e({...this._def,name:t})}describe(t){return new e({...this._def,description:t})}optional(){return new e({...this._def,required:!1})}variadic(){return new e({...this._def,variadic:!0})}default(t){return new e({...this._def,required:!1,default:t})}}});var wo,sf=pe(()=>{"use strict";wo=class e{_def;constructor(t={_kind:"flag"}){this._def=t}describe(t){return new e({...this._def,description:t})}alias(t){return new e({...this._def,short:t})}default(t){return new e({...this._def,default:t})}count(){return new e({...this._def,counted:!0})}}});function of(e){return new Xi({_kind:"option",type:e})}function af(){return of("string")}function cf(){return of("number")}var Xi,ff=pe(()=>{"use strict";Xi=class e{_def;constructor(t){this._def=t}describe(t){return new e({...this._def,description:t})}alias(t){return new e({...this._def,short:t})}env(t){return new e({...this._def,env:t})}impliedValue(t){return new e({...this._def,impliedValue:t})}required(){return new e({...this._def,required:!0})}default(t){return new e({...this._def,default:t})}repeatable(){return new e({...this._def,repeatable:!0,default:[]})}}});function S(){return new wo}var K,W,lf=pe(()=>{"use strict";rf();sf();ff();K={string:af,number:cf};W={string:tf,number:nf}});function nh(e){switch(e.type){case"unknown_option":{let t=`Unknown option "${e.name}".`;return e.suggestions.length>0&&(t+=` Did you mean ${e.suggestions.map(n=>`"${n}"`).join(" or ")}?`),t+=` ++var gh=Object.defineProperty;var xo=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,n)=>(typeof require<"u"?require:t)[n]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var we=(e,t)=>()=>(e&&(t=e(e=0)),t);var wh=(e,t)=>{for(var n in t)gh(e,n,{get:t[n],enumerable:!0})};function lf(e){return new oa({_kind:"arg",type:e,required:!0})}function df(){return lf("string")}function uf(){return lf("number")}var oa,mf=we(()=>{"use strict";oa=class e{_def;constructor(t){this._def=t}name(t){return new e({...this._def,name:t})}describe(t){return new e({...this._def,description:t})}optional(){return new e({...this._def,required:!1})}variadic(){return new e({...this._def,variadic:!0})}default(t){return new e({...this._def,required:!1,default:t})}}});var Po,hf=we(()=>{"use strict";Po=class e{_def;constructor(t={_kind:"flag"}){this._def=t}describe(t){return new e({...this._def,description:t})}alias(t){return new e({...this._def,short:t})}default(t){return new e({...this._def,default:t})}count(){return new e({...this._def,counted:!0})}}});function pf(e){return new ia({_kind:"option",type:e})}function gf(){return pf("string")}function wf(){return pf("number")}var ia,bf=we(()=>{"use strict";ia=class e{_def;constructor(t){this._def=t}describe(t){return new e({...this._def,description:t})}alias(t){return new e({...this._def,short:t})}env(t){return new e({...this._def,env:t})}impliedValue(t){return new e({...this._def,impliedValue:t})}required(){return new e({...this._def,required:!0})}default(t){return new e({...this._def,default:t})}repeatable(){return new e({...this._def,repeatable:!0,default:[]})}}});function S(){return new Po}var K,B,yf=we(()=>{"use strict";mf();hf();bf();K={string:gf,number:wf};B={string:df,number:uf}});function bh(e){switch(e.type){case"unknown_option":{let t=`Unknown option "${e.name}".`;return e.suggestions.length>0&&(t+=` Did you mean ${e.suggestions.map(n=>`"${n}"`).join(" or ")}?`),t+=` + Not all git options are supported. Run 'git --help' for available options.`,t}case"invalid_type":return`Invalid value for "${e.name}": expected ${e.expected}, got "${e.received}".`;case"missing_required":return e.kind==="option"?`Missing required option "--${e.name}".`:`Missing required argument <${e.name}>.`;case"unexpected_positional":return e.maxPositionals===0?`Unexpected argument "${e.value}". This command takes no positional arguments.`:`Unexpected argument "${e.value}". Expected at most ${e.maxPositionals} positional argument${e.maxPositionals===1?"":"s"}.`;case"missing_value":return`Option "--${e.name}" requires a value.`;case"unknown_command":{let t=`git: '${e.path.replace(/^git /,"")}' is not a git command.`;return e.suggestions.length>0&&(t+=` Did you mean ${e.suggestions.map(n=>`"${n}"`).join(" or ")}?`),t+=` +-Run 'git help' for available commands.`,t}}}function Zi(e){return e.map(nh).join(` ++Run 'git help' for available commands.`,t}}}function aa(e){return e.map(bh).join(` + `)+` +-`}function rh(e,t){let n=e.length,r=t.length,o=new Array((n+1)*(r+1));for(let s=0;s<=n;s++)o[s*(r+1)]=s;for(let s=0;s<=r;s++)o[s]=s;for(let s=1;s<=n;s++)for(let i=1;i<=r;i++){let a=e[s-1]===t[i-1]?0:1;o[s*(r+1)+i]=Math.min(o[(s-1)*(r+1)+i]+1,o[s*(r+1)+(i-1)]+1,o[(s-1)*(r+1)+(i-1)]+a)}return o[n*(r+1)+r]}function bo(e,t,n){let r=n??Math.min(Math.max(1,Math.floor(e.length/2)),3);return t.map(s=>({candidate:s,distance:rh(e,s)})).filter(s=>s.distance<=r&&s.distance>0).sort((s,i)=>s.distance-i.distance).slice(0,2).map(s=>s.candidate)}var Qi=pe(()=>{"use strict"});function df(e,t,n,r){let o=[],s=new Map,i=new Map;for(let[u,m]of Object.entries(e)){let h=Es(u);s.set(h,{key:u,def:m}),m.short&&i.set(m.short,{key:u,def:m})}let a={},c=[],f=[],l=0;for(;l`--${C}`)}),l++;continue}if(g.def._kind==="flag"){g.def.counted?a[g.key]=(a[g.key]||0)+1:a[g.key]=!0,l++;continue}let w=p??g.def.impliedValue??n[++l];if(w===void 0){o.push({type:"missing_value",name:g.key}),l++;continue}let b=ks(w,g.def.type,g.key,o);b!==void 0&&(g.def.repeatable?(Array.isArray(a[g.key])||(a[g.key]=[]),a[g.key].push(b)):a[g.key]=b),l++;continue}if(u.startsWith("-")&&u.length>1){let m=u.slice(1);for(let h=0;h0?w:g.def.impliedValue??n[++l];if(b===void 0){o.push({type:"missing_value",name:g.key});break}let R=ks(b,g.def.type,g.key,o);R!==void 0&&(g.def.repeatable?(Array.isArray(a[g.key])||(a[g.key]=[]),a[g.key].push(R)):a[g.key]=R);break}l++;continue}c.push(u),l++}let d=0;for(let u=0;u0?a[h]=p.map(g=>ks(g,m.type,h,o)):m.required?o.push({type:"missing_required",name:h,kind:"arg"}):m.default!==void 0?a[h]=m.default:a[h]=[],d=c.length}else{let p=c[d];p!==void 0?(a[h]=ks(p,m.type,h,o),d++):m.required?o.push({type:"missing_required",name:h,kind:"arg"}):m.default!==void 0&&(a[h]=m.default)}}if(d0?{ok:!1,errors:o}:{ok:!0,args:a,passthrough:f}}function ks(e,t,n,r){switch(t){case"string":return e;case"number":{let o=Number(e);if(Number.isNaN(o)){r.push({type:"invalid_type",name:n,expected:"number",received:e});return}return o}case"boolean":{if(e==="true"||e==="1")return!0;if(e==="false"||e==="0")return!1;r.push({type:"invalid_type",name:n,expected:"boolean",received:e});return}default:return e}}function Es(e){return e.replace(/[A-Z]/g,t=>`-${t.toLowerCase()}`)}var Ji=pe(()=>{"use strict";Qi()});function qr(e){let t=[],n=e.children.size>0;e.description?t.push(`${e.fullPath} - ${e.description}`):t.push(e.fullPath),t.push("");let r=[e.fullPath];n&&r.push(""),Object.keys(e.options).length>0&&r.push("[options]");let o=e.args;for(let i of o){let a=i.name??"arg",c=i.variadic?`${a}...`:a;r.push(i.required?`<${c}>`:`[${c}]`)}if(t.push("Usage:"),t.push(` ${r.join(" ")}`),t.push(""),n){t.push("Commands:");let i=[];for(let[c,f]of e.children)i.push([c,f.description||""]);let a=Math.max(...i.map(([c])=>c.length));for(let[c,f]of i)if(f){let l=" ".repeat(a-c.length+2);t.push(` ${c}${l}${f}`)}else t.push(` ${c}`);t.push("")}if(o.length>0){t.push("Arguments:");let i=[];for(let c of o){let f=c.name??"arg",l=c.variadic?`${f}...`:f,d=[];c.description&&d.push(c.description),c.required&&d.push("(required)"),c.default!==void 0&&d.push(`(default: ${JSON.stringify(c.default)})`),i.push([l,d.join(" ")])}let a=Math.max(...i.map(([c])=>c.length));for(let[c,f]of i)if(f){let l=" ".repeat(a-c.length+2);t.push(` ${c}${l}${f}`)}else t.push(` ${c}`);t.push("")}let s=sh(e.options);if(s.length>0&&(t.push("Options:"),t.push(...s),t.push("")),e.examples.length>0){t.push("Examples:");for(let i of e.examples)t.push(` ${i}`);t.push("")}return t.join(` +-`)}function sh(e,t){let n=Object.entries(e);if(n.length===0)return[];let r=[];for(let[i,a]of n){let c=Es(i);if(a._kind==="flag"){let f=a,l=[];f.short&&l.push(`-${f.short},`),l.push(`--${c}`);let d=[];f.description&&d.push(f.description),f.counted&&d.push("(counted)"),f.default!==void 0&&d.push(`(default: ${f.default})`),r.push([l.join(" "),d.join(" ")])}else{let f=a,l=[];f.short&&l.push(`-${f.short},`),l.push(`--${c} <${f.type}>`);let d=[];f.description&&d.push(f.description),f.repeatable&&d.push("(repeatable)"),f.required&&d.push("(required)"),f.default!==void 0&&!f.repeatable&&d.push(`(default: ${JSON.stringify(f.default)})`),f.env&&d.push(`[env: ${f.env}]`),r.push([l.join(" "),d.join(" ")])}}let o=Math.max(...r.map(([i])=>i.length)),s=[];t&&s.push(t);for(let[i,a]of r)if(a){let c=" ".repeat(o-i.length+2);s.push(` ${i}${c}${a}`)}else s.push(` ${i}`);return s}var ea=pe(()=>{"use strict";Ji()});function uf(e){if(!e)return{};let t={};for(let[n,r]of Object.entries(e))t[n]=r._def;return t}function mf(e){return e?e.map(t=>t._def):[]}function ta(e,t){return new yo(e,t.description,uf(t.options),mf(t.args),t.examples??[],t.handler,t.transformArgs)}function oh(e){return e.some(t=>t==="--help")}var yo,hf=pe(()=>{"use strict";Qi();ea();Ji();yo=class e{name;description;options;args;examples;handler;transformArgs;children=new Map;parent;constructor(t,n,r,o,s,i,a){this.name=t,this.description=n,this.options=r,this.args=o,this.examples=s,this.handler=i,this.transformArgs=a}command(t,n){let r=new e(t,n.description,uf(n.options),mf(n.args),n.examples??[],n.handler,n.transformArgs);return r.parent=this,this.children.set(t,r),r}get fullPath(){let t=[],n=this;for(;n;)t.unshift(n.name),n=n.parent;return t.join(" ")}toCommand(){return{name:this.name,execute:this.execute.bind(this)}}get allOptions(){return this.options}toTokens(t){let n=[],r=this.allOptions,o=t;for(let[s,i]of Object.entries(r)){let a=o[s],c=Es(s);if(i._kind==="flag")if(i.counted&&typeof a=="number"&&a>0)for(let f=0;f{"use strict";lf();hf()});function ko(e){if(e==="")return".";if(e==="/")return"/";let t=e.charCodeAt(0)===47,n=e.charCodeAt(e.length-1)===47,r=e.split("/"),o=[];for(let i of r)i===""||i==="."||(i===".."?t||o.length>0&&o[o.length-1]!==".."?o.pop():o.push(".."):o.push(i));let s=o.join("/");return t&&(s=`/${s}`),n&&s.length>1&&!s.endsWith("/")&&(s+="/"),s||(t?"/":n?"./":".")}function I(...e){if(e.length===0)return".";let t=e.filter(n=>n!=="").join("/");return t===""?".":ko(t)}function Qe(...e){let t="";for(let n=e.length-1;n>=0;n--){let r=e[n];if(r&&(t=t?`${r}/${t}`:r,r.charCodeAt(0)===47))break}return ko(t||".")}function bt(e){if(e==="")return".";if(e==="/")return"/";let t=e.length;for(;t>1&&e.charCodeAt(t-1)===47;)t--;let n=e.slice(0,t),r=n.lastIndexOf("/");return r===-1?".":r===0?"/":n.slice(0,r)}function xt(e,t){if(e==="")return"";let n=e.length;for(;n>1&&e.charCodeAt(n-1)===47;)n--;let r=e.slice(0,n);if(r==="/")return"";let o=r.lastIndexOf("/"),s=o===-1?r:r.slice(o+1);return t&&s.endsWith(t)&&s.length>t.length?s.slice(0,s.length-t.length):s}function lt(e,t){let n=ko(e),r=ko(t);if(n.length>1&&n.endsWith("/")&&(n=n.slice(0,-1)),r.length>1&&r.endsWith("/")&&(r=r.slice(0,-1)),n===r)return"";let o=n==="/"?[""]:n.split("/"),s=r==="/"?[""]:r.split("/"),i=n.charCodeAt(0)===47,a=r.charCodeAt(0)===47,f=i&&a?1:0,l=Math.min(o.length,s.length);for(;f{"use strict"});function na(e){let t=1,n="";for(;t=c.length||c[f+1]==="\r"&&f+2>=c.length){if(a++,a0;)r+=" ",s--}}function ih(e){let t={},n=null,r=e.split(` +-`),o=0;for(;oc.trim().length>0)&&o.length>0&&o[o.length-1].trim()!==""&&o.push(""),o.push(`[${t}]`,i)),o.join(` +-`)}function ch(e,t,n){let r=e.split(` +-`),o=ia(r,t,n);return o.keyStart===-1?{text:e,found:!1}:(r.splice(o.keyStart,o.keyEnd-o.keyStart+1),!o.sectionHasOtherKeys&&o.sectionHeaderLine!==-1&&r.splice(o.sectionHeaderLine,1),{text:r.join(` +-`),found:!0})}async function we(e){let t=I(e.commonDir,"config");if(!await e.fs.exists(t))return{};let n=await e.fs.readFile(t);return ih(n)}async function Eo(e){let t=I(e.commonDir,"config");return await e.fs.exists(t)?e.fs.readFile(t):""}async function et(e,t){let n=I(e.commonDir,"config");await e.fs.writeFile(n,oa(t))}async function Re(e,t){let n=e.configOverrides,r=Rs(t),o=n?.locked?.[r];if(o!==void 0)return o;let s=await we(e),{section:i,key:a}=Cs(t),c=s[i]?.[a];return c!==void 0?c:n?.defaults?.[r]}function Rs(e){let t=e.indexOf(".");if(t===-1)return e.toLowerCase();let n=e.lastIndexOf(".");return e.slice(0,t).toLowerCase()+e.slice(t,n)+e.slice(n).toLowerCase()}async function aa(e,t,n){let r=await Eo(e),{section:o,key:s}=Cs(t),i=ah(r,o,s,n),a=I(e.commonDir,"config");await e.fs.writeFile(a,i)}async function gf(e,t){let n=e.configOverrides,r=Rs(t),o=n?.locked?.[r];if(o!==void 0)return[o];let s=await Eo(e);if(s){let a=ra(s),{section:c,key:f}=Cs(t),l=a[c]?.[f];if(l&&l.length>0)return l}let i=n?.defaults?.[r];return i!==void 0?[i]:[]}function fh(e,t,n,r){let o=e.split(` +-`),s=ia(o,t,n),i=` ${n} = ${sa(r)}`;return s.insertAfter!==-1?o.splice(s.insertAfter+1,0,i):(o.some(c=>c.trim().length>0)&&o.length>0&&o[o.length-1].trim()!==""&&o.push(""),o.push(`[${t}]`,i)),o.join(` +-`)}async function wf(e,t,n){let r=await Eo(e),{section:o,key:s}=Cs(t),i=fh(r,o,s,n),a=I(e.commonDir,"config");await e.fs.writeFile(a,i)}async function bf(e,t){let n=await Eo(e),{section:r,key:o}=Cs(t),s=ch(n,r,o);if(!s.found)return!1;let i=I(e.commonDir,"config");return await e.fs.writeFile(i,s.text),!0}function Cs(e){let t=e.split(".");if(t.length===2){let[n="",r=""]=t;return{section:n,key:r.toLowerCase()}}if(t.length===3){let[n="",r="",o=""]=t;return{section:`${n} "${r}"`,key:o.toLowerCase()}}throw new Error(`Invalid config key: "${e}"`)}var Be=pe(()=>{"use strict";ge()});function Ro(e,t){return yf(e,t,"author")}function xs(e,t){return yf(e,t,"committer")}async function yf(e,t,n){let r=lh[n],o=e.identityOverride,{timestamp:s,timezone:i}=dh(t.get(r.date));if(o?.locked)return{name:o.name,email:o.email,timestamp:s,timezone:i};let a=t.get(r.name)??await Re(e,"user.name")??o?.name,c=t.get(r.email)??await Re(e,"user.email")??o?.email;if(!a||!c)throw new Error(`${n.charAt(0).toUpperCase()}${n.slice(1)} identity unknown ++`}function yh(e,t){let n=e.length,r=t.length,s=new Array((n+1)*(r+1));for(let o=0;o<=n;o++)s[o*(r+1)]=o;for(let o=0;o<=r;o++)s[o]=o;for(let o=1;o<=n;o++)for(let i=1;i<=r;i++){let a=e[o-1]===t[i-1]?0:1;s[o*(r+1)+i]=Math.min(s[(o-1)*(r+1)+i]+1,s[o*(r+1)+(i-1)]+1,s[(o-1)*(r+1)+(i-1)]+a)}return s[n*(r+1)+r]}function $o(e,t,n){let r=n??Math.min(Math.max(1,Math.floor(e.length/2)),3);return t.map(o=>({candidate:o,distance:yh(e,o)})).filter(o=>o.distance<=r&&o.distance>0).sort((o,i)=>o.distance-i.distance).slice(0,2).map(o=>o.candidate)}var ca=we(()=>{"use strict"});function kf(e,t,n,r){let s=[],o=new Map,i=new Map;for(let[u,m]of Object.entries(e)){let h=$s(u);o.set(h,{key:u,def:m}),m.short&&i.set(m.short,{key:u,def:m})}let a={},c=[],f=[],l=0;for(;l`--${C}`)}),l++;continue}if(g.def._kind==="flag"){g.def.counted?a[g.key]=(a[g.key]||0)+1:a[g.key]=!0,l++;continue}let w=p??g.def.impliedValue??n[++l];if(w===void 0){s.push({type:"missing_value",name:g.key}),l++;continue}let b=Ps(w,g.def.type,g.key,s);b!==void 0&&(g.def.repeatable?(Array.isArray(a[g.key])||(a[g.key]=[]),a[g.key].push(b)):a[g.key]=b),l++;continue}if(u.startsWith("-")&&u.length>1){let m=u.slice(1);for(let h=0;h0?w:g.def.impliedValue??n[++l];if(b===void 0){s.push({type:"missing_value",name:g.key});break}let y=Ps(b,g.def.type,g.key,s);y!==void 0&&(g.def.repeatable?(Array.isArray(a[g.key])||(a[g.key]=[]),a[g.key].push(y)):a[g.key]=y);break}l++;continue}c.push(u),l++}let d=0;for(let u=0;u0?a[h]=p.map(g=>Ps(g,m.type,h,s)):m.required?s.push({type:"missing_required",name:h,kind:"arg"}):m.default!==void 0?a[h]=m.default:a[h]=[],d=c.length}else{let p=c[d];p!==void 0?(a[h]=Ps(p,m.type,h,s),d++):m.required?s.push({type:"missing_required",name:h,kind:"arg"}):m.default!==void 0&&(a[h]=m.default)}}if(d0?{ok:!1,errors:s}:{ok:!0,args:a,passthrough:f}}function Ps(e,t,n,r){switch(t){case"string":return e;case"number":{let s=Number(e);if(Number.isNaN(s)){r.push({type:"invalid_type",name:n,expected:"number",received:e});return}return s}case"boolean":{if(e==="true"||e==="1")return!0;if(e==="false"||e==="0")return!1;r.push({type:"invalid_type",name:n,expected:"boolean",received:e});return}default:return e}}function $s(e){return e.replace(/[A-Z]/g,t=>`-${t.toLowerCase()}`)}var fa=we(()=>{"use strict";ca()});function Yr(e){let t=[],n=e.children.size>0;e.description?t.push(`${e.fullPath} - ${e.description}`):t.push(e.fullPath),t.push("");let r=[e.fullPath];n&&r.push(""),Object.keys(e.options).length>0&&r.push("[options]");let s=e.args;for(let i of s){let a=i.name??"arg",c=i.variadic?`${a}...`:a;r.push(i.required?`<${c}>`:`[${c}]`)}if(t.push("Usage:"),t.push(` ${r.join(" ")}`),t.push(""),n){t.push("Commands:");let i=[];for(let[c,f]of e.children)i.push([c,f.description||""]);let a=Math.max(...i.map(([c])=>c.length));for(let[c,f]of i)if(f){let l=" ".repeat(a-c.length+2);t.push(` ${c}${l}${f}`)}else t.push(` ${c}`);t.push("")}if(s.length>0){t.push("Arguments:");let i=[];for(let c of s){let f=c.name??"arg",l=c.variadic?`${f}...`:f,d=[];c.description&&d.push(c.description),c.required&&d.push("(required)"),c.default!==void 0&&d.push(`(default: ${JSON.stringify(c.default)})`),i.push([l,d.join(" ")])}let a=Math.max(...i.map(([c])=>c.length));for(let[c,f]of i)if(f){let l=" ".repeat(a-c.length+2);t.push(` ${c}${l}${f}`)}else t.push(` ${c}`);t.push("")}let o=kh(e.options);if(o.length>0&&(t.push("Options:"),t.push(...o),t.push("")),e.examples.length>0){t.push("Examples:");for(let i of e.examples)t.push(` ${i}`);t.push("")}return t.join(` ++`)}function kh(e,t){let n=Object.entries(e);if(n.length===0)return[];let r=[];for(let[i,a]of n){let c=$s(i);if(a._kind==="flag"){let f=a,l=[];f.short&&l.push(`-${f.short},`),l.push(`--${c}`);let d=[];f.description&&d.push(f.description),f.counted&&d.push("(counted)"),f.default!==void 0&&d.push(`(default: ${f.default})`),r.push([l.join(" "),d.join(" ")])}else{let f=a,l=[];f.short&&l.push(`-${f.short},`),l.push(`--${c} <${f.type}>`);let d=[];f.description&&d.push(f.description),f.repeatable&&d.push("(repeatable)"),f.required&&d.push("(required)"),f.default!==void 0&&!f.repeatable&&d.push(`(default: ${JSON.stringify(f.default)})`),f.env&&d.push(`[env: ${f.env}]`),r.push([l.join(" "),d.join(" ")])}}let s=Math.max(...r.map(([i])=>i.length)),o=[];t&&o.push(t);for(let[i,a]of r)if(a){let c=" ".repeat(s-i.length+2);o.push(` ${i}${c}${a}`)}else o.push(` ${i}`);return o}var la=we(()=>{"use strict";fa()});function Ef(e){if(!e)return{};let t={};for(let[n,r]of Object.entries(e))t[n]=r._def;return t}function Rf(e){return e?e.map(t=>t._def):[]}function da(e,t){return new Oo(e,t.description,Ef(t.options),Rf(t.args),t.examples??[],t.handler,t.transformArgs)}function Eh(e){return e.some(t=>t==="--help")}var Oo,Cf=we(()=>{"use strict";ca();la();fa();Oo=class e{name;description;options;args;examples;handler;transformArgs;children=new Map;parent;constructor(t,n,r,s,o,i,a){this.name=t,this.description=n,this.options=r,this.args=s,this.examples=o,this.handler=i,this.transformArgs=a}command(t,n){let r=new e(t,n.description,Ef(n.options),Rf(n.args),n.examples??[],n.handler,n.transformArgs);return r.parent=this,this.children.set(t,r),r}get fullPath(){let t=[],n=this;for(;n;)t.unshift(n.name),n=n.parent;return t.join(" ")}toCommand(){return{name:this.name,execute:this.execute.bind(this)}}get allOptions(){return this.options}toTokens(t){let n=[],r=this.allOptions,s=t;for(let[o,i]of Object.entries(r)){let a=s[o],c=$s(o);if(i._kind==="flag")if(i.counted&&typeof a=="number"&&a>0)for(let f=0;f{"use strict";yf();Cf()});function So(e){if(e==="")return".";if(e==="/")return"/";let t=e.charCodeAt(0)===47,n=e.charCodeAt(e.length-1)===47,r=e.split("/"),s=[];for(let i of r)i===""||i==="."||(i===".."?t||s.length>0&&s[s.length-1]!==".."?s.pop():s.push(".."):s.push(i));let o=s.join("/");return t&&(o=`/${o}`),n&&o.length>1&&!o.endsWith("/")&&(o+="/"),o||(t?"/":n?"./":".")}function I(...e){if(e.length===0)return".";let t=e.filter(n=>n!=="").join("/");return t===""?".":So(t)}function Je(...e){let t="";for(let n=e.length-1;n>=0;n--){let r=e[n];if(r&&(t=t?`${r}/${t}`:r,r.charCodeAt(0)===47))break}return So(t||".")}function Et(e){if(e==="")return".";if(e==="/")return"/";let t=e.length;for(;t>1&&e.charCodeAt(t-1)===47;)t--;let n=e.slice(0,t),r=n.lastIndexOf("/");return r===-1?".":r===0?"/":n.slice(0,r)}function Pt(e,t){if(e==="")return"";let n=e.length;for(;n>1&&e.charCodeAt(n-1)===47;)n--;let r=e.slice(0,n);if(r==="/")return"";let s=r.lastIndexOf("/"),o=s===-1?r:r.slice(s+1);return t&&o.endsWith(t)&&o.length>t.length?o.slice(0,o.length-t.length):o}function rt(e,t){let n=So(e),r=So(t);if(n.length>1&&n.endsWith("/")&&(n=n.slice(0,-1)),r.length>1&&r.endsWith("/")&&(r=r.slice(0,-1)),n===r)return"";let s=n==="/"?[""]:n.split("/"),o=r==="/"?[""]:r.split("/"),i=n.charCodeAt(0)===47,a=r.charCodeAt(0)===47,f=i&&a?1:0,l=Math.min(s.length,o.length);for(;f{"use strict"});function ua(e){let t=1,n="";for(;t=c.length||c[f+1]==="\r"&&f+2>=c.length){if(a++,a0;)r+=" ",o--}}function Rh(e){let t={},n=null,r=e.split(` ++`),s=0;for(;sc.trim().length>0)&&s.length>0&&s[s.length-1].trim()!==""&&s.push(""),s.push(`[${t}]`,i)),s.join(` ++`)}function xh(e,t,n){let r=e.split(` ++`),s=ga(r,t,n);return s.keyStart===-1?{text:e,found:!1}:(r.splice(s.keyStart,s.keyEnd-s.keyStart+1),!s.sectionHasOtherKeys&&s.sectionHeaderLine!==-1&&r.splice(s.sectionHeaderLine,1),{text:r.join(` ++`),found:!0})}async function be(e){let t=I(e.commonDir,"config");if(!await e.fs.exists(t))return{};let n=await e.fs.readFile(t);return Rh(n)}async function vo(e){let t=I(e.commonDir,"config");return await e.fs.exists(t)?e.fs.readFile(t):""}async function et(e,t){let n=I(e.commonDir,"config");await e.fs.writeFile(n,pa(t))}async function Re(e,t){let n=e.configOverrides,r=Os(t),s=n?.locked?.[r];if(s!==void 0)return s;let o=await be(e),{section:i,key:a}=Ss(t),c=o[i]?.[a];return c!==void 0?c:n?.defaults?.[r]}function Os(e){let t=e.indexOf(".");if(t===-1)return e.toLowerCase();let n=e.lastIndexOf(".");return e.slice(0,t).toLowerCase()+e.slice(t,n)+e.slice(n).toLowerCase()}async function wa(e,t,n){let r=await vo(e),{section:s,key:o}=Ss(t),i=Ch(r,s,o,n),a=I(e.commonDir,"config");await e.fs.writeFile(a,i)}async function Pf(e,t){let n=e.configOverrides,r=Os(t),s=n?.locked?.[r];if(s!==void 0)return[s];let o=await vo(e);if(o){let a=ma(o),{section:c,key:f}=Ss(t),l=a[c]?.[f];if(l&&l.length>0)return l}let i=n?.defaults?.[r];return i!==void 0?[i]:[]}function Ph(e,t,n,r){let s=e.split(` ++`),o=ga(s,t,n),i=` ${n} = ${ha(r)}`;return o.insertAfter!==-1?s.splice(o.insertAfter+1,0,i):(s.some(c=>c.trim().length>0)&&s.length>0&&s[s.length-1].trim()!==""&&s.push(""),s.push(`[${t}]`,i)),s.join(` ++`)}async function $f(e,t,n){let r=await vo(e),{section:s,key:o}=Ss(t),i=Ph(r,s,o,n),a=I(e.commonDir,"config");await e.fs.writeFile(a,i)}async function Of(e,t){let n=await vo(e),{section:r,key:s}=Ss(t),o=xh(n,r,s);if(!o.found)return!1;let i=I(e.commonDir,"config");return await e.fs.writeFile(i,o.text),!0}function Ss(e){let t=e.split(".");if(t.length===2){let[n="",r=""]=t;return{section:n,key:r.toLowerCase()}}if(t.length===3){let[n="",r="",s=""]=t;return{section:`${n} "${r}"`,key:s.toLowerCase()}}throw new Error(`Invalid config key: "${e}"`)}var We=we(()=>{"use strict";ge()});function Io(e,t){return Sf(e,t,"author")}function vs(e,t){return Sf(e,t,"committer")}async function Sf(e,t,n){let r=$h[n],s=e.identityOverride,{timestamp:o,timezone:i}=Oh(t.get(r.date));if(s?.locked)return{name:s.name,email:s.email,timestamp:o,timezone:i};let a=t.get(r.name)??await Re(e,"user.name")??s?.name,c=t.get(r.email)??await Re(e,"user.email")??s?.email;if(!a||!c)throw new Error(`${n.charAt(0).toUpperCase()}${n.slice(1)} identity unknown + + *** Please tell me who you are. + +@@ -23,100 +23,100 @@ Run + + git config user.email "you@example.com" + git config user.name "Your Name" +-`);return{name:a,email:c,timestamp:s,timezone:i}}async function Jn(e,t){try{let n=await xs(e,t);return{name:n.name,email:n.email,timestamp:n.timestamp,tz:n.timezone}}catch{return{name:t.get("GIT_COMMITTER_NAME")??"",email:t.get("GIT_COMMITTER_EMAIL")??"",timestamp:Math.floor(Date.now()/1e3),tz:"+0000"}}}function dh(e){let t={timestamp:Math.floor(Date.now()/1e3),timezone:"+0000"};if(!e)return t;let n=e.trim();if(!n)return t;if(n.startsWith("@")){let s=n.slice(1).trim(),i=parseInt(s,10);if(!Number.isNaN(i))return{timestamp:i,timezone:"+0000"}}if(/^\d+$/.test(n))return{timestamp:parseInt(n,10),timezone:"+0000"};let r=n.match(/^(\d+)\s+([+-]\d{4})$/);if(r)return{timestamp:parseInt(r[1],10),timezone:r[2]};let o=Date.parse(n);return Number.isNaN(o)?t:{timestamp:Math.floor(o/1e3),timezone:uh(n)}}function uh(e){if(/Z$/i.test(e))return"+0000";let t=e.match(/([+-])(\d{2}):(\d{2})$/);if(t)return`${t[1]}${t[2]}${t[3]}`;let n=e.match(/([+-]\d{4})$/);return n?n[1]:"+0000"}var lh,xr=pe(()=>{"use strict";Be();lh={author:{name:"GIT_AUTHOR_NAME",email:"GIT_AUTHOR_EMAIL",date:"GIT_AUTHOR_DATE"},committer:{name:"GIT_COMMITTER_NAME",email:"GIT_COMMITTER_EMAIL",date:"GIT_COMMITTER_DATE"}}});function er(e){let t="";for(let n=0;n<20;n++)t+=kf[e[n]];return t}function Ps(e,t){let n="";for(let r=0;r<20;r++)n+=kf[e[t+r]];return n}function Vt(e){let t=new Uint8Array(20);for(let n=0;n<20;n++)t[n]=parseInt(e.slice(n*2,n*2+2),16);return t}var oe,kf,St=pe(()=>{"use strict";oe="0000000000000000000000000000000000000000",kf=(()=>{let e=new Array(256);for(let t=0;t<256;t++)e[t]=(t>>4).toString(16)+(t&15).toString(16);return e})()});function Ef(e){return e.length===4&&e.toLowerCase()===".git"}function Pr(e){if(e.length===0||e.includes("\0")||e.charCodeAt(0)===47||e.charCodeAt(e.length-1)===47)return!1;let t=e.split("/");for(let n of t)if(n.length===0||n==="."||n===".."||Ef(n))return!1;return!0}function Co(e,t){return t===e?!1:e==="/"?t.startsWith("/")&&t.length>1:t.startsWith(e+"/")}function Rf(e){if(e.length===0||e.charCodeAt(0)===47)return!1;let t=e.split("/");for(let n of t)if(n===".."||Ef(n))return!1;return!0}var xo=pe(()=>{"use strict"});function ca(e){return typeof e=="string"?mh.encode(e):e}function hh(){if(typeof globalThis.Bun<"u")return()=>{let e=new Bun.CryptoHasher("sha1"),t={update(n){return e.update(ca(n)),t},hex:()=>Promise.resolve(e.digest("hex"))};return t};try{let e=go(["node","crypto"].join(":"));if(typeof e.createHash=="function")return()=>{let t=e.createHash("sha1"),n={update(r){return t.update(ca(r)),n},hex:()=>Promise.resolve(t.digest("hex"))};return n}}catch{}if(typeof globalThis.crypto?.subtle?.digest=="function")return()=>{let e=[],t={update(n){return e.push(ca(n)),t},async hex(){let n=0;for(let i of e)n+=i.byteLength;let r=new Uint8Array(n),o=0;for(let i of e)r.set(i,o),o+=i.byteLength;let s=await crypto.subtle.digest("SHA-1",r);return er(new Uint8Array(s))}};return t};throw new Error("No SHA-1 implementation available. Requires Bun, Node.js, Deno, or a browser with Web Crypto.")}async function nr(e){return Cf().update(e).hex()}var mh,Cf,tr,$r=pe(()=>{"use strict";St();mh=new TextEncoder;Cf=hh(),tr=Cf});function Je(e,t){return e.lstat?e.lstat(t):e.stat(t)}function Dn(e){return typeof e=="string"?e==="120000":e===40960}function Yt(e){return typeof e=="string"?e==="160000":e===57344}async function xf(e,t){if((await Je(e,t)).isSymbolicLink&&e.readlink){let r=await e.readlink(t);return ph.encode(r)}return e.readFileBuffer(t)}var ph,cn=pe(()=>{"use strict";ph=new TextEncoder});function vf(e){return Sr.get(e)}async function X(e){let t=I(e.gitDir,"index");if(!await e.fs.exists(t))return{version:fa,entries:[]};let n=await e.fs.stat(t),r=await e.fs.readFileBuffer(t),o=await e.fs.stat(t),s=gh(r),i=zr(n.mtime),a=zr(o.mtime);return n.size===r.byteLength&&o.size===r.byteLength&&i!==null&&i===a&&Sr.set(s,o.mtime),s}async function ie(e,t){let n=I(e.gitDir,"index");await e.fs.writeFile(n,await Pf(t));let r=await Of(e,n);if(r===null){Sr.delete(t);return}if(wh(t,r)&&(await e.fs.writeFile(n,await Pf(t)),r=await Of(e,n),r===null)){Sr.delete(t);return}Sr.set(t,r)}function Mt(e,t){if(!Pr(t.path))throw new Error(`refusing to add unsafe path to index: '${t.path}'`);let n;return t.stage===0?n=e.entries.filter(r=>r.path!==t.path):n=e.entries.filter(r=>!(r.path===t.path&&r.stage===t.stage)),n.push(t),n.sort(la),da(e,n)}function yt(e,t){return da(e,e.entries.filter(n=>n.path!==t))}function Kr(e,t,n=0){return e.entries.find(r=>r.path===t&&r.stage===n)}function kn(e){return e.entries.some(t=>t.stage>0)}function fn(e){return[...new Set(e.entries.filter(t=>t.stage>0).map(t=>t.path))]}function qe(e){return e.entries.filter(t=>t.stage===0)}function If(){return{version:fa,entries:[]}}function Vr(e){let t=[...e].sort(la);return{version:fa,entries:t}}function Fe(){return{ctimeSeconds:0,ctimeNanoseconds:0,mtimeSeconds:0,mtimeNanoseconds:0,dev:0,ino:0,uid:0,gid:0,size:0}}function $o(e,t=e.size){let n=$f(e.mtime),r=e.ctime?$f(e.ctime):{seconds:0,nanoseconds:0};return{ctimeSeconds:r.seconds,ctimeNanoseconds:r.nanoseconds,mtimeSeconds:n.seconds,mtimeNanoseconds:n.nanoseconds,dev:Or(e.dev),ino:Or(e.ino),uid:Or(e.uid),gid:Or(e.gid),size:Or(t)}}function Tf(e,t,n){if(!n||!t.isFile||t.isSymbolicLink||e.stat.mtimeSeconds===0||t.size<0||t.size>4294967295||Oo(t)!==e.mode||t.size!==e.stat.size)return!1;let r=zr(t.mtime),o=zr(n);if(r===null||o===null||r!==Af(e.stat))return!1;if(t.ctime){if(e.stat.ctimeSeconds===0)return!1;let s=e.stat.ctimeSeconds*1e3+Math.floor(e.stat.ctimeNanoseconds/1e6);if(Math.trunc(t.ctime.getTime())!==s)return!1}return!Po(t.dev,e.stat.dev)||!Po(t.ino,e.stat.ino)||!Po(t.uid,e.stat.uid)||!Po(t.gid,e.stat.gid)?!1:rnull);if(!i||Oo(i)!==s.mode){o.push(s);continue}o.push({...s,stat:$o(i)})}return da(t,o)}function gh(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=0,r=t.getUint32(n);if(n+=4,r!==Sf)throw new Error(`Invalid index signature: 0x${r.toString(16)}`);let o=t.getUint32(n);n+=4;let s=t.getUint32(n);n+=4;let i=[];for(let a=0;a>12&3,p=m&4095,g,w;if(p<4095)w=new TextDecoder().decode(e.subarray(n,n+p)),g=p;else{let C=n;for(;Ct.path?1:e.stage-t.stage}function $f(e){let t=zr(e);if(t===null)return{seconds:0,nanoseconds:0};let n=Math.floor(t/1e3);return{seconds:Or(n),nanoseconds:(t-n*1e3)*1e6}}function zr(e){if(!(e instanceof Date))return null;let t=Math.trunc(e.getTime());return Number.isFinite(t)?t:null}function Or(e){return e===void 0||!Number.isFinite(e)||e<0?0:Math.trunc(e)>>>0}function Po(e,t){return e===void 0?!0:t!==0&&Or(e)===t}function Af(e){return e.mtimeSeconds*1e3+Math.floor(e.mtimeNanoseconds/1e6)}function da(e,t){let n={...e,entries:t},r=Sr.get(e);return r&&Sr.set(n,r),n}async function Of(e,t){let{mtime:n}=await e.fs.stat(t);return zr(n)===null?null:n}function wh(e,t){let n=Math.trunc(t.getTime()),r=!1;for(let o=0;o{"use strict";St();xo();ge();$r();cn();Sf=1145655875,fa=2,Sr=new WeakMap});var bh,So,Hf=pe(()=>{"use strict";bh=new Set(["tree","commit","tag"]),So=class{map=new Map;currentBytes=0;maxBytes;constructor(t=16*1024*1024){this.maxBytes=t}get(t){return this.map.get(t)}set(t,n){if(!bh.has(n.type))return;let r=n.content.byteLength;if(!(r>this.maxBytes/2)&&!this.map.has(t)){for(;this.currentBytes+r>this.maxBytes&&this.map.size>0;){let o=this.map.keys().next().value;this.currentBytes-=this.map.get(o).content.byteLength,this.map.delete(o)}this.map.set(t,n),this.currentBytes+=r}}get size(){return this.map.size}get bytes(){return this.currentBytes}clear(){this.map.clear(),this.currentBytes=0}}});function ua(e){let t=4294967295;for(let n=0;n>>8;return(t^4294967295)>>>0}var Df,Mf=pe(()=>{"use strict";Df=new Uint32Array(256);for(let e=0;e<256;e++){let t=e;for(let n=0;n<8;n++)t=t&1?3988292384^t>>>1:t>>>1;Df[e]=t}});function Wf(e){let t=Bf(e);return _f(e.subarray(t,-4),{i:2})}function ga(e){let t=Bf(e),n={i:2},r=_f(e.subarray(t),n),o=Uf(n.p);return{result:r,bytesConsumed:t+o+4}}var dn,Yr,yh,jf,Lf,kh,Gf,Ff,Eh,pa,$s,Os,Nf,Rh,Ch,ma,ln,ha,Uf,xh,En,_f,Bf,qf=pe(()=>{"use strict";dn=Uint8Array,Yr=Uint16Array,yh=Int32Array,jf=new dn([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),Lf=new dn([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),kh=new dn([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Gf=(e,t)=>{let n=new Yr(31);for(let o=0;o<31;++o)n[o]=t+=1<>1|(e&21845)<<1;t=(t&52428)>>2|(t&13107)<<2,t=(t&61680)>>4|(t&3855)<<4,pa[e]=((t&65280)>>8|(t&255)<<8)>>1}$s=(e,t,n)=>{let r=e.length,o=0,s=new Yr(t);for(;o>c]=f}}else for(a=new Yr(r),o=0;o>15-e[o]);return a},Os=new dn(288);for(let e=0;e<144;++e)Os[e]=8;for(let e=144;e<256;++e)Os[e]=9;for(let e=256;e<280;++e)Os[e]=7;for(let e=280;e<288;++e)Os[e]=8;Nf=new dn(32);for(let e=0;e<32;++e)Nf[e]=5;Rh=$s(Os,9,1),Ch=$s(Nf,5,1),ma=e=>{let t=e[0];for(let n=1;nt&&(t=e[n]);return t},ln=(e,t,n)=>{let r=t/8|0;return(e[r]|e[r+1]<<8)>>(t&7)&n},ha=(e,t)=>{let n=t/8|0;return(e[n]|e[n+1]<<8|e[n+2]<<16)>>(t&7)},Uf=e=>(e+7)/8|0,xh=(e,t,n)=>((t==null||t<0)&&(t=0),(n==null||n>e.length)&&(n=e.length),new dn(e.subarray(t,n))),En=(e,t)=>{let n=["unexpected EOF","invalid block type","invalid length/literal","invalid distance"];throw new Error(t||n[e]||"unknown inflate error")},_f=(e,t,n,r)=>{let o=e.length,s=r?r.length:0;if(!o||t.f&&!t.l)return n||new dn(0);let i=!n,a=i||t.i!=2,c=t.i;i&&(n=new dn(o*3));let f=b=>{let R=n.length;if(b>R){let C=new dn(Math.max(R*2,b));C.set(n),n=C}},l=t.f||0,d=t.p||0,u=t.b||0,m=t.l,h=t.d,p=t.m,g=t.n,w=o*8;do{if(!m){l=ln(e,d,1);let x=ln(e,d+1,3);if(d+=3,x)if(x==1)m=Rh,h=Ch,p=9,g=5;else if(x==2){let y=ln(e,d,31)+257,P=ln(e,d+10,15)+4,k=y+ln(e,d+5,31)+1;d+=14;let E=new dn(k),O=new dn(19);for(let N=0;N>4;if(H<16)E[N++]=H;else{let B=0,L=0;for(H==16?(L=3+ln(e,d,3),d+=2,B=E[N-1]):H==17?(L=3+ln(e,d,7),d+=3):H==18&&(L=11+ln(e,d,127),d+=7);L--;)E[N++]=B}}let U=E.subarray(0,y),G=E.subarray(y);p=ma(U),g=ma(G),m=$s(U,p,1),h=$s(G,g,1)}else En(1);else{let y=Uf(d)+4,P=e[y-4]|e[y-3]<<8,k=y+P;if(k>o){c&&En(0);break}a&&f(u+P),n.set(e.subarray(y,k),u),t.b=u+=P,t.p=d=k*8,t.f=l;continue}if(d>w){c&&En(0);break}}a&&f(u+131072);let b=(1<>4;if(d+=x&15,d>w){c&&En(0);break}if(x||En(2),y<256)n[u++]=y;else if(y==256){C=d,m=null;break}else{let P=y-254;if(y>264){let T=y-257,j=jf[T];P=ln(e,d,(1<>4;k||En(3),d+=k&15;let O=Eh[E];if(E>3){let T=Lf[E];O+=ha(e,d)&(1<w){c&&En(0);break}a&&f(u+131072);let $=u+P;if(u(((e[0]&15)!=8||e[0]>>4>7||(e[0]<<8|e[1])%31)&&En(0,"invalid zlib data"),e[1]&32&&En(0,"zlib dictionaries are not supported"),2)});async function Ph(){let e;if(!(typeof document<"u"))try{e=go(["node","zlib"].join(":"))}catch{try{e=await import(["node","zlib"].join(":"))}catch{}}if(e&&typeof e.deflateSync=="function"&&typeof e.inflateSync=="function"){let r=null;try{let o=e.inflateSync(e.deflateSync(Buffer.from("x")),{info:!0});o?.engine&&typeof o.engine.bytesWritten=="number"&&(r=s=>{let i=e.inflateSync(s,{info:!0});return{result:new Uint8Array(i.buffer),bytesConsumed:i.engine.bytesWritten}})}catch{}return{deflateSync:o=>new Uint8Array(e.deflateSync(o)),inflateSync:o=>new Uint8Array(e.inflateSync(o)),inflateWithConsumed:r??ga}}let n;return typeof globalThis.CompressionStream=="function"?n=async r=>{let o=new CompressionStream("deflate"),s=o.writable.getWriter();return s.write(r),s.close(),new Uint8Array(await new Response(o.readable).arrayBuffer())}:n=()=>{throw new Error("No deflate implementation available. Requires node:zlib or CompressionStream.")},{deflateSync:n,inflateSync:Wf,inflateWithConsumed:ga}}function wa(){return $h??=Ph()}async function Xr(e){return await(await wa()).deflateSync(e)}async function Zr(e){return await(await wa()).inflateSync(e)}async function zf(e,t){let n=await wa(),{result:r,bytesConsumed:o}=n.inflateWithConsumed(e);if(r.byteLength!==t)throw new Error(`Inflate size mismatch: got ${r.byteLength}, expected ${t}`);return{result:r,bytesConsumed:o}}var $h,vo=pe(()=>{"use strict";qf();$h=null});async function el(e,t){let n=new DataView(e.buffer,e.byteOffset,e.byteLength),r=n.getUint32(0);if(r!==Io)throw new Error(`Invalid pack signature: 0x${r.toString(16)} (expected 0x${Io.toString(16)})`);let o=n.getUint32(4);if(o!==ka)throw new Error(`Unsupported pack version: ${o}`);if(e.byteLength>=32){let f=Ps(e,e.byteLength-20),l=tr();l.update(e.subarray(0,e.byteLength-20));let d=await l.hex();if(d!==f)throw new Error(`pack checksum mismatch: expected ${f}, computed ${d}`)}let s=n.getUint32(8),i=[],a=12;for(let f=0;f({...f,offset:i[l].headerOffset,nextOffset:i[l].nextOffset}))}async function Sh(e,t){let n=t,r=e[t++],o=r>>4&7,s=r&15,i=4;for(;r&128;)r=e[t++],s|=(r&127)<Kf)throw new Error(`delta chain depth ${i} exceeds limit of ${Kf}`);let a=r[s];if(a)return a;let c=e[s];if(c.typeNum!==Ss&&c.typeNum!==Ea){let m=Oh[c.typeNum];if(!m)throw new Error(`Unknown object type: ${c.typeNum}`);let h={type:m,content:c.inflated,hash:await ba(m,c.inflated)};return r[s]=h,h}if(c.typeNum===Ss){let m=n.get(c.baseOffset);if(m===void 0)throw new Error(`OFS_DELTA base not found at offset ${c.baseOffset}`);let h=await o(m,i+1),p=vs(h.content,c.inflated),g={type:h.type,content:p,hash:await ba(h.type,p)};return r[s]=g,g}let f=await Ih(e,r,c.baseHash,o),l;if(f!==void 0)l=await o(f,i+1);else if(t){let m=await t(c.baseHash);m&&(l=m)}if(!l)throw new Error(`REF_DELTA base not found for hash ${c.baseHash}`);let d=vs(l.content,c.inflated),u={type:l.type,content:d,hash:await ba(l.type,d)};return r[s]=u,u}for(let s=0;s0)a.set(t.subarray(n,n+f),c),c+=f,n+=f;else throw new Error("Unexpected delta opcode 0x00 (reserved)")}if(c!==s)throw new Error(`Delta produced ${c} bytes, expected ${s}`);return a}async function tl(e){let t=[],n=new Uint8Array(12),r=new DataView(n.buffer);r.setUint32(0,Io),r.setUint32(4,ka),r.setUint32(8,e.length),t.push(n);for(let o of e){let s=Jf[o.type],i=await Xr(o.content);t.push(ya(s,o.content.byteLength)),t.push(i)}return nl(t)}async function To(e){let t=[],n=new Map,r=new Uint8Array(12),o=new DataView(r.buffer);o.setUint32(0,Io),o.setUint32(4,ka),o.setUint32(8,e.length),t.push(r);let s=12,i=[];for(let a of e){let c=s;n.set(a.hash,s);let f=a.delta&&a.deltaBaseHash?n.get(a.deltaBaseHash):void 0;if(a.delta&&f!==void 0){let l=ya(Ss,a.delta.byteLength),d=Th(s-f),u=await Xr(a.delta);t.push(l,d,u),s+=l.byteLength+d.byteLength+u.byteLength}else{let l=Jf[a.type],d=ya(l,a.content.byteLength),u=await Xr(a.content);t.push(d,u),s+=d.byteLength+u.byteLength}i.push({hash:a.hash,offset:c,nextOffset:s})}return{data:await nl(t),entries:i}}async function nl(e){let t=0;for(let i of e)t+=i.byteLength;t+=20;let n=new Uint8Array(t),r=0;for(let i of e)n.set(i,r),r+=i.byteLength;let o=tr();o.update(n.subarray(0,r));let s=await o.hex();return n.set(Vt(s),r),n}function Th(e){let t=[];t.push(e&127);let n=e>>>7;for(;n>0;)t.unshift(128|--n&127),n>>>=7;return new Uint8Array(t)}function ya(e,t){let n=[],r=e<<4|t&15;for(t>>=4;t>0;)n.push(r|128),r=t&127,t>>=7;return n.push(r),new Uint8Array(n)}function Vf(e,t){let n=0,r=0,o;do o=e[t++],n|=(o&127)<{"use strict";St();$r();vo();Io=1346454347,ka=2,Yf=1,Xf=2,Zf=3,Qf=4,Ss=6,Ea=7,Oh={[Yf]:"commit",[Xf]:"tree",[Zf]:"blob",[Qf]:"tag"},Jf={commit:Yf,tree:Xf,blob:Zf,tag:Qf};Kf=50;Ah=new TextEncoder});async function ol(e,t){let n=[...e].sort((m,h)=>m.hashh.hash?1:0),r=n.length,o=[];for(let m of n)m.offset>=2147483648&&o.push(BigInt(m.offset));let s=8+256*4+r*20+r*4+r*4+o.length*8+20+20,i=new Uint8Array(s),a=new DataView(i.buffer),c=0;a.setUint32(c,rl),c+=4,a.setUint32(c,sl),c+=4;let f=new Uint32Array(256);for(let m of n){let h=parseInt(m.hash.slice(0,2),16);for(let p=h;p<256;p++)f[p]++}for(let m=0;m<256;m++)a.setUint32(c,f[m]),c+=4;for(let m of n)i.set(Vt(m.hash),c),c+=20;for(let m of n)a.setUint32(c,m.crc),c+=4;let l=0;for(let m of n)m.offset>=2147483648?a.setUint32(c,2147483648|l++):a.setUint32(c,m.offset),c+=4;for(let m of o)a.setBigUint64(c,m),c+=8;i.set(t,c),c+=20;let d=tr();d.update(i.subarray(0,c));let u=await d.hex();return i.set(Vt(u),c),i}async function il(e){let n=(await el(e)).map(o=>({hash:o.hash,offset:o.offset,crc:ua(e.subarray(o.offset,o.nextOffset))})),r=e.subarray(e.byteLength-20);return ol(n,r)}async function al(e,t){let n=t.map(o=>({hash:o.hash,offset:o.offset,crc:ua(e.subarray(o.offset,o.nextOffset))})),r=e.subarray(e.byteLength-20);return ol(n,r)}var rl,sl,un,Ao=pe(()=>{"use strict";St();$r();Mf();Qr();rl=4285812579,sl=2,un=class{fanout;hashes;offsets;largeOffsets;count;constructor(t){let n=new DataView(t.buffer,t.byteOffset,t.byteLength);if(n.getUint32(0)!==rl)throw new Error("Invalid pack index: bad magic");if(n.getUint32(4)!==sl)throw new Error(`Unsupported pack index version: ${n.getUint32(4)}`);this.fanout=new Uint32Array(256);let r=8;for(let s=0;s<256;s++)this.fanout[s]=n.getUint32(r),r+=4;this.count=this.fanout[255],this.hashes=new Uint8Array(t.buffer,t.byteOffset+r,this.count*20),r+=this.count*20,r+=this.count*4,this.offsets=new Uint32Array(this.count);for(let s=0;s>>1,f=this.compareAt(c,n);if(f<0)i=c+1;else if(f>0)a=c;else return this.getOffset(c)}return null}has(t){return this.lookup(t)!==null}get objectCount(){return this.count}allHashes(){let t=[];for(let n=0;n>1)]>>4&15:this.hashes[f+(d>>1)]&15,m=d%2===0?s[d>>1]>>4&15:s[d>>1]&15;if(u!==m){l=!1;break}}l&&a.push(this.hashAtSlot(c))}return a}hashAtSlot(t){let n="",r=t*20;for(let o=0;o<20;o++){let s=this.hashes[r+o];n+=(s>>4).toString(16)+(s&15).toString(16)}return n}compareAt(t,n){let r=t*20;for(let o=0;o<20;o++){let s=this.hashes[r+o],i=n[o];if(si)return 1}return 0}getOffset(t){let n=this.offsets[t];if(n&2147483648){let r=n&2147483647;return Number(this.largeOffsets.getBigUint64(r*8))}return n}}});var Hh,Dh,Mh,cl,Is,fl=pe(()=>{"use strict";St();Ao();Qr();vo();Hh=6,Dh=7,Mh={1:"commit",2:"tree",3:"blob",4:"tag"},cl=50,Is=class{constructor(t,n){this.data=t;this.index=n instanceof un?n:new un(n)}index;hasObject(t){return this.index.has(t)}findByPrefix(t){return this.index.findByPrefix(t)}async readObject(t){let n=this.index.lookup(t);return n===null?null:this.readAt(n,0)}get objectCount(){return this.index.objectCount}async readAt(t,n){if(n>cl)throw new Error(`delta chain depth ${n} exceeds limit of ${cl}`);let r=this.data,o=t,s=r[o++],i=s>>4&7,a=s&15,c=4;for(;s&128;)s=r[o++],a|=(s&127)<{"use strict";St();Hf();Ao();fl();Qr();vo();ge();$r();jh=new TextEncoder,Lh=new TextDecoder;Ts=class{constructor(t,n,r){this.fs=t;this.gitDir=n;this.cache=new So(r),this.packDir=I(n,"objects","pack")}packs=[];loadedPackNames=new Set;discoverPromise=null;cache;packDir;async write(t,n){let r=Ca(t,n),o=await nr(r),s=Ra(this.gitDir,o);if(await this.fs.exists(s))return o;let i=I(this.gitDir,"objects",o.slice(0,2));return await this.fs.mkdir(i,{recursive:!0}),await this.fs.writeFile(s,await Xr(r)),o}async read(t){let n=this.cache.get(t);if(n)return n;let r=Ra(this.gitDir,t);if(await this.fs.exists(r)){let o=await this.fs.readFileBuffer(r),s=await Zr(o),i=await nr(s);if(i!==t)throw new Error(`corrupt loose object ${t}: SHA-1 mismatch (computed ${i})`);let a=Gh(t,s);return this.cache.set(t,a),a}await this.discover();for(let o of this.packs){if(!o.index.has(t))continue;let i=await(await this.ensureReader(o)).readObject(t);if(i)return this.cache.set(t,i),i}throw new Error(`object ${t} not found`)}async exists(t){if(await this.fs.exists(Ra(this.gitDir,t)))return!0;await this.discover();for(let n of this.packs)if(n.index.has(t))return!0;return!1}async ingestPack(t){if(t.byteLength<32)return 0;let n=new DataView(t.buffer,t.byteOffset,t.byteLength),r=n.getUint32(0);if(r!==1346454347)throw new Error(`invalid pack signature: 0x${r.toString(16)} (expected 0x5041434b)`);let o=n.getUint32(4);if(o!==2)throw new Error(`unsupported pack version: ${o}`);let s=n.getUint32(8);if(s===0)return 0;let i=t.subarray(t.byteLength-20),a=er(i),c=await nr(t.subarray(0,t.byteLength-20));if(c!==a)throw new Error(`pack checksum mismatch: expected ${a}, computed ${c}`);await this.fs.mkdir(this.packDir,{recursive:!0});let f=`pack-${a}`,l=I(this.packDir,`${f}.pack`);await this.fs.writeFile(l,t);let d=await il(t),u=I(this.packDir,`${f}.idx`);await this.fs.writeFile(u,d),this.loadedPackNames.add(f);let m=new un(d);return this.packs.push({name:f,index:m,reader:new Is(t,m)}),s}async ingestPackStream(t){let n=[];for await(let o of t)n.push(o);if(n.length===0)return 0;let r=await tl(n);return this.ingestPack(r)}invalidatePacks(){this.packs=[],this.loadedPackNames.clear(),this.discoverPromise=null,this.cache.clear()}async findByPrefix(t){if(t.length<4)return[];let n=t.slice(0,2),r=t.slice(2),o=I(this.gitDir,"objects",n),s=[];if(await this.fs.exists(o)){let i=await this.fs.readdir(o);for(let a of i)a.startsWith(r)&&s.push(`${n}${a}`)}await this.discover();for(let i of this.packs)for(let a of i.index.findByPrefix(t))s.includes(a)||s.push(a);return s}async ensureReader(t){if(t.reader)return t.reader;let n=I(this.packDir,`${t.name}.pack`),r=await this.fs.readFileBuffer(n);return t.reader=new Is(r,t.index),t.reader}discover(){return this.discoverPromise||(this.discoverPromise=this.doDiscover()),this.discoverPromise}async doDiscover(){if(!await this.fs.exists(this.packDir))return;let t=await this.fs.readdir(this.packDir);for(let n of t){if(!n.endsWith(".idx"))continue;let r=n.slice(0,-4);if(this.loadedPackNames.has(r))continue;let o=I(this.packDir,`${r}.pack`);if(!await this.fs.exists(o))continue;let s=await this.fs.readFileBuffer(I(this.packDir,n));this.loadedPackNames.add(r),this.packs.push({name:r,index:new un(s),reader:null})}}}});function As(e){let t=e.indexOf("<"),n=e.indexOf(">");if(t===-1||n===-1)throw new Error(`Malformed identity line: "${e}"`);let r=e.slice(0,t).trimEnd(),o=e.slice(t+1,n),s=e.slice(n+2),[i="0",a="+0000"]=s.split(" "),c=parseInt(i,10);return{name:r,email:o,timestamp:c,timezone:a}}function Hs(e){return`${e.name} <${e.email}> ${e.timestamp} ${e.timezone}`}var Pa=pe(()=>{"use strict"});function Rn(e){let t=Nh.decode(e),n=t.indexOf(` +- +-`),r=n===-1?t:t.slice(0,n),o=n===-1?"":t.slice(n+2),s="",i=[],a,c;for(let f of r.split(` +-`)){let l=f.indexOf(" ");if(l===-1)continue;let d=f.slice(0,l),u=f.slice(l+1);switch(d){case"tree":s=u;break;case"parent":i.push(u);break;case"author":a=As(u);break;case"committer":c=As(u);break}}if(!s)throw new Error("Commit missing tree field");if(!a)throw new Error("Commit missing author field");if(!c)throw new Error("Commit missing committer field");return{type:"commit",tree:s,parents:i,author:a,committer:c,message:o}}function Cn(e){let t=[];t.push(`tree ${e.tree}`);for(let n of e.parents)t.push(`parent ${n}`);return t.push(`author ${Hs(e.author)}`),t.push(`committer ${Hs(e.committer)}`),t.push(""),t.push(e.message),Fh.encode(t.join(` +-`))}var Fh,Nh,Mn=pe(()=>{"use strict";Pa();Fh=new TextEncoder,Nh=new TextDecoder});function mn(e){let t=_h.decode(e),n=t.indexOf(` +- +-`),r=n===-1?t:t.slice(0,n),o=n===-1?"":t.slice(n+2),s="",i="commit",a="",c;for(let f of r.split(` +-`)){let l=f.indexOf(" ");if(l===-1)continue;let d=f.slice(0,l),u=f.slice(l+1);switch(d){case"object":s=u;break;case"type":i=u;break;case"tag":a=u;break;case"tagger":c=As(u);break}}if(!s)throw new Error("Tag missing object field");if(!a)throw new Error("Tag missing tag name field");if(!c)throw new Error("Tag missing tagger field");return{type:"tag",object:s,objectType:i,name:a,tagger:c,message:o}}function ll(e){let t=[];return t.push(`object ${e.object}`),t.push(`type ${e.objectType}`),t.push(`tag ${e.name}`),t.push(`tagger ${Hs(e.tagger)}`),t.push(""),t.push(e.message),Uh.encode(t.join(` +-`))}var Uh,_h,Jr=pe(()=>{"use strict";Pa();Uh=new TextEncoder,_h=new TextDecoder});async function sr(e,t){return nr(Ca(e,t))}async function Me(e,t,n){let r=await e.objectStore.write(t,n);return e.hooks?.onObjectWrite?.({repo:e,type:t,hash:r}),r}async function be(e,t){return e.objectStore.read(t)}async function Xt(e,t){return e.objectStore.exists(t)}async function Ho(e,t){return e.objectStore.ingestPack(t)}async function Do(e,t){return e.objectStore.findByPrefix(t)}function Ne(e){let t=Math.min(e.length,8e3);for(let n=0;n{"use strict";xa();Mn();Jr();$r();Bh=new TextDecoder});function vr(e){return e.includes("/")?e.startsWith("refs/bisect/")||e.startsWith("refs/worktree/")||e.startsWith("refs/rewritten/"):e===e.toUpperCase()}var $a=pe(()=>{"use strict"});function dl(e){return typeof e=="string"?{type:"direct",hash:e}:e}var jn,Oa=pe(()=>{"use strict";jn={REGULAR:"100644",EXECUTABLE:"100755",SYMLINK:"120000",DIRECTORY:"040000",SUBMODULE:"160000"}});function qh(e,t,n){let r=0,o=!1,s=t;for(;s=Sa.length&&e.slice(s-Sa.length,s)===Sa?{len:-1,starConsumed:o}:{len:i,starConsumed:o}}function Ds(e,t=0){if(e==="@"||e.length===0)return!1;let n=0,r=0,o=!!(t&2);for(;n<=e.length;){let{len:s,starConsumed:i}=qh(e,n,o);if(s<0||s===0)return!1;i&&(o=!1),r++,n+=s+1}return!(e.charCodeAt(e.length-1)===46||!(t&1)&&r<2)}function Ln(e){return!e||e.startsWith("-")?!1:Ds(`refs/heads/${e}`,0)}function ul(e){return e?Ds(`refs/tags/${e}`,0):!1}async function hl(e,t){return e.refStore.readRef(t)}async function z(e,t){let n=t;for(let r=0;rf.name==="HEAD");if(!o)return;let s;if(r?.startsWith("refs/heads/"))s=r.slice(11);else{let f=n.find(l=>l.name.startsWith("refs/heads/")&&l.hash===o.hash);if(!f)return;s=f.name.slice(11)}let i=`refs/remotes/${t}/HEAD`;if(await e.refStore.readRef(i))return;let c=`refs/remotes/${t}/${s}`;await e.refStore.writeRef(i,{type:"symbolic",target:c})}async function ke(e,t){let n=e.hooks?await z(e,t):null;await e.refStore.deleteRef(t),await js(e,t),e.hooks&&n&&e.hooks.onRefDelete?.({repo:e,ref:t,oldHash:n})}async function $e(e,t="refs"){return e.refStore.listRefs(t)}function Ie(e){return e.replace("refs/heads/","")}function Zt(e){return e.startsWith("refs/heads/")?e.slice(11):e.startsWith("refs/tags/")?e.slice(10):e.startsWith("refs/remotes/")?e.slice(13):e}async function or(e,t){let n=await te(e);n&&n.type==="symbolic"?await Q(e,n.target,t):await Q(e,"HEAD",t)}async function pl(e){if(e.refStore&&!(e.refStore instanceof Pt))return;let t=(await $e(e,"refs")).filter(s=>!vr(s.name));if(t.length===0)return;let n=["# pack-refs with: peeled fully-peeled sorted"],r=[];for(let s of t){let i=I(e.commonDir,s.name);if(!(await e.fs.exists(i)&&(await e.fs.readFile(i)).trim().startsWith("ref: "))&&(r.push(s.name),n.push(`${s.hash} ${s.name}`),s.name.startsWith("refs/tags/")))try{let a=await be(e,s.hash);if(a.type==="tag"){let c=mn(a.content).object;for(let f=0;f<100;f++){let l=await be(e,c);if(l.type!=="tag")break;c=mn(l.content).object}n.push(`^${c}`)}}catch{}}await e.fs.writeFile(I(e.commonDir,"packed-refs"),`${n.join(` +-`)} +-`);for(let s of r){let i=I(e.commonDir,s);await e.fs.exists(i)&&await e.fs.rm(i)}await gl(e,I(e.commonDir,"refs"));let o=I(e.commonDir,"refs");await e.fs.mkdir(o,{recursive:!0}),await e.fs.mkdir(I(o,"heads"),{recursive:!0}),await e.fs.mkdir(I(o,"tags"),{recursive:!0})}async function gl(e,t){if(e.refStore&&!(e.refStore instanceof Pt)||!await e.fs.exists(t)||!(await e.fs.stat(t)).isDirectory)return;let r=await e.fs.readdir(t);for(let s of r)await gl(e,I(t,s));(await e.fs.readdir(t)).length===0&&await e.fs.rm(t,{recursive:!0})}var Sa,Wh,va,ml,Pt,ye=pe(()=>{"use strict";ae();Jr();ge();$a();Ve();Gn();Oa();Sa=".lock",Wh=[1,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,0,0,0,0,0,0,0,0,0,5,0,0,0,2,1,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,4,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,4,4];va="ref: ",ml=10,Pt=class{constructor(t,n,r){this.fs=t;this.gitDir=n;this.commonDir=r??n}casLocks=new Map;commonDir;dirFor(t){return vr(t)?this.gitDir:this.commonDir}async readRef(t){let n=I(this.dirFor(t),t);if(await this.fs.exists(n)){let s=(await this.fs.readFile(n)).trim();return s.startsWith(va)?{type:"symbolic",target:s.slice(va.length)}:{type:"direct",hash:s}}if(vr(t))return null;let o=(await this.readPackedRefs()).get(t);return o?{type:"direct",hash:o}:null}async writeRef(t,n){let r=dl(n),o=I(this.dirFor(t),t);await Ms(this.fs,o),r.type==="symbolic"?await this.fs.writeFile(o,`${va}${r.target} +-`):await this.fs.writeFile(o,`${r.hash} +-`)}async deleteRef(t){let n=I(this.dirFor(t),t);await this.fs.exists(n)&&await this.fs.rm(n),await this.removePackedRef(t)}async listRefs(t="refs"){let n=[],r=new Set,o=async i=>{let a=I(i,t);if(!await this.fs.exists(a))return;let c=[];await this.walkRefs(a,t,c);for(let f of c)this.dirFor(f.name)===i&&(r.has(f.name)||(r.add(f.name),n.push(f)))};await o(this.commonDir),this.gitDir!==this.commonDir&&await o(this.gitDir);let s=await this.readPackedRefs();if(s.size>0){let i=`${t}/`;for(let[a,c]of s)vr(a)||a.startsWith(i)&&!r.has(a)&&(r.add(a),n.push({name:a,hash:c}))}return n.sort((i,a)=>i.namea.name?1:0)}async compareAndSwapRef(t,n,r){let s=(this.casLocks.get(t)??Promise.resolve(!1)).then(()=>this.compareAndSwapUnsafe(t,n,r),()=>this.compareAndSwapUnsafe(t,n,r));this.casLocks.set(t,s);try{return await s}finally{this.casLocks.get(t)===s&&this.casLocks.delete(t)}}async compareAndSwapUnsafe(t,n,r){let o=await this.resolveRefInternal(t);if(n===null){if(await this.readRef(t)!==null)return!1}else if(o!==n)return!1;return r===null?await this.deleteRef(t):await this.writeRef(t,r),!0}async resolveRefInternal(t){let n=t;for(let r=0;rc&&!c.startsWith("#")&&!c.startsWith("^"))?await this.fs.writeFile(n,s.join(` +-`)):await this.fs.rm(n)}async walkRefs(t,n,r){let o=await this.fs.readdir(t);for(let s of o){let i=I(t,s),a=`${n}/${s}`,c=await this.fs.stat(i);if(c.isDirectory)await this.walkRefs(i,a,r);else if(c.isFile){let f=await this.resolveRefInternal(a);f&&r.push({name:a,hash:f})}}}}});async function Fn(e,t){let n=t;for(;;){let r=I(n,".git");if(await e.exists(r)){let s=await e.stat(r);if(s.isDirectory)return Ia(e,r,r,n);if(s.isFile){let i=await zh(e,r,n);return i?Ia(e,i.gitDir,i.commonDir,n):null}}if(await Kh(e,n))return Ia(e,n,n,null);let o=Vh(n);if(o===n)return null;n=o}}function Ia(e,t,n,r){return{fs:e,gitDir:t,commonDir:n,workTree:r,objectStore:new Ts(e,n),refStore:new Pt(e,t,n)}}async function zh(e,t,n){let r=(await e.readFile(t)).trim(),o="gitdir:";if(!r.startsWith(o))return null;let s=r.slice(o.length).trim();if(!s)return null;let i=Qe(n,s);if(!await e.exists(i))return null;let a=I(i,"commondir");if(!await e.exists(a))return{gitDir:i,commonDir:i};let c=(await e.readFile(a)).trim();return{gitDir:i,commonDir:c?Qe(i,c):i}}async function Kh(e,t){let n=I(t,"HEAD");if(!await e.exists(n))return!1;try{if(!(await e.stat(n)).isFile)return!1}catch{return!1}for(let r of["objects","refs"]){let o=I(t,r);if(!await e.exists(o))return!1;try{if(!(await e.stat(o)).isDirectory)return!1}catch{return!1}}return!0}async function jo(e,t,n={}){let{bare:r=!1,initialBranch:o="main"}=n,s=r?t:I(t,".git"),i=r?null:t,a=I(s,"HEAD"),c=await e.exists(a);await e.mkdir(I(s,"objects"),{recursive:!0}),await e.mkdir(I(s,"refs","heads"),{recursive:!0}),await e.mkdir(I(s,"refs","tags"),{recursive:!0});let f={fs:e,gitDir:s,commonDir:s,workTree:i,objectStore:new Ts(e,s),refStore:new Pt(e,s)};if(!c){await ot(f,"HEAD",`refs/heads/${o}`);let l={core:{repositoryformatversion:"0",filemode:"true",bare:r?"true":"false",...r?{}:{logallrefupdates:"true"}}};await e.writeFile(I(s,"config"),oa(l))}return{ctx:f,reinit:c}}async function Ms(e,t){let n=t.lastIndexOf("/");if(n>0){let r=t.slice(0,n);await e.mkdir(r,{recursive:!0})}}function Vh(e){let t=e.lastIndexOf("/");return t<=0?"/":e.slice(0,t)}var Gn=pe(()=>{"use strict";Be();xa();ge();ye()});function ts(e,t){let n=vr(t)?e.gitDir:e.commonDir;return I(n,"logs",t)}function Yh(e){let t=e.indexOf(" ");if(t<0)return null;let n=e.slice(0,t),r=e.slice(t+1),o=n.split(" ");if(o.length<5)return null;let s=o[0],i=o[1];if(!s||!i)return null;let a=n.indexOf("<"),c=n.indexOf(">",a);if(a<0||c<0)return null;let f=n.slice(s.length+1+i.length+1,a).trim(),l=n.slice(a+1,c),d=n.slice(c+2),u=d.indexOf(" ");if(u<0)return null;let m=parseInt(d.slice(0,u),10),h=d.slice(u+1);return{oldHash:s,newHash:i,name:f,email:l,timestamp:m,tz:h,message:r}}async function vt(e,t){return Ls(e.fs,ts(e,t))}async function Ls(e,t){if(!await e.exists(t))return[];let n=await e.readFile(t);if(!n.trim())return[];let r=[];for(let o of n.split(` +-`)){if(!o)continue;let s=Yh(o);s&&r.push(s)}return r}function wl(e){return`${e.oldHash} ${e.newHash} ${e.name} <${e.email}> ${e.timestamp} ${e.tz} ${e.message}`}async function ns(e,t,n){return Ta(e.fs,ts(e,t),n)}async function Ta(e,t,n){if(await Ms(e,t),n.length===0){await e.writeFile(t,"");return}await e.writeFile(t,`${n.map(wl).join(` +-`)} +-`)}async function rt(e,t,n){let r=ts(e,t);await Ms(e.fs,r);let o=`${wl(n)} +-`;if(await e.fs.exists(r)){let s=await e.fs.readFile(r);await e.fs.writeFile(r,s+o)}else await e.fs.writeFile(r,o)}async function js(e,t){let n=ts(e,t);await e.fs.exists(n)&&await e.fs.rm(n)}async function ee(e,t,n,r,o,s,i=!1){let a=await Jn(e,t),c={oldHash:r??oe,newHash:o,...a,message:s};await rt(e,n,c),i&&n!=="HEAD"&&await rt(e,"HEAD",c)}var Ve=pe(()=>{"use strict";St();xr();ge();$a();Gn();St()});function Xh(e){let t=[],n=e.length;for(;n>0;){let s=e.slice(0,n).match(/^(.+?)~(\d*)$/);if(s&&s[1]!==void 0&&s[2]!==void 0){let c=s[2]===""?1:parseInt(s[2],10);t.unshift({type:"tilde",n:c}),n=s[1].length;continue}let i=e.slice(0,n).match(/^(.+?)\^{([^}]*)}$/);if(i&&i[1]!==void 0&&i[2]!==void 0){t.unshift({type:"peel",target:i[2]}),n=i[1].length;continue}let a=e.slice(0,n).match(/^(.+?)\^(\d*)$/);if(a&&a[1]!==void 0&&a[2]!==void 0){let c=a[2]===""?1:parseInt(a[2],10);t.unshift({type:"caret",n:c}),n=a[1].length;continue}break}let r=e.slice(0,n),o=r.match(/^(.+?)@\{(\d+)\}$/);return o&&o[1]!==void 0&&o[2]!==void 0?{base:o[1],reflogIndex:parseInt(o[2],10),suffixes:t}:{base:r,suffixes:t}}async function Zh(e,t){let n=await Do(e,t);if(n.length===0)return null;if(n.length>1)throw new Aa(t);return n[0]}async function Qh(e,t){if(t==="HEAD"||t==="@")return z(e,"HEAD");if(bl.includes(t))return z(e,t);if(/^[0-9a-f]{40}$/.test(t))return await Xt(e,t)?t:null;if(/^[0-9a-f]{4,39}$/.test(t)){let s=await Zh(e,t);if(s)return s}if(t.startsWith("refs/")){let s=await z(e,t);if(s)return s}let n=await z(e,`refs/heads/${t}`);if(n)return n;let r=await z(e,`refs/tags/${t}`);if(r)return r;let o=await z(e,`refs/remotes/${t}`);return o||null}function Jh(e){if(e==="HEAD"||e==="@")return"HEAD";for(let t of bl)if(e===t)return t;return e.startsWith("refs/")?e:`refs/heads/${e}`}async function ep(e,t,n){let r=Jh(t),o=await vt(e,r);if(o.length===0)return null;let s=o.length-1-n;if(s<0||s>=o.length)return null;let i=o[s];return i?i.newHash:null}async function tp(e,t,n){if(n===""||n==="commit")try{return await Se(e,t)}catch{return null}if(n==="tree"){let o;try{o=await Se(e,t)}catch{return null}return(await M(e,o)).tree}return(await be(e,t)).type!==n?null:t}async function np(e,t,n){let r=t;n.some(s=>s.type==="tilde"||s.type==="caret")&&(r=await Se(e,r));for(let s of n)if(s.type==="peel"){if(!r)return null;r=await tp(e,r,s.target)}else if(s.type==="tilde")for(let i=0;ii.parents.length||(r=i.parents[s.n-1]??null,!r))return null}return r}async function Le(e,t){let{base:n,reflogIndex:r,suffixes:o}=Xh(t),s;return r!==void 0?s=await ep(e,n,r):s=await Qh(e,n),s?np(e,s,o):null}function Lo(e){let t=e.indexOf(":");return t<0?null:{rev:e.slice(0,t)||"HEAD",path:e.slice(t+1)}}var bl,Aa,Qt=pe(()=>{"use strict";ae();Ve();ye();bl=["HEAD","FETCH_HEAD","ORIG_HEAD","MERGE_HEAD","CHERRY_PICK_HEAD","REBASE_HEAD"];Aa=class extends Error{constructor(n){super(`short object ID ${n} is ambiguous`);this.prefix=n}}});function op(e){return e.length===4&&e.toLowerCase()===".git"}function ip(e,t){if(e.length===0)throw new Error("invalid tree entry: empty name");if(e.includes("/"))throw new Error(`invalid tree entry: name contains slash: '${e}'`);if(e.includes("\0"))throw new Error("invalid tree entry: name contains null byte");if(e==="."||e==="..")throw new Error(`invalid tree entry: '${e}'`);if(op(e))throw new Error(`invalid tree entry: '${e}'`);if(!sp.has(t))throw new Error(`invalid tree entry mode: '${t}' for '${e}'`)}function Nn(e){let t=[],n=0;for(;ns+i.byteLength,0),r=new Uint8Array(n),o=0;for(let s of t)r.set(s,o),o+=s.byteLength;return r}var rp,yl,sp,Go=pe(()=>{"use strict";St();rp=new TextEncoder,yl=new TextDecoder,sp=new Set(["100644","100755","040000","120000","160000"])});async function Ye(e,t){return Rl(e,t,"")}async function Rl(e,t,n){let r=[],o=new Map;for(let i of t){let a=n?i.path.slice(n.length+1):i.path,c=a.indexOf("/");if(c===-1)r.push({mode:ap(i.mode),name:a,hash:i.hash});else{let f=a.slice(0,c),l=o.get(f);l||(l=[],o.set(f,l)),l.push(i)}}for(let[i,a]of o){let c=n?`${n}/${i}`:i,f=await Rl(e,a,c);r.push({mode:jn.DIRECTORY,name:i,hash:f})}r.sort((i,a)=>{let c=i.mode===jn.DIRECTORY?`${i.name}/`:i.name,f=a.mode===jn.DIRECTORY?`${a.name}/`:a.name;return cf?1:0});let s=kl({type:"tree",entries:r});return Me(e,"tree",s)}async function ze(e,t,n=""){let r=await be(e,t);if(r.type!=="tree")throw new Error(`Expected tree object, got ${r.type}`);let o=Nn(r.content),s=[];for(let i of o.entries){let a=n?`${n}/${i.name}`:i.name;if(i.mode===jn.DIRECTORY){let c=await ze(e,i.hash,a);s.push(...c)}else s.push({path:a,mode:i.mode,hash:i.hash})}return s}async function de(e,t){if(!t)return new Map;let n=await ze(e,t);return new Map(n.map(r=>[r.path,r]))}async function Ke(e,t,n){if(t===n)return[];let r=[];return await Cl(e,t,n,"",r),r.sort((o,s)=>Te(o.path,s.path))}async function El(e,t){let n=await be(e,t);if(n.type!=="tree")throw new Error(`Expected tree object, got ${n.type}`);return Nn(n.content).entries}async function Cl(e,t,n,r,o){if(t===n)return;let s=t?await El(e,t):[],i=n?await El(e,n):[],a=new Map;for(let l of s)a.set(l.name,l);let c=new Map;for(let l of i)c.set(l.name,l);let f=new Set;for(let l of s)f.add(l.name);for(let l of i)f.add(l.name);for(let l of f){let d=a.get(l),u=c.get(l),m=r?`${r}/${l}`:l;if(d&&u){if(d.hash===u.hash&&d.mode===u.mode)continue;let h=d.mode===jn.DIRECTORY,p=u.mode===jn.DIRECTORY;h&&p?await Cl(e,d.hash,u.hash,m,o):h?(await Fo(e,d.hash,m,"deleted",o),o.push({path:m,status:"added",newHash:u.hash,newMode:u.mode})):p?(o.push({path:m,status:"deleted",oldHash:d.hash,oldMode:d.mode}),await Fo(e,u.hash,m,"added",o)):o.push({path:m,status:"modified",oldHash:d.hash,newHash:u.hash,oldMode:d.mode,newMode:u.mode})}else if(d)d.mode===jn.DIRECTORY?await Fo(e,d.hash,m,"deleted",o):o.push({path:m,status:"deleted",oldHash:d.hash,oldMode:d.mode});else{let h=u;h.mode===jn.DIRECTORY?await Fo(e,h.hash,m,"added",o):o.push({path:m,status:"added",newHash:h.hash,newMode:h.mode})}}}async function Fo(e,t,n,r,o){let s=await ze(e,t,n);for(let i of s)r==="added"?o.push({path:i.path,status:"added",newHash:i.hash,newMode:i.mode}):o.push({path:i.path,status:"deleted",oldHash:i.hash,oldMode:i.mode})}function ap(e){return e.toString(8).padStart(6,"0")}var De=pe(()=>{"use strict";ne();ae();Go();Oa()});function Gs(e){let t=xl.get(e);return t||(t=lp(e),xl.set(e,t)),t}async function lp(e){let t=(await Re(e,"core.autocrlf"))?.toLowerCase();return t==="true"||t==="yes"||t==="on"||t==="1"?{clean:!0,smudgeCrlf:!0}:t==="input"?{clean:!0,smudgeCrlf:!1}:fp}function Pl(e){for(let t=e.indexOf(13);t!==-1;t=e.indexOf(13,t+1))if(e[t+1]===10)return!0;return!1}function $l(e){return e.indexOf(13)!==-1}function Ha(e){if(!Pl(e))return e;let t=new Uint8Array(e.byteLength),n=0,r=0;for(let o=e.indexOf(13);o!==-1;o=e.indexOf(13,o+1))e[o+1]===10&&(t.set(e.subarray(r,o),n),n+=o-r,r=o+1);return t.set(e.subarray(r),n),n+=e.byteLength-r,t.subarray(0,n)}function Ol(e){if(e.indexOf(10)===-1||$l(e)||hn(e))return e;let t=0;for(let o=0;o{"use strict";Be();ae();cn();cp=new TextEncoder,fp={clean:!1,smudgeCrlf:!1},xl=new WeakMap});function Il(e){return/^[a-zA-Z0-9]$/.test(e)}function up(e){return/^[a-zA-Z]$/.test(e)}function mp(e){return e>="0"&&e<="9"}function Ma(e){return e>="A"&&e<="Z"}function ja(e){return e>="a"&&e<="z"}function Tl(e){return/^\s$/.test(e)}function hp(e){return e===" "||e===" "}function Ga(e){let t=e.charCodeAt(0);return t>=32&&t<=126}function pp(e){return Ga(e)&&!Tl(e)}function gp(e){return Ga(e)&&!Il(e)&&e!==" "}function wp(e){let t=e.charCodeAt(0);return t<32||t===127}function bp(e){return/^[0-9a-fA-F]$/.test(e)}function Ns(e,t,n){return n?e.toLowerCase()===t.toLowerCase():e===t}function La(e,t,n,r,o){let s=(o&1)!==0,i=(o&2)!==0;for(;t=n.length&&a!=="*")return-1;let c=r=e.length)return-1;if(!Ns(n[r],e[t],s))return 1;r++,t++;break}case"?":{if(i&&c==="/")return 1;r++,t++;break}case"*":{let f;if(t++,t=e.length||e[t]==="/"||e[t]==="\\"&&t+1=e.length)return!f&&n.indexOf("/",r)!==-1?-2:0;if(!f&&e[t]==="/"){let l=n.indexOf("/",r);if(l===-1)return-1;r=l+1,t++;break}for(;!(r>=n.length);){if(!yp(e[t])){let d=s?e[t].toLowerCase():e[t];for(;r=n.length||!f&&n[r]==="/")return r=e.length)return-1;let f=!1;(e[t]==="!"||e[t]==="^")&&(f=!0,t++);let l=!1,d="",u=!0;for(;t=e.length)return-1;m=e[t],Ns(c,m,s)&&(l=!0)}else if(m==="-"&&d&&t+1=e.length)return-1;m=e[t]}let h=d,p=m;if(c>=h&&c<=p&&(l=!0),s){if(ja(c)){let g=c.toUpperCase();g>=h&&g<=p&&(l=!0)}else if(Ma(c)){let g=c.toLowerCase();g>=h&&g<=p&&(l=!0)}}m=""}else if(m==="["&&t+1=e.length)return-1;let p=t-h-1;if(p<0||e[t-1]!==":")t=h-2,m="[",Ns(c,m,s)&&(l=!0);else{let g=e.slice(h,h+p);kp(g,c,s)&&(l=!0),m=""}}else Ns(c,m,s)&&(l=!0);d=m,t++}if(t>=e.length)return-1;if(t++,l===f)return 1;r++;break}default:{if(!Ns(c,a,s))return 1;r++,t++;break}}}return r>=n.length?0:1}function yp(e){return e==="*"||e==="?"||e==="["||e==="\\"}function kp(e,t,n){switch(e){case"alnum":return Il(t);case"alpha":return up(t);case"blank":return hp(t);case"cntrl":return wp(t);case"digit":return mp(t);case"graph":return pp(t);case"lower":return ja(t)||n&&Ma(t);case"print":return Ga(t);case"punct":return gp(t);case"space":return Tl(t);case"upper":return Ma(t)||n&&ja(t);case"xdigit":return bp(t);default:return!1}}function xn(e,t,n=0){return La(e,0,t,0,n)===0?0:1}var Us=pe(()=>{"use strict"});function Ml(e){for(let t=0;t0;){let c=n[n.length-1];if(c===" "||c===" "){if(n.length>=2&&n[n.length-2]==="\\"){n=n.slice(0,n.length-2)+n[n.length-1];break}n=n.slice(0,-1)}else break}if(n.length===0||n[0]==="#")return null;let r=0,o=n;if(o[0]==="!"&&(r|=No,o=o.slice(1)),o.length===0)return null;let s=o.length;o[s-1]==="/"&&(s--,o=o.slice(0,s),r|=Dl);let i=!1;for(let c=0;c=i.length&&e.endsWith(i)}return xn(n,e,2)===0}function xp(e,t){let{base:n}=t,{pattern:r,patternLen:o,nowildcardLen:s}=t;r[0]==="/"&&(r=r.slice(1),o--,s=Math.max(0,s-1));let i=n.length;if(i>0&&(e.length0?e.slice(i+1):e,c=a.length;if(s>0){if(s>c||a.slice(0,s)!==r.slice(0,s))return!1;if(o===s&&c===s)return!0}return xn(r,a,2)===0}function Fa(e,t,n){let r=e.lastIndexOf("/")>=0?e.slice(e.lastIndexOf("/")+1):e;for(let o=n.patterns.length-1;o>=0;o--){let s=n.patterns[o];if(s&&!(s.flags&Dl&&!t)){if(s.flags&Al){if(s.base&&!e.startsWith(`${s.base}/`))continue;if(Cp(r,s))return s;continue}if(xp(e,s))return s}}return null}function Pn(e,t,n){for(let r=e.dirPatterns.length-1;r>=0;r--){let o=e.dirPatterns[r],s=Fa(t,n,o);if(s)return s.flags&No?"not-ignored":"ignored"}if(e.excludeFile){let r=Fa(t,n,e.excludeFile);if(r)return r.flags&No?"not-ignored":"ignored"}if(e.globalExclude){let r=Fa(t,n,e.globalExclude);if(r)return r.flags&No?"not-ignored":"ignored"}return"undecided"}async function rs(e){let t={dirPatterns:[],excludeFile:null,globalExclude:null},n=I(e.gitDir,"info","exclude");try{let r=await e.fs.readFile(n);t.excludeFile=_s(r,"",n)}catch{}try{let r=await Re(e,"core.excludesFile");if(r)try{let o=await e.fs.readFile(r);t.globalExclude=_s(o,"",r)}catch{}}catch{}return t}function Ir(e,t,n,r){let s=_s(t,n===""?"":n,r);return{...e,dirPatterns:[...e.dirPatterns,s]}}var Al,Hl,Dl,No,_o=pe(()=>{"use strict";Be();ge();Us();Al=1,Hl=4,Dl=8,No=16});async function dt(e,t,n){if(!e.workTree)throw new Error("Cannot diff working tree in a bare repository");let r=n?.includeUntracked??!0,o=n?.stopAfterFirst??!1,s=n?.pathFilter,i=vf(t),a=[];for(let l of t.entries){if(l.stage!==0||Yt(l.mode)||s&&!s(l.path))continue;let d=I(e.workTree,l.path),u;try{u=await Je(e.fs,d)}catch{u=null}if(!u){if(a.push({path:l.path,status:"deleted",indexHash:l.hash}),o)return a;continue}if(!u.isFile&&!u.isSymbolicLink){if(a.push({path:l.path,status:"deleted",indexHash:l.hash}),o)return a;continue}if(Tf(l,u,i))continue;let m=await $t(e,d,l.hash,u);if(m!==l.hash&&(a.push({path:l.path,status:"modified",indexHash:l.hash,worktreeHash:m}),o))return a}if(!r)return a.sort((l,d)=>Te(l.path,d.path));let c=new Set(t.entries.map(l=>l.path)),f=await ut(e,e.workTree,"",{stopAfterFirst:o,_fileFilter:l=>!c.has(l)&&(!s||s(l))});for(let l of f)a.push({path:l,status:"untracked"});return o?a:a.sort((l,d)=>Te(l.path,d.path))}async function at(e,t){if(!e.workTree)throw new Error("Cannot checkout in a bare repository");if(!Pr(t.path))throw new Error(`refusing to check out unsafe path '${t.path}'`);if(t.mode!=null&&Yt(t.mode)){let s=I(e.workTree,t.path);await e.fs.mkdir(s,{recursive:!0});return}let n=await be(e,t.hash);if(n.type!=="blob")throw new Error(`Expected blob for ${t.path}, got ${n.type}`);let r=I(e.workTree,t.path);if(!Co(e.workTree,r))throw new Error(`refusing to check out path outside worktree: '${t.path}'`);let o=r.lastIndexOf("/");if(o>0&&await e.fs.mkdir(r.slice(0,o),{recursive:!0}),t.mode!=null&&Dn(t.mode)&&e.fs.symlink){let s=$p.decode(n.content);if(!Rf(s))throw new Error(`refusing to create symlink with unsafe target '${s}'`);await Je(e.fs,r).then(()=>!0).catch(()=>!1)&&await e.fs.rm(r,{force:!0}),await e.fs.symlink(s,r)}else{if(e.fs.lstat)try{(await e.fs.lstat(r)).isSymbolicLink&&await e.fs.rm(r,{force:!0})}catch{}let i=(await Gs(e)).smudgeCrlf?Ol(n.content):n.content;await e.fs.writeFile(r,i)}}async function jl(e,t){let n=await ze(e,t);for(let r of n)await at(e,r)}async function $n(e,t,n){if(!e.workTree)throw new Error("Cannot stage in a bare repository");if(!Pr(n))throw new Error(`refusing to stage unsafe path '${n}'`);let r=I(e.workTree,n);if(!await e.fs.exists(r))throw new Error(`Path does not exist: ${n}`);let o=await Je(e.fs,r);if(o.isSymbolicLink&&e.fs.readlink){let l=await e.fs.readlink(r),d=Pp.encode(l),u=await Me(e,"blob",d),m={path:n,mode:40960,hash:u,stage:0,stat:$o(o,d.byteLength)};return{index:Mt(t,m),hash:u}}let s=await e.fs.readFileBuffer(r),i=await Fs(e,s,Kr(t,n)?.hash),a=await Me(e,"blob",i),c=Oo(o),f={path:n,mode:c,hash:a,stage:0,stat:$o(o,s.byteLength)};return{index:Mt(t,f),hash:a}}async function ut(e,t,n,r){let o=r?.skipIgnore??!1,s=r?.stopAfterFirst??!1,i=r?._fileFilter,a=null;if(!o){a=r?._ignore??await rs(e);let l=I(t,".gitignore");try{let d=await e.fs.readFile(l);a=Ir(a,d,n,l)}catch{}}let c=[],f=await e.fs.readdir(t);for(let l of f){if(n===""&&l===".git")continue;let d=I(t,l),u=n?`${n}/${l}`:l,m=await Je(e.fs,d);if(m.isSymbolicLink){if(a&&Pn(a,u,!1)==="ignored")continue;(!i||i(u))&&c.push(u)}else if(m.isDirectory){if(a&&Pn(a,u,!0)==="ignored")continue;let h=await ut(e,d,u,{skipIgnore:o,stopAfterFirst:s,_ignore:a??void 0,_fileFilter:i});c.push(...h)}else if(m.isFile){if(a&&Pn(a,u,!1)==="ignored")continue;(!i||i(u))&&c.push(u)}if(s&&c.length>0)break}return c}async function Tr(e,t,n){if(t===n||t==="/"||!t.startsWith(n)||!await e.exists(t)||!(await e.stat(t)).isDirectory)return;(await e.readdir(t)).length===0&&(await e.rm(t,{recursive:!0}),await Tr(e,bt(t),n))}var Pp,$p,st=pe(()=>{"use strict";ne();ir();_o();ve();ae();xo();ge();cn();De();Pp=new TextEncoder,$p=new TextDecoder});function Na(e){return e.existsOnDisk&&e.indexHash===null}async function Op(e,t,n){let r=await Promise.all(t.map(h=>de(e,h.treeHash))),o=new Map,s=new Set;for(let h of n.entries)h.stage===0?o.set(h.path,h):s.add(h.path);let i=e.workTree?new Set(await ut(e,e.workTree,"",{skipIgnore:!0})):new Set,a=null,c=async()=>(a===null&&(a=e.workTree?new Set(await ut(e,e.workTree,"")):new Set),a),f=new Set;for(let h of r)for(let p of h.keys())f.add(p);let l=new Set;for(let h of n.entries)f.has(h.path)||l.add(h.path);for(let h of i)f.has(h)||l.add(h);let d=Array.from(f).sort().concat(Array.from(l).sort()),u=(h,p)=>r[h]?.get(p),m=[];for(let h of d){let p=null,g=null,w=null,b=null,R=null;if(r.length===1){let T=u(0,h);w=T?.hash??null,R=T?.mode??null}else if(r.length===2){let T=u(0,h),j=u(1,h);g=T?.hash??null,b=T?.mode??null,w=j?.hash??null,R=j?.mode??null}else if(r.length>=3){let T=u(0,h),j=u(1,h),U=u(2,h);p=T?.hash??null,g=j?.hash??null,b=j?.mode??null,w=U?.hash??null,R=U?.mode??null}let x=o.get(h)?.hash??null,y=s.has(h)?1:0,P=i.has(h),k,E=async()=>k!==void 0?k:P?(k=!(await c()).has(h),k):(k=!1,!1),O,$=async()=>{if(O!==void 0)return O;if(!P||!e.workTree)return O=null,null;let T=I(e.workTree,h);try{O=await $t(e,T,x??void 0)}catch{O=null}return O};m.push({path:h,baseHash:p,headHash:g,remoteHash:w,indexHash:x,indexStage:y,existsOnDisk:P,isIgnoredOnDisk:E,getWorktreeHash:$,headMode:b,remoteMode:R})}return m}function Bo(e,t){let n=e.remoteHash;return n===null?e.indexHash===null&&e.indexStage===0?{action:"SKIP",requirements:[]}:{action:"DELETE",requirements:t.reset?[]:["WORKTREE_MUST_BE_UPTODATE"]}:e.indexHash===n?{action:"KEEP",requirements:[]}:e.indexHash===null?{action:"TAKE",takeFrom:"remote",requirements:t.reset||!!t.strippedConflictPaths?.has(e.path)?[]:["NO_UNTRACKED"]}:{action:"TAKE",takeFrom:"remote",requirements:t.reset?[]:["WORKTREE_MUST_BE_UPTODATE"]}}function Wo(e,t){let{headHash:n,remoteHash:r,indexHash:o}=e;return e.indexStage>0?n===r?r===null?{action:"DELETE",requirements:[]}:{action:"TAKE",takeFrom:"remote",requirements:[]}:{action:"KEEP",requirements:["INDEX_MUST_MATCH_HEAD"],caseNumber:-1}:o===null?r===null?n===null?{action:"SKIP",caseNumber:0,requirements:[]}:{action:"SKIP",caseNumber:2,requirements:["NO_UNTRACKED_REMOVED"]}:n!==null?n===r?{action:"SKIP",caseNumber:3,requirements:[]}:t.allowStagedChanges?{action:"TAKE",takeFrom:"remote",caseNumber:3,requirements:[]}:{action:"KEEP",caseNumber:3,requirements:["INDEX_MUST_MATCH_HEAD"]}:{action:"TAKE",takeFrom:"remote",caseNumber:1,requirements:["NO_UNTRACKED"]}:n===null&&r===null?{action:"KEEP",caseNumber:4,requirements:[]}:n===null&&r===o?{action:"KEEP",caseNumber:6,requirements:[]}:n===o&&r===null?{action:"DELETE",caseNumber:10,requirements:["WORKTREE_MUST_BE_UPTODATE"]}:n!==null&&n===r?{action:"KEEP",caseNumber:14,requirements:[]}:n!==null&&r!==null&&o===r?{action:"KEEP",caseNumber:18,requirements:[]}:n!==null&&r!==null&&o===n&&o!==r?{action:"TAKE",takeFrom:"remote",caseNumber:20,requirements:["WORKTREE_MUST_BE_UPTODATE"]}:t.allowStagedChanges?r===null?{action:"DELETE",caseNumber:-1,requirements:[]}:{action:"TAKE",takeFrom:"remote",caseNumber:-1,requirements:[]}:{action:"KEEP",requirements:["INDEX_MUST_MATCH_HEAD"],caseNumber:-1}}function Sp(e,t){switch(e.action){case"TAKE":return e.takeFrom==="head"?t.headHash:e.takeFrom==="remote"?t.remoteHash:e.takeFrom==="base"?t.baseHash:null;case"DELETE":return null;case"KEEP":return t.indexHash;default:return null}}async function vp(e,t,n){let r=[];if(n.reset)return r;for(let[o,s]of e){if(s.requirements.length===0)continue;let i=t.get(o);if(!i)continue;let a=Sp(s,i);for(let c of s.requirements){if(n.allowStagedChanges&&c==="INDEX_MUST_MATCH_HEAD")continue;let f=await Ip(c,i,a);if(f){r.push({path:o,error:f});break}}if(n.stopAtFirstError&&r.length>0)break}return r}async function Ip(e,t,n,r){switch(e){case"INDEX_MUST_NOT_EXIST":return t.indexHash!==null?"WOULD_OVERWRITE":Na(t)?"WOULD_LOSE_UNTRACKED_REMOVED":null;case"INDEX_MUST_MATCH_HEAD":return t.indexHash!==t.headHash?"WOULD_OVERWRITE":null;case"INDEX_MUST_MATCH_RESULT":return t.indexHash!==null&&t.indexHash!==n?"WOULD_OVERWRITE":null;case"WORKTREE_MUST_BE_UPTODATE":{if(!t.existsOnDisk)return null;let o=await t.getWorktreeHash();return o!==t.indexHash?r?.allowContentEscapeHatch&&(n!==null&&o===n||o===null&&n===null)?null:"NOT_UPTODATE_FILE":null}case"NO_UNTRACKED":return Na(t)?await t.isIgnoredOnDisk()?null:"WOULD_LOSE_UNTRACKED_OVERWRITTEN":null;case"NO_UNTRACKED_REMOVED":return Na(t)?await t.isIgnoredOnDisk()?null:"WOULD_LOSE_UNTRACKED_REMOVED":null}}function Tp(e,t,n,r){let o=[],s=[],i=new Set(e.keys()),a=new Map;for(let c of n.entries)i.has(c.path)||o.push(c),c.stage===0&&a.set(c.path,c);for(let[c,f]of e){let l=t.get(c);if(l)switch(f.action){case"KEEP":{let d=a.get(c);d&&(o.push(d),r.reset&&r.updateWorktree&&s.push({path:c,type:"checkout",hash:d.hash,mode:d.mode}));break}case"TAKE":{let d=f.takeFrom==="head"?l.headHash:l.remoteHash,u=f.takeFrom==="head"?l.headMode:l.remoteMode,m=u?Number.parseInt(u,8):33188;o.push({path:c,mode:m,hash:d,stage:0,stat:Fe()}),r.updateWorktree&&s.push({path:c,type:"checkout",hash:d,mode:m});break}case"DELETE":{r.updateWorktree&&l.existsOnDisk&&s.push({path:c,type:"delete"});break}case"SKIP":break}}return o.sort((c,f)=>Te(c.path,f.path)||c.stage-f.stage),{newEntries:o,worktreeOps:s}}function qo(e,t){let n=t.actionHint??t.operationName,r=[];for(let{error:s,msg:i,fix:a}of Ap){let c=e.filter(f=>f.error===s).map(f=>f.path).sort();if(c.length>0){let f=c.map(l=>` ${l}`).join(` ++`);return{name:a,email:c,timestamp:o,timezone:i}}async function Jn(e,t){try{let n=await vs(e,t);return{name:n.name,email:n.email,timestamp:n.timestamp,tz:n.timezone}}catch{return{name:t.get("GIT_COMMITTER_NAME")??"",email:t.get("GIT_COMMITTER_EMAIL")??"",timestamp:Math.floor(Date.now()/1e3),tz:"+0000"}}}function Oh(e){let t={timestamp:Math.floor(Date.now()/1e3),timezone:"+0000"};if(!e)return t;let n=e.trim();if(!n)return t;if(n.startsWith("@")){let o=n.slice(1).trim(),i=parseInt(o,10);if(!Number.isNaN(i))return{timestamp:i,timezone:"+0000"}}if(/^\d+$/.test(n))return{timestamp:parseInt(n,10),timezone:"+0000"};let r=n.match(/^(\d+)\s+([+-]\d{4})$/);if(r)return{timestamp:parseInt(r[1],10),timezone:r[2]};let s=Date.parse(n);return Number.isNaN(s)?t:{timestamp:Math.floor(s/1e3),timezone:Sh(n)}}function Sh(e){if(/Z$/i.test(e))return"+0000";let t=e.match(/([+-])(\d{2}):(\d{2})$/);if(t)return`${t[1]}${t[2]}${t[3]}`;let n=e.match(/([+-]\d{4})$/);return n?n[1]:"+0000"}var $h,$r=we(()=>{"use strict";We();$h={author:{name:"GIT_AUTHOR_NAME",email:"GIT_AUTHOR_EMAIL",date:"GIT_AUTHOR_DATE"},committer:{name:"GIT_COMMITTER_NAME",email:"GIT_COMMITTER_EMAIL",date:"GIT_COMMITTER_DATE"}}});function er(e){let t="";for(let n=0;n<20;n++)t+=vf[e[n]];return t}function Is(e,t){let n="";for(let r=0;r<20;r++)n+=vf[e[t+r]];return n}function Qt(e){let t=new Uint8Array(20);for(let n=0;n<20;n++)t[n]=parseInt(e.slice(n*2,n*2+2),16);return t}var se,vf,It=we(()=>{"use strict";se="0000000000000000000000000000000000000000",vf=(()=>{let e=new Array(256);for(let t=0;t<256;t++)e[t]=(t>>4).toString(16)+(t&15).toString(16);return e})()});function If(e){return e.length===4&&e.toLowerCase()===".git"}function Or(e){if(e.length===0||e.includes("\0")||e.charCodeAt(0)===47||e.charCodeAt(e.length-1)===47)return!1;let t=e.split("/");for(let n of t)if(n.length===0||n==="."||n===".."||If(n))return!1;return!0}function To(e,t){return t===e?!1:e==="/"?t.startsWith("/")&&t.length>1:t.startsWith(e+"/")}function Tf(e){if(e.length===0||e.charCodeAt(0)===47)return!1;let t=e.split("/");for(let n of t)if(n===".."||If(n))return!1;return!0}var Ao=we(()=>{"use strict"});function ba(e){return typeof e=="string"?vh.encode(e):e}function Ih(){if(typeof globalThis.Bun<"u")return()=>{let e=new Bun.CryptoHasher("sha1"),t={update(n){return e.update(ba(n)),t},hex:()=>Promise.resolve(e.digest("hex"))};return t};try{let e=xo(["node","crypto"].join(":"));if(typeof e.createHash=="function")return()=>{let t=e.createHash("sha1"),n={update(r){return t.update(ba(r)),n},hex:()=>Promise.resolve(t.digest("hex"))};return n}}catch{}if(typeof globalThis.crypto?.subtle?.digest=="function")return()=>{let e=[],t={update(n){return e.push(ba(n)),t},async hex(){let n=0;for(let i of e)n+=i.byteLength;let r=new Uint8Array(n),s=0;for(let i of e)r.set(i,s),s+=i.byteLength;let o=await crypto.subtle.digest("SHA-1",r);return er(new Uint8Array(o))}};return t};throw new Error("No SHA-1 implementation available. Requires Bun, Node.js, Deno, or a browser with Web Crypto.")}async function nr(e){return Af().update(e).hex()}var vh,Af,tr,Sr=we(()=>{"use strict";It();vh=new TextEncoder;Af=Ih(),tr=Af});function Ye(e,t){return e.lstat?e.lstat(t):e.stat(t)}function dn(e){return typeof e=="string"?e==="120000":e===40960}function Hf(e){return typeof e=="string"?e==="100755":e===33261}function Df(e){return typeof e=="string"?e==="100644"||e==="100755":e===33188||e===33261}function Jt(e){return typeof e=="string"?e==="160000":e===57344}async function Mf(e,t){if((await Ye(e,t)).isSymbolicLink&&e.readlink){let r=await e.readlink(t);return Th.encode(r)}return e.readFileBuffer(t)}var Th,un=we(()=>{"use strict";Th=new TextEncoder});function Nf(e){return Ir.get(e)}async function X(e){let t=I(e.gitDir,"index");if(!await e.fs.exists(t))return{version:ya,entries:[]};let n=await e.fs.stat(t),r=await e.fs.readFileBuffer(t),s=await e.fs.stat(t),o=Mh(r),i=Xr(n.mtime),a=Xr(s.mtime);return n.size===r.byteLength&&s.size===r.byteLength&&i!==null&&i===a&&Ir.set(o,s.mtime),o}async function oe(e,t){let n=I(e.gitDir,"index");await e.fs.writeFile(n,await jf(t));let r=await Gf(e,n);if(r===null){Ir.delete(t);return}if(jh(t,r)&&(await e.fs.writeFile(n,await jf(t)),r=await Gf(e,n),r===null)){Ir.delete(t);return}Ir.set(t,r)}function jt(e,t){if(!Or(t.path))throw new Error(`refusing to add unsafe path to index: '${t.path}'`);let n;return t.stage===0?n=e.entries.filter(r=>r.path!==t.path):n=e.entries.filter(r=>!(r.path===t.path&&r.stage===t.stage)),n.push(t),n.sort(ka),Ea(e,n)}function Rt(e,t){return Ea(e,e.entries.filter(n=>n.path!==t))}function Zr(e,t,n=0){return e.entries.find(r=>r.path===t&&r.stage===n)}function xn(e){return e.entries.some(t=>t.stage>0)}function mn(e){return[...new Set(e.entries.filter(t=>t.stage>0).map(t=>t.path))]}function ze(e){return e.entries.filter(t=>t.stage===0)}function Uf(){return{version:ya,entries:[]}}function Qr(e){let t=[...e].sort(ka);return{version:ya,entries:t}}function Ge(){return{ctimeSeconds:0,ctimeNanoseconds:0,mtimeSeconds:0,mtimeNanoseconds:0,dev:0,ino:0,uid:0,gid:0,size:0}}function Do(e,t=e.size){let n=Lf(e.mtime),r=e.ctime?Lf(e.ctime):{seconds:0,nanoseconds:0};return{ctimeSeconds:r.seconds,ctimeNanoseconds:r.nanoseconds,mtimeSeconds:n.seconds,mtimeNanoseconds:n.nanoseconds,dev:vr(e.dev),ino:vr(e.ino),uid:vr(e.uid),gid:vr(e.gid),size:vr(t)}}function _f(e,t,n,r){if(!r||!n.isFile||n.isSymbolicLink||t.stat.mtimeSeconds===0||n.size<0||n.size>4294967295||Tr(e,t,n)!==t.mode||n.size!==t.stat.size)return!1;let s=Xr(n.mtime),o=Xr(r);if(s===null||o===null||s!==Bf(t.stat))return!1;if(n.ctime){if(t.stat.ctimeSeconds===0)return!1;let i=t.stat.ctimeSeconds*1e3+Math.floor(t.stat.ctimeNanoseconds/1e6);if(Math.trunc(n.ctime.getTime())!==i)return!1}return!Ho(n.dev,t.stat.dev)||!Ho(n.ino,t.stat.ino)||!Ho(n.uid,t.stat.uid)||!Ho(n.gid,t.stat.gid)?!1:snull);if(!i||Tr(e.fs,o,i)!==o.mode){s.push(o);continue}s.push({...o,stat:Do(i)})}return Ea(t,s)}function Mh(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=0,r=t.getUint32(n);if(n+=4,r!==Ff)throw new Error(`Invalid index signature: 0x${r.toString(16)}`);let s=t.getUint32(n);n+=4;let o=t.getUint32(n);n+=4;let i=[];for(let a=0;a>12&3,p=m&4095,g,w;if(p<4095)w=new TextDecoder().decode(e.subarray(n,n+p)),g=p;else{let C=n;for(;Ct.path?1:e.stage-t.stage}function Lf(e){let t=Xr(e);if(t===null)return{seconds:0,nanoseconds:0};let n=Math.floor(t/1e3);return{seconds:vr(n),nanoseconds:(t-n*1e3)*1e6}}function Xr(e){if(!(e instanceof Date))return null;let t=Math.trunc(e.getTime());return Number.isFinite(t)?t:null}function vr(e){return e===void 0||!Number.isFinite(e)||e<0?0:Math.trunc(e)>>>0}function Ho(e,t){return e===void 0?!0:t!==0&&vr(e)===t}function Bf(e){return e.mtimeSeconds*1e3+Math.floor(e.mtimeNanoseconds/1e6)}function Ea(e,t){let n={...e,entries:t},r=Ir.get(e);return r&&Ir.set(n,r),n}async function Gf(e,t){let{mtime:n}=await e.fs.stat(t);return Xr(n)===null?null:n}function jh(e,t){let n=Math.trunc(t.getTime()),r=!1;for(let s=0;s{"use strict";It();Ao();ge();Sr();un();Ff=1145655875,ya=2,Ir=new WeakMap});var Lh,Mo,Wf=we(()=>{"use strict";Lh=new Set(["tree","commit","tag"]),Mo=class{map=new Map;currentBytes=0;maxBytes;constructor(t=16*1024*1024){this.maxBytes=t}get(t){return this.map.get(t)}set(t,n){if(!Lh.has(n.type))return;let r=n.content.byteLength;if(!(r>this.maxBytes/2)&&!this.map.has(t)){for(;this.currentBytes+r>this.maxBytes&&this.map.size>0;){let s=this.map.keys().next().value;this.currentBytes-=this.map.get(s).content.byteLength,this.map.delete(s)}this.map.set(t,n),this.currentBytes+=r}}get size(){return this.map.size}get bytes(){return this.currentBytes}clear(){this.map.clear(),this.currentBytes=0}}});function Ra(e){let t=4294967295;for(let n=0;n>>8;return(t^4294967295)>>>0}var qf,zf=we(()=>{"use strict";qf=new Uint32Array(256);for(let e=0;e<256;e++){let t=e;for(let n=0;n<8;n++)t=t&1?3988292384^t>>>1:t>>>1;qf[e]=t}});function tl(e){let t=el(e);return Jf(e.subarray(t,-4),{i:2})}function $a(e){let t=el(e),n={i:2},r=Jf(e.subarray(t),n),s=Qf(n.p);return{result:r,bytesConsumed:t+s+4}}var pn,Jr,Gh,Kf,Vf,Fh,Yf,Xf,Nh,Pa,Ts,As,Zf,Uh,_h,Ca,hn,xa,Qf,Bh,Pn,Jf,el,nl=we(()=>{"use strict";pn=Uint8Array,Jr=Uint16Array,Gh=Int32Array,Kf=new pn([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),Vf=new pn([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),Fh=new pn([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Yf=(e,t)=>{let n=new Jr(31);for(let s=0;s<31;++s)n[s]=t+=1<>1|(e&21845)<<1;t=(t&52428)>>2|(t&13107)<<2,t=(t&61680)>>4|(t&3855)<<4,Pa[e]=((t&65280)>>8|(t&255)<<8)>>1}Ts=(e,t,n)=>{let r=e.length,s=0,o=new Jr(t);for(;s>c]=f}}else for(a=new Jr(r),s=0;s>15-e[s]);return a},As=new pn(288);for(let e=0;e<144;++e)As[e]=8;for(let e=144;e<256;++e)As[e]=9;for(let e=256;e<280;++e)As[e]=7;for(let e=280;e<288;++e)As[e]=8;Zf=new pn(32);for(let e=0;e<32;++e)Zf[e]=5;Uh=Ts(As,9,1),_h=Ts(Zf,5,1),Ca=e=>{let t=e[0];for(let n=1;nt&&(t=e[n]);return t},hn=(e,t,n)=>{let r=t/8|0;return(e[r]|e[r+1]<<8)>>(t&7)&n},xa=(e,t)=>{let n=t/8|0;return(e[n]|e[n+1]<<8|e[n+2]<<16)>>(t&7)},Qf=e=>(e+7)/8|0,Bh=(e,t,n)=>((t==null||t<0)&&(t=0),(n==null||n>e.length)&&(n=e.length),new pn(e.subarray(t,n))),Pn=(e,t)=>{let n=["unexpected EOF","invalid block type","invalid length/literal","invalid distance"];throw new Error(t||n[e]||"unknown inflate error")},Jf=(e,t,n,r)=>{let s=e.length,o=r?r.length:0;if(!s||t.f&&!t.l)return n||new pn(0);let i=!n,a=i||t.i!=2,c=t.i;i&&(n=new pn(s*3));let f=b=>{let y=n.length;if(b>y){let C=new pn(Math.max(y*2,b));C.set(n),n=C}},l=t.f||0,d=t.p||0,u=t.b||0,m=t.l,h=t.d,p=t.m,g=t.n,w=s*8;do{if(!m){l=hn(e,d,1);let x=hn(e,d+1,3);if(d+=3,x)if(x==1)m=Uh,h=_h,p=9,g=5;else if(x==2){let k=hn(e,d,31)+257,P=hn(e,d+10,15)+4,E=k+hn(e,d+5,31)+1;d+=14;let R=new pn(E),O=new pn(19);for(let L=0;L>4;if(H<16)R[L++]=H;else{let q=0,F=0;for(H==16?(F=3+hn(e,d,3),d+=2,q=R[L-1]):H==17?(F=3+hn(e,d,7),d+=3):H==18&&(F=11+hn(e,d,127),d+=7);F--;)R[L++]=q}}let U=R.subarray(0,k),G=R.subarray(k);p=Ca(U),g=Ca(G),m=Ts(U,p,1),h=Ts(G,g,1)}else Pn(1);else{let k=Qf(d)+4,P=e[k-4]|e[k-3]<<8,E=k+P;if(E>s){c&&Pn(0);break}a&&f(u+P),n.set(e.subarray(k,E),u),t.b=u+=P,t.p=d=E*8,t.f=l;continue}if(d>w){c&&Pn(0);break}}a&&f(u+131072);let b=(1<>4;if(d+=x&15,d>w){c&&Pn(0);break}if(x||Pn(2),k<256)n[u++]=k;else if(k==256){C=d,m=null;break}else{let P=k-254;if(k>264){let T=k-257,j=Kf[T];P=hn(e,d,(1<>4;E||Pn(3),d+=E&15;let O=Nh[R];if(R>3){let T=Vf[R];O+=xa(e,d)&(1<w){c&&Pn(0);break}a&&f(u+131072);let $=u+P;if(u(((e[0]&15)!=8||e[0]>>4>7||(e[0]<<8|e[1])%31)&&Pn(0,"invalid zlib data"),e[1]&32&&Pn(0,"zlib dictionaries are not supported"),2)});async function Wh(){let e;if(!(typeof document<"u"))try{e=xo(["node","zlib"].join(":"))}catch{try{e=await import(["node","zlib"].join(":"))}catch{}}if(e&&typeof e.deflateSync=="function"&&typeof e.inflateSync=="function"){let r=null;try{let s=e.inflateSync(e.deflateSync(Buffer.from("x")),{info:!0});s?.engine&&typeof s.engine.bytesWritten=="number"&&(r=o=>{let i=e.inflateSync(o,{info:!0});return{result:new Uint8Array(i.buffer),bytesConsumed:i.engine.bytesWritten}})}catch{}return{deflateSync:s=>new Uint8Array(e.deflateSync(s)),inflateSync:s=>new Uint8Array(e.inflateSync(s)),inflateWithConsumed:r??$a}}let n;return typeof globalThis.CompressionStream=="function"?n=async r=>{let s=new CompressionStream("deflate"),o=s.writable.getWriter();return o.write(r),o.close(),new Uint8Array(await new Response(s.readable).arrayBuffer())}:n=()=>{throw new Error("No deflate implementation available. Requires node:zlib or CompressionStream.")},{deflateSync:n,inflateSync:tl,inflateWithConsumed:$a}}function Oa(){return qh??=Wh()}async function es(e){return await(await Oa()).deflateSync(e)}async function ts(e){return await(await Oa()).inflateSync(e)}async function rl(e,t){let n=await Oa(),{result:r,bytesConsumed:s}=n.inflateWithConsumed(e);if(r.byteLength!==t)throw new Error(`Inflate size mismatch: got ${r.byteLength}, expected ${t}`);return{result:r,bytesConsumed:s}}var qh,jo=we(()=>{"use strict";nl();qh=null});async function dl(e,t){let n=new DataView(e.buffer,e.byteOffset,e.byteLength),r=n.getUint32(0);if(r!==Lo)throw new Error(`Invalid pack signature: 0x${r.toString(16)} (expected 0x${Lo.toString(16)})`);let s=n.getUint32(4);if(s!==Ia)throw new Error(`Unsupported pack version: ${s}`);if(e.byteLength>=32){let f=Is(e,e.byteLength-20),l=tr();l.update(e.subarray(0,e.byteLength-20));let d=await l.hex();if(d!==f)throw new Error(`pack checksum mismatch: expected ${f}, computed ${d}`)}let o=n.getUint32(8),i=[],a=12;for(let f=0;f({...f,offset:i[l].headerOffset,nextOffset:i[l].nextOffset}))}async function Kh(e,t){let n=t,r=e[t++],s=r>>4&7,o=r&15,i=4;for(;r&128;)r=e[t++],o|=(r&127)<sl)throw new Error(`delta chain depth ${i} exceeds limit of ${sl}`);let a=r[o];if(a)return a;let c=e[o];if(c.typeNum!==Hs&&c.typeNum!==Ta){let m=zh[c.typeNum];if(!m)throw new Error(`Unknown object type: ${c.typeNum}`);let h={type:m,content:c.inflated,hash:await Sa(m,c.inflated)};return r[o]=h,h}if(c.typeNum===Hs){let m=n.get(c.baseOffset);if(m===void 0)throw new Error(`OFS_DELTA base not found at offset ${c.baseOffset}`);let h=await s(m,i+1),p=Ds(h.content,c.inflated),g={type:h.type,content:p,hash:await Sa(h.type,p)};return r[o]=g,g}let f=await Yh(e,r,c.baseHash,s),l;if(f!==void 0)l=await s(f,i+1);else if(t){let m=await t(c.baseHash);m&&(l=m)}if(!l)throw new Error(`REF_DELTA base not found for hash ${c.baseHash}`);let d=Ds(l.content,c.inflated),u={type:l.type,content:d,hash:await Sa(l.type,d)};return r[o]=u,u}for(let o=0;o0)a.set(t.subarray(n,n+f),c),c+=f,n+=f;else throw new Error("Unexpected delta opcode 0x00 (reserved)")}if(c!==o)throw new Error(`Delta produced ${c} bytes, expected ${o}`);return a}async function ul(e){let t=[],n=new Uint8Array(12),r=new DataView(n.buffer);r.setUint32(0,Lo),r.setUint32(4,Ia),r.setUint32(8,e.length),t.push(n);for(let s of e){let o=ll[s.type],i=await es(s.content);t.push(va(o,s.content.byteLength)),t.push(i)}return ml(t)}async function Go(e){let t=[],n=new Map,r=new Uint8Array(12),s=new DataView(r.buffer);s.setUint32(0,Lo),s.setUint32(4,Ia),s.setUint32(8,e.length),t.push(r);let o=12,i=[];for(let a of e){let c=o;n.set(a.hash,o);let f=a.delta&&a.deltaBaseHash?n.get(a.deltaBaseHash):void 0;if(a.delta&&f!==void 0){let l=va(Hs,a.delta.byteLength),d=Xh(o-f),u=await es(a.delta);t.push(l,d,u),o+=l.byteLength+d.byteLength+u.byteLength}else{let l=ll[a.type],d=va(l,a.content.byteLength),u=await es(a.content);t.push(d,u),o+=d.byteLength+u.byteLength}i.push({hash:a.hash,offset:c,nextOffset:o})}return{data:await ml(t),entries:i}}async function ml(e){let t=0;for(let i of e)t+=i.byteLength;t+=20;let n=new Uint8Array(t),r=0;for(let i of e)n.set(i,r),r+=i.byteLength;let s=tr();s.update(n.subarray(0,r));let o=await s.hex();return n.set(Qt(o),r),n}function Xh(e){let t=[];t.push(e&127);let n=e>>>7;for(;n>0;)t.unshift(128|--n&127),n>>>=7;return new Uint8Array(t)}function va(e,t){let n=[],r=e<<4|t&15;for(t>>=4;t>0;)n.push(r|128),r=t&127,t>>=7;return n.push(r),new Uint8Array(n)}function ol(e,t){let n=0,r=0,s;do s=e[t++],n|=(s&127)<{"use strict";It();Sr();jo();Lo=1346454347,Ia=2,il=1,al=2,cl=3,fl=4,Hs=6,Ta=7,zh={[il]:"commit",[al]:"tree",[cl]:"blob",[fl]:"tag"},ll={commit:il,tree:al,blob:cl,tag:fl};sl=50;Zh=new TextEncoder});async function gl(e,t){let n=[...e].sort((m,h)=>m.hashh.hash?1:0),r=n.length,s=[];for(let m of n)m.offset>=2147483648&&s.push(BigInt(m.offset));let o=8+256*4+r*20+r*4+r*4+s.length*8+20+20,i=new Uint8Array(o),a=new DataView(i.buffer),c=0;a.setUint32(c,hl),c+=4,a.setUint32(c,pl),c+=4;let f=new Uint32Array(256);for(let m of n){let h=parseInt(m.hash.slice(0,2),16);for(let p=h;p<256;p++)f[p]++}for(let m=0;m<256;m++)a.setUint32(c,f[m]),c+=4;for(let m of n)i.set(Qt(m.hash),c),c+=20;for(let m of n)a.setUint32(c,m.crc),c+=4;let l=0;for(let m of n)m.offset>=2147483648?a.setUint32(c,2147483648|l++):a.setUint32(c,m.offset),c+=4;for(let m of s)a.setBigUint64(c,m),c+=8;i.set(t,c),c+=20;let d=tr();d.update(i.subarray(0,c));let u=await d.hex();return i.set(Qt(u),c),i}async function wl(e){let n=(await dl(e)).map(s=>({hash:s.hash,offset:s.offset,crc:Ra(e.subarray(s.offset,s.nextOffset))})),r=e.subarray(e.byteLength-20);return gl(n,r)}async function bl(e,t){let n=t.map(s=>({hash:s.hash,offset:s.offset,crc:Ra(e.subarray(s.offset,s.nextOffset))})),r=e.subarray(e.byteLength-20);return gl(n,r)}var hl,pl,gn,Fo=we(()=>{"use strict";It();Sr();zf();ns();hl=4285812579,pl=2,gn=class{fanout;hashes;offsets;largeOffsets;count;constructor(t){let n=new DataView(t.buffer,t.byteOffset,t.byteLength);if(n.getUint32(0)!==hl)throw new Error("Invalid pack index: bad magic");if(n.getUint32(4)!==pl)throw new Error(`Unsupported pack index version: ${n.getUint32(4)}`);this.fanout=new Uint32Array(256);let r=8;for(let o=0;o<256;o++)this.fanout[o]=n.getUint32(r),r+=4;this.count=this.fanout[255],this.hashes=new Uint8Array(t.buffer,t.byteOffset+r,this.count*20),r+=this.count*20,r+=this.count*4,this.offsets=new Uint32Array(this.count);for(let o=0;o>>1,f=this.compareAt(c,n);if(f<0)i=c+1;else if(f>0)a=c;else return this.getOffset(c)}return null}has(t){return this.lookup(t)!==null}get objectCount(){return this.count}allHashes(){let t=[];for(let n=0;n>1)]>>4&15:this.hashes[f+(d>>1)]&15,m=d%2===0?o[d>>1]>>4&15:o[d>>1]&15;if(u!==m){l=!1;break}}l&&a.push(this.hashAtSlot(c))}return a}hashAtSlot(t){let n="",r=t*20;for(let s=0;s<20;s++){let o=this.hashes[r+s];n+=(o>>4).toString(16)+(o&15).toString(16)}return n}compareAt(t,n){let r=t*20;for(let s=0;s<20;s++){let o=this.hashes[r+s],i=n[s];if(oi)return 1}return 0}getOffset(t){let n=this.offsets[t];if(n&2147483648){let r=n&2147483647;return Number(this.largeOffsets.getBigUint64(r*8))}return n}}});var Qh,Jh,ep,yl,Ms,kl=we(()=>{"use strict";It();Fo();ns();jo();Qh=6,Jh=7,ep={1:"commit",2:"tree",3:"blob",4:"tag"},yl=50,Ms=class{constructor(t,n){this.data=t;this.index=n instanceof gn?n:new gn(n)}index;hasObject(t){return this.index.has(t)}findByPrefix(t){return this.index.findByPrefix(t)}async readObject(t){let n=this.index.lookup(t);return n===null?null:this.readAt(n,0)}get objectCount(){return this.index.objectCount}async readAt(t,n){if(n>yl)throw new Error(`delta chain depth ${n} exceeds limit of ${yl}`);let r=this.data,s=t,o=r[s++],i=o>>4&7,a=o&15,c=4;for(;o&128;)o=r[s++],a|=(o&127)<{"use strict";It();Wf();Fo();kl();ns();jo();ge();Sr();tp=new TextEncoder,np=new TextDecoder;js=class{constructor(t,n,r){this.fs=t;this.gitDir=n;this.cache=new Mo(r),this.packDir=I(n,"objects","pack")}packs=[];loadedPackNames=new Set;discoverPromise=null;cache;packDir;async write(t,n){let r=Ha(t,n),s=await nr(r),o=Aa(this.gitDir,s);if(await this.fs.exists(o))return s;let i=I(this.gitDir,"objects",s.slice(0,2));return await this.fs.mkdir(i,{recursive:!0}),await this.fs.writeFile(o,await es(r)),s}async read(t){let n=this.cache.get(t);if(n)return n;let r=Aa(this.gitDir,t);if(await this.fs.exists(r)){let s=await this.fs.readFileBuffer(r),o=await ts(s),i=await nr(o);if(i!==t)throw new Error(`corrupt loose object ${t}: SHA-1 mismatch (computed ${i})`);let a=rp(t,o);return this.cache.set(t,a),a}await this.discover();for(let s of this.packs){if(!s.index.has(t))continue;let i=await(await this.ensureReader(s)).readObject(t);if(i)return this.cache.set(t,i),i}throw new Error(`object ${t} not found`)}async exists(t){if(await this.fs.exists(Aa(this.gitDir,t)))return!0;await this.discover();for(let n of this.packs)if(n.index.has(t))return!0;return!1}async ingestPack(t){if(t.byteLength<32)return 0;let n=new DataView(t.buffer,t.byteOffset,t.byteLength),r=n.getUint32(0);if(r!==1346454347)throw new Error(`invalid pack signature: 0x${r.toString(16)} (expected 0x5041434b)`);let s=n.getUint32(4);if(s!==2)throw new Error(`unsupported pack version: ${s}`);let o=n.getUint32(8);if(o===0)return 0;let i=t.subarray(t.byteLength-20),a=er(i),c=await nr(t.subarray(0,t.byteLength-20));if(c!==a)throw new Error(`pack checksum mismatch: expected ${a}, computed ${c}`);await this.fs.mkdir(this.packDir,{recursive:!0});let f=`pack-${a}`,l=I(this.packDir,`${f}.pack`);await this.fs.writeFile(l,t);let d=await wl(t),u=I(this.packDir,`${f}.idx`);await this.fs.writeFile(u,d),this.loadedPackNames.add(f);let m=new gn(d);return this.packs.push({name:f,index:m,reader:new Ms(t,m)}),o}async ingestPackStream(t){let n=[];for await(let s of t)n.push(s);if(n.length===0)return 0;let r=await ul(n);return this.ingestPack(r)}invalidatePacks(){this.packs=[],this.loadedPackNames.clear(),this.discoverPromise=null,this.cache.clear()}async findByPrefix(t){if(t.length<4)return[];let n=t.slice(0,2),r=t.slice(2),s=I(this.gitDir,"objects",n),o=[];if(await this.fs.exists(s)){let i=await this.fs.readdir(s);for(let a of i)a.startsWith(r)&&o.push(`${n}${a}`)}await this.discover();for(let i of this.packs)for(let a of i.index.findByPrefix(t))o.includes(a)||o.push(a);return o}async ensureReader(t){if(t.reader)return t.reader;let n=I(this.packDir,`${t.name}.pack`),r=await this.fs.readFileBuffer(n);return t.reader=new Ms(r,t.index),t.reader}discover(){return this.discoverPromise||(this.discoverPromise=this.doDiscover()),this.discoverPromise}async doDiscover(){if(!await this.fs.exists(this.packDir))return;let t=await this.fs.readdir(this.packDir);for(let n of t){if(!n.endsWith(".idx"))continue;let r=n.slice(0,-4);if(this.loadedPackNames.has(r))continue;let s=I(this.packDir,`${r}.pack`);if(!await this.fs.exists(s))continue;let o=await this.fs.readFileBuffer(I(this.packDir,n));this.loadedPackNames.add(r),this.packs.push({name:r,index:new gn(o),reader:null})}}}});function Ls(e){let t=e.indexOf("<"),n=e.indexOf(">");if(t===-1||n===-1)throw new Error(`Malformed identity line: "${e}"`);let r=e.slice(0,t).trimEnd(),s=e.slice(t+1,n),o=e.slice(n+2),[i="0",a="+0000"]=o.split(" "),c=parseInt(i,10);return{name:r,email:s,timestamp:c,timezone:a}}function Gs(e){return`${e.name} <${e.email}> ${e.timestamp} ${e.timezone}`}var Ma=we(()=>{"use strict"});function en(e){let t=op.decode(e),n=t.indexOf(` ++ ++`),r=n===-1?t:t.slice(0,n),s=n===-1?"":t.slice(n+2),o="",i=[],a,c;for(let f of r.split(` ++`)){let l=f.indexOf(" ");if(l===-1)continue;let d=f.slice(0,l),u=f.slice(l+1);switch(d){case"tree":o=u;break;case"parent":i.push(u);break;case"author":a=Ls(u);break;case"committer":c=Ls(u);break}}if(!o)throw new Error("Commit missing tree field");if(!a)throw new Error("Commit missing author field");if(!c)throw new Error("Commit missing committer field");return{type:"commit",tree:o,parents:i,author:a,committer:c,message:s}}function $n(e){let t=[];t.push(`tree ${e.tree}`);for(let n of e.parents)t.push(`parent ${n}`);return t.push(`author ${Gs(e.author)}`),t.push(`committer ${Gs(e.committer)}`),t.push(""),t.push(e.message),sp.encode(t.join(` ++`))}var sp,op,On=we(()=>{"use strict";Ma();sp=new TextEncoder,op=new TextDecoder});function Lt(e){let t=ap.decode(e),n=t.indexOf(` ++ ++`),r=n===-1?t:t.slice(0,n),s=n===-1?"":t.slice(n+2),o="",i="commit",a="",c;for(let f of r.split(` ++`)){let l=f.indexOf(" ");if(l===-1)continue;let d=f.slice(0,l),u=f.slice(l+1);switch(d){case"object":o=u;break;case"type":i=u;break;case"tag":a=u;break;case"tagger":c=Ls(u);break}}if(!o)throw new Error("Tag missing object field");if(!a)throw new Error("Tag missing tag name field");if(!c)throw new Error("Tag missing tagger field");return{type:"tag",object:o,objectType:i,name:a,tagger:c,message:s}}function El(e){let t=[];return t.push(`object ${e.object}`),t.push(`type ${e.objectType}`),t.push(`tag ${e.name}`),t.push(`tagger ${Gs(e.tagger)}`),t.push(""),t.push(e.message),ip.encode(t.join(` ++`))}var ip,ap,Ar=we(()=>{"use strict";Ma();ip=new TextEncoder,ap=new TextDecoder});async function sr(e,t){return nr(Ha(e,t))}async function De(e,t,n){let r=await e.objectStore.write(t,n);return e.hooks?.onObjectWrite?.({repo:e,type:t,hash:r}),r}async function me(e,t){return e.objectStore.read(t)}async function tn(e,t){return e.objectStore.exists(t)}async function No(e,t){return e.objectStore.ingestPack(t)}async function Uo(e,t){return e.objectStore.findByPrefix(t)}function Fe(e){let t=Math.min(e.length,8e3);for(let n=0;n{"use strict";Da();On();Ar();Sr();cp=new TextDecoder});function Hr(e){return e.includes("/")?e.startsWith("refs/bisect/")||e.startsWith("refs/worktree/")||e.startsWith("refs/rewritten/"):e===e.toUpperCase()}var ja=we(()=>{"use strict"});function Rl(e){return typeof e=="string"?{type:"direct",hash:e}:e}var ht,Bo=we(()=>{"use strict";ht={REGULAR:"100644",EXECUTABLE:"100755",SYMLINK:"120000",DIRECTORY:"040000",SUBMODULE:"160000"}});function lp(e,t,n){let r=0,s=!1,o=t;for(;o=La.length&&e.slice(o-La.length,o)===La?{len:-1,starConsumed:s}:{len:i,starConsumed:s}}function Fs(e,t=0){if(e==="@"||e.length===0)return!1;let n=0,r=0,s=!!(t&2);for(;n<=e.length;){let{len:o,starConsumed:i}=lp(e,n,s);if(o<0||o===0)return!1;i&&(s=!1),r++,n+=o+1}return!(e.charCodeAt(e.length-1)===46||!(t&1)&&r<2)}function Fn(e){return!e||e.startsWith("-")?!1:Fs(`refs/heads/${e}`,0)}function Cl(e){return e?Fs(`refs/tags/${e}`,0):!1}async function Pl(e,t){return e.refStore.readRef(t)}async function z(e,t){let n=t;for(let r=0;rf.name==="HEAD");if(!s)return;let o;if(r?.startsWith("refs/heads/"))o=r.slice(11);else{let f=n.find(l=>l.name.startsWith("refs/heads/")&&l.hash===s.hash);if(!f)return;o=f.name.slice(11)}let i=`refs/remotes/${t}/HEAD`;if(await e.refStore.readRef(i))return;let c=`refs/remotes/${t}/${o}`;await e.refStore.writeRef(i,{type:"symbolic",target:c})}async function Ee(e,t){let n=e.hooks?await z(e,t):null;await e.refStore.deleteRef(t),await Us(e,t),e.hooks&&n&&e.hooks.onRefDelete?.({repo:e,ref:t,oldHash:n})}async function $e(e,t="refs"){return e.refStore.listRefs(t)}function ve(e){return e.replace("refs/heads/","")}function nn(e){return e.startsWith("refs/heads/")?e.slice(11):e.startsWith("refs/tags/")?e.slice(10):e.startsWith("refs/remotes/")?e.slice(13):e}async function or(e,t){let n=await ne(e);n&&n.type==="symbolic"?await Q(e,n.target,t):await Q(e,"HEAD",t)}async function $l(e){if(e.refStore&&!(e.refStore instanceof $t))return;let t=(await $e(e,"refs")).filter(o=>!Hr(o.name));if(t.length===0)return;let n=["# pack-refs with: peeled fully-peeled sorted"],r=[];for(let o of t){let i=I(e.commonDir,o.name);if(!(await e.fs.exists(i)&&(await e.fs.readFile(i)).trim().startsWith("ref: "))&&(r.push(o.name),n.push(`${o.hash} ${o.name}`),o.name.startsWith("refs/tags/")))try{let a=await me(e,o.hash);if(a.type==="tag"){let c=Lt(a.content).object;for(let f=0;f<100;f++){let l=await me(e,c);if(l.type!=="tag")break;c=Lt(l.content).object}n.push(`^${c}`)}}catch{}}await e.fs.writeFile(I(e.commonDir,"packed-refs"),`${n.join(` ++`)} ++`);for(let o of r){let i=I(e.commonDir,o);await e.fs.exists(i)&&await e.fs.rm(i)}await Ol(e,I(e.commonDir,"refs"));let s=I(e.commonDir,"refs");await e.fs.mkdir(s,{recursive:!0}),await e.fs.mkdir(I(s,"heads"),{recursive:!0}),await e.fs.mkdir(I(s,"tags"),{recursive:!0})}async function Ol(e,t){if(e.refStore&&!(e.refStore instanceof $t)||!await e.fs.exists(t)||!(await e.fs.stat(t)).isDirectory)return;let r=await e.fs.readdir(t);for(let o of r)await Ol(e,I(t,o));(await e.fs.readdir(t)).length===0&&await e.fs.rm(t,{recursive:!0})}var La,fp,Ga,xl,$t,ye=we(()=>{"use strict";ie();Ar();ge();ja();Xe();Nn();Bo();La=".lock",fp=[1,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,0,0,0,0,0,0,0,0,0,5,0,0,0,2,1,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,4,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,4,4];Ga="ref: ",xl=10,$t=class{constructor(t,n,r){this.fs=t;this.gitDir=n;this.commonDir=r??n}casLocks=new Map;commonDir;dirFor(t){return Hr(t)?this.gitDir:this.commonDir}async readRef(t){let n=I(this.dirFor(t),t);if(await this.fs.exists(n)){let o=(await this.fs.readFile(n)).trim();return o.startsWith(Ga)?{type:"symbolic",target:o.slice(Ga.length)}:{type:"direct",hash:o}}if(Hr(t))return null;let s=(await this.readPackedRefs()).get(t);return s?{type:"direct",hash:s}:null}async writeRef(t,n){let r=Rl(n),s=I(this.dirFor(t),t);await Ns(this.fs,s),r.type==="symbolic"?await this.fs.writeFile(s,`${Ga}${r.target} ++`):await this.fs.writeFile(s,`${r.hash} ++`)}async deleteRef(t){let n=I(this.dirFor(t),t);await this.fs.exists(n)&&await this.fs.rm(n),await this.removePackedRef(t)}async listRefs(t="refs"){let n=[],r=new Set,s=async i=>{let a=I(i,t);if(!await this.fs.exists(a))return;let c=[];await this.walkRefs(a,t,c);for(let f of c)this.dirFor(f.name)===i&&(r.has(f.name)||(r.add(f.name),n.push(f)))};await s(this.commonDir),this.gitDir!==this.commonDir&&await s(this.gitDir);let o=await this.readPackedRefs();if(o.size>0){let i=`${t}/`;for(let[a,c]of o)Hr(a)||a.startsWith(i)&&!r.has(a)&&(r.add(a),n.push({name:a,hash:c}))}return n.sort((i,a)=>i.namea.name?1:0)}async compareAndSwapRef(t,n,r){let o=(this.casLocks.get(t)??Promise.resolve(!1)).then(()=>this.compareAndSwapUnsafe(t,n,r),()=>this.compareAndSwapUnsafe(t,n,r));this.casLocks.set(t,o);try{return await o}finally{this.casLocks.get(t)===o&&this.casLocks.delete(t)}}async compareAndSwapUnsafe(t,n,r){let s=await this.resolveRefInternal(t);if(n===null){if(await this.readRef(t)!==null)return!1}else if(s!==n)return!1;return r===null?await this.deleteRef(t):await this.writeRef(t,r),!0}async resolveRefInternal(t){let n=t;for(let r=0;rc&&!c.startsWith("#")&&!c.startsWith("^"))?await this.fs.writeFile(n,o.join(` ++`)):await this.fs.rm(n)}async walkRefs(t,n,r){let s=await this.fs.readdir(t);for(let o of s){let i=I(t,o),a=`${n}/${o}`,c=await this.fs.stat(i);if(c.isDirectory)await this.walkRefs(i,a,r);else if(c.isFile){let f=await this.resolveRefInternal(a);f&&r.push({name:a,hash:f})}}}}});async function Un(e,t){let n=t;for(;;){let r=I(n,".git");if(await e.exists(r)){let o=await e.stat(r);if(o.isDirectory)return Fa(e,r,r,n);if(o.isFile){let i=await dp(e,r,n);return i?Fa(e,i.gitDir,i.commonDir,n):null}}if(await up(e,n))return Fa(e,n,n,null);let s=mp(n);if(s===n)return null;n=s}}function Fa(e,t,n,r){return{fs:e,gitDir:t,commonDir:n,workTree:r,objectStore:new js(e,n),refStore:new $t(e,t,n)}}async function dp(e,t,n){let r=(await e.readFile(t)).trim(),s="gitdir:";if(!r.startsWith(s))return null;let o=r.slice(s.length).trim();if(!o)return null;let i=Je(n,o);if(!await e.exists(i))return null;let a=I(i,"commondir");if(!await e.exists(a))return{gitDir:i,commonDir:i};let c=(await e.readFile(a)).trim();return{gitDir:i,commonDir:c?Je(i,c):i}}async function up(e,t){let n=I(t,"HEAD");if(!await e.exists(n))return!1;try{if(!(await e.stat(n)).isFile)return!1}catch{return!1}for(let r of["objects","refs"]){let s=I(t,r);if(!await e.exists(s))return!1;try{if(!(await e.stat(s)).isDirectory)return!1}catch{return!1}}return!0}async function Wo(e,t,n={}){let{bare:r=!1,initialBranch:s="main"}=n,o=r?t:I(t,".git"),i=r?null:t,a=I(o,"HEAD"),c=await e.exists(a);await e.mkdir(I(o,"objects"),{recursive:!0}),await e.mkdir(I(o,"refs","heads"),{recursive:!0}),await e.mkdir(I(o,"refs","tags"),{recursive:!0});let f={fs:e,gitDir:o,commonDir:o,workTree:i,objectStore:new js(e,o),refStore:new $t(e,o)};if(!c){await ct(f,"HEAD",`refs/heads/${s}`);let l={core:{repositoryformatversion:"0",filemode:"true",bare:r?"true":"false",...r?{}:{logallrefupdates:"true"}}};await e.writeFile(I(o,"config"),pa(l))}return{ctx:f,reinit:c}}async function Ns(e,t){let n=t.lastIndexOf("/");if(n>0){let r=t.slice(0,n);await e.mkdir(r,{recursive:!0})}}function mp(e){let t=e.lastIndexOf("/");return t<=0?"/":e.slice(0,t)}var Nn=we(()=>{"use strict";We();Da();ge();ye()});function ss(e,t){let n=Hr(t)?e.gitDir:e.commonDir;return I(n,"logs",t)}function hp(e){let t=e.indexOf(" ");if(t<0)return null;let n=e.slice(0,t),r=e.slice(t+1),s=n.split(" ");if(s.length<5)return null;let o=s[0],i=s[1];if(!o||!i)return null;let a=n.indexOf("<"),c=n.indexOf(">",a);if(a<0||c<0)return null;let f=n.slice(o.length+1+i.length+1,a).trim(),l=n.slice(a+1,c),d=n.slice(c+2),u=d.indexOf(" ");if(u<0)return null;let m=parseInt(d.slice(0,u),10),h=d.slice(u+1);return{oldHash:o,newHash:i,name:f,email:l,timestamp:m,tz:h,message:r}}async function Tt(e,t){return _s(e.fs,ss(e,t))}async function _s(e,t){if(!await e.exists(t))return[];let n=await e.readFile(t);if(!n.trim())return[];let r=[];for(let s of n.split(` ++`)){if(!s)continue;let o=hp(s);o&&r.push(o)}return r}function Sl(e){return`${e.oldHash} ${e.newHash} ${e.name} <${e.email}> ${e.timestamp} ${e.tz} ${e.message}`}async function os(e,t,n){return Na(e.fs,ss(e,t),n)}async function Na(e,t,n){if(await Ns(e,t),n.length===0){await e.writeFile(t,"");return}await e.writeFile(t,`${n.map(Sl).join(` ++`)} ++`)}async function st(e,t,n){let r=ss(e,t);await Ns(e.fs,r);let s=`${Sl(n)} ++`;if(await e.fs.exists(r)){let o=await e.fs.readFile(r);await e.fs.writeFile(r,o+s)}else await e.fs.writeFile(r,s)}async function Us(e,t){let n=ss(e,t);await e.fs.exists(n)&&await e.fs.rm(n)}async function ee(e,t,n,r,s,o,i=!1){let a=await Jn(e,t),c={oldHash:r??se,newHash:s,...a,message:o};await st(e,n,c),i&&n!=="HEAD"&&await st(e,"HEAD",c)}var Xe=we(()=>{"use strict";It();$r();ge();ja();Nn();It()});function pp(e){let t=[],n=e.length;for(;n>0;){let o=e.slice(0,n).match(/^(.+?)~(\d*)$/);if(o&&o[1]!==void 0&&o[2]!==void 0){let c=o[2]===""?1:parseInt(o[2],10);t.unshift({type:"tilde",n:c}),n=o[1].length;continue}let i=e.slice(0,n).match(/^(.+?)\^{([^}]*)}$/);if(i&&i[1]!==void 0&&i[2]!==void 0){t.unshift({type:"peel",target:i[2]}),n=i[1].length;continue}let a=e.slice(0,n).match(/^(.+?)\^(\d*)$/);if(a&&a[1]!==void 0&&a[2]!==void 0){let c=a[2]===""?1:parseInt(a[2],10);t.unshift({type:"caret",n:c}),n=a[1].length;continue}break}let r=e.slice(0,n),s=r.match(/^(.+?)@\{(\d+)\}$/);return s&&s[1]!==void 0&&s[2]!==void 0?{base:s[1],reflogIndex:parseInt(s[2],10),suffixes:t}:{base:r,suffixes:t}}async function gp(e,t){let n=await Uo(e,t);if(n.length===0)return null;if(n.length>1)throw new Ua(t);return n[0]}async function wp(e,t){if(t==="HEAD"||t==="@")return z(e,"HEAD");if(vl.includes(t))return z(e,t);if(/^[0-9a-f]{40}$/.test(t))return await tn(e,t)?t:null;if(/^[0-9a-f]{4,39}$/.test(t)){let o=await gp(e,t);if(o)return o}if(t.startsWith("refs/")){let o=await z(e,t);if(o)return o}let n=await z(e,`refs/heads/${t}`);if(n)return n;let r=await z(e,`refs/tags/${t}`);if(r)return r;let s=await z(e,`refs/remotes/${t}`);return s||null}function bp(e){if(e==="HEAD"||e==="@")return"HEAD";for(let t of vl)if(e===t)return t;return e.startsWith("refs/")?e:`refs/heads/${e}`}async function yp(e,t,n){let r=bp(t),s=await Tt(e,r);if(s.length===0)return null;let o=s.length-1-n;if(o<0||o>=s.length)return null;let i=s[o];return i?i.newHash:null}async function kp(e,t,n){if(n===""||n==="commit")try{return await Oe(e,t)}catch{return null}if(n==="tree"){let s;try{s=await Oe(e,t)}catch{return null}return(await M(e,s)).tree}return(await me(e,t)).type!==n?null:t}async function Ep(e,t,n){let r=t;n.some(o=>o.type==="tilde"||o.type==="caret")&&(r=await Oe(e,r));for(let o of n)if(o.type==="peel"){if(!r)return null;r=await kp(e,r,o.target)}else if(o.type==="tilde")for(let i=0;ii.parents.length||(r=i.parents[o.n-1]??null,!r))return null}return r}async function Ie(e,t){let{base:n,reflogIndex:r,suffixes:s}=pp(t),o;return r!==void 0?o=await yp(e,n,r):o=await wp(e,n),o?Ep(e,o,s):null}function qo(e){let t=e.indexOf(":");return t<0?null:{rev:e.slice(0,t)||"HEAD",path:e.slice(t+1)}}var vl,Ua,Ft=we(()=>{"use strict";ie();Xe();ye();vl=["HEAD","FETCH_HEAD","ORIG_HEAD","MERGE_HEAD","CHERRY_PICK_HEAD","REBASE_HEAD"];Ua=class extends Error{constructor(n){super(`short object ID ${n} is ambiguous`);this.prefix=n}}});function xp(e){return e.length===4&&e.toLowerCase()===".git"}function Pp(e,t){if(e.length===0)throw new Error("invalid tree entry: empty name");if(e.includes("/"))throw new Error(`invalid tree entry: name contains slash: '${e}'`);if(e.includes("\0"))throw new Error("invalid tree entry: name contains null byte");if(e==="."||e==="..")throw new Error(`invalid tree entry: '${e}'`);if(xp(e))throw new Error(`invalid tree entry: '${e}'`);if(!Cp.has(t))throw new Error(`invalid tree entry mode: '${t}' for '${e}'`)}function bn(e){let t=[],n=0;for(;no+i.byteLength,0),r=new Uint8Array(n),s=0;for(let o of t)r.set(o,s),s+=o.byteLength;return r}var Rp,Il,Cp,Bs=we(()=>{"use strict";It();Rp=new TextEncoder,Il=new TextDecoder,Cp=new Set(["100644","100755","040000","120000","160000"])});async function Ze(e,t){return Al(e,t,"")}async function Al(e,t,n){let r=[],s=new Map;for(let i of t){let a=n?i.path.slice(n.length+1):i.path,c=a.indexOf("/");if(c===-1)r.push({mode:$p(i.mode),name:a,hash:i.hash});else{let f=a.slice(0,c),l=s.get(f);l||(l=[],s.set(f,l)),l.push(i)}}for(let[i,a]of s){let c=n?`${n}/${i}`:i,f=await Al(e,a,c);r.push({mode:ht.DIRECTORY,name:i,hash:f})}r.sort((i,a)=>{let c=i.mode===ht.DIRECTORY?`${i.name}/`:i.name,f=a.mode===ht.DIRECTORY?`${a.name}/`:a.name;return cf?1:0});let o=Tl({type:"tree",entries:r});return De(e,"tree",o)}async function Ke(e,t,n=""){let r=await me(e,t);if(r.type!=="tree")throw new Error(`Expected tree object, got ${r.type}`);let s=bn(r.content),o=[];for(let i of s.entries){let a=n?`${n}/${i.name}`:i.name;if(i.mode===ht.DIRECTORY){let c=await Ke(e,i.hash,a);o.push(...c)}else o.push({path:a,mode:i.mode,hash:i.hash})}return o}async function de(e,t){if(!t)return new Map;let n=await Ke(e,t);return new Map(n.map(r=>[r.path,r]))}async function Ve(e,t,n){if(t===n)return[];let r=[];return await Hl(e,t,n,"",r),r.sort((s,o)=>Ae(s.path,o.path))}async function Ko(e,t){let n=await me(e,t);if(n.type!=="tree")throw new Error(`Expected tree object, got ${n.type}`);return bn(n.content).entries}async function Hl(e,t,n,r,s){if(t===n)return;let o=t?await Ko(e,t):[],i=n?await Ko(e,n):[],a=new Map;for(let l of o)a.set(l.name,l);let c=new Map;for(let l of i)c.set(l.name,l);let f=new Set;for(let l of o)f.add(l.name);for(let l of i)f.add(l.name);for(let l of f){let d=a.get(l),u=c.get(l),m=r?`${r}/${l}`:l;if(d&&u){if(d.hash===u.hash&&d.mode===u.mode)continue;let h=d.mode===ht.DIRECTORY,p=u.mode===ht.DIRECTORY;h&&p?await Hl(e,d.hash,u.hash,m,s):h?(await zo(e,d.hash,m,"deleted",s),s.push({path:m,status:"added",newHash:u.hash,newMode:u.mode})):p?(s.push({path:m,status:"deleted",oldHash:d.hash,oldMode:d.mode}),await zo(e,u.hash,m,"added",s)):s.push({path:m,status:"modified",oldHash:d.hash,newHash:u.hash,oldMode:d.mode,newMode:u.mode})}else if(d)d.mode===ht.DIRECTORY?await zo(e,d.hash,m,"deleted",s):s.push({path:m,status:"deleted",oldHash:d.hash,oldMode:d.mode});else{let h=u;h.mode===ht.DIRECTORY?await zo(e,h.hash,m,"added",s):s.push({path:m,status:"added",newHash:h.hash,newMode:h.mode})}}}async function zo(e,t,n,r,s){let o=await Ke(e,t,n);for(let i of o)r==="added"?s.push({path:i.path,status:"added",newHash:i.hash,newMode:i.mode}):s.push({path:i.path,status:"deleted",oldHash:i.hash,oldMode:i.mode})}function $p(e){return e.toString(8).padStart(6,"0")}var Te=we(()=>{"use strict";te();ie();Bs();Bo()});function Ws(e){let t=Dl.get(e);return t||(t=vp(e),Dl.set(e,t)),t}async function vp(e){let t=(await Re(e,"core.autocrlf"))?.toLowerCase();return t==="true"||t==="yes"||t==="on"||t==="1"?{clean:!0,smudgeCrlf:!0}:t==="input"?{clean:!0,smudgeCrlf:!1}:Sp}function Ml(e){for(let t=e.indexOf(13);t!==-1;t=e.indexOf(13,t+1))if(e[t+1]===10)return!0;return!1}function jl(e){return e.indexOf(13)!==-1}function _a(e){if(!Ml(e))return e;let t=new Uint8Array(e.byteLength),n=0,r=0;for(let s=e.indexOf(13);s!==-1;s=e.indexOf(13,s+1))e[s+1]===10&&(t.set(e.subarray(r,s),n),n+=s-r,r=s+1);return t.set(e.subarray(r),n),n+=e.byteLength-r,t.subarray(0,n)}function Ll(e){if(e.indexOf(10)===-1||jl(e)||wn(e))return e;let t=0;for(let s=0;s{"use strict";We();ie();un();Op=new TextEncoder,Sp={clean:!1,smudgeCrlf:!1},Dl=new WeakMap});function Nl(e){return/^[a-zA-Z0-9]$/.test(e)}function Tp(e){return/^[a-zA-Z]$/.test(e)}function Ap(e){return e>="0"&&e<="9"}function Wa(e){return e>="A"&&e<="Z"}function qa(e){return e>="a"&&e<="z"}function Ul(e){return/^\s$/.test(e)}function Hp(e){return e===" "||e===" "}function Ka(e){let t=e.charCodeAt(0);return t>=32&&t<=126}function Dp(e){return Ka(e)&&!Ul(e)}function Mp(e){return Ka(e)&&!Nl(e)&&e!==" "}function jp(e){let t=e.charCodeAt(0);return t<32||t===127}function Lp(e){return/^[0-9a-fA-F]$/.test(e)}function zs(e,t,n){return n?e.toLowerCase()===t.toLowerCase():e===t}function za(e,t,n,r,s){let o=(s&1)!==0,i=(s&2)!==0;for(;t=n.length&&a!=="*")return-1;let c=r=e.length)return-1;if(!zs(n[r],e[t],o))return 1;r++,t++;break}case"?":{if(i&&c==="/")return 1;r++,t++;break}case"*":{let f;if(t++,t=e.length||e[t]==="/"||e[t]==="\\"&&t+1=e.length)return!f&&n.indexOf("/",r)!==-1?-2:0;if(!f&&e[t]==="/"){let l=n.indexOf("/",r);if(l===-1)return-1;r=l+1,t++;break}for(;!(r>=n.length);){if(!Gp(e[t])){let d=o?e[t].toLowerCase():e[t];for(;r=n.length||!f&&n[r]==="/")return r=e.length)return-1;let f=!1;(e[t]==="!"||e[t]==="^")&&(f=!0,t++);let l=!1,d="",u=!0;for(;t=e.length)return-1;m=e[t],zs(c,m,o)&&(l=!0)}else if(m==="-"&&d&&t+1=e.length)return-1;m=e[t]}let h=d,p=m;if(c>=h&&c<=p&&(l=!0),o){if(qa(c)){let g=c.toUpperCase();g>=h&&g<=p&&(l=!0)}else if(Wa(c)){let g=c.toLowerCase();g>=h&&g<=p&&(l=!0)}}m=""}else if(m==="["&&t+1=e.length)return-1;let p=t-h-1;if(p<0||e[t-1]!==":")t=h-2,m="[",zs(c,m,o)&&(l=!0);else{let g=e.slice(h,h+p);Fp(g,c,o)&&(l=!0),m=""}}else zs(c,m,o)&&(l=!0);d=m,t++}if(t>=e.length)return-1;if(t++,l===f)return 1;r++;break}default:{if(!zs(c,a,o))return 1;r++,t++;break}}}return r>=n.length?0:1}function Gp(e){return e==="*"||e==="?"||e==="["||e==="\\"}function Fp(e,t,n){switch(e){case"alnum":return Nl(t);case"alpha":return Tp(t);case"blank":return Hp(t);case"cntrl":return jp(t);case"digit":return Ap(t);case"graph":return Dp(t);case"lower":return qa(t)||n&&Wa(t);case"print":return Ka(t);case"punct":return Mp(t);case"space":return Ul(t);case"upper":return Wa(t)||n&&qa(t);case"xdigit":return Lp(t);default:return!1}}function Sn(e,t,n=0){return za(e,0,t,0,n)===0?0:1}var Ks=we(()=>{"use strict"});function ql(e){for(let t=0;t0;){let c=n[n.length-1];if(c===" "||c===" "){if(n.length>=2&&n[n.length-2]==="\\"){n=n.slice(0,n.length-2)+n[n.length-1];break}n=n.slice(0,-1)}else break}if(n.length===0||n[0]==="#")return null;let r=0,s=n;if(s[0]==="!"&&(r|=Vo,s=s.slice(1)),s.length===0)return null;let o=s.length;s[o-1]==="/"&&(o--,s=s.slice(0,o),r|=Wl);let i=!1;for(let c=0;c=i.length&&e.endsWith(i)}return Sn(n,e,2)===0}function Bp(e,t){let{base:n}=t,{pattern:r,patternLen:s,nowildcardLen:o}=t;r[0]==="/"&&(r=r.slice(1),s--,o=Math.max(0,o-1));let i=n.length;if(i>0&&(e.length0?e.slice(i+1):e,c=a.length;if(o>0){if(o>c||a.slice(0,o)!==r.slice(0,o))return!1;if(s===o&&c===o)return!0}return Sn(r,a,2)===0}function Va(e,t,n){let r=e.lastIndexOf("/")>=0?e.slice(e.lastIndexOf("/")+1):e;for(let s=n.patterns.length-1;s>=0;s--){let o=n.patterns[s];if(o&&!(o.flags&Wl&&!t)){if(o.flags&_l){if(o.base&&!e.startsWith(`${o.base}/`))continue;if(_p(r,o))return o;continue}if(Bp(e,o))return o}}return null}function vn(e,t,n){for(let r=e.dirPatterns.length-1;r>=0;r--){let s=e.dirPatterns[r],o=Va(t,n,s);if(o)return o.flags&Vo?"not-ignored":"ignored"}if(e.excludeFile){let r=Va(t,n,e.excludeFile);if(r)return r.flags&Vo?"not-ignored":"ignored"}if(e.globalExclude){let r=Va(t,n,e.globalExclude);if(r)return r.flags&Vo?"not-ignored":"ignored"}return"undecided"}async function is(e){let t={dirPatterns:[],excludeFile:null,globalExclude:null},n=I(e.gitDir,"info","exclude");try{let r=await e.fs.readFile(n);t.excludeFile=Vs(r,"",n)}catch{}try{let r=await Re(e,"core.excludesFile");if(r)try{let s=await e.fs.readFile(r);t.globalExclude=Vs(s,"",r)}catch{}}catch{}return t}function Dr(e,t,n,r){let o=Vs(t,n===""?"":n,r);return{...e,dirPatterns:[...e.dirPatterns,o]}}var _l,Bl,Wl,Vo,Xo=we(()=>{"use strict";We();ge();Ks();_l=1,Bl=4,Wl=8,Vo=16});async function pt(e,t,n){if(!e.workTree)throw new Error("Cannot diff working tree in a bare repository");let r=n?.includeUntracked??!0,s=n?.stopAfterFirst??!1,o=n?.pathFilter,i=Nf(t),a=[];for(let l of t.entries){if(l.stage!==0||Jt(l.mode)||o&&!o(l.path))continue;let d=I(e.workTree,l.path),u;try{u=await Ye(e.fs,d)}catch{u=null}if(!u){if(a.push({path:l.path,status:"deleted",indexHash:l.hash}),s)return a;continue}if(!u.isFile&&!u.isSymbolicLink){if(a.push({path:l.path,status:"deleted",indexHash:l.hash}),s)return a;continue}if(_f(e.fs,l,u,i))continue;let m=Tr(e.fs,l,u),h=await Ot(e,d,l.hash,u);if((h!==l.hash||m!==l.mode)&&(a.push({path:l.path,status:"modified",indexHash:l.hash,worktreeHash:h,worktreeMode:m}),s))return a}if(!r)return a.sort((l,d)=>Ae(l.path,d.path));let c=new Set(t.entries.map(l=>l.path)),f=await gt(e,e.workTree,"",{stopAfterFirst:s,_fileFilter:l=>!c.has(l)&&(!o||o(l))});for(let l of f)a.push({path:l,status:"untracked"});return s?a:a.sort((l,d)=>Ae(l.path,d.path))}async function lt(e,t){if(!e.workTree)throw new Error("Cannot checkout in a bare repository");if(!Or(t.path))throw new Error(`refusing to check out unsafe path '${t.path}'`);if(t.mode!=null&&Jt(t.mode)){let o=I(e.workTree,t.path);await e.fs.mkdir(o,{recursive:!0});return}let n=await me(e,t.hash);if(n.type!=="blob")throw new Error(`Expected blob for ${t.path}, got ${n.type}`);let r=I(e.workTree,t.path);if(!To(e.workTree,r))throw new Error(`refusing to check out path outside worktree: '${t.path}'`);let s=r.lastIndexOf("/");if(s>0&&await e.fs.mkdir(r.slice(0,s),{recursive:!0}),t.mode!=null&&dn(t.mode)&&e.fs.symlink){let o=qp.decode(n.content);if(!Tf(o))throw new Error(`refusing to create symlink with unsafe target '${o}'`);await Ye(e.fs,r).then(()=>!0).catch(()=>!1)&&await e.fs.rm(r,{force:!0}),await e.fs.symlink(o,r)}else{let o=null;try{let c=await Ye(e.fs,r);c.isSymbolicLink?await e.fs.rm(r,{force:!0}):o=c.mode}catch{}let a=(await Ws(e)).smudgeCrlf?Ll(n.content):n.content;await e.fs.writeFile(r,a),e.fs.chmod&&(t.mode!=null&&Hf(t.mode)?await e.fs.chmod(r,493):o!==null&&o&73&&await e.fs.chmod(r,420))}}async function zl(e,t){let n=await Ke(e,t);for(let r of n)await lt(e,r)}async function In(e,t,n){if(!e.workTree)throw new Error("Cannot stage in a bare repository");if(!Or(n))throw new Error(`refusing to stage unsafe path '${n}'`);let r=I(e.workTree,n);if(!await e.fs.exists(r))throw new Error(`Path does not exist: ${n}`);let s=await Ye(e.fs,r);if(s.isSymbolicLink&&e.fs.readlink){let l=await e.fs.readlink(r),d=Wp.encode(l),u=await De(e,"blob",d),m={path:n,mode:40960,hash:u,stage:0,stat:Do(s,d.byteLength)};return{index:jt(t,m),hash:u}}let o=Zr(t,n),i=await e.fs.readFileBuffer(r),a=await qs(e,i,o?.hash),c=await De(e,"blob",a),f={path:n,mode:Tr(e.fs,o,s),hash:c,stage:0,stat:Do(s,i.byteLength)};return{index:jt(t,f),hash:c}}async function gt(e,t,n,r){let s=r?.skipIgnore??!1,o=r?.stopAfterFirst??!1,i=r?._fileFilter,a=null;if(!s){a=r?._ignore??await is(e);let l=I(t,".gitignore");try{let d=await e.fs.readFile(l);a=Dr(a,d,n,l)}catch{}}let c=[],f=await e.fs.readdir(t);for(let l of f){if(n===""&&l===".git")continue;let d=I(t,l),u=n?`${n}/${l}`:l,m=await Ye(e.fs,d);if(m.isSymbolicLink){if(a&&vn(a,u,!1)==="ignored")continue;(!i||i(u))&&c.push(u)}else if(m.isDirectory){if(a&&vn(a,u,!0)==="ignored")continue;let h=await gt(e,d,u,{skipIgnore:s,stopAfterFirst:o,_ignore:a??void 0,_fileFilter:i});c.push(...h)}else if(m.isFile){if(a&&vn(a,u,!1)==="ignored")continue;(!i||i(u))&&c.push(u)}if(o&&c.length>0)break}return c}async function Mr(e,t,n){if(t===n||t==="/"||!t.startsWith(n)||!await e.exists(t)||!(await e.stat(t)).isDirectory)return;(await e.readdir(t)).length===0&&(await e.rm(t,{recursive:!0}),await Mr(e,Et(t),n))}var Wp,qp,ot=we(()=>{"use strict";te();ir();Xo();Se();ie();Ao();ge();un();Te();Wp=new TextEncoder,qp=new TextDecoder});function Ya(e){return e.existsOnDisk&&e.indexHash===null}async function zp(e,t,n){let r=await Promise.all(t.map(h=>de(e,h.treeHash))),s=new Map,o=new Set;for(let h of n.entries)h.stage===0?s.set(h.path,h):o.add(h.path);let i=e.workTree?new Set(await gt(e,e.workTree,"",{skipIgnore:!0})):new Set,a=null,c=async()=>(a===null&&(a=e.workTree?new Set(await gt(e,e.workTree,"")):new Set),a),f=new Set;for(let h of r)for(let p of h.keys())f.add(p);let l=new Set;for(let h of n.entries)f.has(h.path)||l.add(h.path);for(let h of i)f.has(h)||l.add(h);let d=Array.from(f).sort().concat(Array.from(l).sort()),u=(h,p)=>r[h]?.get(p),m=[];for(let h of d){let p=null,g=null,w=null,b=null,y=null;if(r.length===1){let L=u(0,h);w=L?.hash??null,y=L?.mode??null}else if(r.length===2){let L=u(0,h),A=u(1,h);g=L?.hash??null,b=L?.mode??null,w=A?.hash??null,y=A?.mode??null}else if(r.length>=3){let L=u(0,h),A=u(1,h),H=u(2,h);p=L?.hash??null,g=A?.hash??null,b=A?.mode??null,w=H?.hash??null,y=H?.mode??null}let C=s.get(h),x=C?.hash??null,k=C?.mode??null,P=o.has(h)?1:0,E=i.has(h),R,O=async()=>R!==void 0?R:E?(R=!(await c()).has(h),R):(R=!1,!1),$,T=async()=>($!==void 0||($=E&&e.workTree?await Ye(e.fs,I(e.workTree,h)).catch(()=>null):null),$),j,U=async()=>{if(j!==void 0)return j;let L=await T();if(!L||!e.workTree)return j=null,null;let A=I(e.workTree,h);try{j=await Ot(e,A,x??void 0,L)}catch{j=null}return j},G=async()=>{let L=await T();return L?Tr(e.fs,C,L):null};m.push({path:h,baseHash:p,headHash:g,remoteHash:w,indexHash:x,indexMode:k,indexStage:P,existsOnDisk:E,isIgnoredOnDisk:O,getWorktreeHash:U,getWorktreeMode:G,headMode:b,remoteMode:y})}return m}function Zo(e,t,n,r){return e!==n?!1:e===null?!0:Kl(t)===Kl(r)}function Kl(e){return typeof e=="string"?Number.parseInt(e,8):e}function Qo(e,t){let n=e.remoteHash;return n===null?e.indexHash===null&&e.indexStage===0?{action:"SKIP",requirements:[]}:{action:"DELETE",requirements:t.reset?[]:["WORKTREE_MUST_BE_UPTODATE"]}:Zo(e.indexHash,e.indexMode,n,e.remoteMode)?{action:"KEEP",requirements:[]}:e.indexHash===null?{action:"TAKE",takeFrom:"remote",requirements:t.reset||!!t.strippedConflictPaths?.has(e.path)?[]:["NO_UNTRACKED"]}:{action:"TAKE",takeFrom:"remote",requirements:t.reset?[]:["WORKTREE_MUST_BE_UPTODATE"]}}function Jo(e,t){let{headHash:n,remoteHash:r,indexHash:s}=e,{headMode:o,remoteMode:i,indexMode:a}=e,c=Zo(n,o,r,i),f=Zo(s,a,n,o),l=Zo(s,a,r,i);return e.indexStage>0?c?r===null?{action:"DELETE",requirements:[]}:{action:"TAKE",takeFrom:"remote",requirements:[]}:{action:"KEEP",requirements:["INDEX_MUST_MATCH_HEAD"],caseNumber:-1}:s===null?r===null?n===null?{action:"SKIP",caseNumber:0,requirements:[]}:{action:"SKIP",caseNumber:2,requirements:["NO_UNTRACKED_REMOVED"]}:n!==null?c?{action:"SKIP",caseNumber:3,requirements:[]}:t.allowStagedChanges?{action:"TAKE",takeFrom:"remote",caseNumber:3,requirements:[]}:{action:"KEEP",caseNumber:3,requirements:["INDEX_MUST_MATCH_HEAD"]}:{action:"TAKE",takeFrom:"remote",caseNumber:1,requirements:["NO_UNTRACKED"]}:n===null&&r===null?{action:"KEEP",caseNumber:4,requirements:[]}:n===null&&l?{action:"KEEP",caseNumber:6,requirements:[]}:f&&r===null?{action:"DELETE",caseNumber:10,requirements:["WORKTREE_MUST_BE_UPTODATE"]}:n!==null&&c?{action:"KEEP",caseNumber:14,requirements:[]}:n!==null&&r!==null&&l?{action:"KEEP",caseNumber:18,requirements:[]}:n!==null&&r!==null&&f&&!l?{action:"TAKE",takeFrom:"remote",caseNumber:20,requirements:["WORKTREE_MUST_BE_UPTODATE"]}:t.allowStagedChanges?r===null?{action:"DELETE",caseNumber:-1,requirements:[]}:{action:"TAKE",takeFrom:"remote",caseNumber:-1,requirements:[]}:{action:"KEEP",requirements:["INDEX_MUST_MATCH_HEAD"],caseNumber:-1}}function Kp(e,t){switch(e.action){case"TAKE":return e.takeFrom==="head"?t.headHash:e.takeFrom==="remote"?t.remoteHash:e.takeFrom==="base"?t.baseHash:null;case"DELETE":return null;case"KEEP":return t.indexHash;default:return null}}async function Vp(e,t,n){let r=[];if(n.reset)return r;for(let[s,o]of e){if(o.requirements.length===0)continue;let i=t.get(s);if(!i)continue;let a=Kp(o,i);for(let c of o.requirements){if(n.allowStagedChanges&&c==="INDEX_MUST_MATCH_HEAD")continue;let f=await Yp(c,i,a);if(f){r.push({path:s,error:f});break}}if(n.stopAtFirstError&&r.length>0)break}return r}async function Yp(e,t,n,r){switch(e){case"INDEX_MUST_NOT_EXIST":return t.indexHash!==null?"WOULD_OVERWRITE":Ya(t)?"WOULD_LOSE_UNTRACKED_REMOVED":null;case"INDEX_MUST_MATCH_HEAD":return t.indexHash!==t.headHash?"WOULD_OVERWRITE":null;case"INDEX_MUST_MATCH_RESULT":return t.indexHash!==null&&t.indexHash!==n?"WOULD_OVERWRITE":null;case"WORKTREE_MUST_BE_UPTODATE":{if(!t.existsOnDisk)return null;let s=await t.getWorktreeHash();return s!==t.indexHash?r?.allowContentEscapeHatch&&(n!==null&&s===n||s===null&&n===null)?null:"NOT_UPTODATE_FILE":s!==null&&await t.getWorktreeMode()!==t.indexMode?"NOT_UPTODATE_FILE":null}case"NO_UNTRACKED":return Ya(t)?await t.isIgnoredOnDisk()?null:"WOULD_LOSE_UNTRACKED_OVERWRITTEN":null;case"NO_UNTRACKED_REMOVED":return Ya(t)?await t.isIgnoredOnDisk()?null:"WOULD_LOSE_UNTRACKED_REMOVED":null}}function Xp(e,t,n,r){let s=[],o=[],i=new Set(e.keys()),a=new Map;for(let c of n.entries)i.has(c.path)||s.push(c),c.stage===0&&a.set(c.path,c);for(let[c,f]of e){let l=t.get(c);if(l)switch(f.action){case"KEEP":{let d=a.get(c);d&&(s.push(d),r.reset&&r.updateWorktree&&o.push({path:c,type:"checkout",hash:d.hash,mode:d.mode}));break}case"TAKE":{let d=f.takeFrom==="head"?l.headHash:l.remoteHash,u=f.takeFrom==="head"?l.headMode:l.remoteMode,m=u?Number.parseInt(u,8):33188;s.push({path:c,mode:m,hash:d,stage:0,stat:Ge()}),r.updateWorktree&&o.push({path:c,type:"checkout",hash:d,mode:m});break}case"DELETE":{r.updateWorktree&&l.existsOnDisk&&o.push({path:c,type:"delete"});break}case"SKIP":break}}return s.sort((c,f)=>Ae(c.path,f.path)||c.stage-f.stage),{newEntries:s,worktreeOps:o}}function ei(e,t){let n=t.actionHint??t.operationName,r=[];for(let{error:o,msg:i,fix:a}of Zp){let c=e.filter(f=>f.error===o).map(f=>f.path).sort();if(c.length>0){let f=c.map(l=>` ${l}`).join(` + `);r.push(`${i(t.operationName)} + ${f} + ${a(n)} + `)}}return{stdout:"",stderr:r.length>0?`${r.join("")}Aborting +-`:"",exitCode:t.errorExitCode}}async function Ar(e,t,n,r){let o=await Op(e,t,n),s=new Map(o.map(l=>[l.path,l])),i=new Map;for(let l of o){let d=r.mergeFn(l,r);i.set(l.path,d)}let a=await vp(i,s,r);if(a.length>0)return{success:!1,newEntries:[],worktreeOps:[],errors:a,errorOutput:qo(a,r)};let{newEntries:c,worktreeOps:f}=Tp(i,s,n,r);return{success:!0,newEntries:c,worktreeOps:f,errors:[],errorOutput:null}}async function je(e,t){if(!e.workTree)return;let n=e.workTree,r=[];for(let o of t){if(!Pr(o.path))throw new Error(`refusing to apply worktree operation on unsafe path '${o.path}'`);let s=I(n,o.path);if(!Co(n,s))throw new Error(`refusing to apply worktree operation outside worktree: '${o.path}'`);o.type==="delete"?await Je(e.fs,s).then(()=>!0).catch(()=>!1)&&(await e.fs.rm(s),r.push(s)):o.type==="checkout"&&o.hash&&await at(e,{path:o.path,hash:o.hash,mode:o.mode})}for(let o of r)await Tr(e.fs,bt(o),n)}async function On(e,t,n,r){return Ar(e,[{label:"current",treeHash:t},{label:"target",treeHash:n}],r,{mergeFn:Wo,updateWorktree:!0,reset:!1,errorExitCode:1,operationName:"checkout",actionHint:"switch branches"})}async function Ua(e,t,n,r){return Ar(e,[{label:"HEAD",treeHash:t},{label:"target",treeHash:n}],r,{mergeFn:Wo,updateWorktree:!0,reset:!1,errorExitCode:1,operationName:"merge"})}async function _n(e,t,n){return Ar(e,[{label:"target",treeHash:t}],n,{mergeFn:Bo,updateWorktree:!0,reset:!0,errorExitCode:128,operationName:"reset"})}async function ss(e,t,n,r){let o=new Set;for(let a of n.entries)a.stage>0&&o.add(a.path);let s={version:n.version,entries:qe(n)},i=await Ar(e,[{label:"ORIG_HEAD",treeHash:t}],s,{mergeFn:Bo,updateWorktree:!0,reset:!1,errorExitCode:128,operationName:"merge",stopAtFirstError:!0,strippedConflictPaths:o});if(!i.success){let a=r??"HEAD",c=[];for(let f of i.errors)f.error==="NOT_UPTODATE_FILE"?c.push(`error: Entry '${f.path}' not uptodate. Cannot merge. ++`:"",exitCode:t.errorExitCode}}async function jr(e,t,n,r){let s=await zp(e,t,n),o=new Map(s.map(l=>[l.path,l])),i=new Map;for(let l of s){let d=r.mergeFn(l,r);i.set(l.path,d)}let a=await Vp(i,o,r);if(a.length>0)return{success:!1,newEntries:[],worktreeOps:[],errors:a,errorOutput:ei(a,r)};let{newEntries:c,worktreeOps:f}=Xp(i,o,n,r);return{success:!0,newEntries:c,worktreeOps:f,errors:[],errorOutput:null}}async function Me(e,t){if(!e.workTree)return;let n=e.workTree,r=[];for(let s of t){if(!Or(s.path))throw new Error(`refusing to apply worktree operation on unsafe path '${s.path}'`);let o=I(n,s.path);if(!To(n,o))throw new Error(`refusing to apply worktree operation outside worktree: '${s.path}'`);s.type==="delete"?await Ye(e.fs,o).then(()=>!0).catch(()=>!1)&&(await e.fs.rm(o),r.push(o)):s.type==="checkout"&&s.hash&&await lt(e,{path:s.path,hash:s.hash,mode:s.mode})}for(let s of r)await Mr(e.fs,Et(s),n)}async function Tn(e,t,n,r){return jr(e,[{label:"current",treeHash:t},{label:"target",treeHash:n}],r,{mergeFn:Jo,updateWorktree:!0,reset:!1,errorExitCode:1,operationName:"checkout",actionHint:"switch branches"})}async function Xa(e,t,n,r){return jr(e,[{label:"HEAD",treeHash:t},{label:"target",treeHash:n}],r,{mergeFn:Jo,updateWorktree:!0,reset:!1,errorExitCode:1,operationName:"merge"})}async function Bn(e,t,n){return jr(e,[{label:"target",treeHash:t}],n,{mergeFn:Qo,updateWorktree:!0,reset:!0,errorExitCode:128,operationName:"reset"})}async function as(e,t,n,r){let s=new Set;for(let a of n.entries)a.stage>0&&s.add(a.path);let o={version:n.version,entries:ze(n)},i=await jr(e,[{label:"ORIG_HEAD",treeHash:t}],o,{mergeFn:Qo,updateWorktree:!0,reset:!1,errorExitCode:128,operationName:"merge",stopAtFirstError:!0,strippedConflictPaths:s});if(!i.success){let a=r??"HEAD",c=[];for(let f of i.errors)f.error==="NOT_UPTODATE_FILE"?c.push(`error: Entry '${f.path}' not uptodate. Cannot merge. + `):f.error==="WOULD_LOSE_UNTRACKED_OVERWRITTEN"&&c.push(`error: Untracked working tree file '${f.path}' would be overwritten by merge. +-`);return c.length>0&&(i.errorOutput=F(c.join("")+`fatal: Could not reset index file to revision '${a}'. +-`,128)),i}if(e.workTree&&o.size>0){let a=await de(e,t),c=new Set(i.newEntries.map(f=>f.path));for(let f of o)!a.has(f)&&!c.has(f)&&i.worktreeOps.push({path:f,type:"delete"})}return i}var Ap,Jt=pe(()=>{"use strict";ne();ve();xo();ge();ir();cn();De();st();Ap=[{error:"WOULD_OVERWRITE",msg:e=>`error: Your local changes to the following files would be overwritten by ${e}:`,fix:e=>`Please commit your changes or stash them before you ${e}.`},{error:"NOT_UPTODATE_FILE",msg:e=>`error: Your local changes to the following files would be overwritten by ${e}:`,fix:e=>`Please commit your changes or stash them before you ${e}.`},{error:"WOULD_LOSE_UNTRACKED_OVERWRITTEN",msg:e=>`error: The following untracked working tree files would be overwritten by ${e}:`,fix:e=>`Please move or remove them before you ${e}.`},{error:"WOULD_LOSE_UNTRACKED_REMOVED",msg:e=>`error: The following untracked working tree files would be removed by ${e}:`,fix:e=>`Please move or remove them before you ${e}.`}]});function ce(e){return S().alias("q").describe(e)}function v(e){return{stdout:"",stderr:`fatal: ${e} +-`,exitCode:128}}function F(e,t=1){return{stdout:"",stderr:e,exitCode:t}}function _a(e,t,n){let r=n.gitDir;if(!n.objectStore||!n.refStore||!r)throw new Error("contextFromExtensions requires objectStore, refStore, and gitDir");return{...n,fs:e,gitDir:r,commonDir:n.commonDir??r,workTree:n.workTree??t,objectStore:n.objectStore,refStore:n.refStore}}async function q(e,t,n){if(n?.objectStore&&n?.refStore&&n?.gitDir)return _a(e,t,n);let r=await Fn(e,t);return r?n?{...r,...n,commonDir:n.commonDir??r.commonDir}:r:Hp}function D(e){return typeof e=="object"&&e!==null&&"exitCode"in e}function tt(e){return e.workTree?null:Dp}async function nt(e){let t=await Z(e);return t||v("your current branch does not have any commits yet")}function Hr(e,t,n=`fatal: Exiting because of an unresolved conflict. +-`){return kn(e)?F(`error: ${t} is not possible because you have unmerged files. ++`);return c.length>0&&(i.errorOutput=N(c.join("")+`fatal: Could not reset index file to revision '${a}'. ++`,128)),i}if(e.workTree&&s.size>0){let a=await de(e,t),c=new Set(i.newEntries.map(f=>f.path));for(let f of s)!a.has(f)&&!c.has(f)&&i.worktreeOps.push({path:f,type:"delete"})}return i}var Zp,rn=we(()=>{"use strict";te();Se();Ao();ge();ir();un();Te();ot();Zp=[{error:"WOULD_OVERWRITE",msg:e=>`error: Your local changes to the following files would be overwritten by ${e}:`,fix:e=>`Please commit your changes or stash them before you ${e}.`},{error:"NOT_UPTODATE_FILE",msg:e=>`error: Your local changes to the following files would be overwritten by ${e}:`,fix:e=>`Please commit your changes or stash them before you ${e}.`},{error:"WOULD_LOSE_UNTRACKED_OVERWRITTEN",msg:e=>`error: The following untracked working tree files would be overwritten by ${e}:`,fix:e=>`Please move or remove them before you ${e}.`},{error:"WOULD_LOSE_UNTRACKED_REMOVED",msg:e=>`error: The following untracked working tree files would be removed by ${e}:`,fix:e=>`Please move or remove them before you ${e}.`}]});function ce(e){return S().alias("q").describe(e)}function v(e){return{stdout:"",stderr:`fatal: ${e} ++`,exitCode:128}}function N(e,t=1){return{stdout:"",stderr:e,exitCode:t}}function Za(e,t,n){let r=n.gitDir;if(!n.objectStore||!n.refStore||!r)throw new Error("contextFromExtensions requires objectStore, refStore, and gitDir");return{...n,fs:e,gitDir:r,commonDir:n.commonDir??r,workTree:n.workTree??t,objectStore:n.objectStore,refStore:n.refStore}}async function W(e,t,n){if(n?.objectStore&&n?.refStore&&n?.gitDir)return Za(e,t,n);let r=await Un(e,t);return r?n?{...r,...n,commonDir:n.commonDir??r.commonDir}:r:Qp}function D(e){return typeof e=="object"&&e!==null&&"exitCode"in e}function tt(e){return e.workTree?null:Jp}async function nt(e){let t=await Z(e);return t||v("your current branch does not have any commits yet")}function Lr(e,t,n=`fatal: Exiting because of an unresolved conflict. ++`){return xn(e)?N(`error: ${t} is not possible because you have unmerged files. + hint: Fix them up in the work tree, and then use 'git add/rm ' + hint: as appropriate to mark resolution and make a commit. +-`+n,128):null}function ar(e){let t=Hr(e,"Committing");if(!t)return null;let n=[...new Set(e.entries.filter(r=>r.stage>0).map(r=>r.path))].sort();return{...t,stdout:n.map(r=>`U ${r} +-`).join("")}}async function It(e,t,n){let r=await Le(e,t);return r||v(n??`bad revision '${t}'`)}async function Ge(e,t,n){let r=await Le(e,t);if(!r)return v(n??`bad revision '${t}'`);try{let o=await Se(e,r),s=await M(e,o);return{hash:o,commit:s}}catch{return v(n??`bad revision '${t}'`)}}async function ct(e,t){try{return await xs(e,t)}catch(n){return v(n.message)}}async function Sn(e,t){try{return await Ro(e,t)}catch(n){return v(n.message)}}function Bn(e,t){let n=new Map;for(let r of e.entries)r.stage===0&&n.set(r.path,r);for(let[r,o]of n){let s=t.get(r);if(!s||s.hash!==o.hash)return!0}for(let[r]of t)if(!n.has(r))return!0;return!1}async function zo(e,t,n){if(!e.workTree)return null;let r=await M(e,t),o=await de(e,r.tree),s=Bn(n,o),a=(await dt(e,n,{includeUntracked:!1,stopAfterFirst:!0})).length>0;return!s&&!a?null:{hasStaged:s,hasUnstaged:a}}function Ko(e,t,n=1){let r=[];return t.hasUnstaged&&r.push(`error: cannot ${e}: You have unstaged changes.`),t.hasStaged&&(t.hasUnstaged?r.push("error: additionally, your index contains uncommitted changes."):r.push(`error: cannot ${e}: Your index contains uncommitted changes.`)),r.push("error: Please commit or stash them."),F(`${r.join(` ++`+n,128):null}function ar(e){let t=Lr(e,"Committing");if(!t)return null;let n=[...new Set(e.entries.filter(r=>r.stage>0).map(r=>r.path))].sort();return{...t,stdout:n.map(r=>`U ${r} ++`).join("")}}async function At(e,t,n){let r=await Ie(e,t);return r||v(n??`bad revision '${t}'`)}async function Le(e,t,n){let r=await Ie(e,t);if(!r)return v(n??`bad revision '${t}'`);try{let s=await Oe(e,r),o=await M(e,s);return{hash:s,commit:o}}catch{return v(n??`bad revision '${t}'`)}}async function dt(e,t){try{return await vs(e,t)}catch(n){return v(n.message)}}async function An(e,t){try{return await Io(e,t)}catch(n){return v(n.message)}}function Wn(e,t){let n=new Map;for(let r of e.entries)r.stage===0&&n.set(r.path,r);for(let[r,s]of n){let o=t.get(r);if(!o||o.hash!==s.hash||Number.parseInt(o.mode,8)!==s.mode)return!0}for(let[r]of t)if(!n.has(r))return!0;return!1}async function ti(e,t,n){if(!e.workTree)return null;let r=await M(e,t),s=await de(e,r.tree),o=Wn(n,s),a=(await pt(e,n,{includeUntracked:!1,stopAfterFirst:!0})).length>0;return!o&&!a?null:{hasStaged:o,hasUnstaged:a}}function ni(e,t,n=1){let r=[];return t.hasUnstaged&&r.push(`error: cannot ${e}: You have unstaged changes.`),t.hasStaged&&(t.hasUnstaged?r.push("error: additionally, your index contains uncommitted changes."):r.push(`error: cannot ${e}: Your index contains uncommitted changes.`)),r.push("error: Please commit or stash them."),N(`${r.join(` + `)} +-`,n)}function Te(e,t){return et?1:0}function kt(e,t){return e.workTree?lt(e.workTree,t):""}function Lt(e){return e.slice(0,Ll)}async function ue(e,t,n=Ll){let r=Math.max(n,4);for(let o=r;o{n.set(r,await ue(e,r))})),r=>n.get(r)??Lt(r)}function me(e){let t=e.indexOf(` +-`);return t===-1?e:e.slice(0,t)}function Et(e){return v(`ambiguous argument '${e}': unknown revision or path not in the working tree. ++`,n)}function Ae(e,t){return et?1:0}function ut(e,t){return e.workTree?rt(e.workTree,t):""}function Nt(e){return e.slice(0,ri)}async function fe(e,t,n=ri){let r=Math.max(n,4);for(let s=r;s{n.set(r,await fe(e,r))})),r=>n.get(r)??Nt(r)}function he(e){let t=e.indexOf(` ++`);return t===-1?e:e.slice(0,t)}function Ct(e){return v(`ambiguous argument '${e}': unknown revision or path not in the working tree. + Use '--' to separate paths from revisions, like this: +-'git [...] -- [...]'`)}async function pn(e,t,n,r,o=!1){return`[${t}${o?" (root-commit)":""} ${await ue(e,n)}] ${me(r)}`}async function cr(e,t,n){if(!await z(e,n.operationRef))return n.noOpError;let o=await Z(e);if(!o)return v(`There is no ${n.operationName} to abort (HEAD missing).`);let s=o,i=await M(e,o),a=await X(e),c=await ss(e,i.tree,a,n.origHeadAsTargetRev?o:void 0);if(!c.success)return c.errorOutput;if(await or(e,o),await ie(e,{version:2,entries:c.newEntries}),await je(e,c.worktreeOps),(await te(e))?.type==="symbolic"){let d=n.origHeadAsTargetRev?o:"HEAD";await ee(e,t,"HEAD",s,o,`reset: moving to ${d}`)}return await n.clearState(e),{stdout:"",stderr:"",exitCode:0}}async function Gt(e,t,n,r,o,s){let i=Cn({type:"commit",tree:t,parents:n,author:r,committer:o,message:s}),a=await Me(e,"commit",i);return await or(e,a),a}function Ft(e){let t=e.split(` +-`).filter(o=>!o.startsWith("#")).map(o=>o.trimEnd());for(;t.length>0&&t[0]==="";)t.shift();for(;t.length>0&&t[t.length-1]==="";)t.pop();if(t.length===0)return"";let n=[],r=!1;for(let o of t)o===""?(r||n.push(o),r=!0):(n.push(o),r=!1);return n.join(` ++'git [...] -- [...]'`)}async function yn(e,t,n,r,s=!1){return`[${t}${s?" (root-commit)":""} ${await fe(e,n)}] ${he(r)}`}async function cr(e,t,n){if(!await z(e,n.operationRef))return n.noOpError;let s=await Z(e);if(!s)return v(`There is no ${n.operationName} to abort (HEAD missing).`);let o=s,i=await M(e,s),a=await X(e),c=await as(e,i.tree,a,n.origHeadAsTargetRev?s:void 0);if(!c.success)return c.errorOutput;if(await or(e,s),await oe(e,{version:2,entries:c.newEntries}),await Me(e,c.worktreeOps),(await ne(e))?.type==="symbolic"){let d=n.origHeadAsTargetRev?s:"HEAD";await ee(e,t,"HEAD",o,s,`reset: moving to ${d}`)}return await n.clearState(e),{stdout:"",stderr:"",exitCode:0}}async function Ut(e,t,n,r,s,o){let i=$n({type:"commit",tree:t,parents:n,author:r,committer:s,message:o}),a=await De(e,"commit",i);return await or(e,a),a}function _t(e){let t=e.split(` ++`).filter(s=>!s.startsWith("#")).map(s=>s.trimEnd());for(;t.length>0&&t[0]==="";)t.shift();for(;t.length>0&&t[t.length-1]==="";)t.pop();if(t.length===0)return"";let n=[],r=!1;for(let s of t)s===""?(r||n.push(s),r=!0):(n.push(s),r=!1);return n.join(` + `)+` +-`}function Nt(e){return e.endsWith(` ++`}function Bt(e){return e.endsWith(` + `)?e:`${e} +-`}function os(e,t=0,n=!0){let o=n?Math.max(t,...e.map(s=>s.from.length)):0;return e.map(s=>{let i=s.prefix.padEnd(21);if(!s.to)return`${i}${s.from} +-`;let a=o>0?s.from.padEnd(o):s.from,c=s.suffix?` ${s.suffix}`:"";return`${i}${a} -> ${s.to}${c} +-`}).join("")}function Bs(e,t,n){let r=[];for(let o of e){let s=t(o.remote.name),i=t(o.localRef);if(o.oldHash){if(o.oldHash!==o.remote.hash){let a=n(o.oldHash),c=n(o.remote.hash);r.push({prefix:` ${a}..${c}`,from:s,to:i})}}else{let c=o.remote.name.startsWith("refs/tags/")?" * [new tag]":" * [new branch]";r.push({prefix:c,from:s,to:i})}}return r}var Hp,Dp,Ll,ne=pe(()=>{"use strict";Ee();xr();ve();ae();Mn();ge();Ve();ye();Gn();Qt();De();Jt();st();Hp=v("not a git repository (or any of the parent directories): .git"),Dp=v("this operation must be run in a work tree");Ll=7});var _l={};th(_l,{CommitHeap:()=>vn,countAheadBehind:()=>za,findOrphanedCommits:()=>Ka,walkCommits:()=>Ot});async function*Ot(e,t,n){if(n?.topoOrder){yield*Np(e,t,n);return}let r=await Ul(e,n?.exclude),o=new Set(r),s=new vn,i=n?.shallowBoundary,a=n?.limit,c=0,f=Array.isArray(t)?t:[t];for(let l of f)o.has(l)||s.push(await is(e,l));for(;s.size>0;){let l=s.pop();if(o.has(l.hash))continue;if(o.add(l.hash),yield l,a!==void 0&&++c>=a)return;if(i?.has(l.hash))continue;let d=n?.firstParent?l.commit.parents.slice(0,1):l.commit.parents;for(let u of d)if(!o.has(u))try{s.push(await is(e,u))}catch{}}}async function*Np(e,t,n){let r=await Ul(e,n?.exclude),o=new Set(r),s=new vn,i=n?.shallowBoundary,a=Array.isArray(t)?t:[t];for(let m of a)o.has(m)||s.push(await is(e,m));let c=[],f=new Map;for(;s.size>0;){let m=s.pop();if(o.has(m.hash)||(o.add(m.hash),f.set(m.hash,c.length),c.push(m),i?.has(m.hash)))continue;let h=n?.firstParent?m.commit.parents.slice(0,1):m.commit.parents;for(let p of h)if(!o.has(p))try{s.push(await is(e,p))}catch{}}let l=c.length;if(l===0)return;let d=new Int32Array(l);for(let m of c){let h=n?.firstParent?m.commit.parents.slice(0,1):m.commit.parents;for(let p of h){let g=f.get(p);g!==void 0&&(d[g]=(d[g]??0)+1)}}let u=[];for(let m=l-1;m>=0;m--)d[m]===0&&u.push(m);for(;u.length>0;){let m=u.pop();yield c[m];let h=n?.firstParent?c[m].commit.parents.slice(0,1):c[m].commit.parents;for(let p of h){let g=f.get(p);if(g!==void 0){let w=(d[g]??0)-1;d[g]=w,w===0&&u.push(g)}}}}async function za(e,t,n){if(t===n)return{ahead:0,behind:0};let r=new Set;for await(let a of Ot(e,t))r.add(a.hash);let o=new Set;for await(let a of Ot(e,n))o.add(a.hash);let s=0;for(let a of r)o.has(a)||s++;let i=0;for(let a of o)r.has(a)||i++;return{ahead:s,behind:i}}async function Ka(e,t,n){let r=n?.maxCount??25,o=await $e(e,"refs"),s=[];for(let l of o)try{s.push(await Se(e,l.hash))}catch{}n?.targetHash&&s.push(n.targetHash);let i=new Set;if(s.length>0)for await(let l of Ot(e,s))i.add(l.hash);if(i.has(t))return[];let a=[],c=new Set,f=new vn;for(f.push(await is(e,t));f.size>0&&a.length{"use strict";ne();ae();ye();vn=class{heap=[];nextEpoch=0;get size(){return this.heap.length}push(t){this.heap.push({entry:t,epoch:this.nextEpoch++}),this.siftUp(this.heap.length-1)}pop(){let{heap:t}=this;if(t.length===0)return;let n=t[0],r=t.pop();return t.length>0&&(t[0]=r,this.siftDown(0)),n.entry}higher(t,n){let r=t.entry.commit.committer.timestamp,o=n.entry.commit.committer.timestamp;return r>o||r===o&&t.epoch0;){let r=t-1>>1;if(!this.higher(n[t],n[r]))break;[n[r],n[t]]=[n[t],n[r]],t=r}}siftDown(t){let{heap:n}=this,r=n.length;for(;;){let o=t,s=2*t+1,i=2*t+2;if(s0&&n[n.length-1]!==".."&&n.pop();continue}n.push(r)}return n.join("/")}function We(e,t){let n=0,r=e;if(r.startsWith(":(")){let c=r.indexOf(")");if(c!==-1){let f=r.slice(2,c);r=r.slice(c+1);for(let l of f.split(",")){let d=jp[l.trim()];d!==void 0&&(n|=d)}}}else r.startsWith(":/")?(n|=Wa,r=r.slice(2)):(r.startsWith(":!")||r.startsWith(":^"))&&(n|=Ws,r=r.slice(2));n&Ba&&n&Yo&&(n&=~Yo);let o;n&Wa||t===""?o=Gl(r):o=Gl(`${t}/${r}`);let s=!!(n&Ba),i=s?!1:Dr(o),a=s?o.length:Lp(o);return{original:e,pattern:o,magic:n,hasWildcard:i,nowildcardLen:a}}function Xo(e,t){let{pattern:n,hasWildcard:r,magic:o,nowildcardLen:s}=e;if(n==="")return!0;if(!r){let a=!!(o&Vo),c=a?n.toLowerCase():n,f=a?t.toLowerCase():t;return!!(c===f||f.startsWith(c)&&f[c.length]==="/"||c.endsWith("/")&&f.startsWith(c))}if(s>0){let a=n.slice(0,s),c=t.slice(0,s);if(o&Vo){if(a.toLowerCase()!==c.toLowerCase())return!1}else if(a!==c)return!1}let i=0;return o&Yo&&(i|=2),o&Vo&&(i|=1),xn(n,t,i)===0}function Pe(e,t){let n=!1,r=!1;for(let o of e)o.magic&Ws?Xo(o,t)&&(r=!0):Xo(o,t)&&(n=!0);return n&&!r}st();Ee();function Nl(e,t){e.command("add",{description:"Add file contents to the index",args:[W.string().name("paths").describe("Pathspec of files to add").optional().variadic()],options:{all:S().alias("A").describe("Add changes from all tracked and untracked files"),force:S().alias("f").describe("Allow adding otherwise ignored files"),update:S().alias("u").describe("Update tracked files"),"dry-run":S().alias("n").describe("Don't actually add the file(s)")},handler:async(n,r)=>{let o=await q(r.fs,r.cwd,t);if(D(o))return o;let s=o,i=tt(s);if(i)return i;let a=s.workTree,c={skipIgnore:n.force,updateOnly:n.update,actions:n["dry-run"]?[]:void 0},f=n.paths;if((n.all||n.update)&&f.length===0){let p=await X(s);return p=await qa(s,p,a,"",c),n["dry-run"]||await ie(s,p),{stdout:c.actions?c.actions.join(""):"",stderr:"",exitCode:0}}if(f.length===0)return{stdout:"",stderr:`Nothing specified, nothing added. +-Maybe you wanted to say 'git add .'?`,exitCode:0};let l=await X(s),d=[],u=[];for(let p of f)Dr(p)?u.push(p):d.push(p);let m=[];for(let p of d){let g=Qe(r.cwd,p),w=lt(a,g);if((w==="."||w==="")&&(w=""),w.startsWith(".."))return v(`'${p}' is outside repository at '${a}'`);if(await r.fs.exists(g)){if(!n.force&&w!==""){let C=l.entries.some(y=>y.path===w||y.path.startsWith(`${w}/`)),x=await Fp(s,a,w,C);if(x){C&&((await r.fs.stat(g)).isDirectory?l=await qa(s,l,g,w,c):l=(await $n(s,l,w)).index),m.push(x);continue}}if((await r.fs.stat(g)).isDirectory)l=await qa(s,l,g,w,c);else{let C=l.entries.find(y=>y.path===w&&y.stage===0)?.hash,x=await $n(s,l,w);l=x.index,c.actions&&x.hash!==C&&c.actions.push(`add '${w}' ++`}function cs(e,t=0,n=!0){let s=n?Math.max(t,...e.map(o=>o.from.length)):0;return e.map(o=>{let i=o.prefix.padEnd(21);if(!o.to)return`${i}${o.from} ++`;let a=s>0?o.from.padEnd(s):o.from,c=o.suffix?` ${o.suffix}`:"";return`${i}${a} -> ${o.to}${c} ++`}).join("")}function Ys(e,t,n){let r=[];for(let s of e){let o=t(s.remote.name),i=t(s.localRef);if(s.oldHash){if(s.oldHash!==s.remote.hash){let a=n(s.oldHash),c=n(s.remote.hash);r.push({prefix:` ${a}..${c}`,from:o,to:i})}}else{let c=s.remote.name.startsWith("refs/tags/")?" * [new tag]":" * [new branch]";r.push({prefix:c,from:o,to:i})}}return r}var Qp,Jp,ri,te=we(()=>{"use strict";ke();$r();Se();ie();On();ge();Xe();ye();Nn();Ft();Te();rn();ot();Qp=v("not a git repository (or any of the parent directories): .git"),Jp=v("this operation must be run in a work tree");ri=7});var Ql={};wh(Ql,{CommitHeap:()=>Hn,countAheadBehind:()=>tc,findOrphanedCommits:()=>nc,walkCommits:()=>St});async function*St(e,t,n){if(n?.topoOrder){yield*og(e,t,n);return}let r=await Zl(e,n?.exclude),s=new Set(r),o=new Hn,i=n?.shallowBoundary,a=n?.limit,c=0,f=Array.isArray(t)?t:[t];for(let l of f)s.has(l)||o.push(await fs(e,l));for(;o.size>0;){let l=o.pop();if(s.has(l.hash))continue;if(s.add(l.hash),yield l,a!==void 0&&++c>=a)return;if(i?.has(l.hash))continue;let d=n?.firstParent?l.commit.parents.slice(0,1):l.commit.parents;for(let u of d)if(!s.has(u))try{o.push(await fs(e,u))}catch{}}}async function*og(e,t,n){let r=await Zl(e,n?.exclude),s=new Set(r),o=new Hn,i=n?.shallowBoundary,a=Array.isArray(t)?t:[t];for(let m of a)s.has(m)||o.push(await fs(e,m));let c=[],f=new Map;for(;o.size>0;){let m=o.pop();if(s.has(m.hash)||(s.add(m.hash),f.set(m.hash,c.length),c.push(m),i?.has(m.hash)))continue;let h=n?.firstParent?m.commit.parents.slice(0,1):m.commit.parents;for(let p of h)if(!s.has(p))try{o.push(await fs(e,p))}catch{}}let l=c.length;if(l===0)return;let d=new Int32Array(l);for(let m of c){let h=n?.firstParent?m.commit.parents.slice(0,1):m.commit.parents;for(let p of h){let g=f.get(p);g!==void 0&&(d[g]=(d[g]??0)+1)}}let u=[];for(let m=l-1;m>=0;m--)d[m]===0&&u.push(m);for(;u.length>0;){let m=u.pop();yield c[m];let h=n?.firstParent?c[m].commit.parents.slice(0,1):c[m].commit.parents;for(let p of h){let g=f.get(p);if(g!==void 0){let w=(d[g]??0)-1;d[g]=w,w===0&&u.push(g)}}}}async function tc(e,t,n){if(t===n)return{ahead:0,behind:0};let r=new Set;for await(let a of St(e,t))r.add(a.hash);let s=new Set;for await(let a of St(e,n))s.add(a.hash);let o=0;for(let a of r)s.has(a)||o++;let i=0;for(let a of s)r.has(a)||i++;return{ahead:o,behind:i}}async function nc(e,t,n){let r=n?.maxCount??25,s=await $e(e,"refs"),o=[];for(let l of s)try{o.push(await Oe(e,l.hash))}catch{}n?.targetHash&&o.push(n.targetHash);let i=new Set;if(o.length>0)for await(let l of St(e,o))i.add(l.hash);if(i.has(t))return[];let a=[],c=new Set,f=new Hn;for(f.push(await fs(e,t));f.size>0&&a.length{"use strict";te();ie();ye();Hn=class{heap=[];nextEpoch=0;get size(){return this.heap.length}push(t){this.heap.push({entry:t,epoch:this.nextEpoch++}),this.siftUp(this.heap.length-1)}pop(){let{heap:t}=this;if(t.length===0)return;let n=t[0],r=t.pop();return t.length>0&&(t[0]=r,this.siftDown(0)),n.entry}higher(t,n){let r=t.entry.commit.committer.timestamp,s=n.entry.commit.committer.timestamp;return r>s||r===s&&t.epoch0;){let r=t-1>>1;if(!this.higher(n[t],n[r]))break;[n[r],n[t]]=[n[t],n[r]],t=r}}siftDown(t){let{heap:n}=this,r=n.length;for(;;){let s=t,o=2*t+1,i=2*t+2;if(o0&&n[n.length-1]!==".."&&n.pop();continue}n.push(r)}return n.join("/")}function qe(e,t){let n=0,r=e;if(r.startsWith(":(")){let c=r.indexOf(")");if(c!==-1){let f=r.slice(2,c);r=r.slice(c+1);for(let l of f.split(",")){let d=tg[l.trim()];d!==void 0&&(n|=d)}}}else r.startsWith(":/")?(n|=Ja,r=r.slice(2)):(r.startsWith(":!")||r.startsWith(":^"))&&(n|=Xs,r=r.slice(2));n&Qa&&n&oi&&(n&=~oi);let s;n&Ja||t===""?s=Vl(r):s=Vl(`${t}/${r}`);let o=!!(n&Qa),i=o?!1:Gr(s),a=o?s.length:ng(s);return{original:e,pattern:s,magic:n,hasWildcard:i,nowildcardLen:a}}function ii(e,t){let{pattern:n,hasWildcard:r,magic:s,nowildcardLen:o}=e;if(n==="")return!0;if(!r){let a=!!(s&si),c=a?n.toLowerCase():n,f=a?t.toLowerCase():t;return!!(c===f||f.startsWith(c)&&f[c.length]==="/"||c.endsWith("/")&&f.startsWith(c))}if(o>0){let a=n.slice(0,o),c=t.slice(0,o);if(s&si){if(a.toLowerCase()!==c.toLowerCase())return!1}else if(a!==c)return!1}let i=0;return s&oi&&(i|=2),s&si&&(i|=1),Sn(n,t,i)===0}function Pe(e,t){let n=!1,r=!1;for(let s of e)s.magic&Xs?ii(s,t)&&(r=!0):ii(s,t)&&(n=!0);return n&&!r}ot();ke();function Xl(e,t){e.command("add",{description:"Add file contents to the index",args:[B.string().name("paths").describe("Pathspec of files to add").optional().variadic()],options:{all:S().alias("A").describe("Add changes from all tracked and untracked files"),force:S().alias("f").describe("Allow adding otherwise ignored files"),update:S().alias("u").describe("Update tracked files"),"dry-run":S().alias("n").describe("Don't actually add the file(s)")},handler:async(n,r)=>{let s=await W(r.fs,r.cwd,t);if(D(s))return s;let o=s,i=tt(o);if(i)return i;let a=o.workTree,c={skipIgnore:n.force,updateOnly:n.update,actions:n["dry-run"]?[]:void 0},f=n.paths;if((n.all||n.update)&&f.length===0){let p=await X(o);return p=await ec(o,p,a,"",c),n["dry-run"]||await oe(o,p),{stdout:c.actions?c.actions.join(""):"",stderr:"",exitCode:0}}if(f.length===0)return{stdout:"",stderr:`Nothing specified, nothing added. ++Maybe you wanted to say 'git add .'?`,exitCode:0};let l=await X(o),d=[],u=[];for(let p of f)Gr(p)?u.push(p):d.push(p);let m=[];for(let p of d){let g=Je(r.cwd,p),w=rt(a,g);if((w==="."||w==="")&&(w=""),w.startsWith(".."))return v(`'${p}' is outside repository at '${a}'`);if(await r.fs.exists(g)){if(!n.force&&w!==""){let C=l.entries.some(k=>k.path===w||k.path.startsWith(`${w}/`)),x=await sg(o,a,w,C);if(x){C&&((await r.fs.stat(g)).isDirectory?l=await ec(o,l,g,w,c):l=(await In(o,l,w)).index),m.push(x);continue}}if((await r.fs.stat(g)).isDirectory)l=await ec(o,l,g,w,c);else{let C=l.entries.find(k=>k.path===w&&k.stage===0)?.hash,x=await In(o,l,w);l=x.index,c.actions&&x.hash!==C&&c.actions.push(`add '${w}' + `)}}else if(l.entries.some(C=>C.path===w||C.path.startsWith(`${w}/`))){if(c.actions)for(let C of l.entries)(C.path===w||C.path.startsWith(`${w}/`))&&c.actions.push(`remove '${C.path}' +-`);l={...l,entries:l.entries.filter(C=>C.path!==w&&!C.path.startsWith(`${w}/`))}}else return v(`pathspec '${p}' did not match any files`)}if(m.length>0)return n["dry-run"]||await ie(s,l),F(`The following paths are ignored by one of your .gitignore files: ++`);l={...l,entries:l.entries.filter(C=>C.path!==w&&!C.path.startsWith(`${w}/`))}}else return v(`pathspec '${p}' did not match any files`)}if(m.length>0)return n["dry-run"]||await oe(o,l),N(`The following paths are ignored by one of your .gitignore files: + ${m.join(` + `)} + hint: Use -f if you really want to add them. + hint: Disable this message with "git config set advice.addIgnoredFile false" +-`);if(u.length>0){let p=await Gp(s,r.cwd,l,u,c);if(p.error)return p.error;l=p.index}return n["dry-run"]||await ie(s,l),{stdout:c.actions?c.actions.join(""):"",stderr:"",exitCode:0}}})}async function Gp(e,t,n,r,o){let s=e.workTree,i=kt(e,t),a=r.map(d=>We(d,i)),c=new Array(a.length).fill(!1),f=d=>{for(let u=0;u0||!Pe(a,d.path))continue;f(d.path);let u=I(s,d.path);if(await e.fs.exists(u)){let m=await $n(e,n,d.path);n=m.index,o?.actions&&m.hash!==d.hash&&o.actions.push(`add '${d.path}' +-`)}else o?.actions&&o.actions.push(`remove '${d.path}' +-`),l.push(d.path)}for(let d of l)n=yt(n,d);if(!o?.updateOnly){let d=new Set(n.entries.map(m=>m.path)),u=await ut(e,s,"",{skipIgnore:o?.skipIgnore});for(let m of u){if(d.has(m)||!Pe(a,m))continue;f(m),o?.actions&&o.actions.push(`add '${m}' +-`),n=(await $n(e,n,m)).index}}for(let d=0;d0,u=await $n(e,t,f.path);t=u.index,o?.actions&&(d||u.hash!==f.hash)&&o.actions.push(`add '${f.path}' +-`)}else o?.actions&&o.actions.push(`remove '${f.path}' +-`),a.push(f.path)}for(let f of a)t=yt(t,f);if(!o?.updateOnly){let f=new Set(t.entries.map(d=>d.path)),l=await ut(e,n,r===""?"":r,{skipIgnore:o?.skipIgnore});for(let d of l){if(f.has(d))continue;o?.actions&&o.actions.push(`add '${d}' +-`),t=(await $n(e,t,d)).index}}return t}async function Fp(e,t,n,r){let o=await rs(e);try{let i=await e.fs.readFile(I(t,".gitignore"));o=Ir(o,i,"",I(t,".gitignore"))}catch{}let s=n.split("/");for(let i=0;ia.isDirectory).catch(()=>!1);if(Pn(o,n,i)==="ignored")return n}return null}ne();ne();fr();ae();ge();ye();async function Ae(e,t){let n=I(e.gitDir,t);return await e.fs.exists(n)?e.fs.readFile(n):null}async function Ue(e,t,n){await e.fs.writeFile(I(e.gitDir,t),n)}async function Ce(e,t){let n=I(e.gitDir,t);await e.fs.exists(n)&&await e.fs.rm(n)}async function qs(e){await ke(e,"MERGE_HEAD"),await ke(e,"ORIG_HEAD"),await Ce(e,"MERGE_MSG"),await Ce(e,"MERGE_MODE"),await Ce(e,"SQUASH_MSG")}async function gn(e){await ke(e,"CHERRY_PICK_HEAD"),await ke(e,"ORIG_HEAD"),await Ce(e,"MERGE_MSG"),await Ce(e,"SQUASH_MSG")}async function tn(e){await ke(e,"REVERT_HEAD"),await ke(e,"ORIG_HEAD"),await Ce(e,"MERGE_MSG"),await Ce(e,"SQUASH_MSG")}async function lr(e){for(let t of["CHERRY_PICK_HEAD","REVERT_HEAD","MERGE_HEAD","ORIG_HEAD"])await ke(e,t);await Ce(e,"MERGE_MSG"),await Ce(e,"MERGE_MODE"),await Ce(e,"SQUASH_MSG")}var Va="DETACH_POINT";async function Bl(e,t){await e.fs.writeFile(I(e.gitDir,Va),t)}async function Tt(e){let t=I(e.gitDir,Va);await e.fs.exists(t)&&await e.fs.rm(t)}async function zs(e){let t=I(e.gitDir,Va);return await e.fs.exists(t)?(await e.fs.readFile(t))?.trim()??null:null}ge();ye();async function Ut(e){let t=await Ae(e,"BISECT_START");return t!=null&&t.trim().length>0}async function Ks(e){let t=await Ae(e,"BISECT_TERMS");if(!t)return{termBad:"bad",termGood:"good"};let n=t.trim().split(` +-`);return{termBad:n[0]??"bad",termGood:n[1]??"good"}}async function Zo(e){let t=(await Ae(e,"BISECT_START"))?.trim()??"",{termBad:n,termGood:r}=await Ks(e),o=await z(e,`refs/bisect/${n}`),s=[],i=[],a=await $e(e,"refs/bisect");for(let l of a)l.name.startsWith(`refs/bisect/${r}-`)?s.push(l.hash):l.name.startsWith("refs/bisect/skip-")&&i.push(l.hash);let c=await Ae(e,"BISECT_HEAD")!=null||await e.fs.exists(I(e.gitDir,"BISECT_HEAD")),f=await e.fs.exists(I(e.gitDir,"BISECT_FIRST_PARENT"));return{startRef:t,badHash:o,goodHashes:s,skipHashes:i,termBad:n,termGood:r,noCheckout:c,firstParent:f}}async function _t(e,t){let n=await Ae(e,"BISECT_LOG")??"";await Ue(e,"BISECT_LOG",n+t+` +-`)}async function Qo(e){let t=await $e(e,"refs/bisect");for(let r of t)await ke(e,r.name);await Ce(e,"BISECT_EXPECTED_REV"),await Ce(e,"BISECT_ANCESTORS_OK"),await Ce(e,"BISECT_LOG"),await Ce(e,"BISECT_TERMS"),await Ce(e,"BISECT_NAMES"),await Ce(e,"BISECT_FIRST_PARENT"),await Ce(e,"BISECT_HEAD"),await Ce(e,"BISECT_START");let n=I(e.gitDir,"refs","bisect");if(await e.fs.exists(n))try{await e.fs.rm(n,{recursive:!0})}catch{}}async function Wl(e,t,n,r,o){let s=[],i=new Map;for await(let g of Ot(e,t,{exclude:n})){let w=o?g.commit.parents.slice(0,1):g.commit.parents;s.push({hash:g.hash,subject:me(g.commit.message)}),i.set(g.hash,w)}let a=s.length;if(a===0)return null;if(a===1)return{hash:s[0].hash,subject:s[0].subject,remaining:0,steps:0,found:!0,onlySkippedLeft:!1};let c=new Set(s.map(g=>g.hash)),f=new Map;for(let g of s){let w=new Set,b=[g.hash],R=0;for(;Rg.hash===l),h=Up(a),p=_p(a);return{hash:m.hash,subject:m.subject,remaining:h,steps:p,found:!1,onlySkippedLeft:u}}function Up(e){return Math.floor((e-1)/2)}function _p(e){return e<=1?0:Math.ceil(Math.log2(e))}function ql(e){let t=e.badHash!=null,n=e.goodHashes.length;return!t&&n===0?`status: waiting for both ${e.termGood} and ${e.termBad} commits ++`);if(u.length>0){let p=await rg(o,r.cwd,l,u,c);if(p.error)return p.error;l=p.index}return n["dry-run"]||await oe(o,l),{stdout:c.actions?c.actions.join(""):"",stderr:"",exitCode:0}}})}async function rg(e,t,n,r,s){let o=e.workTree,i=ut(e,t),a=r.map(d=>qe(d,i)),c=new Array(a.length).fill(!1),f=d=>{for(let u=0;u0||!Pe(a,d.path))continue;f(d.path);let u=I(o,d.path);if(await e.fs.exists(u)){let m=await In(e,n,d.path);n=m.index,s?.actions&&m.hash!==d.hash&&s.actions.push(`add '${d.path}' ++`)}else s?.actions&&s.actions.push(`remove '${d.path}' ++`),l.push(d.path)}for(let d of l)n=Rt(n,d);if(!s?.updateOnly){let d=new Set(n.entries.map(m=>m.path)),u=await gt(e,o,"",{skipIgnore:s?.skipIgnore});for(let m of u){if(d.has(m)||!Pe(a,m))continue;f(m),s?.actions&&s.actions.push(`add '${m}' ++`),n=(await In(e,n,m)).index}}for(let d=0;d0,u=await In(e,t,f.path);t=u.index,s?.actions&&(d||u.hash!==f.hash)&&s.actions.push(`add '${f.path}' ++`)}else s?.actions&&s.actions.push(`remove '${f.path}' ++`),a.push(f.path)}for(let f of a)t=Rt(t,f);if(!s?.updateOnly){let f=new Set(t.entries.map(d=>d.path)),l=await gt(e,n,r===""?"":r,{skipIgnore:s?.skipIgnore});for(let d of l){if(f.has(d))continue;s?.actions&&s.actions.push(`add '${d}' ++`),t=(await In(e,t,d)).index}}return t}async function sg(e,t,n,r){let s=await is(e);try{let i=await e.fs.readFile(I(t,".gitignore"));s=Dr(s,i,"",I(t,".gitignore"))}catch{}let o=n.split("/");for(let i=0;ia.isDirectory).catch(()=>!1);if(vn(s,n,i)==="ignored")return n}return null}te();te();fr();ie();ge();ye();async function He(e,t){let n=I(e.gitDir,t);return await e.fs.exists(n)?e.fs.readFile(n):null}async function Ne(e,t,n){await e.fs.writeFile(I(e.gitDir,t),n)}async function xe(e,t){let n=I(e.gitDir,t);await e.fs.exists(n)&&await e.fs.rm(n)}async function Zs(e){await Ee(e,"MERGE_HEAD"),await Ee(e,"ORIG_HEAD"),await xe(e,"MERGE_MSG"),await xe(e,"MERGE_MODE"),await xe(e,"SQUASH_MSG")}async function kn(e){await Ee(e,"CHERRY_PICK_HEAD"),await Ee(e,"ORIG_HEAD"),await xe(e,"MERGE_MSG"),await xe(e,"SQUASH_MSG")}async function on(e){await Ee(e,"REVERT_HEAD"),await Ee(e,"ORIG_HEAD"),await xe(e,"MERGE_MSG"),await xe(e,"SQUASH_MSG")}async function lr(e){for(let t of["CHERRY_PICK_HEAD","REVERT_HEAD","MERGE_HEAD","ORIG_HEAD"])await Ee(e,t);await xe(e,"MERGE_MSG"),await xe(e,"MERGE_MODE"),await xe(e,"SQUASH_MSG")}var rc="DETACH_POINT";async function Jl(e,t){await e.fs.writeFile(I(e.gitDir,rc),t)}async function Ht(e){let t=I(e.gitDir,rc);await e.fs.exists(t)&&await e.fs.rm(t)}async function Qs(e){let t=I(e.gitDir,rc);return await e.fs.exists(t)?(await e.fs.readFile(t))?.trim()??null:null}ge();ye();async function Wt(e){let t=await He(e,"BISECT_START");return t!=null&&t.trim().length>0}async function Js(e){let t=await He(e,"BISECT_TERMS");if(!t)return{termBad:"bad",termGood:"good"};let n=t.trim().split(` ++`);return{termBad:n[0]??"bad",termGood:n[1]??"good"}}async function ai(e){let t=(await He(e,"BISECT_START"))?.trim()??"",{termBad:n,termGood:r}=await Js(e),s=await z(e,`refs/bisect/${n}`),o=[],i=[],a=await $e(e,"refs/bisect");for(let l of a)l.name.startsWith(`refs/bisect/${r}-`)?o.push(l.hash):l.name.startsWith("refs/bisect/skip-")&&i.push(l.hash);let c=await He(e,"BISECT_HEAD")!=null||await e.fs.exists(I(e.gitDir,"BISECT_HEAD")),f=await e.fs.exists(I(e.gitDir,"BISECT_FIRST_PARENT"));return{startRef:t,badHash:s,goodHashes:o,skipHashes:i,termBad:n,termGood:r,noCheckout:c,firstParent:f}}async function qt(e,t){let n=await He(e,"BISECT_LOG")??"";await Ne(e,"BISECT_LOG",n+t+` ++`)}async function ci(e){let t=await $e(e,"refs/bisect");for(let r of t)await Ee(e,r.name);await xe(e,"BISECT_EXPECTED_REV"),await xe(e,"BISECT_ANCESTORS_OK"),await xe(e,"BISECT_LOG"),await xe(e,"BISECT_TERMS"),await xe(e,"BISECT_NAMES"),await xe(e,"BISECT_FIRST_PARENT"),await xe(e,"BISECT_HEAD"),await xe(e,"BISECT_START");let n=I(e.gitDir,"refs","bisect");if(await e.fs.exists(n))try{await e.fs.rm(n,{recursive:!0})}catch{}}async function ed(e,t,n,r,s){let o=[],i=new Map;for await(let g of St(e,t,{exclude:n})){let w=s?g.commit.parents.slice(0,1):g.commit.parents;o.push({hash:g.hash,subject:he(g.commit.message)}),i.set(g.hash,w)}let a=o.length;if(a===0)return null;if(a===1)return{hash:o[0].hash,subject:o[0].subject,remaining:0,steps:0,found:!0,onlySkippedLeft:!1};let c=new Set(o.map(g=>g.hash)),f=new Map;for(let g of o){let w=new Set,b=[g.hash],y=0;for(;yg.hash===l),h=ig(a),p=ag(a);return{hash:m.hash,subject:m.subject,remaining:h,steps:p,found:!1,onlySkippedLeft:u}}function ig(e){return Math.floor((e-1)/2)}function ag(e){return e<=1?0:Math.ceil(Math.log2(e))}function td(e){let t=e.badHash!=null,n=e.goodHashes.length;return!t&&n===0?`status: waiting for both ${e.termGood} and ${e.termBad} commits + `:t?n===0?`status: waiting for ${e.termGood} commit(s), ${e.termBad} commit known + `:"":`status: waiting for ${e.termBad} commit, ${n} ${e.termGood} commit(s) known +-`}function zl(e){return`Bisecting: ${e.remaining} revision${e.remaining===1?"":"s"} left to test after this (roughly ${e.steps} step${e.steps===1?"":"s"}) ++`}function nd(e){return`Bisecting: ${e.remaining} revision${e.remaining===1?"":"s"} left to test after this (roughly ${e.steps} step${e.steps===1?"":"s"}) + [${e.hash}] ${e.subject} +-`}async function Kl(e,t){let n=await M(e,t),r=me(n.message),s=new Date(n.author.timestamp*1e3).toUTCString().replace("GMT","+0000"),i=`${t} is the first bad commit ++`}async function rd(e,t){let n=await M(e,t),r=he(n.message),o=new Date(n.author.timestamp*1e3).toUTCString().replace("GMT","+0000"),i=`${t} is the first bad commit + `;return i+=`commit ${t} + `,i+=`Author: ${n.author.name} <${n.author.email}> +-`,i+=`Date: ${s} ++`,i+=`Date: ${o} + `,i+=` + `,i+=` ${r} + `,i+=` +-`,i}ne();fr();Be();ir();ve();ae();ge();Ve();ye();ne();fr();Be();ve();ae();ge();ae();Mn();ge();function dr(e){return I(e.gitDir,"rebase-merge")}async function wn(e){return e.fs.exists(dr(e))}async function Bt(e){let t=dr(e);if(!await e.fs.exists(t))return null;let n=await e.fs.readFile(I(t,"head-name")),r=await e.fs.readFile(I(t,"orig-head")),o=await e.fs.readFile(I(t,"onto")),s=Number.parseInt(await e.fs.readFile(I(t,"msgnum")),10),i=Number.parseInt(await e.fs.readFile(I(t,"end")),10),a=await e.fs.exists(I(t,"git-rebase-todo"))?I(t,"git-rebase-todo"):I(t,"todo"),c=Vl(await e.fs.readFile(a)),f=await e.fs.exists(I(t,"done"))?await e.fs.readFile(I(t,"done")):"",l=Vl(f),d=await e.fs.exists(I(t,"reflog-action"))?(await e.fs.readFile(I(t,"reflog-action"))).trim():"rebase",u=await e.fs.exists(I(t,"quiet"));return{headName:n.trim(),origHead:r.trim(),onto:o.trim(),todo:c,done:l,msgnum:s,end:i,reflogAction:d,...u?{quiet:u}:{}}}async function Ya(e,t){let n=dr(e);await e.fs.mkdir(n,{recursive:!0}),await e.fs.writeFile(I(n,"head-name"),`${t.headName} ++`,i}te();fr();We();ir();Se();ie();ge();Xe();ye();te();fr();We();Se();ie();ge();ie();On();ge();function dr(e){return I(e.gitDir,"rebase-merge")}async function En(e){return e.fs.exists(dr(e))}async function zt(e){let t=dr(e);if(!await e.fs.exists(t))return null;let n=await e.fs.readFile(I(t,"head-name")),r=await e.fs.readFile(I(t,"orig-head")),s=await e.fs.readFile(I(t,"onto")),o=Number.parseInt(await e.fs.readFile(I(t,"msgnum")),10),i=Number.parseInt(await e.fs.readFile(I(t,"end")),10),a=await e.fs.exists(I(t,"git-rebase-todo"))?I(t,"git-rebase-todo"):I(t,"todo"),c=sd(await e.fs.readFile(a)),f=await e.fs.exists(I(t,"done"))?await e.fs.readFile(I(t,"done")):"",l=sd(f),d=await e.fs.exists(I(t,"reflog-action"))?(await e.fs.readFile(I(t,"reflog-action"))).trim():"rebase",u=await e.fs.exists(I(t,"quiet"));return{headName:n.trim(),origHead:r.trim(),onto:s.trim(),todo:c,done:l,msgnum:o,end:i,reflogAction:d,...u?{quiet:u}:{}}}async function sc(e,t){let n=dr(e);await e.fs.mkdir(n,{recursive:!0}),await e.fs.writeFile(I(n,"head-name"),`${t.headName} + `),await e.fs.writeFile(I(n,"orig-head"),`${t.origHead} + `),await e.fs.writeFile(I(n,"onto"),`${t.onto} + `),await e.fs.writeFile(I(n,"msgnum"),`${String(t.msgnum)} + `),await e.fs.writeFile(I(n,"end"),`${String(t.end)} + `),await e.fs.writeFile(I(n,"reflog-action"),`${t.reflogAction??"rebase"} +-`),await e.fs.writeFile(I(n,"git-rebase-todo"),ei(t.todo)),await e.fs.writeFile(I(n,"done"),ei(t.done)),await e.fs.writeFile(I(n,"interactive"),""),t.quiet&&await e.fs.writeFile(I(n,"quiet"),"")}async function Zl(e){let t=dr(e),n=await Bt(e);if(!n)throw new Error("No rebase in progress");let r=n.todo.shift();r&&n.done.push(r),n.msgnum=n.done.length,await e.fs.writeFile(I(t,"msgnum"),`${String(n.msgnum)} +-`),await e.fs.writeFile(I(t,"git-rebase-todo"),ei(n.todo)),await e.fs.writeFile(I(t,"done"),ei(n.done))}async function Xa(e){let t=dr(e);await e.fs.exists(t)&&await e.fs.rm(t,{recursive:!0})}async function ti(e,t,n){let r=dr(e),o=`@${n.timestamp} ${n.timezone}`;await e.fs.writeFile(I(r,"author-script"),`GIT_AUTHOR_NAME='${n.name}' ++`),await e.fs.writeFile(I(n,"git-rebase-todo"),li(t.todo)),await e.fs.writeFile(I(n,"done"),li(t.done)),await e.fs.writeFile(I(n,"interactive"),""),t.quiet&&await e.fs.writeFile(I(n,"quiet"),"")}async function ad(e){let t=dr(e),n=await zt(e);if(!n)throw new Error("No rebase in progress");let r=n.todo.shift();r&&n.done.push(r),n.msgnum=n.done.length,await e.fs.writeFile(I(t,"msgnum"),`${String(n.msgnum)} ++`),await e.fs.writeFile(I(t,"git-rebase-todo"),li(n.todo)),await e.fs.writeFile(I(t,"done"),li(n.done))}async function oc(e){let t=dr(e);await e.fs.exists(t)&&await e.fs.rm(t,{recursive:!0})}async function di(e,t,n){let r=dr(e),s=`@${n.timestamp} ${n.timezone}`;await e.fs.writeFile(I(r,"author-script"),`GIT_AUTHOR_NAME='${n.name}' + GIT_AUTHOR_EMAIL='${n.email}' +-GIT_AUTHOR_DATE='${o}' ++GIT_AUTHOR_DATE='${s}' + `),await e.fs.writeFile(I(r,"stopped-sha"),`${t} +-`)}function Vl(e){let t=[];for(let n of e.split(` +-`)){let r=n.trim();if(!r||r.startsWith("#"))continue;let o=r.match(/^pick\s+([0-9a-f]+)\s+(.*)/);if(o?.[1]&&o[2]){let s=o[2],i=s.endsWith(" # empty");i&&(s=s.slice(0,-8));let a=s.startsWith("# ")?s.slice(2):s;t.push(i?{hash:o[1],subject:a,empty:i}:{hash:o[1],subject:a})}}return t}function ei(e){return e.length===0?"":`${e.map(t=>`pick ${t.hash} # ${t.subject}${t.empty?" # empty":""}`).join(` ++`)}function sd(e){let t=[];for(let n of e.split(` ++`)){let r=n.trim();if(!r||r.startsWith("#"))continue;let s=r.match(/^pick\s+([0-9a-f]+)\s+(.*)/);if(s?.[1]&&s[2]){let o=s[2],i=o.endsWith(" # empty");i&&(o=o.slice(0,-8));let a=o.startsWith("# ")?o.slice(2):o;t.push(i?{hash:s[1],subject:a,empty:i}:{hash:s[1],subject:a})}}return t}function li(e){return e.length===0?"":`${e.map(t=>`pick ${t.hash} # ${t.subject}${t.empty?" # empty":""}`).join(` + `)} +-`}async function Ql(e,t,n){let r=new Map,[o,s]=await Promise.all([Yl(e,t,r),Yl(e,n,r)]),i=new Set;for(let c of s)o.has(c)||i.add(c);let a=new Set;for(let c of o)s.has(c)||a.add(c);return{right:await Xl(e,r,n,i),left:await Xl(e,r,t,a)}}async function Yl(e,t,n){let r=new Set,o=[t],s=0;for(;sf.commit.committer.timestamp-l.commit.committer.timestamp);let i=s.map(f=>f.hash),a=[],c=new Set;for(;i.length>0;){let f=i.pop();if(!f||c.has(f))continue;c.add(f);let l=await Jo(e,f,t);l.commit.parents.length<=1&&a.push(l);for(let d of l.commit.parents)if(r.has(d)&&!c.has(d)){let u=(o.get(d)??0)-1;o.set(d,u),u<=0&&i.push(d)}}return a.reverse(),a}async function Jo(e,t,n){let r=n.get(t);if(r)return r;let o=await be(e,t);if(o.type!=="commit")throw new Error(`Expected commit object, got ${o.type}`);let s={hash:t,commit:Rn(o.content)};return n.set(t,s),s}ye();ae();Be();function as(e){let t=e.lastIndexOf("/");return t>=0?e.slice(t+1):e}function Bp(e,t){if(e.length===0)return;if(e.length===1)return e.shift();let n=as(t),r=0;for(let o=0;of.commit.committer.timestamp-l.commit.committer.timestamp);let i=o.map(f=>f.hash),a=[],c=new Set;for(;i.length>0;){let f=i.pop();if(!f||c.has(f))continue;c.add(f);let l=await fi(e,f,t);l.commit.parents.length<=1&&a.push(l);for(let d of l.commit.parents)if(r.has(d)&&!c.has(d)){let u=(s.get(d)??0)-1;s.set(d,u),u<=0&&i.push(d)}}return a.reverse(),a}async function fi(e,t,n){let r=n.get(t);if(r)return r;let s=await me(e,t);if(s.type!=="commit")throw new Error(`Expected commit object, got ${s.type}`);let o={hash:t,commit:en(s.content)};return n.set(t,o),o}ye();ie();We();function ls(e){let t=e.lastIndexOf("/");return t>=0?e.slice(t+1):e}function cg(e,t){if(e.length===0)return;if(e.length===1)return e.shift();let n=ls(t),r=0;for(let s=0;s0){let p=Bp(h,u.path);p&&f.push({oldPath:p.path,newPath:u.path,oldHash:p.oldHash??m,newHash:m,similarity:100,oldMode:p.oldMode,newMode:u.newMode})}else l.push(u)}let d=[...s.values()].flat();if(d.length>0&&l.length>0){let u=await zp(e,d,l,r);if(u.length>0){let m=new Set(u.map(p=>p.oldPath)),h=new Set(u.map(p=>p.newPath));d=d.filter(p=>!m.has(p.path)),l=l.filter(p=>!h.has(p.path)),f.push(...u)}}if(o>0&&d.length*l.length>o*o)return{remaining:[...c,...d,...l],renames:f,neededRenameLimit:Math.max(d.length,l.length)};if(d.length>0&&l.length>0){let u=await Yp(e,d,l,r);if(u.length>0){let m=new Set(u.map(p=>p.oldPath)),h=new Set(u.map(p=>p.newPath));d=d.filter(p=>!m.has(p.path)),l=l.filter(p=>!h.has(p.path)),f.push(...u)}}return{remaining:[...c,...d,...l],renames:f}}async function zp(e,t,n,r){let o=new Map;for(let a=0;a>>25)>>>0,o=(o<<7^c>>>25)>>>0,r=r+a>>>0,n++,n<64&&a!==10)continue;let f=(r+Math.imul(o,97))%ed;t.set(f,(t.get(f)??0)+n),n=0,r=0,o=0}if(n>0){let i=(r+Math.imul(o,97))%ed;t.set(i,(t.get(i)??0)+n)}let s=[];for(let[i,a]of t)s.push({hash:i,count:a});return s.sort((i,a)=>i.hash-a.hash),s}function Kp(e,t){let n=0,r=0,o=0,s=0;for(;o=i.hash)break;r+=f.count,s++}let a=i.count,c=0;if(s=r){let w=as(d.path)===as(h.path)?1:0;i.push({similarity:g,nameScore:w,delIdx:l,addIdx:m})}}}i.sort((l,d)=>d.similarity-l.similarity||d.nameScore-l.nameScore);let a=new Set,c=new Set,f=[];for(let{similarity:l,delIdx:d,addIdx:u}of i){if(a.has(d)||c.has(u))continue;a.add(d),c.add(u);let m=t[d],h=n[u];!m||!h||f.push({oldPath:m.path,newPath:h.path,oldHash:m.oldHash??"",newHash:h.newHash??"",similarity:l,oldMode:m.oldMode,newMode:h.newMode})}return f}function In(e,t){let n=e.length,r=t.length,o=0,s=0;for(;s0?1:0,a=0,c=n,f=r;for(;o-i<=c&&o-i<=f&&c>=0&&f>=0;){if(c===n&&f===r){c--,f--;continue}if(e[c]!==t[f])break;e[c]==="/"&&(a=n-c),c--,f--}let l=Math.max(0,n-o-a),d=Math.max(0,r-o-a),u=e.slice(0,o),m=e.slice(n-a),h=e.slice(o,o+l),p=t.slice(o,o+d);return o+a>0?`${u}{${h} => ${p}}${m}`:`${e} => ${t}`}De();st();async function pt(e,t){let n=await te(e),r=await Z(e),o,s=!1;n&&n.type==="symbolic"?o=Ie(n.target):(s=!0,o="HEAD detached");let i=t?.index??await X(e),a=Ja(i),c=t?.compareHash!==void 0?t.compareHash:r,f=t?.compareHash!==void 0?!t.compareHash:!r,l=await Qa(e,c,i,a),d=t?.untrackedMode??"normal",u=await dt(e,i,{includeUntracked:d!=="no"}),m=[],h=[];for(let w of u)w.status==="untracked"?h.push(w.path):m.push({path:w.path,status:w.status});m.sort((w,b)=>Te(w.path,b.path));let p=new Set(i.entries.map(w=>w.path)),g=d==="no"?[]:d==="all"?[...h].sort(Te):ec(h,p);return Xp(e,r,s,o,i,l,m,a,g,{fromCommit:t?.fromCommit,noWarn:t?.noWarn,isInitial:f,untrackedMode:d})}async function nd(e,t,n){let r=async o=>` pick ${await ue(e,o.hash)} # ${o.subject}${o.empty?" # empty":""}`;if(n.done.length>0){let o=n.done.length;t.push(`Last command${o===1?"":"s"} done (${o} command${o===1?"":"s"} done):`);for(let s of n.done.slice(-2))t.push(await r(s));o>2&&t.push(" (see more in file .git/rebase-merge/done)")}if(n.todo.length>0){let o=n.todo.length;t.push(`Next command${o===1?"":"s"} to do (${o} remaining command${o===1?"":"s"}):`);for(let s of n.todo.slice(0,2))t.push(await r(s));t.push(' (use "git rebase --edit-todo" to view and edit)')}else t.push("No commands remaining.")}async function Xp(e,t,n,r,o,s,i,a,c,f){let l=[],d=!1,u=await z(e,"CHERRY_PICK_HEAD"),m=await z(e,"REVERT_HEAD"),h=await z(e,"MERGE_HEAD"),p=!u&&!h,w=await wn(e)?await Bt(e):null;if(n&&w){let k=await ue(e,w.onto);l.push(`interactive rebase in progress; onto ${k}`)}else if(n){let k=await zs(e);if(k){let E=t===k?"at":"from";l.push(`HEAD detached ${E} ${await ue(e,k)}`)}else l.push("Not currently on any branch.")}else l.push(`On branch ${r}`);let b=f?.isInitial??!t;if(!n&&!w&&!b){let k=await we(e),E=await nn(e,k,r);if(E){let O=ur(E,{abbreviated:f?.fromCommit});for(let $ of O.trimEnd().split(` +-`))l.push($);d=!0}}if(d&&(w||u||m||h)&&l.push(""),w&&h)await nd(e,l,w),l.push(""),a.length>0?(l.push("You have unmerged paths."),l.push(' (fix conflicts and run "git commit")'),l.push(' (use "git merge --abort" to abort the merge)')):(l.push("All conflicts fixed but you are still merging."),l.push(' (use "git commit" to conclude merge)')),d=!0;else if(w){let k=kn(o),E=await e.fs.exists(I(e.gitDir,"MERGE_MSG"));await nd(e,l,w);let $=w.headName==="detached HEAD"?null:Ie(w.headName),T=await ue(e,w.onto),j=$?` branch '${$}' on '${T}'`:"";if(k)l.push(`You are currently rebasing${j}.`),l.push(' (fix conflicts and then run "git rebase --continue")'),l.push(' (use "git rebase --skip" to skip this patch)'),l.push(' (use "git rebase --abort" to check out the original branch)');else if(E)l.push(`You are currently rebasing${j}.`),l.push(' (all conflicts fixed: run "git rebase --continue")');else{let U=j?`You are currently editing a commit while rebasing${j}.`:"You are currently editing a commit during a rebase.";l.push(U),l.push(' (use "git commit --amend" to amend the current commit)'),l.push(' (use "git rebase --continue" once you are satisfied with your changes)')}d=!0}else u?(l.push(`You are currently cherry-picking commit ${await ue(e,u)}.`),a.length>0?l.push(' (fix conflicts and run "git cherry-pick --continue")'):l.push(' (all conflicts fixed: run "git cherry-pick --continue")'),l.push(' (use "git cherry-pick --skip" to skip this patch)'),l.push(' (use "git cherry-pick --abort" to cancel the cherry-pick operation)'),d=!0):m?(l.push(`You are currently reverting commit ${await ue(e,m)}.`),a.length>0?l.push(' (fix conflicts and run "git revert --continue")'):l.push(' (all conflicts fixed: run "git revert --continue")'),l.push(' (use "git revert --skip" to skip this patch)'),l.push(' (use "git revert --abort" to cancel the revert operation)'),d=!0):h&&(a.length>0?(l.push("You have unmerged paths."),l.push(' (fix conflicts and run "git commit")'),l.push(' (use "git merge --abort" to abort the merge)')):(l.push("All conflicts fixed but you are still merging."),l.push(' (use "git commit" to conclude merge)')),d=!0);if(await Ut(e)){let E=(await Ae(e,"BISECT_START"))?.trim()??"";l.push(`You are currently bisecting, started from branch '${E}'.`),l.push(' (use "git bisect reset" to get back to the original branch)'),d=!0}b&&(l.push(""),l.push(f?.fromCommit?"Initial commit":"No commits yet"),d=!0);let R=null;p&&(R=t?' (use "git restore --staged ..." to unstage)':' (use "git rm --cached ..." to unstage)');let x=i.some(k=>k.status==="deleted")?' (use "git add/rm ..." to update what will be committed)':' (use "git add ..." to update what will be committed)',y=!1;if(s.length>0){d&&l.push(""),l.push("Changes to be committed:"),R&&l.push(R);for(let k of s)l.push(` ${rd(k.status,k.path,k.displayPath)}`);l.push(""),y=!0}if(a.length>0){!y&&d&&l.push(""),l.push("Unmerged paths:"),p&&(t?l.push(' (use "git restore --staged ..." to unstage)'):l.push(' (use "git rm --cached ..." to unstage)')),a.some(E=>E.status==="deleted by us"||E.status==="deleted by them"||E.status==="both deleted")?l.push(' (use "git add/rm ..." as appropriate to mark resolution)'):l.push(' (use "git add ..." to mark resolution)');for(let E of a)l.push(` ${Zp(E.status,E.path)}`);l.push(""),y=!0}if(i.length>0){!y&&d&&l.push(""),l.push("Changes not staged for commit:"),l.push(x),l.push(' (use "git restore ..." to discard changes in working directory)');for(let k of i)l.push(` ${rd(k.status,k.path)}`);l.push(""),y=!0}let P=s.length>0||!!h&&a.length===0;if(f?.untrackedMode==="no")P&&(!y&&d&&l.push(""),l.push("Untracked files not listed (use -u option to show untracked files)"));else if(c.length>0){!y&&d&&l.push(""),l.push("Untracked files:"),l.push(' (use "git add ..." to include in what will be committed)');for(let k of c)l.push(` ${k}`);l.push(""),y=!0}return!y&&d&&(f?.noWarn||P)&&l.push(""),!P&&!f?.noWarn&&(!y&&d&&i.length===0&&a.length===0&&c.length===0&&l.push(""),i.length>0||a.length>0?l.push('no changes added to commit (use "git add" and/or "git commit -a")'):c.length>0?l.push('nothing added to commit but untracked files present (use "git add" to track)'):b?l.push('nothing to commit (create/copy files and use "git add" to track)'):f?.untrackedMode==="no"?l.push("nothing to commit (use -u to show untracked files)"):l.push("nothing to commit, working tree clean")),`${l.join(` ++`}async function bt(e,t,n={}){let r=n.threshold??fg,s=n.limit??ic,o=new Map,i=[],a=[],c=[];for(let u of t)if(u.status==="deleted"&&u.oldHash){let m=o.get(u.oldHash)??[];m.push(u),o.set(u.oldHash,m),i.push(u)}else u.status==="added"&&u.newHash?a.push(u):c.push(u);let f=[],l=[];for(let u of a){let m=u.newHash;if(!m){l.push(u);continue}let h=o.get(m);if(h&&h.length>0){let p=cg(h,u.path);p&&f.push({oldPath:p.path,newPath:u.path,oldHash:p.oldHash??m,newHash:m,similarity:100,oldMode:p.oldMode,newMode:u.newMode})}else l.push(u)}let d=[...o.values()].flat();if(d.length>0&&l.length>0){let u=await dg(e,d,l,r);if(u.length>0){let m=new Set(u.map(p=>p.oldPath)),h=new Set(u.map(p=>p.newPath));d=d.filter(p=>!m.has(p.path)),l=l.filter(p=>!h.has(p.path)),f.push(...u)}}if(s>0&&d.length*l.length>s*s)return{remaining:[...c,...d,...l],renames:f,neededRenameLimit:Math.max(d.length,l.length)};if(d.length>0&&l.length>0){let u=await hg(e,d,l,r);if(u.length>0){let m=new Set(u.map(p=>p.oldPath)),h=new Set(u.map(p=>p.newPath));d=d.filter(p=>!m.has(p.path)),l=l.filter(p=>!h.has(p.path)),f.push(...u)}}return{remaining:[...c,...d,...l],renames:f}}async function dg(e,t,n,r){let s=new Map;for(let a=0;a>>25)>>>0,s=(s<<7^c>>>25)>>>0,r=r+a>>>0,n++,n<64&&a!==10)continue;let f=(r+Math.imul(s,97))%ld;t.set(f,(t.get(f)??0)+n),n=0,r=0,s=0}if(n>0){let i=(r+Math.imul(s,97))%ld;t.set(i,(t.get(i)??0)+n)}let o=[];for(let[i,a]of t)o.push({hash:i,count:a});return o.sort((i,a)=>i.hash-a.hash),o}function ug(e,t){let n=0,r=0,s=0,o=0;for(;s=i.hash)break;r+=f.count,o++}let a=i.count,c=0;if(o=r){let w=ls(d.path)===ls(h.path)?1:0;i.push({similarity:g,nameScore:w,delIdx:l,addIdx:m})}}}i.sort((l,d)=>d.similarity-l.similarity||d.nameScore-l.nameScore);let a=new Set,c=new Set,f=[];for(let{similarity:l,delIdx:d,addIdx:u}of i){if(a.has(d)||c.has(u))continue;a.add(d),c.add(u);let m=t[d],h=n[u];!m||!h||f.push({oldPath:m.path,newPath:h.path,oldHash:m.oldHash??"",newHash:h.newHash??"",similarity:l,oldMode:m.oldMode,newMode:h.newMode})}return f}function Dn(e,t){let n=e.length,r=t.length,s=0,o=0;for(;o0?1:0,a=0,c=n,f=r;for(;s-i<=c&&s-i<=f&&c>=0&&f>=0;){if(c===n&&f===r){c--,f--;continue}if(e[c]!==t[f])break;e[c]==="/"&&(a=n-c),c--,f--}let l=Math.max(0,n-s-a),d=Math.max(0,r-s-a),u=e.slice(0,s),m=e.slice(n-a),h=e.slice(s,s+l),p=t.slice(s,s+d);return s+a>0?`${u}{${h} => ${p}}${m}`:`${e} => ${t}`}Te();ot();async function yt(e,t){let n=await ne(e),r=await Z(e),s,o=!1;n&&n.type==="symbolic"?s=ve(n.target):(o=!0,s="HEAD detached");let i=t?.index??await X(e),a=cc(i),c=t?.compareHash!==void 0?t.compareHash:r,f=t?.compareHash!==void 0?!t.compareHash:!r,l=await ac(e,c,i,a),d=t?.untrackedMode??"normal",u=await pt(e,i,{includeUntracked:d!=="no"}),m=[],h=[];for(let w of u)w.status==="untracked"?h.push(w.path):m.push({path:w.path,status:w.status});m.sort((w,b)=>Ae(w.path,b.path));let p=new Set(i.entries.map(w=>w.path)),g=d==="no"?[]:d==="all"?[...h].sort(Ae):fc(h,p);return pg(e,r,o,s,i,l,m,a,g,{fromCommit:t?.fromCommit,noWarn:t?.noWarn,isInitial:f,untrackedMode:d})}async function ud(e,t,n){let r=async s=>` pick ${await fe(e,s.hash)} # ${s.subject}${s.empty?" # empty":""}`;if(n.done.length>0){let s=n.done.length;t.push(`Last command${s===1?"":"s"} done (${s} command${s===1?"":"s"} done):`);for(let o of n.done.slice(-2))t.push(await r(o));s>2&&t.push(" (see more in file .git/rebase-merge/done)")}if(n.todo.length>0){let s=n.todo.length;t.push(`Next command${s===1?"":"s"} to do (${s} remaining command${s===1?"":"s"}):`);for(let o of n.todo.slice(0,2))t.push(await r(o));t.push(' (use "git rebase --edit-todo" to view and edit)')}else t.push("No commands remaining.")}async function pg(e,t,n,r,s,o,i,a,c,f){let l=[],d=!1,u=await z(e,"CHERRY_PICK_HEAD"),m=await z(e,"REVERT_HEAD"),h=await z(e,"MERGE_HEAD"),p=!u&&!h,w=await En(e)?await zt(e):null;if(n&&w){let E=await fe(e,w.onto);l.push(`interactive rebase in progress; onto ${E}`)}else if(n){let E=await Qs(e);if(E){let R=t===E?"at":"from";l.push(`HEAD detached ${R} ${await fe(e,E)}`)}else l.push("Not currently on any branch.")}else l.push(`On branch ${r}`);let b=f?.isInitial??!t;if(!n&&!w&&!b){let E=await be(e),R=await an(e,E,r);if(R){let O=ur(R,{abbreviated:f?.fromCommit});for(let $ of O.trimEnd().split(` ++`))l.push($);d=!0}}if(d&&(w||u||m||h)&&l.push(""),w&&h)await ud(e,l,w),l.push(""),a.length>0?(l.push("You have unmerged paths."),l.push(' (fix conflicts and run "git commit")'),l.push(' (use "git merge --abort" to abort the merge)')):(l.push("All conflicts fixed but you are still merging."),l.push(' (use "git commit" to conclude merge)')),d=!0;else if(w){let E=xn(s),R=await e.fs.exists(I(e.gitDir,"MERGE_MSG"));await ud(e,l,w);let $=w.headName==="detached HEAD"?null:ve(w.headName),T=await fe(e,w.onto),j=$?` branch '${$}' on '${T}'`:"";if(E)l.push(`You are currently rebasing${j}.`),l.push(' (fix conflicts and then run "git rebase --continue")'),l.push(' (use "git rebase --skip" to skip this patch)'),l.push(' (use "git rebase --abort" to check out the original branch)');else if(R)l.push(`You are currently rebasing${j}.`),l.push(' (all conflicts fixed: run "git rebase --continue")');else{let U=j?`You are currently editing a commit while rebasing${j}.`:"You are currently editing a commit during a rebase.";l.push(U),l.push(' (use "git commit --amend" to amend the current commit)'),l.push(' (use "git rebase --continue" once you are satisfied with your changes)')}d=!0}else u?(l.push(`You are currently cherry-picking commit ${await fe(e,u)}.`),a.length>0?l.push(' (fix conflicts and run "git cherry-pick --continue")'):l.push(' (all conflicts fixed: run "git cherry-pick --continue")'),l.push(' (use "git cherry-pick --skip" to skip this patch)'),l.push(' (use "git cherry-pick --abort" to cancel the cherry-pick operation)'),d=!0):m?(l.push(`You are currently reverting commit ${await fe(e,m)}.`),a.length>0?l.push(' (fix conflicts and run "git revert --continue")'):l.push(' (all conflicts fixed: run "git revert --continue")'),l.push(' (use "git revert --skip" to skip this patch)'),l.push(' (use "git revert --abort" to cancel the revert operation)'),d=!0):h&&(a.length>0?(l.push("You have unmerged paths."),l.push(' (fix conflicts and run "git commit")'),l.push(' (use "git merge --abort" to abort the merge)')):(l.push("All conflicts fixed but you are still merging."),l.push(' (use "git commit" to conclude merge)')),d=!0);if(await Wt(e)){let R=(await He(e,"BISECT_START"))?.trim()??"";l.push(`You are currently bisecting, started from branch '${R}'.`),l.push(' (use "git bisect reset" to get back to the original branch)'),d=!0}b&&(l.push(""),l.push(f?.fromCommit?"Initial commit":"No commits yet"),d=!0);let y=null;p&&(y=t?' (use "git restore --staged ..." to unstage)':' (use "git rm --cached ..." to unstage)');let x=i.some(E=>E.status==="deleted")?' (use "git add/rm ..." to update what will be committed)':' (use "git add ..." to update what will be committed)',k=!1;if(o.length>0){d&&l.push(""),l.push("Changes to be committed:"),y&&l.push(y);for(let E of o)l.push(` ${md(E.status,E.path,E.displayPath)}`);l.push(""),k=!0}if(a.length>0){!k&&d&&l.push(""),l.push("Unmerged paths:"),p&&(t?l.push(' (use "git restore --staged ..." to unstage)'):l.push(' (use "git rm --cached ..." to unstage)')),a.some(R=>R.status==="deleted by us"||R.status==="deleted by them"||R.status==="both deleted")?l.push(' (use "git add/rm ..." as appropriate to mark resolution)'):l.push(' (use "git add ..." to mark resolution)');for(let R of a)l.push(` ${gg(R.status,R.path)}`);l.push(""),k=!0}if(i.length>0){!k&&d&&l.push(""),l.push("Changes not staged for commit:"),l.push(x),l.push(' (use "git restore ..." to discard changes in working directory)');for(let E of i)l.push(` ${md(E.status,E.path)}`);l.push(""),k=!0}let P=o.length>0||!!h&&a.length===0;if(f?.untrackedMode==="no")P&&(!k&&d&&l.push(""),l.push("Untracked files not listed (use -u option to show untracked files)"));else if(c.length>0){!k&&d&&l.push(""),l.push("Untracked files:"),l.push(' (use "git add ..." to include in what will be committed)');for(let E of c)l.push(` ${E}`);l.push(""),k=!0}return!k&&d&&(f?.noWarn||P)&&l.push(""),!P&&!f?.noWarn&&(!k&&d&&i.length===0&&a.length===0&&c.length===0&&l.push(""),i.length>0||a.length>0?l.push('no changes added to commit (use "git add" and/or "git commit -a")'):c.length>0?l.push('nothing added to commit but untracked files present (use "git add" to track)'):b?l.push('nothing to commit (create/copy files and use "git add" to track)'):f?.untrackedMode==="no"?l.push("nothing to commit (use -u to show untracked files)"):l.push("nothing to commit, working tree clean")),`${l.join(` + `)} +-`}async function Qa(e,t,n,r){let o=new Set(r?.map(h=>h.path)),s=null;t&&(s=(await M(e,t)).tree);let i=await de(e,s),a=new Map(qe(n).map(h=>[h.path,h])),c=[];for(let[h,p]of a){if(o.has(h))continue;let g=i.get(h);g?g.hash!==p.hash&&c.push({path:h,status:"modified",oldHash:g.hash,newHash:p.hash,oldMode:g.mode,newMode:p.mode.toString(8).padStart(6,"0")}):c.push({path:h,status:"added",newHash:p.hash,newMode:p.mode.toString(8).padStart(6,"0")})}for(let[h,p]of i)o.has(h)||a.has(h)||c.push({path:h,status:"deleted",oldHash:p.hash,oldMode:p.mode});let f=await Rt(e,"status"),{remaining:l,renames:d}=await ht(e,c,{limit:f}),u={added:"new file",deleted:"deleted",modified:"modified"},m=[];for(let h of l){let p=u[h.status];p&&m.push({path:h.path,status:p})}for(let h of d)m.push({path:h.newPath,status:"renamed",displayPath:`${h.oldPath} -> ${h.newPath}`});return m.sort((h,p)=>Te(h.path,p.path))}function Ja(e){let t=new Map;for(let r of e.entries)if(r.stage>0){let o=t.get(r.path);o||(o=new Set,t.set(r.path,o)),o.add(r.stage)}let n=[];for(let[r,o]of t){let s,i=o.has(1),a=o.has(2),c=o.has(3);a&&c?s=i?"both modified":"both added":i&&!a&&!c?s="both deleted":i&&c?s="deleted by us":i&&a?s="deleted by them":a&&!i&&!c?s="added by us":c&&!i&&!a?s="added by them":s="unmerged",n.push({path:r,status:s})}return n.sort((r,o)=>Te(r.path,o.path))}function ec(e,t){if(e.length===0)return[];let n=new Set;for(let o of t){let s=o.indexOf("/");for(;s!==-1;)n.add(o.slice(0,s+1)),s=o.indexOf("/",s+1)}let r=new Set;for(let o of e){let s=o.split("/");if(s.length===1){r.add(o);continue}let i=!1;for(let a=1;a0&&r.push(`ahead ${e.ahead}`),e.behind>0&&r.push(`behind ${e.behind}`),`[${e.upstream}: ${r.join(", ")}]`}if(e.gone)return"[gone]";if(e.ahead===0&&e.behind===0)return"";let n=[];return e.ahead>0&&n.push(`ahead ${e.ahead}`),e.behind>0&&n.push(`behind ${e.behind}`),`[${n.join(", ")}]`}function ur(e,t){if(e.gone)return`Your branch is based on '${e.upstream}', but the upstream is gone. ++`}async function ac(e,t,n,r){let s=new Set(r?.map(h=>h.path)),o=null;t&&(o=(await M(e,t)).tree);let i=await de(e,o),a=new Map(ze(n).map(h=>[h.path,h])),c=[];for(let[h,p]of a){if(s.has(h))continue;let g=i.get(h);g?(g.hash!==p.hash||Number.parseInt(g.mode,8)!==p.mode)&&c.push({path:h,status:"modified",oldHash:g.hash,newHash:p.hash,oldMode:g.mode,newMode:p.mode.toString(8).padStart(6,"0")}):c.push({path:h,status:"added",newHash:p.hash,newMode:p.mode.toString(8).padStart(6,"0")})}for(let[h,p]of i)s.has(h)||a.has(h)||c.push({path:h,status:"deleted",oldHash:p.hash,oldMode:p.mode});let f=await xt(e,"status"),{remaining:l,renames:d}=await bt(e,c,{limit:f}),u={added:"new file",deleted:"deleted",modified:"modified"},m=[];for(let h of l){let p=u[h.status];p&&m.push({path:h.path,status:p})}for(let h of d)m.push({path:h.newPath,status:"renamed",displayPath:`${h.oldPath} -> ${h.newPath}`});return m.sort((h,p)=>Ae(h.path,p.path))}function cc(e){let t=new Map;for(let r of e.entries)if(r.stage>0){let s=t.get(r.path);s||(s=new Set,t.set(r.path,s)),s.add(r.stage)}let n=[];for(let[r,s]of t){let o,i=s.has(1),a=s.has(2),c=s.has(3);a&&c?o=i?"both modified":"both added":i&&!a&&!c?o="both deleted":i&&c?o="deleted by us":i&&a?o="deleted by them":a&&!i&&!c?o="added by us":c&&!i&&!a?o="added by them":o="unmerged",n.push({path:r,status:o})}return n.sort((r,s)=>Ae(r.path,s.path))}function fc(e,t){if(e.length===0)return[];let n=new Set;for(let s of t){let o=s.indexOf("/");for(;o!==-1;)n.add(s.slice(0,o+1)),o=s.indexOf("/",o+1)}let r=new Set;for(let s of e){let o=s.split("/");if(o.length===1){r.add(s);continue}let i=!1;for(let a=1;a0&&r.push(`ahead ${e.ahead}`),e.behind>0&&r.push(`behind ${e.behind}`),`[${e.upstream}: ${r.join(", ")}]`}if(e.gone)return"[gone]";if(e.ahead===0&&e.behind===0)return"";let n=[];return e.ahead>0&&n.push(`ahead ${e.ahead}`),e.behind>0&&n.push(`behind ${e.behind}`),`[${n.join(", ")}]`}function ur(e,t){if(e.gone)return`Your branch is based on '${e.upstream}', but the upstream is gone. + (use "git branch --unset-upstream" to fixup) + `;if(e.ahead===0&&e.behind===0)return`Your branch is up to date with '${e.upstream}'. + `;if(e.ahead>0&&e.behind===0){let r=e.ahead===1?"commit":"commits";return`Your branch is ahead of '${e.upstream}' by ${e.ahead} ${r}. +@@ -126,34 +126,34 @@ warning: you may want to set your ${e}.renameLimit variable to at least ${t} and + `}let n=`Your branch and '${e.upstream}' have diverged, + and have ${e.ahead} and ${e.behind} different commits each, respectively. + `;return t?.abbreviated?n:n+` (use "git pull" if you want to integrate the remote branch with yours) +-`}cn();De();Jt();st();async function tc(e){let t=await vt(e,"HEAD");for(let n=t.length-1;n>=0;n--){let r=t[n];if(!r)continue;let o=r.message.match(/^checkout: moving from (.+) to (.+)$/);if(!o?.[1])continue;let s=o[1],i=`refs/heads/${s}`,a=await z(e,i);if(a)return{kind:"branch",name:s,refName:i,hash:a};let c=await Ge(e,s,`a branch is expected, got commit '${s}'`);return D(c)?null:{kind:"commit",target:s}}return null}async function od(e){let t=await tc(e);return t?.kind==="branch"?t:null}async function Wn(e,t=!1){if(t)return await lr(e),"";let n="";return await z(e,"CHERRY_PICK_HEAD")&&(n=`warning: cancelling a cherry picking in progress ++`}un();Te();rn();ot();async function lc(e){let t=await Tt(e,"HEAD");for(let n=t.length-1;n>=0;n--){let r=t[n];if(!r)continue;let s=r.message.match(/^checkout: moving from (.+) to (.+)$/);if(!s?.[1])continue;let o=s[1],i=`refs/heads/${o}`,a=await z(e,i);if(a)return{kind:"branch",name:o,refName:i,hash:a};let c=await Le(e,o,`a branch is expected, got commit '${o}'`);return D(c)?null:{kind:"commit",target:o}}return null}async function pd(e){let t=await lc(e);return t?.kind==="branch"?t:null}async function qn(e,t=!1){if(t)return await lr(e),"";let n="";return await z(e,"CHERRY_PICK_HEAD")&&(n=`warning: cancelling a cherry picking in progress + `),await z(e,"REVERT_HEAD")&&(n+=`warning: cancelling a revert in progress +-`),await lr(e),n}function nc(e){let t=new Set,n=[];for(let r of e.entries)r.stage>0&&!t.has(r.path)&&(t.add(r.path),n.push(`${r.path}: needs merge`));return n.sort(),n.length>0?`${n.join(` ++`),await lr(e),n}function dc(e){let t=new Set,n=[];for(let r of e.entries)r.stage>0&&!t.has(r.path)&&(t.add(r.path),n.push(`${r.path}: needs merge`));return n.sort(),n.length>0?`${n.join(` + `)} +-`:""}function mr(e){return e.entries.some(t=>t.stage>0)?{stdout:nc(e),stderr:`error: you need to resolve your current index first +-`,exitCode:1}:null}async function si(e,t,n,r){if(!e.workTree)return v("this operation must be run in a work tree");if(r)return Qp(e,t,n,r);let o=await X(e),s=t.map(a=>We(a,n)),i=o.entries.filter(a=>a.stage===0&&Pe(s,a.path));if(i.length===0)return o.entries.some(c=>c.stage>0&&Pe(s,c.path))?F(`error: path '${t[0]}' is unmerged +-`):F(`error: pathspec '${t[0]}' did not match any file(s) known to git +-`);for(let a of i)await at(e,{path:a.path,hash:a.hash,mode:a.mode});return{stdout:"",stderr:"",exitCode:0}}async function Qp(e,t,n,r){let o=await de(e,r),s=await X(e),i=t.map(c=>We(c,n)),a=[];for(let[c]of o)Pe(i,c)&&a.push(c);if(a.length===0)return F(`error: pathspec '${t[0]}' did not match any file(s) known to git +-`);for(let c of a){let f=o.get(c);f&&(await at(e,{path:f.path,hash:f.hash,mode:f.mode}),s=Mt(s,{path:f.path,hash:f.hash,mode:parseInt(f.mode,8),stage:0,stat:Fe()}))}return s=await rr(e,s,a),await ie(e,s),{stdout:"",stderr:"",exitCode:0}}async function oi(e,t,n,r,o){if(!e.workTree)return v("this operation must be run in a work tree");let s=o?.deleteOnMissing??!1,i=await X(e),a=t.map(f=>We(f,n)),c=new Set;for(let f of i.entries)Pe(a,f.path)&&c.add(f.path);if(c.size===0)return F(`error: pathspec '${t[0]}' did not match any file(s) known to git +-`);for(let f of c){let l=i.entries.find(m=>m.path===f&&m.stage===r),d=!l&&i.entries.find(m=>m.path===f&&m.stage===0),u=l||d;if(u)await at(e,{path:u.path,hash:u.hash,mode:u.mode});else if(s){let m=I(e.workTree,f);await e.fs.exists(m)&&await e.fs.rm(m)}else if(i.entries.some(h=>h.path===f&&h.stage>0))return F(`error: path '${f}' does not have ${r===2?"our":"their"} version +-`)}return{stdout:"",stderr:"",exitCode:0}}async function hr(e,t,n){if(!e.workTree)return"";let r=await ze(e,t),o=new Map;for(let c of r)Yt(c.mode)||o.set(c.path,c.hash);let s=new Map;for(let c of n.entries)c.stage===0&&s.set(c.path,c.hash);let i=new Map;for(let[c]of s){let f=I(e.workTree,c);await e.fs.exists(f)?(await e.fs.stat(f)).isFile&&i.set(c,await $t(e,f,s.get(c))):i.set(c,null)}let a=[];for(let[c,f]of o){let l=s.get(c);if(l===void 0){a.push(`D ${c}`);continue}let d=i.get(c);d===null?a.push(`D ${c}`):(l!==f||d!==void 0&&d!==f)&&a.push(`M ${c}`)}for(let[c]of s)o.has(c)||i.get(c)!=null&&a.push(`A ${c}`);return a.length===0?"":(a.sort((c,f)=>{let l=c.slice(2),d=f.slice(2);return ld?1:0}),`${a.join(` ++`:""}function mr(e){return e.entries.some(t=>t.stage>0)?{stdout:dc(e),stderr:`error: you need to resolve your current index first ++`,exitCode:1}:null}async function hi(e,t,n,r){if(!e.workTree)return v("this operation must be run in a work tree");if(r)return wg(e,t,n,r);let s=await X(e),o=t.map(a=>qe(a,n)),i=s.entries.filter(a=>a.stage===0&&Pe(o,a.path));if(i.length===0)return s.entries.some(c=>c.stage>0&&Pe(o,c.path))?N(`error: path '${t[0]}' is unmerged ++`):N(`error: pathspec '${t[0]}' did not match any file(s) known to git ++`);for(let a of i)await lt(e,{path:a.path,hash:a.hash,mode:a.mode});return{stdout:"",stderr:"",exitCode:0}}async function wg(e,t,n,r){let s=await de(e,r),o=await X(e),i=t.map(c=>qe(c,n)),a=[];for(let[c]of s)Pe(i,c)&&a.push(c);if(a.length===0)return N(`error: pathspec '${t[0]}' did not match any file(s) known to git ++`);for(let c of a){let f=s.get(c);f&&(await lt(e,{path:f.path,hash:f.hash,mode:f.mode}),o=jt(o,{path:f.path,hash:f.hash,mode:parseInt(f.mode,8),stage:0,stat:Ge()}))}return o=await rr(e,o,a),await oe(e,o),{stdout:"",stderr:"",exitCode:0}}async function pi(e,t,n,r,s){if(!e.workTree)return v("this operation must be run in a work tree");let o=s?.deleteOnMissing??!1,i=await X(e),a=t.map(f=>qe(f,n)),c=new Set;for(let f of i.entries)Pe(a,f.path)&&c.add(f.path);if(c.size===0)return N(`error: pathspec '${t[0]}' did not match any file(s) known to git ++`);for(let f of c){let l=i.entries.find(m=>m.path===f&&m.stage===r),d=!l&&i.entries.find(m=>m.path===f&&m.stage===0),u=l||d;if(u)await lt(e,{path:u.path,hash:u.hash,mode:u.mode});else if(o){let m=I(e.workTree,f);await e.fs.exists(m)&&await e.fs.rm(m)}else if(i.entries.some(h=>h.path===f&&h.stage>0))return N(`error: path '${f}' does not have ${r===2?"our":"their"} version ++`)}return{stdout:"",stderr:"",exitCode:0}}async function hr(e,t,n){if(!e.workTree)return"";let r=await Ke(e,t),s=new Map;for(let c of r)Jt(c.mode)||s.set(c.path,c.hash);let o=new Map;for(let c of n.entries)c.stage===0&&o.set(c.path,c.hash);let i=new Map;for(let[c]of o){let f=I(e.workTree,c);await e.fs.exists(f)?(await e.fs.stat(f)).isFile&&i.set(c,await Ot(e,f,o.get(c))):i.set(c,null)}let a=[];for(let[c,f]of s){let l=o.get(c);if(l===void 0){a.push(`D ${c}`);continue}let d=i.get(c);d===null?a.push(`D ${c}`):(l!==f||d!==void 0&&d!==f)&&a.push(`M ${c}`)}for(let[c]of o)s.has(c)||i.get(c)!=null&&a.push(`A ${c}`);return a.length===0?"":(a.sort((c,f)=>{let l=c.slice(2),d=f.slice(2);return ld?1:0}),`${a.join(` + `)} +-`)}var sd=5;async function Jp(e,t){let n=t.length,r=n===1?"commit":"commits",o=n===1?"it":"them",s=n>sd?sd-1:n,i=t.slice(0,s),a=await Promise.all(i.map(d=>ue(e,d.hash))),c=i.map((d,u)=>` ${a[u]} ${d.subject}`),f=n-s;f>0&&c.push(` ... and ${f} more.`);let l=a[0];return`Warning: you are leaving ${n} ${r} behind, not connected to ++`)}var hd=5;async function bg(e,t){let n=t.length,r=n===1?"commit":"commits",s=n===1?"it":"them",o=n>hd?hd-1:n,i=t.slice(0,o),a=await Promise.all(i.map(d=>fe(e,d.hash))),c=i.map((d,u)=>` ${a[u]} ${d.subject}`),f=n-o;f>0&&c.push(` ... and ${f} more.`);let l=a[0];return`Warning: you are leaving ${n} ${r} behind, not connected to + any of your branches: + + ${c.join(` + `)} + +-If you want to keep ${o} by creating a new branch, this may be a good time ++If you want to keep ${s} by creating a new branch, this may be a good time + to do so with: + + git branch ${l} + +-`}async function rc(e,t){let n=await M(e,t);return`Previous HEAD position was ${await ue(e,t)} ${me(n.message)} +-`}async function ii(e,t,n){let r=await Ka(e,t,{targetHash:n});return r.length>0?Jp(e,r):t!==n?rc(e,t):""}async function Mr(e,t,n,r,o,s,i){let a=i?.quiet??!1,c=await te(e);if(c?.type==="symbolic"&&c.target===n)return{stdout:"",stderr:a?"":`Already on '${t}' +-`,exitCode:0};let f=await X(e),l=mr(f);if(l)return l;let d=await Z(e),m=(await M(e,r)).tree,h=null;if(d&&(h=(await M(e,d)).tree),h!==m){let x=await On(e,h,m,f);if(!x.success)return x.errorOutput??F("error: checkout would overwrite local changes");f={version:2,entries:x.newEntries},await ie(e,f),await je(e,x.worktreeOps)}let p="";!a&&c?.type==="direct"&&d&&(p=await ii(e,d,r));let g=c?.type==="symbolic"?c.target.replace(/^refs\/heads\//,""):d??oe;await ot(e,"HEAD",n),await Tt(e);let w=await Wn(e,a);if(await ee(e,o,"HEAD",d,r,`checkout: moving from ${g} to ${t}`),await s?.hooks?.postCheckout?.({repo:e,prevHead:d,newHead:r,isBranchCheckout:!0}),a)return{stdout:"",stderr:"",exitCode:0};let b=await hr(e,m,f),R=await we(e),C=await nn(e,R,t);return C&&(b+=ur(C)),{stdout:b,stderr:`${p}Switched to ${i?.isNew?"a new ":""}branch '${t}' +-${w}`,exitCode:0}}async function pr(e,t,n,r,o){let s=o?.quiet??!1,i=await X(e),a=mr(i);if(a)return a;let c=await Z(e),f=await M(e,t),l=f.tree,d=null;if(c&&(d=(await M(e,c)).tree),d!==l){let C=await On(e,d,l,i);if(!C.success)return C.errorOutput??F("error: checkout would overwrite local changes");i={version:2,entries:C.newEntries},await ie(e,i),await je(e,C.worktreeOps)}let u=await te(e),m=u?.type==="direct"&&c===t;if(await Q(e,"HEAD",t),!m){await Bl(e,t);let C=u?.type==="symbolic"?u.target.replace(/^refs\/heads\//,""):c??oe;await ee(e,n,"HEAD",c,t,`checkout: moving from ${C} to ${t}`)}let h=await Wn(e,s);if(await r?.hooks?.postCheckout?.({repo:e,prevHead:c,newHead:t,isBranchCheckout:!1}),s)return{stdout:"",stderr:"",exitCode:0};let p=await ue(e,t),g=me(f.message),w=u?.type==="direct",b="";return w&&c&&c!==t&&(b+=await ii(e,c,t)),w||!o?.detachAdviceTarget?b+=`HEAD is now at ${p} ${g} +-`:b=`Note: switching to '${o.detachAdviceTarget}'. ++`}async function uc(e,t){let n=await M(e,t);return`Previous HEAD position was ${await fe(e,t)} ${he(n.message)} ++`}async function gi(e,t,n){let r=await nc(e,t,{targetHash:n});return r.length>0?bg(e,r):t!==n?uc(e,t):""}async function Fr(e,t,n,r,s,o,i){let a=i?.quiet??!1,c=await ne(e);if(c?.type==="symbolic"&&c.target===n)return{stdout:"",stderr:a?"":`Already on '${t}' ++`,exitCode:0};let f=await X(e),l=mr(f);if(l)return l;let d=await Z(e),m=(await M(e,r)).tree,h=null;if(d&&(h=(await M(e,d)).tree),h!==m){let x=await Tn(e,h,m,f);if(!x.success)return x.errorOutput??N("error: checkout would overwrite local changes");f={version:2,entries:x.newEntries},await oe(e,f),await Me(e,x.worktreeOps)}let p="";!a&&c?.type==="direct"&&d&&(p=await gi(e,d,r));let g=c?.type==="symbolic"?c.target.replace(/^refs\/heads\//,""):d??se;await ct(e,"HEAD",n),await Ht(e);let w=await qn(e,a);if(await ee(e,s,"HEAD",d,r,`checkout: moving from ${g} to ${t}`),await o?.hooks?.postCheckout?.({repo:e,prevHead:d,newHead:r,isBranchCheckout:!0}),a)return{stdout:"",stderr:"",exitCode:0};let b=await hr(e,m,f),y=await be(e),C=await an(e,y,t);return C&&(b+=ur(C)),{stdout:b,stderr:`${p}Switched to ${i?.isNew?"a new ":""}branch '${t}' ++${w}`,exitCode:0}}async function pr(e,t,n,r,s){let o=s?.quiet??!1,i=await X(e),a=mr(i);if(a)return a;let c=await Z(e),f=await M(e,t),l=f.tree,d=null;if(c&&(d=(await M(e,c)).tree),d!==l){let C=await Tn(e,d,l,i);if(!C.success)return C.errorOutput??N("error: checkout would overwrite local changes");i={version:2,entries:C.newEntries},await oe(e,i),await Me(e,C.worktreeOps)}let u=await ne(e),m=u?.type==="direct"&&c===t;if(await Q(e,"HEAD",t),!m){await Jl(e,t);let C=u?.type==="symbolic"?u.target.replace(/^refs\/heads\//,""):c??se;await ee(e,n,"HEAD",c,t,`checkout: moving from ${C} to ${t}`)}let h=await qn(e,o);if(await r?.hooks?.postCheckout?.({repo:e,prevHead:c,newHead:t,isBranchCheckout:!1}),o)return{stdout:"",stderr:"",exitCode:0};let p=await fe(e,t),g=he(f.message),w=u?.type==="direct",b="";return w&&c&&c!==t&&(b+=await gi(e,c,t)),w||!s?.detachAdviceTarget?b+=`HEAD is now at ${p} ${g} ++`:b=`Note: switching to '${s.detachAdviceTarget}'. + + You are in 'detached HEAD' state. You can look around, make experimental + changes and commit them, and you can discard any commits you make in this +@@ -171,70 +171,75 @@ Or undo this operation with: + Turn off this advice by setting config variable advice.detachedHead to false + + HEAD is now at ${p} ${g} +-`,b+=h,{stdout:await hr(e,l,i),stderr:b,exitCode:0}}async function eg(e,t){if(t.startsWith("refs/remotes/")){if(!await z(e,t))return null;let s=t.slice(13).split("/");if(s.length<2)return null;let i=s[0],a=s.slice(1).join("/");return{remote:i,branch:a,ref:t}}let n=`refs/remotes/${t}`;if(await z(e,n)){let o=t.split("/");if(o.length<2)return null;let s=o[0],i=o.slice(1).join("/");return{remote:s,branch:i,ref:n}}return null}async function cs(e,t,n){let r=await eg(e,n);if(!r||await Re(e,"branch.autoSetupMerge")==="false")return"";let s=await we(e),i=`branch "${t}"`;return s[i]||(s[i]={}),s[i].remote=r.remote,s[i].merge=`refs/heads/${r.branch}`,await et(e,s),`branch '${t}' set up to track '${r.remote}/${r.branch}'. +-`}async function fs(e,t){let n=await $e(e,"refs/remotes"),r=[];for(let o of n){let s=o.name.replace(/^refs\/remotes\//,"").split("/"),i=s[0];s.length>=2&&i&&s.slice(1).join("/")===t&&r.push({remote:i,ref:o.name})}if(r.length===1){let o=r[0];return{remote:o.remote,startPoint:o.ref,trackingRef:o.ref}}if(r.length>1){let o=await Re(e,"checkout.defaultRemote");if(o){let s=r.filter(i=>i.remote===o);if(s.length===1){let i=s[0];return{remote:i.remote,startPoint:i.ref,trackingRef:i.ref}}}}return null}ae();ge();ye();Qt();Ee();var id=new Set(["help","start","skip","next","reset","visualize","view","replay","log","run","terms"]),Ys={stdout:`You need to start by "git bisect start" +-`,stderr:"",exitCode:1};async function sc(e){let t=await Ae(e,"BISECT_HEAD");if(t?.trim())return t.trim();let n=await Z(e);return n||v("no current commit")}function ad(e,t){let n=e.command("bisect",{description:"Use binary search to find the commit that introduced a bug",args:[W.string().name("subcommand").describe("Subcommand or custom term").optional(),W.string().name("rest").describe("Additional arguments").optional().variadic()],handler:async(r,o)=>{let s=r.subcommand;if(!s)return{stdout:"",stderr:`usage: git bisect [start|bad|good|new|old|terms|skip|next|reset|visualize|view|replay|log|run] +-`,exitCode:1};let i=r.rest??[],a=await q(o.fs,o.cwd,t);return D(a)?a:sg(a,o.env,t,s,i)}});tg(n,t),ng(n,t),og(n,t),ig(n,t),cg(n,t),fg(n,t),dg(n,t),mg(n,t),hg(n,t)}function tg(e,t){e.command("start",{description:"Start bisecting",args:[W.string().name("revs").describe("Bad and good revisions").optional().variadic()],options:{"term-new":K.string().describe("Alternate term for new/bad"),"term-bad":K.string().describe("Alternate term for new/bad"),"term-old":K.string().describe("Alternate term for old/good"),"term-good":K.string().describe("Alternate term for old/good"),"no-checkout":S().describe("Do not checkout the bisection commit"),"first-parent":S().describe("Follow only first parent on merges")},handler:async(n,r)=>{let o=await q(r.fs,r.cwd,t);if(D(o))return o;let s=o,i=tt(s);if(i&&!n["no-checkout"])return i;let a=n["term-new"]??n["term-bad"]??"bad",c=n["term-old"]??n["term-good"]??"good";return id.has(a)?v(`'${a}' is not a valid term`):id.has(c)?v(`'${c}' is not a valid term`):a===c?v("'bad' and 'good' terms must be different"):cd(s,r.env,t,n.revs??[],a,c,n["no-checkout"]??!1,n["first-parent"]??!1)}})}async function cd(e,t,n,r,o,s,i,a){await Ut(e)&&await Qo(e);let c=await te(e),f;if(c?.type==="symbolic"?f=c.target.replace(/^refs\/heads\//,""):f=await Z(e)??"HEAD",await Ue(e,"BISECT_START",f+` +-`),await Ue(e,"BISECT_TERMS",`${o} +-${s} +-`),await Ue(e,"BISECT_NAMES",` +-`),a&&await Ue(e,"BISECT_FIRST_PARENT",""),i){let u=await Z(e);u&&await Ue(e,"BISECT_HEAD",u)}if(r.length>0){let u=r[0],m=await It(e,u);if(D(m))return m;await Q(e,`refs/bisect/${o}`,m);let h=await M(e,m);await _t(e,`# ${o}: [${m}] ${me(h.message)}`);for(let p=1;p`'${u}'`),d=l.length>0?` ${l.join(" ")}`:"";return await _t(e,`git bisect start${d}`),Xs(e,t,n)}function ng(e,t){for(let n of["bad","good","new","old"])e.command(n,{description:n==="bad"||n==="new"?"Mark a commit as bad/new":"Mark a commit as good/old",args:[W.string().name("rev").describe("Revision to mark").optional()],handler:async(r,o)=>{let s=await q(o.fs,o.cwd,t);return D(s)?s:rg(s,o.env,t,n,r.rev)}})}async function rg(e,t,n,r,o){if(!await Ut(e))return Ys;let s=await Ks(e),i=r==="bad"||r==="new"?s.termBad:s.termGood;return Vs(e,t,n,i,s,o)}async function sg(e,t,n,r,o){if(!await Ut(e))return Ys;let s=await Ks(e);return r!==s.termBad&&r!==s.termGood?{stdout:"",stderr:`error: unknown command: 'git bisect ${r}' +-`,exitCode:1}:Vs(e,t,n,r,s,o[0])}async function Vs(e,t,n,r,o,s){let i;if(s){let f=await It(e,s);if(D(f))return f;i=f}else{let f=await sc(e);if(D(f))return f;i=f}let a=await M(e,i),c=me(a.message);return r===o.termBad?await Q(e,`refs/bisect/${o.termBad}`,i):await Q(e,`refs/bisect/${o.termGood}-${i}`,i),await _t(e,`# ${r}: [${i}] ${c}`),await _t(e,`git bisect ${r} ${i}`),Xs(e,t,n)}function og(e,t){e.command("skip",{description:"Mark a commit as untestable",args:[W.string().name("revs").describe("Revisions to skip").optional().variadic()],handler:async(n,r)=>{let o=await q(r.fs,r.cwd,t);if(D(o))return o;let s=o;if(!await Ut(s))return Ys;let i=n.revs??[];if(i.length===0){let a=await sc(s);if(D(a))return a;i.push(a)}for(let a of i){let c;if(a.length===40&&/^[0-9a-f]+$/.test(a))c=a;else{let l=await It(s,a);if(D(l))return l;c=l}await Q(s,`refs/bisect/skip-${c}`,c);let f=await M(s,c);await _t(s,`# skip: [${c}] ${me(f.message)}`),await _t(s,`git bisect skip ${c}`)}return Xs(s,r.env,t)}})}function ig(e,t){e.command("reset",{description:"Finish bisecting and return to original branch",args:[W.string().name("commit").describe("Branch or commit to checkout").optional()],handler:async(n,r)=>{let o=await q(r.fs,r.cwd,t);if(D(o))return o;let s=o;return await Ut(s)?ag(s,r.env,t,n.commit):{stdout:`We are not bisecting. +-`,stderr:"",exitCode:0}}})}async function ag(e,t,n,r){let o=(await Ae(e,"BISECT_START"))?.trim()??"";if(await Qo(e),r){let s=await It(e,r);return D(s)?s:pr(e,s,t,n)}if(o){let s=`refs/heads/${o}`,i=await z(e,s);if(i)return Mr(e,o,s,i,t,n);let a=await Le(e,o);if(a)return pr(e,a,t,n)}return{stdout:"",stderr:"",exitCode:0}}function cg(e,t){e.command("log",{description:"Show the bisect log",handler:async(n,r)=>{let o=await q(r.fs,r.cwd,t);if(D(o))return o;let s=o;return await Ut(s)?{stdout:await Ae(s,"BISECT_LOG")??"",stderr:"",exitCode:0}:{stdout:"",stderr:`error: We are not bisecting. +-`,exitCode:1}}})}function fg(e,t){e.command("replay",{description:"Replay a bisect log",args:[W.string().name("logfile").describe("Path to bisect log file")],handler:async(n,r)=>{let o=await q(r.fs,r.cwd,t);if(D(o))return o;let s=o,i=n.logfile.startsWith("/")?n.logfile:I(r.cwd,n.logfile);if(!await r.fs.exists(i))return v(`cannot open '${n.logfile}': No such file or directory`);let a=await r.fs.readFile(i);return lg(s,r.env,t,a)}})}async function lg(e,t,n,r){await Ut(e)&&await Qo(e);let o={termBad:"bad",termGood:"good"},s="";for(let i of r.split(` +-`)){let a=i.trim();if(!a||a.startsWith("#"))continue;let c=a.match(/^git[\s-]bisect\s+(\S+)(.*)$/);if(!c)continue;let f=c[1],l=c[2].trim(),d;if(f==="start"){let u=l?l.split(/\s+/).map(m=>m.replace(/^'|'$/g,"")):[];d=await cd(e,t,n,u,"bad","good",!1,!1)}else if(f==="bad"||f==="new")d=await Vs(e,t,n,"bad",o,l||void 0);else if(f==="good"||f==="old")d=await Vs(e,t,n,"good",o,l||void 0);else if(f==="skip"){for(let u of l?l.split(/\s+/):[]){await Q(e,`refs/bisect/skip-${u}`,u);let m=await M(e,u);await _t(e,`# skip: [${u}] ${me(m.message)}`),await _t(e,`git bisect skip ${u}`)}d=await Xs(e,t,n)}else continue;if(d.exitCode!==0)return d;s+=d.stdout}return{stdout:s,stderr:"",exitCode:0}}function dg(e,t){e.command("run",{description:"Bisect by running a command",args:[W.string().name("cmd").describe("Command and arguments to run").variadic()],handler:async(n,r)=>{let o=await q(r.fs,r.cwd,t);if(D(o))return o;let s=o;if(!await Ut(s))return Ys;if(!r.exec)return v("bisect run requires shell execution support");let i=n.cmd.join(" ");return ug(s,r.env,t,i,r.exec,r.cwd)}})}async function ug(e,t,n,r,o,s){let i="";for(;;){i+=`running '${r}' +-`;let c=(await o(r,{cwd:s})).exitCode;if(c===125){let u=await sc(e);if(D(u))return u;await Q(e,`refs/bisect/skip-${u}`,u);let m=await M(e,u);await _t(e,`# skip: [${u}] ${me(m.message)}`),await _t(e,`git bisect skip ${u}`);let h=await Xs(e,t,n);if(i+=h.stdout,h.stdout.includes("is the first bad commit"))return i+=`bisect found first bad commit +-`,{stdout:i,stderr:"",exitCode:0};if(h.exitCode!==0)return{stdout:i,stderr:h.stderr,exitCode:h.exitCode};continue}let f=await Zo(e),l=c===0?f.termGood:f.termBad,d=await Vs(e,t,n,l,f,void 0);if(i+=d.stdout,d.stdout.includes("is the first bad commit"))return i+=`bisect found first bad commit +-`,{stdout:i,stderr:"",exitCode:0};if(d.exitCode!==0)return{stdout:i,stderr:d.stderr,exitCode:d.exitCode}}}function mg(e,t){e.command("terms",{description:"Show the terms used for old and new commits",options:{"term-good":S().describe("Show the term for the old state"),"term-bad":S().describe("Show the term for the new state")},handler:async(n,r)=>{let o=await q(r.fs,r.cwd,t);if(D(o))return o;let s=o;if(!await Ut(s))return{stdout:"",stderr:`error: no terms defined +-`,exitCode:1};let{termBad:i,termGood:a}=await Ks(s);return n["term-good"]?{stdout:`${a} ++`,b+=h,{stdout:await hr(e,l,i),stderr:b,exitCode:0}}async function yg(e,t){if(t.startsWith("refs/remotes/")){if(!await z(e,t))return null;let o=t.slice(13).split("/");if(o.length<2)return null;let i=o[0],a=o.slice(1).join("/");return{remote:i,branch:a,ref:t}}let n=`refs/remotes/${t}`;if(await z(e,n)){let s=t.split("/");if(s.length<2)return null;let o=s[0],i=s.slice(1).join("/");return{remote:o,branch:i,ref:n}}return null}async function ds(e,t,n){let r=await yg(e,n);if(!r||await Re(e,"branch.autoSetupMerge")==="false")return"";let o=await be(e),i=`branch "${t}"`;return o[i]||(o[i]={}),o[i].remote=r.remote,o[i].merge=`refs/heads/${r.branch}`,await et(e,o),`branch '${t}' set up to track '${r.remote}/${r.branch}'. ++`}async function us(e,t){let n=await $e(e,"refs/remotes"),r=[];for(let s of n){let o=s.name.replace(/^refs\/remotes\//,"").split("/"),i=o[0];o.length>=2&&i&&o.slice(1).join("/")===t&&r.push({remote:i,ref:s.name})}if(r.length===1){let s=r[0];return{remote:s.remote,startPoint:s.ref,trackingRef:s.ref}}if(r.length>1){let s=await Re(e,"checkout.defaultRemote");if(s){let o=r.filter(i=>i.remote===s);if(o.length===1){let i=o[0];return{remote:i.remote,startPoint:i.ref,trackingRef:i.ref}}}}return null}ie();ge();ye();Ft();ke();var gd=new Set(["help","start","skip","next","reset","visualize","view","replay","log","run","terms"]),to={stdout:`You need to start by "git bisect start" ++`,stderr:"",exitCode:1};async function mc(e){let t=await He(e,"BISECT_HEAD");if(t?.trim())return t.trim();let n=await Z(e);return n||v("no current commit")}function wd(e,t){let n=e.command("bisect",{description:"Use binary search to find the commit that introduced a bug",args:[B.string().name("subcommand").describe("Subcommand or custom term").optional(),B.string().name("rest").describe("Additional arguments").optional().variadic()],handler:async(r,s)=>{let o=r.subcommand;if(!o)return{stdout:"",stderr:`usage: git bisect [start|bad|good|new|old|terms|skip|next|reset|visualize|view|replay|log|run] ++`,exitCode:1};let i=r.rest??[],a=await W(s.fs,s.cwd,t);return D(a)?a:Cg(a,s.env,t,o,i)}});kg(n,t),Eg(n,t),xg(n,t),Pg(n,t),Og(n,t),Sg(n,t),Ig(n,t),Ag(n,t),Hg(n,t)}function kg(e,t){e.command("start",{description:"Start bisecting",args:[B.string().name("revs").describe("Bad and good revisions").optional().variadic()],options:{"term-new":K.string().describe("Alternate term for new/bad"),"term-bad":K.string().describe("Alternate term for new/bad"),"term-old":K.string().describe("Alternate term for old/good"),"term-good":K.string().describe("Alternate term for old/good"),"no-checkout":S().describe("Do not checkout the bisection commit"),"first-parent":S().describe("Follow only first parent on merges")},handler:async(n,r)=>{let s=await W(r.fs,r.cwd,t);if(D(s))return s;let o=s,i=tt(o);if(i&&!n["no-checkout"])return i;let a=n["term-new"]??n["term-bad"]??"bad",c=n["term-old"]??n["term-good"]??"good";return gd.has(a)?v(`'${a}' is not a valid term`):gd.has(c)?v(`'${c}' is not a valid term`):a===c?v("'bad' and 'good' terms must be different"):bd(o,r.env,t,n.revs??[],a,c,n["no-checkout"]??!1,n["first-parent"]??!1)}})}async function bd(e,t,n,r,s,o,i,a){await Wt(e)&&await ci(e);let c=await ne(e),f;if(c?.type==="symbolic"?f=c.target.replace(/^refs\/heads\//,""):f=await Z(e)??"HEAD",await Ne(e,"BISECT_START",f+` ++`),await Ne(e,"BISECT_TERMS",`${s} ++${o} ++`),await Ne(e,"BISECT_NAMES",` ++`),a&&await Ne(e,"BISECT_FIRST_PARENT",""),i){let u=await Z(e);u&&await Ne(e,"BISECT_HEAD",u)}if(r.length>0){let u=r[0],m=await At(e,u);if(D(m))return m;await Q(e,`refs/bisect/${s}`,m);let h=await M(e,m);await qt(e,`# ${s}: [${m}] ${he(h.message)}`);for(let p=1;p`'${u}'`),d=l.length>0?` ${l.join(" ")}`:"";return await qt(e,`git bisect start${d}`),no(e,t,n)}function Eg(e,t){for(let n of["bad","good","new","old"])e.command(n,{description:n==="bad"||n==="new"?"Mark a commit as bad/new":"Mark a commit as good/old",args:[B.string().name("rev").describe("Revision to mark").optional()],handler:async(r,s)=>{let o=await W(s.fs,s.cwd,t);return D(o)?o:Rg(o,s.env,t,n,r.rev)}})}async function Rg(e,t,n,r,s){if(!await Wt(e))return to;let o=await Js(e),i=r==="bad"||r==="new"?o.termBad:o.termGood;return eo(e,t,n,i,o,s)}async function Cg(e,t,n,r,s){if(!await Wt(e))return to;let o=await Js(e);return r!==o.termBad&&r!==o.termGood?{stdout:"",stderr:`error: unknown command: 'git bisect ${r}' ++`,exitCode:1}:eo(e,t,n,r,o,s[0])}async function eo(e,t,n,r,s,o){let i;if(o){let f=await At(e,o);if(D(f))return f;i=f}else{let f=await mc(e);if(D(f))return f;i=f}let a=await M(e,i),c=he(a.message);return r===s.termBad?await Q(e,`refs/bisect/${s.termBad}`,i):await Q(e,`refs/bisect/${s.termGood}-${i}`,i),await qt(e,`# ${r}: [${i}] ${c}`),await qt(e,`git bisect ${r} ${i}`),no(e,t,n)}function xg(e,t){e.command("skip",{description:"Mark a commit as untestable",args:[B.string().name("revs").describe("Revisions to skip").optional().variadic()],handler:async(n,r)=>{let s=await W(r.fs,r.cwd,t);if(D(s))return s;let o=s;if(!await Wt(o))return to;let i=n.revs??[];if(i.length===0){let a=await mc(o);if(D(a))return a;i.push(a)}for(let a of i){let c;if(a.length===40&&/^[0-9a-f]+$/.test(a))c=a;else{let l=await At(o,a);if(D(l))return l;c=l}await Q(o,`refs/bisect/skip-${c}`,c);let f=await M(o,c);await qt(o,`# skip: [${c}] ${he(f.message)}`),await qt(o,`git bisect skip ${c}`)}return no(o,r.env,t)}})}function Pg(e,t){e.command("reset",{description:"Finish bisecting and return to original branch",args:[B.string().name("commit").describe("Branch or commit to checkout").optional()],handler:async(n,r)=>{let s=await W(r.fs,r.cwd,t);if(D(s))return s;let o=s;return await Wt(o)?$g(o,r.env,t,n.commit):{stdout:`We are not bisecting. ++`,stderr:"",exitCode:0}}})}async function $g(e,t,n,r){let s=(await He(e,"BISECT_START"))?.trim()??"";if(await ci(e),r){let o=await At(e,r);return D(o)?o:pr(e,o,t,n)}if(s){let o=`refs/heads/${s}`,i=await z(e,o);if(i)return Fr(e,s,o,i,t,n);let a=await Ie(e,s);if(a)return pr(e,a,t,n)}return{stdout:"",stderr:"",exitCode:0}}function Og(e,t){e.command("log",{description:"Show the bisect log",handler:async(n,r)=>{let s=await W(r.fs,r.cwd,t);if(D(s))return s;let o=s;return await Wt(o)?{stdout:await He(o,"BISECT_LOG")??"",stderr:"",exitCode:0}:{stdout:"",stderr:`error: We are not bisecting. ++`,exitCode:1}}})}function Sg(e,t){e.command("replay",{description:"Replay a bisect log",args:[B.string().name("logfile").describe("Path to bisect log file")],handler:async(n,r)=>{let s=await W(r.fs,r.cwd,t);if(D(s))return s;let o=s,i=n.logfile.startsWith("/")?n.logfile:I(r.cwd,n.logfile);if(!await r.fs.exists(i))return v(`cannot open '${n.logfile}': No such file or directory`);let a=await r.fs.readFile(i);return vg(o,r.env,t,a)}})}async function vg(e,t,n,r){await Wt(e)&&await ci(e);let s={termBad:"bad",termGood:"good"},o="";for(let i of r.split(` ++`)){let a=i.trim();if(!a||a.startsWith("#"))continue;let c=a.match(/^git[\s-]bisect\s+(\S+)(.*)$/);if(!c)continue;let f=c[1],l=c[2].trim(),d;if(f==="start"){let u=l?l.split(/\s+/).map(m=>m.replace(/^'|'$/g,"")):[];d=await bd(e,t,n,u,"bad","good",!1,!1)}else if(f==="bad"||f==="new")d=await eo(e,t,n,"bad",s,l||void 0);else if(f==="good"||f==="old")d=await eo(e,t,n,"good",s,l||void 0);else if(f==="skip"){for(let u of l?l.split(/\s+/):[]){await Q(e,`refs/bisect/skip-${u}`,u);let m=await M(e,u);await qt(e,`# skip: [${u}] ${he(m.message)}`),await qt(e,`git bisect skip ${u}`)}d=await no(e,t,n)}else continue;if(d.exitCode!==0)return d;o+=d.stdout}return{stdout:o,stderr:"",exitCode:0}}function Ig(e,t){e.command("run",{description:"Bisect by running a command",args:[B.string().name("cmd").describe("Command and arguments to run").variadic()],handler:async(n,r)=>{let s=await W(r.fs,r.cwd,t);if(D(s))return s;let o=s;if(!await Wt(o))return to;if(!r.exec)return v("bisect run requires shell execution support");let i=n.cmd.join(" ");return Tg(o,r.env,t,i,r.exec,r.cwd)}})}async function Tg(e,t,n,r,s,o){let i="";for(;;){i+=`running '${r}' ++`;let c=(await s(r,{cwd:o})).exitCode;if(c===125){let u=await mc(e);if(D(u))return u;await Q(e,`refs/bisect/skip-${u}`,u);let m=await M(e,u);await qt(e,`# skip: [${u}] ${he(m.message)}`),await qt(e,`git bisect skip ${u}`);let h=await no(e,t,n);if(i+=h.stdout,h.stdout.includes("is the first bad commit"))return i+=`bisect found first bad commit ++`,{stdout:i,stderr:"",exitCode:0};if(h.exitCode!==0)return{stdout:i,stderr:h.stderr,exitCode:h.exitCode};continue}let f=await ai(e),l=c===0?f.termGood:f.termBad,d=await eo(e,t,n,l,f,void 0);if(i+=d.stdout,d.stdout.includes("is the first bad commit"))return i+=`bisect found first bad commit ++`,{stdout:i,stderr:"",exitCode:0};if(d.exitCode!==0)return{stdout:i,stderr:d.stderr,exitCode:d.exitCode}}}function Ag(e,t){e.command("terms",{description:"Show the terms used for old and new commits",options:{"term-good":S().describe("Show the term for the old state"),"term-bad":S().describe("Show the term for the new state")},handler:async(n,r)=>{let s=await W(r.fs,r.cwd,t);if(D(s))return s;let o=s;if(!await Wt(o))return{stdout:"",stderr:`error: no terms defined ++`,exitCode:1};let{termBad:i,termGood:a}=await Js(o);return n["term-good"]?{stdout:`${a} + `,stderr:"",exitCode:0}:n["term-bad"]?{stdout:`${i} + `,stderr:"",exitCode:0}:{stdout:`Your current terms are ${a} for the old state + and ${i} for the new state. +-`,stderr:"",exitCode:0}}})}function hg(e,t){for(let n of["visualize","view"])e.command(n,{description:"Show remaining suspects in git log",handler:async(r,o)=>{let s=await q(o.fs,o.cwd,t);if(D(s))return s;let i=s;if(!await Ut(i))return Ys;let a=await Zo(i);if(!a.badHash||a.goodHashes.length===0)return{stdout:"",stderr:`error: need both bad and good commits to visualize +-`,exitCode:1};let{walkCommits:c}=await Promise.resolve().then(()=>(fr(),_l)),f="";for await(let l of c(i,a.badHash,{exclude:a.goodHashes}))f+=`${await ue(i,l.hash)} ${me(l.commit.message)} +-`;return{stdout:f,stderr:"",exitCode:0}}})}async function Xs(e,t,n){let r=await Zo(e);return!r.badHash||r.goodHashes.length===0?{stdout:ql(r),stderr:"",exitCode:0}:(await Ue(e,"BISECT_ANCESTORS_OK",""),pg(e,t,n,r))}async function pg(e,t,n,r){let o=await Wl(e,r.badHash,r.goodHashes,new Set(r.skipHashes),r.firstParent);if(!o)return{stdout:"",stderr:`error: no testable commits found +-`,exitCode:1};if(o.found){let s=await Kl(e,o.hash);return await _t(e,`# first bad commit: [${o.hash}] ${o.subject}`),{stdout:s,stderr:"",exitCode:0}}if(o.onlySkippedLeft){let s=`There are only 'skip'ped commits left to test. ++`,stderr:"",exitCode:0}}})}function Hg(e,t){for(let n of["visualize","view"])e.command(n,{description:"Show remaining suspects in git log",handler:async(r,s)=>{let o=await W(s.fs,s.cwd,t);if(D(o))return o;let i=o;if(!await Wt(i))return to;let a=await ai(i);if(!a.badHash||a.goodHashes.length===0)return{stdout:"",stderr:`error: need both bad and good commits to visualize ++`,exitCode:1};let{walkCommits:c}=await Promise.resolve().then(()=>(fr(),Ql)),f="";for await(let l of c(i,a.badHash,{exclude:a.goodHashes}))f+=`${await fe(i,l.hash)} ${he(l.commit.message)} ++`;return{stdout:f,stderr:"",exitCode:0}}})}async function no(e,t,n){let r=await ai(e);return!r.badHash||r.goodHashes.length===0?{stdout:td(r),stderr:"",exitCode:0}:(await Ne(e,"BISECT_ANCESTORS_OK",""),Dg(e,t,n,r))}async function Dg(e,t,n,r){let s=await ed(e,r.badHash,r.goodHashes,new Set(r.skipHashes),r.firstParent);if(!s)return{stdout:"",stderr:`error: no testable commits found ++`,exitCode:1};if(s.found){let o=await rd(e,s.hash);return await qt(e,`# first bad commit: [${s.hash}] ${s.subject}`),{stdout:o,stderr:"",exitCode:0}}if(s.onlySkippedLeft){let o=`There are only 'skip'ped commits left to test. + The first bad commit could be any of: +-`;for(let i of r.skipHashes)s+=i+` +-`;return r.badHash&&(s+=r.badHash+` +-`),s+=`We cannot bisect more! +-`,{stdout:s,stderr:"",exitCode:2}}if(r.noCheckout)await Ue(e,"BISECT_HEAD",o.hash);else{let s=await pr(e,o.hash,t,n);if(s.exitCode!==0)return s}return await Ue(e,"BISECT_EXPECTED_REV",o.hash+` +-`),{stdout:zl(o),stderr:"",exitCode:0}}ne();ae();function rn(e){if(e.length===0)return[];let t=e.split(` +-`);return t[t.length-1]===""&&t.pop(),t}function Ht(e){if(e.length===0)return[];let t=[],n=0;for(let r=0;rai&&(n=t-ai),r-t>ai&&(r=t+ai);let o=0,s=1;for(let c=1;t-c>=n;c++){let f=e[t-c];if(f===li)o++;else if(f===ls)s++;else break}if(o===0)return!1;let i=0,a=1;for(let c=1;t+c<=r;c++){let f=e[t+c];if(f===li)i++;else if(f===ls)a++;else break}return i===0?!1:(i+=o,a+=s,a*gg=u?l[g]=ls:l[g]=ci}let m=Math.min(ic(r),fd);for(let g=s;g<=a;g++){let w=o[n[g]].len1;w===0?d[g]=li:w>=m?d[g]=ls:d[g]=ci}let h=[];for(let g=s;g<=i;g++)l[g]===ci||l[g]===ls&&!ld(l,g,s,i)?h.push(g):c[g]=1;let p=[];for(let g=s;g<=a;g++)d[g]===ci||d[g]===ls&&!ld(d,g,s,a)?p.push(g):f[g]=1;return{refIndex1:h,nreff1:h.length,refIndex2:p,nreff2:p.length}}var gr=20,dd=4,kg=256,Eg=256,fi=2147483647;function At(e,t){return e[t]??0}function Rg(e,t,n,r,o,s,i,a,c,f){let l=t-s,d=n-o,u=t-o,m=n-s,h=u-m&1,p=u,g=u,w=m,b=m;i[u]=t,a[m]=n;for(let R=1;;R++){let C=!1;p>l?i[--p-1]=-1:++p,g=p;x-=2){let y;At(i,x-1)>=At(i,x+1)?y=At(i,x-1)+1:y=At(i,x+1);let P=y,k=y-x;for(;ygr&&(C=!0),i[x]=y,h&&w<=x&&x<=b&&At(a,x)<=y)return{i1:y,i2:k,minLo:!0,minHi:!0}}w>l?a[--w-1]=fi:++w,b=w;x-=2){let y;At(a,x-1)t&&k>o&&e[y-1]===r[k-1];)y--,k--;if(P-y>gr&&(C=!0),a[x]=y,!h&&p<=x&&x<=g&&y<=At(i,x))return{i1:y,i2:k,minLo:!0,minHi:!0}}if(!c){if(C&&R>kg){let x=0,y=null;for(let P=g;P>=p;P-=2){let k=P>u?P-u:u-P,E=At(i,P),O=E-P,$=E-t+(O-o)-k;if($>dd*R&&$>x&&t+gr<=E&&E=w;P-=2){let k=P>m?P-m:m-P,E=At(a,P),O=E-P,$=n-E+(s-O)-k;if($>dd*R&&$>x&&t=f){let x=-1,y=-1;for(let E=g;E>=p;E-=2){let O=Math.min(At(i,E),n),$=O-E;s<$&&(O=s+E,$=s),x=w;E-=2){let O=Math.max(t,At(a,E)),$=O-E;$=ud)return ud}return-1}function pd(e,t,n){let r={endOfFile:!1,indent:-1,preBlank:0,preIndent:-1,postBlank:0,postIndent:-1};n>=t?(r.endOfFile=!0,r.indent=-1):(r.endOfFile=!1,r.indent=oc(e[n]));for(let o=n-1;o>=0&&(r.preIndent=oc(e[o]),r.preIndent===-1);o--)if(r.preBlank+=1,r.preBlank===md){r.preIndent=0;break}for(let o=n+1;oe.preIndent?t.penalty+=s?vg:Sg:o===e.preIndent||(e.postIndent!==-1&&e.postIndent>o?t.penalty+=s?Tg:Ig:t.penalty+=s?Hg:Ag))}function Mg(e,t){let n=(e.effectiveIndent>t.effectiveIndent?1:0)-(e.effectiveIndentt[d]===t[u];for(;;){if(a!==i){let d,u,m;do{for(d=a-i,u=-1;i>0&&l(i-1,a-1);){for(e[--i]=1,e[--a]=0;e[i-1];)i--;if(c===0)break;for(f=c-1,c=f;o[c-1];c--);}for(m=a,f>c&&(u=a);!(a>=r||!l(i,a));){for(e[i++]=0,e[a++]=1;e[a];)a++;if(f>=s)break;for(c=f+1,f=c;o[f];f++);f>c&&(u=a)}}while(d!==a-i);if(a!==m)if(u!==-1)for(;f===c;){for(e[--a]=0,e[--i]=1;e[i-1];)i--;for(f=c-1,c=f;o[c-1];c--);}else{let h=-1,p={effectiveIndent:0,penalty:0},g=m;for(a-d-1>g&&(g=a-d-1),a-hd>g&&(g=a-hd);g<=a;g++){let w={effectiveIndent:0,penalty:0},b=pd(n,r,g);gd(b,w);let R=pd(n,r,g-d);gd(R,w),(h===-1||Mg(w,p)<=0)&&(p={effectiveIndent:w.effectiveIndent,penalty:w.penalty},h=g)}for(;a>h;){for(e[--a]=0,e[--i]=1;e[i-1];)i--;for(f=c-1,c=f;o[c-1];c--);}}}if(a>=r)break;for(i=a+1,a=i;e[a];a++);if(f>=s)break;for(c=f+1,f=c;o[f];f++);}}function cc(e,t){let n=e.length,r=t.length,o=new Uint8Array(n),s=new Uint8Array(r);if(n>0&&r>0){let{classes1:i,classes2:a,classInfo:c}=wg(e,t),{dstart:f,dend1:l,dend2:d}=bg(i,n,a,r);if(f>l)for(let u=f;ud)for(let u=f;u0&&p>0){let g=new Array(m);for(let y=0;y({type:"insert",line:i,oldLineNo:0,newLineNo:a+1}));if(r===0)return e.map((i,a)=>({type:"delete",line:i,oldLineNo:a+1,newLineNo:0}));let{changedOld:o,changedNew:s}=cc(e,t);return Cg(e,t,o,s)}var jg=3;function Lg(e,t=jg){if(t=Math.max(0,t),e.length===0)return[];let n=[];for(let a=0;aGg(e,a.start,a.end))}function Gg(e,t,n){let r=0,o=0,s=0,i=0,a=[],c=!1,f=!1;for(let l=t;l<=n;l++){let d=e[l];if(d)switch(d.type){case"keep":c||(r=d.oldLineNo,c=!0),f||(s=d.newLineNo,f=!0),o++,i++,a.push({type:"context",content:d.line});break;case"delete":c||(r=d.oldLineNo,c=!0),o++,a.push({type:"delete",content:d.line});break;case"insert":f||(s=d.newLineNo,f=!0),i++,a.push({type:"insert",content:d.line});break}}if(c||(r=s>0?s:1),f||(s=r>0?r:1),o===0)for(let l=t;l<=n;l++){let d=e[l];if(d&&d.type==="insert"){r=d.newLineNo>1?d.newLineNo-1:0;break}}if(i===0)for(let l=t;l<=n;l++){let d=e[l];if(d&&d.type==="delete"){s=d.oldLineNo>1?d.oldLineNo-1:0;break}}return{oldStart:r,oldCount:o,newStart:s,newCount:i,lines:a}}function di(e){return e?e.length<40?e:Lt(e):"0000000"}function bd(e,t,n,r,o,s){let{path:i,oldMode:a,newMode:c}=t;e.push(`diff --git a/${i} b/${n}`),s?(e.push(`similarity index ${t.similarity??100}%`),e.push(`rename from ${i}`),e.push(`rename to ${n}`)):r?e.push(`new file mode ${c||"100644"}`):o?e.push(`deleted file mode ${a||"100644"}`):a&&c&&a!==c&&(e.push(`old mode ${a}`),e.push(`new mode ${c}`))}function Fg(e,t,n){let{path:r,oldContent:o,newContent:s,oldMode:i,oldHash:a,newHash:c}=e,f=e.renameTo!==void 0,l=e.renameTo??r,d=e.isNew??o==="",u=e.isDeleted??s==="";if(o===s&&!f)return"";let m=[];if(bd(m,e,l,d,u,f),o!==s){if(a||c){let h=di(a),p=di(c);d||u||f?m.push(`index ${h}..${p}`):m.push(`index ${h}..${p} ${i||"100644"}`)}t&&n?m.push(`Binary files a/${r} and b/${l} differ`):d?m.push(`Binary files /dev/null and b/${l} differ`):u?m.push(`Binary files a/${r} and /dev/null differ`):m.push(`Binary files a/${r} and b/${l} differ`)}return`${m.join(` +-`)} +-`}function Wt(e){let{path:t,oldContent:n,newContent:r,oldMode:o,newMode:s,oldHash:i,newHash:a}=e,c=e.renameTo!==void 0,f=e.renameTo??t,l=Ne(n),d=Ne(r);if(l||d)return Fg(e,l,d);let u=rn(n),m=rn(r),h=n.length>0&&n.endsWith(` ++`;for(let i of r.skipHashes)o+=i+` ++`;return r.badHash&&(o+=r.badHash+` ++`),o+=`We cannot bisect more! ++`,{stdout:o,stderr:"",exitCode:2}}if(r.noCheckout)await Ne(e,"BISECT_HEAD",s.hash);else{let o=await pr(e,s.hash,t,n);if(o.exitCode!==0)return o}return await Ne(e,"BISECT_EXPECTED_REV",s.hash+` ++`),{stdout:nd(s),stderr:"",exitCode:0}}te();ie();function cn(e){if(e.length===0)return[];let t=e.split(` ++`);return t[t.length-1]===""&&t.pop(),t}function Mt(e){if(e.length===0)return[];let t=[],n=0;for(let r=0;rwi&&(n=t-wi),r-t>wi&&(r=t+wi);let s=0,o=1;for(let c=1;t-c>=n;c++){let f=e[t-c];if(f===ki)s++;else if(f===ms)o++;else break}if(s===0)return!1;let i=0,a=1;for(let c=1;t+c<=r;c++){let f=e[t+c];if(f===ki)i++;else if(f===ms)a++;else break}return i===0?!1:(i+=s,a+=o,a*Mg=u?l[g]=ms:l[g]=bi}let m=Math.min(pc(r),yd);for(let g=o;g<=a;g++){let w=s[n[g]].len1;w===0?d[g]=ki:w>=m?d[g]=ms:d[g]=bi}let h=[];for(let g=o;g<=i;g++)l[g]===bi||l[g]===ms&&!kd(l,g,o,i)?h.push(g):c[g]=1;let p=[];for(let g=o;g<=a;g++)d[g]===bi||d[g]===ms&&!kd(d,g,o,a)?p.push(g):f[g]=1;return{refIndex1:h,nreff1:h.length,refIndex2:p,nreff2:p.length}}var gr=20,Ed=4,Fg=256,Ng=256,yi=2147483647;function Dt(e,t){return e[t]??0}function Ug(e,t,n,r,s,o,i,a,c,f){let l=t-o,d=n-s,u=t-s,m=n-o,h=u-m&1,p=u,g=u,w=m,b=m;i[u]=t,a[m]=n;for(let y=1;;y++){let C=!1;p>l?i[--p-1]=-1:++p,g=p;x-=2){let k;Dt(i,x-1)>=Dt(i,x+1)?k=Dt(i,x-1)+1:k=Dt(i,x+1);let P=k,E=k-x;for(;kgr&&(C=!0),i[x]=k,h&&w<=x&&x<=b&&Dt(a,x)<=k)return{i1:k,i2:E,minLo:!0,minHi:!0}}w>l?a[--w-1]=yi:++w,b=w;x-=2){let k;Dt(a,x-1)t&&E>s&&e[k-1]===r[E-1];)k--,E--;if(P-k>gr&&(C=!0),a[x]=k,!h&&p<=x&&x<=g&&k<=Dt(i,x))return{i1:k,i2:E,minLo:!0,minHi:!0}}if(!c){if(C&&y>Fg){let x=0,k=null;for(let P=g;P>=p;P-=2){let E=P>u?P-u:u-P,R=Dt(i,P),O=R-P,$=R-t+(O-s)-E;if($>Ed*y&&$>x&&t+gr<=R&&R=w;P-=2){let E=P>m?P-m:m-P,R=Dt(a,P),O=R-P,$=n-R+(o-O)-E;if($>Ed*y&&$>x&&t=f){let x=-1,k=-1;for(let R=g;R>=p;R-=2){let O=Math.min(Dt(i,R),n),$=O-R;o<$&&(O=o+R,$=o),x=w;R-=2){let O=Math.max(t,Dt(a,R)),$=O-R;$=Rd)return Rd}return-1}function Pd(e,t,n){let r={endOfFile:!1,indent:-1,preBlank:0,preIndent:-1,postBlank:0,postIndent:-1};n>=t?(r.endOfFile=!0,r.indent=-1):(r.endOfFile=!1,r.indent=hc(e[n]));for(let s=n-1;s>=0&&(r.preIndent=hc(e[s]),r.preIndent===-1);s--)if(r.preBlank+=1,r.preBlank===Cd){r.preIndent=0;break}for(let s=n+1;se.preIndent?t.penalty+=o?Vg:Kg:s===e.preIndent||(e.postIndent!==-1&&e.postIndent>s?t.penalty+=o?Xg:Yg:t.penalty+=o?Qg:Zg))}function ew(e,t){let n=(e.effectiveIndent>t.effectiveIndent?1:0)-(e.effectiveIndentt[d]===t[u];for(;;){if(a!==i){let d,u,m;do{for(d=a-i,u=-1;i>0&&l(i-1,a-1);){for(e[--i]=1,e[--a]=0;e[i-1];)i--;if(c===0)break;for(f=c-1,c=f;s[c-1];c--);}for(m=a,f>c&&(u=a);!(a>=r||!l(i,a));){for(e[i++]=0,e[a++]=1;e[a];)a++;if(f>=o)break;for(c=f+1,f=c;s[f];f++);f>c&&(u=a)}}while(d!==a-i);if(a!==m)if(u!==-1)for(;f===c;){for(e[--a]=0,e[--i]=1;e[i-1];)i--;for(f=c-1,c=f;s[c-1];c--);}else{let h=-1,p={effectiveIndent:0,penalty:0},g=m;for(a-d-1>g&&(g=a-d-1),a-xd>g&&(g=a-xd);g<=a;g++){let w={effectiveIndent:0,penalty:0},b=Pd(n,r,g);$d(b,w);let y=Pd(n,r,g-d);$d(y,w),(h===-1||ew(w,p)<=0)&&(p={effectiveIndent:w.effectiveIndent,penalty:w.penalty},h=g)}for(;a>h;){for(e[--a]=0,e[--i]=1;e[i-1];)i--;for(f=c-1,c=f;s[c-1];c--);}}}if(a>=r)break;for(i=a+1,a=i;e[a];a++);if(f>=o)break;for(c=f+1,f=c;s[f];f++);}}function wc(e,t){let n=e.length,r=t.length,s=new Uint8Array(n),o=new Uint8Array(r);if(n>0&&r>0){let{classes1:i,classes2:a,classInfo:c}=jg(e,t),{dstart:f,dend1:l,dend2:d}=Lg(i,n,a,r);if(f>l)for(let u=f;ud)for(let u=f;u0&&p>0){let g=new Array(m);for(let k=0;k({type:"insert",line:i,oldLineNo:0,newLineNo:a+1}));if(r===0)return e.map((i,a)=>({type:"delete",line:i,oldLineNo:a+1,newLineNo:0}));let{changedOld:s,changedNew:o}=wc(e,t);return _g(e,t,s,o)}var tw=3;function nw(e,t=tw){if(t=Math.max(0,t),e.length===0)return[];let n=[];for(let a=0;arw(e,a.start,a.end))}function rw(e,t,n){let r=0,s=0,o=0,i=0,a=[],c=!1,f=!1;for(let l=t;l<=n;l++){let d=e[l];if(d)switch(d.type){case"keep":c||(r=d.oldLineNo,c=!0),f||(o=d.newLineNo,f=!0),s++,i++,a.push({type:"context",content:d.line});break;case"delete":c||(r=d.oldLineNo,c=!0),s++,a.push({type:"delete",content:d.line});break;case"insert":f||(o=d.newLineNo,f=!0),i++,a.push({type:"insert",content:d.line});break}}if(c||(r=o>0?o:1),f||(o=r>0?r:1),s===0)for(let l=t;l<=n;l++){let d=e[l];if(d&&d.type==="insert"){r=d.newLineNo>1?d.newLineNo-1:0;break}}if(i===0)for(let l=t;l<=n;l++){let d=e[l];if(d&&d.type==="delete"){o=d.oldLineNo>1?d.oldLineNo-1:0;break}}return{oldStart:r,oldCount:s,newStart:o,newCount:i,lines:a}}function Ei(e){return e?e.length<40?e:Nt(e):"0000000"}function Sd(e){return!!e.oldMode&&!!e.newMode&&e.oldMode!==e.newMode}function vd(e,t,n,r,s,o){let{path:i,oldMode:a,newMode:c}=t;e.push(`diff --git a/${i} b/${n}`),o?(e.push(`similarity index ${t.similarity??100}%`),e.push(`rename from ${i}`),e.push(`rename to ${n}`)):r?e.push(`new file mode ${c||"100644"}`):s?e.push(`deleted file mode ${a||"100644"}`):a&&c&&a!==c&&(e.push(`old mode ${a}`),e.push(`new mode ${c}`))}function sw(e,t,n){let{path:r,oldContent:s,newContent:o,oldMode:i,oldHash:a,newHash:c}=e,f=e.renameTo!==void 0,l=e.renameTo??r,d=e.isNew??s==="",u=e.isDeleted??o==="";if(s===o&&!f&&!Sd(e))return"";let m=[];if(vd(m,e,l,d,u,f),s!==o){if(a||c){let h=Ei(a),p=Ei(c);d||u||f?m.push(`index ${h}..${p}`):m.push(`index ${h}..${p} ${i||"100644"}`)}t&&n?m.push(`Binary files a/${r} and b/${l} differ`):d?m.push(`Binary files /dev/null and b/${l} differ`):u?m.push(`Binary files a/${r} and /dev/null differ`):m.push(`Binary files a/${r} and b/${l} differ`)}return`${m.join(` ++`)} ++`}function Kt(e){let{path:t,oldContent:n,newContent:r,oldMode:s,newMode:o,oldHash:i,newHash:a}=e,c=e.renameTo!==void 0,f=e.renameTo??t,l=Fe(n),d=Fe(r);if(l||d)return sw(e,l,d);let u=cn(n),m=cn(r),h=n.length>0&&n.endsWith(` + `),p=r.length>0&&r.endsWith(` +-`),g="\0NOEOL",w=u;!h&&u.length>0&&(w=u.slice(),w[w.length-1]+=g);let b=m;!p&&m.length>0&&(b=m.slice(),b[b.length-1]+=g);let R=gt(w,b);if(!h||!p)for(let $ of R)$.line.includes(g)&&($.line=$.line.replace(g,""));let C=Lg(R,e.contextLines);if(C.length===0&&!c)return"";let x=e.isNew??n==="",y=e.isDeleted??r==="",P=[];if(bd(P,e,f,x,y,c),C.length===0)return`${P.join(` ++`),g="\0NOEOL",w=u;!h&&u.length>0&&(w=u.slice(),w[w.length-1]+=g);let b=m;!p&&m.length>0&&(b=m.slice(),b[b.length-1]+=g);let y=kt(w,b);if(!h||!p)for(let $ of y)$.line.includes(g)&&($.line=$.line.replace(g,""));let C=nw(y,e.contextLines);if(C.length===0&&!c&&!Sd(e))return"";let x=e.isNew??n==="",k=e.isDeleted??r==="",P=[];if(vd(P,e,f,x,k,c),C.length===0)return`${P.join(` + `)} +-`;if(i||a){let $=di(i),T=di(a);x||y?P.push(`index ${$}..${T}`):c?P.push(`index ${$}..${T} ${o||"100644"}`):o&&s&&o!==s?P.push(`index ${$}..${T}`):P.push(`index ${$}..${T} ${o||"100644"}`)}let k=$=>$.includes(" ")?" ":"";x?(P.push("--- /dev/null"),P.push(`+++ b/${f}${k(f)}`)):y?(P.push(`--- a/${t}${k(t)}`),P.push("+++ /dev/null")):(P.push(`--- a/${t}${k(t)}`),P.push(`+++ b/${f}${k(f)}`));let E=u.length,O=m.length;for(let $ of C){let T=$.oldCount===1?`${$.oldStart}`:`${$.oldStart},${$.oldCount}`,j=$.newCount===1?`${$.newStart}`:`${$.newStart},${$.newCount}`,U="",G=$.oldCount===0?$.oldStart-1:$.oldStart-2;for(let H=G;H>=0;H--){let B=u[H];if(B&&/^[a-zA-Z$_]/.test(B)){U=` ${B.trimEnd().slice(0,79)}`;break}}P.push(`@@ -${T} +${j} @@${U}`);let N=$.oldStart,A=$.newStart;for(let H of $.lines)switch(H.type){case"context":P.push(` ${H.content}`),(!h&&N===E||!p&&A===O)&&P.push("\\ No newline at end of file"),N++,A++;break;case"delete":P.push(`-${H.content}`),!h&&N===E&&P.push("\\ No newline at end of file"),N++;break;case"insert":P.push(`+${H.content}`),!p&&A===O&&P.push("\\ No newline at end of file"),A++;break}}return`${P.join(` ++`;if(i||a){let $=Ei(i),T=Ei(a);x||k?P.push(`index ${$}..${T}`):c?P.push(`index ${$}..${T} ${s||"100644"}`):s&&o&&s!==o?P.push(`index ${$}..${T}`):P.push(`index ${$}..${T} ${s||"100644"}`)}let E=$=>$.includes(" ")?" ":"";x?(P.push("--- /dev/null"),P.push(`+++ b/${f}${E(f)}`)):k?(P.push(`--- a/${t}${E(t)}`),P.push("+++ /dev/null")):(P.push(`--- a/${t}${E(t)}`),P.push(`+++ b/${f}${E(f)}`));let R=u.length,O=m.length;for(let $ of C){let T=$.oldCount===1?`${$.oldStart}`:`${$.oldStart},${$.oldCount}`,j=$.newCount===1?`${$.newStart}`:`${$.newStart},${$.newCount}`,U="",G=$.oldCount===0?$.oldStart-1:$.oldStart-2;for(let H=G;H>=0;H--){let q=u[H];if(q&&/^[a-zA-Z$_]/.test(q)){U=` ${q.trimEnd().slice(0,79)}`;break}}P.push(`@@ -${T} +${j} @@${U}`);let L=$.oldStart,A=$.newStart;for(let H of $.lines)switch(H.type){case"context":P.push(` ${H.content}`),(!h&&L===R||!p&&A===O)&&P.push("\\ No newline at end of file"),L++,A++;break;case"delete":P.push(`-${H.content}`),!h&&L===R&&P.push("\\ No newline at end of file"),L++;break;case"insert":P.push(`+${H.content}`),!p&&A===O&&P.push("\\ No newline at end of file"),A++;break}}return`${P.join(` + `)} +-`}ae();De();async function wr(e,t,n){return(await de(e,t)).get(n)?.hash??null}async function yd(e,t,n,r){let o=await Ke(e,t,n);if(!o.find(f=>f.status==="added"&&f.path===r))return null;let i=await Rt(e,"diff"),{renames:a}=await ht(e,o,{limit:i});return a.find(f=>f.newPath===r)?.oldPath??null}async function Ng(e,t,n,r,o,s){let i=await wr(e,(await M(e,t)).tree,n);if(!i){let p=new Map,g=await M(e,t);for(let w of r)p.set(w.finalIdx,br(t,n,w.currentLine,s+w.finalIdx,o[w.finalIdx],g,!1,void 0));return p}let a=await le(e,i),c=rn(a),f=new Array(o.length),l=[...r],d=t,u=n,m=c;for(;l.length>0;){let p=await M(e,d);if(p.parents.length===0){for(let E of l)f[E.finalIdx]=br(d,u,E.currentLine,s+E.finalIdx,o[E.finalIdx],p,!0,void 0);break}let g=await wr(e,p.tree,u),w=null,b=[];for(let E of p.parents){let O=await M(e,E),$=u,T=await wr(e,O.tree,$);if(!T){let j=await yd(e,O.tree,p.tree,u);j&&($=j,T=await wr(e,O.tree,$))}if(T&&(b.push({hash:E,path:$,blobHash:T}),T===g)){w={hash:E,path:$};break}}if(w){d=w.hash,u=w.path;continue}if(b.length===0){for(let E of l)f[E.finalIdx]=br(d,u,E.currentLine,s+E.finalIdx,o[E.finalIdx],p,!1,void 0);break}let R=b[0],C=await le(e,R.blobHash),x=rn(C),y=gt(x,m),P=new Map;for(let E of y)E.type==="keep"&&P.set(E.newLineNo,E.oldLineNo);let k=[];for(let E of l){let O=P.get(E.currentLine);O!==void 0?k.push({finalIdx:E.finalIdx,currentLine:O}):f[E.finalIdx]=br(d,u,E.currentLine,s+E.finalIdx,o[E.finalIdx],p,!1,{hash:R.hash,path:R.path})}l=k,d=R.hash,u=R.path,m=x}let h=new Map;for(let p of r)f[p.finalIdx]&&h.set(p.finalIdx,f[p.finalIdx]);return h}async function kd(e,t,n,r){let o=await M(e,t),s=await wr(e,o.tree,n);if(!s)throw new Error(`no such path '${n}' in ${t.slice(0,7)}`);let i=await le(e,s),a=rn(i),c=r?.startLine??1,f=r?.endLine??a.length,l=a.slice(c-1,f),d=new Array(l.length),u=l.map((g,w)=>({finalIdx:w,currentLine:c+w})),m=t,h=n,p=a;for(;u.length>0;){let g=await M(e,m);if(g.parents.length===0){for(let P of u)d[P.finalIdx]=br(m,h,P.currentLine,c+P.finalIdx,l[P.finalIdx],g,!0,void 0);break}let w=await wr(e,g.tree,h),b=[],R=null;for(let P of g.parents){let k=await M(e,P),E=h,O=await wr(e,k.tree,E);if(!O){let $=await yd(e,k.tree,g.tree,h);$&&(E=$,O=await wr(e,k.tree,E))}if(O){let $={hash:P,path:E,blobHash:O};if(b.push($),O===w){R=$;break}}}if(R){m=R.hash,h=R.path;continue}if(b.length===0){for(let P of u)d[P.finalIdx]=br(m,h,P.currentLine,c+P.finalIdx,l[P.finalIdx],g,!1,void 0);break}if(b.length===1){let P=b[0],k=await le(e,P.blobHash),E=rn(k),O=gt(E,p),$=new Map;for(let j of O)j.type==="keep"&&$.set(j.newLineNo,j.oldLineNo);let T=[];for(let j of u){let U=$.get(j.currentLine);U!==void 0?T.push({finalIdx:j.finalIdx,currentLine:U}):d[j.finalIdx]=br(m,h,j.currentLine,c+j.finalIdx,l[j.finalIdx],g,!1,{hash:P.hash,path:P.path})}u=T,m=P.hash,h=P.path,p=E;continue}let C=[];for(let P of b){let k=await le(e,P.blobHash),E=rn(k),O=gt(E,p),$=new Map;for(let T of O)T.type==="keep"&&$.set(T.newLineNo,T.oldLineNo);C.push({info:P,newToOld:$})}let x=new Map;for(let P of u){let k=!1;for(let E=0;E0){u=y.lines,m=y.info.hash,h=y.info.path;let P=await le(e,y.info.blobHash);p=rn(P)}else break}return d}function br(e,t,n,r,o,s,i,a){return{hash:e,origPath:t,origLine:n,finalLine:r,content:o,author:s.author,committer:s.committer,summary:s.message.split(` +-`)[0],boundary:i,previous:a}}ne();ae();De();ae();ge();Ee();function Ug(e){let t=e.startsWith("-")?-1:1,n=e.replace(/^[+-]/,""),r=parseInt(n.slice(0,2),10)||0,o=parseInt(n.slice(2,4),10)||0;return t*(r*60+o)}function _g(e,t){let n=Ug(t),r=new Date((e+n*60)*1e3),o=r.getUTCFullYear(),s=(r.getUTCMonth()+1).toString().padStart(2,"0"),i=r.getUTCDate().toString().padStart(2,"0"),a=r.getUTCHours().toString().padStart(2,"0"),c=r.getUTCMinutes().toString().padStart(2,"0"),f=r.getUTCSeconds().toString().padStart(2,"0");return`${o}-${s}-${i} ${a}:${c}:${f} ${t}`}function Bg(e,t,n,r,o){if(e.length===0)return"";let s=Math.max(...e.map(d=>d.finalLine)),i=String(s).length,a=e.some(d=>d.origPath!==t),c=0;if(!o)for(let d of e){let u=r?`<${d.author.email}>`:d.author.name;u.length>c&&(c=u.length)}let f=0;if(a)for(let d of e)d.origPath.length>f&&(f=d.origPath.length);let l=[];for(let d of e){let u;n?u=d.boundary?`^${d.hash.slice(0,39)}`:d.hash:u=d.boundary?`^${d.hash.slice(0,7)}`:d.hash.slice(0,8);let m=a?` ${d.origPath.padEnd(f)}`:"";if(o)l.push(`${u}${m} ${String(d.finalLine).padStart(i)}) ${d.content}`);else{let h=r?`<${d.author.email}>`:d.author.name,p=_g(d.author.timestamp,d.author.timezone);l.push(`${u}${m} (${h.padEnd(c)} ${p} ${String(d.finalLine).padStart(i)}) ${d.content}`)}}return`${l.join(` ++`}ie();Te();async function wr(e,t,n){return(await de(e,t)).get(n)?.hash??null}async function Id(e,t,n,r){let s=await Ve(e,t,n);if(!s.find(f=>f.status==="added"&&f.path===r))return null;let i=await xt(e,"diff"),{renames:a}=await bt(e,s,{limit:i});return a.find(f=>f.newPath===r)?.oldPath??null}async function ow(e,t,n,r,s,o){let i=await wr(e,(await M(e,t)).tree,n);if(!i){let p=new Map,g=await M(e,t);for(let w of r)p.set(w.finalIdx,br(t,n,w.currentLine,o+w.finalIdx,s[w.finalIdx],g,!1,void 0));return p}let a=await le(e,i),c=cn(a),f=new Array(s.length),l=[...r],d=t,u=n,m=c;for(;l.length>0;){let p=await M(e,d);if(p.parents.length===0){for(let R of l)f[R.finalIdx]=br(d,u,R.currentLine,o+R.finalIdx,s[R.finalIdx],p,!0,void 0);break}let g=await wr(e,p.tree,u),w=null,b=[];for(let R of p.parents){let O=await M(e,R),$=u,T=await wr(e,O.tree,$);if(!T){let j=await Id(e,O.tree,p.tree,u);j&&($=j,T=await wr(e,O.tree,$))}if(T&&(b.push({hash:R,path:$,blobHash:T}),T===g)){w={hash:R,path:$};break}}if(w){d=w.hash,u=w.path;continue}if(b.length===0){for(let R of l)f[R.finalIdx]=br(d,u,R.currentLine,o+R.finalIdx,s[R.finalIdx],p,!1,void 0);break}let y=b[0],C=await le(e,y.blobHash),x=cn(C),k=kt(x,m),P=new Map;for(let R of k)R.type==="keep"&&P.set(R.newLineNo,R.oldLineNo);let E=[];for(let R of l){let O=P.get(R.currentLine);O!==void 0?E.push({finalIdx:R.finalIdx,currentLine:O}):f[R.finalIdx]=br(d,u,R.currentLine,o+R.finalIdx,s[R.finalIdx],p,!1,{hash:y.hash,path:y.path})}l=E,d=y.hash,u=y.path,m=x}let h=new Map;for(let p of r)f[p.finalIdx]&&h.set(p.finalIdx,f[p.finalIdx]);return h}async function Td(e,t,n,r){let s=await M(e,t),o=await wr(e,s.tree,n);if(!o)throw new Error(`no such path '${n}' in ${t.slice(0,7)}`);let i=await le(e,o),a=cn(i),c=r?.startLine??1,f=r?.endLine??a.length,l=a.slice(c-1,f),d=new Array(l.length),u=l.map((g,w)=>({finalIdx:w,currentLine:c+w})),m=t,h=n,p=a;for(;u.length>0;){let g=await M(e,m);if(g.parents.length===0){for(let P of u)d[P.finalIdx]=br(m,h,P.currentLine,c+P.finalIdx,l[P.finalIdx],g,!0,void 0);break}let w=await wr(e,g.tree,h),b=[],y=null;for(let P of g.parents){let E=await M(e,P),R=h,O=await wr(e,E.tree,R);if(!O){let $=await Id(e,E.tree,g.tree,h);$&&(R=$,O=await wr(e,E.tree,R))}if(O){let $={hash:P,path:R,blobHash:O};if(b.push($),O===w){y=$;break}}}if(y){m=y.hash,h=y.path;continue}if(b.length===0){for(let P of u)d[P.finalIdx]=br(m,h,P.currentLine,c+P.finalIdx,l[P.finalIdx],g,!1,void 0);break}if(b.length===1){let P=b[0],E=await le(e,P.blobHash),R=cn(E),O=kt(R,p),$=new Map;for(let j of O)j.type==="keep"&&$.set(j.newLineNo,j.oldLineNo);let T=[];for(let j of u){let U=$.get(j.currentLine);U!==void 0?T.push({finalIdx:j.finalIdx,currentLine:U}):d[j.finalIdx]=br(m,h,j.currentLine,c+j.finalIdx,l[j.finalIdx],g,!1,{hash:P.hash,path:P.path})}u=T,m=P.hash,h=P.path,p=R;continue}let C=[];for(let P of b){let E=await le(e,P.blobHash),R=cn(E),O=kt(R,p),$=new Map;for(let T of O)T.type==="keep"&&$.set(T.newLineNo,T.oldLineNo);C.push({info:P,newToOld:$})}let x=new Map;for(let P of u){let E=!1;for(let R=0;R0){u=k.lines,m=k.info.hash,h=k.info.path;let P=await le(e,k.info.blobHash);p=cn(P)}else break}return d}function br(e,t,n,r,s,o,i,a){return{hash:e,origPath:t,origLine:n,finalLine:r,content:s,author:o.author,committer:o.committer,summary:o.message.split(` ++`)[0],boundary:i,previous:a}}te();ie();Te();ie();ge();ke();function iw(e){let t=e.startsWith("-")?-1:1,n=e.replace(/^[+-]/,""),r=parseInt(n.slice(0,2),10)||0,s=parseInt(n.slice(2,4),10)||0;return t*(r*60+s)}function aw(e,t){let n=iw(t),r=new Date((e+n*60)*1e3),s=r.getUTCFullYear(),o=(r.getUTCMonth()+1).toString().padStart(2,"0"),i=r.getUTCDate().toString().padStart(2,"0"),a=r.getUTCHours().toString().padStart(2,"0"),c=r.getUTCMinutes().toString().padStart(2,"0"),f=r.getUTCSeconds().toString().padStart(2,"0");return`${s}-${o}-${i} ${a}:${c}:${f} ${t}`}function cw(e,t,n,r,s){if(e.length===0)return"";let o=Math.max(...e.map(d=>d.finalLine)),i=String(o).length,a=e.some(d=>d.origPath!==t),c=0;if(!s)for(let d of e){let u=r?`<${d.author.email}>`:d.author.name;u.length>c&&(c=u.length)}let f=0;if(a)for(let d of e)d.origPath.length>f&&(f=d.origPath.length);let l=[];for(let d of e){let u;n?u=d.boundary?`^${d.hash.slice(0,39)}`:d.hash:u=d.boundary?`^${d.hash.slice(0,7)}`:d.hash.slice(0,8);let m=a?` ${d.origPath.padEnd(f)}`:"";if(s)l.push(`${u}${m} ${String(d.finalLine).padStart(i)}) ${d.content}`);else{let h=r?`<${d.author.email}>`:d.author.name,p=aw(d.author.timestamp,d.author.timezone);l.push(`${u}${m} (${h.padEnd(c)} ${p} ${String(d.finalLine).padStart(i)}) ${d.content}`)}}return`${l.join(` + `)} +-`}function Wg(e,t){let n=new Set,r=[];for(let o of e){let s=!n.has(o.hash);n.add(o.hash),r.push(`${o.hash} ${o.origLine} ${o.finalLine} 1`),(s||t)&&(r.push(`author ${o.author.name}`),r.push(`author-mail <${o.author.email}>`),r.push(`author-time ${o.author.timestamp}`),r.push(`author-tz ${o.author.timezone}`),r.push(`committer ${o.committer.name}`),r.push(`committer-mail <${o.committer.email}>`),r.push(`committer-time ${o.committer.timestamp}`),r.push(`committer-tz ${o.committer.timezone}`),r.push(`summary ${o.summary}`),o.boundary&&r.push("boundary"),o.previous&&r.push(`previous ${o.previous.hash} ${o.previous.path}`),r.push(`filename ${o.origPath}`)),r.push(` ${o.content}`)}return`${r.join(` ++`}function fw(e,t){let n=new Set,r=[];for(let s of e){let o=!n.has(s.hash);n.add(s.hash),r.push(`${s.hash} ${s.origLine} ${s.finalLine} 1`),(o||t)&&(r.push(`author ${s.author.name}`),r.push(`author-mail <${s.author.email}>`),r.push(`author-time ${s.author.timestamp}`),r.push(`author-tz ${s.author.timezone}`),r.push(`committer ${s.committer.name}`),r.push(`committer-mail <${s.committer.email}>`),r.push(`committer-time ${s.committer.timestamp}`),r.push(`committer-tz ${s.committer.timezone}`),r.push(`summary ${s.summary}`),s.boundary&&r.push("boundary"),s.previous&&r.push(`previous ${s.previous.hash} ${s.previous.path}`),r.push(`filename ${s.origPath}`)),r.push(` ${s.content}`)}return`${r.join(` + `)} +-`}function qg(e,t,n){if(e.startsWith("/"))return lt(n,e);let r=lt(n,t);return r===""||r==="."?e:`${r}/${e}`}function Ed(e,t){e.command("blame",{description:"Show what revision and author last modified each line of a file",args:[W.string().name("args").variadic().optional()],options:{lineRange:K.string().alias("L").describe("Annotate only the given line range (,)"),long:S().alias("l").describe("Show long revision"),showEmail:S().alias("e").describe("Show author email instead of name"),suppress:S().alias("s").describe("Suppress author name and date"),porcelain:S().alias("p").describe("Show in machine-readable format"),linePorcelain:S().describe("Show porcelain format with full headers for each line")},handler:async(n,r,o)=>{let s=await q(r.fs,r.cwd,t);if(D(s))return s;let i=s;if(!i.workTree)return v("this operation must be run in a work tree");let a=await nt(i);if(D(a))return a;let c=n.args??[],f=o.passthrough??[],l=null,d=null;if(f.length>0?(d=f[f.length-1],c.length>0&&(l=c[0])):c.length===2?(l=c[0],d=c[1]):c.length===1&&(d=c[0]),!d)return v("no file specified");let u=qg(d,r.cwd,i.workTree),m;if(l){let y=await It(i,l);if(D(y))return y;m=await Se(i,y)}else m=a;let h=await M(i,m),p=await de(i,h.tree);if(!p.has(u))return v(`no such path ${u} in ${l??"HEAD"}`);let g=p.get(u).hash,w=await le(i,g);if(Ne(w))return v(`cannot blame binary file '${u}'`);let b,R;if(n.lineRange){let y=n.lineRange,P=y.match(/^(\d+),(\d+)$/);if(P)b=parseInt(P[1],10),R=parseInt(P[2],10);else return v(`invalid -L range: '${y}'`)}let C;try{C=await kd(i,m,u,{startLine:b,endLine:R})}catch(y){let P=y instanceof Error?y.message:String(y);return v(P)}let x;return n.porcelain||n.linePorcelain?x=Wg(C,!!n.linePorcelain):x=Bg(C,u,!!n.long,!!n.showEmail,!!n.suppress),{stdout:x,stderr:"",exitCode:0}}})}ne();Be();xr();ne();var zg=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],Kg=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function qn(e,t){let n=Vg(t),r=new Date((e+n*60)*1e3),o=zg[r.getUTCDay()],s=Kg[r.getUTCMonth()],i=r.getUTCDate(),a=r.getUTCHours().toString().padStart(2,"0"),c=r.getUTCMinutes().toString().padStart(2,"0"),f=r.getUTCSeconds().toString().padStart(2,"0"),l=r.getUTCFullYear();return`${o} ${s} ${i} ${a}:${c}:${f} ${l} ${t}`}function ds(e){let t=e.trim();if(/^\d+$/.test(t))return parseInt(t,10);let n=Date.parse(t);return Number.isNaN(n)?null:Math.floor(n/1e3)}function Vg(e){let t=e.startsWith("-")?-1:1,n=e.replace(/^[+-]/,""),r=parseInt(n.slice(0,2),10)||0,o=parseInt(n.slice(2,4),10)||0;return t*(r*60+o)}ae();De();var ui=new TextDecoder;function Rd(e){if(e.length===0)return 0;let t=0;for(let n=0;n,)"),long:S().alias("l").describe("Show long revision"),showEmail:S().alias("e").describe("Show author email instead of name"),suppress:S().alias("s").describe("Suppress author name and date"),porcelain:S().alias("p").describe("Show in machine-readable format"),linePorcelain:S().describe("Show porcelain format with full headers for each line")},handler:async(n,r,s)=>{let o=await W(r.fs,r.cwd,t);if(D(o))return o;let i=o;if(!i.workTree)return v("this operation must be run in a work tree");let a=await nt(i);if(D(a))return a;let c=n.args??[],f=s.passthrough??[],l=null,d=null;if(f.length>0?(d=f[f.length-1],c.length>0&&(l=c[0])):c.length===2?(l=c[0],d=c[1]):c.length===1&&(d=c[0]),!d)return v("no file specified");let u=lw(d,r.cwd,i.workTree),m;if(l){let k=await At(i,l);if(D(k))return k;m=await Oe(i,k)}else m=a;let h=await M(i,m),p=await de(i,h.tree);if(!p.has(u))return v(`no such path ${u} in ${l??"HEAD"}`);let g=p.get(u).hash,w=await le(i,g);if(Fe(w))return v(`cannot blame binary file '${u}'`);let b,y;if(n.lineRange){let k=n.lineRange,P=k.match(/^(\d+),(\d+)$/);if(P)b=parseInt(P[1],10),y=parseInt(P[2],10);else return v(`invalid -L range: '${k}'`)}let C;try{C=await Td(i,m,u,{startLine:b,endLine:y})}catch(k){let P=k instanceof Error?k.message:String(k);return v(P)}let x;return n.porcelain||n.linePorcelain?x=fw(C,!!n.linePorcelain):x=cw(C,u,!!n.long,!!n.showEmail,!!n.suppress),{stdout:x,stderr:"",exitCode:0}}})}te();We();$r();te();var dw=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],uw=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function zn(e,t){let n=mw(t),r=new Date((e+n*60)*1e3),s=dw[r.getUTCDay()],o=uw[r.getUTCMonth()],i=r.getUTCDate(),a=r.getUTCHours().toString().padStart(2,"0"),c=r.getUTCMinutes().toString().padStart(2,"0"),f=r.getUTCSeconds().toString().padStart(2,"0"),l=r.getUTCFullYear();return`${s} ${o} ${i} ${a}:${c}:${f} ${l} ${t}`}function hs(e){let t=e.trim();if(/^\d+$/.test(t))return parseInt(t,10);let n=Date.parse(t);return Number.isNaN(n)?null:Math.floor(n/1e3)}function mw(e){let t=e.startsWith("-")?-1:1,n=e.replace(/^[+-]/,""),r=parseInt(n.slice(0,2),10)||0,s=parseInt(n.slice(2,4),10)||0;return t*(r*60+s)}ie();Te();var Ri=new TextDecoder;function Hd(e){if(e.length===0)return 0;let t=0;for(let n=0;n0||n===0)&&r.push(`${t} insertion${t!==1?"s":""}(+)`),(n>0||t===0)&&r.push(`${n} deletion${n!==1?"s":""}(-)`),` ${r.join(", ")}`}async function kr(e,t,n){let r=[],o=[],s=[];for(let a of t)if(a.status==="added"&&a.newHash&&a.newMode){let c=await jt(e,a.newHash);hn(c)?r.push({path:a.path,sortKey:a.path,insertions:0,deletions:0,isBinary:!0,oldSize:0,newSize:c.byteLength}):r.push({path:a.path,sortKey:a.path,insertions:Rd(ui.decode(c)),deletions:0}),o.push({path:a.path,mode:a.newMode})}else if(a.status==="deleted"&&a.oldHash&&a.oldMode){let c=await jt(e,a.oldHash);hn(c)?r.push({path:a.path,sortKey:a.path,insertions:0,deletions:0,isBinary:!0,oldSize:c.byteLength,newSize:0}):r.push({path:a.path,sortKey:a.path,insertions:0,deletions:Rd(ui.decode(c))}),s.push({path:a.path,mode:a.oldMode})}else if(a.status==="modified"&&a.oldHash&&a.newHash){let c=await jt(e,a.oldHash),f=await jt(e,a.newHash);if(hn(c)||hn(f))r.push({path:a.path,sortKey:a.path,insertions:0,deletions:0,isBinary:!0,oldSize:c.byteLength,newSize:f.byteLength});else{let l=Ht(ui.decode(c)),d=Ht(ui.decode(f)),u=gt(l,d),m=0,h=0;for(let p of u)p.type==="insert"?m++:p.type==="delete"&&h++;r.push({path:a.path,sortKey:a.path,insertions:m,deletions:h})}a.oldMode&&a.newMode&&a.oldMode!==a.newMode&&(s.push({path:a.path,mode:a.oldMode}),o.push({path:a.path,mode:a.newMode}))}for(let a of n){let c=In(a.oldPath,a.newPath),f=0,l=0;if(a.similarity<100&&a.oldHash&&a.newHash){let d=await le(e,a.oldHash),u=await le(e,a.newHash);if(!Ne(d)&&!Ne(u)){let m=Ht(d),h=Ht(u),p=gt(m,h);for(let g of p)g.type==="insert"?f++:g.type==="delete"&&l++}}r.push({path:c,sortKey:a.newPath,insertions:f,deletions:l})}let i=[];for(let{path:a,mode:c}of o)i.push({sortKey:a,text:` create mode ${c} ${a}`});for(let{path:a,mode:c}of s)i.push({sortKey:a,text:` delete mode ${c} ${a}`});for(let a of n){let c=In(a.oldPath,a.newPath);i.push({sortKey:a.newPath,text:` rename ${c} (${a.similarity}%)`})}return i.sort((a,c)=>a.sortKeyc.sortKey?1:0),{fileStats:r,modeLines:i.map(a=>a.text)}}async function zn(e,t,n,r,o,s=!1,i=!1){let a=[];if((r.name!==o.name||r.email!==o.email)&&a.push(` Author: ${r.name} <${r.email}>`),s&&a.push(` Date: ${qn(r.timestamp,r.timezone)}`),i)return a.join(` ++`&&t++,t}function yr(e,t,n){if(e===0)return"";let r=[];return r.push(`${e} file${e!==1?"s":""} changed`),(t>0||n===0)&&r.push(`${t} insertion${t!==1?"s":""}(+)`),(n>0||t===0)&&r.push(`${n} deletion${n!==1?"s":""}(-)`),` ${r.join(", ")}`}async function kr(e,t,n){let r=[];for(let s of t)if(s.status==="added"&&s.newHash&&s.newMode){let o=await Gt(e,s.newHash);wn(o)?r.push({path:s.path,sortKey:s.path,insertions:0,deletions:0,isBinary:!0,oldSize:0,newSize:o.byteLength}):r.push({path:s.path,sortKey:s.path,insertions:Hd(Ri.decode(o)),deletions:0})}else if(s.status==="deleted"&&s.oldHash&&s.oldMode){let o=await Gt(e,s.oldHash);wn(o)?r.push({path:s.path,sortKey:s.path,insertions:0,deletions:0,isBinary:!0,oldSize:o.byteLength,newSize:0}):r.push({path:s.path,sortKey:s.path,insertions:0,deletions:Hd(Ri.decode(o))})}else if(s.status==="modified"&&s.oldHash&&s.newHash){let o=await Gt(e,s.oldHash),i=await Gt(e,s.newHash);if(wn(o)||wn(i))r.push({path:s.path,sortKey:s.path,insertions:0,deletions:0,isBinary:!0,oldSize:o.byteLength,newSize:i.byteLength});else{let a=Mt(Ri.decode(o)),c=Mt(Ri.decode(i)),f=kt(a,c),l=0,d=0;for(let u of f)u.type==="insert"?l++:u.type==="delete"&&d++;r.push({path:s.path,sortKey:s.path,insertions:l,deletions:d})}}for(let s of n){let o=Dn(s.oldPath,s.newPath),i=0,a=0;if(s.similarity<100&&s.oldHash&&s.newHash){let c=await le(e,s.oldHash),f=await le(e,s.newHash);if(!Fe(c)&&!Fe(f)){let l=Mt(c),d=Mt(f),u=kt(l,d);for(let m of u)m.type==="insert"?i++:m.type==="delete"&&a++}}r.push({path:o,sortKey:s.newPath,insertions:i,deletions:a})}return r}var hw={7:"\\a",8:"\\b",9:"\\t",10:"\\n",11:"\\v",12:"\\f",13:"\\r",34:'\\"',92:"\\\\"};function bc(e){let t="",n=!1;for(let r of new TextEncoder().encode(e)){let s=hw[r];s?(t+=s,n=!0):r<32||r>=127?(t+=`\\${r.toString(8).padStart(3,"0")}`,n=!0):t+=String.fromCharCode(r)}return n?`"${t}"`:e}function Er(e,t){let n=(s,o)=>s&&o&&s!==o?` mode change ${s} => ${o}`:null,r=[];for(let s of e){let o=bc(s.path),i=null;if(s.status==="added")i=` create mode ${s.newMode} ${o} ++`;else if(s.status==="deleted")i=` delete mode ${s.oldMode} ${o} ++`;else{let a=n(s.oldMode,s.newMode);a&&(i=`${a} ${o} ++`)}i&&r.push({sortKey:s.path,text:i})}for(let s of t){let o=bc(s.oldPath),i=bc(s.newPath),a=o!==s.oldPath||i!==s.newPath?`${o} => ${i}`:Dn(s.oldPath,s.newPath),c=n(s.oldMode,s.newMode);r.push({sortKey:s.newPath,text:` rename ${a} (${s.similarity}%) ++${c?`${c} ++`:""}`})}return r.sort((s,o)=>s.sortKeyo.sortKey?1:0),r.map(s=>s.text).join("")}function ro(e,t,n){return n&&t?`${t} ++${e}`:e+t}async function Kn(e,t,n,r,s,o=!1,i=!1){let a=[];if((r.name!==s.name||r.email!==s.email)&&a.push(` Author: ${r.name} <${r.email}>`),o&&a.push(` Date: ${zn(r.timestamp,r.timezone)}`),i)return a.join(` + `)+(a.length>0?` +-`:"");let c=await Ke(e,t,n),f=await Rt(e,"diff"),{remaining:l,renames:d}=await ht(e,c,{limit:f}),{fileStats:u,modeLines:m}=await kr(e,l,d),h=0,p=0;for(let w of u)h+=w.insertions,p+=w.deletions;let g=yr(u.length,h,p);g&&a.push(g);for(let w of m)a.push(w);return a.join(` ++`:"");let c=await Ve(e,t,n),f=await xt(e,"diff"),{remaining:l,renames:d}=await bt(e,c,{limit:f}),u=await kr(e,l,d),m=0,h=0;for(let w of u)m+=w.insertions,h+=w.deletions;let p=yr(u.length,m,h);return p&&a.push(p),a.join(` + `)+(a.length>0?` +-`:"")}var Yg=80;function Xg(e,t){if(e.length<=t)return e;let n=e;for(;n.length+4>t;){let o=n.indexOf("/");if(o===-1)break;n=n.slice(o+1)}let r=`.../${n}`;return r.length<=t?r:`...${e.slice(e.length-(t-3))}`}function jr(e,t=Yg){if(e.length===0)return"";let n=e.filter(p=>!p.isUnmerged),r=n.length>0?Math.max(...n.map(p=>p.insertions+p.deletions)):0,o=e.some(p=>p.isBinary),s=r>0?String(r).length:1;o&&s<3&&(s=3);let i=Math.max(...e.map(p=>p.path.length)),a=r,c=i;if(c+s+6+a>t){let p=Math.floor(t*3/8)-s-6;a>p&&(a=Math.max(p,6));let g=t-s-6-a;c>g?c=g:a=t-s-6-c}for(let p of e)p.path=Xg(p.path,c);let f=c,l=[],d=0,u=0,m=0;for(let p of e){let g=p.path.padEnd(f);if(p.isUnmerged){l.push(` ${g} | Unmerged`);continue}if(m++,d+=p.insertions,u+=p.deletions,p.isBinary){let k=`${"Bin".padStart(s)} ${p.oldSize??0} -> ${p.newSize??0} bytes`;l.push(` ${g} | ${k}`);continue}let w=p.insertions+p.deletions,b=String(w).padStart(s),R,C;if(r<=a)R=p.insertions,C=p.deletions;else{let P=O=>O===0?0:1+Math.floor(O*(a-1)/r),k=P(w),E=k<2&&p.insertions>0&&p.deletions>0?2:k;p.insertionsp.isUnmerged)&&l.push(" 0 files changed"),`${l.join(` +-`)} +-`}async function Tn(e,t,n){let r=await Ke(e,t,n),o=await Rt(e,"diff"),{remaining:s,renames:i}=await ht(e,r,{limit:o});if(s.length===0&&i.length===0)return"";let{fileStats:a,modeLines:c}=await kr(e,s,i);a.sort((l,d)=>l.sortKeyd.sortKey?1:0);let f=jr(a);for(let l of c)f+=`${l} +-`;return f}Be();ve();ae();ye();Jt();async function Zg(e,t){let n=new Set,r=[t],o=0;for(;o0;){let u=0,m=await d(l[0].hash);for(let b=1;bm||C===m&&R.seqt;){let s=n.indexOf("/");if(s===-1)break;n=n.slice(s+1)}let r=`.../${n}`;return r.length<=t?r:`...${e.slice(e.length-(t-3))}`}function Nr(e,t=pw){if(e.length===0)return"";let n=e.filter(p=>!p.isUnmerged),r=n.length>0?Math.max(...n.map(p=>p.insertions+p.deletions)):0,s=e.some(p=>p.isBinary),o=r>0?String(r).length:1;s&&o<3&&(o=3);let i=Math.max(...e.map(p=>p.path.length)),a=r,c=i;if(c+o+6+a>t){let p=Math.floor(t*3/8)-o-6;a>p&&(a=Math.max(p,6));let g=t-o-6-a;c>g?c=g:a=t-o-6-c}for(let p of e)p.path=gw(p.path,c);let f=c,l=[],d=0,u=0,m=0;for(let p of e){let g=p.path.padEnd(f);if(p.isUnmerged){l.push(` ${g} | Unmerged`);continue}if(m++,d+=p.insertions,u+=p.deletions,p.isBinary){let E=`${"Bin".padStart(o)} ${p.oldSize??0} -> ${p.newSize??0} bytes`;l.push(` ${g} | ${E}`);continue}let w=p.insertions+p.deletions,b=String(w).padStart(o),y,C;if(r<=a)y=p.insertions,C=p.deletions;else{let P=O=>O===0?0:1+Math.floor(O*(a-1)/r),E=P(w),R=E<2&&p.insertions>0&&p.deletions>0?2:E;p.insertionsp.isUnmerged)&&l.push(" 0 files changed"),`${l.join(` ++`)} ++`}async function Mn(e,t,n){let r=await Ve(e,t,n),s=await xt(e,"diff"),{remaining:o,renames:i}=await bt(e,r,{limit:s});if(o.length===0&&i.length===0)return"";let a=await kr(e,o,i);return a.sort((c,f)=>c.sortKeyf.sortKey?1:0),Nr(a)+Er(o,i)}We();Se();ie();ye();rn();async function ww(e,t){let n=new Set,r=[t],s=0;for(;s0;){let u=0,m=await d(l[0].hash);for(let b=1;bm||C===m&&y.seq{let{branch:i,hash:a}=await tw(e,s);if(a)return{branch:null,head:a};if(!i)return{branch:null,head:null};let c=await e.refStore.readRef(i);return{branch:i,head:c?.type==="direct"?c.hash:null}},n=[],r=e.workTree===null&&e.gitDir===e.commonDir,o=r?e.commonDir:ew(e);if(o){let s=r?{branch:null,head:null}:await t(e.commonDir);n.push({path:o,adminDir:e.commonDir,branch:s.branch,head:s.head,isMain:!0,bare:r,locked:!1,lockReason:null,prunable:null})}for(let s of await Gr(e)){let i=await Jg(e,s.privateDir),a=i?bt(i):null,c=await hi(e,s.privateDir),f=null;i?await e.fs.exists(i)||(f="gitdir file points to non-existent location"):f="gitdir file does not exist";let l=await t(s.privateDir);n.push({path:a??"",adminDir:s.privateDir,branch:l.branch,head:l.head,isMain:!1,bare:!1,locked:c,lockReason:c&&await pi(e,s.privateDir)||null,prunable:f})}return n}async function dc(e){let t=[];for(let n of await An(e))n.head&&t.push(n.head);return t}async function Sd(e,t){for(let n of["rebase-merge","rebase-apply"]){let r=I(t,n,"head-name");if(!await e.fs.exists(r))continue;let o=(await e.fs.readFile(r)).trim();if(o.startsWith("refs/"))return o}return null}async function Hn(e,t,n){for(let r of await An(e))if(r.adminDir!==n&&(r.branch===t||await Sd(e,r.adminDir)===t))return r.path;return null}async function vd(e,t){for(let n of await An(e))if(await Sd(e,n.adminDir)===t)return n.path;return null}Ee();function Id(e,t){return e?"* ":t?"+ ":" "}function Td(e){return{stdout:"",stderr:`fatal: the requested upstream branch '${e}' does not exist ++`)}async function Gd(e,t){let n=I(t,"locked");await e.fs.exists(n)&&await e.fs.rm(n)}async function xi(e,t){return e.fs.exists(I(t,"locked"))}async function Pi(e,t){let n=I(t,"locked");return await e.fs.exists(n)?(await e.fs.readFile(n)).trim():""}async function yw(e,t){let n=I(t,"gitdir");return await e.fs.exists(n)&&(await e.fs.readFile(n)).trim()||null}function kw(e){return e.workTree&&e.gitDir===e.commonDir?e.workTree:Pt(e.commonDir)===".git"?Et(e.commonDir):null}async function Ew(e,t){let n=I(t,"HEAD");if(!await e.fs.exists(n))return{branch:null,hash:null};let r=(await e.fs.readFile(n)).trim();return r.startsWith("ref: ")?{branch:r.slice(5),hash:null}:{branch:null,hash:r}}async function jn(e){let t=async o=>{let{branch:i,hash:a}=await Ew(e,o);if(a)return{branch:null,head:a};if(!i)return{branch:null,head:null};let c=await e.refStore.readRef(i);return{branch:i,head:c?.type==="direct"?c.hash:null}},n=[],r=e.workTree===null&&e.gitDir===e.commonDir,s=r?e.commonDir:kw(e);if(s){let o=r?{branch:null,head:null}:await t(e.commonDir);n.push({path:s,adminDir:e.commonDir,branch:o.branch,head:o.head,isMain:!0,bare:r,locked:!1,lockReason:null,prunable:null})}for(let o of await _r(e)){let i=await yw(e,o.privateDir),a=i?Et(i):null,c=await xi(e,o.privateDir),f=null;i?await e.fs.exists(i)||(f="gitdir file points to non-existent location"):f="gitdir file does not exist";let l=await t(o.privateDir);n.push({path:a??"",adminDir:o.privateDir,branch:l.branch,head:l.head,isMain:!1,bare:!1,locked:c,lockReason:c&&await Pi(e,o.privateDir)||null,prunable:f})}return n}async function Ec(e){let t=[];for(let n of await jn(e))n.head&&t.push(n.head);return t}async function Fd(e,t){for(let n of["rebase-merge","rebase-apply"]){let r=I(t,n,"head-name");if(!await e.fs.exists(r))continue;let s=(await e.fs.readFile(r)).trim();if(s.startsWith("refs/"))return s}return null}async function Ln(e,t,n){for(let r of await jn(e))if(r.adminDir!==n&&(r.branch===t||await Fd(e,r.adminDir)===t))return r.path;return null}async function Nd(e,t){for(let n of await jn(e))if(await Fd(e,n.adminDir)===t)return n.path;return null}ke();function Ud(e,t){return e?"* ":t?"+ ":" "}function _d(e){return{stdout:"",stderr:`fatal: the requested upstream branch '${e}' does not exist + hint: + hint: If you are planning on basing your work on an upstream + hint: branch that already exists at the remote, you may need to +@@ -244,95 +249,95 @@ hint: If you are planning to push out a new local branch that + hint: will track its remote counterpart, you may want to use + hint: "git push -u" to set the upstream config as you push. + hint: Disable this message with "git config set advice.setUpstreamFailure false" +-`,exitCode:128}}async function Ad(e,t,n=""){let r=(await Re(e,"advice.forceDeleteBranch"))?.toLowerCase();return r==="false"?F(`${n}error: the branch '${t}' is not fully merged +-`):r==="true"?F(`${n}error: the branch '${t}' is not fully merged ++`,exitCode:128}}async function Bd(e,t,n=""){let r=(await Re(e,"advice.forceDeleteBranch"))?.toLowerCase();return r==="false"?N(`${n}error: the branch '${t}' is not fully merged ++`):r==="true"?N(`${n}error: the branch '${t}' is not fully merged + hint: If you are sure you want to delete it, run 'git branch -D ${t}' +-`):F(`${n}error: the branch '${t}' is not fully merged ++`):N(`${n}error: the branch '${t}' is not fully merged + hint: If you are sure you want to delete it, run 'git branch -D ${t}' + hint: Disable this message with "git config set advice.forceDeleteBranch false" +-`)}function Hd(e,t){e.command("branch",{description:"List, create, or delete branches",args:[W.string().name("name").describe("Branch name").optional(),W.string().name("newName").describe("New branch name (for -m) or start-point (for create)").optional()],options:{delete:S().alias("d").describe("Delete a branch"),forceDelete:S().alias("D").describe("Force delete a branch"),move:S().alias("m").describe("Rename a branch"),forceMove:S().alias("M").describe("Force rename a branch"),remotes:S().alias("r").describe("List remote-tracking branches"),all:S().alias("a").describe("List all branches"),showCurrent:S().describe("Print the current branch name"),setUpstreamTo:K.string().alias("u").describe("Set upstream tracking branch"),verbose:S().alias("v").count().describe("Show hash and subject"),quiet:ce("suppress informational messages")},handler:async(n,r)=>{let o=await q(r.fs,r.cwd,t);if(D(o))return o;let s=o,i=await te(s),a=i?.type==="symbolic"?Ie(i.target):null;if(n.showCurrent)return{stdout:a?`${a} +-`:"",stderr:"",exitCode:0};let c=!!n.forceMove;if(n.move||c){let b,R;if(n.newName)b=n.name,R=n.newName;else if(n.name){if(!a)return v("not on any branch");b=a,R=n.name}else return v("branch name required");if(!Ln(R))return v(`'${R}' is not a valid branch name`);let C=`refs/heads/${b}`,x=`refs/heads/${R}`,y=await z(s,C);if(!y)return v(`no branch named '${b}'`);let P=await vd(s,C);if(P)return v(`branch ${C} is being rebased at ${P}`);let k=await z(s,x);if(k&&!c)return v(`a branch named '${R}' already exists`);k&&await ke(s,x);let E=await vt(s,C);await Q(s,x,y),await ke(s,C),b===a&&await ot(s,"HEAD",x);let O=`Branch: renamed ${C} to ${x}`;for(let j of await An(s)){if(j.adminDir===s.gitDir||j.branch!==C)continue;await fc(s,j.adminDir,{type:"branch",ref:x});let U={...s,gitDir:j.adminDir,workTree:j.path,refStore:new Pt(s.fs,j.adminDir,s.commonDir)};await ee(U,r.env,"HEAD",oe,y,O)}if(E.length>0&&await ns(s,x,E),await ee(s,r.env,x,y,y,O),b===a){let j=await Jn(s,r.env);await rt(s,"HEAD",{oldHash:y,newHash:oe,...j,message:O}),await rt(s,"HEAD",{oldHash:oe,newHash:y,...j,message:O})}let $=await we(s),T=`branch "${b}"`;return $[T]&&($[`branch "${R}"`]=$[T],delete $[T],await et(s,$)),{stdout:"",stderr:"",exitCode:0}}let f=n.forceDelete;if(n.delete||f){if(!n.name)return v("branch name required");let b=n.name===a;if(!b&&!a&&await wn(s)&&(await Bt(s))?.headName===`refs/heads/${n.name}`&&(b=!0),b)return F(`error: cannot delete branch '${n.name}' used by worktree at '${s.workTree}' +-`);let R=`refs/heads/${n.name}`,C=await Hn(s,R,s.gitDir);if(C)return F(`error: cannot delete branch '${n.name}' used by worktree at '${C}' +-`);let x=await z(s,R);if(!x)return F(`error: branch '${n.name}' not found +-`);let y="";if(!f){let P=await Z(s),E=(await we(s))[`branch "${n.name}"`],O=E?.remote,$=E?.merge,T=null,j=null;if(O&&$&&(T=$.replace(/^refs\/heads\//,`refs/remotes/${O}/`),j=await z(s,T)),j&&T){if(!(x===j||await qt(s,x,j))){let A=P!=null&&(x===P||await qt(s,x,P))?`warning: not deleting branch '${n.name}' that is not yet merged to ++`)}function Wd(e,t){e.command("branch",{description:"List, create, or delete branches",args:[B.string().name("name").describe("Branch name").optional(),B.string().name("newName").describe("New branch name (for -m) or start-point (for create)").optional()],options:{delete:S().alias("d").describe("Delete a branch"),forceDelete:S().alias("D").describe("Force delete a branch"),move:S().alias("m").describe("Rename a branch"),forceMove:S().alias("M").describe("Force rename a branch"),remotes:S().alias("r").describe("List remote-tracking branches"),all:S().alias("a").describe("List all branches"),showCurrent:S().describe("Print the current branch name"),setUpstreamTo:K.string().alias("u").describe("Set upstream tracking branch"),verbose:S().alias("v").count().describe("Show hash and subject"),quiet:ce("suppress informational messages")},handler:async(n,r)=>{let s=await W(r.fs,r.cwd,t);if(D(s))return s;let o=s,i=await ne(o),a=i?.type==="symbolic"?ve(i.target):null;if(n.showCurrent)return{stdout:a?`${a} ++`:"",stderr:"",exitCode:0};let c=!!n.forceMove;if(n.move||c){let b,y;if(n.newName)b=n.name,y=n.newName;else if(n.name){if(!a)return v("not on any branch");b=a,y=n.name}else return v("branch name required");if(!Fn(y))return v(`'${y}' is not a valid branch name`);let C=`refs/heads/${b}`,x=`refs/heads/${y}`,k=await z(o,C);if(!k)return v(`no branch named '${b}'`);let P=await Nd(o,C);if(P)return v(`branch ${C} is being rebased at ${P}`);let E=await z(o,x);if(E&&!c)return v(`a branch named '${y}' already exists`);E&&await Ee(o,x);let R=await Tt(o,C);await Q(o,x,k),await Ee(o,C),b===a&&await ct(o,"HEAD",x);let O=`Branch: renamed ${C} to ${x}`;for(let j of await jn(o)){if(j.adminDir===o.gitDir||j.branch!==C)continue;await yc(o,j.adminDir,{type:"branch",ref:x});let U={...o,gitDir:j.adminDir,workTree:j.path,refStore:new $t(o.fs,j.adminDir,o.commonDir)};await ee(U,r.env,"HEAD",se,k,O)}if(R.length>0&&await os(o,x,R),await ee(o,r.env,x,k,k,O),b===a){let j=await Jn(o,r.env);await st(o,"HEAD",{oldHash:k,newHash:se,...j,message:O}),await st(o,"HEAD",{oldHash:se,newHash:k,...j,message:O})}let $=await be(o),T=`branch "${b}"`;return $[T]&&($[`branch "${y}"`]=$[T],delete $[T],await et(o,$)),{stdout:"",stderr:"",exitCode:0}}let f=n.forceDelete;if(n.delete||f){if(!n.name)return v("branch name required");let b=n.name===a;if(!b&&!a&&await En(o)&&(await zt(o))?.headName===`refs/heads/${n.name}`&&(b=!0),b)return N(`error: cannot delete branch '${n.name}' used by worktree at '${o.workTree}' ++`);let y=`refs/heads/${n.name}`,C=await Ln(o,y,o.gitDir);if(C)return N(`error: cannot delete branch '${n.name}' used by worktree at '${C}' ++`);let x=await z(o,y);if(!x)return N(`error: branch '${n.name}' not found ++`);let k="";if(!f){let P=await Z(o),R=(await be(o))[`branch "${n.name}"`],O=R?.remote,$=R?.merge,T=null,j=null;if(O&&$&&(T=$.replace(/^refs\/heads\//,`refs/remotes/${O}/`),j=await z(o,T)),j&&T){if(!(x===j||await Vt(o,x,j))){let A=P!=null&&(x===P||await Vt(o,x,P))?`warning: not deleting branch '${n.name}' that is not yet merged to + '${T}', even though it is merged to HEAD +-`:"";return Ad(s,n.name,A)}P!=null&&(x===P||await qt(s,x,P))||(y=`warning: deleting branch '${n.name}' that has been merged to ++`:"";return Bd(o,n.name,A)}P!=null&&(x===P||await Vt(o,x,P))||(k=`warning: deleting branch '${n.name}' that has been merged to + '${T}', but not yet merged to HEAD +-`)}else if(P&&x!==P&&!await qt(s,x,P))return Ad(s,n.name)}return await ke(s,R),{stdout:n.quiet?"":`Deleted branch ${n.name} (was ${await ue(s,x)}). +-`,stderr:y,exitCode:0}}if(n.setUpstreamTo){let b=n.setUpstreamTo,R=n.name||a;if(!R)return v("could not set upstream of HEAD when it does not point to any branch.");if(!await z(s,`refs/heads/${R}`))return v(`branch '${R}' does not exist`);let x=b.indexOf("/");if(x<0)return Td(b);let y=b.slice(0,x),P=b.slice(x+1);if(!await z(s,`refs/remotes/${b}`))return Td(b);let E=await we(s),O=`branch "${R}"`;return E[O]||(E[O]={}),E[O].remote=y,E[O].merge=`refs/heads/${P}`,await et(s,E),{stdout:n.quiet?"":`branch '${R}' set up to track '${b}'. +-`,stderr:"",exitCode:0}}if(n.name&&!n.remotes&&!n.all){if(!Ln(n.name))return v(`'${n.name}' is not a valid branch name`);let b=n.newName,R;if(b){let k=await Ge(s,b,`not a valid object name: '${b}'`);if(D(k))return k;R=k.hash}else if(R=await Z(s),!R)return v("Not a valid object name: 'HEAD'.");let C=`refs/heads/${n.name}`;if(await z(s,C))return v(`a branch named '${n.name}' already exists`);await Q(s,C,R);let y=b??"HEAD";await ee(s,r.env,C,null,R,`branch: Created from ${y}`);let P="";return b&&(P=await cs(s,n.name,b)),{stdout:"",stderr:n.quiet?"":P,exitCode:0}}let l=n.verbose||0,d=!n.remotes||n.all,u=n.remotes||n.all,m=[],h=new Set((await An(s)).filter(b=>b.adminDir!==s.gitDir&&b.branch).map(b=>b.branch));if(d&&!a){let b=await Z(s);if(b){let R=await wn(s),C;if(R){let x=await Bt(s);if(x?.headName){let y=Ie(x.headName);if(y==="detached HEAD"){let P=await zs(s);C=`(no branch, rebasing detached HEAD ${P?await ue(s,P):"(null)"})`}else C=`(no branch, rebasing ${y})`}else C="(no branch)"}else{let x=await zs(s);x?C=`(HEAD detached ${b===x?"at":"from"} ${await ue(s,x)})`:C="(no branch)"}m.push({displayName:C,hash:b,isCurrent:!0,branchName:null})}}if(d){let b=await $e(s,"refs/heads");for(let R of b){let C=Ie(R.name);m.push({displayName:C,hash:R.hash,isCurrent:C===a,branchName:C,inOtherWorktree:h.has(R.name)})}}if(u){let b=await $e(s,"refs/remotes");for(let R of b){let C=R.name.replace("refs/remotes/",""),x=null,y=await s.refStore.readRef(R.name);y?.type==="symbolic"&&(x=y.target.replace("refs/remotes/",""));let P=x?n.all?`remotes/${C} -> ${x}`:`${C} -> ${x}`:n.all?`remotes/${C}`:C;m.push({displayName:P,hash:R.hash,isCurrent:!1,branchName:null})}}if(m.length===0)return{stdout:"",stderr:"",exitCode:0};if(l===0)return{stdout:`${m.map(R=>`${Id(R.isCurrent,R.inOtherWorktree)}${R.displayName}`).join(` ++`)}else if(P&&x!==P&&!await Vt(o,x,P))return Bd(o,n.name)}return await Ee(o,y),{stdout:n.quiet?"":`Deleted branch ${n.name} (was ${await fe(o,x)}). ++`,stderr:k,exitCode:0}}if(n.setUpstreamTo){let b=n.setUpstreamTo,y=n.name||a;if(!y)return v("could not set upstream of HEAD when it does not point to any branch.");if(!await z(o,`refs/heads/${y}`))return v(`branch '${y}' does not exist`);let x=b.indexOf("/");if(x<0)return _d(b);let k=b.slice(0,x),P=b.slice(x+1);if(!await z(o,`refs/remotes/${b}`))return _d(b);let R=await be(o),O=`branch "${y}"`;return R[O]||(R[O]={}),R[O].remote=k,R[O].merge=`refs/heads/${P}`,await et(o,R),{stdout:n.quiet?"":`branch '${y}' set up to track '${b}'. ++`,stderr:"",exitCode:0}}if(n.name&&!n.remotes&&!n.all){if(!Fn(n.name))return v(`'${n.name}' is not a valid branch name`);let b=n.newName,y;if(b){let E=await Le(o,b,`not a valid object name: '${b}'`);if(D(E))return E;y=E.hash}else if(y=await Z(o),!y)return v("Not a valid object name: 'HEAD'.");let C=`refs/heads/${n.name}`;if(await z(o,C))return v(`a branch named '${n.name}' already exists`);await Q(o,C,y);let k=b??"HEAD";await ee(o,r.env,C,null,y,`branch: Created from ${k}`);let P="";return b&&(P=await ds(o,n.name,b)),{stdout:"",stderr:n.quiet?"":P,exitCode:0}}let l=n.verbose||0,d=!n.remotes||n.all,u=n.remotes||n.all,m=[],h=new Set((await jn(o)).filter(b=>b.adminDir!==o.gitDir&&b.branch).map(b=>b.branch));if(d&&!a){let b=await Z(o);if(b){let y=await En(o),C;if(y){let x=await zt(o);if(x?.headName){let k=ve(x.headName);if(k==="detached HEAD"){let P=await Qs(o);C=`(no branch, rebasing detached HEAD ${P?await fe(o,P):"(null)"})`}else C=`(no branch, rebasing ${k})`}else C="(no branch)"}else{let x=await Qs(o);x?C=`(HEAD detached ${b===x?"at":"from"} ${await fe(o,x)})`:C="(no branch)"}m.push({displayName:C,hash:b,isCurrent:!0,branchName:null})}}if(d){let b=await $e(o,"refs/heads");for(let y of b){let C=ve(y.name);m.push({displayName:C,hash:y.hash,isCurrent:C===a,branchName:C,inOtherWorktree:h.has(y.name)})}}if(u){let b=await $e(o,"refs/remotes");for(let y of b){let C=y.name.replace("refs/remotes/",""),x=null,k=await o.refStore.readRef(y.name);k?.type==="symbolic"&&(x=k.target.replace("refs/remotes/",""));let P=x?n.all?`remotes/${C} -> ${x}`:`${C} -> ${x}`:n.all?`remotes/${C}`:C;m.push({displayName:P,hash:y.hash,isCurrent:!1,branchName:null})}}if(m.length===0)return{stdout:"",stderr:"",exitCode:0};if(l===0)return{stdout:`${m.map(y=>`${Ud(y.isCurrent,y.inOtherWorktree)}${y.displayName}`).join(` + `)} +-`,stderr:"",exitCode:0};let p=l>=1?await we(s):null,g=Math.max(...m.map(b=>b.displayName.length)),w=[];for(let b of m){let R=Id(b.isCurrent,b.inOtherWorktree),C=b.displayName.padEnd(g),x=await ue(s,b.hash),y="";try{let k=await M(s,b.hash);y=me(k.message)}catch{}let P="";if(p&&b.branchName){let k=await nn(s,p,b.branchName);if(k){let E=ri(k,l>=2);E&&(P=` ${E}`)}}w.push(`${R}${C} ${x}${P} ${y}`)}return{stdout:`${w.join(` ++`,stderr:"",exitCode:0};let p=l>=1?await be(o):null,g=Math.max(...m.map(b=>b.displayName.length)),w=[];for(let b of m){let y=Ud(b.isCurrent,b.inOtherWorktree),C=b.displayName.padEnd(g),x=await fe(o,b.hash),k="";try{let E=await M(o,b.hash);k=he(E.message)}catch{}let P="";if(p&&b.branchName){let E=await an(o,p,b.branchName);if(E){let R=mi(E,l>=2);R&&(P=` ${R}`)}}w.push(`${y}${C} ${x}${P} ${k}`)}return{stdout:`${w.join(` + `)} +-`,stderr:"",exitCode:0}}})}function he(e){return e!=null&&typeof e=="object"&&"reject"in e&&e.reject===!0}var nw=["preCommit","preMergeCommit","preCheckout","prePush","preFetch","preClone","prePull","preRebase","preReset","preCherryPick","preRevert","beforeCommand"],rw=["commitMsg","mergeMsg"],sw=["postCommit","postMerge","postCheckout","postPush","postFetch","postClone","postPull","postReset","postCherryPick","postRevert","afterCommand"],ow=["onRefUpdate","onRefDelete","onObjectWrite"];function iw(...e){let t=e.filter(r=>r!=null);if(t.length===0)return{};if(t.length===1)return t[0];let n={};for(let r of nw){let o=t.filter(s=>s[r]).map(s=>s[r]);o.length>0&&(n[r]=async s=>{for(let i of o){let a=await i(s);if(he(a))return a}})}for(let r of rw){let o=t.filter(s=>s[r]).map(s=>s[r]);o.length>0&&(n[r]=async s=>{for(let i of o){let a=await i(s);if(he(a))return a}})}for(let r of sw){let o=t.filter(s=>s[r]).map(s=>s[r]);o.length>0&&(n[r]=async s=>{for(let i of o)try{await i(s)}catch{}})}for(let r of ow){let o=t.filter(s=>s[r]).map(s=>s[r]);o.length>0&&(n[r]=s=>{for(let i of o)try{i(s)}catch{}})}return n}ne();Be();ve();ae();Ve();ye();Qt();Jt();st();Ee();function Md(e,t){e.command("checkout",{description:"Switch branches or restore working tree files",args:[W.string().name("target").describe("Branch, commit, path, or start-point for -b/-B").optional()],options:{branch:K.string().alias("b").describe("Create and switch to a new branch"),forceBranch:K.string().alias("B").describe("Create/reset and switch to a new branch"),detach:S().alias("d").describe("Detach HEAD at named commit"),orphan:S().describe("Create a new orphan branch"),ours:S().describe("Checkout our version for unmerged files"),theirs:S().describe("Checkout their version for unmerged files"),ignoreOtherWorktrees:S().describe("Allow checking out a branch used by another worktree"),quiet:ce("suppress progress reporting")},handler:async(n,r,o)=>{let s=await q(r.fs,r.cwd,t);if(D(s))return s;let i=s,a=n.target,c=!!n.quiet;if(n.ours&&n.theirs)return v("--ours and --theirs are incompatible");if(n.detach&&(n.branch||n.forceBranch||n.orphan))return v("'--detach' cannot be used with '-b/-B/--orphan'");if(o.passthrough.length>0){if(n.detach)return v(`git checkout: --detach does not take a path argument '${o.passthrough[0]}'`);let m=kt(i,r.cwd),h=o.passthrough,p=null;if(a){if(n.ours||n.theirs)return v("cannot specify both a revision and --ours/--theirs");let g=await Ge(i,a,`invalid reference: ${a}`);if(D(g))return g;p=g.commit.tree}return n.ours||n.theirs?oi(i,h,m,n.theirs?3:2):si(i,h,m,p)}if(n.orphan)return n.branch?v("--orphan and -b are incompatible"):n.ours||n.theirs?v("--orphan and --ours/--theirs are incompatible"):a?cw(i,a,r.env,t,c):v("you must specify a branch to checkout");if(n.detach){let m=a??"HEAD",h=await Ge(i,m,`invalid reference: ${m}`);return D(h)?h:Dd(i,m,h.hash,r.env,t,c)}if(n.branch||n.forceBranch){let m=n.branch||n.forceBranch;return fw(i,m,a,r.env,t,!!n.forceBranch,!!n.ignoreOtherWorktrees,c)}if(!a)return v("you must specify a branch to checkout");if(a==="-")return aw(i,r.env,t,c);let f=`refs/heads/${a}`,l=await z(i,f);if(l){if(!n.ignoreOtherWorktrees){let m=await Hn(i,f,i.gitDir);if(m)return v(`'${a}' is already used by worktree at '${m}'`)}return jd(i,a,f,l,r.env,t,c)}let d=await fs(i,a);if(d)return lw(i,a,d.trackingRef,r.env,t,c);let u=await Le(i,a);if(u){let m=await Se(i,u);return Dd(i,a,m,r.env,t,c)}if(i.workTree){let m=await X(i),h=Kr(m,a);if(h)return await at(i,{path:h.path,hash:h.hash,mode:h.mode}),{stdout:"",stderr:"",exitCode:0}}return F(`error: pathspec '${a}' did not match any file(s) known to git +-`)}})}async function aw(e,t,n,r=!1){let o=await od(e);return o?jd(e,o.name,o.refName,o.hash,t,n,r):v("no previous branch")}async function cw(e,t,n,r,o=!1){if(!Ln(t))return v(`'${t}' is not a valid branch name`);let s=`refs/heads/${t}`;if(await z(e,s))return v(`a branch named '${t}' already exists`);let a=await X(e),c=mr(a);if(c)return c;let f=await Z(e),l=null;f&&(l=(await M(e,f)).tree),await ot(e,"HEAD",s),await Tt(e);let d=await Wn(e,o);if(await r?.hooks?.postCheckout?.({repo:e,prevHead:f,newHead:oe,isBranchCheckout:!0}),o)return{stdout:"",stderr:"",exitCode:0};let u="";return l&&(u=await hr(e,l,a)),{stdout:u,stderr:`Switched to a new branch '${t}' +-${d}`,exitCode:0}}async function fw(e,t,n,r,o,s=!1,i=!1,a=!1){if(!Ln(t))return v(`'${t}' is not a valid branch name`);let c=await o?.hooks?.preCheckout?.({repo:e,target:t,mode:"create-branch"});if(he(c))return F(c.message??"");let f=await te(e),l=await Z(e),d=`refs/heads/${t}`,u=await z(e,d);if(u&&!s)return v(`a branch named '${t}' already exists`);if(u&&!i){let P=await Hn(e,d,e.gitDir);if(P)return v(`'${t}' is already used by worktree at '${P}'`)}let m;if(n){let P=await Ge(e,n,`invalid reference: ${n}`);if(D(P))return P;m=P.hash}else m=l;if(s||n||a){let P=await X(e),k=mr(P);if(k)return k}m&&await Q(e,d,m);let h=await X(e);if(m&&l&&m!==l){let P=await M(e,l),k=await M(e,m);if(P.tree!==k.tree){let E=await On(e,P.tree,k.tree,h);if(!E.success)return E.errorOutput??F("error: checkout would overwrite local changes");h={version:2,entries:E.newEntries},await ie(e,h),await je(e,E.worktreeOps)}}await ot(e,"HEAD",d),await Tt(e);let p=await Wn(e,a),g=f?.type==="symbolic"?f.target.replace(/^refs\/heads\//,""):l??oe,w=n??"HEAD";if(m&&(u?u!==m&&await ee(e,r,d,u,m,`branch: Reset to ${w}`):await ee(e,r,d,null,m,`branch: Created from ${w}`)),await ee(e,r,"HEAD",l,m??oe,`checkout: moving from ${g} to ${t}`),await o?.hooks?.postCheckout?.({repo:e,prevHead:l,newHead:m??oe,isBranchCheckout:!0}),a)return{stdout:"",stderr:"",exitCode:0};let b="";if((s||n)&&m){let P=await M(e,m);b=await hr(e,P.tree,h)}let R=await we(e),C=await nn(e,R,t);C&&(b+=ur(C));let x=f?.type==="symbolic"&&f.target===d,y=u?x?`Reset branch '${t}' ++`,stderr:"",exitCode:0}}})}function pe(e){return e!=null&&typeof e=="object"&&"reject"in e&&e.reject===!0}var Rw=["preCommit","preMergeCommit","preCheckout","prePush","preFetch","preClone","prePull","preRebase","preReset","preCherryPick","preRevert","beforeCommand"],Cw=["commitMsg","mergeMsg"],xw=["postCommit","postMerge","postCheckout","postPush","postFetch","postClone","postPull","postReset","postCherryPick","postRevert","afterCommand"],Pw=["onRefUpdate","onRefDelete","onObjectWrite"];function $w(...e){let t=e.filter(r=>r!=null);if(t.length===0)return{};if(t.length===1)return t[0];let n={};for(let r of Rw){let s=t.filter(o=>o[r]).map(o=>o[r]);s.length>0&&(n[r]=async o=>{for(let i of s){let a=await i(o);if(pe(a))return a}})}for(let r of Cw){let s=t.filter(o=>o[r]).map(o=>o[r]);s.length>0&&(n[r]=async o=>{for(let i of s){let a=await i(o);if(pe(a))return a}})}for(let r of xw){let s=t.filter(o=>o[r]).map(o=>o[r]);s.length>0&&(n[r]=async o=>{for(let i of s)try{await i(o)}catch{}})}for(let r of Pw){let s=t.filter(o=>o[r]).map(o=>o[r]);s.length>0&&(n[r]=o=>{for(let i of s)try{i(o)}catch{}})}return n}te();We();Se();ie();Xe();ye();Ft();rn();ot();ke();function zd(e,t){e.command("checkout",{description:"Switch branches or restore working tree files",args:[B.string().name("target").describe("Branch, commit, path, or start-point for -b/-B").optional()],options:{branch:K.string().alias("b").describe("Create and switch to a new branch"),forceBranch:K.string().alias("B").describe("Create/reset and switch to a new branch"),detach:S().alias("d").describe("Detach HEAD at named commit"),orphan:S().describe("Create a new orphan branch"),ours:S().describe("Checkout our version for unmerged files"),theirs:S().describe("Checkout their version for unmerged files"),ignoreOtherWorktrees:S().describe("Allow checking out a branch used by another worktree"),quiet:ce("suppress progress reporting")},handler:async(n,r,s)=>{let o=await W(r.fs,r.cwd,t);if(D(o))return o;let i=o,a=n.target,c=!!n.quiet;if(n.ours&&n.theirs)return v("--ours and --theirs are incompatible");if(n.detach&&(n.branch||n.forceBranch||n.orphan))return v("'--detach' cannot be used with '-b/-B/--orphan'");if(s.passthrough.length>0){if(n.detach)return v(`git checkout: --detach does not take a path argument '${s.passthrough[0]}'`);let m=ut(i,r.cwd),h=s.passthrough,p=null;if(a){if(n.ours||n.theirs)return v("cannot specify both a revision and --ours/--theirs");let g=await Le(i,a,`invalid reference: ${a}`);if(D(g))return g;p=g.commit.tree}return n.ours||n.theirs?pi(i,h,m,n.theirs?3:2):hi(i,h,m,p)}if(n.orphan)return n.branch?v("--orphan and -b are incompatible"):n.ours||n.theirs?v("--orphan and --ours/--theirs are incompatible"):a?Sw(i,a,r.env,t,c):v("you must specify a branch to checkout");if(n.detach){let m=a??"HEAD",h=await Le(i,m,`invalid reference: ${m}`);return D(h)?h:qd(i,m,h.hash,r.env,t,c)}if(n.branch||n.forceBranch){let m=n.branch||n.forceBranch;return vw(i,m,a,r.env,t,!!n.forceBranch,!!n.ignoreOtherWorktrees,c)}if(!a)return v("you must specify a branch to checkout");if(a==="-")return Ow(i,r.env,t,c);let f=`refs/heads/${a}`,l=await z(i,f);if(l){if(!n.ignoreOtherWorktrees){let m=await Ln(i,f,i.gitDir);if(m)return v(`'${a}' is already used by worktree at '${m}'`)}return Kd(i,a,f,l,r.env,t,c)}let d=await us(i,a);if(d)return Iw(i,a,d.trackingRef,r.env,t,c);let u=await Ie(i,a);if(u){let m=await Oe(i,u);return qd(i,a,m,r.env,t,c)}if(i.workTree){let m=await X(i),h=Zr(m,a);if(h)return await lt(i,{path:h.path,hash:h.hash,mode:h.mode}),{stdout:"",stderr:"",exitCode:0}}return N(`error: pathspec '${a}' did not match any file(s) known to git ++`)}})}async function Ow(e,t,n,r=!1){let s=await pd(e);return s?Kd(e,s.name,s.refName,s.hash,t,n,r):v("no previous branch")}async function Sw(e,t,n,r,s=!1){if(!Fn(t))return v(`'${t}' is not a valid branch name`);let o=`refs/heads/${t}`;if(await z(e,o))return v(`a branch named '${t}' already exists`);let a=await X(e),c=mr(a);if(c)return c;let f=await Z(e),l=null;f&&(l=(await M(e,f)).tree),await ct(e,"HEAD",o),await Ht(e);let d=await qn(e,s);if(await r?.hooks?.postCheckout?.({repo:e,prevHead:f,newHead:se,isBranchCheckout:!0}),s)return{stdout:"",stderr:"",exitCode:0};let u="";return l&&(u=await hr(e,l,a)),{stdout:u,stderr:`Switched to a new branch '${t}' ++${d}`,exitCode:0}}async function vw(e,t,n,r,s,o=!1,i=!1,a=!1){if(!Fn(t))return v(`'${t}' is not a valid branch name`);let c=await s?.hooks?.preCheckout?.({repo:e,target:t,mode:"create-branch"});if(pe(c))return N(c.message??"");let f=await ne(e),l=await Z(e),d=`refs/heads/${t}`,u=await z(e,d);if(u&&!o)return v(`a branch named '${t}' already exists`);if(u&&!i){let P=await Ln(e,d,e.gitDir);if(P)return v(`'${t}' is already used by worktree at '${P}'`)}let m;if(n){let P=await Le(e,n,`invalid reference: ${n}`);if(D(P))return P;m=P.hash}else m=l;if(o||n||a){let P=await X(e),E=mr(P);if(E)return E}m&&await Q(e,d,m);let h=await X(e);if(m&&l&&m!==l){let P=await M(e,l),E=await M(e,m);if(P.tree!==E.tree){let R=await Tn(e,P.tree,E.tree,h);if(!R.success)return R.errorOutput??N("error: checkout would overwrite local changes");h={version:2,entries:R.newEntries},await oe(e,h),await Me(e,R.worktreeOps)}}await ct(e,"HEAD",d),await Ht(e);let p=await qn(e,a),g=f?.type==="symbolic"?f.target.replace(/^refs\/heads\//,""):l??se,w=n??"HEAD";if(m&&(u?u!==m&&await ee(e,r,d,u,m,`branch: Reset to ${w}`):await ee(e,r,d,null,m,`branch: Created from ${w}`)),await ee(e,r,"HEAD",l,m??se,`checkout: moving from ${g} to ${t}`),await s?.hooks?.postCheckout?.({repo:e,prevHead:l,newHead:m??se,isBranchCheckout:!0}),a)return{stdout:"",stderr:"",exitCode:0};let b="";if((o||n)&&m){let P=await M(e,m);b=await hr(e,P.tree,h)}let y=await be(e),C=await an(e,y,t);C&&(b+=ur(C));let x=f?.type==="symbolic"&&f.target===d,k=u?x?`Reset branch '${t}' + `:`Switched to and reset branch '${t}' + `:`Switched to a new branch '${t}' +-`;return{stdout:b,stderr:`${y}${p}`,exitCode:0}}async function jd(e,t,n,r,o,s,i=!1){let a=await s?.hooks?.preCheckout?.({repo:e,target:t,mode:"switch"});return he(a)?F(a.message??""):Mr(e,t,n,r,o,s,{quiet:i})}async function lw(e,t,n,r,o,s=!1){let i=await o?.hooks?.preCheckout?.({repo:e,target:t,mode:"create-branch"});if(he(i))return F(i.message??"");let a=await z(e,n);if(!a)return v(`invalid reference: ${n}`);let c=`refs/heads/${t}`;await Q(e,c,a);let f=n.replace(/^refs\/remotes\//,"").split("/"),l=f[0]??"",d=`refs/heads/${f.slice(1).join("/")}`,u=await we(e);u[`branch "${t}"`]={...u[`branch "${t}"`],remote:l,merge:d},await et(e,u),await ee(e,r,c,null,a,`branch: Created from ${n}`);let m=await Mr(e,t,c,a,r,o,{isNew:!0,quiet:s});if(s)return m;let h=f.slice(1).join("/");return m.stdout=`branch '${t}' set up to track '${l}/${h}'. +-`,m}async function Dd(e,t,n,r,o,s=!1){let i=await o?.hooks?.preCheckout?.({repo:e,target:t,mode:"detach"});return he(i)?F(i.message??""):pr(e,n,r,o,{detachAdviceTarget:t,quiet:s})}ne();Be();ve();ne();function uc(e,t){let n=e.length,r=t.length;if(n===0&&r===0)return[];if(n===0)return[{buffer1:[0,0],buffer2:[0,r]}];if(r===0)return[{buffer1:[0,n],buffer2:[0,0]}];let{changedOld:o,changedNew:s}=cc(e,t);return dw(o,n,s,r)}function dw(e,t,n,r){let o=[],s=0,i=0;for(;s=t&&i>=r)break;let a=s,c=i;for(;sa||i>c)&&o.push({buffer1:[a,s-a],buffer2:[c,i-c]})}return o}function uw(e,t,n){let r=[];for(let c of uc(t,e))r.push({ab:"a",oStart:c.buffer1[0],oLength:c.buffer1[1],abStart:c.buffer2[0],abLength:c.buffer2[1]});for(let c of uc(t,n))r.push({ab:"b",oStart:c.buffer1[0],oLength:c.buffer1[1],abStart:c.buffer2[0],abLength:c.buffer2[1]});r.sort((c,f)=>c.oStart-f.oStart);let o=[],s=0;function i(c){c>s&&(o.push({stable:!0,buffer:"o",bufferStart:s,bufferLength:c-s,content:t.slice(s,c)}),s=c)}let a=0;for(;al)break;l=Math.max(l,u.oStart+u.oLength),d.push(u),a++}if(d.length===1){if(c.abLength>0){let u=c.ab==="a"?e:n;o.push({stable:!0,buffer:c.ab,bufferStart:c.abStart,bufferLength:c.abLength,content:u.slice(c.abStart,c.abStart+c.abLength)})}}else{let u={a:{abMin:e.length,abMax:-1,oMin:t.length,oMax:-1},b:{abMin:n.length,abMax:-1,oMin:t.length,oMax:-1}};for(let w of d){let b=w.oStart,R=b+w.oLength,C=w.abStart,x=C+w.abLength,y=u[w.ab];y.abMin=Math.min(C,y.abMin),y.abMax=Math.max(x,y.abMax),y.oMin=Math.min(b,y.oMin),y.oMax=Math.max(R,y.oMax)}let m=u.a.abMin+(f-u.a.oMin),h=u.a.abMax+(l-u.a.oMax),p=u.b.abMin+(f-u.b.oMin),g=u.b.abMax+(l-u.b.oMax);o.push({stable:!1,a:e.slice(m,h),o:t.slice(f,l),b:n.slice(p,g)})}s=l}return i(t.length),o}function mw(e,t,n,r){let o=r?.excludeFalseConflicts??!0,s=uw(e,t,n),i=[],a=[];function c(){a.length&&(i.push({type:"ok",lines:a}),a=[])}for(let f of s)f.stable?a.push(...f.content):o&&Gd(f.a,f.b)?a.push(...f.a):(c(),i.push({type:"conflict",a:f.a,o:f.o,b:f.b}));return c(),r?.conflictStyle==="diff3"?Ld(i):Ld(hw(i))}function Qs(e,t,n,r){let o=r?.markerSize??7,s=r?.conflictStyle??"merge",i=`${"<".repeat(o)}${r?.a?` ${r.a}`:""}`,a=`${"|".repeat(o)}${r?.o?` ${r.o}`:""}`,c="=".repeat(o),f=`${">".repeat(o)}${r?.b?` ${r.b}`:""}`,l=mw(e,t,n,{conflictStyle:s}),d=!1,u=[];for(let m of l)m.type==="ok"?u.push(...m.lines):(d=!0,s==="diff3"?u.push(i,...m.a,a,...m.o,c,...m.b,f):u.push(i,...m.a,c,...m.b,f));return{conflict:d,result:u}}function hw(e){let t=[];for(let n of e)n.type==="ok"?t.push(n):t.push(...pw(n));return t}function pw(e){let{a:t,b:n}=e;if(t.length===0||n.length===0)return[e];if(Gd(t,n))return[e];let r=uc(t,n);if(r.length===0)return[{type:"ok",lines:t}];let o=[],s=0;for(let a of r){let c=a.buffer1[0];c-s>0&&o.push({type:"ok",lines:t.slice(s,c)});let l=c+a.buffer1[1],d=a.buffer2[0]+a.buffer2[1];o.push({type:"conflict",a:t.slice(c,l),o:[],b:n.slice(a.buffer2[0],d)}),s=l}return t.length-s>0&&o.push({type:"ok",lines:t.slice(s)}),o.length===1&&o[0].type==="conflict"?[e]:o}function Ld(e){if(e.length<3)return e;let t=[e[0]];for(let r=1;r>>>>>>")||!i?`${a.join(` ++`;return{stdout:b,stderr:`${k}${p}`,exitCode:0}}async function Kd(e,t,n,r,s,o,i=!1){let a=await o?.hooks?.preCheckout?.({repo:e,target:t,mode:"switch"});return pe(a)?N(a.message??""):Fr(e,t,n,r,s,o,{quiet:i})}async function Iw(e,t,n,r,s,o=!1){let i=await s?.hooks?.preCheckout?.({repo:e,target:t,mode:"create-branch"});if(pe(i))return N(i.message??"");let a=await z(e,n);if(!a)return v(`invalid reference: ${n}`);let c=`refs/heads/${t}`;await Q(e,c,a);let f=n.replace(/^refs\/remotes\//,"").split("/"),l=f[0]??"",d=`refs/heads/${f.slice(1).join("/")}`,u=await be(e);u[`branch "${t}"`]={...u[`branch "${t}"`],remote:l,merge:d},await et(e,u),await ee(e,r,c,null,a,`branch: Created from ${n}`);let m=await Fr(e,t,c,a,r,s,{isNew:!0,quiet:o});if(o)return m;let h=f.slice(1).join("/");return m.stdout=`branch '${t}' set up to track '${l}/${h}'. ++`,m}async function qd(e,t,n,r,s,o=!1){let i=await s?.hooks?.preCheckout?.({repo:e,target:t,mode:"detach"});return pe(i)?N(i.message??""):pr(e,n,r,s,{detachAdviceTarget:t,quiet:o})}te();We();Se();te();function Rc(e,t){let n=e.length,r=t.length;if(n===0&&r===0)return[];if(n===0)return[{buffer1:[0,0],buffer2:[0,r]}];if(r===0)return[{buffer1:[0,n],buffer2:[0,0]}];let{changedOld:s,changedNew:o}=wc(e,t);return Tw(s,n,o,r)}function Tw(e,t,n,r){let s=[],o=0,i=0;for(;o=t&&i>=r)break;let a=o,c=i;for(;oa||i>c)&&s.push({buffer1:[a,o-a],buffer2:[c,i-c]})}return s}function Aw(e,t,n){let r=[];for(let c of Rc(t,e))r.push({ab:"a",oStart:c.buffer1[0],oLength:c.buffer1[1],abStart:c.buffer2[0],abLength:c.buffer2[1]});for(let c of Rc(t,n))r.push({ab:"b",oStart:c.buffer1[0],oLength:c.buffer1[1],abStart:c.buffer2[0],abLength:c.buffer2[1]});r.sort((c,f)=>c.oStart-f.oStart);let s=[],o=0;function i(c){c>o&&(s.push({stable:!0,buffer:"o",bufferStart:o,bufferLength:c-o,content:t.slice(o,c)}),o=c)}let a=0;for(;al)break;l=Math.max(l,u.oStart+u.oLength),d.push(u),a++}if(d.length===1){if(c.abLength>0){let u=c.ab==="a"?e:n;s.push({stable:!0,buffer:c.ab,bufferStart:c.abStart,bufferLength:c.abLength,content:u.slice(c.abStart,c.abStart+c.abLength)})}}else{let u={a:{abMin:e.length,abMax:-1,oMin:t.length,oMax:-1},b:{abMin:n.length,abMax:-1,oMin:t.length,oMax:-1}};for(let w of d){let b=w.oStart,y=b+w.oLength,C=w.abStart,x=C+w.abLength,k=u[w.ab];k.abMin=Math.min(C,k.abMin),k.abMax=Math.max(x,k.abMax),k.oMin=Math.min(b,k.oMin),k.oMax=Math.max(y,k.oMax)}let m=u.a.abMin+(f-u.a.oMin),h=u.a.abMax+(l-u.a.oMax),p=u.b.abMin+(f-u.b.oMin),g=u.b.abMax+(l-u.b.oMax);s.push({stable:!1,a:e.slice(m,h),o:t.slice(f,l),b:n.slice(p,g)})}o=l}return i(t.length),s}function Hw(e,t,n,r){let s=r?.excludeFalseConflicts??!0,o=Aw(e,t,n),i=[],a=[];function c(){a.length&&(i.push({type:"ok",lines:a}),a=[])}for(let f of o)f.stable?a.push(...f.content):s&&Yd(f.a,f.b)?a.push(...f.a):(c(),i.push({type:"conflict",a:f.a,o:f.o,b:f.b}));return c(),r?.conflictStyle==="diff3"?Vd(i):Vd(Dw(i))}function oo(e,t,n,r){let s=r?.markerSize??7,o=r?.conflictStyle??"merge",i=`${"<".repeat(s)}${r?.a?` ${r.a}`:""}`,a=`${"|".repeat(s)}${r?.o?` ${r.o}`:""}`,c="=".repeat(s),f=`${">".repeat(s)}${r?.b?` ${r.b}`:""}`,l=Hw(e,t,n,{conflictStyle:o}),d=!1,u=[];for(let m of l)m.type==="ok"?u.push(...m.lines):(d=!0,o==="diff3"?u.push(i,...m.a,a,...m.o,c,...m.b,f):u.push(i,...m.a,c,...m.b,f));return{conflict:d,result:u}}function Dw(e){let t=[];for(let n of e)n.type==="ok"?t.push(n):t.push(...Mw(n));return t}function Mw(e){let{a:t,b:n}=e;if(t.length===0||n.length===0)return[e];if(Yd(t,n))return[e];let r=Rc(t,n);if(r.length===0)return[{type:"ok",lines:t}];let s=[],o=0;for(let a of r){let c=a.buffer1[0];c-o>0&&s.push({type:"ok",lines:t.slice(o,c)});let l=c+a.buffer1[1],d=a.buffer2[0]+a.buffer2[1];s.push({type:"conflict",a:t.slice(c,l),o:[],b:n.slice(a.buffer2[0],d)}),o=l}return t.length-o>0&&s.push({type:"ok",lines:t.slice(o)}),s.length===1&&s[0].type==="conflict"?[e]:s}function Vd(e){if(e.length<3)return e;let t=[e[0]];for(let r=1;r>>>>>>")||!i?`${a.join(` + `)} + `:a.join(` +-`)}function zt(e){if(e==="")return[];let t=e.split(` +-`);if(t[t.length-1]==="")t.pop();else{let n=t[t.length-1]??"";t[t.length-1]=`${n}\0`}return t}function mc(e){return e.endsWith("\0")?e.slice(0,-1):e}function Gd(e,t){if(e.length!==t.length)return!1;for(let n=0;nA.newPath)),x=new Set(u.renames.map(A=>A.newPath)),y=Nd(n,r),P=Nd(n,o),k=Ud(y,o,n),E=Ud(P,r,n),O=_d(d.renames,k),$=_d(u.renames,E),T=Bd(O),j=Bd($);for(let A of[...T.keys()])j.has(A)&&(T.delete(A),j.delete(A));let U=new Set(T.keys()),G=new Set(j.keys());if(j.size>0)for(let A of c){if(A.status!=="added"||C.has(A.path))continue;let H=Wd(A.path,j,U);if(!H)continue;if(t.has(H)||n.has(H)||r.has(H)||o.has(H)){if(r.has(H)){R(H,`CONFLICT (implicit dir rename): Existing file/dir at ${H} in the way of implicit directory rename(s) putting the following path(s) there: ${A.path}.`,1);continue}let _=r.get(A.path),V=o.get(H)??n.get(H);a.entries.push(wt(H,_.mode,_.hash,2)),V&&a.entries.push(wt(H,V.mode,V.hash,3)),a.worktreeBlobs.set(H,{hash:_.hash,mode:_.mode}),a.conflicts.push({path:H,reason:"add-add"}),R(H,`CONFLICT (file location): ${A.path} added in ${w} inside a directory that was renamed in ${b}, suggesting it should perhaps be moved to ${H}.`,1);let Y=t.get(A.path);Y&&(Y.merged={result:null,clean:!0}),g.add(A.path);continue}let B=r.get(A.path);a.entries.push(wt(H,B.mode,B.hash,2)),a.worktreeBlobs.set(H,{hash:B.hash,mode:B.mode}),a.conflicts.push({path:H,reason:"directory-rename"}),R(H,`CONFLICT (file location): ${A.path} added in ${w} inside a directory that was renamed in ${b}, suggesting it should perhaps be moved to ${H}.`,1);let L=t.get(A.path);L&&(L.merged={result:null,clean:!0}),g.add(A.path)}if(T.size>0)for(let A of f){if(A.status!=="added"||x.has(A.path))continue;let H=Wd(A.path,T,G);if(!H)continue;if(t.has(H)||n.has(H)||r.has(H)||o.has(H)){if(o.has(H)){R(H,`CONFLICT (implicit dir rename): Existing file/dir at ${H} in the way of implicit directory rename(s) putting the following path(s) there: ${A.path}.`,1);continue}let _=o.get(A.path),V=r.get(H)??n.get(H);V&&a.entries.push(wt(H,V.mode,V.hash,2)),a.entries.push(wt(H,_.mode,_.hash,3)),a.worktreeBlobs.set(H,{hash:_.hash,mode:_.mode}),a.conflicts.push({path:H,reason:"add-add"}),R(H,`CONFLICT (file location): ${A.path} added in ${b} inside a directory that was renamed in ${w}, suggesting it should perhaps be moved to ${H}.`,1);let Y=t.get(A.path);Y&&(Y.merged={result:null,clean:!0}),g.add(A.path);continue}let B=o.get(A.path);a.entries.push(wt(H,B.mode,B.hash,3)),a.worktreeBlobs.set(H,{hash:B.hash,mode:B.mode}),a.conflicts.push({path:H,reason:"directory-rename"}),R(H,`CONFLICT (file location): ${A.path} added in ${b} inside a directory that was renamed in ${w}, suggesting it should perhaps be moved to ${H}.`,1);let L=t.get(A.path);L&&(L.merged={result:null,clean:!0}),g.add(A.path)}let N=new Set(a.entries.map(A=>A.path));for(let A of N){let H=t.get(A);H&&(H.merged={result:null,clean:!0})}for(let A of g){if(N.has(A))continue;let H=t.get(A);if(!H||H.merged.clean)continue;H.filemask===7&&!H.pathConflict||(H.merged={result:null,clean:!0})}return a}function Nd(e,t){let n=new Set;for(let s of e.keys()){let i=Kt(s);for(;i;)n.add(i),i=Kt(i)}let r=new Set;for(let s of t.keys()){let i=Kt(s);for(;i;)r.add(i),i=Kt(i)}let o=new Set;for(let s of n)r.has(s)||o.add(s);return o}function Ud(e,t,n){if(e.size===0)return e;let r=new Set;for(let o of t.keys()){if(n.has(o))continue;let s=Kt(o)??"";e.has(s)&&r.add(s)}for(let o of[...r]){let s=Kt(o);for(;s;)e.has(s)&&!r.has(s)&&r.add(s),s=Kt(s)}return r}function _d(e,t){let n=new Map;for(let r of e){let o=Kt(r.oldPath),s=Kt(r.newPath),i=!0;for(;;){if(!i){let a=o.length+(o?1:0),c=s.length+(s?1:0),f=r.oldPath.slice(a,r.oldPath.indexOf("/",a)),l=r.newPath.slice(c,r.newPath.indexOf("/",c));if(f!==l)break}if(t.has(o)){let a=n.get(o);a||(a=new Map,n.set(o,a)),a.set(s,(a.get(s)??0)+1)}if(i=!1,!o||!s)break;o=Kt(o),s=Kt(s)}}return n}function Bd(e){let t=new Map;for(let[n,r]of e){let o=0,s=0,i=null;for(let[a,c]of r)c===o?s=o:c>o&&(o=c,i=a);o>0&&s!==o&&i!==null&&t.set(n,i)}return t}function Wd(e,t,n){let r=Kt(e);for(;r;){let s=t.get(r);if(s!==void 0){if(n.has(s))return null;let i=e.slice(r.length+1);return s?`${s}/${i}`:i}r=Kt(r)}let o=t.get("");return o!==void 0&&!n.has(o)?`${o}/${e}`:null}function Kt(e){let t=e.lastIndexOf("/");return t===-1?"":e.slice(0,t)}async function qd(e,t,n,r,o,s,i,a,c,f=!1,l,d){let u=f?a.get(n):c.get(n),m=f?i:s;if(u.hash===m.hash){t.entries.push(wt(n,u.mode,u.hash)),t.msgBuf.push({sortKey:r,subOrder:0,text:`Auto-merging ${r}`});return}let p=await Kd(e,o,s,i,l,f?{oursPath:r,theirsPath:n}:{oursPath:n,theirsPath:r},8,d);if(u.hash===p.hash)t.entries.push(wt(n,u.mode,p.hash));else if(t.conflicts.push({path:n,reason:"add-add"}),t.msgBuf.push({sortKey:n,subOrder:0,text:`Auto-merging ${n}`}),t.msgBuf.push({sortKey:n,subOrder:1,text:`CONFLICT (add/add): Merge conflict in ${n}`}),f){t.entries.push(Dt(n,u,2)),t.entries.push(wt(n,i.mode,p.hash,3));let g=await gi(e,u.hash,p.hash,u.mode,l);t.worktreeBlobs.set(n,{hash:g,mode:u.mode})}else{t.entries.push(wt(n,s.mode,p.hash,2)),t.entries.push(Dt(n,u,3));let g=await gi(e,p.hash,u.hash,s.mode,l);t.worktreeBlobs.set(n,{hash:g,mode:s.mode})}}async function Kd(e,t,n,r,o,s,i,a){if(n.hash===t.hash)return{hash:r.hash,conflict:!1};if(r.hash===t.hash)return{hash:n.hash,conflict:!1};if(n.hash===r.hash)return{hash:n.hash,conflict:!1};if(Dn(t.mode)||Dn(n.mode)||Dn(r.mode))return{hash:n.hash,conflict:!0};let c=await le(e,t.hash),f=await le(e,n.hash),l=await le(e,r.hash);if(Ne(f)||Ne(l)||Ne(c))return{hash:n.hash,conflict:!0};if(a){let y=await a({path:t.path??n.path??r.path??"",base:c,ours:f,theirs:l});if(y!==null)return{hash:await Me(e,"blob",bn.encode(y.content)),conflict:y.conflict}}let d=zt(c),u=zt(f),m=zt(l),h=o?.conflictStyle,p=Qs(u,d,m,{conflictStyle:h});if(!p.conflict)return{hash:await gc(e,p.result),conflict:!1};let g=o?.a??"HEAD",w=o?.b??"theirs",b=s?.oursPath?`${g}:${s.oursPath}`:g,R=s?.theirsPath?`${w}:${s.theirsPath}`:w,C=Fr(f,c,l,{a:b,b:R,markerSize:i??7,conflictStyle:h});return{hash:await Me(e,"blob",bn.encode(C)),conflict:!0}}async function gi(e,t,n,r,o){let s=await le(e,t),i=await le(e,n),a=Fr(s,"",i,{a:o?.a??"HEAD",b:o?.b??"theirs",conflictStyle:o?.conflictStyle});return Me(e,"blob",bn.encode(a))}function Dt(e,t,n=0){return wt(e,t.mode,t.hash,n)}function wt(e,t,n,r=0){return{path:e,mode:parseInt(t,8),hash:n,stage:r,stat:Fe()}}async function kw(e,t,n,r,o){let s=[...r.entries],i=[...r.conflicts],a=[...r.msgBuf],c=new Map(r.worktreeBlobs);function f(h,p,g=0){a.push({sortKey:h,subOrder:g,text:p})}for(let h of[...t.keys()].sort()){let p=t.get(h);if(p.merged.clean){p.merged.result?.hash&&s.push(He(h,p.merged.result.hash,p.merged.result.mode));continue}await Ew(e,p,n,s,i,f,c,o)}a.sort((h,p)=>(h.sortKeyp.sortKey?1:0)||h.subOrder-p.subOrder);let l=a.map(h=>h.text),d=[],u=new Set;for(let h of s)h.stage===0&&(d.push(h),u.add(h.path));for(let[h,p]of c)u.has(h)||d.push(He(h,p.hash,p.mode));d.sort((h,p)=>Te(h.path,p.path));let m=await Ye(e,d);return{entries:s,conflicts:i,messages:l,resultTree:m,neededRenameLimit:r.neededRenameLimit}}async function Ew(e,t,n,r,o,s,i,a){let c=t.path,[f,l,d]=t.stages,u=f?.hash??null,m=l?.hash??null,h=d?.hash??null;if(m===null&&h!==null&&u!==null){o.push({path:c,reason:"delete-modify",deletedBy:"ours"});let p=n?.a??"HEAD",g=n?.b??"theirs";s(c,`CONFLICT (modify/delete): ${c} deleted in ${p} and modified in ${g}. Version ${g} of ${c} left in tree.`),f&&r.push(He(c,u,f.mode,1)),r.push(He(c,h,d.mode,3)),i.set(c,{hash:h,mode:d.mode});return}if(h===null&&m!==null&&u!==null){o.push({path:c,reason:"delete-modify",deletedBy:"theirs"});let p=n?.b??"theirs",g=n?.a??"HEAD";s(c,`CONFLICT (modify/delete): ${c} deleted in ${p} and modified in ${g}. Version ${g} of ${c} left in tree.`),f&&r.push(He(c,u,f.mode,1)),r.push(He(c,m,l.mode,2)),i.set(c,{hash:m,mode:l.mode});return}if(u===null&&m!==null&&h!==null){if(m===h){r.push(He(c,m,l.mode));return}s(c,`Auto-merging ${c}`,0);let p=await le(e,m),g=await le(e,h);if(Ne(p)||Ne(g)){o.push({path:c,reason:"add-add"}),s(c,`warning: Cannot merge binary files: ${c} (${n?.a??"HEAD"} vs. ${n?.b??"theirs"})`,-1),s(c,`CONFLICT (add/add): Merge conflict in ${c}`,1),r.push(He(c,m,l.mode,2)),r.push(He(c,h,d.mode,3)),i.set(c,{hash:m,mode:l.mode});return}if(a){let P=await a({path:c,base:null,ours:p,theirs:g});if(P!==null){let k=await Me(e,"blob",bn.encode(P.content));if(!P.conflict){r.push(He(c,k,l.mode));return}o.push({path:c,reason:"add-add"}),s(c,`CONFLICT (add/add): Merge conflict in ${c}`,1),r.push(He(c,m,l.mode,2)),r.push(He(c,h,d.mode,3)),i.set(c,{hash:k,mode:l.mode});return}}let w=zt(""),b=zt(p),R=zt(g),C=Qs(b,w,R,{conflictStyle:n?.conflictStyle});if(!C.conflict){let P=await gc(e,C.result);r.push(He(c,P,l.mode));return}o.push({path:c,reason:"add-add"}),s(c,`CONFLICT (add/add): Merge conflict in ${c}`,1),r.push(He(c,m,l.mode,2)),r.push(He(c,h,d.mode,3));let x=Fr(p,"",g,{a:n?.a??"HEAD",b:n?.b??"theirs",conflictStyle:n?.conflictStyle}),y=await Me(e,"blob",bn.encode(x));i.set(c,{hash:y,mode:l.mode});return}if(u!==null&&m!==null&&h!==null){if(m===u){r.push(He(c,h,d.mode));return}if(h===u){r.push(He(c,m,l.mode));return}if(m===h){r.push(He(c,m,l.mode));return}if(s(c,`Auto-merging ${c}`,0),Dn(f.mode)||Dn(l.mode)||Dn(d.mode)){o.push({path:c,reason:"content"}),s(c,`CONFLICT (content): Merge conflict in ${c}`,1),r.push(He(c,u,f.mode,1)),r.push(He(c,m,l.mode,2)),r.push(He(c,h,d.mode,3)),i.set(c,{hash:m,mode:l.mode});return}let p=await le(e,u),g=await le(e,m),w=await le(e,h);if(Ne(g)||Ne(w)||Ne(p)){o.push({path:c,reason:"content"}),s(c,`warning: Cannot merge binary files: ${c} (${n?.a??"HEAD"} vs. ${n?.b??"theirs"})`,-1),s(c,`CONFLICT (content): Merge conflict in ${c}`,1),r.push(He(c,u,f.mode,1)),r.push(He(c,m,l.mode,2)),r.push(He(c,h,d.mode,3)),i.set(c,{hash:m,mode:l.mode});return}if(a){let y=await a({path:c,base:p,ours:g,theirs:w});if(y!==null){let P=await Me(e,"blob",bn.encode(y.content));if(!y.conflict){r.push(He(c,P,l.mode));return}let k=t.pathnames[1],E=t.pathnames[2],O=k!==c||E!==c,$={path:c,reason:"content"};O&&(k!==c&&($.oursOrigPath=k),E!==c&&($.theirsOrigPath=E)),o.push($),s(c,`CONFLICT (content): Merge conflict in ${c}`,1),r.push(He(c,u,f.mode,1)),r.push(He(c,m,l.mode,2)),r.push(He(c,h,d.mode,3)),i.set(c,{hash:P,mode:l.mode});return}}let b=zt(p),R=zt(g),C=zt(w),x=Qs(R,b,C,{conflictStyle:n?.conflictStyle});if(x.conflict){let y=t.pathnames[1],P=t.pathnames[2],k=y!==c||P!==c,E={path:c,reason:"content"};k&&(y!==c&&(E.oursOrigPath=y),P!==c&&(E.theirsOrigPath=P)),o.push(E),s(c,`CONFLICT (content): Merge conflict in ${c}`,1),r.push(He(c,u,f.mode,1)),r.push(He(c,m,l.mode,2)),r.push(He(c,h,d.mode,3));let O=k?`${n?.a??"HEAD"}:${y}`:n?.a??"HEAD",$=k?`${n?.b??"theirs"}:${P}`:n?.b??"theirs",T=Fr(g,p,w,{a:O,b:$,conflictStyle:n?.conflictStyle}),j=await Me(e,"blob",bn.encode(T));i.set(c,{hash:j,mode:l.mode})}else{let y=await gc(e,x.result);r.push(He(c,y,l.mode))}return}}var Rw=200;async function Vd(e,t,n,r,o,s){let i=await Promise.all(r.map(async u=>({hash:u,timestamp:(await M(e,u)).committer.timestamp})));i.sort((u,m)=>u.timestamp-m.timestamp);let a=i.map(u=>u.hash),c=a[0],f=c,l=(await M(e,c)).tree,d;for(let u=1;u=Rw)p=l;else{let b=await ft(e,f,m);if(b.length===0)p=null;else if(b.length===1)p=(await M(e,b[0])).tree;else{let R=await Vd(e,f,m,b,o+1,s);p=R.tree,d=Math.max(d??0,R.neededRenameLimit??0)||void 0}}let g=await sn(e,p,l,h,void 0,s);d=Math.max(d??0,g.neededRenameLimit??0)||void 0,l=await Cw(e,g,o);let w=Cn({type:"commit",tree:l,parents:[f,m],author:Fd,committer:Fd,message:"merged common ancestors"});f=await Me(e,"commit",w)}return{tree:l,neededRenameLimit:d}}async function Cw(e,t,n){let r=t.entries.filter(a=>a.stage===0),o=new Map;for(let a of t.entries)a.stage>0&&o.set(`${a.path}\0${a.stage}`,a);let s=(a,c)=>o.get(`${a}\0${c}`),i={a:"Temporary merge branch 1",b:"Temporary merge branch 2",markerSize:7+n*2};for(let a of t.conflicts){if(a.reason==="delete-modify"||a.reason==="rename-delete"){let l=s(a.path,1);if(l){r.push({...l,stage:0});continue}}if(a.reason==="rename-rename"){let l=a.oursPath??a.path,d=a.theirsPath??a.path,u=s(a.path,1),m=s(l,2),h=s(d,3);if(m&&h){let p=us.decode((await be(e,m.hash)).content),g=us.decode((await be(e,h.hash)).content),w=u?us.decode((await be(e,u.hash)).content):"",b=8+n*2,R=i.a??"Temporary merge branch 1",C=i.b??"Temporary merge branch 2",x=Fr(p,w,g,{a:`${R}:${l}`,o:i.o,b:`${C}:${d}`,markerSize:b}),y=await Me(e,"blob",bn.encode(x));r.push({path:l,mode:m.mode,hash:y,stage:0,stat:Fe()}),r.push({path:d,mode:h.mode,hash:y,stage:0,stat:Fe()});continue}else if(m){r.push({...m,stage:0});continue}}let c=s(a.path,2),f=s(a.path,3);if(c&&f&&(a.reason==="content"||a.reason==="add-add")){let l=us.decode((await be(e,c.hash)).content),d=us.decode((await be(e,f.hash)).content),u=a.reason==="content"?s(a.path,1):null,m=u?us.decode((await be(e,u.hash)).content):"",h=a.oursOrigPath||a.theirsOrigPath,p=i.a??"Temporary merge branch 1",g=i.b??"Temporary merge branch 2",w=h?`${p}:${a.oursOrigPath??a.path}`:p,b=h?`${g}:${a.theirsOrigPath??a.path}`:g,R=Fr(l,m,d,{a:w,o:i.o,b,markerSize:i.markerSize}),C=await Me(e,"blob",bn.encode(R));r.push({path:a.path,mode:c.mode,hash:C,stage:0,stat:Fe()})}else c?r.push({...c,stage:0}):f&&r.push({...f,stage:0})}return r.sort((a,c)=>Te(a.path,c.path)),Ye(e,r)}async function gc(e,t){let n=t.map(mc);if(n.length===0)return Me(e,"blob",bn.encode(""));let s=(t[t.length-1]??"").endsWith("\0")?n.join(` ++`)}function Yt(e){if(e==="")return[];let t=e.split(` ++`);if(t[t.length-1]==="")t.pop();else{let n=t[t.length-1]??"";t[t.length-1]=`${n}\0`}return t}function Cc(e){return e.endsWith("\0")?e.slice(0,-1):e}function Yd(e,t){if(e.length!==t.length)return!1;for(let n=0;n$c.has(r))?t===e?n:t:null}async function Fw(e,t,n,r,s,o,i){let a={entries:[],conflicts:[],msgBuf:[],worktreeBlobs:new Map},c=[],f=[];for(let[A,H]of n)r.has(A)||c.push({path:A,status:"deleted",oldHash:H.hash,oldMode:H.mode}),s.has(A)||f.push({path:A,status:"deleted",oldHash:H.hash,oldMode:H.mode});for(let[A,H]of r)n.has(A)||c.push({path:A,status:"added",newHash:H.hash,newMode:H.mode});for(let[A,H]of s)n.has(A)||f.push({path:A,status:"added",newHash:H.hash,newMode:H.mode});let l=await xt(e,"merge"),d=await bt(e,c,{limit:l}),u=await bt(e,f,{limit:l});if(a.neededRenameLimit=Math.max(d.neededRenameLimit??0,u.neededRenameLimit??0)||void 0,d.renames.length===0&&u.renames.length===0)return a;let m=new Map,h=new Map;for(let A of d.renames)m.set(A.oldPath,A);for(let A of u.renames)h.set(A.oldPath,A);let p=new Set;for(let[A]of r)!n.has(A)&&s.has(A)&&p.add(A);let g=new Set,w=o?.a??"HEAD",b=o?.b??"theirs";function y(A,H,q=0){a.msgBuf.push({sortKey:A,subOrder:q,text:H})}for(let A of[...n.keys()].sort()){let H=m.get(A),q=h.get(A);if(!H&&!q)continue;let F=n.get(A);if(g.add(A),H&&q)if(g.add(H.newPath),g.add(q.newPath),H.newPath===q.newPath){let _=r.get(H.newPath),Y=s.get(q.newPath);if(_.hash===Y.hash){let V=ao(F.mode,_.mode,Y.mode);a.entries.push(it(H.newPath,V??_.mode,_.hash))}else{let V=xc(t,H.newPath);V.stages=[{hash:F.hash,mode:F.mode},{hash:_.hash,mode:_.mode},{hash:Y.hash,mode:Y.mode}],V.pathnames=[A,H.newPath,q.newPath],V.filemask=7,V.merged={result:null,clean:!1}}}else{let _=r.get(H.newPath),Y=s.get(q.newPath),V=await su(e,F,_,Y,o,void 0,void 0,i);V.conflict&&y(A,`Auto-merging ${A}`,-1),a.conflicts.push({path:A,reason:"rename-rename",oursPath:H.newPath,theirsPath:q.newPath}),y(A,`CONFLICT (rename/rename): ${A} renamed to ${H.newPath} in ${w} and to ${q.newPath} in ${b}.`);let ue=ao(F.mode,_.mode,Y.mode),Ce=ue??_.mode,Qe=ue??Y.mode;a.entries.push(Vn(A,F,1)),a.entries.push(it(H.newPath,Ce,V.hash,2)),a.entries.push(it(q.newPath,Qe,V.hash,3)),a.worktreeBlobs.set(H.newPath,{hash:V.hash,mode:Ce}),a.worktreeBlobs.set(q.newPath,{hash:V.hash,mode:Qe})}else if(H){g.add(H.newPath);let _=s.get(A),Y=r.get(H.newPath),V=p.has(H.newPath);if(_)if(V)await nu(e,a,H.newPath,A,F,Y,_,r,s,!1,o,i);else{let ue=ao(F.mode,Y.mode,_.mode)??Y.mode;if(_.hash===F.hash)a.entries.push(it(H.newPath,ue,Y.hash));else if(Y.hash===F.hash)a.entries.push(it(H.newPath,ue,_.hash));else{let Ce=xc(t,H.newPath);Ce.stages=[{hash:F.hash,mode:F.mode},{hash:Y.hash,mode:Y.mode},{hash:_.hash,mode:_.mode}],Ce.pathnames=[A,H.newPath,A],Ce.filemask=7,Ce.merged={result:null,clean:!1}}}else{let ue=s.get(H.newPath);if(a.conflicts.push({path:H.newPath,reason:"rename-delete",deletedBy:"theirs",oldPath:A}),y(H.newPath,`CONFLICT (rename/delete): ${A} renamed to ${H.newPath} in ${w}, but deleted in ${b}.`),ue){a.conflicts.push({path:H.newPath,reason:"add-add"}),y(H.newPath,`Auto-merging ${H.newPath}`,0),y(H.newPath,`CONFLICT (add/add): Merge conflict in ${H.newPath}`,1),a.entries.push(Vn(H.newPath,Y,2)),a.entries.push(Vn(H.newPath,ue,3));let Ce=await $i(e,Y.hash,ue.hash,Y.mode,o);a.worktreeBlobs.set(H.newPath,{hash:Ce,mode:Y.mode})}else a.entries.push(it(H.newPath,F.mode,F.hash,1)),a.entries.push(Vn(H.newPath,Y,2)),a.worktreeBlobs.set(H.newPath,{hash:Y.hash,mode:Y.mode}),Y.hash!==F.hash&&y(H.newPath,`CONFLICT (modify/delete): ${H.newPath} deleted in ${b} and modified in ${w}. Version ${w} of ${H.newPath} left in tree.`,1)}}else if(q){g.add(q.newPath);let _=r.get(A),Y=s.get(q.newPath),V=p.has(q.newPath);if(_)if(V)await nu(e,a,q.newPath,A,F,_,Y,r,s,!0,o,i);else{let ue=ao(F.mode,_.mode,Y.mode)??Y.mode;if(_.hash===F.hash)a.entries.push(it(q.newPath,ue,Y.hash));else if(Y.hash===F.hash)a.entries.push(it(q.newPath,ue,_.hash));else{let Ce=xc(t,q.newPath);Ce.stages=[{hash:F.hash,mode:F.mode},{hash:_.hash,mode:_.mode},{hash:Y.hash,mode:Y.mode}],Ce.pathnames=[A,A,q.newPath],Ce.filemask=7,Ce.merged={result:null,clean:!1}}}else{let ue=r.get(q.newPath);if(a.conflicts.push({path:q.newPath,reason:"rename-delete",deletedBy:"ours",oldPath:A}),y(q.newPath,`CONFLICT (rename/delete): ${A} renamed to ${q.newPath} in ${b}, but deleted in ${w}.`),ue){a.conflicts.push({path:q.newPath,reason:"add-add"}),y(q.newPath,`Auto-merging ${q.newPath}`,0),y(q.newPath,`CONFLICT (add/add): Merge conflict in ${q.newPath}`,1),a.entries.push(Vn(q.newPath,ue,2)),a.entries.push(Vn(q.newPath,Y,3));let Ce=await $i(e,ue.hash,Y.hash,ue.mode,o);a.worktreeBlobs.set(q.newPath,{hash:Ce,mode:ue.mode})}else a.entries.push(it(q.newPath,F.mode,F.hash,1)),a.entries.push(Vn(q.newPath,Y,3)),a.worktreeBlobs.set(q.newPath,{hash:Y.hash,mode:Y.mode}),Y.hash!==F.hash&&y(q.newPath,`CONFLICT (modify/delete): ${q.newPath} deleted in ${w} and modified in ${b}. Version ${b} of ${q.newPath} left in tree.`,1)}}}let C=new Set(d.renames.map(A=>A.newPath)),x=new Set(u.renames.map(A=>A.newPath)),k=Zd(n,r),P=Zd(n,s),E=Qd(k,s,n),R=Qd(P,r,n),O=Jd(d.renames,E),$=Jd(u.renames,R),T=eu(O),j=eu($);for(let A of[...T.keys()])j.has(A)&&(T.delete(A),j.delete(A));let U=new Set(T.keys()),G=new Set(j.keys());if(j.size>0)for(let A of c){if(A.status!=="added"||C.has(A.path))continue;let H=tu(A.path,j,U);if(!H)continue;if(t.has(H)||n.has(H)||r.has(H)||s.has(H)){if(r.has(H)){y(H,`CONFLICT (implicit dir rename): Existing file/dir at ${H} in the way of implicit directory rename(s) putting the following path(s) there: ${A.path}.`,1);continue}let _=r.get(A.path),Y=s.get(H)??n.get(H);a.entries.push(it(H,_.mode,_.hash,2)),Y&&a.entries.push(it(H,Y.mode,Y.hash,3)),a.worktreeBlobs.set(H,{hash:_.hash,mode:_.mode}),a.conflicts.push({path:H,reason:"add-add"}),y(H,`CONFLICT (file location): ${A.path} added in ${w} inside a directory that was renamed in ${b}, suggesting it should perhaps be moved to ${H}.`,1);let V=t.get(A.path);V&&(V.merged={result:null,clean:!0}),g.add(A.path);continue}let q=r.get(A.path);a.entries.push(it(H,q.mode,q.hash,2)),a.worktreeBlobs.set(H,{hash:q.hash,mode:q.mode}),a.conflicts.push({path:H,reason:"directory-rename"}),y(H,`CONFLICT (file location): ${A.path} added in ${w} inside a directory that was renamed in ${b}, suggesting it should perhaps be moved to ${H}.`,1);let F=t.get(A.path);F&&(F.merged={result:null,clean:!0}),g.add(A.path)}if(T.size>0)for(let A of f){if(A.status!=="added"||x.has(A.path))continue;let H=tu(A.path,T,G);if(!H)continue;if(t.has(H)||n.has(H)||r.has(H)||s.has(H)){if(s.has(H)){y(H,`CONFLICT (implicit dir rename): Existing file/dir at ${H} in the way of implicit directory rename(s) putting the following path(s) there: ${A.path}.`,1);continue}let _=s.get(A.path),Y=r.get(H)??n.get(H);Y&&a.entries.push(it(H,Y.mode,Y.hash,2)),a.entries.push(it(H,_.mode,_.hash,3)),a.worktreeBlobs.set(H,{hash:_.hash,mode:_.mode}),a.conflicts.push({path:H,reason:"add-add"}),y(H,`CONFLICT (file location): ${A.path} added in ${b} inside a directory that was renamed in ${w}, suggesting it should perhaps be moved to ${H}.`,1);let V=t.get(A.path);V&&(V.merged={result:null,clean:!0}),g.add(A.path);continue}let q=s.get(A.path);a.entries.push(it(H,q.mode,q.hash,3)),a.worktreeBlobs.set(H,{hash:q.hash,mode:q.mode}),a.conflicts.push({path:H,reason:"directory-rename"}),y(H,`CONFLICT (file location): ${A.path} added in ${b} inside a directory that was renamed in ${w}, suggesting it should perhaps be moved to ${H}.`,1);let F=t.get(A.path);F&&(F.merged={result:null,clean:!0}),g.add(A.path)}let L=new Set(a.entries.map(A=>A.path));for(let A of L){let H=t.get(A);H&&(H.merged={result:null,clean:!0})}for(let A of g){if(L.has(A))continue;let H=t.get(A);if(!H||H.merged.clean)continue;H.filemask===7&&!H.pathConflict||(H.merged={result:null,clean:!0})}return a}function Zd(e,t){let n=new Set;for(let o of e.keys()){let i=Xt(o);for(;i;)n.add(i),i=Xt(i)}let r=new Set;for(let o of t.keys()){let i=Xt(o);for(;i;)r.add(i),i=Xt(i)}let s=new Set;for(let o of n)r.has(o)||s.add(o);return s}function Qd(e,t,n){if(e.size===0)return e;let r=new Set;for(let s of t.keys()){if(n.has(s))continue;let o=Xt(s)??"";e.has(o)&&r.add(o)}for(let s of[...r]){let o=Xt(s);for(;o;)e.has(o)&&!r.has(o)&&r.add(o),o=Xt(o)}return r}function Jd(e,t){let n=new Map;for(let r of e){let s=Xt(r.oldPath),o=Xt(r.newPath),i=!0;for(;;){if(!i){let a=s.length+(s?1:0),c=o.length+(o?1:0),f=r.oldPath.slice(a,r.oldPath.indexOf("/",a)),l=r.newPath.slice(c,r.newPath.indexOf("/",c));if(f!==l)break}if(t.has(s)){let a=n.get(s);a||(a=new Map,n.set(s,a)),a.set(o,(a.get(o)??0)+1)}if(i=!1,!s||!o)break;s=Xt(s),o=Xt(o)}}return n}function eu(e){let t=new Map;for(let[n,r]of e){let s=0,o=0,i=null;for(let[a,c]of r)c===s?o=s:c>s&&(s=c,i=a);s>0&&o!==s&&i!==null&&t.set(n,i)}return t}function tu(e,t,n){let r=Xt(e);for(;r;){let o=t.get(r);if(o!==void 0){if(n.has(o))return null;let i=e.slice(r.length+1);return o?`${o}/${i}`:i}r=Xt(r)}let s=t.get("");return s!==void 0&&!n.has(s)?`${s}/${e}`:null}function Xt(e){let t=e.lastIndexOf("/");return t===-1?"":e.slice(0,t)}async function nu(e,t,n,r,s,o,i,a,c,f=!1,l,d){let u=f?a.get(n):c.get(n),m=f?i:o;if(u.hash===m.hash){t.entries.push(it(n,u.mode,u.hash)),t.msgBuf.push({sortKey:r,subOrder:0,text:`Auto-merging ${r}`});return}let p=await su(e,s,o,i,l,f?{oursPath:r,theirsPath:n}:{oursPath:n,theirsPath:r},8,d);if(u.hash===p.hash)t.entries.push(it(n,u.mode,p.hash));else if(t.conflicts.push({path:n,reason:"add-add"}),t.msgBuf.push({sortKey:n,subOrder:0,text:`Auto-merging ${n}`}),t.msgBuf.push({sortKey:n,subOrder:1,text:`CONFLICT (add/add): Merge conflict in ${n}`}),f){t.entries.push(Vn(n,u,2)),t.entries.push(it(n,i.mode,p.hash,3));let g=await $i(e,u.hash,p.hash,u.mode,l);t.worktreeBlobs.set(n,{hash:g,mode:u.mode})}else{t.entries.push(it(n,o.mode,p.hash,2)),t.entries.push(Vn(n,u,3));let g=await $i(e,p.hash,u.hash,o.mode,l);t.worktreeBlobs.set(n,{hash:g,mode:o.mode})}}async function su(e,t,n,r,s,o,i,a){if(n.hash===t.hash)return{hash:r.hash,conflict:!1};if(r.hash===t.hash)return{hash:n.hash,conflict:!1};if(n.hash===r.hash)return{hash:n.hash,conflict:!1};if(dn(t.mode)||dn(n.mode)||dn(r.mode))return{hash:n.hash,conflict:!0};let c=await le(e,t.hash),f=await le(e,n.hash),l=await le(e,r.hash);if(Fe(f)||Fe(l)||Fe(c))return{hash:n.hash,conflict:!0};if(a){let k=await a({path:t.path??n.path??r.path??"",base:c,ours:f,theirs:l});if(k!==null)return{hash:await De(e,"blob",Rn.encode(k.content)),conflict:k.conflict}}let d=Yt(c),u=Yt(f),m=Yt(l),h=s?.conflictStyle,p=oo(u,d,m,{conflictStyle:h});if(!p.conflict)return{hash:await Oc(e,p.result),conflict:!1};let g=s?.a??"HEAD",w=s?.b??"theirs",b=o?.oursPath?`${g}:${o.oursPath}`:g,y=o?.theirsPath?`${w}:${o.theirsPath}`:w,C=Br(f,c,l,{a:b,b:y,markerSize:i??7,conflictStyle:h});return{hash:await De(e,"blob",Rn.encode(C)),conflict:!0}}async function $i(e,t,n,r,s){let o=await le(e,t),i=await le(e,n),a=Br(o,"",i,{a:s?.a??"HEAD",b:s?.b??"theirs",conflictStyle:s?.conflictStyle});return De(e,"blob",Rn.encode(a))}function Vn(e,t,n=0){return it(e,t.mode,t.hash,n)}function it(e,t,n,r=0){return{path:e,mode:parseInt(t,8),hash:n,stage:r,stat:Ge()}}async function Nw(e,t,n,r,s){let o=[...r.entries],i=[...r.conflicts],a=[...r.msgBuf],c=new Map(r.worktreeBlobs);function f(h,p,g=0){a.push({sortKey:h,subOrder:g,text:p})}for(let h of[...t.keys()].sort()){let p=t.get(h);if(p.merged.clean){p.merged.result?.hash&&o.push(Ue(h,p.merged.result.hash,p.merged.result.mode));continue}await Uw(e,p,n,o,i,f,c,s)}a.sort((h,p)=>(h.sortKeyp.sortKey?1:0)||h.subOrder-p.subOrder);let l=a.map(h=>h.text),d=[],u=new Set;for(let h of o)h.stage===0&&(d.push(h),u.add(h.path));for(let[h,p]of c)u.has(h)||d.push(Ue(h,p.hash,p.mode));d.sort((h,p)=>Ae(h.path,p.path));let m=await Ze(e,d);return{entries:o,conflicts:i,messages:l,resultTree:m,neededRenameLimit:r.neededRenameLimit}}async function Uw(e,t,n,r,s,o,i,a){let c=t.path,[f,l,d]=t.stages,u=f?.hash??null,m=l?.hash??null,h=d?.hash??null;if(m===null&&h!==null&&u!==null){s.push({path:c,reason:"delete-modify",deletedBy:"ours"});let p=n?.a??"HEAD",g=n?.b??"theirs";o(c,`CONFLICT (modify/delete): ${c} deleted in ${p} and modified in ${g}. Version ${g} of ${c} left in tree.`),f&&r.push(Ue(c,u,f.mode,1)),r.push(Ue(c,h,d.mode,3)),i.set(c,{hash:h,mode:d.mode});return}if(h===null&&m!==null&&u!==null){s.push({path:c,reason:"delete-modify",deletedBy:"theirs"});let p=n?.b??"theirs",g=n?.a??"HEAD";o(c,`CONFLICT (modify/delete): ${c} deleted in ${p} and modified in ${g}. Version ${g} of ${c} left in tree.`),f&&r.push(Ue(c,u,f.mode,1)),r.push(Ue(c,m,l.mode,2)),i.set(c,{hash:m,mode:l.mode});return}if(u===null&&m!==null&&h!==null){let p=l.mode!==d.mode&&$c.has(l.mode)&&$c.has(d.mode),g=E=>{s.push({path:c,reason:"add-add"}),o(c,`CONFLICT (add/add): Merge conflict in ${c}`,1),r.push(Ue(c,m,l.mode,2)),r.push(Ue(c,h,d.mode,3)),i.set(c,{hash:E,mode:l.mode})};if(m===h){p?g(m):r.push(Ue(c,m,l.mode));return}o(c,`Auto-merging ${c}`,0);let w=await le(e,m),b=await le(e,h);if(Fe(w)||Fe(b)){o(c,`warning: Cannot merge binary files: ${c} (${n?.a??"HEAD"} vs. ${n?.b??"theirs"})`,-1),g(m);return}if(a){let E=await a({path:c,base:null,ours:w,theirs:b});if(E!==null){let R=await De(e,"blob",Rn.encode(E.content));E.conflict||p?g(R):r.push(Ue(c,R,l.mode));return}}let y=Yt(""),C=Yt(w),x=Yt(b),k=oo(C,y,x,{conflictStyle:n?.conflictStyle});if(!k.conflict){let E=await Oc(e,k.result);p?g(E):r.push(Ue(c,E,l.mode));return}let P=Br(w,"",b,{a:n?.a??"HEAD",b:n?.b??"theirs",conflictStyle:n?.conflictStyle});g(await De(e,"blob",Rn.encode(P)));return}if(u!==null&&m!==null&&h!==null){let p=ao(f.mode,l.mode,d.mode);if(m===u){r.push(Ue(c,h,p??d.mode));return}if(h===u){r.push(Ue(c,m,p??l.mode));return}if(m===h){r.push(Ue(c,m,p??l.mode));return}if(o(c,`Auto-merging ${c}`,0),dn(f.mode)||dn(l.mode)||dn(d.mode)){s.push({path:c,reason:"content"}),o(c,`CONFLICT (content): Merge conflict in ${c}`,1),r.push(Ue(c,u,f.mode,1)),r.push(Ue(c,m,l.mode,2)),r.push(Ue(c,h,d.mode,3)),i.set(c,{hash:m,mode:l.mode});return}let g=p??l.mode,w=await le(e,u),b=await le(e,m),y=await le(e,h);if(Fe(b)||Fe(y)||Fe(w)){s.push({path:c,reason:"content"}),o(c,`warning: Cannot merge binary files: ${c} (${n?.a??"HEAD"} vs. ${n?.b??"theirs"})`,-1),o(c,`CONFLICT (content): Merge conflict in ${c}`,1),r.push(Ue(c,u,f.mode,1)),r.push(Ue(c,m,l.mode,2)),r.push(Ue(c,h,d.mode,3)),i.set(c,{hash:m,mode:g});return}if(a){let E=await a({path:c,base:w,ours:b,theirs:y});if(E!==null){let R=await De(e,"blob",Rn.encode(E.content));if(!E.conflict){r.push(Ue(c,R,g));return}let O=t.pathnames[1],$=t.pathnames[2],T=O!==c||$!==c,j={path:c,reason:"content"};T&&(O!==c&&(j.oursOrigPath=O),$!==c&&(j.theirsOrigPath=$)),s.push(j),o(c,`CONFLICT (content): Merge conflict in ${c}`,1),r.push(Ue(c,u,f.mode,1)),r.push(Ue(c,m,l.mode,2)),r.push(Ue(c,h,d.mode,3)),i.set(c,{hash:R,mode:g});return}}let C=Yt(w),x=Yt(b),k=Yt(y),P=oo(x,C,k,{conflictStyle:n?.conflictStyle});if(P.conflict){let E=t.pathnames[1],R=t.pathnames[2],O=E!==c||R!==c,$={path:c,reason:"content"};O&&(E!==c&&($.oursOrigPath=E),R!==c&&($.theirsOrigPath=R)),s.push($),o(c,`CONFLICT (content): Merge conflict in ${c}`,1),r.push(Ue(c,u,f.mode,1)),r.push(Ue(c,m,l.mode,2)),r.push(Ue(c,h,d.mode,3));let T=O?`${n?.a??"HEAD"}:${E}`:n?.a??"HEAD",j=O?`${n?.b??"theirs"}:${R}`:n?.b??"theirs",U=Br(b,w,y,{a:T,b:j,conflictStyle:n?.conflictStyle}),G=await De(e,"blob",Rn.encode(U));i.set(c,{hash:G,mode:g})}else{let E=await Oc(e,P.result);r.push(Ue(c,E,g))}return}}var _w=200;async function ou(e,t,n,r,s,o){let i=await Promise.all(r.map(async u=>({hash:u,timestamp:(await M(e,u)).committer.timestamp})));i.sort((u,m)=>u.timestamp-m.timestamp);let a=i.map(u=>u.hash),c=a[0],f=c,l=(await M(e,c)).tree,d;for(let u=1;u=_w)p=l;else{let b=await mt(e,f,m);if(b.length===0)p=null;else if(b.length===1)p=(await M(e,b[0])).tree;else{let y=await ou(e,f,m,b,s+1,o);p=y.tree,d=Math.max(d??0,y.neededRenameLimit??0)||void 0}}let g=await fn(e,p,l,h,void 0,o);d=Math.max(d??0,g.neededRenameLimit??0)||void 0,l=await Bw(e,g,s);let w=$n({type:"commit",tree:l,parents:[f,m],author:Xd,committer:Xd,message:"merged common ancestors"});f=await De(e,"commit",w)}return{tree:l,neededRenameLimit:d}}async function Bw(e,t,n){let r=t.entries.filter(a=>a.stage===0),s=new Map;for(let a of t.entries)a.stage>0&&s.set(`${a.path}\0${a.stage}`,a);let o=(a,c)=>s.get(`${a}\0${c}`),i={a:"Temporary merge branch 1",b:"Temporary merge branch 2",markerSize:7+n*2};for(let a of t.conflicts){if(a.reason==="delete-modify"||a.reason==="rename-delete"){let l=o(a.path,1);if(l){r.push({...l,stage:0});continue}}if(a.reason==="rename-rename"){let l=a.oursPath??a.path,d=a.theirsPath??a.path,u=o(a.path,1),m=o(l,2),h=o(d,3);if(m&&h){let p=ps.decode((await me(e,m.hash)).content),g=ps.decode((await me(e,h.hash)).content),w=u?ps.decode((await me(e,u.hash)).content):"",b=8+n*2,y=i.a??"Temporary merge branch 1",C=i.b??"Temporary merge branch 2",x=Br(p,w,g,{a:`${y}:${l}`,o:i.o,b:`${C}:${d}`,markerSize:b}),k=await De(e,"blob",Rn.encode(x));r.push({path:l,mode:m.mode,hash:k,stage:0,stat:Ge()}),r.push({path:d,mode:h.mode,hash:k,stage:0,stat:Ge()});continue}else if(m){r.push({...m,stage:0});continue}}let c=o(a.path,2),f=o(a.path,3);if(c&&f&&(a.reason==="content"||a.reason==="add-add")){let l=ps.decode((await me(e,c.hash)).content),d=ps.decode((await me(e,f.hash)).content),u=a.reason==="content"?o(a.path,1):null,m=u?ps.decode((await me(e,u.hash)).content):"",h=a.oursOrigPath||a.theirsOrigPath,p=i.a??"Temporary merge branch 1",g=i.b??"Temporary merge branch 2",w=h?`${p}:${a.oursOrigPath??a.path}`:p,b=h?`${g}:${a.theirsOrigPath??a.path}`:g,y=Br(l,m,d,{a:w,o:i.o,b,markerSize:i.markerSize}),C=await De(e,"blob",Rn.encode(y));r.push({path:a.path,mode:c.mode,hash:C,stage:0,stat:Ge()})}else c?r.push({...c,stage:0}):f&&r.push({...f,stage:0})}return r.sort((a,c)=>Ae(a.path,c.path)),Ze(e,r)}async function Oc(e,t){let n=t.map(Cc);if(n.length===0)return De(e,"blob",Rn.encode(""));let o=(t[t.length-1]??"").endsWith("\0")?n.join(` + `):`${n.join(` + `)} +-`;return Me(e,"blob",bn.encode(s))}function He(e,t,n,r=0){let o=typeof n=="string"?parseInt(n,8):n;return{path:e,mode:o,hash:t,stage:r,stat:Fe()}}function hc(e,t){let n=e.get(t);return n||(n={path:t,stages:[null,null,null],pathnames:[t,t,t],filemask:0,matchMask:0,merged:{result:null,clean:!1},pathConflict:!1},e.set(t,n)),n}function Js(e,t,n,r,o){let s=r==="untracked"?`error: The following untracked working tree files would be overwritten by ${t}:`:`error: Your local changes to the following files would be overwritten by ${t}:`;if(n==="merge"){if(o==="staged")return`${s} ++`;return De(e,"blob",Rn.encode(o))}function Ue(e,t,n,r=0){let s=typeof n=="string"?parseInt(n,8):n;return{path:e,mode:s,hash:t,stage:r,stat:Ge()}}function xc(e,t){let n=e.get(t);return n||(n={path:t,stages:[null,null,null],pathnames:[t,t,t],filemask:0,matchMask:0,merged:{result:null,clean:!1},pathConflict:!1},e.set(t,n)),n}function io(e,t,n,r,s){let o=r==="untracked"?`error: The following untracked working tree files would be overwritten by ${t}:`:`error: Your local changes to the following files would be overwritten by ${t}:`;if(n==="merge"){if(s==="staged")return`${o} + ${e.join(" ")} + Merge with strategy ort failed. + `;let c=e.map(l=>` ${l}`).join(` +-`),f=r==="untracked"?`Please move or remove them before you ${t}.`:`Please commit your changes or stash them before you ${t}.`;return`${s} ++`),f=r==="untracked"?`Please move or remove them before you ${t}.`:`Please commit your changes or stash them before you ${t}.`;return`${o} + ${c} + ${f} + Aborting + Merge with strategy ort failed. + `}let i=e.map(c=>` ${c}`).join(` +-`),a=r==="untracked"?`Please move or remove them before you ${t}.`:`Please commit your changes or stash them before you ${t}.`;return`${s} ++`),a=r==="untracked"?`Please move or remove them before you ${t}.`:`Please commit your changes or stash them before you ${t}.`;return`${o} + ${i} + ${a} + Aborting + fatal: ${n} failed +-`}function zd(e,t,n,r){let o=[];if(e.length>0){let i=e.map(a=>` ${a}`).join(` +-`);o.push(`error: Your local changes to the following files would be overwritten by ${n}: ++`}function ru(e,t,n,r){let s=[];if(e.length>0){let i=e.map(a=>` ${a}`).join(` ++`);s.push(`error: Your local changes to the following files would be overwritten by ${n}: + ${i} + Please commit your changes or stash them before you ${n}. + `)}if(t.length>0){let i=t.map(a=>` ${a}`).join(` +-`);o.push(`error: The following untracked working tree files would be overwritten by ${n}: ++`);s.push(`error: The following untracked working tree files would be overwritten by ${n}: + ${i} + Please move or remove them before you ${n}. +-`)}let s=r==="merge"?"Merge with strategy ort failed.":`fatal: ${r} failed`;return`${o.join("")}Aborting +-${s} +-`}async function Kn(e,t,n,r){let o=await X(e),s=await de(e,n);if(!r.skipStagedChangeCheck&&e.workTree){let h=new Map(qe(o).map(g=>[g.path,g])),p=[];for(let[g,w]of h){let b=s.get(g);(!b||b.hash!==w.hash)&&p.push(g)}for(let[g]of s)h.has(g)||p.push(g);if(p.length>0){let g=[...p].sort();r.atomicCheckout||await pc(e,o,s);let w=r.operationName??"merge",b=r.callerCommand??"merge";return{ok:!1,stdout:"",stderr:Js(g,w,b,"local","staged"),exitCode:r.errorExitCode??2,failureKind:"staged"}}}if(e.workTree&&r.preflightOnewayCheck){let h=await Ar(e,[{label:"target",treeHash:t.resultTree}],o,{mergeFn:Bo,updateWorktree:!1,reset:!1,errorExitCode:r.errorExitCode??2,operationName:r.operationName??"merge"});if(!h.success){r.atomicCheckout||await pc(e,o,s);let p=r.operationName??"merge",g=r.callerCommand??"merge",w=h.errors.filter(C=>C.error==="WOULD_OVERWRITE"||C.error==="NOT_UPTODATE_FILE").map(C=>C.path).sort(),b=h.errors.filter(C=>C.error==="WOULD_LOSE_UNTRACKED_OVERWRITTEN"||C.error==="WOULD_LOSE_UNTRACKED_REMOVED").map(C=>C.path).sort(),R;return w.length>0&&b.length>0?R=zd(w,b,p,g):b.length>0?R=Js(b,p,g,"untracked","worktree"):R=Js(w,p,g,"local","worktree"),{ok:!1,stdout:"",stderr:R,exitCode:r.errorExitCode??2,failureKind:"worktree"}}}if(e.workTree){let h=await Ar(e,[{label:"current",treeHash:n},{label:"target",treeHash:t.resultTree}],o,{mergeFn:Wo,updateWorktree:!0,reset:!1,errorExitCode:r.errorExitCode??2,operationName:r.operationName??"merge",allowStagedChanges:!!r.preflightOnewayCheck});if(!h.success){r.atomicCheckout||await pc(e,o,s);let p=r.operationName??"merge",g=r.callerCommand??"merge",w=h.errors.filter(x=>x.error==="WOULD_OVERWRITE"||x.error==="NOT_UPTODATE_FILE").map(x=>x.path).sort(),b=h.errors.filter(x=>x.error==="WOULD_LOSE_UNTRACKED_OVERWRITTEN"||x.error==="WOULD_LOSE_UNTRACKED_REMOVED").map(x=>x.path).sort(),R=[];w.length>0&&R.push(Js(w,p,g,"local","worktree")),b.length>0&&R.push(Js(b,p,g,"untracked","worktree"));let C;return R.length>1?C=zd(w,b,p,g):C=R[0]??"",{ok:!1,stdout:"",stderr:C,exitCode:r.errorExitCode??2,failureKind:"worktree"}}await je(e,h.worktreeOps)}let i=new Set,a=t.entries;if(r.preflightOnewayCheck){let h=[];for(let p of t.entries){if(p.stage===0){let g=s.get(p.path);if(g&&g.hash===p.hash){i.add(p.path);continue}}h.push(p)}a=h}let c=new Set(a.map(h=>h.path));for(let h of s.keys())i.has(h)||c.add(h);let f=o.entries.filter(h=>!c.has(h.path)),l=[...a,...f];l.sort((h,p)=>Te(h.path,p.path)||h.stage-p.stage);let d={version:2,entries:l};await ie(e,d);let u=l.filter(h=>h.stage===0),m=await Ye(e,u);return{ok:!0,finalIndex:d,mergedTreeHash:m}}async function pc(e,t,n){if(e.workTree)for(let r of t.entries){if(r.stage!==0||n.has(r.path))continue;let o=I(e.workTree,r.path);await e.fs.exists(o)||await at(e,{path:r.path,hash:r.hash,mode:r.mode})}}ae();Ve();ye();De();Jt();Ee();function Yd(e,t){e.command("cherry-pick",{description:"Apply the changes introduced by some existing commits",args:[W.string().name("commit").describe("The commit to cherry-pick").optional()],options:{abort:S().describe("Abort the current cherry-pick operation"),continue:S().describe("Continue the cherry-pick after conflict resolution"),skip:S().describe("Skip the current cherry-pick and continue with the rest"),"record-origin":S().alias("x").describe('Append "(cherry picked from commit ...)" to the commit message'),mainline:K.number().alias("m").describe("Select parent number for merge commit (1-based)"),noCommit:S().alias("n").describe("Apply changes without creating a commit")},handler:async(n,r)=>{let o=await q(r.fs,r.cwd,t);if(D(o))return o;let s=o;if(n.abort){let H=await t?.hooks?.preCherryPick?.({repo:s,mode:"abort",commitRef:null});if(he(H))return{stdout:"",stderr:H.message??"",exitCode:1};let B=await Pw(s,r.env);return B.exitCode===0&&await t?.hooks?.postCherryPick?.({repo:s,mode:"abort",commitHash:null,hadConflicts:!1}),B}if(n.continue){let H=await t?.hooks?.preCherryPick?.({repo:s,mode:"continue",commitRef:null});if(he(H))return{stdout:"",stderr:H.message??"",exitCode:1};let B=await $w(s,r.env);if(B.exitCode===0){let L=await Z(s);await t?.hooks?.postCherryPick?.({repo:s,mode:"continue",commitHash:L,hadConflicts:!1})}return B}if(n.skip)return xw(s,r.env);let i=n.commit;if(!i)return v("you must specify a commit to cherry-pick");let a=await t?.hooks?.preCherryPick?.({repo:s,mode:"pick",commitRef:i});if(he(a))return{stdout:"",stderr:a.message??"",exitCode:1};let c=await Ge(s,i);if(D(c))return c;let f=c.hash,l=c.commit,d=await nt(s);if(D(d))return d;let u=await X(s);if(n.noCommit){let H=u.entries.filter(B=>B.stage>0);if(H.length>0){let _=H.slice(0,10).map(Y=>`${Y.path}: unmerged (${Y.hash})`).join(` +-`),V=H.length>10?` +-...`:"";return F(`${_}${V} ++`)}let o=r==="merge"?"Merge with strategy ort failed.":`fatal: ${r} failed`;return`${s.join("")}Aborting ++${o} ++`}async function Yn(e,t,n,r){let s=await X(e),o=await de(e,n);if(!r.skipStagedChangeCheck&&e.workTree){let h=new Map(ze(s).map(g=>[g.path,g])),p=[];for(let[g,w]of h){let b=o.get(g);(!b||b.hash!==w.hash)&&p.push(g)}for(let[g]of o)h.has(g)||p.push(g);if(p.length>0){let g=[...p].sort();r.atomicCheckout||await Pc(e,s,o);let w=r.operationName??"merge",b=r.callerCommand??"merge";return{ok:!1,stdout:"",stderr:io(g,w,b,"local","staged"),exitCode:r.errorExitCode??2,failureKind:"staged"}}}if(e.workTree&&r.preflightOnewayCheck){let h=await jr(e,[{label:"target",treeHash:t.resultTree}],s,{mergeFn:Qo,updateWorktree:!1,reset:!1,errorExitCode:r.errorExitCode??2,operationName:r.operationName??"merge"});if(!h.success){r.atomicCheckout||await Pc(e,s,o);let p=r.operationName??"merge",g=r.callerCommand??"merge",w=h.errors.filter(C=>C.error==="WOULD_OVERWRITE"||C.error==="NOT_UPTODATE_FILE").map(C=>C.path).sort(),b=h.errors.filter(C=>C.error==="WOULD_LOSE_UNTRACKED_OVERWRITTEN"||C.error==="WOULD_LOSE_UNTRACKED_REMOVED").map(C=>C.path).sort(),y;return w.length>0&&b.length>0?y=ru(w,b,p,g):b.length>0?y=io(b,p,g,"untracked","worktree"):y=io(w,p,g,"local","worktree"),{ok:!1,stdout:"",stderr:y,exitCode:r.errorExitCode??2,failureKind:"worktree"}}}if(e.workTree){let h=await jr(e,[{label:"current",treeHash:n},{label:"target",treeHash:t.resultTree}],s,{mergeFn:Jo,updateWorktree:!0,reset:!1,errorExitCode:r.errorExitCode??2,operationName:r.operationName??"merge",allowStagedChanges:!!r.preflightOnewayCheck});if(!h.success){r.atomicCheckout||await Pc(e,s,o);let p=r.operationName??"merge",g=r.callerCommand??"merge",w=h.errors.filter(x=>x.error==="WOULD_OVERWRITE"||x.error==="NOT_UPTODATE_FILE").map(x=>x.path).sort(),b=h.errors.filter(x=>x.error==="WOULD_LOSE_UNTRACKED_OVERWRITTEN"||x.error==="WOULD_LOSE_UNTRACKED_REMOVED").map(x=>x.path).sort(),y=[];w.length>0&&y.push(io(w,p,g,"local","worktree")),b.length>0&&y.push(io(b,p,g,"untracked","worktree"));let C;return y.length>1?C=ru(w,b,p,g):C=y[0]??"",{ok:!1,stdout:"",stderr:C,exitCode:r.errorExitCode??2,failureKind:"worktree"}}await Me(e,h.worktreeOps)}let i=new Set,a=t.entries;if(r.preflightOnewayCheck){let h=[];for(let p of t.entries){if(p.stage===0){let g=o.get(p.path);if(g&&g.hash===p.hash){i.add(p.path);continue}}h.push(p)}a=h}let c=new Set(a.map(h=>h.path));for(let h of o.keys())i.has(h)||c.add(h);let f=s.entries.filter(h=>!c.has(h.path)),l=[...a,...f];l.sort((h,p)=>Ae(h.path,p.path)||h.stage-p.stage);let d={version:2,entries:l};await oe(e,d);let u=l.filter(h=>h.stage===0),m=await Ze(e,u);return{ok:!0,finalIndex:d,mergedTreeHash:m}}async function Pc(e,t,n){if(e.workTree)for(let r of t.entries){if(r.stage!==0||n.has(r.path))continue;let s=I(e.workTree,r.path);await e.fs.exists(s)||await lt(e,{path:r.path,hash:r.hash,mode:r.mode})}}ie();Xe();ye();Te();rn();ke();function iu(e,t){e.command("cherry-pick",{description:"Apply the changes introduced by some existing commits",args:[B.string().name("commit").describe("The commit to cherry-pick").optional()],options:{abort:S().describe("Abort the current cherry-pick operation"),continue:S().describe("Continue the cherry-pick after conflict resolution"),skip:S().describe("Skip the current cherry-pick and continue with the rest"),"record-origin":S().alias("x").describe('Append "(cherry picked from commit ...)" to the commit message'),mainline:K.number().alias("m").describe("Select parent number for merge commit (1-based)"),noCommit:S().alias("n").describe("Apply changes without creating a commit")},handler:async(n,r)=>{let s=await W(r.fs,r.cwd,t);if(D(s))return s;let o=s;if(n.abort){let H=await t?.hooks?.preCherryPick?.({repo:o,mode:"abort",commitRef:null});if(pe(H))return{stdout:"",stderr:H.message??"",exitCode:1};let q=await qw(o,r.env);return q.exitCode===0&&await t?.hooks?.postCherryPick?.({repo:o,mode:"abort",commitHash:null,hadConflicts:!1}),q}if(n.continue){let H=await t?.hooks?.preCherryPick?.({repo:o,mode:"continue",commitRef:null});if(pe(H))return{stdout:"",stderr:H.message??"",exitCode:1};let q=await zw(o,r.env);if(q.exitCode===0){let F=await Z(o);await t?.hooks?.postCherryPick?.({repo:o,mode:"continue",commitHash:F,hadConflicts:!1})}return q}if(n.skip)return Ww(o,r.env);let i=n.commit;if(!i)return v("you must specify a commit to cherry-pick");let a=await t?.hooks?.preCherryPick?.({repo:o,mode:"pick",commitRef:i});if(pe(a))return{stdout:"",stderr:a.message??"",exitCode:1};let c=await Le(o,i);if(D(c))return c;let f=c.hash,l=c.commit,d=await nt(o);if(D(d))return d;let u=await X(o);if(n.noCommit){let H=u.entries.filter(q=>q.stage>0);if(H.length>0){let _=H.slice(0,10).map(V=>`${V.path}: unmerged (${V.hash})`).join(` ++`),Y=H.length>10?` ++...`:"";return N(`${_}${Y} + error: your index file is unmerged. + fatal: cherry-pick failed +-`,128)}}else{let H=Hr(u,"Cherry-picking",`fatal: cherry-pick failed +-`);if(H)return H}let m=await M(s,d),p=!!n["record-origin"]?Ow(l.message,f):l.message;if(s.workTree&&!n.noCommit){let H=await de(s,m.tree);if(Bn(u,H))return F(`error: your local changes would be overwritten by cherry-pick. ++`,128)}}else{let H=Lr(u,"Cherry-picking",`fatal: cherry-pick failed ++`);if(H)return H}let m=await M(o,d),p=!!n["record-origin"]?Kw(l.message,f):l.message;if(o.workTree&&!n.noCommit){let H=await de(o,m.tree);if(Wn(u,H))return N(`error: your local changes would be overwritten by cherry-pick. + hint: commit your changes or stash them to proceed. + fatal: cherry-pick failed +-`,128)}if(l.parents.length>1){if(!n.mainline)return F(`error: commit ${f} is a merge but no -m option was given. ++`,128)}if(l.parents.length>1){if(!n.mainline)return N(`error: commit ${f} is a merge but no -m option was given. + fatal: cherry-pick failed +-`,128);let H=n.mainline-1;if(H<0||H>=l.parents.length)return F(`error: commit ${f} does not have parent ${n.mainline} ++`,128);let H=n.mainline-1;if(H<0||H>=l.parents.length)return N(`error: commit ${f} does not have parent ${n.mainline} + fatal: cherry-pick failed +-`,128)}else if(n.mainline)return F(`error: mainline was specified but commit is not a merge. ++`,128)}else if(n.mainline)return N(`error: mainline was specified but commit is not a merge. + fatal: cherry-pick failed +-`,128);let g;if(l.parents.length===0)g=await Ye(s,[]);else{let H=l.parents.length>1?n.mainline-1:0,B=l.parents[H];if(!B)throw new Error("unreachable: parent must exist");g=(await M(s,B)).tree}let w=await ue(s,f),b=me(l.message),R=await Re(s,"merge.conflictstyle")??"merge",C={a:"HEAD",b:b?`${w} (${b})`:w,conflictStyle:R},x=await sn(s,g,m.tree,l.tree,C,t?.mergeDriver);if(x.conflicts.length===0&&x.resultTree===m.tree){if(n.noCommit)return{stdout:"",stderr:"",exitCode:0};await Q(s,"CHERRY_PICK_HEAD",f),await Q(s,"ORIG_HEAD",d),await Ue(s,"MERGE_MSG",p);let H=x.messages.length>0?`${x.messages.join(` ++`,128);let g;if(l.parents.length===0)g=await Ze(o,[]);else{let H=l.parents.length>1?n.mainline-1:0,q=l.parents[H];if(!q)throw new Error("unreachable: parent must exist");g=(await M(o,q)).tree}let w=await fe(o,f),b=he(l.message),y=await Re(o,"merge.conflictstyle")??"merge",C={a:"HEAD",b:b?`${w} (${b})`:w,conflictStyle:y},x=await fn(o,g,m.tree,l.tree,C,t?.mergeDriver);if(x.conflicts.length===0&&x.resultTree===m.tree){if(n.noCommit)return{stdout:"",stderr:"",exitCode:0};await Q(o,"CHERRY_PICK_HEAD",f),await Q(o,"ORIG_HEAD",d),await Ne(o,"MERGE_MSG",p);let H=x.messages.length>0?`${x.messages.join(` + `)} +-`:"",B=await pt(s,{fromCommit:!0});return{stdout:`${H}${B}`,stderr:`The previous cherry-pick is now empty, possibly due to conflict resolution. ++`:"",q=await yt(o,{fromCommit:!0});return{stdout:`${H}${q}`,stderr:`The previous cherry-pick is now empty, possibly due to conflict resolution. + If you wish to commit it anyway, use: + + git commit --allow-empty + + Otherwise, please use 'git cherry-pick --skip' +-`,exitCode:1}}let y=await Kn(s,x,m.tree,{labels:C,errorExitCode:128,operationName:"merge",callerCommand:"cherry-pick",skipStagedChangeCheck:!0,preflightOnewayCheck:!!n.noCommit});if(!y.ok)return y;if(x.conflicts.length>0){let H=x.messages.join(` +-`);return await t?.hooks?.postCherryPick?.({repo:s,mode:"pick",commitHash:null,hadConflicts:!0}),n.noCommit?{stdout:H?`${H} +-`:"",stderr:`error: could not apply ${w}... ${me(l.message)} ++`,exitCode:1}}let k=await Yn(o,x,m.tree,{labels:C,errorExitCode:128,operationName:"merge",callerCommand:"cherry-pick",skipStagedChangeCheck:!0,preflightOnewayCheck:!!n.noCommit});if(!k.ok)return k;if(x.conflicts.length>0){let H=x.messages.join(` ++`);return await t?.hooks?.postCherryPick?.({repo:o,mode:"pick",commitHash:null,hadConflicts:!0}),n.noCommit?{stdout:H?`${H} ++`:"",stderr:`error: could not apply ${w}... ${he(l.message)} + hint: after resolving the conflicts, mark the corrected paths + hint: with 'git add ' or 'git rm ' + hint: Disable this message with "git config set advice.mergeConflict false" +-`,exitCode:1}:(await Q(s,"CHERRY_PICK_HEAD",f),await Q(s,"ORIG_HEAD",d),await Ue(s,"MERGE_MSG",p),{stdout:H?`${H} +-`:"",stderr:`error: could not apply ${w}... ${me(l.message)} ++`,exitCode:1}:(await Q(o,"CHERRY_PICK_HEAD",f),await Q(o,"ORIG_HEAD",d),await Ne(o,"MERGE_MSG",p),{stdout:H?`${H} ++`:"",stderr:`error: could not apply ${w}... ${he(l.message)} + hint: After resolving the conflicts, mark them with + hint: "git add/rm ", then run + hint: "git cherry-pick --continue". +@@ -340,147 +345,149 @@ hint: You can instead skip this commit with "git cherry-pick --skip". + hint: To abort and get back to the state before "git cherry-pick", + hint: run "git cherry-pick --abort". + hint: Disable this message with "git config set advice.mergeConflict false" +-`,exitCode:1})}let P=y.mergedTreeHash;if(n.noCommit)return{stdout:"",stderr:"",exitCode:0};let k=await ct(s,r.env);if(D(k))return k;let E=await Gt(s,P,[d],l.author,k,p);await gn(s),await tn(s);let O=await te(s),$=p.split(` +-`)[0]??"",T=O?.type==="symbolic"?O.target:"HEAD";await ee(s,r.env,T,d,E,`cherry-pick: ${$}`,O?.type==="symbolic");let j=O?.type==="symbolic"?Ie(O.target):"detached HEAD",U=m.tree,G=await zn(s,U,P,l.author,k,!0),N=await pn(s,j,E,p),A=x.messages.length>0?`${x.messages.join(` ++`,exitCode:1})}let P=k.mergedTreeHash;if(n.noCommit)return{stdout:"",stderr:"",exitCode:0};let E=await dt(o,r.env);if(D(E))return E;let R=await Ut(o,P,[d],l.author,E,p);await kn(o),await on(o);let O=await ne(o),$=p.split(` ++`)[0]??"",T=O?.type==="symbolic"?O.target:"HEAD";await ee(o,r.env,T,d,R,`cherry-pick: ${$}`,O?.type==="symbolic");let j=O?.type==="symbolic"?ve(O.target):"detached HEAD",U=m.tree,G=await Kn(o,U,P,l.author,E,!0),L=await yn(o,j,R,p),A=x.messages.length>0?`${x.messages.join(` + `)} +-`:"";return await t?.hooks?.postCherryPick?.({repo:s,mode:"pick",commitHash:E,hadConflicts:!1}),{stdout:`${A}${N} +-${G}`,stderr:"",exitCode:0}}})}async function xw(e,t){if(!await z(e,"CHERRY_PICK_HEAD"))return F(`error: no cherry-pick in progress ++`:"";return await t?.hooks?.postCherryPick?.({repo:o,mode:"pick",commitHash:R,hadConflicts:!1}),{stdout:`${A}${L} ++${G}`,stderr:"",exitCode:0}}})}async function Ww(e,t){if(!await z(e,"CHERRY_PICK_HEAD"))return N(`error: no cherry-pick in progress + fatal: cherry-pick failed +-`,128);let r=await Z(e);if(!r)return v("unable to resolve HEAD");let o=await M(e,r),s=await X(e),i=await ss(e,o.tree,s,r);if(!i.success){let a=i.errorOutput;return{...a,stderr:a.stderr+`error: failed to skip the commit ++`,128);let r=await Z(e);if(!r)return v("unable to resolve HEAD");let s=await M(e,r),o=await X(e),i=await as(e,s.tree,o,r);if(!i.success){let a=i.errorOutput;return{...a,stderr:a.stderr+`error: failed to skip the commit + fatal: cherry-pick failed +-`}}return await ie(e,{version:2,entries:i.newEntries}),await je(e,i.worktreeOps),await ee(e,t,"HEAD",r,r,`reset: moving to ${r}`),await gn(e),{stdout:"",stderr:"",exitCode:0}}async function Pw(e,t){return await z(e,"CHERRY_PICK_HEAD")?cr(e,t,{operationRef:"CHERRY_PICK_HEAD",noOpError:F(`error: no cherry-pick or revert in progress ++`}}return await oe(e,{version:2,entries:i.newEntries}),await Me(e,i.worktreeOps),await ee(e,t,"HEAD",r,r,`reset: moving to ${r}`),await kn(e),{stdout:"",stderr:"",exitCode:0}}async function qw(e,t){return await z(e,"CHERRY_PICK_HEAD")?cr(e,t,{operationRef:"CHERRY_PICK_HEAD",noOpError:N(`error: no cherry-pick or revert in progress + fatal: cherry-pick failed +-`,128),operationName:"cherry-pick",clearState:gn,origHeadAsTargetRev:!0}):await z(e,"REVERT_HEAD")?cr(e,t,{operationRef:"REVERT_HEAD",noOpError:F(`error: no cherry-pick or revert in progress ++`,128),operationName:"cherry-pick",clearState:kn,origHeadAsTargetRev:!0}):await z(e,"REVERT_HEAD")?cr(e,t,{operationRef:"REVERT_HEAD",noOpError:N(`error: no cherry-pick or revert in progress + fatal: cherry-pick failed +-`,128),operationName:"cherry-pick",clearState:tn,origHeadAsTargetRev:!0}):F(`error: no cherry-pick or revert in progress ++`,128),operationName:"cherry-pick",clearState:on,origHeadAsTargetRev:!0}):N(`error: no cherry-pick or revert in progress + fatal: cherry-pick failed +-`,128)}async function $w(e,t){let n=await z(e,"CHERRY_PICK_HEAD");if(!n)return F(`error: no cherry-pick or revert in progress ++`,128)}async function zw(e,t){let n=await z(e,"CHERRY_PICK_HEAD");if(!n)return N(`error: no cherry-pick or revert in progress + fatal: cherry-pick failed +-`,128);let r=await X(e),o=ar(r);if(o)return o;let s=await M(e,n),i=await Ae(e,"MERGE_MSG");if(!i)return F(`Aborting commit due to empty commit message. +-`,1);let a=await Ae(e,"SQUASH_MSG");if(a&&(i=a+i),i=Ft(i),!i)return F(`Aborting commit due to empty commit message. +-`,1);let c=qe(r),f=await Ye(e,c),l=await nt(e);if(D(l))return l;let u=(await M(e,l)).tree,m=await ct(e,t);if(D(m))return m;let h=Nt(i),p=await Gt(e,f,[l],s.author,m,h);await gn(e),await tn(e);let g=await te(e),w=me(h),b=g?.type==="symbolic"?g.target:"HEAD";await ee(e,t,b,l,p,`commit (cherry-pick): ${w}`,g?.type==="symbolic");let R=g?.type==="symbolic"?Ie(g.target):"detached HEAD",C=await zn(e,u,f,s.author,m,!0);return{stdout:`${await pn(e,R,p,i)} +-${C}`,stderr:"",exitCode:0}}function Ow(e,t){let n=`(cherry picked from commit ${t})`,r=e.replace(/\n+$/,""),o=r.lastIndexOf(` +-`),s=o===-1?r:r.slice(o+1);return/^\(cherry picked from commit [0-9a-f]+\)$/.test(s)?`${r} ++`,128);let r=await X(e),s=ar(r);if(s)return s;let o=await M(e,n),i=await He(e,"MERGE_MSG");if(!i)return N(`Aborting commit due to empty commit message. ++`,1);let a=await He(e,"SQUASH_MSG");if(a&&(i=a+i),i=_t(i),!i)return N(`Aborting commit due to empty commit message. ++`,1);let c=ze(r),f=await Ze(e,c),l=await nt(e);if(D(l))return l;let u=(await M(e,l)).tree,m=await dt(e,t);if(D(m))return m;let h=Bt(i),p=await Ut(e,f,[l],o.author,m,h);await kn(e),await on(e);let g=await ne(e),w=he(h),b=g?.type==="symbolic"?g.target:"HEAD";await ee(e,t,b,l,p,`commit (cherry-pick): ${w}`,g?.type==="symbolic");let y=g?.type==="symbolic"?ve(g.target):"detached HEAD",C=await Kn(e,u,f,o.author,m,!0);return{stdout:`${await yn(e,y,p,i)} ++${C}`,stderr:"",exitCode:0}}function Kw(e,t){let n=`(cherry picked from commit ${t})`,r=e.replace(/\n+$/,""),s=r.lastIndexOf(` ++`),o=s===-1?r:r.slice(s+1);return/^\(cherry picked from commit [0-9a-f]+\)$/.test(o)?`${r} + ${n} + `:`${r} + + ${n} +-`}ne();Be();_o();ve();ge();Ee();function Xd(e,t){e.command("clean",{description:"Remove untracked files from the working tree",args:[W.string().name("pathspec").describe("Pathspec to limit which files are removed").optional().variadic()],options:{force:S().alias("f").describe("Required to actually remove files"),"dry-run":S().alias("n").describe("Don't actually remove anything, just show what would be done"),directories:S().alias("d").describe("Also remove untracked directories"),removeIgnored:S().alias("x").describe("Remove ignored files as well"),onlyIgnored:S().alias("X").describe("Remove only ignored files"),exclude:K.string().alias("e").describe("Additional exclude pattern"),quiet:ce("do not print names of files removed")},handler:async(n,r)=>{let o=await q(r.fs,r.cwd,t);if(D(o))return o;let s=o,i=tt(s);if(i)return i;let a=s.workTree,c=n["dry-run"],f=n.force,l=n.directories,d=n.removeIgnored,u=n.onlyIgnored;if(!f&&!c&&await Re(s,"clean.requireForce")!=="false")return v("clean.requireForce defaults to true and neither -i, -n, nor -f given; refusing to clean");let m=await X(s),h=new Set(m.entries.map(k=>k.path)),p=kt(s,r.cwd),g=n.pathspec,w=g.length>0?g.map(k=>We(k,p)):null,b=n.exclude?[n.exclude]:[],R=await Zd(s,a,"",{trackedPaths:h,removeDirs:l,removeIgnored:d,onlyIgnored:u,extraExcludes:b}),C;w?C=R.filter(k=>Pe(w,k.path)):C=R,C.sort((k,E)=>k.pathE.path?1:0);let x=n.quiet,y=[];if(c){if(!x)for(let k of C){let E=k.isDir?`Would remove ${k.path}/`:`Would remove ${k.path}`;y.push(E)}}else for(let k of C){let E=I(a,k.path);k.isDir?(await r.fs.rm(E,{recursive:!0}),x||y.push(`Removing ${k.path}/`)):(await r.fs.rm(E),x||y.push(`Removing ${k.path}`))}return{stdout:y.length>0?`${y.join(` ++`}te();We();Xo();Se();ge();ke();function au(e,t){e.command("clean",{description:"Remove untracked files from the working tree",args:[B.string().name("pathspec").describe("Pathspec to limit which files are removed").optional().variadic()],options:{force:S().alias("f").describe("Required to actually remove files"),"dry-run":S().alias("n").describe("Don't actually remove anything, just show what would be done"),directories:S().alias("d").describe("Also remove untracked directories"),removeIgnored:S().alias("x").describe("Remove ignored files as well"),onlyIgnored:S().alias("X").describe("Remove only ignored files"),exclude:K.string().alias("e").describe("Additional exclude pattern"),quiet:ce("do not print names of files removed")},handler:async(n,r)=>{let s=await W(r.fs,r.cwd,t);if(D(s))return s;let o=s,i=tt(o);if(i)return i;let a=o.workTree,c=n["dry-run"],f=n.force,l=n.directories,d=n.removeIgnored,u=n.onlyIgnored;if(!f&&!c&&await Re(o,"clean.requireForce")!=="false")return v("clean.requireForce defaults to true and neither -i, -n, nor -f given; refusing to clean");let m=await X(o),h=new Set(m.entries.map(E=>E.path)),p=ut(o,r.cwd),g=n.pathspec,w=g.length>0?g.map(E=>qe(E,p)):null,b=n.exclude?[n.exclude]:[],y=await cu(o,a,"",{trackedPaths:h,removeDirs:l,removeIgnored:d,onlyIgnored:u,extraExcludes:b}),C;w?C=y.filter(E=>Pe(w,E.path)):C=y,C.sort((E,R)=>E.pathR.path?1:0);let x=n.quiet,k=[];if(c){if(!x)for(let E of C){let R=E.isDir?`Would remove ${E.path}/`:`Would remove ${E.path}`;k.push(R)}}else for(let E of C){let R=I(a,E.path);E.isDir?(await r.fs.rm(R,{recursive:!0}),x||k.push(`Removing ${E.path}/`)):(await r.fs.rm(R),x||k.push(`Removing ${E.path}`))}return{stdout:k.length>0?`${k.join(` + `)} +-`:"",stderr:"",exitCode:0}}})}async function Zd(e,t,n,r){let o=[],s=!r.removeIgnored,i=null;if(s||r.onlyIgnored){i=r._ignore??await rs(e);let c=I(t,".gitignore");try{let f=await e.fs.readFile(c);i=Ir(i,f,n,c)}catch{}if(!r._ignore&&r.extraExcludes.length>0){let f=r.extraExcludes.join(` +-`),l=_s(f,"","");i={...i,dirPatterns:[l,...i.dirPatterns]}}}let a=await e.fs.readdir(t);for(let c of a){if(n===""&&c===".git")continue;let f=I(t,c),l=n?`${n}/${c}`:c,d=await e.fs.stat(f);if(d.isDirectory){let u=i&&Pn(i,l,!0)==="ignored",m=Sw(r.trackedPaths,l),h=()=>Zd(e,f,l,{...r,_ignore:i??void 0});if(r.onlyIgnored){if(u&&!m){r.removeDirs&&o.push({path:l,isDir:!0});continue}let p=await h();!m&&r.removeDirs?p.length>0&&o.push({path:l,isDir:!0}):o.push(...p)}else if(m){let p=await h();o.push(...p)}else if(!(u&&s)){if(r.removeDirs)if(r.removeIgnored)o.push({path:l,isDir:!0});else{let p=await h(),g=await e.fs.readdir(f);(p.length>0||g.length===0)&&o.push({path:l,isDir:!0})}}}else if(d.isFile){if(r.trackedPaths.has(l))continue;let u=i&&Pn(i,l,!1)==="ignored";r.onlyIgnored?u&&o.push({path:l,isDir:!1}):u&&s||o.push({path:l,isDir:!1})}}return o}function Sw(e,t){let n=`${t}/`;for(let r of e)if(r.startsWith(n))return!0;return!1}ne();Be();ve();ae();ge();Ve();ye();Gn();ae();ge();var wc=2147483647;async function wi(e){let t=I(e.gitDir,"shallow");try{let n=await e.fs.readFile(t),r=new Set;for(let o of n.split(` +-`)){let s=o.trim();s.length===40&&r.add(s)}return r}catch{return new Set}}async function vw(e,t){let n=I(e.gitDir,"shallow");if(t.size===0){try{await e.fs.rm(n,{force:!0})}catch{}return}let r=[...t].sort();await e.fs.writeFile(n,r.join(` ++`:"",stderr:"",exitCode:0}}})}async function cu(e,t,n,r){let s=[],o=!r.removeIgnored,i=null;if(o||r.onlyIgnored){i=r._ignore??await is(e);let c=I(t,".gitignore");try{let f=await e.fs.readFile(c);i=Dr(i,f,n,c)}catch{}if(!r._ignore&&r.extraExcludes.length>0){let f=r.extraExcludes.join(` ++`),l=Vs(f,"","");i={...i,dirPatterns:[l,...i.dirPatterns]}}}let a=await e.fs.readdir(t);for(let c of a){if(n===""&&c===".git")continue;let f=I(t,c),l=n?`${n}/${c}`:c,d=await e.fs.stat(f);if(d.isDirectory){let u=i&&vn(i,l,!0)==="ignored",m=Vw(r.trackedPaths,l),h=()=>cu(e,f,l,{...r,_ignore:i??void 0});if(r.onlyIgnored){if(u&&!m){r.removeDirs&&s.push({path:l,isDir:!0});continue}let p=await h();!m&&r.removeDirs?p.length>0&&s.push({path:l,isDir:!0}):s.push(...p)}else if(m){let p=await h();s.push(...p)}else if(!(u&&o)){if(r.removeDirs)if(r.removeIgnored)s.push({path:l,isDir:!0});else{let p=await h(),g=await e.fs.readdir(f);(p.length>0||g.length===0)&&s.push({path:l,isDir:!0})}}}else if(d.isFile){if(r.trackedPaths.has(l))continue;let u=i&&vn(i,l,!1)==="ignored";r.onlyIgnored?u&&s.push({path:l,isDir:!1}):u&&o||s.push({path:l,isDir:!1})}}return s}function Vw(e,t){let n=`${t}/`;for(let r of e)if(r.startsWith(n))return!0;return!1}te();We();Se();ie();ge();Xe();ye();Nn();ie();ge();var Sc=2147483647;async function Oi(e){let t=I(e.gitDir,"shallow");try{let n=await e.fs.readFile(t),r=new Set;for(let s of n.split(` ++`)){let o=s.trim();o.length===40&&r.add(o)}return r}catch{return new Set}}async function Yw(e,t){let n=I(e.gitDir,"shallow");if(t.size===0){try{await e.fs.rm(n,{force:!0})}catch{}return}let r=[...t].sort();await e.fs.writeFile(n,r.join(` + `)+` +-`)}async function Qd(e){return(await wi(e)).size>0}async function ms(e,t,n){let r=n??await wi(e);for(let o of t.shallow)r.add(o);for(let o of t.unshallow)r.delete(o);await vw(e,r)}async function Jd(e,t,n,r){if(n>=wc)return{shallow:[],unshallow:[...r]};let o=new Map,s=[];for(let f of t)!o.has(f)&&await Xt(e,f)&&(o.set(f,1),s.push({hash:f,level:1}));let i=new Set,a=0;for(;a=n){i.add(f);continue}let d;try{d=await M(e,f)}catch{continue}for(let u of d.parents)!o.has(u)&&await Xt(e,u)&&(o.set(u,l+1),s.push({hash:u,level:l+1}))}let c=[];for(let f of r){let l=o.get(f);l!==void 0&&l>>2;r<16&&(r=16),r=Mw(r);let o=r-1,s=new Uint32Array(r),i=[],a=-1>>>0;for(let u=n*16-16;u>=0;u-=16){let m=0;for(let h=1;h<=16;h++)m=(m<<8|e[u+h])^yi[m>>>23];if(m=m>>>0,m===a)i[i.length-1].ptr=u+16;else{a=m;let h=m&o;i.push({ptr:u+16,val:m}),s[h]++}}let c=new Map;for(let u of i){let m=u.val&o,h=c.get(m);h||(h=[],c.set(m,h)),h.push(u)}for(let[u,m]of c){if(m.length<=bi)continue;let h=[],p=m.length/bi;for(let g=0;gi.length;){let g=new Uint8Array(i.length*2);g.set(i),i=g}}a=nu(i,a,r),a=nu(i,a,o),c(18),a++;let f=0,l=0,d=Math.min(16,o);for(let p=0;p>>23],l++;f=f>>>0;let u=d,m=0,h=0;for(;u>>23])>>>0;let p=f&e.hashMask,g=e.buckets[p],w=e.buckets[p+1];for(let b=g;by&&(x=y),x<=h)break;let P=0;for(;Ph&&(h=P,m=C,h>=bc))break}}if(h0){for(;m>0&&s[m-1]===t[u-1];)if(h++,m--,u--,a--,!(--l>0)){a--,l=-1;break}l>0&&(i[a-l-1]=l),l=0}let p=h>eu?h-eu:0;h-=p,c(8);let g=a++,w=128;if(m&255&&(i[a++]=m&255,w|=1),m&65280&&(i[a++]=m>>>8&255,w|=2),m&16711680&&(i[a++]=m>>>16&255,w|=4),m&4278190080&&(i[a++]=m>>>24&255,w|=8),h&255&&(i[a++]=h&255,w|=16),h&65280&&(i[a++]=h>>>8&255,w|=32),i[g]=w,u+=h,m+=h,h=p,m>4294967295&&(h=0),h>>23];f=f>>>0}}if(n&&a>n)return null}return l>0&&(i[a-l-1]=l),n&&a>n?null:i.subarray(0,a)}var tu={blob:0,tree:1,commit:2,tag:3};function ki(e,t){let n=t?.window??10,r=t?.depth??50,o=e.slice().sort((f,l)=>{let d=tu[f.type]??99,u=tu[l.type]??99;return d!==u?d-u:l.content.byteLength-f.content.byteLength}),s=new Map,i=[],a=[],c=[];for(let f=0;f=h;p--){let g=o[p];if(g.type!==l.type||(s.get(g.hash)?.depth??0)>=r||l.content.byteLength>>5)continue;let R=a[p-h]??null;if(!R)continue;let C=u?u.byteLength:l.content.byteLength/2|0;if(C<16)continue;let x=Dw(R,l.content,C);x&&(!u||x.byteLength=n&&(a.shift(),c.shift()),a.push(Hw(l.content)),c.push(l.hash)}return i}function Mw(e){let t=e;return t--,t|=t>>1,t|=t>>2,t|=t>>4,t|=t>>8,t|=t>>16,t++,t<16?16:t}function nu(e,t,n){let r=n;do{let o=r&127;r>>>=7,r>0&&(o|=128),e[t++]=o}while(r>0);return t}Qr();ye();ae();Mn();Jr();Go();async function hs(e,t,n,r,o){let s=o??r,i=new Set;for(let l of n)await to(e,l,i,s);let a=[...t];if(o&&r)for(let l of o)try{let d=await M(e,l);for(let u of d.parents)i.has(u)||a.push(u)}catch{}let c=[],f=new Set;for(let l of a)await no(e,l,i,f,c,r);return{count:c.length,objects:jw(c)}}async function*jw(e){for(let t of e)yield t}async function ps(e){let t=[];for await(let n of e.objects)t.push(n);return t}async function to(e,t,n,r){if(n.has(t))return;n.add(t);let o=await Lw(e,t);if(o)switch(o.type){case"commit":{let s=Rn(o.content);if(await to(e,s.tree,n,r),!r?.has(t))for(let i of s.parents)await to(e,i,n,r);break}case"tree":{let s=Nn(o.content);for(let i of s.entries)await to(e,i.hash,n,r);break}case"tag":{let s=mn(o.content);await to(e,s.object,n,r);break}case"blob":break}}async function no(e,t,n,r,o,s){if(r.has(t)||n.has(t))return;r.add(t);let i=await be(e,t);switch(o.push({hash:t,type:i.type,content:i.content}),i.type){case"commit":{let a=Rn(i.content);if(await no(e,a.tree,n,r,o,s),!s?.has(t))for(let c of a.parents)await no(e,c,n,r,o,s);break}case"tree":{let a=Nn(i.content);for(let c of a.entries)await no(e,c.hash,n,r,o,s);break}case"tag":{let a=mn(i.content);await no(e,a.object,n,r,o,s);break}case"blob":break}}async function Lw(e,t){try{return await be(e,t)}catch(n){if(n instanceof Error&&n.message===`object ${t} not found`)return null;throw n}}var Gw=new TextEncoder,Er=new TextDecoder,ru=65520,Fw=new Uint8Array([48,48,48,48]),m$=new Uint8Array([48,48,48,49]),h$=new Uint8Array([48,48,48,50]);function Vn(e){let t=typeof e=="string"?Gw.encode(e):e,n=4+t.byteLength;if(n>ru)throw new Error(`pkt-line too long: ${n} bytes (max ${ru})`);let r=n.toString(16).padStart(4,"0"),o=new Uint8Array(n);return o[0]=r.charCodeAt(0),o[1]=r.charCodeAt(1),o[2]=r.charCodeAt(2),o[3]=r.charCodeAt(3),o.set(t,4),o}function yc(){return Fw.slice()}function Ei(...e){let t=0;for(let o of e)t+=o.byteLength;let n=new Uint8Array(t),r=0;for(let o of e)n.set(o,r),r+=o.byteLength;return n}function Nr(e){let t=[],n=0;for(;ne.byteLength)throw new Error("Truncated pkt-line header");let r=Er.decode(e.subarray(n,n+4)),o=parseInt(r,16);if(Number.isNaN(o))throw new Error(`Invalid pkt-line length: ${r}`);if(o===0){t.push({type:"flush"}),n+=4;continue}if(o===1){t.push({type:"delim"}),n+=4;continue}if(o===2){t.push({type:"response-end"}),n+=4;continue}if(o<4)throw new Error(`Invalid pkt-line length: ${o}`);if(n+o>e.byteLength)throw new Error(`Truncated pkt-line: need ${o} bytes at offset ${n}, have ${e.byteLength-n}`);t.push({type:"data",data:e.subarray(n+4,n+o)}),n+=o}return t}function ro(e){if(e.type!=="data")return"";let t=Er.decode(e.data);return t.endsWith(` +-`)?t.slice(0,-1):t}var Nw=65536;async function*kc(e){let t=e.getReader(),n=new Uint8Array(Nw),r=0;try{for(;;){for(;!(r<4);){let c=Er.decode(n.subarray(0,4)),f=parseInt(c,16);if(Number.isNaN(f))throw new Error(`Invalid pkt-line length: ${c}`);if(f===0){yield{type:"flush"},o(4);continue}if(f===1){yield{type:"delim"},o(4);continue}if(f===2){yield{type:"response-end"},o(4);continue}if(f<4)throw new Error(`Invalid pkt-line length: ${f}`);if(rn.byteLength){let c=n.byteLength;for(;c0)throw new Error("Truncated pkt-line header")}finally{t.releaseLock()}function o(s){n.copyWithin(0,s,r),r-=s}}var su=1,ou=2,iu=3;async function Ec(e,t){let n=[],r=[],o=0,s=!1;for await(let c of e){if(c.type!=="data"){s||n.push(c);continue}if(c.data.byteLength===0){s||n.push(c);continue}let f=c.data[0];if(!s)if(f>=1&&f<=3)s=!0;else{n.push(c);continue}let l=c.data.subarray(1);switch(f){case su:r.push(l),o+=l.byteLength;break;case ou:t?.(Er.decode(l));break;case iu:throw new Error(`Remote error: ${Er.decode(l)}`);default:break}}let i=new Uint8Array(o),a=0;for(let c of r)i.set(c,a),a+=c.byteLength;return{packData:i,preambleLines:n}}function Rc(e){let t=[],n=[],r=[],o=0;for(let a of e){if(a.type!=="data"||a.data.byteLength===0)continue;let c=a.data[0];if(c===void 0)continue;let f=a.data.subarray(1);switch(c){case su:t.push(f),o+=f.byteLength;break;case ou:n.push(Er.decode(f));break;case iu:r.push(Er.decode(f));break;default:break}}let s=new Uint8Array(o),i=0;for(let a of t)s.set(a,i),i+=a.byteLength;return{packData:s,progress:n,errors:r}}St();function Cc(e){return e?e.type==="bearer"?{Authorization:`Bearer ${e.token}`}:{Authorization:`Basic ${btoa(`${e.username}:${e.password}`)}`}:{}}async function xc(e,t,n,r=globalThis.fetch){let o=e.replace(/\/+$/,""),s=await r(`${o}/info/refs?service=${t}`,{headers:{...Cc(n),"User-Agent":"just-git/1.0"}});if(!s.ok)throw new Error(`HTTP ${s.status} discovering refs at ${o}`);let i=s.headers.get("content-type")??"",a=`application/x-${t}-advertisement`,c=new Uint8Array(await s.arrayBuffer());if(!i.startsWith(a)){let l=new TextDecoder().decode(c.subarray(0,5));if(!/^[0-9a-f]{4}#/.test(l))throw new Error(`Server does not support smart HTTP (Content-Type: ${i})`)}let f=Nr(c);return Uw(f,t)}function Uw(e,t){let n=0,r=e[n];r?.type==="data"&&ro(r)===`# service=${t}`&&n++,e[n]?.type==="flush"&&n++;let o=[],s=[],i=new Map;for(;ng.name===h);p&&(p.peeledHash=u);continue}o.push({name:m,hash:u})}}return{refs:o,capabilities:s,symrefs:i}}var _w=["multi_ack_detailed","no-done","side-band-64k","ofs-delta","include-tag","shallow"];async function au(e,t,n,r,o,s=globalThis.fetch,i,a){if(t.length===0)throw new Error("fetchPack requires at least one want");let c=lu(r,_w),f=[];f.push(Vn(`want ${t[0]} ${c.join(" ")} +-`));for(let p=1;p0)throw new Error(`Remote error: ${h.join("")}`);if(n)for(let p of m)n(p);return{packData:u,acks:o,shallowLines:s,unshallowLines:i}}let f=0;for(let u of c)u.type==="data"&&(f+=u.data.byteLength);let l=new Uint8Array(f),d=0;for(let u of c)u.type==="data"&&(l.set(u.data,d),d+=u.data.byteLength);return{packData:l,acks:o,shallowLines:s,unshallowLines:i}}var qw=["report-status","side-band-64k","ofs-delta","delete-refs"];async function cu(e,t,n,r,o,s=globalThis.fetch,i){if(t.length===0)throw new Error("pushPack requires at least one command");let a=lu(r,qw),c=[],[f,...l]=t;if(!f)throw new Error("pushPack requires at least one command");c.push(Vn(`${f.oldHash} ${f.newHash} ${f.refName}\0${a.join(" ")} +-`));for(let g of l)c.push(Vn(`${g.oldHash} ${g.newHash} ${g.refName} +-`));c.push(yc());let d;if(n&&n.byteLength>0){let g=Ei(...c);d=new Uint8Array(g.byteLength+n.byteLength),d.set(g,0),d.set(n,g.byteLength)}else d=Ei(...c);let u=e.replace(/\/+$/,""),m=await s(`${u}/git-receive-pack`,{method:"POST",headers:{"Content-Type":"application/x-git-receive-pack-request",...Cc(o),"User-Agent":"just-git/1.0"},body:d});if(!m.ok)throw new Error(`HTTP ${m.status} pushing to ${u}`);if(!a.includes("report-status"))return{unpackOk:!0,refResults:[]};let h=a.includes("side-band-64k");if(h&&m.body)return zw(m.body,i);let p=new Uint8Array(await m.arrayBuffer());return Kw(p,h,i)}async function zw(e,t){let n=kc(e),{packData:r}=await Ec(n,t),o=Nr(r);return fu(o)}function Kw(e,t,n){let r;if(t){let o=Nr(e),{packData:s,progress:i,errors:a}=Rc(o);if(a.length>0)throw new Error(`Remote error: ${a.join("")}`);if(n)for(let c of i)n(c);r=Nr(s)}else r=Nr(e);return fu(r)}function fu(e){let t=!1,n,r=[];for(let o of e){if(o.type==="flush")break;let s=ro(o);if(s.startsWith("unpack "))t=s==="unpack ok",t||(n=s.slice(7));else if(s.startsWith("ok "))r.push({name:s.slice(3),ok:!0});else if(s.startsWith("ng ")){let i=s.slice(3),a=i.indexOf(" ");a!==-1?r.push({name:i.slice(0,a),ok:!1,error:i.slice(a+1)}):r.push({name:i,ok:!1})}}return{unpackOk:t,unpackError:n,refResults:r}}function lu(e,t){let n=new Set(e.map(o=>o.split("=",1)[0]??o)),r=[];for(let o of t)n.has(o)&&r.push(o);return r.push("agent=just-git/1.0"),r}var so=class{constructor(t,n){this.local=t;this.remote=n}headTarget;async advertiseRefs(){let t=await $e(this.remote),n=[];for(let s of t){if(s.name.startsWith("refs/tags/"))try{if((await be(this.remote,s.hash)).type==="tag"){n.push({name:s.name,hash:s.hash,peeledHash:await Se(this.remote,s.hash)});continue}}catch{}n.push({name:s.name,hash:s.hash})}let r=await z(this.remote,"HEAD");r&&n.push({name:"HEAD",hash:r});let o=await te(this.remote);return o?.type==="symbolic"&&(this.headTarget=o.target),n}async fetch(t,n,r){let o=await this.advertiseRefs();if(t.length===0)return{remoteRefs:o,objectCount:0};let s,i,a;if(r?.depth!==void 0){let l=r.existingShallows??new Set,d=await Jd(this.remote,t,r.depth,l);i=d,s=new Set(d.shallow),l.size>0&&(a=l)}let c=await Pc(this.remote,t,n,s,a);if(!c)return{remoteRefs:o,objectCount:0,shallowUpdates:i};let f=await Ho(this.local,c);return{remoteRefs:o,objectCount:f,shallowUpdates:i}}async push(t){let n=[],r=[];for(let s of t)s.newHash!==oe&&n.push(s.newHash),s.oldHash&&r.push(s.oldHash);if(n.length>0){let s=await Pc(this.local,n,r);s&&await Ho(this.remote,s)}let o=[];for(let s of t)try{let i=s.newHash===oe,a=s.oldHash??null;if(uu(s)&&!s.ok){o.push({...s,ok:!1,error:`non-fast-forward update rejected for ${s.name}`});continue}if(!i&&!s.ok&&s.oldHash&&!await qt(this.remote,s.oldHash,s.newHash)){o.push({...s,ok:!1,error:`non-fast-forward update rejected for ${s.name}`});continue}let c=i?null:{type:"direct",hash:s.newHash};if(!await this.remote.refStore.compareAndSwapRef(s.name,a,c)){o.push({...s,ok:!1,error:`failed to lock ref '${s.name}'`});continue}this.remote.hooks&&(i&&s.oldHash?this.remote.hooks.onRefDelete?.({repo:this.remote,ref:s.name,oldHash:s.oldHash}):i||this.remote.hooks.onRefUpdate?.({repo:this.remote,ref:s.name,oldHash:s.oldHash,newHash:s.newHash})),o.push({...s,ok:!0})}catch(i){o.push({...s,ok:!1,error:i instanceof Error?i.message:String(i)})}return{updates:o}}},oo=class{constructor(t,n,r,o,s){this.local=t;this.url=n;this.auth=r;this.fetchFn=o;this.onProgress=s}headTarget;cachedFetchCaps=null;cachedPushCaps=null;cachedFetchRefs=null;async advertiseRefs(){let t=await xc(this.url,"git-upload-pack",this.auth,this.fetchFn);this.cachedFetchCaps=t.capabilities,this.cachedFetchRefs=t.refs;let n=t.symrefs.get("HEAD");return n&&(this.headTarget=n),t.refs}async ensureFetchDiscovery(){return(!this.cachedFetchCaps||!this.cachedFetchRefs)&&await this.advertiseRefs(),{caps:this.cachedFetchCaps,refs:this.cachedFetchRefs}}async ensurePushDiscovery(){if(!this.cachedPushCaps){let t=await xc(this.url,"git-receive-pack",this.auth,this.fetchFn);this.cachedPushCaps=t.capabilities}return this.cachedPushCaps}async fetch(t,n,r){let{caps:o,refs:s}=await this.ensureFetchDiscovery();if(t.length===0)return{remoteRefs:s,objectCount:0};let i=await au(this.url,t,n,o,this.auth,this.fetchFn,r,this.onProgress);if(i.packData.byteLength===0)return{remoteRefs:s,objectCount:0};let a=await Ho(this.local,i.packData),c=i.shallowLines.length>0||i.unshallowLines.length>0?{shallow:i.shallowLines,unshallow:i.unshallowLines}:void 0;return{remoteRefs:s,objectCount:a,shallowUpdates:c}}async push(t){let n=new Set,r=[];for(let m of t){if(uu(m)&&!m.ok){n.add(m.name),r.push({...m,ok:!1,error:"non-fast-forward"});continue}if(du(m)&&!m.ok&&!await qt(this.local,m.oldHash,m.newHash)){let g=await Xt(this.local,m.oldHash)?"non-fast-forward":"fetch first";n.add(m.name),r.push({...m,ok:!1,error:g})}}let o=t.filter(m=>!n.has(m.name));if(o.length===0)return{updates:r};let s=await this.ensurePushDiscovery(),i=o.map(m=>({oldHash:m.oldHash??oe,newHash:m.newHash,refName:m.name})),a=[],c=[],f=!1;for(let m of o)m.newHash!==oe&&(a.push(m.newHash),f=!0),m.oldHash&&m.oldHash!==oe&&c.push(m.oldHash);let l=null;f&&(l=await Pc(this.local,a,c)??null);let d=await cu(this.url,i,l,s,this.auth,this.fetchFn,this.onProgress);return{updates:[...o.map(m=>{let h=d.refResults.find(w=>w.name===m.name),p=h?.ok??d.unpackOk,g=h?.error??(!p&&d.unpackError?`unpack failed: ${d.unpackError}`:void 0);return{...m,ok:p,error:g}}),...r]}}};function du(e){return!!e.oldHash&&e.oldHash!==oe&&e.newHash!==oe}function uu(e){return e.name.startsWith("refs/tags/")&&du(e)}async function Pc(e,t,n,r,o){let s=await hs(e,t,n,r,o);if(s.count===0)return;let i=await ps(s),c=ki(i).map(l=>({hash:l.hash,type:l.type,content:l.content,delta:l.delta,deltaBaseHash:l.deltaBase})),{data:f}=await To(c);return f}function Vw(e){if(!Ri(e))return{url:e};try{let t=new URL(e);if(!t.username&&!t.password)return{url:e};let n={type:"basic",username:decodeURIComponent(t.username),password:decodeURIComponent(t.password)};return t.username="",t.password="",{url:t.href,embeddedAuth:n}}catch{return{url:e}}}function Ur(e,t){let n=Vw(e);if(n.embeddedAuth&&t)try{t.set(new URL(n.url).origin,n.embeddedAuth)}catch{}return n}async function Yw(e,t){let r=(await we(e))[`remote "${t}"`];return r?.url?{name:t,url:r.url,fetchRefspec:r.fetch??"+refs/heads/*:refs/remotes/origin/*"}:null}function Xw(e){return e.length===0?null:{name:e,url:e,fetchRefspec:"+refs/heads/*:refs/remotes/origin/*",anonymous:!0}}function Ri(e){return e.startsWith("http://")||e.startsWith("https://")}function mu(e){return e.startsWith("ssh://")||e.startsWith("git@")||e.startsWith("git+ssh://")}function hu(e,t){if(t===void 0)return null;if(t===!1)return"network access is disabled";if(!t.allowed)return null;if(t.allowed.length===0)return"network access is disabled";let n;try{n=new URL(e).hostname}catch{return`network policy: access to '${e}' is not allowed`}for(let r of t.allowed)if(Ri(r)){if(e===r||e.startsWith(r))return null}else if(n===r)return null;return`network policy: access to '${e}' is not allowed`}function Zw(e){let t=e.get("GIT_HTTP_BEARER_TOKEN");if(t)return{type:"bearer",token:t};let n=e.get("GIT_HTTP_USER"),r=e.get("GIT_HTTP_PASSWORD");if(n&&r)return{type:"basic",username:n,password:r}}async function pu(e,t,n){if(e.credentialProvider){let o=await e.credentialProvider(t);if(o)return o}let r=Zw(n);if(r)return r;if(e.credentialCache)try{return e.credentialCache.get(new URL(t).origin)}catch{return}}async function gu(e,t,n,r){let o=Ur(t,e.credentialCache).url;if(Ri(o)){let s=hu(o,e.networkPolicy);if(s)throw new Error(s);let i=await pu(e,o,n);return new oo(e,o,i,e.fetchFn,e.onProgress)}if(!r&&e.resolveRemote&&(r=await e.resolveRemote(o)??void 0),!r)throw mu(o)?new Error(`SSH transport is not supported. Use an HTTPS URL instead of '${o}'.`):new Error(`'${o}' does not appear to be a git repository`);return new so(e,r)}async function Ci(e,t,n){let r=await Yw(e,t)??Xw(t);if(!r)return null;let o=Ur(r.url,e.credentialCache).url;if(Ri(o)){let i=hu(o,e.networkPolicy);if(i)throw new Error(i);let a=n?await pu(e,o,n):void 0;return{transport:new oo(e,o,a,e.fetchFn,e.onProgress),config:{...r,url:o}}}let s=(e.resolveRemote?await e.resolveRemote(o):null)??await Fn(e.fs,o);if(!s){if(mu(o))throw new Error(`SSH transport is not supported. Use an HTTPS URL instead of '${o}'.`);return null}return{transport:new so(e,s),config:{...r,url:o}}}De();st();Ee();function wu(e,t){e.command("clone",{description:"Clone a repository into a new directory",args:[W.string().name("repository").describe("Repository to clone"),W.string().name("directory").describe("Target directory").optional()],options:{bare:S().describe("Create a bare clone"),branch:K.string().alias("b").describe("Checkout this branch instead of HEAD"),depth:K.number().describe("Create a shallow clone with history truncated to N commits"),singleBranch:S().describe("Clone only the history of the specified or default branch"),noSingleBranch:S().describe("Clone all branches even with --depth"),noTags:S().describe("Don't clone any tags"),noCheckout:S().alias("n").describe("Don't create a checkout"),quiet:ce("be more quiet")},handler:async(n,r)=>{let o=n.repository;if(!o)return v("You must specify a repository to clone.");let s=o.startsWith("http://")||o.startsWith("https://"),i=n.branch,a=!!n.quiet,c=null,f=o;if(s)f=Ur(o,t?.credentialCache).url;else if(t?.resolveRemote&&(c=await t.resolveRemote(o)),c||(f=Qe(r.cwd,o),c=await Fn(r.fs,f)),!c)return v(`repository '${o}' does not exist`);let l=n.directory;if(!l){let U;s||o.includes("://")?U=f.split("/").pop()??f:U=xt(f),U.endsWith(".git")&&(U=U.slice(0,-4)),l=U}let d=Qe(r.cwd,l),u=await t?.hooks?.preClone?.({repository:f,targetPath:d,bare:n.bare,branch:i??null});if(he(u))return F(u.message??"");if(await r.fs.exists(d))try{if((await r.fs.readdir(d)).length>0)return v(`destination path '${l}' already exists and is not an empty directory.`)}catch{return v(`destination path '${l}' already exists and is not an empty directory.`)}await r.fs.mkdir(d,{recursive:!0});let{ctx:m}=await jo(r.fs,d,{bare:n.bare}),h=t?{...m,...t}:m,p=n.depth,g=n.singleBranch||p!==void 0&&!n.noSingleBranch,w=n.noTags||g,b=n.noCheckout,R=await we(h),C;try{C=await gu(h,f,r.env,c??void 0)}catch(U){let G=U instanceof Error?U.message:"";return G.startsWith("network")?v(G):v(`repository '${o}' does not exist`)}let x=await C.advertiseRefs();if(x.length===0)return R['remote "origin"']={url:f,fetch:"+refs/heads/*:refs/remotes/origin/*"},await et(h,R),await t?.hooks?.postClone?.({repo:h,repository:f,targetPath:d,bare:n.bare,branch:i??null}),{stdout:"",stderr:`${a?"":`Cloning into '${l}'... ++`)}async function fu(e){return(await Oi(e)).size>0}async function ws(e,t,n){let r=n??await Oi(e);for(let s of t.shallow)r.add(s);for(let s of t.unshallow)r.delete(s);await Yw(e,r)}async function lu(e,t,n,r){if(n>=Sc)return{shallow:[],unshallow:[...r]};let s=new Map,o=[];for(let f of t)!s.has(f)&&await tn(e,f)&&(s.set(f,1),o.push({hash:f,level:1}));let i=new Set,a=0;for(;a=n){i.add(f);continue}let d;try{d=await M(e,f)}catch{continue}for(let u of d.parents)!s.has(u)&&await tn(e,u)&&(s.set(u,l+1),o.push({hash:u,level:l+1}))}let c=[];for(let f of r){let l=s.get(f);l!==void 0&&l>>2;r<16&&(r=16),r=tb(r);let s=r-1,o=new Uint32Array(r),i=[],a=-1>>>0;for(let u=n*16-16;u>=0;u-=16){let m=0;for(let h=1;h<=16;h++)m=(m<<8|e[u+h])^vi[m>>>23];if(m=m>>>0,m===a)i[i.length-1].ptr=u+16;else{a=m;let h=m&s;i.push({ptr:u+16,val:m}),o[h]++}}let c=new Map;for(let u of i){let m=u.val&s,h=c.get(m);h||(h=[],c.set(m,h)),h.push(u)}for(let[u,m]of c){if(m.length<=Si)continue;let h=[],p=m.length/Si;for(let g=0;gi.length;){let g=new Uint8Array(i.length*2);g.set(i),i=g}}a=mu(i,a,r),a=mu(i,a,s),c(18),a++;let f=0,l=0,d=Math.min(16,s);for(let p=0;p>>23],l++;f=f>>>0;let u=d,m=0,h=0;for(;u>>23])>>>0;let p=f&e.hashMask,g=e.buckets[p],w=e.buckets[p+1];for(let b=g;bk&&(x=k),x<=h)break;let P=0;for(;Ph&&(h=P,m=C,h>=vc))break}}if(h0){for(;m>0&&o[m-1]===t[u-1];)if(h++,m--,u--,a--,!(--l>0)){a--,l=-1;break}l>0&&(i[a-l-1]=l),l=0}let p=h>du?h-du:0;h-=p,c(8);let g=a++,w=128;if(m&255&&(i[a++]=m&255,w|=1),m&65280&&(i[a++]=m>>>8&255,w|=2),m&16711680&&(i[a++]=m>>>16&255,w|=4),m&4278190080&&(i[a++]=m>>>24&255,w|=8),h&255&&(i[a++]=h&255,w|=16),h&65280&&(i[a++]=h>>>8&255,w|=32),i[g]=w,u+=h,m+=h,h=p,m>4294967295&&(h=0),h>>23];f=f>>>0}}if(n&&a>n)return null}return l>0&&(i[a-l-1]=l),n&&a>n?null:i.subarray(0,a)}var uu={blob:0,tree:1,commit:2,tag:3};function Ii(e,t){let n=t?.window??10,r=t?.depth??50,s=e.slice().sort((f,l)=>{let d=uu[f.type]??99,u=uu[l.type]??99;return d!==u?d-u:l.content.byteLength-f.content.byteLength}),o=new Map,i=[],a=[],c=[];for(let f=0;f=h;p--){let g=s[p];if(g.type!==l.type||(o.get(g.hash)?.depth??0)>=r||l.content.byteLength>>5)continue;let y=a[p-h]??null;if(!y)continue;let C=u?u.byteLength:l.content.byteLength/2|0;if(C<16)continue;let x=eb(y,l.content,C);x&&(!u||x.byteLength=n&&(a.shift(),c.shift()),a.push(Jw(l.content)),c.push(l.hash)}return i}function tb(e){let t=e;return t--,t|=t>>1,t|=t>>2,t|=t>>4,t|=t>>8,t|=t>>16,t++,t<16?16:t}function mu(e,t,n){let r=n;do{let s=r&127;r>>>=7,r>0&&(s|=128),e[t++]=s}while(r>0);return t}ns();ye();ie();On();Ar();Bs();async function bs(e,t,n,r,s){let o=s??r,i=new Set;for(let l of n)await fo(e,l,i,o);let a=[...t];if(s&&r)for(let l of s)try{let d=await M(e,l);for(let u of d.parents)i.has(u)||a.push(u)}catch{}let c=[],f=new Set;for(let l of a)await lo(e,l,i,f,c,r);return{count:c.length,objects:nb(c)}}async function*nb(e){for(let t of e)yield t}async function ys(e){let t=[];for await(let n of e.objects)t.push(n);return t}async function fo(e,t,n,r){if(n.has(t))return;n.add(t);let s=await rb(e,t);if(s)switch(s.type){case"commit":{let o=en(s.content);if(await fo(e,o.tree,n,r),!r?.has(t))for(let i of o.parents)await fo(e,i,n,r);break}case"tree":{let o=bn(s.content);for(let i of o.entries)await fo(e,i.hash,n,r);break}case"tag":{let o=Lt(s.content);await fo(e,o.object,n,r);break}case"blob":break}}async function lo(e,t,n,r,s,o){if(r.has(t)||n.has(t))return;r.add(t);let i=await me(e,t);switch(s.push({hash:t,type:i.type,content:i.content}),i.type){case"commit":{let a=en(i.content);if(await lo(e,a.tree,n,r,s,o),!o?.has(t))for(let c of a.parents)await lo(e,c,n,r,s,o);break}case"tree":{let a=bn(i.content);for(let c of a.entries)await lo(e,c.hash,n,r,s,o);break}case"tag":{let a=Lt(i.content);await lo(e,a.object,n,r,s,o);break}case"blob":break}}async function rb(e,t){try{return await me(e,t)}catch(n){if(n instanceof Error&&n.message===`object ${t} not found`)return null;throw n}}var sb=new TextEncoder,Rr=new TextDecoder,hu=65520,ob=new Uint8Array([48,48,48,48]),W$=new Uint8Array([48,48,48,49]),q$=new Uint8Array([48,48,48,50]);function Xn(e){let t=typeof e=="string"?sb.encode(e):e,n=4+t.byteLength;if(n>hu)throw new Error(`pkt-line too long: ${n} bytes (max ${hu})`);let r=n.toString(16).padStart(4,"0"),s=new Uint8Array(n);return s[0]=r.charCodeAt(0),s[1]=r.charCodeAt(1),s[2]=r.charCodeAt(2),s[3]=r.charCodeAt(3),s.set(t,4),s}function Ic(){return ob.slice()}function Ti(...e){let t=0;for(let s of e)t+=s.byteLength;let n=new Uint8Array(t),r=0;for(let s of e)n.set(s,r),r+=s.byteLength;return n}function Wr(e){let t=[],n=0;for(;ne.byteLength)throw new Error("Truncated pkt-line header");let r=Rr.decode(e.subarray(n,n+4)),s=parseInt(r,16);if(Number.isNaN(s))throw new Error(`Invalid pkt-line length: ${r}`);if(s===0){t.push({type:"flush"}),n+=4;continue}if(s===1){t.push({type:"delim"}),n+=4;continue}if(s===2){t.push({type:"response-end"}),n+=4;continue}if(s<4)throw new Error(`Invalid pkt-line length: ${s}`);if(n+s>e.byteLength)throw new Error(`Truncated pkt-line: need ${s} bytes at offset ${n}, have ${e.byteLength-n}`);t.push({type:"data",data:e.subarray(n+4,n+s)}),n+=s}return t}function uo(e){if(e.type!=="data")return"";let t=Rr.decode(e.data);return t.endsWith(` ++`)?t.slice(0,-1):t}var ib=65536;async function*Tc(e){let t=e.getReader(),n=new Uint8Array(ib),r=0;try{for(;;){for(;!(r<4);){let c=Rr.decode(n.subarray(0,4)),f=parseInt(c,16);if(Number.isNaN(f))throw new Error(`Invalid pkt-line length: ${c}`);if(f===0){yield{type:"flush"},s(4);continue}if(f===1){yield{type:"delim"},s(4);continue}if(f===2){yield{type:"response-end"},s(4);continue}if(f<4)throw new Error(`Invalid pkt-line length: ${f}`);if(rn.byteLength){let c=n.byteLength;for(;c0)throw new Error("Truncated pkt-line header")}finally{t.releaseLock()}function s(o){n.copyWithin(0,o,r),r-=o}}var pu=1,gu=2,wu=3;async function Ac(e,t){let n=[],r=[],s=0,o=!1;for await(let c of e){if(c.type!=="data"){o||n.push(c);continue}if(c.data.byteLength===0){o||n.push(c);continue}let f=c.data[0];if(!o)if(f>=1&&f<=3)o=!0;else{n.push(c);continue}let l=c.data.subarray(1);switch(f){case pu:r.push(l),s+=l.byteLength;break;case gu:t?.(Rr.decode(l));break;case wu:throw new Error(`Remote error: ${Rr.decode(l)}`);default:break}}let i=new Uint8Array(s),a=0;for(let c of r)i.set(c,a),a+=c.byteLength;return{packData:i,preambleLines:n}}function Hc(e){let t=[],n=[],r=[],s=0;for(let a of e){if(a.type!=="data"||a.data.byteLength===0)continue;let c=a.data[0];if(c===void 0)continue;let f=a.data.subarray(1);switch(c){case pu:t.push(f),s+=f.byteLength;break;case gu:n.push(Rr.decode(f));break;case wu:r.push(Rr.decode(f));break;default:break}}let o=new Uint8Array(s),i=0;for(let a of t)o.set(a,i),i+=a.byteLength;return{packData:o,progress:n,errors:r}}It();function Dc(e){return e?e.type==="bearer"?{Authorization:`Bearer ${e.token}`}:{Authorization:`Basic ${btoa(`${e.username}:${e.password}`)}`}:{}}async function Mc(e,t,n,r=globalThis.fetch){let s=e.replace(/\/+$/,""),o=await r(`${s}/info/refs?service=${t}`,{headers:{...Dc(n),"User-Agent":"just-git/1.0"}});if(!o.ok)throw new Error(`HTTP ${o.status} discovering refs at ${s}`);let i=o.headers.get("content-type")??"",a=`application/x-${t}-advertisement`,c=new Uint8Array(await o.arrayBuffer());if(!i.startsWith(a)){let l=new TextDecoder().decode(c.subarray(0,5));if(!/^[0-9a-f]{4}#/.test(l))throw new Error(`Server does not support smart HTTP (Content-Type: ${i})`)}let f=Wr(c);return ab(f,t)}function ab(e,t){let n=0,r=e[n];r?.type==="data"&&uo(r)===`# service=${t}`&&n++,e[n]?.type==="flush"&&n++;let s=[],o=[],i=new Map;for(;ng.name===h);p&&(p.peeledHash=u);continue}s.push({name:m,hash:u})}}return{refs:s,capabilities:o,symrefs:i}}var cb=["multi_ack_detailed","no-done","side-band-64k","ofs-delta","include-tag","shallow"];async function bu(e,t,n,r,s,o=globalThis.fetch,i,a){if(t.length===0)throw new Error("fetchPack requires at least one want");let c=Eu(r,cb),f=[];f.push(Xn(`want ${t[0]} ${c.join(" ")} ++`));for(let p=1;p0)throw new Error(`Remote error: ${h.join("")}`);if(n)for(let p of m)n(p);return{packData:u,acks:s,shallowLines:o,unshallowLines:i}}let f=0;for(let u of c)u.type==="data"&&(f+=u.data.byteLength);let l=new Uint8Array(f),d=0;for(let u of c)u.type==="data"&&(l.set(u.data,d),d+=u.data.byteLength);return{packData:l,acks:s,shallowLines:o,unshallowLines:i}}var db=["report-status","side-band-64k","ofs-delta","delete-refs"];async function yu(e,t,n,r,s,o=globalThis.fetch,i){if(t.length===0)throw new Error("pushPack requires at least one command");let a=Eu(r,db),c=[],[f,...l]=t;if(!f)throw new Error("pushPack requires at least one command");c.push(Xn(`${f.oldHash} ${f.newHash} ${f.refName}\0${a.join(" ")} ++`));for(let g of l)c.push(Xn(`${g.oldHash} ${g.newHash} ${g.refName} ++`));c.push(Ic());let d;if(n&&n.byteLength>0){let g=Ti(...c);d=new Uint8Array(g.byteLength+n.byteLength),d.set(g,0),d.set(n,g.byteLength)}else d=Ti(...c);let u=e.replace(/\/+$/,""),m=await o(`${u}/git-receive-pack`,{method:"POST",headers:{"Content-Type":"application/x-git-receive-pack-request",...Dc(s),"User-Agent":"just-git/1.0"},body:d});if(!m.ok)throw new Error(`HTTP ${m.status} pushing to ${u}`);if(!a.includes("report-status"))return{unpackOk:!0,refResults:[]};let h=a.includes("side-band-64k");if(h&&m.body)return ub(m.body,i);let p=new Uint8Array(await m.arrayBuffer());return mb(p,h,i)}async function ub(e,t){let n=Tc(e),{packData:r}=await Ac(n,t),s=Wr(r);return ku(s)}function mb(e,t,n){let r;if(t){let s=Wr(e),{packData:o,progress:i,errors:a}=Hc(s);if(a.length>0)throw new Error(`Remote error: ${a.join("")}`);if(n)for(let c of i)n(c);r=Wr(o)}else r=Wr(e);return ku(r)}function ku(e){let t=!1,n,r=[];for(let s of e){if(s.type==="flush")break;let o=uo(s);if(o.startsWith("unpack "))t=o==="unpack ok",t||(n=o.slice(7));else if(o.startsWith("ok "))r.push({name:o.slice(3),ok:!0});else if(o.startsWith("ng ")){let i=o.slice(3),a=i.indexOf(" ");a!==-1?r.push({name:i.slice(0,a),ok:!1,error:i.slice(a+1)}):r.push({name:i,ok:!1})}}return{unpackOk:t,unpackError:n,refResults:r}}function Eu(e,t){let n=new Set(e.map(s=>s.split("=",1)[0]??s)),r=[];for(let s of t)n.has(s)&&r.push(s);return r.push("agent=just-git/1.0"),r}var mo=class{constructor(t,n){this.local=t;this.remote=n}headTarget;async advertiseRefs(){let t=await $e(this.remote),n=[];for(let o of t){if(o.name.startsWith("refs/tags/"))try{if((await me(this.remote,o.hash)).type==="tag"){n.push({name:o.name,hash:o.hash,peeledHash:await Oe(this.remote,o.hash)});continue}}catch{}n.push({name:o.name,hash:o.hash})}let r=await z(this.remote,"HEAD");r&&n.push({name:"HEAD",hash:r});let s=await ne(this.remote);return s?.type==="symbolic"&&(this.headTarget=s.target),n}async fetch(t,n,r){let s=await this.advertiseRefs();if(t.length===0)return{remoteRefs:s,objectCount:0};let o,i,a;if(r?.depth!==void 0){let l=r.existingShallows??new Set,d=await lu(this.remote,t,r.depth,l);i=d,o=new Set(d.shallow),l.size>0&&(a=l)}let c=await jc(this.remote,t,n,o,a);if(!c)return{remoteRefs:s,objectCount:0,shallowUpdates:i};let f=await No(this.local,c);return{remoteRefs:s,objectCount:f,shallowUpdates:i}}async push(t){let n=[],r=[];for(let o of t)o.newHash!==se&&n.push(o.newHash),o.oldHash&&r.push(o.oldHash);if(n.length>0){let o=await jc(this.local,n,r);o&&await No(this.remote,o)}let s=[];for(let o of t)try{let i=o.newHash===se,a=o.oldHash??null;if(Cu(o)&&!o.ok){s.push({...o,ok:!1,error:`non-fast-forward update rejected for ${o.name}`});continue}if(!i&&!o.ok&&o.oldHash&&!await Vt(this.remote,o.oldHash,o.newHash)){s.push({...o,ok:!1,error:`non-fast-forward update rejected for ${o.name}`});continue}let c=i?null:{type:"direct",hash:o.newHash};if(!await this.remote.refStore.compareAndSwapRef(o.name,a,c)){s.push({...o,ok:!1,error:`failed to lock ref '${o.name}'`});continue}this.remote.hooks&&(i&&o.oldHash?this.remote.hooks.onRefDelete?.({repo:this.remote,ref:o.name,oldHash:o.oldHash}):i||this.remote.hooks.onRefUpdate?.({repo:this.remote,ref:o.name,oldHash:o.oldHash,newHash:o.newHash})),s.push({...o,ok:!0})}catch(i){s.push({...o,ok:!1,error:i instanceof Error?i.message:String(i)})}return{updates:s}}},ho=class{constructor(t,n,r,s,o){this.local=t;this.url=n;this.auth=r;this.fetchFn=s;this.onProgress=o}headTarget;cachedFetchCaps=null;cachedPushCaps=null;cachedFetchRefs=null;async advertiseRefs(){let t=await Mc(this.url,"git-upload-pack",this.auth,this.fetchFn);this.cachedFetchCaps=t.capabilities,this.cachedFetchRefs=t.refs;let n=t.symrefs.get("HEAD");return n&&(this.headTarget=n),t.refs}async ensureFetchDiscovery(){return(!this.cachedFetchCaps||!this.cachedFetchRefs)&&await this.advertiseRefs(),{caps:this.cachedFetchCaps,refs:this.cachedFetchRefs}}async ensurePushDiscovery(){if(!this.cachedPushCaps){let t=await Mc(this.url,"git-receive-pack",this.auth,this.fetchFn);this.cachedPushCaps=t.capabilities}return this.cachedPushCaps}async fetch(t,n,r){let{caps:s,refs:o}=await this.ensureFetchDiscovery();if(t.length===0)return{remoteRefs:o,objectCount:0};let i=await bu(this.url,t,n,s,this.auth,this.fetchFn,r,this.onProgress);if(i.packData.byteLength===0)return{remoteRefs:o,objectCount:0};let a=await No(this.local,i.packData),c=i.shallowLines.length>0||i.unshallowLines.length>0?{shallow:i.shallowLines,unshallow:i.unshallowLines}:void 0;return{remoteRefs:o,objectCount:a,shallowUpdates:c}}async push(t){let n=new Set,r=[];for(let m of t){if(Cu(m)&&!m.ok){n.add(m.name),r.push({...m,ok:!1,error:"non-fast-forward"});continue}if(Ru(m)&&!m.ok&&!await Vt(this.local,m.oldHash,m.newHash)){let g=await tn(this.local,m.oldHash)?"non-fast-forward":"fetch first";n.add(m.name),r.push({...m,ok:!1,error:g})}}let s=t.filter(m=>!n.has(m.name));if(s.length===0)return{updates:r};let o=await this.ensurePushDiscovery(),i=s.map(m=>({oldHash:m.oldHash??se,newHash:m.newHash,refName:m.name})),a=[],c=[],f=!1;for(let m of s)m.newHash!==se&&(a.push(m.newHash),f=!0),m.oldHash&&m.oldHash!==se&&c.push(m.oldHash);let l=null;f&&(l=await jc(this.local,a,c)??null);let d=await yu(this.url,i,l,o,this.auth,this.fetchFn,this.onProgress);return{updates:[...s.map(m=>{let h=d.refResults.find(w=>w.name===m.name),p=h?.ok??d.unpackOk,g=h?.error??(!p&&d.unpackError?`unpack failed: ${d.unpackError}`:void 0);return{...m,ok:p,error:g}}),...r]}}};function Ru(e){return!!e.oldHash&&e.oldHash!==se&&e.newHash!==se}function Cu(e){return e.name.startsWith("refs/tags/")&&Ru(e)}async function jc(e,t,n,r,s){let o=await bs(e,t,n,r,s);if(o.count===0)return;let i=await ys(o),c=Ii(i).map(l=>({hash:l.hash,type:l.type,content:l.content,delta:l.delta,deltaBaseHash:l.deltaBase})),{data:f}=await Go(c);return f}function hb(e){if(!Ai(e))return{url:e};try{let t=new URL(e);if(!t.username&&!t.password)return{url:e};let n={type:"basic",username:decodeURIComponent(t.username),password:decodeURIComponent(t.password)};return t.username="",t.password="",{url:t.href,embeddedAuth:n}}catch{return{url:e}}}function qr(e,t){let n=hb(e);if(n.embeddedAuth&&t)try{t.set(new URL(n.url).origin,n.embeddedAuth)}catch{}return n}async function pb(e,t){let r=(await be(e))[`remote "${t}"`];return r?.url?{name:t,url:r.url,fetchRefspec:r.fetch??"+refs/heads/*:refs/remotes/origin/*"}:null}function gb(e){return e.length===0?null:{name:e,url:e,fetchRefspec:"+refs/heads/*:refs/remotes/origin/*",anonymous:!0}}function Ai(e){return e.startsWith("http://")||e.startsWith("https://")}function xu(e){return e.startsWith("ssh://")||e.startsWith("git@")||e.startsWith("git+ssh://")}function Pu(e,t){if(t===void 0)return null;if(t===!1)return"network access is disabled";if(!t.allowed)return null;if(t.allowed.length===0)return"network access is disabled";let n;try{n=new URL(e).hostname}catch{return`network policy: access to '${e}' is not allowed`}for(let r of t.allowed)if(Ai(r)){if(e===r||e.startsWith(r))return null}else if(n===r)return null;return`network policy: access to '${e}' is not allowed`}function wb(e){let t=e.get("GIT_HTTP_BEARER_TOKEN");if(t)return{type:"bearer",token:t};let n=e.get("GIT_HTTP_USER"),r=e.get("GIT_HTTP_PASSWORD");if(n&&r)return{type:"basic",username:n,password:r}}async function $u(e,t,n){if(e.credentialProvider){let s=await e.credentialProvider(t);if(s)return s}let r=wb(n);if(r)return r;if(e.credentialCache)try{return e.credentialCache.get(new URL(t).origin)}catch{return}}async function Ou(e,t,n,r){let s=qr(t,e.credentialCache).url;if(Ai(s)){let o=Pu(s,e.networkPolicy);if(o)throw new Error(o);let i=await $u(e,s,n);return new ho(e,s,i,e.fetchFn,e.onProgress)}if(!r&&e.resolveRemote&&(r=await e.resolveRemote(s)??void 0),!r)throw xu(s)?new Error(`SSH transport is not supported. Use an HTTPS URL instead of '${s}'.`):new Error(`'${s}' does not appear to be a git repository`);return new mo(e,r)}async function Hi(e,t,n){let r=await pb(e,t)??gb(t);if(!r)return null;let s=qr(r.url,e.credentialCache).url;if(Ai(s)){let i=Pu(s,e.networkPolicy);if(i)throw new Error(i);let a=n?await $u(e,s,n):void 0;return{transport:new ho(e,s,a,e.fetchFn,e.onProgress),config:{...r,url:s}}}let o=(e.resolveRemote?await e.resolveRemote(s):null)??await Un(e.fs,s);if(!o){if(xu(s))throw new Error(`SSH transport is not supported. Use an HTTPS URL instead of '${s}'.`);return null}return{transport:new mo(e,o),config:{...r,url:s}}}Te();ot();ke();function Su(e,t){e.command("clone",{description:"Clone a repository into a new directory",args:[B.string().name("repository").describe("Repository to clone"),B.string().name("directory").describe("Target directory").optional()],options:{bare:S().describe("Create a bare clone"),branch:K.string().alias("b").describe("Checkout this branch instead of HEAD"),depth:K.number().describe("Create a shallow clone with history truncated to N commits"),singleBranch:S().describe("Clone only the history of the specified or default branch"),noSingleBranch:S().describe("Clone all branches even with --depth"),noTags:S().describe("Don't clone any tags"),noCheckout:S().alias("n").describe("Don't create a checkout"),quiet:ce("be more quiet")},handler:async(n,r)=>{let s=n.repository;if(!s)return v("You must specify a repository to clone.");let o=s.startsWith("http://")||s.startsWith("https://"),i=n.branch,a=!!n.quiet,c=null,f=s;if(o)f=qr(s,t?.credentialCache).url;else if(t?.resolveRemote&&(c=await t.resolveRemote(s)),c||(f=Je(r.cwd,s),c=await Un(r.fs,f)),!c)return v(`repository '${s}' does not exist`);let l=n.directory;if(!l){let U;o||s.includes("://")?U=f.split("/").pop()??f:U=Pt(f),U.endsWith(".git")&&(U=U.slice(0,-4)),l=U}let d=Je(r.cwd,l),u=await t?.hooks?.preClone?.({repository:f,targetPath:d,bare:n.bare,branch:i??null});if(pe(u))return N(u.message??"");if(await r.fs.exists(d))try{if((await r.fs.readdir(d)).length>0)return v(`destination path '${l}' already exists and is not an empty directory.`)}catch{return v(`destination path '${l}' already exists and is not an empty directory.`)}await r.fs.mkdir(d,{recursive:!0});let{ctx:m}=await Wo(r.fs,d,{bare:n.bare}),h=t?{...m,...t}:m,p=n.depth,g=n.singleBranch||p!==void 0&&!n.noSingleBranch,w=n.noTags||g,b=n.noCheckout,y=await be(h),C;try{C=await Ou(h,f,r.env,c??void 0)}catch(U){let G=U instanceof Error?U.message:"";return G.startsWith("network")?v(G):v(`repository '${s}' does not exist`)}let x=await C.advertiseRefs();if(x.length===0)return y['remote "origin"']={url:f,fetch:"+refs/heads/*:refs/remotes/origin/*"},await et(h,y),await t?.hooks?.postClone?.({repo:h,repository:f,targetPath:d,bare:n.bare,branch:i??null}),{stdout:"",stderr:`${a?"":`Cloning into '${l}'... + `}warning: You appear to have cloned an empty repository. +-`,exitCode:0};let y=null,P=null;if(i){let U=x.find(G=>G.name===`refs/heads/${i}`);if(!U)return v(`Remote branch '${i}' not found in upstream origin`);y=i,P=U.hash}else{let U=C.headTarget;if(U?.startsWith("refs/heads/")&&x.some(G=>G.name===U)&&(y=U.slice(11),P=x.find(G=>G.name===U)?.hash??null),!y){let G=x.find(N=>N.name==="HEAD");if(G){let N=x.find(A=>A.name.startsWith("refs/heads/")&&A.hash===G.hash);N&&(y=N.name.slice(11),P=N.hash)}}if(!y){let G=x.find(N=>N.name.startsWith("refs/heads/"));G&&(y=G.name.slice(11),P=G.hash)}}let k={url:f,fetch:g&&y?`+refs/heads/${y}:refs/remotes/origin/${y}`:"+refs/heads/*:refs/remotes/origin/*"};w&&(k.tagOpt="--no-tags"),R['remote "origin"']=k;let E=[],O=new Set;for(let U of x)if(U.name!=="HEAD"){if(U.name.startsWith("refs/heads/")){if(g&&y&&U.name!==`refs/heads/${y}`)continue}else if(U.name.startsWith("refs/tags/")){if(w)continue}else continue;O.has(U.hash)||(O.add(U.hash),E.push(U.hash))}let $=p!==void 0&&p>0?{depth:p}:void 0;if(E.length>0){let U=await C.fetch(E,[],$);U.shallowUpdates&&await ms(h,U.shallowUpdates)}let T=`clone: from ${f}`;for(let U of x)if(U.name!=="HEAD"){if(U.name.startsWith("refs/heads/")){if(g&&y&&U.name!==`refs/heads/${y}`)continue;let G=`refs/remotes/origin/${U.name.slice(11)}`;await Q(h,G,U.hash),await ee(h,r.env,G,null,U.hash,T)}U.name.startsWith("refs/tags/")&&(w||await Q(h,U.name,U.hash))}if(n.bare)return await et(h,R),y&&await ot(h,"HEAD",`refs/heads/${y}`),await t?.hooks?.postClone?.({repo:h,repository:f,targetPath:d,bare:n.bare,branch:y}),{stdout:"",stderr:a?"":`Cloning into bare repository '${l}'... +-`,exitCode:0};if(await es(h,"origin",x,C.headTarget),y&&P&&(await Q(h,`refs/heads/${y}`,P),await ot(h,"HEAD",`refs/heads/${y}`),await ee(h,r.env,`refs/heads/${y}`,null,P,T,!0),R[`branch "${y}"`]={remote:"origin",merge:`refs/heads/${y}`},!b)){let U=await M(h,P);await jl(h,U.tree);let G=await ze(h,U.tree),N=Vr(G.map(A=>({path:A.path,mode:parseInt(A.mode,8),hash:A.hash,stage:0,stat:Fe()})));N=await rr(h,N),await ie(h,N)}await et(h,R);let j={stdout:"",stderr:a?"":`Cloning into '${l}'... +-`,exitCode:0};return await t?.hooks?.postClone?.({repo:h,repository:f,targetPath:d,bare:n.bare,branch:y}),j}})}ne();ae();ve();ye();Qt();De();st();Us();Jr();Ee();function yu(e,t){e.command("describe",{description:"Give an object a human readable name based on an available ref",args:[W.string().name("committish").describe("Commit to describe").optional()],options:{tags:S().describe("Use any tag, not just annotated"),always:S().describe("Show abbreviated hash as fallback"),long:S().describe("Always output long format"),abbrev:K.number().describe("Abbreviation length"),dirty:K.string().describe("Append dirty marker if worktree has changes"),match:K.string().describe("Only consider tags matching glob"),exclude:K.string().describe("Exclude tags matching glob"),exactMatch:S().alias("exact-match").describe("Only output exact matches"),firstParent:S().alias("first-parent").describe("Only follow first parent"),candidates:K.number().describe("Consider N most recent tags")},transformArgs(n){return n.map(r=>r==="--dirty"?"--dirty=-dirty":r)},handler:async(n,r)=>{let o=await q(r.fs,r.cwd,t);if(D(o))return o;let s=o,i=n.committish,a=n.tags,c=n.always,f=n.long,l=n.abbrev??7,d=n.dirty,u=n.match,m=n.exclude,h=n.exactMatch,p=n.firstParent,g;if(i){let k=await Le(s,i);if(!k)return v(`Not a valid object name ${i}`);try{g=await Se(s,k)}catch{return v(`Not a valid object name ${i}`)}}else g=await Z(s);if(!g)return v("your current branch does not have any commits yet");let w=await Qw(s,a,u,m),b=new Map,R=!1;for(let k of w){k.timestamp===0&&(R=!0);let E=b.get(k.commitHash);E||(E=[],b.set(k.commitHash,E)),E.push(k)}let C=await Jw(s,g,b,p,h?0:void 0);if(!C){if(h)return v(`no tag exactly matches '${g}'`);if(c){let E=g.slice(0,Math.max(l,1));return d&&await bu(s)&&(E+=d),{stdout:E+` +-`,stderr:"",exitCode:0}}let k;return!a&&R?k=`fatal: No annotated tags can describe '${g}'. ++`,exitCode:0};let k=null,P=null;if(i){let U=x.find(G=>G.name===`refs/heads/${i}`);if(!U)return v(`Remote branch '${i}' not found in upstream origin`);k=i,P=U.hash}else{let U=C.headTarget;if(U?.startsWith("refs/heads/")&&x.some(G=>G.name===U)&&(k=U.slice(11),P=x.find(G=>G.name===U)?.hash??null),!k){let G=x.find(L=>L.name==="HEAD");if(G){let L=x.find(A=>A.name.startsWith("refs/heads/")&&A.hash===G.hash);L&&(k=L.name.slice(11),P=L.hash)}}if(!k){let G=x.find(L=>L.name.startsWith("refs/heads/"));G&&(k=G.name.slice(11),P=G.hash)}}let E={url:f,fetch:g&&k?`+refs/heads/${k}:refs/remotes/origin/${k}`:"+refs/heads/*:refs/remotes/origin/*"};w&&(E.tagOpt="--no-tags"),y['remote "origin"']=E;let R=[],O=new Set;for(let U of x)if(U.name!=="HEAD"){if(U.name.startsWith("refs/heads/")){if(g&&k&&U.name!==`refs/heads/${k}`)continue}else if(U.name.startsWith("refs/tags/")){if(w)continue}else continue;O.has(U.hash)||(O.add(U.hash),R.push(U.hash))}let $=p!==void 0&&p>0?{depth:p}:void 0;if(R.length>0){let U=await C.fetch(R,[],$);U.shallowUpdates&&await ws(h,U.shallowUpdates)}let T=`clone: from ${f}`;for(let U of x)if(U.name!=="HEAD"){if(U.name.startsWith("refs/heads/")){if(g&&k&&U.name!==`refs/heads/${k}`)continue;let G=`refs/remotes/origin/${U.name.slice(11)}`;await Q(h,G,U.hash),await ee(h,r.env,G,null,U.hash,T)}U.name.startsWith("refs/tags/")&&(w||await Q(h,U.name,U.hash))}if(n.bare)return await et(h,y),k&&await ct(h,"HEAD",`refs/heads/${k}`),await t?.hooks?.postClone?.({repo:h,repository:f,targetPath:d,bare:n.bare,branch:k}),{stdout:"",stderr:a?"":`Cloning into bare repository '${l}'... ++`,exitCode:0};if(await rs(h,"origin",x,C.headTarget),k&&P&&(await Q(h,`refs/heads/${k}`,P),await ct(h,"HEAD",`refs/heads/${k}`),await ee(h,r.env,`refs/heads/${k}`,null,P,T,!0),y[`branch "${k}"`]={remote:"origin",merge:`refs/heads/${k}`},!b)){let U=await M(h,P);await zl(h,U.tree);let G=await Ke(h,U.tree),L=Qr(G.map(A=>({path:A.path,mode:parseInt(A.mode,8),hash:A.hash,stage:0,stat:Ge()})));L=await rr(h,L),await oe(h,L)}await et(h,y);let j={stdout:"",stderr:a?"":`Cloning into '${l}'... ++`,exitCode:0};return await t?.hooks?.postClone?.({repo:h,repository:f,targetPath:d,bare:n.bare,branch:k}),j}})}te();ie();Se();ye();Ft();Te();ot();Ks();Ar();ke();function Iu(e,t){e.command("describe",{description:"Give an object a human readable name based on an available ref",args:[B.string().name("committish").describe("Commit to describe").optional()],options:{tags:S().describe("Use any tag, not just annotated"),always:S().describe("Show abbreviated hash as fallback"),long:S().describe("Always output long format"),abbrev:K.number().describe("Abbreviation length"),dirty:K.string().describe("Append dirty marker if worktree has changes"),match:K.string().describe("Only consider tags matching glob"),exclude:K.string().describe("Exclude tags matching glob"),exactMatch:S().alias("exact-match").describe("Only output exact matches"),firstParent:S().alias("first-parent").describe("Only follow first parent"),candidates:K.number().describe("Consider N most recent tags")},transformArgs(n){return n.map(r=>r==="--dirty"?"--dirty=-dirty":r)},handler:async(n,r)=>{let s=await W(r.fs,r.cwd,t);if(D(s))return s;let o=s,i=n.committish,a=n.tags,c=n.always,f=n.long,l=n.abbrev??7,d=n.dirty,u=n.match,m=n.exclude,h=n.exactMatch,p=n.firstParent,g;if(i){let E=await Ie(o,i);if(!E)return v(`Not a valid object name ${i}`);try{g=await Oe(o,E)}catch{return v(`Not a valid object name ${i}`)}}else g=await Z(o);if(!g)return v("your current branch does not have any commits yet");let w=await bb(o,a,u,m),b=new Map,y=!1;for(let E of w){E.timestamp===0&&(y=!0);let R=b.get(E.commitHash);R||(R=[],b.set(E.commitHash,R)),R.push(E)}let C=await yb(o,g,b,p,h?0:void 0);if(!C){if(h)return v(`no tag exactly matches '${g}'`);if(c){let R=g.slice(0,Math.max(l,1));return d&&await vu(o)&&(R+=d),{stdout:R+` ++`,stderr:"",exitCode:0}}let E;return!a&&y?E=`fatal: No annotated tags can describe '${g}'. + However, there were unannotated tags: try --tags. +-`:w.length===0&&!a&&(await $e(s,"refs/tags")).length>0?k=`fatal: No annotated tags can describe '${g}'. ++`:w.length===0&&!a&&(await $e(o,"refs/tags")).length>0?E=`fatal: No annotated tags can describe '${g}'. + However, there were unannotated tags: try --tags. +-`:k=`fatal: No names found, cannot describe anything. +-`,{stdout:"",stderr:k,exitCode:128}}let{tag:x,depth:y}=C,P;if(y===0&&!f)P=x.name;else if(l===0)P=x.name;else{let k=g.slice(0,Math.max(l,1));P=`${x.name}-${y}-g${k}`}return d&&await bu(s)&&(P+=d),{stdout:P+` +-`,stderr:"",exitCode:0}}})}async function Qw(e,t,n,r){let o=await $e(e,"refs/tags"),s=[];for(let i of o){let a=i.name.replace("refs/tags/","");if(n&&xn(n,a,0)!==0||r&&xn(r,a,0)===0)continue;let c=await be(e,i.hash);if(c.type==="tag"){let f=mn(c.content),l;try{l=await Se(e,f.object)}catch{continue}s.push({name:a,commitHash:l,timestamp:f.tagger.timestamp})}else c.type==="commit"&&t&&s.push({name:a,commitHash:i.hash,timestamp:0})}return s}async function Jw(e,t,n,r,o){let s=new Set,i=[{hash:t,depth:0}];for(;i.length>0;){let{hash:a,depth:c}=i.shift();if(s.has(a)||(s.add(a),o!==void 0&&c>o))continue;let f=n.get(a);if(f&&f.length>0)return{tag:eb(f),depth:c};let l;try{l=await M(e,a)}catch{continue}if(r)l.parents.length>0&&!s.has(l.parents[0])&&i.push({hash:l.parents[0],depth:c+1});else for(let d of l.parents)s.has(d)||i.push({hash:d,depth:c+1})}return null}function eb(e){return e.sort((t,n)=>n.timestamp!==t.timestamp?n.timestamp-t.timestamp:t.name.localeCompare(n.name))[0]}async function bu(e){if(tt(e))return!1;let n=await Z(e);if(!n)return!1;let r=await M(e,n),o=await de(e,r.tree),s=await X(e);return Bn(s,o)?!0:(await dt(e,s,{includeUntracked:!1,stopAfterFirst:!0})).length>0}ne();ve();ae();Mn();ge();Ve();ye();De();st();Ee();function tb(e){let t=e;for(let r=0;r255)return t;let n=Uint8Array.from(t,r=>r.charCodeAt(0));try{return new TextDecoder("utf-8",{fatal:!0}).decode(n)}catch{return t}}function ku(e,t){e.command("commit",{description:"Record changes to the repository",options:{message:K.string().alias("m").repeatable().describe("Commit message"),file:K.string().alias("F").describe("Read commit message from file ('-' for stdin)"),allowEmpty:S().describe("Allow creating an empty commit"),amend:S().describe("Amend the previous commit"),noEdit:S().describe("Use the previous commit message without editing"),all:S().alias("a").describe("Auto-stage modified and deleted tracked files"),quiet:ce("suppress summary after successful commit")},handler:async(n,r)=>{let o=n.message;if(o.length>0&&n.file!==void 0)return v("options '-m' and '-F' cannot be used together");let s=await q(r.fs,r.cwd,t);if(D(s))return s;let i=s,a=await X(i);if(n.all){let xe=tt(i);if(xe)return xe;let Xe=await dt(i,a,{includeUntracked:!1});for(let Ze of Xe)Ze.status==="modified"?a=(await $n(i,a,Ze.path)).index:Ze.status==="deleted"&&(a=yt(a,Ze.path));let Ct=new Set(qe(a).map(Ze=>Ze.path)),an=new Set(a.entries.filter(Ze=>Ze.stage>0&&!Ct.has(Ze.path)).map(Ze=>Ze.path));for(let Ze of an){let Zn=I(i.workTree,Ze);await r.fs.exists(Zn)?a=(await $n(i,a,Ze)).index:a=yt(a,Ze)}}let c=await z(i,"MERGE_HEAD"),f=await z(i,"CHERRY_PICK_HEAD"),l=await z(i,"REVERT_HEAD"),u=await wn(i)?await z(i,"REBASE_HEAD"):null,m=n.amend,h=await Z(i);if(m){if(!h)return v("You have nothing yet to amend.");if(c)return v("You are in the middle of a merge -- cannot amend.");if(f)return v("You are in the middle of a cherry-pick -- cannot amend.")}let p=ar(a);if(p)return p;let g=m&&h?await M(i,h):null,w=o.length>0?o.join(` ++`:E=`fatal: No names found, cannot describe anything. ++`,{stdout:"",stderr:E,exitCode:128}}let{tag:x,depth:k}=C,P;if(k===0&&!f)P=x.name;else if(l===0)P=x.name;else{let E=g.slice(0,Math.max(l,1));P=`${x.name}-${k}-g${E}`}return d&&await vu(o)&&(P+=d),{stdout:P+` ++`,stderr:"",exitCode:0}}})}async function bb(e,t,n,r){let s=await $e(e,"refs/tags"),o=[];for(let i of s){let a=i.name.replace("refs/tags/","");if(n&&Sn(n,a,0)!==0||r&&Sn(r,a,0)===0)continue;let c=await me(e,i.hash);if(c.type==="tag"){let f=Lt(c.content),l;try{l=await Oe(e,f.object)}catch{continue}o.push({name:a,commitHash:l,timestamp:f.tagger.timestamp})}else c.type==="commit"&&t&&o.push({name:a,commitHash:i.hash,timestamp:0})}return o}async function yb(e,t,n,r,s){let o=new Set,i=[{hash:t,depth:0}];for(;i.length>0;){let{hash:a,depth:c}=i.shift();if(o.has(a)||(o.add(a),s!==void 0&&c>s))continue;let f=n.get(a);if(f&&f.length>0)return{tag:kb(f),depth:c};let l;try{l=await M(e,a)}catch{continue}if(r)l.parents.length>0&&!o.has(l.parents[0])&&i.push({hash:l.parents[0],depth:c+1});else for(let d of l.parents)o.has(d)||i.push({hash:d,depth:c+1})}return null}function kb(e){return e.sort((t,n)=>n.timestamp!==t.timestamp?n.timestamp-t.timestamp:t.name.localeCompare(n.name))[0]}async function vu(e){if(tt(e))return!1;let n=await Z(e);if(!n)return!1;let r=await M(e,n),s=await de(e,r.tree),o=await X(e);return Wn(o,s)?!0:(await pt(e,o,{includeUntracked:!1,stopAfterFirst:!0})).length>0}te();Se();ie();On();ge();Xe();ye();Te();ot();ke();function Eb(e){let t=e;for(let r=0;r255)return t;let n=Uint8Array.from(t,r=>r.charCodeAt(0));try{return new TextDecoder("utf-8",{fatal:!0}).decode(n)}catch{return t}}function Tu(e,t){e.command("commit",{description:"Record changes to the repository",options:{message:K.string().alias("m").repeatable().describe("Commit message"),file:K.string().alias("F").describe("Read commit message from file ('-' for stdin)"),allowEmpty:S().describe("Allow creating an empty commit"),amend:S().describe("Amend the previous commit"),noEdit:S().describe("Use the previous commit message without editing"),all:S().alias("a").describe("Auto-stage modified and deleted tracked files"),quiet:ce("suppress summary after successful commit")},handler:async(n,r)=>{let s=n.message;if(s.length>0&&n.file!==void 0)return v("options '-m' and '-F' cannot be used together");let o=await W(r.fs,r.cwd,t);if(D(o))return o;let i=o,a=await X(i);if(n.all){let J=tt(i);if(J)return J;let je=await pt(i,a,{includeUntracked:!1});for(let _e of je)_e.status==="modified"?a=(await In(i,a,_e.path)).index:_e.status==="deleted"&&(a=Rt(a,_e.path));let at=new Set(ze(a).map(_e=>_e.path)),vt=new Set(a.entries.filter(_e=>_e.stage>0&&!at.has(_e.path)).map(_e=>_e.path));for(let _e of vt){let Zt=I(i.workTree,_e);await r.fs.exists(Zt)?a=(await In(i,a,_e)).index:a=Rt(a,_e)}}let c=await z(i,"MERGE_HEAD"),f=await z(i,"CHERRY_PICK_HEAD"),l=await z(i,"REVERT_HEAD"),u=await En(i)?await z(i,"REBASE_HEAD"):null,m=n.amend,h=await Z(i);if(m){if(!h)return v("You have nothing yet to amend.");if(c)return v("You are in the middle of a merge -- cannot amend.");if(f)return v("You are in the middle of a cherry-pick -- cannot amend.")}let p=ar(a);if(p)return p;let g=m&&h?await M(i,h):null,w=s.length>0?s.join(` + +-`):void 0;if(w!==void 0&&(w=Ft(w),!w))return{stdout:`Aborting commit due to empty commit message. +-`,stderr:"",exitCode:1};if(!w&&n.file!==void 0){if(n.file==="-")w=tb(r.stdin);else{let xe=n.file.startsWith("/")?n.file:I(r.cwd,n.file);if(!await r.fs.exists(xe))return v(`could not read log file '${n.file}': No such file or directory`);let Xe=await r.fs.readFile(xe);w=typeof Xe=="string"?Xe:new TextDecoder().decode(Xe)}if(w=Ft(w),!w)return{stdout:`Aborting commit due to empty commit message. +-`,stderr:"",exitCode:1}}if(!w&&m&&g&&(w=g.message),!w&&(c||f||l||u)){let xe=await Ae(i,"SQUASH_MSG");if(xe)w=Ft(xe);else{let Xe=await Ae(i,"MERGE_MSG");Xe!==null&&(w=Ft(Xe))}}if(!w)return F("error: must provide a commit message with -m or -F");let b=qe(a),R=await Ye(i,b),C=await t?.hooks?.preCommit?.({repo:i,index:a,treeHash:R});if(he(C))return F(C.message??"");let x=n.allowEmpty,y=null;if(m&&g){let xe=g.parents[0];xe?y=(await M(i,xe)).tree:y=await sr("tree",new Uint8Array(0))}else h&&(y=(await M(i,h)).tree);let P=m&&g&&g.parents.length>1;if(!x&&!c&&!P){if(!h&&!m&&b.length===0)return{stdout:await pt(i,{fromCommit:!0,index:a}),stderr:"",exitCode:1};if(y!==null&&y===R){if(m){let xe=g?.parents[0]??null;return{stdout:`${await pt(i,{fromCommit:!0,compareHash:xe,noWarn:!0,index:a})}No changes ++`):void 0;if(w!==void 0&&(w=_t(w),!w))return{stdout:`Aborting commit due to empty commit message. ++`,stderr:"",exitCode:1};if(!w&&n.file!==void 0){if(n.file==="-")w=Eb(r.stdin);else{let J=n.file.startsWith("/")?n.file:I(r.cwd,n.file);if(!await r.fs.exists(J))return v(`could not read log file '${n.file}': No such file or directory`);let je=await r.fs.readFile(J);w=typeof je=="string"?je:new TextDecoder().decode(je)}if(w=_t(w),!w)return{stdout:`Aborting commit due to empty commit message. ++`,stderr:"",exitCode:1}}if(!w&&m&&g&&(w=g.message),!w&&(c||f||l||u)){let J=await He(i,"SQUASH_MSG");if(J)w=_t(J);else{let je=await He(i,"MERGE_MSG");je!==null&&(w=_t(je))}}if(!w)return N("error: must provide a commit message with -m or -F");let b=ze(a),y=await Ze(i,b),C=await t?.hooks?.preCommit?.({repo:i,index:a,treeHash:y});if(pe(C))return N(C.message??"");let x=n.allowEmpty,k=null;if(m&&g){let J=g.parents[0];J?k=(await M(i,J)).tree:k=await sr("tree",new Uint8Array(0))}else h&&(k=(await M(i,h)).tree);let P=m&&g&&g.parents.length>1;if(!x&&!c&&!P){if(!h&&!m&&b.length===0)return{stdout:await yt(i,{fromCommit:!0,index:a}),stderr:"",exitCode:1};if(k!==null&&k===y){if(m){let J=g?.parents[0]??null;return{stdout:`${await yt(i,{fromCommit:!0,compareHash:J,noWarn:!0,index:a})}No changes + `,stderr:`You asked to amend the most recent commit, but doing so would make + it empty. You can repeat your command with --allow-empty, or you can + remove the commit entirely with "git reset HEAD^". +-`,exitCode:1}}return f?{stdout:await pt(i,{fromCommit:!0,index:a}),stderr:`The previous cherry-pick is now empty, possibly due to conflict resolution. ++`,exitCode:1}}return f?{stdout:await yt(i,{fromCommit:!0,index:a}),stderr:`The previous cherry-pick is now empty, possibly due to conflict resolution. + If you wish to commit it anyway, use: + + git commit --allow-empty + + Otherwise, please use 'git cherry-pick --skip' +-`,exitCode:1}:{stdout:await pt(i,{fromCommit:!0,index:a}),stderr:"",exitCode:1}}}let k=await Sn(i,r.env);if(D(k))return k;let E=await ct(i,r.env);if(D(E))return E;m&&g&&(k.name=g.author.name,k.email=g.author.email,k.timestamp=g.author.timestamp,k.timezone=g.author.timezone),f&&(k=(await M(i,f)).author);let O=Nt(w),$={repo:i,message:O},T=await t?.hooks?.commitMsg?.($);if(he(T))return F(T.message??"");O=$.message;let j;m&&g?j=[...g.parents]:(j=h?[h]:[],c&&j.push(c));let U=Cn({type:"commit",tree:R,parents:j,author:k,committer:E,message:O}),G=await Me(i,"commit",U);await ie(i,a);let N=await te(i);N&&N.type==="symbolic"?await Q(i,N.target,G):await Q(i,"HEAD",G);let A=me(O),H;m?H="commit (amend)":c?H="commit (merge)":f?H="commit (cherry-pick)":h?H="commit":H="commit (initial)";let B=`${H}: ${A}`,L=N?.type==="symbolic"?N.target:"HEAD";if(await ee(i,r.env,L,h,G,B,N?.type==="symbolic"),c&&await qs(i),f&&await gn(i),l&&await tn(i),u&&await Ce(i,"MERGE_MSG"),await Ce(i,"SQUASH_MSG"),await t?.hooks?.postCommit?.({repo:i,hash:G,message:O,branch:N?.type==="symbolic"?Ie(N.target):null,parents:j,author:k}),n.quiet)return{stdout:"",stderr:"",exitCode:0};let _=N?.type==="symbolic"?N.target:null,V=_?Ie(_):"detached HEAD",Y;if(m&&g){let xe=g.parents[0];Y=xe?(await M(i,xe)).tree:null}else Y=h?(await M(i,h)).tree:null;let fe=k.timestamp!==E.timestamp||k.timezone!==E.timezone,J=j.length>1,re=await zn(i,Y,R,k,E,fe,J);return{stdout:`${await pn(i,V,G,w,j.length===0&&!m)} +-${re}`,stderr:"",exitCode:0}}})}ne();Be();ge();Ee();function Yn(e){let t=e.split(".");return t.length===2||t.length===3}function nb(e){let t=[];for(let[n,r]of Object.entries(e)){let o=n.match(/^(\S+)\s+"(.+)"$/);for(let[s,i]of Object.entries(r)){let a=o?`${o[1]}.${o[2]}.${s}`:`${n}.${s}`;for(let c of i)t.push(`${a}=${c}`)}}return t}function xu(e,t){e.command("config",{description:"Get and set repository options",args:[W.string().name("positionals").variadic().optional()],options:{list:S().alias("l").describe("List all config entries"),get:S().describe("Get the value for a given key"),unset:S().describe("Remove a config key"),"get-all":S().describe("Get all values for a multi-valued key"),add:S().describe("Add a new line without altering existing values")},handler:async(n,r)=>{let o=await q(r.fs,r.cwd,t);if(D(o))return o;let s=o,i=n.positionals,a=i[0];if(n.list)return Cu(s);if(n.get){let f=a;return f?Yn(f)?$c(s,f):F(`error: invalid key: ${f}`,2):F("error: missing key",2)}if(n["get-all"]){let f=a;return f?Yn(f)?Eu(s,f):F(`error: invalid key: ${f}`,2):F("error: missing key",2)}if(n.add){let f=a,l=i[1];return!f||l===void 0?F("error: missing key and/or value",2):Yn(f)?(await wf(s,f,l),{stdout:"",stderr:"",exitCode:0}):F(`error: invalid key: ${f}`,2)}if(n.unset){let f=a;return f?Yn(f)?Ru(s,f):F(`error: invalid key: ${f}`,2):F("error: missing key",2)}if(a==="list")return Cu(s);if(a==="get"){let f=i[1];return f?Yn(f)?$c(s,f):F(`error: invalid key: ${f}`,2):F("error: missing key",2)}if(a==="get-all"){let f=i[1];return f?Yn(f)?Eu(s,f):F(`error: invalid key: ${f}`,2):F("error: missing key",2)}if(a==="set"){let f=i[1],l=i[2];return!f||l===void 0?F("error: missing key and/or value",2):Yn(f)?(await aa(s,f,l),{stdout:"",stderr:"",exitCode:0}):F(`error: invalid key: ${f}`,2)}if(a==="unset"){let f=i[1];return f?Yn(f)?Ru(s,f):F(`error: invalid key: ${f}`,2):F("error: missing key",2)}if(!a)return F("usage: git config [get|set|unset|list] [] []",2);if(!Yn(a))return F(`error: invalid key: ${a}`,2);let c=i[1];return c!==void 0?(await aa(s,a,c),{stdout:"",stderr:"",exitCode:0}):$c(s,a)}})}async function $c(e,t){let n=await Re(e,t);return n===void 0?F(""):{stdout:`${n} +-`,stderr:"",exitCode:0}}async function Eu(e,t){let n=await gf(e,t);return n.length===0?F(""):{stdout:`${n.join(` ++`,exitCode:1}:{stdout:await yt(i,{fromCommit:!0,index:a}),stderr:"",exitCode:1}}}let E=await An(i,r.env);if(D(E))return E;let R=await dt(i,r.env);if(D(R))return R;m&&g&&(E.name=g.author.name,E.email=g.author.email,E.timestamp=g.author.timestamp,E.timezone=g.author.timezone),f&&(E=(await M(i,f)).author);let O=Bt(w),$={repo:i,message:O},T=await t?.hooks?.commitMsg?.($);if(pe(T))return N(T.message??"");O=$.message;let j;m&&g?j=[...g.parents]:(j=h?[h]:[],c&&j.push(c));let U=$n({type:"commit",tree:y,parents:j,author:E,committer:R,message:O}),G=await De(i,"commit",U);await oe(i,a);let L=await ne(i);L&&L.type==="symbolic"?await Q(i,L.target,G):await Q(i,"HEAD",G);let A=he(O),H;m?H="commit (amend)":c?H="commit (merge)":f?H="commit (cherry-pick)":h?H="commit":H="commit (initial)";let q=`${H}: ${A}`,F=L?.type==="symbolic"?L.target:"HEAD";if(await ee(i,r.env,F,h,G,q,L?.type==="symbolic"),c&&await Zs(i),f&&await kn(i),l&&await on(i),u&&await xe(i,"MERGE_MSG"),await xe(i,"SQUASH_MSG"),await t?.hooks?.postCommit?.({repo:i,hash:G,message:O,branch:L?.type==="symbolic"?ve(L.target):null,parents:j,author:E}),n.quiet)return{stdout:"",stderr:"",exitCode:0};let _=L?.type==="symbolic"?L.target:null,Y=_?ve(_):"detached HEAD",V;if(m&&g){let J=g.parents[0];V=J?(await M(i,J)).tree:null}else V=h?(await M(i,h)).tree:null;let ue=E.timestamp!==R.timestamp||E.timezone!==R.timezone,Ce=j.length>1,Qe=await Kn(i,V,y,E,R,ue,Ce);return{stdout:`${await yn(i,Y,G,w,j.length===0&&!m)} ++${Qe}`,stderr:"",exitCode:0}}})}te();We();ge();ke();function Zn(e){let t=e.split(".");return t.length===2||t.length===3}function Rb(e){let t=[];for(let[n,r]of Object.entries(e)){let s=n.match(/^(\S+)\s+"(.+)"$/);for(let[o,i]of Object.entries(r)){let a=s?`${s[1]}.${s[2]}.${o}`:`${n}.${o}`;for(let c of i)t.push(`${a}=${c}`)}}return t}function Mu(e,t){e.command("config",{description:"Get and set repository options",args:[B.string().name("positionals").variadic().optional()],options:{list:S().alias("l").describe("List all config entries"),get:S().describe("Get the value for a given key"),unset:S().describe("Remove a config key"),"get-all":S().describe("Get all values for a multi-valued key"),add:S().describe("Add a new line without altering existing values")},handler:async(n,r)=>{let s=await W(r.fs,r.cwd,t);if(D(s))return s;let o=s,i=n.positionals,a=i[0];if(n.list)return Du(o);if(n.get){let f=a;return f?Zn(f)?Lc(o,f):N(`error: invalid key: ${f}`,2):N("error: missing key",2)}if(n["get-all"]){let f=a;return f?Zn(f)?Au(o,f):N(`error: invalid key: ${f}`,2):N("error: missing key",2)}if(n.add){let f=a,l=i[1];return!f||l===void 0?N("error: missing key and/or value",2):Zn(f)?(await $f(o,f,l),{stdout:"",stderr:"",exitCode:0}):N(`error: invalid key: ${f}`,2)}if(n.unset){let f=a;return f?Zn(f)?Hu(o,f):N(`error: invalid key: ${f}`,2):N("error: missing key",2)}if(a==="list")return Du(o);if(a==="get"){let f=i[1];return f?Zn(f)?Lc(o,f):N(`error: invalid key: ${f}`,2):N("error: missing key",2)}if(a==="get-all"){let f=i[1];return f?Zn(f)?Au(o,f):N(`error: invalid key: ${f}`,2):N("error: missing key",2)}if(a==="set"){let f=i[1],l=i[2];return!f||l===void 0?N("error: missing key and/or value",2):Zn(f)?(await wa(o,f,l),{stdout:"",stderr:"",exitCode:0}):N(`error: invalid key: ${f}`,2)}if(a==="unset"){let f=i[1];return f?Zn(f)?Hu(o,f):N(`error: invalid key: ${f}`,2):N("error: missing key",2)}if(!a)return N("usage: git config [get|set|unset|list] [] []",2);if(!Zn(a))return N(`error: invalid key: ${a}`,2);let c=i[1];return c!==void 0?(await wa(o,a,c),{stdout:"",stderr:"",exitCode:0}):Lc(o,a)}})}async function Lc(e,t){let n=await Re(e,t);return n===void 0?N(""):{stdout:`${n} ++`,stderr:"",exitCode:0}}async function Au(e,t){let n=await Pf(e,t);return n.length===0?N(""):{stdout:`${n.join(` + `)} +-`,stderr:"",exitCode:0}}async function Ru(e,t){return await bf(e,t)?{stdout:"",stderr:"",exitCode:0}:F("",5)}async function Cu(e){let t=I(e.commonDir,"config"),n="";await e.fs.exists(t)&&(n=await e.fs.readFile(t));let r=ra(n),o=nb(r),s=new Set(o.map(c=>c.split("=")[0])),i=e.configOverrides?.defaults;if(i)for(let[c,f]of Object.entries(i))s.has(c)||(o.push(`${c}=${f}`),s.add(c));let a=e.configOverrides?.locked;if(a)for(let[c,f]of Object.entries(a))s.has(c)||o.push(`${c}=${f}`);return{stdout:o.length>0?`${o.join(` ++`,stderr:"",exitCode:0}}async function Hu(e,t){return await Of(e,t)?{stdout:"",stderr:"",exitCode:0}:N("",5)}async function Du(e){let t=I(e.commonDir,"config"),n="";await e.fs.exists(t)&&(n=await e.fs.readFile(t));let r=ma(n),s=Rb(r),o=new Set(s.map(c=>c.split("=")[0])),i=e.configOverrides?.defaults;if(i)for(let[c,f]of Object.entries(i))o.has(c)||(s.push(`${c}=${f}`),o.add(c));let a=e.configOverrides?.locked;if(a)for(let[c,f]of Object.entries(a))o.has(c)||s.push(`${c}=${f}`);return{stdout:s.length>0?`${s.join(` + `)} +-`:"",stderr:"",exitCode:0}}ne();function xi(e){let{path:t,parentHashes:n,parentModes:r,resultHash:o,resultMode:s}=e,i=[];i.push(`diff --cc ${t}`);let a=n.map(b=>b?Lt(b):"0000000"),c=o?Lt(o):"0000000";i.push(`index ${a.join(",")}..${c}`);let f=e.resultContent.length>0,l=n.every(b=>b===null),d=!f&&n.some(b=>b!==null);if(l&&s)i.push(`new file mode ${s}`);else if(d){let b=r.map(R=>R||"000000").join(",");i.push(`deleted file mode ${b}`)}else{let b=r.map(x=>x||"000000"),R=s||"000000";b.some(x=>x!==R)&&i.push(`mode ${b.join(",")}..${R}`)}let u=n.some(b=>b!==null);if(i.push(u?`--- a/${t}`:"--- /dev/null"),i.push(f?`+++ b/${t}`:"+++ /dev/null"),d||l)return`${i.join(` ++`:"",stderr:"",exitCode:0}}te();function Di(e){let{path:t,parentHashes:n,parentModes:r,resultHash:s,resultMode:o}=e,i=[];i.push(`diff --cc ${t}`);let a=n.map(b=>b?Nt(b):"0000000"),c=s?Nt(s):"0000000";i.push(`index ${a.join(",")}..${c}`);let f=e.resultContent.length>0,l=n.every(b=>b===null),d=!f&&n.some(b=>b!==null);if(l&&o)i.push(`new file mode ${o}`);else if(d){let b=r.map(y=>y||"000000").join(",");i.push(`deleted file mode ${b}`)}else{let b=r.map(x=>x||"000000"),y=o||"000000";b.some(x=>x!==y)&&i.push(`mode ${b.join(",")}..${y}`)}let u=n.some(b=>b!==null);if(i.push(u?`--- a/${t}`:"--- /dev/null"),i.push(f?`+++ b/${t}`:"+++ /dev/null"),d||l)return`${i.join(` + `)} +-`;let m=e.parentContents.map(b=>b.length>0?rn(b):[]),h=e.resultContent.length>0?rn(e.resultContent):[],p=m.map(b=>gt(b,h)),g=rb(m,h,p),w=ob(g,m.length,h);if(w.length===0)return"";for(let b of w)i.push(b);return`${i.join(` ++`;let m=e.parentContents.map(b=>b.length>0?cn(b):[]),h=e.resultContent.length>0?cn(e.resultContent):[],p=m.map(b=>kt(b,h)),g=Cb(m,h,p),w=Pb(g,m.length,h);if(w.length===0)return"";for(let b of w)i.push(b);return`${i.join(` + `)} +-`}function rb(e,t,n){let r=e.length,o=n.map(i=>{let a=[],c=new Map,f=0;for(let l of i)if(l.type==="keep")a[l.newLineNo-1]="keep",f=l.newLineNo;else if(l.type==="insert")a[l.newLineNo-1]="insert",f=l.newLineNo;else if(l.type==="delete"){let d=c.get(f)??[];d.push({text:l.line,parentLineNo:l.oldLineNo}),c.set(f,d)}return{resultStatus:a,deletions:c}}),s=[];for(let i=0;i<=t.length;i++){let a=[];for(let f=0;fo.length>0))return[];if(t===2){let o=e[0]??[],s=e[1]??[];if(o.length===0)return s.map(l=>({columns:[" ","-"],text:l.text,resultLineNo:0,parentLineNos:[0,l.parentLineNo]}));if(s.length===0)return o.map(l=>({columns:["-"," "],text:l.text,resultLineNo:0,parentLineNos:[l.parentLineNo,0]}));let i=o.map(l=>l.text),a=s.map(l=>l.text),c=gt(i,a),f=[];for(let l of c)if(l.type==="keep"){let d=o.find(m=>m.text===l.line&&m.parentLineNo===l.oldLineNo),u=s.find(m=>m.text===l.line&&m.parentLineNo===l.newLineNo);f.push({columns:["-","-"],text:l.line,resultLineNo:0,parentLineNos:[d?.parentLineNo??0,u?.parentLineNo??0]})}else if(l.type==="delete"){let d=o.find(u=>u.parentLineNo===l.oldLineNo);f.push({columns:["-"," "],text:l.line,resultLineNo:0,parentLineNos:[d?.parentLineNo??0,0]})}else if(l.type==="insert"){let d=s.find(u=>u.parentLineNo===l.newLineNo);f.push({columns:[" ","-"],text:l.line,resultLineNo:0,parentLineNos:[0,d?.parentLineNo??0]})}return f}let r=[];for(let o=0;ou!==" ")&&o.push(l);if(o.length===0)return[];let s=[],i=o[0]??0,a=Math.max(0,i-3),c=Math.min(e.length-1,i+3);for(let l=1;l(y.parentLineNos[C]??0)>0||y.columns[C]==="-");if(x.length===0)u.push({start:1,count:0});else{let P=x.find(k=>(k.parentLineNos[C]??0)>0)?.parentLineNos[C]??1;u.push({start:P,count:x.length})}}let m=d.filter(C=>C.resultLineNo>0),h=m[0],p=h?h.resultLineNo:1,g=m.length,w="";for(let C=p-2;C>=0;C--){let x=n[C];if(x&&/^[a-zA-Z$_]/.test(x)){w=` ${x.trimEnd().slice(0,79)}`;break}}let b=u.map(C=>`-${C.start},${C.count}`),R=`${"@".repeat(t+1)} ${b.join(" ")} +${p},${g} ${"@".repeat(t+1)}${w}`;f.push(R);for(let C of d)f.push(`${C.columns.join("")}${C.text}`)}return f}ne();ve();ae();ge();function gs(e){let t=e.indexOf("...");if(t>=0)return{type:"three-dot",left:e.slice(0,t)||"HEAD",right:e.slice(t+3)||"HEAD"};let n=e.indexOf("..");return n>=0?{type:"two-dot",left:e.slice(0,n)||"HEAD",right:e.slice(n+2)||"HEAD"}:null}ir();cn();ye();De();st();Ee();var Oc=new TextDecoder;function Ou(e){return"exitCode"in e}function Xn(e){return e.toString(8).padStart(6,"0")}function Su(e,t){let n=[];for(let r of e)n.push({path:r.path,status:r.status==="added"?"A":r.status==="deleted"?"D":"M",oldHash:r.oldHash,newHash:r.newHash,oldMode:r.oldMode,newMode:r.newMode});for(let r of t)n.push({path:r.newPath,status:"R",oldHash:r.oldHash,newHash:r.newHash,oldMode:r.oldMode,newMode:r.newMode,oldPath:r.oldPath,similarity:r.similarity});return n}function vu(e,t){e.command("diff",{description:"Show changes between commits, commit and working tree, etc.",transformArgs:n=>n.map(r=>{let o=/^-U(\d+)$/.exec(r);return o?`--unified=${o[1]}`:r}),args:[W.string().name("commits").variadic().optional()],options:{cached:S().describe("Show staged changes (index vs HEAD)"),staged:S().describe("Synonym for --cached"),stat:S().describe("Show diffstat summary"),nameOnly:S().describe("Show only names of changed files"),nameStatus:S().describe("Show names and status of changed files"),shortstat:S().describe("Show only the shortstat summary line"),numstat:S().describe("Machine-readable insertions/deletions per file"),unified:K.number().alias("U").describe("Generate diffs with lines of context"),findRenames:S().alias("M").describe("Detect renames (enabled by default)"),findCopies:S().alias("C").describe("Detect copies (accepted for compatibility)"),color:S().describe("Show colored diff (accepted for compatibility)"),noColor:S().describe("Turn off colored diff (accepted for compatibility)")},handler:async(n,r,o)=>{let s=await q(r.fs,r.cwd,t);if(D(s))return s;let i=s,a=n.cached||n.staged,c=n.commits,f=kt(i,r.cwd),l=o.passthrough.length>0?o.passthrough.map(g=>We(g,f)):null,d=n.stat?"stat":n.nameOnly?"name-only":n.nameStatus?"name-status":n.shortstat?"shortstat":n.numstat?"numstat":"unified",u,m=c.length===1?gs(c[0]):null;if(m){if(a)return v("too many arguments");m.type==="three-dot"?u=await fb(i,m.left,m.right,l):u=await $u(i,m.left,m.right,l)}else if(c.length===2)u=await $u(i,c[0],c[1],l);else{if(c.length>2)return v("too many arguments");a?u=await cb(i,c.length===1?c[0]:null,l):c.length===1?u=await lb(i,c[0],l):u=await ib(i,l)}if(Ou(u))return u;let h=n.unified,p=await db(i,u.items,d,h);return u.stderr&&(p.stderr=u.stderr),p}})}async function ib(e,t){let n=tt(e);if(n)return n;let r=await X(e),o=new Set,s=new Map,i=new Map,a=new Map;for(let l of r.entries)l.stage===0?s.set(l.path,l):(o.add(l.path),l.stage===2?i.set(l.path,l):l.stage===3&&a.set(l.path,l));let c=await dt(e,r,{includeUntracked:!1,pathFilter:t?l=>Pe(t,l):void 0}),f=[];for(let l of c){if(o.has(l.path))continue;let d=s.get(l.path);if(!d)continue;let u=Xn(d.mode);f.push({path:l.path,status:l.status==="deleted"?"D":"M",oldHash:d.hash,newHash:l.worktreeHash,oldMode:u,newMode:u,newFromWorkTree:l.status==="modified"})}for(let l of o){if(t&&!Pe(t,l))continue;let d=i.get(l),u=a.get(l);await ab(f,e,l,d,u)}return f.sort((l,d)=>{let u=Te(l.path,d.path);return u!==0?u:l.status==="U"&&d.status!=="U"?-1:l.status!=="U"&&d.status==="U"?1:0}),{items:f}}async function ab(e,t,n,r,o){let s=t.workTree;if(s&&r&&o){let i=Xn(r.mode),a=Xn(o.mode),{exists:c,hash:f}=await $i(t,s,n,r.hash);e.push({path:n,status:"U",newHash:f,newMode:i,newFromWorkTree:c,combinedParentHashes:[r.hash,o.hash],combinedParentModes:[i,a]}),Pu(e,n,r.hash,i,c,f);return}if(e.push({path:n,status:"U"}),s&&r){let i=Xn(r.mode),{exists:a,hash:c}=await $i(t,s,n,r.hash);Pu(e,n,r.hash,i,a,c)}}async function $i(e,t,n,r){let o=I(t,n),s=await Je(e.fs,o).catch(()=>null);return!s||!s.isFile&&!s.isSymbolicLink?{exists:!1}:{exists:!0,hash:await $t(e,o,r,s)}}function Pu(e,t,n,r,o,s){o&&s&&s!==n?e.push({path:t,status:"M",oldHash:n,newHash:s,oldMode:r,newMode:r,newFromWorkTree:!0}):o||e.push({path:t,status:"D",oldHash:n,oldMode:r})}async function cb(e,t,n){let r=null;if(t){let h=await Ge(e,t);if(D(h))return h;r=h.commit.tree}else{let h=await Z(e);h&&(r=(await M(e,h)).tree)}let o=await de(e,r),s=await X(e),i=new Set;for(let h of s.entries)h.stage>0&&i.add(h.path);let a=new Map(qe(s).map(h=>[h.path,h])),c=[];for(let[h,p]of a){if(i.has(h))continue;let g=o.get(h);g?g.hash!==p.hash&&c.push({path:h,status:"modified",oldHash:g.hash,newHash:p.hash,oldMode:g.mode,newMode:Xn(p.mode)}):c.push({path:h,status:"added",newHash:p.hash,newMode:Xn(p.mode)})}for(let[h,p]of o)i.has(h)||a.has(h)||c.push({path:h,status:"deleted",oldHash:p.hash,oldMode:p.mode});let f=await Rt(e,"diff"),{remaining:l,renames:d,neededRenameLimit:u}=await ht(e,c,{limit:f}),m=Su(l,d);for(let h of i)m.push({path:h,status:"U"});return m.sort((h,p)=>Te(h.path,p.path)),n?{items:m.filter(h=>Pe(n,h.path)),stderr:mt("diff",u)}:{items:m,stderr:mt("diff",u)}}async function $u(e,t,n,r){let o=await Ge(e,t);if(D(o))return o;let s=await Ge(e,n);if(D(s))return s;let i=await Ke(e,o.commit.tree,s.commit.tree);return Iu(e,i,r)}async function fb(e,t,n,r){let o=await Ge(e,t);if(D(o))return o;let s=await Ge(e,n);if(D(s))return s;let i=await ft(e,o.hash,s.hash);if(i.length===0)return v(`${t}...${n}: no merge base`);let a;i.length>1&&(a=`warning: ${t}...${n}: multiple merge bases, using ${i[0]} +-`);let c=i[0],f=await M(e,c),l=await Ke(e,f.tree,s.commit.tree),d=await Iu(e,l,r);return Ou(d)||a&&(d.stderr=a+(d.stderr??"")),d}async function Iu(e,t,n){let r=await Rt(e,"diff"),{remaining:o,renames:s,neededRenameLimit:i}=await ht(e,t,{limit:r}),a=Su(o,s);return a.sort((c,f)=>Te(c.path,f.path)),n?{items:a.filter(c=>Pe(n,c.path)),stderr:mt("diff",i)}:{items:a,stderr:mt("diff",i)}}async function lb(e,t,n){let r=tt(e);if(r)return r;let o=await Ge(e,t);if(D(o))return o;let s=e.workTree,i=await de(e,o.commit.tree),a=await X(e),c=new Map(qe(a).map(h=>[h.path,h])),f=new Set(a.entries.filter(h=>h.stage>0).map(h=>h.path)),l=h=>!n||Pe(n,h),d=await dt(e,a,{includeUntracked:!1,pathFilter:l}),u=new Map(d.map(h=>[h.path,h])),m=[];for(let[h,p]of i){if(!l(h))continue;if(f.has(h)){let C=await $i(e,s,h,p.hash);C.exists?C.hash!==p.hash&&m.push({path:h,status:"M",oldHash:p.hash,newHash:C.hash,oldMode:p.mode,newMode:p.mode,newFromWorkTree:!0}):m.push({path:h,status:"D",oldHash:p.hash,oldMode:p.mode});continue}let g=c.get(h);if(!g){m.push({path:h,status:"D",oldHash:p.hash,oldMode:p.mode});continue}let w=u.get(h);if(Yt(g.mode)&&(await Je(e.fs,I(s,h)).then(()=>!0).catch(()=>!1)||(w={path:h,status:"deleted",indexHash:g.hash})),w?.status==="deleted"){m.push({path:h,status:"D",oldHash:p.hash,oldMode:p.mode});continue}let b=w?.status==="modified"?w.worktreeHash:g.hash,R=Xn(g.mode);(b!==p.hash||R!==p.mode)&&m.push({path:h,status:"M",oldHash:p.hash,newHash:b,oldMode:p.mode,newMode:R,newFromWorkTree:w?.status==="modified"})}for(let[h,p]of c){if(i.has(h)||!l(h))continue;let g=u.get(h);g?.status!=="deleted"&&m.push({path:h,status:"A",newHash:g?.status==="modified"?g.worktreeHash:p.hash,newMode:Xn(p.mode),newFromWorkTree:g?.status==="modified"})}for(let h of f){if(i.has(h)||!l(h))continue;let p=a.entries.find(w=>w.path===h&&w.stage>0),g=await $i(e,s,h,p?.hash);g.exists&&m.push({path:h,status:"A",newHash:g.hash,newMode:p?Xn(p.mode):void 0,newFromWorkTree:!0})}return m.sort((h,p)=>Te(h.path,p.path)),{items:m}}async function db(e,t,n,r){let o;switch(n){case"stat":o=await wb(e,t);break;case"shortstat":o=await bb(e,t);break;case"numstat":o=await gb(e,t);break;case"name-only":o=hb(t);break;case"name-status":o=pb(t);break;default:o=await ub(e,t,r);break}return{stdout:o,stderr:"",exitCode:0}}async function ub(e,t,n){let r="",o=new Set,s=await mb(e,t);for(let i of t)if(i.status==="U")if(i.combinedParentHashes){let a=await Promise.all(i.combinedParentHashes.map(async l=>l?await le(e,l):"")),c=await Sc(e,i);if(a.some(l=>Ne(l))||Ne(c)){let l=i.combinedParentHashes.map(d=>d?Lt(d):"0000000");r+=`diff --cc ${i.path} ++`}function Cb(e,t,n){let r=e.length,s=n.map(i=>{let a=[],c=new Map,f=0;for(let l of i)if(l.type==="keep")a[l.newLineNo-1]="keep",f=l.newLineNo;else if(l.type==="insert")a[l.newLineNo-1]="insert",f=l.newLineNo;else if(l.type==="delete"){let d=c.get(f)??[];d.push({text:l.line,parentLineNo:l.oldLineNo}),c.set(f,d)}return{resultStatus:a,deletions:c}}),o=[];for(let i=0;i<=t.length;i++){let a=[];for(let f=0;fs.length>0))return[];if(t===2){let s=e[0]??[],o=e[1]??[];if(s.length===0)return o.map(l=>({columns:[" ","-"],text:l.text,resultLineNo:0,parentLineNos:[0,l.parentLineNo]}));if(o.length===0)return s.map(l=>({columns:["-"," "],text:l.text,resultLineNo:0,parentLineNos:[l.parentLineNo,0]}));let i=s.map(l=>l.text),a=o.map(l=>l.text),c=kt(i,a),f=[];for(let l of c)if(l.type==="keep"){let d=s.find(m=>m.text===l.line&&m.parentLineNo===l.oldLineNo),u=o.find(m=>m.text===l.line&&m.parentLineNo===l.newLineNo);f.push({columns:["-","-"],text:l.line,resultLineNo:0,parentLineNos:[d?.parentLineNo??0,u?.parentLineNo??0]})}else if(l.type==="delete"){let d=s.find(u=>u.parentLineNo===l.oldLineNo);f.push({columns:["-"," "],text:l.line,resultLineNo:0,parentLineNos:[d?.parentLineNo??0,0]})}else if(l.type==="insert"){let d=o.find(u=>u.parentLineNo===l.newLineNo);f.push({columns:[" ","-"],text:l.line,resultLineNo:0,parentLineNos:[0,d?.parentLineNo??0]})}return f}let r=[];for(let s=0;su!==" ")&&s.push(l);if(s.length===0)return[];let o=[],i=s[0]??0,a=Math.max(0,i-3),c=Math.min(e.length-1,i+3);for(let l=1;l(k.parentLineNos[C]??0)>0||k.columns[C]==="-");if(x.length===0)u.push({start:1,count:0});else{let P=x.find(E=>(E.parentLineNos[C]??0)>0)?.parentLineNos[C]??1;u.push({start:P,count:x.length})}}let m=d.filter(C=>C.resultLineNo>0),h=m[0],p=h?h.resultLineNo:1,g=m.length,w="";for(let C=p-2;C>=0;C--){let x=n[C];if(x&&/^[a-zA-Z$_]/.test(x)){w=` ${x.trimEnd().slice(0,79)}`;break}}let b=u.map(C=>`-${C.start},${C.count}`),y=`${"@".repeat(t+1)} ${b.join(" ")} +${p},${g} ${"@".repeat(t+1)}${w}`;f.push(y);for(let C of d)f.push(`${C.columns.join("")}${C.text}`)}return f}te();Se();ie();ge();function ks(e){let t=e.indexOf("...");if(t>=0)return{type:"three-dot",left:e.slice(0,t)||"HEAD",right:e.slice(t+3)||"HEAD"};let n=e.indexOf("..");return n>=0?{type:"two-dot",left:e.slice(0,n)||"HEAD",right:e.slice(n+2)||"HEAD"}:null}ir();un();ye();Te();ot();ke();var Gc=new TextDecoder;function Gu(e){return"exitCode"in e}function Gn(e){return e.toString(8).padStart(6,"0")}function Fu(e,t){let n=[];for(let r of e)n.push({path:r.path,status:r.status==="added"?"A":r.status==="deleted"?"D":"M",oldHash:r.oldHash,newHash:r.newHash,oldMode:r.oldMode,newMode:r.newMode});for(let r of t)n.push({path:r.newPath,status:"R",oldHash:r.oldHash,newHash:r.newHash,oldMode:r.oldMode,newMode:r.newMode,oldPath:r.oldPath,similarity:r.similarity});return n}function Nu(e,t){e.command("diff",{description:"Show changes between commits, commit and working tree, etc.",transformArgs:n=>n.map(r=>{let s=/^-U(\d+)$/.exec(r);return s?`--unified=${s[1]}`:r}),args:[B.string().name("commits").variadic().optional()],options:{cached:S().describe("Show staged changes (index vs HEAD)"),staged:S().describe("Synonym for --cached"),stat:S().describe("Show diffstat summary"),nameOnly:S().describe("Show only names of changed files"),nameStatus:S().describe("Show names and status of changed files"),shortstat:S().describe("Show only the shortstat summary line"),numstat:S().describe("Machine-readable insertions/deletions per file"),summary:S().describe("Show creations, deletions, renames and mode changes"),unified:K.number().alias("U").describe("Generate diffs with lines of context"),findRenames:S().alias("M").describe("Detect renames (enabled by default)"),findCopies:S().alias("C").describe("Detect copies (accepted for compatibility)"),color:S().describe("Show colored diff (accepted for compatibility)"),noColor:S().describe("Turn off colored diff (accepted for compatibility)")},handler:async(n,r,s)=>{let o=await W(r.fs,r.cwd,t);if(D(o))return o;let i=o,a=n.cached||n.staged,c=n.commits,f=ut(i,r.cwd),l=s.passthrough.length>0?s.passthrough.map(w=>qe(w,f)):null,d=n.stat?"stat":n.nameOnly?"name-only":n.nameStatus?"name-status":n.shortstat?"shortstat":n.numstat?"numstat":"unified",u,m=c.length===1?ks(c[0]):null;if(m){if(a)return v("too many arguments");m.type==="three-dot"?u=await vb(i,m.left,m.right,l):u=await Lu(i,m.left,m.right,l)}else if(c.length===2)u=await Lu(i,c[0],c[1],l);else{if(c.length>2)return v("too many arguments");a?u=await Sb(i,c.length===1?c[0]:null,l):c.length===1?u=await Ib(i,c[0],l):u=await $b(i,l)}if(Gu(u))return u;let h=n.unified,p=n.summary&&d!=="name-only"&&d!=="name-status",g=p&&d==="unified"?{stdout:"",stderr:"",exitCode:0}:await Tb(i,u.items,d,h);return p&&(g.stdout+=Lb(u.items)),u.stderr&&(g.stderr=u.stderr),g}})}async function $b(e,t){let n=tt(e);if(n)return n;let r=await X(e),s=new Set,o=new Map,i=new Map,a=new Map;for(let l of r.entries)l.stage===0?o.set(l.path,l):(s.add(l.path),l.stage===2?i.set(l.path,l):l.stage===3&&a.set(l.path,l));let c=await pt(e,r,{includeUntracked:!1,pathFilter:t?l=>Pe(t,l):void 0}),f=[];for(let l of c){if(s.has(l.path))continue;let d=o.get(l.path);d&&f.push({path:l.path,status:l.status==="deleted"?"D":"M",oldHash:d.hash,newHash:l.worktreeHash,oldMode:Gn(d.mode),newMode:Gn(l.worktreeMode??d.mode),newFromWorkTree:l.status==="modified"})}for(let l of s){if(t&&!Pe(t,l))continue;let d=i.get(l),u=a.get(l);await Ob(f,e,l,d,u)}return f.sort((l,d)=>{let u=Ae(l.path,d.path);return u!==0?u:l.status==="U"&&d.status!=="U"?-1:l.status!=="U"&&d.status==="U"?1:0}),{items:f}}async function Ob(e,t,n,r,s){let o=t.workTree;if(o&&r&&s){let i=Gn(r.mode),a=Gn(s.mode),{exists:c,hash:f}=await ji(t,o,n,r.hash);e.push({path:n,status:"U",newHash:f,newMode:i,newFromWorkTree:c,combinedParentHashes:[r.hash,s.hash],combinedParentModes:[i,a]}),ju(e,n,r.hash,i,c,f);return}if(e.push({path:n,status:"U"}),o&&r){let i=Gn(r.mode),{exists:a,hash:c}=await ji(t,o,n,r.hash);ju(e,n,r.hash,i,a,c)}}async function ji(e,t,n,r){let s=I(t,n),o=await Ye(e.fs,s).catch(()=>null);return!o||!o.isFile&&!o.isSymbolicLink?{exists:!1}:{exists:!0,hash:await Ot(e,s,r,o)}}function ju(e,t,n,r,s,o){s&&o&&o!==n?e.push({path:t,status:"M",oldHash:n,newHash:o,oldMode:r,newMode:r,newFromWorkTree:!0}):s||e.push({path:t,status:"D",oldHash:n,oldMode:r})}async function Sb(e,t,n){let r=null;if(t){let h=await Le(e,t);if(D(h))return h;r=h.commit.tree}else{let h=await Z(e);h&&(r=(await M(e,h)).tree)}let s=await de(e,r),o=await X(e),i=new Set;for(let h of o.entries)h.stage>0&&i.add(h.path);let a=new Map(ze(o).map(h=>[h.path,h])),c=[];for(let[h,p]of a){if(i.has(h))continue;let g=s.get(h);g?(g.hash!==p.hash||Number.parseInt(g.mode,8)!==p.mode)&&c.push({path:h,status:"modified",oldHash:g.hash,newHash:p.hash,oldMode:g.mode,newMode:Gn(p.mode)}):c.push({path:h,status:"added",newHash:p.hash,newMode:Gn(p.mode)})}for(let[h,p]of s)i.has(h)||a.has(h)||c.push({path:h,status:"deleted",oldHash:p.hash,oldMode:p.mode});let f=await xt(e,"diff"),{remaining:l,renames:d,neededRenameLimit:u}=await bt(e,c,{limit:f}),m=Fu(l,d);for(let h of i)m.push({path:h,status:"U"});return m.sort((h,p)=>Ae(h.path,p.path)),n?{items:m.filter(h=>Pe(n,h.path)),stderr:wt("diff",u)}:{items:m,stderr:wt("diff",u)}}async function Lu(e,t,n,r){let s=await Le(e,t);if(D(s))return s;let o=await Le(e,n);if(D(o))return o;let i=await Ve(e,s.commit.tree,o.commit.tree);return Uu(e,i,r)}async function vb(e,t,n,r){let s=await Le(e,t);if(D(s))return s;let o=await Le(e,n);if(D(o))return o;let i=await mt(e,s.hash,o.hash);if(i.length===0)return v(`${t}...${n}: no merge base`);let a;i.length>1&&(a=`warning: ${t}...${n}: multiple merge bases, using ${i[0]} ++`);let c=i[0],f=await M(e,c),l=await Ve(e,f.tree,o.commit.tree),d=await Uu(e,l,r);return Gu(d)||a&&(d.stderr=a+(d.stderr??"")),d}async function Uu(e,t,n){let r=await xt(e,"diff"),{remaining:s,renames:o,neededRenameLimit:i}=await bt(e,t,{limit:r}),a=Fu(s,o);return a.sort((c,f)=>Ae(c.path,f.path)),n?{items:a.filter(c=>Pe(n,c.path)),stderr:wt("diff",i)}:{items:a,stderr:wt("diff",i)}}async function Ib(e,t,n){let r=tt(e);if(r)return r;let s=await Le(e,t);if(D(s))return s;let o=e.workTree,i=await de(e,s.commit.tree),a=await X(e),c=new Map(ze(a).map(h=>[h.path,h])),f=new Set(a.entries.filter(h=>h.stage>0).map(h=>h.path)),l=h=>!n||Pe(n,h),d=await pt(e,a,{includeUntracked:!1,pathFilter:l}),u=new Map(d.map(h=>[h.path,h])),m=[];for(let[h,p]of i){if(!l(h))continue;if(f.has(h)){let C=await ji(e,o,h,p.hash);C.exists?C.hash!==p.hash&&m.push({path:h,status:"M",oldHash:p.hash,newHash:C.hash,oldMode:p.mode,newMode:p.mode,newFromWorkTree:!0}):m.push({path:h,status:"D",oldHash:p.hash,oldMode:p.mode});continue}let g=c.get(h);if(!g){m.push({path:h,status:"D",oldHash:p.hash,oldMode:p.mode});continue}let w=u.get(h);if(Jt(g.mode)&&(await Ye(e.fs,I(o,h)).then(()=>!0).catch(()=>!1)||(w={path:h,status:"deleted",indexHash:g.hash})),w?.status==="deleted"){m.push({path:h,status:"D",oldHash:p.hash,oldMode:p.mode});continue}let b=w?.status==="modified"?w.worktreeHash:g.hash,y=Gn(w?.worktreeMode??g.mode);(b!==p.hash||y!==p.mode)&&m.push({path:h,status:"M",oldHash:p.hash,newHash:b,oldMode:p.mode,newMode:y,newFromWorkTree:w?.status==="modified"})}for(let[h,p]of c){if(i.has(h)||!l(h))continue;let g=u.get(h);g?.status!=="deleted"&&m.push({path:h,status:"A",newHash:g?.status==="modified"?g.worktreeHash:p.hash,newMode:Gn(p.mode),newFromWorkTree:g?.status==="modified"})}for(let h of f){if(i.has(h)||!l(h))continue;let p=a.entries.find(w=>w.path===h&&w.stage>0),g=await ji(e,o,h,p?.hash);g.exists&&m.push({path:h,status:"A",newHash:g.hash,newMode:p?Gn(p.mode):void 0,newFromWorkTree:!0})}return m.sort((h,p)=>Ae(h.path,p.path)),{items:m}}async function Tb(e,t,n,r){let s;switch(n){case"stat":s=await Gb(e,t);break;case"shortstat":s=await Fb(e,t);break;case"numstat":s=await jb(e,t);break;case"name-only":s=Db(t);break;case"name-status":s=Mb(t);break;default:s=await Ab(e,t,r);break}return{stdout:s,stderr:"",exitCode:0}}async function Ab(e,t,n){let r="",s=new Set,o=await Hb(e,t);for(let i of t)if(i.status==="U")if(i.combinedParentHashes){let a=await Promise.all(i.combinedParentHashes.map(async l=>l?await le(e,l):"")),c=await Fc(e,i);if(a.some(l=>Fe(l))||Fe(c)){let l=i.combinedParentHashes.map(d=>d?Nt(d):"0000000");r+=`diff --cc ${i.path} + index ${l.join(",")}..0000000 + Binary files differ +-`,o.add(i.path)}else{let l=xi({path:i.path,parentHashes:i.combinedParentHashes,parentModes:i.combinedParentModes??[],parentContents:a,resultHash:null,resultMode:i.newMode??null,resultContent:c});l?(r+=l,o.add(i.path)):r+=`* Unmerged path ${i.path} ++`,s.add(i.path)}else{let l=Di({path:i.path,parentHashes:i.combinedParentHashes,parentModes:i.combinedParentModes??[],parentContents:a,resultHash:null,resultMode:i.newMode??null,resultContent:c});l?(r+=l,s.add(i.path)):r+=`* Unmerged path ${i.path} + `}}else r+=`* Unmerged path ${i.path} +-`;for(let i of t){if(i.status==="U"||o.has(i.path))continue;let a=i.oldHash?await le(e,i.oldHash):"",c=await Sc(e,i);i.status==="R"&&i.oldPath?r+=Wt({path:i.oldPath,oldContent:a,newContent:c,oldMode:i.oldMode,newMode:i.newMode,oldHash:Pi(i.oldHash,s),newHash:Pi(i.newHash,s),renameTo:i.path,similarity:i.similarity,contextLines:n}):r+=Wt({path:i.path,oldContent:a,newContent:c,oldMode:i.oldMode,newMode:i.newMode,oldHash:Pi(i.oldHash,s),newHash:Pi(i.newHash,s),isNew:i.status==="A",isDeleted:i.status==="D",contextLines:n})}return r}async function mb(e,t){let n=new Set;for(let a of t)a.oldHash&&a.oldHash.length===40&&n.add(a.oldHash),a.newHash&&a.newHash.length===40&&n.add(a.newHash);let r=new Map,o=async a=>{let c=r.get(a);if(c)return c;let f=I(e.gitDir,"objects",a),l=await e.fs.exists(f)?await e.fs.readdir(f):[];return r.set(a,l),l},s=async(a,c)=>{let f=a.slice(0,2),l=a.slice(2,c),d=await o(f),u=0;for(let m of d)if(m.startsWith(l)&&(u++,u>1))return!1;return u===1},i=new Map;for(let a of n){let c=7;for(;c<40&&!await s(a,c);)c++;i.set(a,a.slice(0,c))}return i}function Pi(e,t){if(e)return e.length!==40?e:t.get(e)??Lt(e)}function hb(e){let t="";for(let n of e)t+=`${n.path} +-`;return t}function pb(e){let t="";for(let n of e)if(n.status==="R"){let r=String(n.similarity??100).padStart(3,"0");t+=`R${r} ${n.oldPath} ${n.path} ++`;for(let i of t){if(i.status==="U"||s.has(i.path))continue;let a=i.oldHash?await le(e,i.oldHash):"",c=await Fc(e,i);i.status==="R"&&i.oldPath?r+=Kt({path:i.oldPath,oldContent:a,newContent:c,oldMode:i.oldMode,newMode:i.newMode,oldHash:Mi(i.oldHash,o),newHash:Mi(i.newHash,o),renameTo:i.path,similarity:i.similarity,contextLines:n}):r+=Kt({path:i.path,oldContent:a,newContent:c,oldMode:i.oldMode,newMode:i.newMode,oldHash:Mi(i.oldHash,o),newHash:Mi(i.newHash,o),isNew:i.status==="A",isDeleted:i.status==="D",contextLines:n})}return r}async function Hb(e,t){let n=new Set;for(let a of t)a.oldHash&&a.oldHash.length===40&&n.add(a.oldHash),a.newHash&&a.newHash.length===40&&n.add(a.newHash);let r=new Map,s=async a=>{let c=r.get(a);if(c)return c;let f=I(e.gitDir,"objects",a),l=await e.fs.exists(f)?await e.fs.readdir(f):[];return r.set(a,l),l},o=async(a,c)=>{let f=a.slice(0,2),l=a.slice(2,c),d=await s(f),u=0;for(let m of d)if(m.startsWith(l)&&(u++,u>1))return!1;return u===1},i=new Map;for(let a of n){let c=7;for(;c<40&&!await o(a,c);)c++;i.set(a,a.slice(0,c))}return i}function Mi(e,t){if(e)return e.length!==40?e:t.get(e)??Nt(e)}function Db(e){let t="";for(let n of e)t+=`${n.path} ++`;return t}function Mb(e){let t="";for(let n of e)if(n.status==="R"){let r=String(n.similarity??100).padStart(3,"0");t+=`R${r} ${n.oldPath} ${n.path} + `}else t+=`${n.status} ${n.path} +-`;return t}async function gb(e,t){let n="";for(let r of t){if(r.status==="U"){n+=`0 0 ${r.path} +-`;continue}let o=r.oldHash?await le(e,r.oldHash):"",s=await Sc(e,r),i=Ne(o)||Ne(s),a,c;if(i)a="-",c="-";else{let{ins:f,del:l}=Au(o,s);a=String(f),c=String(l)}if(r.status==="R"&&r.oldPath){let f=In(r.oldPath,r.path);n+=`${a} ${c} ${f} ++`;return t}async function jb(e,t){let n="";for(let r of t){if(r.status==="U"){n+=`0 0 ${r.path} ++`;continue}let s=r.oldHash?await le(e,r.oldHash):"",o=await Fc(e,r),i=Fe(s)||Fe(o),a,c;if(i)a="-",c="-";else{let{ins:f,del:l}=Bu(s,o);a=String(f),c=String(l)}if(r.status==="R"&&r.oldPath){let f=Dn(r.oldPath,r.path);n+=`${a} ${c} ${f} + `}else n+=`${a} ${c} ${r.path} +-`}return n}async function wb(e,t){let n=await Hu(e,t);return jr(n)}async function bb(e,t){let n=await Hu(e,t);if(n.length===0)return"";let r=0,o=0,s=0;for(let a of n)a.isUnmerged||(s++,r+=a.insertions,o+=a.deletions);let i=yr(s,r,o);return i?`${i} ++`}return n}function Lb(e){let t=[],n=[];for(let{path:r,status:s,oldPath:o,oldMode:i,newMode:a,similarity:c}of e)if(s==="R"&&o)n.push({oldPath:o,newPath:r,similarity:c??100,oldMode:i,newMode:a});else if(s==="A"||s==="D"||s==="M"){let f=s==="A"?"added":s==="D"?"deleted":"modified";t.push({path:r,status:f,oldMode:i,newMode:a})}return Er(t,n)}async function Gb(e,t){let n=await Wu(e,t);return Nr(n)}async function Fb(e,t){let n=await Wu(e,t);if(n.length===0)return"";let r=0,s=0,o=0;for(let a of n)a.isUnmerged||(o++,r+=a.insertions,s+=a.deletions);let i=yr(o,r,s);return i?`${i} + `:n.some(a=>a.isUnmerged)?` 0 files changed +-`:""}async function Sc(e,t){return Oc.decode(await Tu(e,t))}async function Tu(e,t){if(!t.newHash)return new Uint8Array(0);if(t.newFromWorkTree&&e.workTree){let n=I(e.workTree,t.path),r=await xf(e.fs,n);return vl(e,r,t.newHash)}return jt(e,t.newHash)}function Au(e,t){let n=Ht(e),r=Ht(t),o=gt(n,r),s=0,i=0;for(let a of o)a.type==="insert"?s++:a.type==="delete"&&i++;return{ins:s,del:i}}async function Hu(e,t){let n=[];for(let r of t){if(r.status==="U"){n.push({path:r.path,sortKey:r.path,insertions:0,deletions:0,isUnmerged:!0});continue}let o=r.status==="R"&&r.oldPath?In(r.oldPath,r.path):r.path,s=r.oldHash?await jt(e,r.oldHash):new Uint8Array(0),i=await Tu(e,r);if(hn(s)||hn(i))n.push({path:o,sortKey:r.path,insertions:0,deletions:0,isBinary:!0,oldSize:s.byteLength,newSize:i.byteLength});else{let a=Oc.decode(s),c=Oc.decode(i),{ins:f,del:l}=Au(a,c);n.push({path:o,sortKey:r.path,insertions:f,deletions:l})}}return n}ne();Be();ne();ae();Ve();ye();async function Oi(e,t){return t.depth!==void 0&&t.unshallow?v("--depth and --unshallow cannot be used together"):t.unshallow&&!await Qd(e)?v("--unshallow on a complete repository does not make sense"):{depth:t.unshallow?wc:t.depth}}async function Si(e,t,n,r=v){try{let o=await Ci(e,t,n);return o||r(`'${t}' does not appear to be a git repository`)}catch(o){let s=o instanceof Error?o.message:"";if(s.startsWith("network"))return r(s);throw o}}async function io(e){let n=(await $e(e)).map(o=>o.hash),r=await z(e,"HEAD");return r&&n.push(r),n}async function vi(e,t){let n=t!==void 0?await wi(e):void 0;return{existingShallows:n,shallowOpts:t!==void 0?{depth:t,existingShallows:n}:void 0}}async function Ii(e){let{gitCtx:t,transport:n,remoteRefs:r,ident:o,reflogAction:s}=e,i=[];for(let f of r){if(!f.name.startsWith("refs/tags/")||await z(t,f.name))continue;let l=f.peeledHash??f.hash;await Xt(t,l)&&i.push(f)}let a=[];for(let f of i)f.peeledHash&&!await Xt(t,f.hash)&&a.push(f.hash);a.length>0&&await n.fetch(a,await io(t));let c=[];for(let f of i)await Q(t,f.name,f.hash),await rt(t,f.name,{oldHash:oe,newHash:f.hash,name:o.name,email:o.email,timestamp:o.timestamp,tz:o.tz,message:`${s}: storing head`}),c.push({prefix:" * [new tag]",from:Zt(f.name),to:Zt(f.name)});return c}xr();ge();Ve();ye();function _r(e){let t=e,n=!1;t.startsWith("+")&&(n=!0,t=t.slice(1));let r=t.indexOf(":");return r===-1?{force:n,src:t,dst:t}:{force:n,src:t.slice(0,r),dst:t.slice(r+1)}}function yb(e,t){let n=e.indexOf("*");if(n===-1)return e===t;let r=e.slice(0,n),o=e.slice(n+1);return t.startsWith(r)&&t.endsWith(o)&&t.length>=r.length+o.length}function ao(e,t){if(!yb(e.src,t))return null;let n=e.src.indexOf("*"),r=e.dst.indexOf("*");if(n===-1)return e.dst;let o=e.src.slice(0,n),s=e.src.slice(n+1),i=s.length>0?t.length-s.length:t.length,a=t.slice(o.length,i);return r===-1?e.dst:e.dst.slice(0,r)+a+e.dst.slice(r+1)}Ee();function Mu(e,t){e.command("fetch",{description:"Download objects and refs from another repository",args:[W.string().name("remote").describe("Remote to fetch from").optional(),W.string().name("refspec").describe("Refspec(s) to fetch").optional().variadic()],options:{all:S().describe("Fetch from all remotes"),prune:S().alias("p").describe("Remove stale remote-tracking refs"),tags:S().describe("Also fetch tags"),depth:K.number().describe("Limit fetching to the specified number of commits"),unshallow:S().describe("Convert a shallow repository to a complete one"),quiet:ce("be more quiet")},handler:async(n,r)=>{let o=await q(r.fs,r.cwd,t);if(D(o))return o;let s=o,i=await Oi(s,n);if(D(i))return i;let{depth:a}=i;if(n.all){if(n.remote)return v("fetch --all does not take a remote argument");let f=await we(s),l=[];for(let m of Object.keys(f)){let h=m.match(/^remote "(.+)"$/);h?.[1]&&l.push(h[1])}if(l.length===0)return{stdout:"",stderr:"",exitCode:0};let d=[],u=0;for(let m of l){let h=await Du(s,m,void 0,n.prune,n.tags,r.env,t,a,n.quiet);h.stderr&&d.push(h.stderr),h.exitCode!==0&&(u=h.exitCode)}return{stdout:"",stderr:d.join(""),exitCode:u}}let c=n.remote||"origin";return Du(s,c,n.refspec,n.prune,n.tags,r.env,t,a,n.quiet)}})}function kb(e,t){return!e||e.length===0?[t]:e.map(n=>{let r=_r(n);if(n.includes(":"))return r;for(let o of[r.src,`refs/heads/${r.src}`,`refs/tags/${r.src}`]){let s=ao(t,o);if(s!==null)return{force:r.force||t.force,src:o,dst:s}}return r})}function Eb(e,t){let n=[],r=new Set,o=[],s=new Array(t.length).fill(!1);for(let i of e)if(i.name!=="HEAD")for(let[a,c]of t.entries()){let f=ao(c,i.name);if(f!==null){s[a]=!0,o.push({remote:i,localRef:f,force:c.force}),r.has(i.hash)||(r.add(i.hash),n.push(i.hash));break}}return{wants:n,refUpdates:o,matchedSpecs:s}}function Rb(e,t,n){if(!e||e.length===0)return null;for(let[r,o]of t.entries())if(!n[r]&&!o.src.includes("*"))return v(`couldn't find remote ref ${o.src}`);return null}async function Cb(e,t,n,r,o){let s=[],i=!1,a=[],c=[];for(let d of t){let u=await z(e,d.localRef);if(r&&d.remote.name.startsWith("refs/tags/")&&u&&u!==d.remote.hash){i=!0,c.push({prefix:" ! [rejected]",from:Zt(d.remote.name),to:Zt(d.localRef),suffix:" (would clobber existing tag)"});continue}a.push({...d,oldHash:u}),d.localRef.startsWith("refs/tags/")&&c.push({update:d,oldHash:u}),await Q(e,d.localRef,d.remote.hash),await rt(e,d.localRef,{oldHash:u??oe,newHash:d.remote.hash,name:n.name,email:n.email,timestamp:n.timestamp,tz:n.tz,message:u?"fetch":"fetch: storing head"})}if(o)return{refLines:s,hadTagRejection:i,appliedUpdates:a};let f=await en(e,a.flatMap(d=>d.oldHash?[d.oldHash,d.remote.hash]:[d.remote.hash])),l=a.filter(d=>!d.localRef.startsWith("refs/tags/"));s.push(...Bs(l,Zt,f));for(let d of c){if("prefix"in d){s.push(d);continue}s.push(...Bs([{...d.update,oldHash:d.oldHash}],Zt,f))}return{refLines:s,hadTagRejection:i,appliedUpdates:a}}async function Du(e,t,n,r,o,s,i,a,c=!1){let f=await Si(e,t,s);if(D(f))return f;let{transport:l,config:d}=f,u=!!n&&n.length>0,m=d.anonymous===!0&&!u,h=_r(d.fetchRefspec),p=m?[]:kb(n,h),g=await i?.hooks?.preFetch?.({repo:e,remote:t,url:d.url,refspecs:p.map(L=>`${L.src}:${L.dst}`),prune:r,tags:o});if(he(g))return{stdout:"",stderr:g.message??"",exitCode:1};let w=await l.advertiseRefs();if(w.length===0){if(n&&n.length>0){for(let L of p)if(!L.src.includes("*"))return v(`couldn't find remote ref ${L.src}`)}return{stdout:"",stderr:"",exitCode:0}}let{wants:b,refUpdates:R,matchedSpecs:C}=Eb(w,p),x=Rb(n,p,C);if(x)return x;let y=new Set(b);if(m){let L=w.find(_=>_.name==="HEAD");L&&!y.has(L.hash)&&(y.add(L.hash),b.push(L.hash))}if(o)for(let L of w)L.name.startsWith("refs/tags/")&&(R.push({remote:L,localRef:L.name,force:!1}),y.has(L.hash)||(y.add(L.hash),b.push(L.hash)));let P=await io(e),k=new Set(P),E=b.filter(L=>!k.has(L)),{existingShallows:O,shallowOpts:$}=await vi(e,a),T=E.length>0?E:$?b:[];if(T.length>0){let L=await l.fetch(T,P,$);L.shallowUpdates&&await ms(e,L.shallowUpdates,O)}let j=await Jn(e,s),{refLines:U,hadTagRejection:G,appliedUpdates:N}=await Cb(e,R,j,o,c);if(!c&&m&&w.some(L=>L.name==="HEAD")&&U.push({prefix:" * branch",from:"HEAD",to:"FETCH_HEAD"}),!o){let L=await Ii({gitCtx:e,transport:l,remoteRefs:w,ident:j,reflogAction:"fetch"});c||U.push(...L)}if(r){let L=`refs/remotes/${t}`,_=await $e(e,L),V=new Set(w.filter(Y=>Y.name.startsWith("refs/heads/")).map(Y=>Y.name.slice(11)));for(let Y of _){if((await e.refStore.readRef(Y.name))?.type==="symbolic")continue;let J=Y.name.slice(L.length+1);J!=="HEAD"&&(V.has(J)||(await ke(e,Y.name),c||U.push({prefix:" - [deleted]",from:"(none)",to:`${t}/${J}`})))}}let A=w.find(L=>L.name==="HEAD");if(A){let L=I(e.gitDir,"FETCH_HEAD"),_=w.find(fe=>fe.name.startsWith("refs/heads/")&&fe.hash===A.hash),V=_?`branch '${_.name.slice(11)}' of`:"of",Y=m?d.url:`${V} ${d.url}`;await e.fs.writeFile(L,`${A.hash} ${Y} +-`),!d.anonymous&&!u&&await es(e,t,w,l.headTarget)}let B={stdout:"",stderr:U.length>0?`From ${d.url} +-${os(U,10)}`:"",exitCode:G?1:0};return await i?.hooks?.postFetch?.({repo:e,remote:t,url:d.url,updatedRefCount:N.length}),B}ne();Be();ve();ae();ge();ye();Ve();async function Ti(e){let t=new Set;await Lu(ju(e,e.commonDir),t);for(let r of await Gr(e))await Lu(ju(e,r.privateDir),t);let n=[];for(let r of t)await Xt(e,r)&&n.push(r);return n}function ju(e,t){return t===e.gitDir?e:{...e,gitDir:t,refStore:new Pt(e.fs,t,e.commonDir)}}async function Lu(e,t){let n=await Z(e);n&&t.add(n);for(let o of await $e(e,"refs"))t.add(o.hash);await vc(e,I(e.commonDir,"logs"),t),e.gitDir!==e.commonDir&&await vc(e,I(e.gitDir,"logs"),t);let r=await X(e);for(let o of r.entries)t.add(o.hash);for(let o of["MERGE_HEAD","CHERRY_PICK_HEAD","REVERT_HEAD","ORIG_HEAD"]){let s=await z(e,o);s&&t.add(s)}}async function vc(e,t,n){if(await e.fs.exists(t))for(let r of await e.fs.readdir(t)){let o=I(t,r),s=await e.fs.stat(o);if(s.isDirectory){await vc(e,o,n);continue}if(s.isFile)for(let i of await Ls(e.fs,o))i.newHash!==oe&&n.add(i.newHash)}}ge();Ve();ye();Ee();Ao();Qr();ge();async function xb(e,t){let n=new Set,r=I(e.commonDir,"objects","pack");try{let s=await e.fs.readdir(r);for(let i of s){if(!i.endsWith(".idx"))continue;let a=await e.fs.readFileBuffer(I(r,i)),c=new un(a);for(let f of c.allHashes())n.add(f)}}catch{}return n.size===0?ps(await hs(e,t,[])):(await ps(await hs(e,t,[]))).filter(s=>!n.has(s.hash))}async function Ai(e){let{gitCtx:t,fs:n,tips:r,cleanup:o}=e,s=e.window??10,i=e.depth??50;if(r.length===0)return null;let a=e.all?await ps(await hs(t,r,[])):await xb(t,r);if(a.length===0)return null;let c=a.length,f=ki(a,{window:s,depth:i}),l=f.filter(y=>y.delta).length,d=f.map(y=>({hash:y.hash,type:y.type,content:y.content,delta:y.delta,deltaBaseHash:y.deltaBase})),{data:u,entries:m}=await To(d),h=await al(u,m),p=u.subarray(u.byteLength-20),g="";for(let y=0;y<20;y++){let P=p[y];g+=(P>>4).toString(16)+(P&15).toString(16)}let w=I(t.commonDir,"objects","pack");await n.mkdir(w,{recursive:!0});let b=`pack-${g}`,R=I(w,`${b}.pack`),C=I(w,`${b}.idx`);await n.writeFile(R,u),await n.writeFile(C,h);let x=new Set(f.map(y=>y.hash));if(t.objectStore.invalidatePacks?.(),o){let y=await n.readdir(w);for(let E of y){if(!E.endsWith(".idx"))continue;let O=E.slice(0,-4);if(O===b)continue;let $=I(w,`${O}.idx`),T=!0;try{let j=await n.readFileBuffer($),U=new un(j);for(let G of U.allHashes())if(!x.has(G)){T=!1;break}}catch{T=!1}if(T){try{await n.rm(I(w,`${O}.pack`))}catch{}try{await n.rm($)}catch{}}}let P=I(t.commonDir,"objects"),k;try{k=await n.readdir(P)}catch{k=[]}for(let E of k){if(E==="pack"||E==="info"||E.length!==2)continue;let O=I(P,E),$;try{$=await n.readdir(O)}catch{continue}for(let T of $){let j=`${E}${T}`;x.has(j)&&await n.rm(I(O,T))}try{(await n.readdir(O)).length===0&&await n.rm(O,{recursive:!0})}catch{}}}return{totalCount:c,deltaCount:l,packHash:g}}function Hi(e,t,n=!1){let r=e-t,o=[`Enumerating objects: ${e}, done.`];return n&&o.push(`Counting objects: 100% (${e}/${e}), done.`),o.push("Delta compression using 1 thread.",`Compressing objects: 100% (${r}/${e}), done.`,`Writing objects: 100% (${e}/${e}), done.`,`Total ${e} (delta ${t}), reused 0 (delta 0), pack-reused 0`),o.join(` +-`)}function Gu(e,t){e.command("gc",{description:"Cleanup unnecessary files and optimize the local repository",options:{aggressive:S().describe("More aggressively optimize the repository"),quiet:ce("suppress progress reporting")},handler:async(n,r)=>{let o=await q(r.fs,r.cwd,t);if(D(o))return o;let s=o;await pl(s);let i=await we(s),a=Pb(i);a!==null&&await Tt(s);let c=await $b(s,a);if(c.length>0){let f=n.aggressive?250:10,l=n.aggressive?250:50,d=await Ai({gitCtx:s,fs:r.fs,tips:c,window:f,depth:l,cleanup:!0,all:!0});if(d&&!n.quiet)return{stdout:"",stderr:`${Hi(d.totalCount,d.deltaCount,!0)} +-`,exitCode:0}}return{stdout:"",stderr:"",exitCode:0}}})}var ws=1440*60,Ic=90*ws;function Pb(e){let t=e.gc?.reflogexpire?.trim().toLowerCase();if(!t)return Ic;if(t==="never")return null;if(t==="now")return 0;let n=t.match(/^(\d+)[.\s]*(second|minute|hour|day|week|month|year)s?/);if(!n?.[1]||!n[2])return Ic;let r=parseInt(n[1],10),o={second:1,minute:60,hour:3600,day:ws,week:7*ws,month:30*ws,year:365*ws};return r*(o[n[2]]??ws)}async function $b(e,t){return t!==null&&await Ob(e,t),Ti(e)}async function Ob(e,t=Ic){let n=Math.floor(Date.now()/1e3)-t;await Tc(e,I(e.commonDir,"logs"),n,r=>r!=="refs/stash");for(let r of await Gr(e))await Tc(e,I(r.privateDir,"logs"),n,()=>!0)}async function Tc(e,t,n,r,o=t){if(await e.fs.exists(t))for(let s of await e.fs.readdir(t)){let i=I(t,s),a=await e.fs.stat(i);if(a.isDirectory){await Tc(e,i,n,r,o);try{(await e.fs.readdir(i)).length===0&&await e.fs.rm(i,{recursive:!0})}catch{}continue}if(!a.isFile)continue;let c=i.slice(o.length+1);if(!r(c))continue;let f=await Ls(e.fs,i),l=f.filter(d=>d.timestamp>=n);l.length!==f.length&&await Ta(e.fs,i,l)}}ne();function Sb(e){let t=Math.min(e.length,8e3),n=0;for(let r=0;rt*.01}function Fu(e,t,n,r){if(Sb(e)){let i=t.some(a=>a.test(e));return{matches:[],binary:i}}let o=e.split(` +-`);if(o.length>0&&o[o.length-1]===""&&o.pop(),n&&t.length>1&&!t.every(a=>o.some(c=>a.test(c))))return{matches:[],binary:!1};let s=[];for(let i=0;if.test(a));(r?!c:c)&&s.push({lineNo:i+1,line:a})}return{matches:s,binary:!1}}function vb(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Nu(e,t){let n=t?.fixed?vb(e):e;t?.wordRegexp&&(n=`\\b${n}\\b`);let r=t?.ignoreCase?"i":"";try{return new RegExp(n,r)}catch{return null}}ve();ae();ge();De();Ee();async function Ib(e){let t=await X(e),n=new Set,r=[];for(let o of t.entries){if(o.stage!==0||n.has(o.path))continue;n.add(o.path);let s=I(e.workTree,o.path);r.push({path:o.path,getContent:async()=>{try{return await e.fs.readFile(s)}catch{return""}}})}return r}async function Tb(e){let t=await X(e),n=new Set,r=[];for(let o of t.entries){if(o.stage!==0||n.has(o.path))continue;n.add(o.path);let s=o.hash;r.push({path:o.path,getContent:()=>le(e,s)})}return r}async function Ab(e,t){return(await ze(e,t)).filter(r=>!r.mode.startsWith("120")).map(r=>({path:r.path,getContent:()=>le(e,r.hash)}))}function Hb(e){let t=0;for(let n=0;n levels of directories"),maxCount:K.number().alias("m").describe("Maximum number of matches per file"),afterContext:K.number().alias("A").describe("Show lines after match"),beforeContext:K.number().alias("B").describe("Show lines before match"),context:K.number().alias("C").describe("Show lines before and after match"),heading:S().describe("Show filename above matches"),break:S().describe("Print empty line between results from different files"),pattern:K.string().alias("e").repeatable().describe("Match ")},handler:async(n,r,o)=>{let s=await q(r.fs,r.cwd,t);if(D(s))return s;let i=s,a=n.args??[],c=o.passthrough??[],f=n.pattern,l=[],d=0;if(f.length===0){if(a.length===0)return v("no pattern given");f.push(a[d++])}for(;d0)for(let B of l){let L=await It(i,B);if(D(L))return L;let _;try{_=await Se(i,L)}catch{return v(`bad revision '${B}'`)}let V=await M(i,_),Y=await Ab(i,V.tree);m.push({prefix:`${B}:`,files:Y})}else if(n.cached)m.push({prefix:"",files:await Tb(i)});else{if(!i.workTree)return v("this operation must be run in a work tree");m.push({prefix:"",files:await Ib(i)})}let h=kt(i,r.cwd),p=null;c.length>0&&(p=c.map(B=>We(B,h)));let g=n.maxDepth,w=n.maxCount,b=!!(n.lineNumber||n.afterContext!=null||n.beforeContext!=null||n.context!=null),R=!!n.filesWithMatches,C=!!n.filesWithoutMatch,x=!!n.count,y=!!n.quiet,P=!!n.heading,k=!!n.break,E=!!n.suppressFilename,O=!!n.invertMatch,$=!!n.allMatch,T=n.context??n.afterContext??0,j=n.context??n.beforeContext??0,U=T>0||j>0,G=[],N=!1,A=!0;for(let B of m){let L=B.files.slice().sort((_,V)=>_.pathV.path?1:0);for(let _ of L){if(p&&!Pe(p,_.path)||g!==void 0&&Hb(_.path)>g)continue;let V=await _.getContent(),Y=Fu(V,u,$,O),fe=Db(_.path,h,!!n.fullName),J=B.prefix;if(Y.binary){if(N=!0,y)return{stdout:"",stderr:"",exitCode:0};R?G.push(`${J}${fe}`):!C&&!x&&G.push(`Binary file ${J}${fe} matches`);continue}if(Y.matches.length===0){C&&G.push(`${J}${fe}`);continue}if(N=!0,y)return{stdout:"",stderr:"",exitCode:0};if(C)continue;if(R){G.push(`${J}${fe}`);continue}if(x){let Oe=w!==void 0?Math.min(Y.matches.length,w):Y.matches.length;G.push(`${J}${fe}:${Oe}`);continue}let re=Y.matches;if(w!==void 0&&(re=re.slice(0,w)),U)Mb(G,V,re,J,fe,E,j,T,P,k,A);else if(P){!A&&k&&G.push(""),G.push(`${J}${fe}`);for(let Oe of re)b?G.push(`${Oe.lineNo}:${Oe.line}`):G.push(Oe.line)}else{!A&&k&&G.push("");for(let Oe of re){let xe=E?"":`${J}${fe}:`;b?G.push(`${xe}${Oe.lineNo}:${Oe.line}`):G.push(`${xe}${Oe.line}`)}}A=!1}}return y?{stdout:"",stderr:"",exitCode:N?0:1}:{stdout:G.length>0?`${G.join(` +-`)} +-`:"",stderr:"",exitCode:N?0:1}}})}function Mb(e,t,n,r,o,s,i,a,c,f,l){let d=t.split(` +-`);d.length>0&&d[d.length-1]===""&&d.pop();let u=new Set(n.map(g=>g.lineNo)),m=[];for(let g of n){let w=Math.max(1,g.lineNo-i),b=Math.min(d.length,g.lineNo+a);m.push([w,b])}let h=[];for(let[g,w]of m)h.length>0&&g<=h[h.length-1][1]+1?h[h.length-1][1]=Math.max(h[h.length-1][1],w):h.push([g,w]);let p=s?"":`${r}${o}`;c?(!l&&f&&e.push(""),e.push(`${r}${o}`)):!l&&f&&e.push("");for(let g=0;g0&&e.push("--");let[w,b]=h[g];for(let R=w;R<=b;R++){let C=d[R-1],y=u.has(R)?":":"-";c?e.push(`${R}${y}${C}`):e.push(`${p}${y}${R}${y}${C}`)}}}ne();ge();Gn();Ee();function _u(e,t){e.command("init",{description:"Initialize a new repository",args:[W.string().name("directory").describe("The directory to initialize").optional()],options:{bare:S().describe("Create a bare repository"),initialBranch:K.string().alias("b").describe("Name for the initial branch"),quiet:ce("be quiet")},examples:["git init","git init --bare","git init my-project"],handler:async(n,r)=>{let o=n.initialBranch??t?.configOverrides?.locked?.["init.defaultbranch"]??t?.configOverrides?.defaults?.["init.defaultbranch"],s=n.directory?Qe(r.cwd,n.directory):r.cwd;n.directory&&await r.fs.mkdir(s,{recursive:!0});let{ctx:i,reinit:a}=await jo(r.fs,s,{bare:n.bare,...o?{initialBranch:o}:{}}),c="";if(a&&o&&(c=`warning: re-init: ignored --initial-branch=${o} ++`:""}async function Fc(e,t){return Gc.decode(await _u(e,t))}async function _u(e,t){if(!t.newHash)return new Uint8Array(0);if(t.newFromWorkTree&&e.workTree){let n=I(e.workTree,t.path),r=await Mf(e.fs,n);return Fl(e,r,t.newHash)}return Gt(e,t.newHash)}function Bu(e,t){let n=Mt(e),r=Mt(t),s=kt(n,r),o=0,i=0;for(let a of s)a.type==="insert"?o++:a.type==="delete"&&i++;return{ins:o,del:i}}async function Wu(e,t){let n=[];for(let r of t){if(r.status==="U"){n.push({path:r.path,sortKey:r.path,insertions:0,deletions:0,isUnmerged:!0});continue}let s=r.status==="R"&&r.oldPath?Dn(r.oldPath,r.path):r.path,o=r.oldHash?await Gt(e,r.oldHash):new Uint8Array(0),i=await _u(e,r);if(wn(o)||wn(i))n.push({path:s,sortKey:r.path,insertions:0,deletions:0,isBinary:!0,oldSize:o.byteLength,newSize:i.byteLength});else{let a=Gc.decode(o),c=Gc.decode(i),{ins:f,del:l}=Bu(a,c);n.push({path:s,sortKey:r.path,insertions:f,deletions:l})}}return n}te();We();te();ie();Xe();ye();async function Li(e,t){return t.depth!==void 0&&t.unshallow?v("--depth and --unshallow cannot be used together"):t.unshallow&&!await fu(e)?v("--unshallow on a complete repository does not make sense"):{depth:t.unshallow?Sc:t.depth}}async function Gi(e,t,n,r=v){try{let s=await Hi(e,t,n);return s||r(`'${t}' does not appear to be a git repository`)}catch(s){let o=s instanceof Error?s.message:"";if(o.startsWith("network"))return r(o);throw s}}async function po(e){let n=(await $e(e)).map(s=>s.hash),r=await z(e,"HEAD");return r&&n.push(r),n}async function Fi(e,t){let n=t!==void 0?await Oi(e):void 0;return{existingShallows:n,shallowOpts:t!==void 0?{depth:t,existingShallows:n}:void 0}}async function Ni(e){let{gitCtx:t,transport:n,remoteRefs:r,ident:s,reflogAction:o}=e,i=[];for(let f of r){if(!f.name.startsWith("refs/tags/")||await z(t,f.name))continue;let l=f.peeledHash??f.hash;await tn(t,l)&&i.push(f)}let a=[];for(let f of i)f.peeledHash&&!await tn(t,f.hash)&&a.push(f.hash);a.length>0&&await n.fetch(a,await po(t));let c=[];for(let f of i)await Q(t,f.name,f.hash),await st(t,f.name,{oldHash:se,newHash:f.hash,name:s.name,email:s.email,timestamp:s.timestamp,tz:s.tz,message:`${o}: storing head`}),c.push({prefix:" * [new tag]",from:nn(f.name),to:nn(f.name)});return c}$r();ge();Xe();ye();function zr(e){let t=e,n=!1;t.startsWith("+")&&(n=!0,t=t.slice(1));let r=t.indexOf(":");return r===-1?{force:n,src:t,dst:t}:{force:n,src:t.slice(0,r),dst:t.slice(r+1)}}function Nb(e,t){let n=e.indexOf("*");if(n===-1)return e===t;let r=e.slice(0,n),s=e.slice(n+1);return t.startsWith(r)&&t.endsWith(s)&&t.length>=r.length+s.length}function go(e,t){if(!Nb(e.src,t))return null;let n=e.src.indexOf("*"),r=e.dst.indexOf("*");if(n===-1)return e.dst;let s=e.src.slice(0,n),o=e.src.slice(n+1),i=o.length>0?t.length-o.length:t.length,a=t.slice(s.length,i);return r===-1?e.dst:e.dst.slice(0,r)+a+e.dst.slice(r+1)}ke();function zu(e,t){e.command("fetch",{description:"Download objects and refs from another repository",args:[B.string().name("remote").describe("Remote to fetch from").optional(),B.string().name("refspec").describe("Refspec(s) to fetch").optional().variadic()],options:{all:S().describe("Fetch from all remotes"),prune:S().alias("p").describe("Remove stale remote-tracking refs"),tags:S().describe("Also fetch tags"),depth:K.number().describe("Limit fetching to the specified number of commits"),unshallow:S().describe("Convert a shallow repository to a complete one"),quiet:ce("be more quiet")},handler:async(n,r)=>{let s=await W(r.fs,r.cwd,t);if(D(s))return s;let o=s,i=await Li(o,n);if(D(i))return i;let{depth:a}=i;if(n.all){if(n.remote)return v("fetch --all does not take a remote argument");let f=await be(o),l=[];for(let m of Object.keys(f)){let h=m.match(/^remote "(.+)"$/);h?.[1]&&l.push(h[1])}if(l.length===0)return{stdout:"",stderr:"",exitCode:0};let d=[],u=0;for(let m of l){let h=await qu(o,m,void 0,n.prune,n.tags,r.env,t,a,n.quiet);h.stderr&&d.push(h.stderr),h.exitCode!==0&&(u=h.exitCode)}return{stdout:"",stderr:d.join(""),exitCode:u}}let c=n.remote||"origin";return qu(o,c,n.refspec,n.prune,n.tags,r.env,t,a,n.quiet)}})}function Ub(e,t){return!e||e.length===0?[t]:e.map(n=>{let r=zr(n);if(n.includes(":"))return r;for(let s of[r.src,`refs/heads/${r.src}`,`refs/tags/${r.src}`]){let o=go(t,s);if(o!==null)return{force:r.force||t.force,src:s,dst:o}}return r})}function _b(e,t){let n=[],r=new Set,s=[],o=new Array(t.length).fill(!1);for(let i of e)if(i.name!=="HEAD")for(let[a,c]of t.entries()){let f=go(c,i.name);if(f!==null){o[a]=!0,s.push({remote:i,localRef:f,force:c.force}),r.has(i.hash)||(r.add(i.hash),n.push(i.hash));break}}return{wants:n,refUpdates:s,matchedSpecs:o}}function Bb(e,t,n){if(!e||e.length===0)return null;for(let[r,s]of t.entries())if(!n[r]&&!s.src.includes("*"))return v(`couldn't find remote ref ${s.src}`);return null}async function Wb(e,t,n,r,s){let o=[],i=!1,a=[],c=[];for(let d of t){let u=await z(e,d.localRef);if(r&&d.remote.name.startsWith("refs/tags/")&&u&&u!==d.remote.hash){i=!0,c.push({prefix:" ! [rejected]",from:nn(d.remote.name),to:nn(d.localRef),suffix:" (would clobber existing tag)"});continue}a.push({...d,oldHash:u}),d.localRef.startsWith("refs/tags/")&&c.push({update:d,oldHash:u}),await Q(e,d.localRef,d.remote.hash),await st(e,d.localRef,{oldHash:u??se,newHash:d.remote.hash,name:n.name,email:n.email,timestamp:n.timestamp,tz:n.tz,message:u?"fetch":"fetch: storing head"})}if(s)return{refLines:o,hadTagRejection:i,appliedUpdates:a};let f=await sn(e,a.flatMap(d=>d.oldHash?[d.oldHash,d.remote.hash]:[d.remote.hash])),l=a.filter(d=>!d.localRef.startsWith("refs/tags/"));o.push(...Ys(l,nn,f));for(let d of c){if("prefix"in d){o.push(d);continue}o.push(...Ys([{...d.update,oldHash:d.oldHash}],nn,f))}return{refLines:o,hadTagRejection:i,appliedUpdates:a}}async function qu(e,t,n,r,s,o,i,a,c=!1){let f=await Gi(e,t,o);if(D(f))return f;let{transport:l,config:d}=f,u=!!n&&n.length>0,m=d.anonymous===!0&&!u,h=zr(d.fetchRefspec),p=m?[]:Ub(n,h),g=await i?.hooks?.preFetch?.({repo:e,remote:t,url:d.url,refspecs:p.map(F=>`${F.src}:${F.dst}`),prune:r,tags:s});if(pe(g))return{stdout:"",stderr:g.message??"",exitCode:1};let w=await l.advertiseRefs();if(w.length===0){if(n&&n.length>0){for(let F of p)if(!F.src.includes("*"))return v(`couldn't find remote ref ${F.src}`)}return{stdout:"",stderr:"",exitCode:0}}let{wants:b,refUpdates:y,matchedSpecs:C}=_b(w,p),x=Bb(n,p,C);if(x)return x;let k=new Set(b);if(m){let F=w.find(_=>_.name==="HEAD");F&&!k.has(F.hash)&&(k.add(F.hash),b.push(F.hash))}if(s)for(let F of w)F.name.startsWith("refs/tags/")&&(y.push({remote:F,localRef:F.name,force:!1}),k.has(F.hash)||(k.add(F.hash),b.push(F.hash)));let P=await po(e),E=new Set(P),R=b.filter(F=>!E.has(F)),{existingShallows:O,shallowOpts:$}=await Fi(e,a),T=R.length>0?R:$?b:[];if(T.length>0){let F=await l.fetch(T,P,$);F.shallowUpdates&&await ws(e,F.shallowUpdates,O)}let j=await Jn(e,o),{refLines:U,hadTagRejection:G,appliedUpdates:L}=await Wb(e,y,j,s,c);if(!c&&m&&w.some(F=>F.name==="HEAD")&&U.push({prefix:" * branch",from:"HEAD",to:"FETCH_HEAD"}),!s){let F=await Ni({gitCtx:e,transport:l,remoteRefs:w,ident:j,reflogAction:"fetch"});c||U.push(...F)}if(r){let F=`refs/remotes/${t}`,_=await $e(e,F),Y=new Set(w.filter(V=>V.name.startsWith("refs/heads/")).map(V=>V.name.slice(11)));for(let V of _){if((await e.refStore.readRef(V.name))?.type==="symbolic")continue;let Ce=V.name.slice(F.length+1);Ce!=="HEAD"&&(Y.has(Ce)||(await Ee(e,V.name),c||U.push({prefix:" - [deleted]",from:"(none)",to:`${t}/${Ce}`})))}}let A=w.find(F=>F.name==="HEAD");if(A){let F=I(e.gitDir,"FETCH_HEAD"),_=w.find(ue=>ue.name.startsWith("refs/heads/")&&ue.hash===A.hash),Y=_?`branch '${_.name.slice(11)}' of`:"of",V=m?d.url:`${Y} ${d.url}`;await e.fs.writeFile(F,`${A.hash} ${V} ++`),!d.anonymous&&!u&&await rs(e,t,w,l.headTarget)}let q={stdout:"",stderr:U.length>0?`From ${d.url} ++${cs(U,10)}`:"",exitCode:G?1:0};return await i?.hooks?.postFetch?.({repo:e,remote:t,url:d.url,updatedRefCount:L.length}),q}te();We();Se();ie();ge();ye();Xe();async function Ui(e){let t=new Set;await Vu(Ku(e,e.commonDir),t);for(let r of await _r(e))await Vu(Ku(e,r.privateDir),t);let n=[];for(let r of t)await tn(e,r)&&n.push(r);return n}function Ku(e,t){return t===e.gitDir?e:{...e,gitDir:t,refStore:new $t(e.fs,t,e.commonDir)}}async function Vu(e,t){let n=await Z(e);n&&t.add(n);for(let s of await $e(e,"refs"))t.add(s.hash);await Nc(e,I(e.commonDir,"logs"),t),e.gitDir!==e.commonDir&&await Nc(e,I(e.gitDir,"logs"),t);let r=await X(e);for(let s of r.entries)t.add(s.hash);for(let s of["MERGE_HEAD","CHERRY_PICK_HEAD","REVERT_HEAD","ORIG_HEAD"]){let o=await z(e,s);o&&t.add(o)}}async function Nc(e,t,n){if(await e.fs.exists(t))for(let r of await e.fs.readdir(t)){let s=I(t,r),o=await e.fs.stat(s);if(o.isDirectory){await Nc(e,s,n);continue}if(o.isFile)for(let i of await _s(e.fs,s))i.newHash!==se&&n.add(i.newHash)}}ge();Xe();ye();ke();Fo();ns();ge();async function qb(e,t){let n=new Set,r=I(e.commonDir,"objects","pack");try{let o=await e.fs.readdir(r);for(let i of o){if(!i.endsWith(".idx"))continue;let a=await e.fs.readFileBuffer(I(r,i)),c=new gn(a);for(let f of c.allHashes())n.add(f)}}catch{}return n.size===0?ys(await bs(e,t,[])):(await ys(await bs(e,t,[]))).filter(o=>!n.has(o.hash))}async function _i(e){let{gitCtx:t,fs:n,tips:r,cleanup:s}=e,o=e.window??10,i=e.depth??50;if(r.length===0)return null;let a=e.all?await ys(await bs(t,r,[])):await qb(t,r);if(a.length===0)return null;let c=a.length,f=Ii(a,{window:o,depth:i}),l=f.filter(k=>k.delta).length,d=f.map(k=>({hash:k.hash,type:k.type,content:k.content,delta:k.delta,deltaBaseHash:k.deltaBase})),{data:u,entries:m}=await Go(d),h=await bl(u,m),p=u.subarray(u.byteLength-20),g="";for(let k=0;k<20;k++){let P=p[k];g+=(P>>4).toString(16)+(P&15).toString(16)}let w=I(t.commonDir,"objects","pack");await n.mkdir(w,{recursive:!0});let b=`pack-${g}`,y=I(w,`${b}.pack`),C=I(w,`${b}.idx`);await n.writeFile(y,u),await n.writeFile(C,h);let x=new Set(f.map(k=>k.hash));if(t.objectStore.invalidatePacks?.(),s){let k=await n.readdir(w);for(let R of k){if(!R.endsWith(".idx"))continue;let O=R.slice(0,-4);if(O===b)continue;let $=I(w,`${O}.idx`),T=!0;try{let j=await n.readFileBuffer($),U=new gn(j);for(let G of U.allHashes())if(!x.has(G)){T=!1;break}}catch{T=!1}if(T){try{await n.rm(I(w,`${O}.pack`))}catch{}try{await n.rm($)}catch{}}}let P=I(t.commonDir,"objects"),E;try{E=await n.readdir(P)}catch{E=[]}for(let R of E){if(R==="pack"||R==="info"||R.length!==2)continue;let O=I(P,R),$;try{$=await n.readdir(O)}catch{continue}for(let T of $){let j=`${R}${T}`;x.has(j)&&await n.rm(I(O,T))}try{(await n.readdir(O)).length===0&&await n.rm(O,{recursive:!0})}catch{}}}return{totalCount:c,deltaCount:l,packHash:g}}function Bi(e,t,n=!1){let r=e-t,s=[`Enumerating objects: ${e}, done.`];return n&&s.push(`Counting objects: 100% (${e}/${e}), done.`),s.push("Delta compression using 1 thread.",`Compressing objects: 100% (${r}/${e}), done.`,`Writing objects: 100% (${e}/${e}), done.`,`Total ${e} (delta ${t}), reused 0 (delta 0), pack-reused 0`),s.join(` ++`)}function Yu(e,t){e.command("gc",{description:"Cleanup unnecessary files and optimize the local repository",options:{aggressive:S().describe("More aggressively optimize the repository"),quiet:ce("suppress progress reporting")},handler:async(n,r)=>{let s=await W(r.fs,r.cwd,t);if(D(s))return s;let o=s;await $l(o);let i=await be(o),a=zb(i);a!==null&&await Ht(o);let c=await Kb(o,a);if(c.length>0){let f=n.aggressive?250:10,l=n.aggressive?250:50,d=await _i({gitCtx:o,fs:r.fs,tips:c,window:f,depth:l,cleanup:!0,all:!0});if(d&&!n.quiet)return{stdout:"",stderr:`${Bi(d.totalCount,d.deltaCount,!0)} ++`,exitCode:0}}return{stdout:"",stderr:"",exitCode:0}}})}var Es=1440*60,Uc=90*Es;function zb(e){let t=e.gc?.reflogexpire?.trim().toLowerCase();if(!t)return Uc;if(t==="never")return null;if(t==="now")return 0;let n=t.match(/^(\d+)[.\s]*(second|minute|hour|day|week|month|year)s?/);if(!n?.[1]||!n[2])return Uc;let r=parseInt(n[1],10),s={second:1,minute:60,hour:3600,day:Es,week:7*Es,month:30*Es,year:365*Es};return r*(s[n[2]]??Es)}async function Kb(e,t){return t!==null&&await Vb(e,t),Ui(e)}async function Vb(e,t=Uc){let n=Math.floor(Date.now()/1e3)-t;await _c(e,I(e.commonDir,"logs"),n,r=>r!=="refs/stash");for(let r of await _r(e))await _c(e,I(r.privateDir,"logs"),n,()=>!0)}async function _c(e,t,n,r,s=t){if(await e.fs.exists(t))for(let o of await e.fs.readdir(t)){let i=I(t,o),a=await e.fs.stat(i);if(a.isDirectory){await _c(e,i,n,r,s);try{(await e.fs.readdir(i)).length===0&&await e.fs.rm(i,{recursive:!0})}catch{}continue}if(!a.isFile)continue;let c=i.slice(s.length+1);if(!r(c))continue;let f=await _s(e.fs,i),l=f.filter(d=>d.timestamp>=n);l.length!==f.length&&await Na(e.fs,i,l)}}te();function Yb(e){let t=Math.min(e.length,8e3),n=0;for(let r=0;rt*.01}function Xu(e,t,n,r){if(Yb(e)){let i=t.some(a=>a.test(e));return{matches:[],binary:i}}let s=e.split(` ++`);if(s.length>0&&s[s.length-1]===""&&s.pop(),n&&t.length>1&&!t.every(a=>s.some(c=>a.test(c))))return{matches:[],binary:!1};let o=[];for(let i=0;if.test(a));(r?!c:c)&&o.push({lineNo:i+1,line:a})}return{matches:o,binary:!1}}function Xb(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Zu(e,t){let n=t?.fixed?Xb(e):e;t?.wordRegexp&&(n=`\\b${n}\\b`);let r=t?.ignoreCase?"i":"";try{return new RegExp(n,r)}catch{return null}}Se();ie();ge();Te();ke();async function Zb(e){let t=await X(e),n=new Set,r=[];for(let s of t.entries){if(s.stage!==0||n.has(s.path))continue;n.add(s.path);let o=I(e.workTree,s.path);r.push({path:s.path,getContent:async()=>{try{return await e.fs.readFile(o)}catch{return""}}})}return r}async function Qb(e){let t=await X(e),n=new Set,r=[];for(let s of t.entries){if(s.stage!==0||n.has(s.path))continue;n.add(s.path);let o=s.hash;r.push({path:s.path,getContent:()=>le(e,o)})}return r}async function Jb(e,t){return(await Ke(e,t)).filter(r=>!r.mode.startsWith("120")).map(r=>({path:r.path,getContent:()=>le(e,r.hash)}))}function ey(e){let t=0;for(let n=0;n levels of directories"),maxCount:K.number().alias("m").describe("Maximum number of matches per file"),afterContext:K.number().alias("A").describe("Show lines after match"),beforeContext:K.number().alias("B").describe("Show lines before match"),context:K.number().alias("C").describe("Show lines before and after match"),heading:S().describe("Show filename above matches"),break:S().describe("Print empty line between results from different files"),pattern:K.string().alias("e").repeatable().describe("Match ")},handler:async(n,r,s)=>{let o=await W(r.fs,r.cwd,t);if(D(o))return o;let i=o,a=n.args??[],c=s.passthrough??[],f=n.pattern,l=[],d=0;if(f.length===0){if(a.length===0)return v("no pattern given");f.push(a[d++])}for(;d0)for(let q of l){let F=await At(i,q);if(D(F))return F;let _;try{_=await Oe(i,F)}catch{return v(`bad revision '${q}'`)}let Y=await M(i,_),V=await Jb(i,Y.tree);m.push({prefix:`${q}:`,files:V})}else if(n.cached)m.push({prefix:"",files:await Qb(i)});else{if(!i.workTree)return v("this operation must be run in a work tree");m.push({prefix:"",files:await Zb(i)})}let h=ut(i,r.cwd),p=null;c.length>0&&(p=c.map(q=>qe(q,h)));let g=n.maxDepth,w=n.maxCount,b=!!(n.lineNumber||n.afterContext!=null||n.beforeContext!=null||n.context!=null),y=!!n.filesWithMatches,C=!!n.filesWithoutMatch,x=!!n.count,k=!!n.quiet,P=!!n.heading,E=!!n.break,R=!!n.suppressFilename,O=!!n.invertMatch,$=!!n.allMatch,T=n.context??n.afterContext??0,j=n.context??n.beforeContext??0,U=T>0||j>0,G=[],L=!1,A=!0;for(let q of m){let F=q.files.slice().sort((_,Y)=>_.pathY.path?1:0);for(let _ of F){if(p&&!Pe(p,_.path)||g!==void 0&&ey(_.path)>g)continue;let Y=await _.getContent(),V=Xu(Y,u,$,O),ue=ty(_.path,h,!!n.fullName),Ce=q.prefix;if(V.binary){if(L=!0,k)return{stdout:"",stderr:"",exitCode:0};y?G.push(`${Ce}${ue}`):!C&&!x&&G.push(`Binary file ${Ce}${ue} matches`);continue}if(V.matches.length===0){C&&G.push(`${Ce}${ue}`);continue}if(L=!0,k)return{stdout:"",stderr:"",exitCode:0};if(C)continue;if(y){G.push(`${Ce}${ue}`);continue}if(x){let ae=w!==void 0?Math.min(V.matches.length,w):V.matches.length;G.push(`${Ce}${ue}:${ae}`);continue}let Qe=V.matches;if(w!==void 0&&(Qe=Qe.slice(0,w)),U)ny(G,Y,Qe,Ce,ue,R,j,T,P,E,A);else if(P){!A&&E&&G.push(""),G.push(`${Ce}${ue}`);for(let ae of Qe)b?G.push(`${ae.lineNo}:${ae.line}`):G.push(ae.line)}else{!A&&E&&G.push("");for(let ae of Qe){let J=R?"":`${Ce}${ue}:`;b?G.push(`${J}${ae.lineNo}:${ae.line}`):G.push(`${J}${ae.line}`)}}A=!1}}return k?{stdout:"",stderr:"",exitCode:L?0:1}:{stdout:G.length>0?`${G.join(` ++`)} ++`:"",stderr:"",exitCode:L?0:1}}})}function ny(e,t,n,r,s,o,i,a,c,f,l){let d=t.split(` ++`);d.length>0&&d[d.length-1]===""&&d.pop();let u=new Set(n.map(g=>g.lineNo)),m=[];for(let g of n){let w=Math.max(1,g.lineNo-i),b=Math.min(d.length,g.lineNo+a);m.push([w,b])}let h=[];for(let[g,w]of m)h.length>0&&g<=h[h.length-1][1]+1?h[h.length-1][1]=Math.max(h[h.length-1][1],w):h.push([g,w]);let p=o?"":`${r}${s}`;c?(!l&&f&&e.push(""),e.push(`${r}${s}`)):!l&&f&&e.push("");for(let g=0;g0&&e.push("--");let[w,b]=h[g];for(let y=w;y<=b;y++){let C=d[y-1],k=u.has(y)?":":"-";c?e.push(`${y}${k}${C}`):e.push(`${p}${k}${y}${k}${C}`)}}}te();ge();Nn();ke();function Ju(e,t){e.command("init",{description:"Initialize a new repository",args:[B.string().name("directory").describe("The directory to initialize").optional()],options:{bare:S().describe("Create a bare repository"),initialBranch:K.string().alias("b").describe("Name for the initial branch"),quiet:ce("be quiet")},examples:["git init","git init --bare","git init my-project"],handler:async(n,r)=>{let s=n.initialBranch??t?.configOverrides?.locked?.["init.defaultbranch"]??t?.configOverrides?.defaults?.["init.defaultbranch"],o=n.directory?Je(r.cwd,n.directory):r.cwd;n.directory&&await r.fs.mkdir(o,{recursive:!0});let{ctx:i,reinit:a}=await Wo(r.fs,o,{bare:n.bare,...s?{initialBranch:s}:{}}),c="";if(a&&s&&(c=`warning: re-init: ignored --initial-branch=${s} + `),n.quiet)return{stdout:"",stderr:c,exitCode:0};let f=n.bare?"bare ":"";return{stdout:`${a?"Reinitialized existing":"Initialized empty"} ${f}Git repository in ${i.gitDir}/ +-`,stderr:c,exitCode:0}}})}ne();fr();var Di=class{hash=null;parents=[];nParents=0;state=0;prevState=0;commitIdx=0;prevCommitIdx=0;mergeLayout=0;edgesAdded=0;prevEdgesAdded=0;w=0;expRow=0;cols=[];nCols=0;newCols=[];nNewCols=0;map=[];oldMap=[];mapSize=0;get width(){return this.w}update(t,n){this.hash=t,this.parents=n,this.nParents=n.length,this.prevCommitIdx=this.commitIdx,this.updateColumns(),this.expRow=0,this.state!==0?this.state=1:this.needsPreCommit()?this.state=2:this.state=3}nextLine(){let t,n=!1;switch(this.state){case 0:t=this.outPadding();break;case 1:t=this.outSkip();break;case 2:t=this.outPreCommit();break;case 3:t=this.outCommit(),n=!0;break;case 4:t=this.outPostMerge();break;case 5:t=this.outCollapsing();break}return{prefix:Bu(t,this.w),isCommitLine:n}}isFinished(){return this.state===0}paddingPrefix(){if(this.state!==3)return this.nextLine().prefix;let t="";for(let n=0;n1&&this.map[this.mapSize-1]<0;)this.mapSize--}findNewCol(t){for(let n=0;n1&&n>-1&&this.mergeLayout===-1){let s=n-r,i=s>1?2*s-3:1;this.mergeLayout=s>0?0:1,this.edgesAdded=this.nParents+this.mergeLayout-2,o=this.w+(this.mergeLayout-1)*i,this.w+=2*this.mergeLayout}else this.edgesAdded>0&&this.w>=2&&r===this.map[this.w-2]?(o=this.w-2,this.edgesAdded=-1):(o=this.w,this.w+=2);this.map[o]=r}setState(t){this.prevState=this.state,this.state=t}numDashedParents(){return this.nParents+this.mergeLayout-3}numExpansionRows(){return this.numDashedParents()*2}needsPreCommit(){return this.nParents>=3&&this.commitIdx>1)return!1}return!0}outPadding(){let t="";for(let n=0;n2&&(t+=this.drawOctopus())):n&&this.edgesAdded>1?t+="\\":n&&this.edgesAdded===1?this.prevState===4&&this.prevEdgesAdded>0&&this.prevCommitIdx1?this.setState(4):this.isMappingCorrect()?this.setState(0):this.setState(5),t}drawOctopus(){let t=this.numDashedParents(),n="";for(let r=0;r0||c0?n+="\\":n+="|",n+=" "):(n+="|",(this.mergeLayout!==0||s!==this.commitIdx-1)&&(o>=0?n+="_":n+=" "));i===this.parents[0]&&(o=s)}return this.isMappingCorrect()?this.setState(0):this.setState(5),n}outCollapsing(){let t=this.map;this.map=this.oldMap,this.oldMap=t,this.map.fill(-1,0,this.mapSize);let n=-1,r=-1;for(let i=0;i0&&this.map[this.mapSize-1]<0&&this.mapSize--;let o="",s=!1;for(let i=0;i=t?e:e+" ".repeat(t-e.length)}ne();function Br(e,t){let{hash:n,commit:r}=t,o=t.abbrev??Lt,s="",i=0;for(;i1&&this.map[this.mapSize-1]<0;)this.mapSize--}findNewCol(t){for(let n=0;n1&&n>-1&&this.mergeLayout===-1){let o=n-r,i=o>1?2*o-3:1;this.mergeLayout=o>0?0:1,this.edgesAdded=this.nParents+this.mergeLayout-2,s=this.w+(this.mergeLayout-1)*i,this.w+=2*this.mergeLayout}else this.edgesAdded>0&&this.w>=2&&r===this.map[this.w-2]?(s=this.w-2,this.edgesAdded=-1):(s=this.w,this.w+=2);this.map[s]=r}setState(t){this.prevState=this.state,this.state=t}numDashedParents(){return this.nParents+this.mergeLayout-3}numExpansionRows(){return this.numDashedParents()*2}needsPreCommit(){return this.nParents>=3&&this.commitIdx>1)return!1}return!0}outPadding(){let t="";for(let n=0;n2&&(t+=this.drawOctopus())):n&&this.edgesAdded>1?t+="\\":n&&this.edgesAdded===1?this.prevState===4&&this.prevEdgesAdded>0&&this.prevCommitIdx1?this.setState(4):this.isMappingCorrect()?this.setState(0):this.setState(5),t}drawOctopus(){let t=this.numDashedParents(),n="";for(let r=0;r0||c0?n+="\\":n+="|",n+=" "):(n+="|",(this.mergeLayout!==0||o!==this.commitIdx-1)&&(s>=0?n+="_":n+=" "));i===this.parents[0]&&(s=o)}return this.isMappingCorrect()?this.setState(0):this.setState(5),n}outCollapsing(){let t=this.map;this.map=this.oldMap,this.oldMap=t,this.map.fill(-1,0,this.mapSize);let n=-1,r=-1;for(let i=0;i0&&this.map[this.mapSize-1]<0&&this.mapSize--;let s="",o=!1;for(let i=0;i=t?e:e+" ".repeat(t-e.length)}te();function Kr(e,t){let{hash:n,commit:r}=t,s=t.abbrev??Nt,o="",i=0;for(;i=2&&c.push(`Merge: ${s.parents.map(i).join(" ")}`),c.push(`Author: ${s.author.name} <${s.author.email}>`),c.push(""),c.push(` ${Ac(s.message)}`),c.join(` +-`)}case"full":{let c=[];n||c.push(""),c.push(a?`commit ${o} ${a}`:`commit ${o}`),s.parents.length>=2&&c.push(`Merge: ${s.parents.map(i).join(" ")}`),c.push(`Author: ${s.author.name} <${s.author.email}>`),c.push(`Commit: ${s.committer.name} <${s.committer.email}>`),c.push("");let f=s.message.replace(/\n$/,"");for(let l of f.split(` ++`);return t===-1?"":e.slice(t+2).replace(/\n$/,"")}function Rs(e){return e.startsWith("format:")?{formatStr:e.slice(7),preset:null}:e.startsWith("tformat:")?{formatStr:e.slice(8),preset:null}:["oneline","short","medium","full","fuller","raw"].includes(e)?{formatStr:null,preset:e}:{formatStr:e,preset:null}}function wo(e,t,n,r=!1){let{hash:s,commit:o}=t,i=t.abbrev??Nt,a=t.decorations?t.decorations(s):"";switch(e){case"oneline":{let c=r?i(s):s,f=Bc(o.message);return a?`${c} ${a} ${f}`:`${c} ${f}`}case"short":{let c=[];return n||c.push(""),c.push(a?`commit ${s} ${a}`:`commit ${s}`),o.parents.length>=2&&c.push(`Merge: ${o.parents.map(i).join(" ")}`),c.push(`Author: ${o.author.name} <${o.author.email}>`),c.push(""),c.push(` ${Bc(o.message)}`),c.join(` ++`)}case"full":{let c=[];n||c.push(""),c.push(a?`commit ${s} ${a}`:`commit ${s}`),o.parents.length>=2&&c.push(`Merge: ${o.parents.map(i).join(" ")}`),c.push(`Author: ${o.author.name} <${o.author.email}>`),c.push(`Commit: ${o.committer.name} <${o.committer.email}>`),c.push("");let f=o.message.replace(/\n$/,"");for(let l of f.split(` + `))c.push(` ${l}`);return c.join(` +-`)}case"fuller":{let c=[];n||c.push(""),c.push(a?`commit ${o} ${a}`:`commit ${o}`),s.parents.length>=2&&c.push(`Merge: ${s.parents.map(i).join(" ")}`),c.push(`Author: ${s.author.name} <${s.author.email}>`),c.push(`AuthorDate: ${Mi(s.author.timestamp,s.author.timezone,t.dateMode)}`),c.push(`Commit: ${s.committer.name} <${s.committer.email}>`),c.push(`CommitDate: ${Mi(s.committer.timestamp,s.committer.timezone,t.dateMode)}`),c.push("");let f=s.message.replace(/\n$/,"");for(let l of f.split(` ++`)}case"fuller":{let c=[];n||c.push(""),c.push(a?`commit ${s} ${a}`:`commit ${s}`),o.parents.length>=2&&c.push(`Merge: ${o.parents.map(i).join(" ")}`),c.push(`Author: ${o.author.name} <${o.author.email}>`),c.push(`AuthorDate: ${qi(o.author.timestamp,o.author.timezone,t.dateMode)}`),c.push(`Commit: ${o.committer.name} <${o.committer.email}>`),c.push(`CommitDate: ${qi(o.committer.timestamp,o.committer.timezone,t.dateMode)}`),c.push("");let f=o.message.replace(/\n$/,"");for(let l of f.split(` + `))c.push(` ${l}`);return c.join(` +-`)}case"raw":return Lb(t,n);default:return Gb(t,n)}}function Lb(e,t){let{hash:n,commit:r}=e,o=[];t||o.push(""),o.push(`commit ${n}`),o.push(`tree ${r.tree}`);for(let i of r.parents)o.push(`parent ${i}`);o.push(`author ${r.author.name} <${r.author.email}> ${r.author.timestamp} ${r.author.timezone}`),o.push(`committer ${r.committer.name} <${r.committer.email}> ${r.committer.timestamp} ${r.committer.timezone}`),o.push("");let s=r.message.replace(/\n$/,"");for(let i of s.split(` +-`))o.push(` ${i}`);return o.join(` +-`)}function Gb(e,t){let{hash:n,commit:r}=e,o=e.abbrev??Lt,s=e.decorations?e.decorations(n):"",i=[];t||i.push(""),i.push(s?`commit ${n} ${s}`:`commit ${n}`),r.parents.length>=2&&i.push(`Merge: ${r.parents.map(o).join(" ")}`),i.push(`Author: ${r.author.name} <${r.author.email}>`),i.push(`Date: ${Mi(r.author.timestamp,r.author.timezone,e.dateMode)}`),i.push("");let a=r.message.replace(/\n$/,"");for(let c of a.split(` ++`)}case"raw":return sy(t,n);default:return oy(t,n)}}function sy(e,t){let{hash:n,commit:r}=e,s=[];t||s.push(""),s.push(`commit ${n}`),s.push(`tree ${r.tree}`);for(let i of r.parents)s.push(`parent ${i}`);s.push(`author ${r.author.name} <${r.author.email}> ${r.author.timestamp} ${r.author.timezone}`),s.push(`committer ${r.committer.name} <${r.committer.email}> ${r.committer.timestamp} ${r.committer.timezone}`),s.push("");let o=r.message.replace(/\n$/,"");for(let i of o.split(` ++`))s.push(` ${i}`);return s.join(` ++`)}function oy(e,t){let{hash:n,commit:r}=e,s=e.abbrev??Nt,o=e.decorations?e.decorations(n):"",i=[];t||i.push(""),i.push(o?`commit ${n} ${o}`:`commit ${n}`),r.parents.length>=2&&i.push(`Merge: ${r.parents.map(s).join(" ")}`),i.push(`Author: ${r.author.name} <${r.author.email}>`),i.push(`Date: ${qi(r.author.timestamp,r.author.timezone,e.dateMode)}`),i.push("");let a=r.message.replace(/\n$/,"");for(let c of a.split(` + `))i.push(` ${c}`);return i.join(` +-`)}var Wu=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],qu=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function Fb(e){let t=e.startsWith("-")?-1:1,n=e.replace(/^[+-]/,""),r=parseInt(n.slice(0,2),10)||0,o=parseInt(n.slice(2,4),10)||0;return t*(r*60+o)}function ji(e,t){let n=Fb(t);return new Date((e+n*60)*1e3)}function Nb(e){return`${e.slice(0,3)}:${e.slice(3)}`}function zu(e,t){let n=ji(e,t),r=n.getUTCFullYear(),o=String(n.getUTCMonth()+1).padStart(2,"0"),s=String(n.getUTCDate()).padStart(2,"0"),i=String(n.getUTCHours()).padStart(2,"0"),a=String(n.getUTCMinutes()).padStart(2,"0"),c=String(n.getUTCSeconds()).padStart(2,"0"),f=t==="+0000"||t==="-0000"?"Z":Nb(t);return`${r}-${o}-${s}T${i}:${a}:${c}${f}`}function Ku(e,t){let n=ji(e,t),r=n.getUTCFullYear(),o=String(n.getUTCMonth()+1).padStart(2,"0"),s=String(n.getUTCDate()).padStart(2,"0"),i=String(n.getUTCHours()).padStart(2,"0"),a=String(n.getUTCMinutes()).padStart(2,"0"),c=String(n.getUTCSeconds()).padStart(2,"0");return`${r}-${o}-${s} ${i}:${a}:${c} ${t}`}function Vu(e){let n=Math.floor(Date.now()/1e3)-e;if(n<0&&(n=0),n<90)return n===1?"1 second ago":`${n} seconds ago`;if(n=Math.round(n/60),n<90)return n===1?"1 minute ago":`${n} minutes ago`;if(n=Math.round(n/60),n<36)return n===1?"1 hour ago":`${n} hours ago`;if(n=Math.round(n/24),n<14)return n===1?"1 day ago":`${n} days ago`;if(n<70){let s=Math.round(n/7);return s===1?"1 week ago":`${s} weeks ago`}if(n<365){let s=Math.round(n/30);return s===1?"1 month ago":`${s} months ago`}let r=Math.floor(n/365),o=Math.round((n-r*365)/30);if(o>0){let s=r===1?"1 year":`${r} years`,i=o===1?"1 month":`${o} months`;return`${s}, ${i} ago`}return r===1?"1 year ago":`${r} years ago`}function Ub(e,t){let n=ji(e,t),r=n.getUTCFullYear(),o=String(n.getUTCMonth()+1).padStart(2,"0"),s=String(n.getUTCDate()).padStart(2,"0");return`${r}-${o}-${s}`}function _b(e,t){return`${e} ${t}`}function Bb(e){return e.toString()}function Wb(e,t){let n=new Date(e*1e3),r=Wu[n.getDay()]?.slice(0,3),o=qu[n.getMonth()],s=n.getDate(),i=String(n.getHours()).padStart(2,"0"),a=String(n.getMinutes()).padStart(2,"0"),c=String(n.getSeconds()).padStart(2,"0"),f=n.getFullYear();return`${r} ${o} ${s} ${i}:${a}:${c} ${f}`}function Mi(e,t,n){switch(n){case"short":return Ub(e,t);case"iso":return Ku(e,t);case"iso-strict":return zu(e,t);case"relative":case"human":return Vu(e);case"rfc":return Yu(e,t);case"raw":return _b(e,t);case"unix":return Bb(e);case"local":return Wb(e,t);default:return qn(e,t)}}function Yu(e,t){let n=ji(e,t),r=Wu[n.getUTCDay()]?.slice(0,3),o=qu[n.getUTCMonth()],s=n.getUTCDate(),i=String(n.getUTCHours()).padStart(2,"0"),a=String(n.getUTCMinutes()).padStart(2,"0"),c=String(n.getUTCSeconds()).padStart(2,"0"),f=n.getUTCFullYear();return`${r}, ${s} ${o} ${f} ${i}:${a}:${c} ${t}`}ae();ye();Qt();De();Ee();function Qu(e,t){e.command("log",{description:"Show commit logs",transformArgs:n=>n.map(r=>/^-(\d+)$/.test(r)?`-n${r.slice(1)}`:r),args:[W.string().name("revisions").variadic().optional()],options:{maxCount:K.number().alias("n").describe("Limit the number of commits to output"),oneline:S().describe("Condense each commit to a single line"),all:S().describe("Walk all refs, not just HEAD"),author:K.string().describe("Filter by author (regex or substring)"),grep:K.string().describe("Filter by commit message (regex or substring)"),since:K.string().describe("Show commits after date"),after:K.string().describe("Synonym for --since"),until:K.string().describe("Show commits before date"),before:K.string().describe("Synonym for --until"),decorate:S().describe("Show ref names next to commit hashes"),reverse:S().describe("Output commits in reverse order"),format:K.string().describe("Pretty-print format string"),pretty:K.string().describe("Pretty-print format or preset name"),patch:S().alias("p").describe("Show diff in patch format"),stat:S().describe("Show diffstat summary"),nameStatus:S().describe("Show names and status of changed files"),nameOnly:S().describe("Show only names of changed files"),shortstat:S().describe("Show only the shortstat summary line"),numstat:S().describe("Machine-readable insertions/deletions per file"),quiet:ce("suppress diff output"),graph:S().describe("Draw text-based graph of the commit history"),firstParent:S().describe("Follow only the first parent of merge commits"),skip:K.number().describe("Skip number of commits before starting to show output"),date:K.string().describe("Date format: short, iso, iso-strict, relative, rfc, raw, unix, local, human, default")},handler:async(n,r,o)=>{let s=await q(r.fs,r.cwd,t);if(D(s))return s;let i=s,a,c,f=n.revisions,l=f&&f.length===1?gs(f[0]):null;if(l){let J=async Ct=>{let an=await Le(i,Ct);if(!an)return Et(Ct);try{return await Se(i,an)}catch{return Et(Ct)}},re=await J(l.left);if(typeof re=="object"&&"exitCode"in re)return re;let Oe=await J(l.right);if(typeof Oe=="object"&&"exitCode"in Oe)return Oe;let xe=re,Xe=Oe;if(l.type==="two-dot")a=[Xe],c=[xe];else{a=[xe,Xe];let Ct=await ft(i,xe,Xe);c=Ct.length>0?Ct:void 0}if(n.all){let Ct=await $e(i);for(let Ze of Ct)try{let Zn=await Se(i,Ze.hash);a.includes(Zn)||a.push(Zn)}catch{}let an=await Z(i);an&&!a.includes(an)&&a.push(an);for(let Ze of await dc(i))a.includes(Ze)||a.push(Ze)}}else if(n.all){let J=await $e(i),re=new Set;for(let xe of J)try{re.add(await Se(i,xe.hash))}catch{}let Oe=await Z(i);Oe&&re.add(Oe);for(let xe of await dc(i))re.add(xe);a=[...re]}else if(f&&f.length>0){let J=[];for(let re of f){let Oe=await Le(i,re);if(!Oe)return Et(re);try{J.push(await Se(i,Oe))}catch{return Et(re)}}a=J}else{let J=await nt(i);if(D(J))return J;a=[J]}if(a.length===0)return v("your current branch does not have any commits yet");if(n.quiet&&(n.nameOnly||n.nameStatus))return v("options '--name-only', '--name-status', '--check', and '-s' cannot be used together");let d=o.passthrough.length>0?o.passthrough.map(J=>We(J,"")):null,u=n.author?Xu(n.author):null,m=n.grep?Xu(n.grep):null,h=n.since??n.after,p=n.until??n.before,g=h?ds(h):null,w=p?ds(p):null,b=n.format??n.pretty,R=null,C=null,x=!1;if(n.oneline)C="oneline",x=!0;else if(b!==void 0){let J=bs(b);R=J.formatStr,C=J.preset}let y=new Set(["default","short","iso","iso-strict","relative","rfc","raw","unix","local","human"]);if(n.date&&!y.has(n.date))return{stdout:"",stderr:`fatal: unknown date format ${n.date} +-`,exitCode:128};let P=n.date,k=n.patch?"patch":n.stat?"stat":n.nameStatus?"name-status":n.nameOnly?"name-only":n.shortstat?"shortstat":n.numstat?"numstat":null,E=n.graph;if(E&&n.reverse)return v("options '--graph' and '--reverse' cannot be used together");let $=n.decorate||R!=null&&(R.includes("%d")||R.includes("%D"))?await Kb(i):null,T=$?J=>Zu($,J):void 0,j=$?J=>{let re=Zu($,J);return re.startsWith("(")&&re.endsWith(")")?re.slice(1,-1):re}:void 0,U=n.maxCount,G=n.reverse,N=n.firstParent,A=d?zb(i,a,d,c?await qb(i,c):void 0,N):Ot(i,a,{exclude:c,topoOrder:E,firstParent:N}),H=[],B=n.skip??0;for await(let J of A){if(U!==void 0&&H.length>=U)break;let{commit:re}=J;if(!(w!==null&&re.committer.timestamp>w)&&!(g!==null&&re.committer.timestamp<=g)){if(u){let Oe=`${re.author.name} <${re.author.email}>`;if(!u(Oe))continue}if(!(m&&!m(re.message))){if(B>0){B--;continue}H.push(J)}}}let L=G?H.reverse():H,_={limit:await Rt(i,"diff")};if(E)return Vb(L,i,R,C,x,k,T,j,_,P);if(R!==null){let J=[];for(let re of L){let Oe={hash:re.hash,commit:re.commit,decorations:T,decorationsRaw:j,dateMode:P,abbrev:await en(i,[re.hash,re.commit.tree,...re.commit.parents])},xe=Br(R,Oe),Xe=await Hc(i,re.commit,k,_);Xe&&(xe+=` ++`)}var tm=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],nm=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function iy(e){let t=e.startsWith("-")?-1:1,n=e.replace(/^[+-]/,""),r=parseInt(n.slice(0,2),10)||0,s=parseInt(n.slice(2,4),10)||0;return t*(r*60+s)}function zi(e,t){let n=iy(t);return new Date((e+n*60)*1e3)}function ay(e){return`${e.slice(0,3)}:${e.slice(3)}`}function rm(e,t){let n=zi(e,t),r=n.getUTCFullYear(),s=String(n.getUTCMonth()+1).padStart(2,"0"),o=String(n.getUTCDate()).padStart(2,"0"),i=String(n.getUTCHours()).padStart(2,"0"),a=String(n.getUTCMinutes()).padStart(2,"0"),c=String(n.getUTCSeconds()).padStart(2,"0"),f=t==="+0000"||t==="-0000"?"Z":ay(t);return`${r}-${s}-${o}T${i}:${a}:${c}${f}`}function sm(e,t){let n=zi(e,t),r=n.getUTCFullYear(),s=String(n.getUTCMonth()+1).padStart(2,"0"),o=String(n.getUTCDate()).padStart(2,"0"),i=String(n.getUTCHours()).padStart(2,"0"),a=String(n.getUTCMinutes()).padStart(2,"0"),c=String(n.getUTCSeconds()).padStart(2,"0");return`${r}-${s}-${o} ${i}:${a}:${c} ${t}`}function om(e){let n=Math.floor(Date.now()/1e3)-e;if(n<0&&(n=0),n<90)return n===1?"1 second ago":`${n} seconds ago`;if(n=Math.round(n/60),n<90)return n===1?"1 minute ago":`${n} minutes ago`;if(n=Math.round(n/60),n<36)return n===1?"1 hour ago":`${n} hours ago`;if(n=Math.round(n/24),n<14)return n===1?"1 day ago":`${n} days ago`;if(n<70){let o=Math.round(n/7);return o===1?"1 week ago":`${o} weeks ago`}if(n<365){let o=Math.round(n/30);return o===1?"1 month ago":`${o} months ago`}let r=Math.floor(n/365),s=Math.round((n-r*365)/30);if(s>0){let o=r===1?"1 year":`${r} years`,i=s===1?"1 month":`${s} months`;return`${o}, ${i} ago`}return r===1?"1 year ago":`${r} years ago`}function cy(e,t){let n=zi(e,t),r=n.getUTCFullYear(),s=String(n.getUTCMonth()+1).padStart(2,"0"),o=String(n.getUTCDate()).padStart(2,"0");return`${r}-${s}-${o}`}function fy(e,t){return`${e} ${t}`}function ly(e){return e.toString()}function dy(e,t){let n=new Date(e*1e3),r=tm[n.getDay()]?.slice(0,3),s=nm[n.getMonth()],o=n.getDate(),i=String(n.getHours()).padStart(2,"0"),a=String(n.getMinutes()).padStart(2,"0"),c=String(n.getSeconds()).padStart(2,"0"),f=n.getFullYear();return`${r} ${s} ${o} ${i}:${a}:${c} ${f}`}function qi(e,t,n){switch(n){case"short":return cy(e,t);case"iso":return sm(e,t);case"iso-strict":return rm(e,t);case"relative":case"human":return om(e);case"rfc":return im(e,t);case"raw":return fy(e,t);case"unix":return ly(e);case"local":return dy(e,t);default:return zn(e,t)}}function im(e,t){let n=zi(e,t),r=tm[n.getUTCDay()]?.slice(0,3),s=nm[n.getUTCMonth()],o=n.getUTCDate(),i=String(n.getUTCHours()).padStart(2,"0"),a=String(n.getUTCMinutes()).padStart(2,"0"),c=String(n.getUTCSeconds()).padStart(2,"0"),f=n.getUTCFullYear();return`${r}, ${o} ${s} ${f} ${i}:${a}:${c} ${t}`}ie();ye();Ft();Te();ke();function fm(e,t){e.command("log",{description:"Show commit logs",transformArgs:n=>n.map(r=>/^-(\d+)$/.test(r)?`-n${r.slice(1)}`:r),args:[B.string().name("revisions").variadic().optional()],options:{maxCount:K.number().alias("n").describe("Limit the number of commits to output"),oneline:S().describe("Condense each commit to a single line"),all:S().describe("Walk all refs, not just HEAD"),author:K.string().describe("Filter by author (regex or substring)"),grep:K.string().describe("Filter by commit message (regex or substring)"),since:K.string().describe("Show commits after date"),after:K.string().describe("Synonym for --since"),until:K.string().describe("Show commits before date"),before:K.string().describe("Synonym for --until"),decorate:S().describe("Show ref names next to commit hashes"),reverse:S().describe("Output commits in reverse order"),format:K.string().describe("Pretty-print format string"),pretty:K.string().describe("Pretty-print format or preset name"),patch:S().alias("p").describe("Show diff in patch format"),stat:S().describe("Show diffstat summary"),nameStatus:S().describe("Show names and status of changed files"),nameOnly:S().describe("Show only names of changed files"),shortstat:S().describe("Show only the shortstat summary line"),numstat:S().describe("Machine-readable insertions/deletions per file"),summary:S().describe("Show creations, deletions, renames and mode changes"),quiet:ce("suppress diff output"),graph:S().describe("Draw text-based graph of the commit history"),firstParent:S().describe("Follow only the first parent of merge commits"),skip:K.number().describe("Skip number of commits before starting to show output"),date:K.string().describe("Date format: short, iso, iso-strict, relative, rfc, raw, unix, local, human, default")},handler:async(n,r,s)=>{let o=await W(r.fs,r.cwd,t);if(D(o))return o;let i=o,a,c,f=n.revisions,l=f&&f.length===1?ks(f[0]):null;if(l){let ae=async _e=>{let Zt=await Ie(i,_e);if(!Zt)return Ct(_e);try{return await Oe(i,Zt)}catch{return Ct(_e)}},J=await ae(l.left);if(typeof J=="object"&&"exitCode"in J)return J;let je=await ae(l.right);if(typeof je=="object"&&"exitCode"in je)return je;let at=J,vt=je;if(l.type==="two-dot")a=[vt],c=[at];else{a=[at,vt];let _e=await mt(i,at,vt);c=_e.length>0?_e:void 0}if(n.all){let _e=await $e(i);for(let Cr of _e)try{let xs=await Oe(i,Cr.hash);a.includes(xs)||a.push(xs)}catch{}let Zt=await Z(i);Zt&&!a.includes(Zt)&&a.push(Zt);for(let Cr of await Ec(i))a.includes(Cr)||a.push(Cr)}}else if(n.all){let ae=await $e(i),J=new Set;for(let at of ae)try{J.add(await Oe(i,at.hash))}catch{}let je=await Z(i);je&&J.add(je);for(let at of await Ec(i))J.add(at);a=[...J]}else if(f&&f.length>0){let ae=[];for(let J of f){let je=await Ie(i,J);if(!je)return Ct(J);try{ae.push(await Oe(i,je))}catch{return Ct(J)}}a=ae}else{let ae=await nt(i);if(D(ae))return ae;a=[ae]}if(a.length===0)return v("your current branch does not have any commits yet");if(n.quiet&&(n.nameOnly||n.nameStatus))return v("options '--name-only', '--name-status', '--check', and '-s' cannot be used together");let d=s.passthrough.length>0?s.passthrough.map(ae=>qe(ae,"")):null,u=n.author?am(n.author):null,m=n.grep?am(n.grep):null,h=n.since??n.after,p=n.until??n.before,g=h?hs(h):null,w=p?hs(p):null,b=n.format??n.pretty,y=null,C=null,x=!1;if(n.oneline)C="oneline",x=!0;else if(b!==void 0){let ae=Rs(b);y=ae.formatStr,C=ae.preset}let k=new Set(["default","short","iso","iso-strict","relative","rfc","raw","unix","local","human"]);if(n.date&&!k.has(n.date))return{stdout:"",stderr:`fatal: unknown date format ${n.date} ++`,exitCode:128};let P=n.date,E=n.patch?"patch":n.stat?"stat":n.nameStatus?"name-status":n.nameOnly?"name-only":n.shortstat?"shortstat":n.numstat?"numstat":null,R=n.summary&&E!=="name-only"&&E!=="name-status",O=E||R?{format:E,summary:R}:null,$=n.graph;if($&&n.reverse)return v("options '--graph' and '--reverse' cannot be used together");let j=n.decorate||y!=null&&(y.includes("%d")||y.includes("%D"))?await hy(i):null,U=j?ae=>cm(j,ae):void 0,G=j?ae=>{let J=cm(j,ae);return J.startsWith("(")&&J.endsWith(")")?J.slice(1,-1):J}:void 0,L=n.maxCount,A=n.reverse,H=n.firstParent,q=d?my(i,a,d,c?await uy(i,c):void 0,H):St(i,a,{exclude:c,topoOrder:$,firstParent:H}),F=[],_=n.skip??0;for await(let ae of q){if(L!==void 0&&F.length>=L)break;let{commit:J}=ae;if(!(w!==null&&J.committer.timestamp>w)&&!(g!==null&&J.committer.timestamp<=g)){if(u){let je=`${J.author.name} <${J.author.email}>`;if(!u(je))continue}if(!(m&&!m(J.message))){if(_>0){_--;continue}F.push(ae)}}}let Y=A?F.reverse():F,V={limit:await xt(i,"diff")};if($)return py(Y,i,y,C,x,O,U,G,V,P);if(y!==null){let ae=[];for(let J of Y){let je={hash:J.hash,commit:J.commit,decorations:U,decorationsRaw:G,dateMode:P,abbrev:await sn(i,[J.hash,J.commit.tree,...J.commit.parents])},at=Kr(y,je),vt=await Wc(i,J.commit,O,V);vt!==null&&(at+=` + +-${Xe.replace(/\n$/,"")}`),J.push(xe)}return{stdout:J.length>0?`${J.join(` ++${vt}`.replace(/\n$/,"")),ae.push(at)}return{stdout:ae.length>0?`${ae.join(` + `)} +-`:"",stderr:mt("diff",_.needed),exitCode:0}}let V=C??"medium",Y=V==="oneline",fe=[];for(let J=0;J0?`${fe.join(` +-`)} +-`:"",stderr:mt("diff",_.needed),exitCode:0}}})}async function qb(e,t){let n=new Set;for await(let r of Ot(e,t))n.add(r.hash);return n}function Xu(e){try{let t=new RegExp(e);return n=>t.test(n)}catch{return t=>t.includes(e)}}async function*zb(e,t,n,r,o){let s=new Set(r),i=new vn,a=async c=>{if(!s.has(c))try{let f=await M(e,c);i.push({hash:c,commit:f})}catch{}};for(let c of t)await a(c);for(;i.size>0;){let c=i.pop();if(s.has(c.hash))continue;s.add(c.hash);let{commit:f}=c,l=o?f.parents.slice(0,1):f.parents;if(l.length===0){(await Ke(e,null,f.tree)).some(m=>Pe(n,m.path))&&(yield c);continue}if(l.length===1){let u=l[0];if(u){try{let m=await M(e,u);(await Ke(e,m.tree,f.tree)).some(p=>Pe(n,p.path))&&(yield c)}catch{yield c}await a(u)}continue}let d=[];for(let u of l)try{let m=await M(e,u);(await Ke(e,m.tree,f.tree)).some(p=>Pe(n,p.path))||d.push(u)}catch{}if(d.length>0&&d[0])await a(d[0]);else{yield c;for(let u of l)await a(u)}}}async function Kb(e){let t=await te(e),n=t?.type==="symbolic"?Ie(t.target):null,r=await Z(e),o=new Map,s=(f,l,d)=>{let u=o.get(f);u||(u=[],o.set(f,u)),u.push({label:l,fullRef:d})},i=await $e(e,"refs/heads");for(let f of i)s(f.hash,Ie(f.name),f.name);let a=await $e(e,"refs/remotes");for(let f of a)s(f.hash,f.name.replace("refs/remotes/",""),f.name);let c=await $e(e,"refs/tags");for(let f of c){let l=f.hash;try{l=await Se(e,f.hash)}catch{}s(l,`tag: ${f.name.replace("refs/tags/","")}`,f.name)}return{headTarget:n,headHash:r,byHash:o}}function Zu(e,t){let n=e.byHash.get(t),r=!e.headTarget&&e.headHash!==null&&e.headHash===t;if((!n||n.length===0)&&!r)return"";let o=[],s=e.headTarget&&n?n.find(a=>a.label===e.headTarget):null;s?o.push(`HEAD -> ${s.label}`):r&&o.push("HEAD");let i=n?n.filter(a=>a!==s):[];i.sort((a,c)=>a.fullRef>c.fullRef?-1:a.fullRef0?`(${o.join(", ")})`:""}async function Vb(e,t,n,r,o,s,i,a,c,f){let l=new Di,d=r??"medium",u=d==="oneline",m=[];for(let h=0;h0&&!u&&n===null&&m.push(l.paddingPrefix());let b=w.split(` +-`),R=0;for(;;){let{prefix:y,isCommitLine:P}=l.nextLine();if(P){m.push(y+(b[R++]??""));break}m.push(y)}for(;R0?`${m.join(` +-`)} +-`:"",stderr:mt("diff",c.needed),exitCode:0}}async function Hc(e,t,n,r,o){if(!n||t.parents.length>=2)return"";let s=t.parents.length===1?(await M(e,t.parents[0])).tree:null,i=await Ke(e,s,t.tree),{remaining:a,renames:c,neededRenameLimit:f}=await ht(e,i,{limit:r.limit});switch(r.needed=Math.max(r.needed??0,f??0)||void 0,n){case"name-only":return Yb(a,c);case"name-status":return Xb(a,c);case"stat":return Zb(e,a,c,o);case"shortstat":return Qb(e,a,c);case"numstat":return Jb(e,a,c);case"patch":return ey(e,a,c)}}function Yb(e,t){let n=[];for(let r of e)n.push({key:r.path,line:r.path});for(let r of t)n.push({key:r.newPath,line:r.newPath});return n.sort((r,o)=>r.keyo.key?1:0),n.map(r=>`${r.line} +-`).join("")}function Xb(e,t){let n=[];for(let r of e){let o=r.status==="added"?"A":r.status==="deleted"?"D":"M";n.push({key:r.path,line:`${o} ${r.path}`})}for(let r of t){let o=String(r.similarity??100).padStart(3,"0");n.push({key:r.newPath,line:`R${o} ${r.oldPath} ${r.newPath}`})}return n.sort((r,o)=>r.keyo.key?1:0),n.map(r=>`${r.line} +-`).join("")}async function Zb(e,t,n,r){let{fileStats:o}=await kr(e,t,n);return o.sort((s,i)=>s.sortKeyi.sortKey?1:0),jr(o,r)}async function Qb(e,t,n){let{fileStats:r}=await kr(e,t,n),o=0,s=0;for(let a of r)o+=a.insertions,s+=a.deletions;let i=yr(r.length,o,s);return i?`${i} +-`:""}async function Jb(e,t,n){let r=[];for(let s of t)r.push({key:s.path,oldHash:s.oldHash,newHash:s.newHash,display:s.path});for(let s of n)r.push({key:s.newPath,oldHash:s.oldHash,newHash:s.newHash,display:In(s.oldPath,s.newPath)});r.sort((s,i)=>s.keyi.key?1:0);let o="";for(let s of r){let i=s.oldHash?await le(e,s.oldHash):"",a=s.newHash?await le(e,s.newHash):"";if(Ne(i)||Ne(a))o+=`- - ${s.display} +-`;else{let c=Ht(i),f=Ht(a),l=gt(c,f),d=0,u=0;for(let m of l)m.type==="insert"?d++:m.type==="delete"&&u++;o+=`${d} ${u} ${s.display} +-`}}return o}async function ey(e,t,n){let r=[];for(let s of t)r.push({type:"diff",entry:s});for(let s of n)r.push({type:"rename",entry:s});r.sort((s,i)=>{let a=s.type==="diff"?s.entry.path:s.entry.newPath,c=i.type==="diff"?i.entry.path:i.entry.newPath;return ac?1:0});let o="";for(let s of r)if(s.type==="rename"){let i=s.entry,a=i.oldHash?await le(e,i.oldHash):"",c=i.newHash?await le(e,i.newHash):"";o+=Wt({path:i.oldPath,oldContent:a,newContent:c,oldMode:i.oldMode,newMode:i.newMode,oldHash:i.oldHash,newHash:i.newHash,renameTo:i.newPath,similarity:i.similarity})}else{let i=s.entry,a=i.oldHash?await le(e,i.oldHash):"",c=i.newHash?await le(e,i.newHash):"";o+=Wt({path:i.path,oldContent:a,newContent:c,oldMode:i.oldMode,newMode:i.newMode,oldHash:i.oldHash,newHash:i.newHash,isNew:i.status==="added",isDeleted:i.status==="deleted"})}return o}ne();ve();ge();ir();cn();st();Ee();function em(e,t){e.command("ls-files",{description:"Show information about files in the index and the working tree",args:[W.string().name("pathspec").variadic().optional()],options:{cached:S().alias("c").describe("Show cached files (default)"),modified:S().alias("m").describe("Show modified files"),deleted:S().alias("d").describe("Show deleted files"),others:S().alias("o").describe("Show other (untracked) files"),unmerged:S().alias("u").describe("Show unmerged files"),stage:S().alias("s").describe("Show staged contents' mode, hash, and stage number"),"exclude-standard":S().describe("Add standard git exclusions (.gitignore, info/exclude, core.excludesFile)"),"nul-terminate":S().alias("z").describe("Use \\0 as line terminator instead of \\n"),"show-tags":S().alias("t").describe("Show status tags")},handler:async(n,r,o)=>{let s=await q(r.fs,r.cwd,t);if(D(s))return s;let i=s,a=tt(i);if(a)return a;let c=i.workTree,f=n.cached,l=n.modified,d=n.deleted,u=n.others,m=n.unmerged,h=n.stage,p=n["exclude-standard"],g=n["nul-terminate"],w=n["show-tags"];f||l||d||u||m||(f=!0);let R=await X(i),C=g?"\0":` +-`,x=[...n.pathspec??[],...o.passthrough],y=x.length>0?x.map(E=>{let O=r.cwd!==c?ty(c,r.cwd):"";return We(E,O)}):null,P=[];if(f)for(let E of R.entries){if(y&&!Pe(y,E.path))continue;let O=w?E.stage>0?"M":"H":null;P.push(Ju(E,h,O))}if(m&&!f)for(let E of R.entries)E.stage!==0&&(y&&!Pe(y,E.path)||P.push(Ju(E,!0,w?"M":null)));if(l||d){let E=await ny(i,c,R);for(let{path:O,status:$}of E){if($==="modified"&&!l||$==="deleted"&&!d||y&&!Pe(y,O))continue;let T=w?$==="deleted"?"R":"C":null;P.push(T?`${T} ${O}`:O)}}if(u){let E=await ry(i,c,R,p);for(let O of E)y&&!Pe(y,O)||P.push(w?`? ${O}`:O)}return{stdout:P.length>0?P.join(C)+C:"",stderr:"",exitCode:0}}})}function Ju(e,t,n){if(t){let r=e.mode.toString(8).padStart(6,"0");return`${n?`${n} `:""}${r} ${e.hash} ${e.stage} ${e.path}`}return n?`${n} ${e.path}`:e.path}function ty(e,t){return t===e?"":t.startsWith(`${e}/`)?t.slice(e.length+1):""}async function ny(e,t,n){let r=[];for(let o of n.entries){if(o.stage!==0)continue;let s=I(t,o.path);if(!await e.fs.exists(s)){r.push({path:o.path,status:"deleted"});continue}let a=await Je(e.fs,s);if(!a.isFile&&!a.isSymbolicLink)continue;await $t(e,s,o.hash)!==o.hash&&r.push({path:o.path,status:"modified"})}return r}async function ry(e,t,n,r){let o=new Set(n.entries.map(i=>i.path));return(await ut(e,t,"",{skipIgnore:!r})).filter(i=>!o.has(i))}ne();fr();Be();ve();ae();Ve();ye();Qt();De();Ee();var sy=`usage: git merge [] [...] ++`}${vt}`.replace(/\n$/,"")),Qe.push(at)}return{stdout:Qe.length>0?`${Qe.join(` ++`)} ++`:"",stderr:wt("diff",V.needed),exitCode:0}}})}async function uy(e,t){let n=new Set;for await(let r of St(e,t))n.add(r.hash);return n}function am(e){try{let t=new RegExp(e);return n=>t.test(n)}catch{return t=>t.includes(e)}}async function*my(e,t,n,r,s){let o=new Set(r),i=new Hn,a=async c=>{if(!o.has(c))try{let f=await M(e,c);i.push({hash:c,commit:f})}catch{}};for(let c of t)await a(c);for(;i.size>0;){let c=i.pop();if(o.has(c.hash))continue;o.add(c.hash);let{commit:f}=c,l=s?f.parents.slice(0,1):f.parents;if(l.length===0){(await Ve(e,null,f.tree)).some(m=>Pe(n,m.path))&&(yield c);continue}if(l.length===1){let u=l[0];if(u){try{let m=await M(e,u);(await Ve(e,m.tree,f.tree)).some(p=>Pe(n,p.path))&&(yield c)}catch{yield c}await a(u)}continue}let d=[];for(let u of l)try{let m=await M(e,u);(await Ve(e,m.tree,f.tree)).some(p=>Pe(n,p.path))||d.push(u)}catch{}if(d.length>0&&d[0])await a(d[0]);else{yield c;for(let u of l)await a(u)}}}async function hy(e){let t=await ne(e),n=t?.type==="symbolic"?ve(t.target):null,r=await Z(e),s=new Map,o=(f,l,d)=>{let u=s.get(f);u||(u=[],s.set(f,u)),u.push({label:l,fullRef:d})},i=await $e(e,"refs/heads");for(let f of i)o(f.hash,ve(f.name),f.name);let a=await $e(e,"refs/remotes");for(let f of a)o(f.hash,f.name.replace("refs/remotes/",""),f.name);let c=await $e(e,"refs/tags");for(let f of c){let l=f.hash;try{l=await Oe(e,f.hash)}catch{}o(l,`tag: ${f.name.replace("refs/tags/","")}`,f.name)}return{headTarget:n,headHash:r,byHash:s}}function cm(e,t){let n=e.byHash.get(t),r=!e.headTarget&&e.headHash!==null&&e.headHash===t;if((!n||n.length===0)&&!r)return"";let s=[],o=e.headTarget&&n?n.find(a=>a.label===e.headTarget):null;o?s.push(`HEAD -> ${o.label}`):r&&s.push("HEAD");let i=n?n.filter(a=>a!==o):[];i.sort((a,c)=>a.fullRef>c.fullRef?-1:a.fullRef0?`(${s.join(", ")})`:""}async function py(e,t,n,r,s,o,i,a,c,f){let l=new Wi,d=r??"medium",u=d==="oneline",m=[];for(let h=0;h0&&!u&&n===null&&m.push(l.paddingPrefix());let b=w.split(` ++`),y=0;for(;;){let{prefix:k,isCommitLine:P}=l.nextLine();if(P){m.push(k+(b[y++]??""));break}m.push(k)}for(;y0?`${m.join(` ++`)} ++`:"",stderr:wt("diff",c.needed),exitCode:0}}async function Wc(e,t,n,r,s){if(!n||t.parents.length>=2)return null;let o=t.parents.length===1?(await M(e,t.parents[0])).tree:null,i=await Ve(e,o,t.tree),{remaining:a,renames:c,neededRenameLimit:f}=await bt(e,i,{limit:r.limit});if(r.needed=Math.max(r.needed??0,f??0)||void 0,a.length===0&&c.length===0)return null;let l=await gy(e,a,c,n.format,s);return n.summary?ro(l,Er(a,c),n.format==="patch"):l}async function gy(e,t,n,r,s){switch(r){case"name-only":return wy(t,n);case"name-status":return by(t,n);case"stat":return yy(e,t,n,s);case"shortstat":return ky(e,t,n);case"numstat":return Ey(e,t,n);case"patch":return Ry(e,t,n);case null:return""}}function wy(e,t){let n=[];for(let r of e)n.push({key:r.path,line:r.path});for(let r of t)n.push({key:r.newPath,line:r.newPath});return n.sort((r,s)=>r.keys.key?1:0),n.map(r=>`${r.line} ++`).join("")}function by(e,t){let n=[];for(let r of e){let s=r.status==="added"?"A":r.status==="deleted"?"D":"M";n.push({key:r.path,line:`${s} ${r.path}`})}for(let r of t){let s=String(r.similarity??100).padStart(3,"0");n.push({key:r.newPath,line:`R${s} ${r.oldPath} ${r.newPath}`})}return n.sort((r,s)=>r.keys.key?1:0),n.map(r=>`${r.line} ++`).join("")}async function yy(e,t,n,r){let s=await kr(e,t,n);return s.sort((o,i)=>o.sortKeyi.sortKey?1:0),Nr(s,r)}async function ky(e,t,n){let r=await kr(e,t,n),s=0,o=0;for(let a of r)s+=a.insertions,o+=a.deletions;let i=yr(r.length,s,o);return i?`${i} ++`:""}async function Ey(e,t,n){let r=[];for(let o of t)r.push({key:o.path,oldHash:o.oldHash,newHash:o.newHash,display:o.path});for(let o of n)r.push({key:o.newPath,oldHash:o.oldHash,newHash:o.newHash,display:Dn(o.oldPath,o.newPath)});r.sort((o,i)=>o.keyi.key?1:0);let s="";for(let o of r){let i=o.oldHash?await le(e,o.oldHash):"",a=o.newHash?await le(e,o.newHash):"";if(Fe(i)||Fe(a))s+=`- - ${o.display} ++`;else{let c=Mt(i),f=Mt(a),l=kt(c,f),d=0,u=0;for(let m of l)m.type==="insert"?d++:m.type==="delete"&&u++;s+=`${d} ${u} ${o.display} ++`}}return s}async function Ry(e,t,n){let r=[];for(let o of t)r.push({type:"diff",entry:o});for(let o of n)r.push({type:"rename",entry:o});r.sort((o,i)=>{let a=o.type==="diff"?o.entry.path:o.entry.newPath,c=i.type==="diff"?i.entry.path:i.entry.newPath;return ac?1:0});let s="";for(let o of r)if(o.type==="rename"){let i=o.entry,a=i.oldHash?await le(e,i.oldHash):"",c=i.newHash?await le(e,i.newHash):"";s+=Kt({path:i.oldPath,oldContent:a,newContent:c,oldMode:i.oldMode,newMode:i.newMode,oldHash:i.oldHash,newHash:i.newHash,renameTo:i.newPath,similarity:i.similarity})}else{let i=o.entry,a=i.oldHash?await le(e,i.oldHash):"",c=i.newHash?await le(e,i.newHash):"";s+=Kt({path:i.path,oldContent:a,newContent:c,oldMode:i.oldMode,newMode:i.newMode,oldHash:i.oldHash,newHash:i.newHash,isNew:i.status==="added",isDeleted:i.status==="deleted"})}return s}te();Se();ge();ir();un();ot();ke();function dm(e,t){e.command("ls-files",{description:"Show information about files in the index and the working tree",args:[B.string().name("pathspec").variadic().optional()],options:{cached:S().alias("c").describe("Show cached files (default)"),modified:S().alias("m").describe("Show modified files"),deleted:S().alias("d").describe("Show deleted files"),others:S().alias("o").describe("Show other (untracked) files"),unmerged:S().alias("u").describe("Show unmerged files"),stage:S().alias("s").describe("Show staged contents' mode, hash, and stage number"),"exclude-standard":S().describe("Add standard git exclusions (.gitignore, info/exclude, core.excludesFile)"),"nul-terminate":S().alias("z").describe("Use \\0 as line terminator instead of \\n"),"show-tags":S().alias("t").describe("Show status tags")},handler:async(n,r,s)=>{let o=await W(r.fs,r.cwd,t);if(D(o))return o;let i=o,a=tt(i);if(a)return a;let c=i.workTree,f=n.cached,l=n.modified,d=n.deleted,u=n.others,m=n.unmerged,h=n.stage,p=n["exclude-standard"],g=n["nul-terminate"],w=n["show-tags"];f||l||d||u||m||(f=!0);let y=await X(i),C=g?"\0":` ++`,x=[...n.pathspec??[],...s.passthrough],k=x.length>0?x.map(R=>{let O=r.cwd!==c?Cy(c,r.cwd):"";return qe(R,O)}):null,P=[];if(f)for(let R of y.entries){if(k&&!Pe(k,R.path))continue;let O=w?R.stage>0?"M":"H":null;P.push(lm(R,h,O))}if(m&&!f)for(let R of y.entries)R.stage!==0&&(k&&!Pe(k,R.path)||P.push(lm(R,!0,w?"M":null)));if(l||d){let R=await xy(i,c,y);for(let{path:O,status:$}of R){if($==="modified"&&!l||$==="deleted"&&!d||k&&!Pe(k,O))continue;let T=w?$==="deleted"?"R":"C":null;P.push(T?`${T} ${O}`:O)}}if(u){let R=await Py(i,c,y,p);for(let O of R)k&&!Pe(k,O)||P.push(w?`? ${O}`:O)}return{stdout:P.length>0?P.join(C)+C:"",stderr:"",exitCode:0}}})}function lm(e,t,n){if(t){let r=e.mode.toString(8).padStart(6,"0");return`${n?`${n} `:""}${r} ${e.hash} ${e.stage} ${e.path}`}return n?`${n} ${e.path}`:e.path}function Cy(e,t){return t===e?"":t.startsWith(`${e}/`)?t.slice(e.length+1):""}async function xy(e,t,n){let r=[];for(let s of n.entries){if(s.stage!==0)continue;let o=I(t,s.path);if(!await e.fs.exists(o)){r.push({path:s.path,status:"deleted"});continue}let a=await Ye(e.fs,o);if(!a.isFile&&!a.isSymbolicLink)continue;await Ot(e,o,s.hash)!==s.hash&&r.push({path:s.path,status:"modified"})}return r}async function Py(e,t,n,r){let s=new Set(n.entries.map(i=>i.path));return(await gt(e,t,"",{skipIgnore:!r})).filter(i=>!s.has(i))}te();ie();On();Ar();Bs();ge();Ft();Te();Bo();ke();var $y=`usage: git ls-tree [] [...] ++`;function um(e,t){e.command("ls-tree",{description:"List the contents of a tree object",args:[B.string().name("tree-ish").describe("Tree, commit or tag to list").optional(),B.string().name("path").variadic().optional()],options:{treesOnly:S().alias("d").describe("Only show trees"),recursive:S().alias("r").describe("Recurse into subtrees"),showTrees:S().alias("t").describe("Show trees when recursing"),nulTerminate:S().alias("z").describe("Terminate entries with NUL byte"),nameOnly:S().describe("List only filenames"),nameStatus:S().describe("List only filenames"),fullTree:S().describe("List entire tree; not just current directory"),abbrev:K.number().impliedValue(String(ri)).describe("Use digits to display object names")},handler:async(n,r,s)=>{let o=await W(r.fs,r.cwd,t);if(D(o))return o;let i=o,[a,...c]=n["tree-ish"]===void 0?s.passthrough:[n["tree-ish"],...n.path??[],...s.passthrough];if(a===void 0)return{stdout:"",stderr:$y,exitCode:129};let f=ut(i,r.cwd),l=await Oy(i,a,f);if(typeof l!="string")return v(l.error);if(c.includes(""))return v("empty string is not a valid pathspec. please use . instead if you meant to match all paths");let d=n.fullTree?"":f,u=[];for(let b of c){let y=Sy(b,d,i.workTree);if(y===null)return v(`${b}: '${b}' is outside repository at '${i.workTree??i.gitDir}'`);u.push(y)}u.length===0&&d!==""&&u.push({path:d,listContents:!0});let m=await mm(i,l);if(!m)return v("not a tree object");let h=[];await hm(i,m,"",h,{recursive:n.recursive,showTrees:n.showTrees||n.recursive&&n.treesOnly,treesOnly:n.treesOnly,filters:u});let p=n.nameOnly||n.nameStatus,g=n.nulTerminate?"\0":` ++`,w="";for(let b of h){let y=Iy(d,b.path),C=n.nulTerminate?y:Hy(y);if(p){w+=C+g;continue}let x=n.abbrev?await fe(i,b.hash,n.abbrev):b.hash;w+=`${b.mode} ${Ty(b.mode)} ${x} ${C}${g}`}return{stdout:w,stderr:"",exitCode:0}}})}async function Oy(e,t,n){let r={error:`Not a valid object name ${t}`},s=t.indexOf(":");if(s<0)return await Ie(e,t)??r;let o=t.slice(0,s);if(o==="")return r;let i=await Ie(e,o);if(!i)return r;let a=await mm(e,i);if(!a)return r;let c=t.slice(s+1),f=c;if((f.startsWith("./")||f.startsWith("../"))&&(f=I(n,f),f==="."&&(f=""),f===".."||f.startsWith("../")))return{error:`'${c}' is outside repository at '${e.workTree??e.gitDir}'`};if(f.endsWith("/")&&(f=f.slice(0,-1)),f==="")return a;for(let l of f.split("/")){if(l===""||l==="."||l==="..")return r;let d=await me(e,a);if(d.type!=="tree")return r;let u=bn(d.content).entries.find(m=>m.name===l);if(!u)return r;a=u.hash}return a}async function mm(e,t){let n=t;for(;;){let r=await me(e,n);if(r.type==="tree")return n;if(r.type==="commit")return en(r.content).tree;if(r.type!=="tag")return null;n=Lt(r.content).object}}function Sy(e,t,n){let r=e.endsWith("/")||/(^|\/)\.\.?$/.test(e),s;if(e.startsWith("/")){if(!n)return null;s=rt(n,e)}else s=I(t,e);return s=s.replace(/\/$/,""),s==="."&&(s=""),s===".."||s.startsWith("../")?null:{path:s,listContents:r||s===""}}async function hm(e,t,n,r,s){for(let o of await Ko(e,t)){let i=n?`${n}/${o.name}`:o.name;if(!(s.filters.length>0&&!s.filters.some(a=>vy(a,i,o.mode)))){if(o.mode===ht.DIRECTORY){let a=s.recursive||s.filters.some(c=>c.path.startsWith(`${i}/`)||c.listContents&&c.path===i);(!a||s.showTrees)&&r.push({...o,path:i}),a&&await hm(e,o.hash,i,r,s);continue}s.treesOnly&&o.mode!==ht.SUBMODULE||r.push({...o,path:i})}}}function vy(e,t,n){return e.path===""||t.startsWith(`${e.path}/`)?!0:t===e.path?!e.listContents||n===ht.DIRECTORY||n===ht.SUBMODULE:n===ht.DIRECTORY&&e.path.startsWith(`${t}/`)}function Iy(e,t){if(!e)return t;let n=rt(e,t)||".";return e===t||e.startsWith(`${t}/`)?`${n}/`:n}function Ty(e){return e===ht.DIRECTORY?"tree":e===ht.SUBMODULE?"commit":"blob"}var Ay={7:"\\a",8:"\\b",9:"\\t",10:"\\n",11:"\\v",12:"\\f",13:"\\r",34:'\\"',92:"\\\\"};function Hy(e){let t=new TextEncoder().encode(e),n="",r=!1;for(let s of t){let o=Ay[s];o?(n+=o,r=!0):s<32||s>=127?(n+=`\\${s.toString(8).padStart(3,"0")}`,r=!0):n+=String.fromCharCode(s)}return r?`"${n}"`:e}te();fr();We();Se();ie();Xe();ye();Ft();Te();ke();var Dy=`usage: git merge [] [...] + or: git merge --abort + or: git merge --continue +-`;function nm(e,t){e.command("merge",{description:"Join two or more development histories together",args:[W.string().name("branch").describe("Branch to merge into the current branch").optional()],options:{abort:S().describe("Abort the current in-progress merge"),continue:S().describe("Continue the merge after conflict resolution"),noFf:S().describe("Create a merge commit even when fast-forward is possible"),ffOnly:S().describe("Refuse to merge unless fast-forward is possible"),squash:S().describe("Apply merge result to worktree/index without creating a merge commit"),edit:S().describe("Edit the merge message (no-op, accepted for compatibility)"),message:K.string().alias("m").describe("Merge commit message"),quiet:ce("be more quiet")},transformArgs:n=>n.filter(r=>r!=="--ff"),handler:async(n,r)=>{let o=await q(r.fs,r.cwd,t);if(D(o))return o;let s=o;if((n.abort||n.continue)&&(n.abort&&n.continue||n.branch!==void 0||n.noFf||n.ffOnly||n.squash||n.edit||n.message!==void 0||n.quiet))return{stdout:"",stderr:`fatal: ${n.abort?"--abort":"--continue"} expects no arguments ++`;function gm(e,t){e.command("merge",{description:"Join two or more development histories together",args:[B.string().name("branch").describe("Branch to merge into the current branch").optional()],options:{abort:S().describe("Abort the current in-progress merge"),continue:S().describe("Continue the merge after conflict resolution"),noFf:S().describe("Create a merge commit even when fast-forward is possible"),ffOnly:S().describe("Refuse to merge unless fast-forward is possible"),squash:S().describe("Apply merge result to worktree/index without creating a merge commit"),edit:S().describe("Edit the merge message (no-op, accepted for compatibility)"),message:K.string().alias("m").describe("Merge commit message"),quiet:ce("be more quiet")},transformArgs:n=>n.filter(r=>r!=="--ff"),handler:async(n,r)=>{let s=await W(r.fs,r.cwd,t);if(D(s))return s;let o=s;if((n.abort||n.continue)&&(n.abort&&n.continue||n.branch!==void 0||n.noFf||n.ffOnly||n.squash||n.edit||n.message!==void 0||n.quiet))return{stdout:"",stderr:`fatal: ${n.abort?"--abort":"--continue"} expects no arguments + +-${sy}`,exitCode:129};if(n.abort)return cy(s,r.env);if(n.continue)return ay(s,r.env,t);let i=!!n.quiet,a=n.branch;if(!a)return v("you must specify a branch to merge");let c=await nt(s);if(D(c))return c;let f=await X(s),l=Hr(f,"Merging");if(l)return l;if(await z(s,"MERGE_HEAD"))return v(`You have not concluded your merge (MERGE_HEAD exists). +-Please, commit your changes before you merge.`);if(await z(s,"CHERRY_PICK_HEAD"))return v(`You have not concluded your cherry-pick (CHERRY_PICK_HEAD exists). +-Please, commit your changes before you merge.`);let m=!!n.noFf,h=!!n.ffOnly;if(!n.noFf&&!n.ffOnly){let y=await Re(s,"merge.ff");y==="false"?m=!0:y==="only"&&(h=!0)}if(n.squash&&m)return v("options '--squash' and '--no-ff.' cannot be used together");let p=await Le(s,a);if(!p)return F(`merge: ${a} - not something we can merge +-`);let g=await Se(s,p),w=await ft(s,c,g),b=w[0]??null;if(w.length===0)return v("refusing to merge unrelated histories");if(b===g){await Ce(s,"MERGE_MSG");let y=n.squash?" (nothing to squash)":"";return{stdout:i?"":`Already up to date.${y} +-`,stderr:"",exitCode:0}}if(m&&h)return v("--no-ff and --ff-only are incompatible");let R=b===c&&!m;if(h&&!R)return F(`hint: Diverging branches can't be fast-forwarded, you need to either: ++${Dy}`,exitCode:129};if(n.abort)return Gy(o,r.env);if(n.continue)return Ly(o,r.env,t);let i=!!n.quiet,a=n.branch;if(!a)return v("you must specify a branch to merge");let c=await nt(o);if(D(c))return c;let f=await X(o),l=Lr(f,"Merging");if(l)return l;if(await z(o,"MERGE_HEAD"))return v(`You have not concluded your merge (MERGE_HEAD exists). ++Please, commit your changes before you merge.`);if(await z(o,"CHERRY_PICK_HEAD"))return v(`You have not concluded your cherry-pick (CHERRY_PICK_HEAD exists). ++Please, commit your changes before you merge.`);let m=!!n.noFf,h=!!n.ffOnly;if(!n.noFf&&!n.ffOnly){let k=await Re(o,"merge.ff");k==="false"?m=!0:k==="only"&&(h=!0)}if(n.squash&&m)return v("options '--squash' and '--no-ff.' cannot be used together");let p=await Ie(o,a);if(!p)return N(`merge: ${a} - not something we can merge ++`);let g=await Oe(o,p),w=await mt(o,c,g),b=w[0]??null;if(w.length===0)return v("refusing to merge unrelated histories");if(b===g){await xe(o,"MERGE_MSG");let k=n.squash?" (nothing to squash)":"";return{stdout:i?"":`Already up to date.${k} ++`,stderr:"",exitCode:0}}if(m&&h)return v("--no-ff and --ff-only are incompatible");let y=b===c&&!m;if(h&&!y)return N(`hint: Diverging branches can't be fast-forwarded, you need to either: + hint: + hint: git merge --no-ff + hint: +@@ -490,46 +497,46 @@ hint: git rebase + hint: + hint: Disable this message with "git config set advice.diverging false" + fatal: Not possible to fast-forward, aborting. +-`,128);if(await z(s,"REVERT_HEAD")&&await tn(s),R&&!n.squash){let y=await te(s),P=await Zs(s,c,g,{quiet:i});if(P.exitCode===0&&n.message&&(P.stdout=P.stdout.replace(/^Fast-forward$/m,"Fast-forward (no commit created; -m option ignored)")),P.exitCode===0){await Ce(s,"MERGE_MSG");let k=y?.type==="symbolic"?y.target:"HEAD";await ee(s,r.env,k,c,g,`merge ${a}: Fast-forward${n.message?" (no commit created; -m option ignored)":""}`,y?.type==="symbolic"),await t?.hooks?.postMerge?.({repo:s,headHash:c,theirsHash:g,strategy:"fast-forward",commitHash:null})}return P}let C=n.message,x=C?C.endsWith(` ++`,128);if(await z(o,"REVERT_HEAD")&&await on(o),y&&!n.squash){let k=await ne(o),P=await so(o,c,g,{quiet:i});if(P.exitCode===0&&n.message&&(P.stdout=P.stdout.replace(/^Fast-forward$/m,"Fast-forward (no commit created; -m option ignored)")),P.exitCode===0){await xe(o,"MERGE_MSG");let E=k?.type==="symbolic"?k.target:"HEAD";await ee(o,r.env,E,c,g,`merge ${a}: Fast-forward${n.message?" (no commit created; -m option ignored)":""}`,k?.type==="symbolic"),await t?.hooks?.postMerge?.({repo:o,headHash:c,theirsHash:g,strategy:"fast-forward",commitHash:null})}return P}let C=n.message,x=C?C.endsWith(` + `)?C:`${C} +-`:void 0;return n.squash?iy(s,c,g,a,r.env,t,x,i):oy(s,c,g,a,r.env,m,t,x,i)}})}async function oy(e,t,n,r,o,s=!1,i,a,c=!1){let f=await M(e,t),l=await te(e),d=l?.type==="symbolic"?Ie(l.target):"HEAD",u=await Re(e,"merge.conflictstyle")??"merge",m={a:"HEAD",b:r,conflictStyle:u},h=await eo(e,t,n,m,i?.mergeDriver),p=mt("merge",h.neededRenameLimit),g=await Kn(e,h,f.tree,{labels:m,errorExitCode:2,operationName:"merge"});if(!g.ok){await Ce(e,"MERGE_MSG"),g.failureKind==="staged"&&l?.type==="symbolic"&&await ee(e,o,"HEAD",t,t,`merge ${r}: updating HEAD`);let T=g;return{...T,stderr:p+T.stderr}}if(h.conflicts.length>0){await Q(e,"MERGE_HEAD",n),await Q(e,"ORIG_HEAD",t);let T=a??await Lr(e,r,d),j={repo:e,message:T,treeHash:g.mergedTreeHash,headHash:t,theirsHash:n},U=await i?.hooks?.mergeMsg?.(j);if(he(U))return{stdout:"",stderr:U.message??"",exitCode:1};T=j.message;let G=fn({version:2,entries:h.entries}).sort();return T+=` ++`:void 0;return n.squash?jy(o,c,g,a,r.env,t,x,i):My(o,c,g,a,r.env,m,t,x,i)}})}async function My(e,t,n,r,s,o=!1,i,a,c=!1){let f=await M(e,t),l=await ne(e),d=l?.type==="symbolic"?ve(l.target):"HEAD",u=await Re(e,"merge.conflictstyle")??"merge",m={a:"HEAD",b:r,conflictStyle:u},h=await co(e,t,n,m,i?.mergeDriver),p=wt("merge",h.neededRenameLimit),g=await Yn(e,h,f.tree,{labels:m,errorExitCode:2,operationName:"merge"});if(!g.ok){await xe(e,"MERGE_MSG"),g.failureKind==="staged"&&l?.type==="symbolic"&&await ee(e,s,"HEAD",t,t,`merge ${r}: updating HEAD`);let T=g;return{...T,stderr:p+T.stderr}}if(h.conflicts.length>0){await Q(e,"MERGE_HEAD",n),await Q(e,"ORIG_HEAD",t);let T=a??await Ur(e,r,d),j={repo:e,message:T,treeHash:g.mergedTreeHash,headHash:t,theirsHash:n},U=await i?.hooks?.mergeMsg?.(j);if(pe(U))return{stdout:"",stderr:U.message??"",exitCode:1};T=j.message;let G=mn({version:2,entries:h.entries}).sort();return T+=` + # Conflicts: + ${G.map(A=>`# ${A}`).join(` + `)} +-`,await Ue(e,"MERGE_MSG",T),await Ue(e,"MERGE_MODE",s?"no-ff":""),{stdout:`${[...h.messages,"Automatic merge failed; fix conflicts and then commit the result."].join(` ++`,await Ne(e,"MERGE_MSG",T),await Ne(e,"MERGE_MODE",o?"no-ff":""),{stdout:`${[...h.messages,"Automatic merge failed; fix conflicts and then commit the result."].join(` + `)} +-`,stderr:p,exitCode:1}}await Ce(e,"MERGE_MSG");let w=g.mergedTreeHash,b=await Sn(e,o);if(D(b))return b;let R=await ct(e,o);if(D(R))return R;let C=a??await Lr(e,r,d),x={repo:e,message:C,treeHash:w,headHash:t,theirsHash:n},y=await i?.hooks?.mergeMsg?.(x);if(he(y))return{stdout:"",stderr:y.message??"",exitCode:1};C=x.message;let P=await i?.hooks?.preMergeCommit?.({repo:e,message:C,treeHash:w,headHash:t,theirsHash:n});if(he(P))return{stdout:"",stderr:P.message??"",exitCode:1};let k=await Gt(e,w,[t,n],b,R,C),E=l?.type==="symbolic"?l.target:"HEAD";await ee(e,o,E,t,k,`merge ${r}: Merge made by the 'ort' strategy.`,l?.type==="symbolic"),await i?.hooks?.postMerge?.({repo:e,headHash:t,theirsHash:n,strategy:"three-way",commitHash:k});let O=h.messages.length>0?`${h.messages.join(` ++`,stderr:p,exitCode:1}}await xe(e,"MERGE_MSG");let w=g.mergedTreeHash,b=await An(e,s);if(D(b))return b;let y=await dt(e,s);if(D(y))return y;let C=a??await Ur(e,r,d),x={repo:e,message:C,treeHash:w,headHash:t,theirsHash:n},k=await i?.hooks?.mergeMsg?.(x);if(pe(k))return{stdout:"",stderr:k.message??"",exitCode:1};C=x.message;let P=await i?.hooks?.preMergeCommit?.({repo:e,message:C,treeHash:w,headHash:t,theirsHash:n});if(pe(P))return{stdout:"",stderr:P.message??"",exitCode:1};let E=await Ut(e,w,[t,n],b,y,C),R=l?.type==="symbolic"?l.target:"HEAD";await ee(e,s,R,t,E,`merge ${r}: Merge made by the 'ort' strategy.`,l?.type==="symbolic"),await i?.hooks?.postMerge?.({repo:e,headHash:t,theirsHash:n,strategy:"three-way",commitHash:E});let O=h.messages.length>0?`${h.messages.join(` + `)} + `:"",$=c?"":`Merge made by the 'ort' strategy. +-${await Tn(e,f.tree,w)}`;return{stdout:`${O}${$}`,stderr:p,exitCode:0}}async function tm(e,t,n){let r=[];for await(let o of Ot(e,n,{exclude:[t]})){r.push(`commit ${o.hash}`),o.commit.parents.length>1&&r.push(`Merge: ${o.commit.parents.map(i=>i.slice(0,7)).join(" ")}`);let s=o.commit.author;r.push(`Author: ${s.name} <${s.email}>`),r.push(`Date: ${qn(s.timestamp,s.timezone)}`),r.push("");for(let i of o.commit.message.replace(/\n+$/,"").split(` ++${await Mn(e,f.tree,w)}`;return{stdout:`${O}${$}`,stderr:p,exitCode:0}}async function pm(e,t,n){let r=[];for await(let s of St(e,n,{exclude:[t]})){r.push(`commit ${s.hash}`),s.commit.parents.length>1&&r.push(`Merge: ${s.commit.parents.map(i=>i.slice(0,7)).join(" ")}`);let o=s.commit.author;r.push(`Author: ${o.name} <${o.email}>`),r.push(`Date: ${zn(o.timestamp,o.timezone)}`),r.push("");for(let i of s.commit.message.replace(/\n+$/,"").split(` + `))r.push(` ${i}`);r.push("")}return r.join(` +-`)}async function iy(e,t,n,r,o,s,i,a=!1){let c=await M(e,t),f=await te(e),l=await ft(e,t,n);if(l.length>0&&l[0]===t){let C=a?"":`Updating ${await ue(e,t)}..${await ue(e,n)} +-`,x=await Cd(e,t,n,{quiet:a});if(!x.ok)return await Ce(e,"MERGE_MSG"),{stdout:C+x.stdout,stderr:x.stderr,exitCode:x.exitCode};let y=await tm(e,t,n);return await Ue(e,"SQUASH_MSG",`Squashed commit of the following: ++`)}async function jy(e,t,n,r,s,o,i,a=!1){let c=await M(e,t),f=await ne(e),l=await mt(e,t,n);if(l.length>0&&l[0]===t){let C=a?"":`Updating ${await fe(e,t)}..${await fe(e,n)} ++`,x=await Dd(e,t,n,{quiet:a});if(!x.ok)return await xe(e,"MERGE_MSG"),{stdout:C+x.stdout,stderr:x.stderr,exitCode:x.exitCode};let k=await pm(e,t,n);return await Ne(e,"SQUASH_MSG",`Squashed commit of the following: + +-${y}`),{stdout:`${C}${a?"":i?`Fast-forward (no commit created; -m option ignored) ++${k}`),{stdout:`${C}${a?"":i?`Fast-forward (no commit created; -m option ignored) + `:`Fast-forward + `}Squash commit -- not updating HEAD +-${x.diffstat}`,stderr:"",exitCode:0}}let u=await Re(e,"merge.conflictstyle")??"merge",m={a:"HEAD",b:r,conflictStyle:u},h=await eo(e,t,n,m,s?.mergeDriver),p=mt("merge",h.neededRenameLimit),g=await Kn(e,h,c.tree,{labels:m,errorExitCode:2,operationName:"merge"});if(!g.ok){await Ce(e,"MERGE_MSG"),g.failureKind==="staged"&&f?.type==="symbolic"&&await ee(e,o,"HEAD",t,t,`merge ${r}: updating HEAD`);let C=g;return{...C,stderr:p+C.stderr}}let b=`Squashed commit of the following: ++${x.diffstat}`,stderr:"",exitCode:0}}let u=await Re(e,"merge.conflictstyle")??"merge",m={a:"HEAD",b:r,conflictStyle:u},h=await co(e,t,n,m,o?.mergeDriver),p=wt("merge",h.neededRenameLimit),g=await Yn(e,h,c.tree,{labels:m,errorExitCode:2,operationName:"merge"});if(!g.ok){await xe(e,"MERGE_MSG"),g.failureKind==="staged"&&f?.type==="symbolic"&&await ee(e,s,"HEAD",t,t,`merge ${r}: updating HEAD`);let C=g;return{...C,stderr:p+C.stderr}}let b=`Squashed commit of the following: + +-${await tm(e,t,n)}`;if(await Ue(e,"SQUASH_MSG",b),h.conflicts.length>0){let x=` ++${await pm(e,t,n)}`;if(await Ne(e,"SQUASH_MSG",b),h.conflicts.length>0){let x=` + # Conflicts: +-${fn({version:2,entries:h.entries}).sort().map(k=>`# ${k}`).join(` ++${mn({version:2,entries:h.entries}).sort().map(E=>`# ${E}`).join(` + `)} +-`,y=await Ae(e,"MERGE_MSG");return await Ue(e,"MERGE_MSG",(y??"")+x),{stdout:`${[...h.messages,"Squash commit -- not updating HEAD","Automatic merge failed; fix conflicts and then commit the result."].join(` ++`,k=await He(e,"MERGE_MSG");return await Ne(e,"MERGE_MSG",(k??"")+x),{stdout:`${[...h.messages,"Squash commit -- not updating HEAD","Automatic merge failed; fix conflicts and then commit the result."].join(` + `)} + `,stderr:p,exitCode:1}}return{stdout:`${h.messages.length>0?`${h.messages.join(` + `)} + `:""}Squash commit -- not updating HEAD + `,stderr:p+`Automatic merge went well; stopped before committing as requested +-`,exitCode:0}}async function ay(e,t,n){let r=await z(e,"MERGE_HEAD");if(!r)return v("There is no merge in progress (MERGE_HEAD missing).");let o=await X(e),s=ar(o);if(s)return s;let i=await nt(e);if(D(i))return i;let a=await M(e,i),c=await Ae(e,"MERGE_MSG");if(c)c=Ft(c);else{let k=await te(e),E=k?.type==="symbolic"?Ie(k.target):"HEAD";c=await Lr(e,"unknown",E)}let f=qe(o),l=await Ye(e,f),d=await Sn(e,t);if(D(d))return d;let u=await ct(e,t);if(D(u))return u;let m=Nt(c),h={repo:e,message:m,treeHash:l,headHash:i,theirsHash:r},p=await n?.hooks?.mergeMsg?.(h);if(he(p))return{stdout:"",stderr:p.message??"",exitCode:1};m=h.message;let g=await n?.hooks?.preMergeCommit?.({repo:e,message:m,treeHash:l,headHash:i,theirsHash:r});if(he(g))return{stdout:"",stderr:g.message??"",exitCode:1};let w=await Gt(e,l,[i,r],d,u,m);await qs(e);let b=await te(e),R=me(m),C=b?.type==="symbolic"?b.target:"HEAD";await ee(e,t,C,i,w,`commit (merge): ${R}`,b?.type==="symbolic"),await n?.hooks?.postMerge?.({repo:e,headHash:i,theirsHash:r,strategy:"three-way",commitHash:w});let x=await Tn(e,a.tree,l),y=b?.type==="symbolic"?Ie(b.target):"detached HEAD";return{stdout:`${await pn(e,y,w,c)} +-${x}`,stderr:"",exitCode:0}}async function cy(e,t){return cr(e,t,{operationRef:"MERGE_HEAD",noOpError:v("There is no merge to abort (MERGE_HEAD missing)."),operationName:"merge",clearState:qs})}ne();ve();ge();st();Ee();function rm(e,t){e.command("mv",{description:"Move or rename a file, directory, or symlink",args:[W.string().name("sources").describe("Source file(s) or directory").optional().variadic()],options:{force:S().alias("f").describe("Force renaming even if target exists"),"dry-run":S().alias("n").describe("Do nothing; only show what would happen"),skip:S().alias("k").describe("Skip move/rename actions that would lead to errors")},handler:async(n,r)=>{let o=await q(r.fs,r.cwd,t);if(D(o))return o;let s=o,i=tt(s);if(i)return i;let a=s.workTree,c=n.sources;if(c.length<2)return F(`usage: git mv [] ... +-`);let f=c[c.length-1],l=c.slice(0,-1),d=Qe(r.cwd,f),u=lt(a,d);if(u.startsWith(".."))return v(`'${f}' is outside repository at '${a}'`);let m=await X(s),h=await r.fs.exists(d),p=h&&(await r.fs.stat(d)).isDirectory;if(l.length>1&&!p)return v(h?`destination '${f}' is not a directory`:`destination directory '${f}' does not exist`);let g=[];for(let w of l){let b=Qe(r.cwd,w),R=lt(a,b);if(R.startsWith("..")){if(n.skip)continue;return v(`'${w}' is outside repository at '${a}'`)}if(!await r.fs.exists(b)){if(n.skip)continue;return v(`bad source, source=${R}, destination=${u}`)}let y=(await r.fs.stat(b)).isDirectory;if(!(y?m.entries.some(T=>T.path===R||T.path.startsWith(`${R}/`)):m.entries.some(T=>T.path===R&&T.stage===0))){let T=!y&&m.entries.some(j=>j.path===R&&j.stage>0);if(n.skip)continue;return v(T?`conflicted, source=${R}, destination=${u}`:`not under version control, source=${R}, destination=${u}`)}let k,E;if(p){let T=xt(R);k=u===""||u==="."?T:`${u}/${T}`,E=I(d,T)}else k=u,E=d;if(await r.fs.exists(E)&&!n.force)if((await r.fs.stat(E)).isDirectory){let j=xt(R);k=`${k}/${j}`,E=I(E,j)}else{if(n.skip)continue;return v(`destination exists, source=${R}, destination=${k}`)}if(R===k){if(n.skip)continue;return v(`can not move directory into itself, source=${R}, destination=${k}`)}let $=bt(E);if(!await r.fs.exists($)){if(n.skip)continue;return v(`renaming '${R}' failed: No such file or directory`)}if(y){let T=`${R}/`,j=m.entries.filter(U=>U.path.startsWith(T)&&U.stage===0);for(let U of j){let G=U.path.slice(R.length),N=k+G,A=E+G;g.push({srcRel:U.path,dstRel:N,srcAbs:I(a,U.path),dstAbs:A})}}else g.push({srcRel:R,dstRel:k,srcAbs:b,dstAbs:E})}if(g.length===0)return{stdout:"",stderr:"",exitCode:0};if(n["dry-run"])return{stdout:"",stderr:"",exitCode:0};for(let w of g){let b=bt(w.dstAbs);await r.fs.exists(b)||await r.fs.mkdir(b,{recursive:!0});let R=await r.fs.readFileBuffer(w.srcAbs);await r.fs.writeFile(w.dstAbs,R),await r.fs.rm(w.srcAbs);let C=Kr(m,w.srcRel,0);if(C){m=yt(m,w.srcRel);let x={...C,path:w.dstRel};m=Mt(m,x)}}for(let w of g)await Tr(r.fs,bt(w.srcAbs),a);return await ie(s,m),{stdout:"",stderr:"",exitCode:0}}})}ne();Be();xr();ve();ae();ge();St();Ve();ye();Ee();ne();Be();ve();ae();ne();ae();Mn();$r();De();async function Dc(e,t){let n=await be(e,t);if(n.type!=="commit")return null;let r=Rn(n.content),o=null;if(r.parents.length>0&&r.parents[0]){let f=await be(e,r.parents[0]);f.type==="commit"&&(o=Rn(f.content).tree)}let s=await Ke(e,o,r.tree);if(s.length===0)return null;let i=tr(),a=!1,c=[...s].sort((f,l)=>Te(f.path,l.path));for(let f of c){let l="",d="";if(f.oldHash)try{let m=await be(e,f.oldHash);l=new TextDecoder().decode(m.content)}catch{}if(f.newHash)try{let m=await be(e,f.newHash);d=new TextDecoder().decode(m.content)}catch{}let u=Wt({path:f.path,oldContent:l,newContent:d,oldMode:f.oldMode,newMode:f.newMode});if(u)for(let m of u.split(` ++`,exitCode:0}}async function Ly(e,t,n){let r=await z(e,"MERGE_HEAD");if(!r)return v("There is no merge in progress (MERGE_HEAD missing).");let s=await X(e),o=ar(s);if(o)return o;let i=await nt(e);if(D(i))return i;let a=await M(e,i),c=await He(e,"MERGE_MSG");if(c)c=_t(c);else{let E=await ne(e),R=E?.type==="symbolic"?ve(E.target):"HEAD";c=await Ur(e,"unknown",R)}let f=ze(s),l=await Ze(e,f),d=await An(e,t);if(D(d))return d;let u=await dt(e,t);if(D(u))return u;let m=Bt(c),h={repo:e,message:m,treeHash:l,headHash:i,theirsHash:r},p=await n?.hooks?.mergeMsg?.(h);if(pe(p))return{stdout:"",stderr:p.message??"",exitCode:1};m=h.message;let g=await n?.hooks?.preMergeCommit?.({repo:e,message:m,treeHash:l,headHash:i,theirsHash:r});if(pe(g))return{stdout:"",stderr:g.message??"",exitCode:1};let w=await Ut(e,l,[i,r],d,u,m);await Zs(e);let b=await ne(e),y=he(m),C=b?.type==="symbolic"?b.target:"HEAD";await ee(e,t,C,i,w,`commit (merge): ${y}`,b?.type==="symbolic"),await n?.hooks?.postMerge?.({repo:e,headHash:i,theirsHash:r,strategy:"three-way",commitHash:w});let x=await Mn(e,a.tree,l),k=b?.type==="symbolic"?ve(b.target):"detached HEAD";return{stdout:`${await yn(e,k,w,c)} ++${x}`,stderr:"",exitCode:0}}async function Gy(e,t){return cr(e,t,{operationRef:"MERGE_HEAD",noOpError:v("There is no merge to abort (MERGE_HEAD missing)."),operationName:"merge",clearState:Zs})}te();Se();ge();ot();ke();function wm(e,t){e.command("mv",{description:"Move or rename a file, directory, or symlink",args:[B.string().name("sources").describe("Source file(s) or directory").optional().variadic()],options:{force:S().alias("f").describe("Force renaming even if target exists"),"dry-run":S().alias("n").describe("Do nothing; only show what would happen"),skip:S().alias("k").describe("Skip move/rename actions that would lead to errors")},handler:async(n,r)=>{let s=await W(r.fs,r.cwd,t);if(D(s))return s;let o=s,i=tt(o);if(i)return i;let a=o.workTree,c=n.sources;if(c.length<2)return N(`usage: git mv [] ... ++`);let f=c[c.length-1],l=c.slice(0,-1),d=Je(r.cwd,f),u=rt(a,d);if(u.startsWith(".."))return v(`'${f}' is outside repository at '${a}'`);let m=await X(o),h=await r.fs.exists(d),p=h&&(await r.fs.stat(d)).isDirectory;if(l.length>1&&!p)return v(h?`destination '${f}' is not a directory`:`destination directory '${f}' does not exist`);let g=[];for(let w of l){let b=Je(r.cwd,w),y=rt(a,b);if(y.startsWith("..")){if(n.skip)continue;return v(`'${w}' is outside repository at '${a}'`)}if(!await r.fs.exists(b)){if(n.skip)continue;return v(`bad source, source=${y}, destination=${u}`)}let k=(await r.fs.stat(b)).isDirectory;if(!(k?m.entries.some(T=>T.path===y||T.path.startsWith(`${y}/`)):m.entries.some(T=>T.path===y&&T.stage===0))){let T=!k&&m.entries.some(j=>j.path===y&&j.stage>0);if(n.skip)continue;return v(T?`conflicted, source=${y}, destination=${u}`:`not under version control, source=${y}, destination=${u}`)}let E,R;if(p){let T=Pt(y);E=u===""||u==="."?T:`${u}/${T}`,R=I(d,T)}else E=u,R=d;if(await r.fs.exists(R)&&!n.force)if((await r.fs.stat(R)).isDirectory){let j=Pt(y);E=`${E}/${j}`,R=I(R,j)}else{if(n.skip)continue;return v(`destination exists, source=${y}, destination=${E}`)}if(y===E){if(n.skip)continue;return v(`can not move directory into itself, source=${y}, destination=${E}`)}let $=Et(R);if(!await r.fs.exists($)){if(n.skip)continue;return v(`renaming '${y}' failed: No such file or directory`)}if(k){let T=`${y}/`,j=m.entries.filter(U=>U.path.startsWith(T)&&U.stage===0);for(let U of j){let G=U.path.slice(y.length),L=E+G,A=R+G;g.push({srcRel:U.path,dstRel:L,srcAbs:I(a,U.path),dstAbs:A})}}else g.push({srcRel:y,dstRel:E,srcAbs:b,dstAbs:R})}if(g.length===0)return{stdout:"",stderr:"",exitCode:0};if(n["dry-run"])return{stdout:"",stderr:"",exitCode:0};for(let w of g){let b=Et(w.dstAbs);await r.fs.exists(b)||await r.fs.mkdir(b,{recursive:!0});let y=await r.fs.readFileBuffer(w.srcAbs),C=(await r.fs.stat(w.srcAbs)).mode;await r.fs.writeFile(w.dstAbs,y),r.fs.chmod&&await r.fs.chmod(w.dstAbs,C&4095),await r.fs.rm(w.srcAbs);let x=Zr(m,w.srcRel,0);if(x){m=Rt(m,w.srcRel);let k={...x,path:w.dstRel};m=jt(m,k)}}for(let w of g)await Mr(r.fs,Et(w.srcAbs),a);return await oe(o,m),{stdout:"",stderr:"",exitCode:0}}})}te();We();$r();Se();ie();ge();It();Xe();ye();ke();te();We();Se();ie();te();ie();On();Sr();Te();async function qc(e,t){let n=await me(e,t);if(n.type!=="commit")return null;let r=en(n.content),s=null;if(r.parents.length>0&&r.parents[0]){let f=await me(e,r.parents[0]);f.type==="commit"&&(s=en(f.content).tree)}let o=await Ve(e,s,r.tree);if(o.length===0)return null;let i=tr(),a=!1,c=[...o].sort((f,l)=>Ae(f.path,l.path));for(let f of c){let l="",d="";if(f.oldHash)try{let m=await me(e,f.oldHash);l=new TextDecoder().decode(m.content)}catch{}if(f.newHash)try{let m=await me(e,f.newHash);d=new TextDecoder().decode(m.content)}catch{}let u=Kt({path:f.path,oldContent:l,newContent:d,oldMode:f.oldMode,newMode:f.newMode});if(u)for(let m of u.split(` + `)){if(!m||m.startsWith("index "))continue;let p=(m.startsWith("@@")?m.replace(/^@@ [^@]* @@/,"@@ @@"):m).replace(/[ \t\r]/g,"");p&&(i.update(p),i.update(` +-`),a=!0)}}return a?i.hex():null}Ve();ye();De();Jt();st();async function fy(e){let t=await te(e);return t?.type==="symbolic"?Ie(t.target):"detached HEAD"}var im="4b825dc642cb6eb9a060e54bf8d69288fbee4904";async function ly(e,t){let n=t.parents[0];if(n===void 0)return t.tree===im;if(t.parents.length>1)return!1;let r=await M(e,n);return t.tree===r.tree}function dy(e){return e==="HEAD"?`HEAD is up to date. ++`),a=!0)}}return a?i.hex():null}Xe();ye();Te();rn();ot();async function Fy(e){let t=await ne(e);return t?.type==="symbolic"?ve(t.target):"detached HEAD"}var km="4b825dc642cb6eb9a060e54bf8d69288fbee4904";async function Ny(e,t){let n=t.parents[0];if(n===void 0)return t.tree===km;if(t.parents.length>1)return!1;let r=await M(e,n);return t.tree===r.tree}function Uy(e){return e==="HEAD"?`HEAD is up to date. + `:`Current branch ${e} is up to date. +-`}async function uy(e,t,n){let r=n;for(;r&&r!==t;){let o=await M(e,r);if(o.parents.length===0)return!0;if(o.parents.length>1)return!1;r=o.parents[0]}return!0}async function my(e,t,n,r){let o=await ft(e,t,r);if(o.length!==1||o[0]!==t)return!1;let s=await ft(e,n,r);return s.length!==1||s[0]!==t?!1:uy(e,t,r)}async function hy(e,t,n){if(!e.workTree)return null;let r=await de(e,t),o=new Map(qe(n).map(a=>[a.path,a])),s=new Set(await ut(e,e.workTree,"")),i=[];for(let[a]of r)o.has(a)||s.has(a)&&i.push({path:a,error:"WOULD_LOSE_UNTRACKED_OVERWRITTEN"});if(i.length>0){let a=qo(i,{errorExitCode:1,operationName:"checkout",actionHint:"switch branches"});return F(`${a.stderr}error: could not detach HEAD +-`)}return null}async function py(e,t,n,r){if(!e.workTree)return null;let o=await de(e,t),s=new Set(n.entries.map(c=>c.path)),i=new Set(await ut(e,e.workTree,"")),a=[];for(let[c]of o)!s.has(c)&&i.has(c)&&a.push({path:c,error:"WOULD_LOSE_UNTRACKED_OVERWRITTEN"});return a.length>0?{stdout:"",stderr:`${qo(a,{errorExitCode:128,operationName:"reset",actionHint:"reset"}).stderr}fatal: could not move back to ${r} +-`,exitCode:128}:null}async function sm(e,t,n){if(!e.workTree)return null;let r=new Map(qe(t).map(i=>[i.path,i])),o=new Set(await ut(e,e.workTree,"")),s=[];for(let[i]of n)!r.has(i)&&o.has(i)&&s.push(i);return s.length>0?s:null}function om(e,t){return`error: The following untracked working tree files would be overwritten by merge: ++`}async function _y(e,t,n){let r=n;for(;r&&r!==t;){let s=await M(e,r);if(s.parents.length===0)return!0;if(s.parents.length>1)return!1;r=s.parents[0]}return!0}async function By(e,t,n,r){let s=await mt(e,t,r);if(s.length!==1||s[0]!==t)return!1;let o=await mt(e,n,r);return o.length!==1||o[0]!==t?!1:_y(e,t,r)}async function Wy(e,t,n){if(!e.workTree)return null;let r=await de(e,t),s=new Map(ze(n).map(a=>[a.path,a])),o=new Set(await gt(e,e.workTree,"")),i=[];for(let[a]of r)s.has(a)||o.has(a)&&i.push({path:a,error:"WOULD_LOSE_UNTRACKED_OVERWRITTEN"});if(i.length>0){let a=ei(i,{errorExitCode:1,operationName:"checkout",actionHint:"switch branches"});return N(`${a.stderr}error: could not detach HEAD ++`)}return null}async function qy(e,t,n,r){if(!e.workTree)return null;let s=await de(e,t),o=new Set(n.entries.map(c=>c.path)),i=new Set(await gt(e,e.workTree,"")),a=[];for(let[c]of s)!o.has(c)&&i.has(c)&&a.push({path:c,error:"WOULD_LOSE_UNTRACKED_OVERWRITTEN"});return a.length>0?{stdout:"",stderr:`${ei(a,{errorExitCode:128,operationName:"reset",actionHint:"reset"}).stderr}fatal: could not move back to ${r} ++`,exitCode:128}:null}async function bm(e,t,n){if(!e.workTree)return null;let r=new Map(ze(t).map(i=>[i.path,i])),s=new Set(await gt(e,e.workTree,"")),o=[];for(let[i]of n)!r.has(i)&&s.has(i)&&o.push(i);return o.length>0?o:null}function ym(e,t){return`error: The following untracked working tree files would be overwritten by merge: + ${e.map(r=>` ${r}`).join(` + `)} + Please move or remove them before you merge. +@@ -543,18 +550,18 @@ hint: edit the todo list first: + hint: + hint: git rebase --edit-todo + hint: git rebase --continue +-`}async function fo(e,t,n,r,o,s,i,a){await ee(e,t,"HEAD",n,r,`${i} (start): checkout ${s}`),o!=="detached HEAD"&&(n!==r&&await ee(e,t,o,n,r,`${i} (finish): ${o} onto ${a}`),await ee(e,t,"HEAD",r,r,`${i} (finish): returning to ${o}`))}async function Li(e,t,n,r){let o=await M(e,t),s=await hy(e,o.tree,n);if(s)return s;let i=await _n(e,o.tree,n);return i.success&&(await ie(e,{version:2,entries:i.newEntries}),await je(e,i.worktreeOps)),r!=="detached HEAD"?await Q(e,r,t):await Q(e,"HEAD",t),null}async function Gi(e,t,n,r,o,s,i,a,c,f){let l=r.startsWith("refs/heads/")?Ie(r):"HEAD",d=f?.reflogAction??"rebase",u=f?.quiet??!1,m=u?"":`Successfully rebased and updated ${r}. +-`,h=await X(e),p=fn(h).sort();if(p.length>0)return{stdout:p.map(G=>`${G}: needs merge ++`}async function bo(e,t,n,r,s,o,i,a){await ee(e,t,"HEAD",n,r,`${i} (start): checkout ${o}`),s!=="detached HEAD"&&(n!==r&&await ee(e,t,s,n,r,`${i} (finish): ${s} onto ${a}`),await ee(e,t,"HEAD",r,r,`${i} (finish): returning to ${s}`))}async function Ki(e,t,n,r){let s=await M(e,t),o=await Wy(e,s.tree,n);if(o)return o;let i=await Bn(e,s.tree,n);return i.success&&(await oe(e,{version:2,entries:i.newEntries}),await Me(e,i.worktreeOps)),r!=="detached HEAD"?await Q(e,r,t):await Q(e,"HEAD",t),null}async function Vi(e,t,n,r,s,o,i,a,c,f){let l=r.startsWith("refs/heads/")?ve(r):"HEAD",d=f?.reflogAction??"rebase",u=f?.quiet??!1,m=u?"":`Successfully rebased and updated ${r}. ++`,h=await X(e),p=mn(h).sort();if(p.length>0)return{stdout:p.map(G=>`${G}: needs merge + `).join(""),stderr:`error: cannot rebase: You have unstaged changes. + error: additionally, your index contains uncommitted changes. + error: Please commit or stash them. +-`,exitCode:1};let g=await zo(e,n,h);if(g)return Ko("rebase",g);let w=await c?.hooks?.preRebase?.({repo:e,upstream:i,branch:r!=="detached HEAD"?l:null});if(he(w))return{stdout:"",stderr:w.message??"",exitCode:1};if(await my(e,s,o,n))return{stdout:u?"":dy(l),stderr:"",exitCode:0};let b=await Ql(e,o,n),R=b.right;if(R.length===0){if(s!==n){let G=await Li(e,s,h,r);return G||(await fo(e,t,n,s,r,a,d,s),{stdout:"",stderr:m,exitCode:0})}return await fo(e,t,n,n,r,a,d,s),{stdout:"",stderr:m,exitCode:0}}let C=[],x=!1,y=[];if(f?.reapplyCherryPicks)y.push(...R);else{let G=b.left,N=new Set;for(let A of G){let H=await Dc(e,A.hash);H&&N.add(H)}if(N.size>0)for(let A of R){let H=await Dc(e,A.hash);H&&N.has(H)?(x=!0,u||C.push(`warning: skipped previously applied commit ${await ue(e,A.hash)}`)):y.push(A)}else y.push(...R)}let P="";if(x&&(P=C.map(G=>`${G} ++`,exitCode:1};let g=await ti(e,n,h);if(g)return ni("rebase",g);let w=await c?.hooks?.preRebase?.({repo:e,upstream:i,branch:r!=="detached HEAD"?l:null});if(pe(w))return{stdout:"",stderr:w.message??"",exitCode:1};if(await By(e,o,s,n))return{stdout:u?"":Uy(l),stderr:"",exitCode:0};let b=await cd(e,s,n),y=b.right;if(y.length===0){if(o!==n){let G=await Ki(e,o,h,r);return G||(await bo(e,t,n,o,r,a,d,o),{stdout:"",stderr:m,exitCode:0})}return await bo(e,t,n,n,r,a,d,o),{stdout:"",stderr:m,exitCode:0}}let C=[],x=!1,k=[];if(f?.reapplyCherryPicks)k.push(...y);else{let G=b.left,L=new Set;for(let A of G){let H=await qc(e,A.hash);H&&L.add(H)}if(L.size>0)for(let A of y){let H=await qc(e,A.hash);H&&L.has(H)?(x=!0,u||C.push(`warning: skipped previously applied commit ${await fe(e,A.hash)}`)):k.push(A)}else k.push(...y)}let P="";if(x&&(P=C.map(G=>`${G} + `).join("")+`hint: use --reapply-cherry-picks to include skipped commits + hint: Disable this message with "git config set advice.skippedCherryPicks false" +-`),y.length===0){if(await qt(e,s,n))return await fo(e,t,n,n,r,a,d,s),{stdout:"",stderr:P+m,exitCode:0};let G=await Li(e,s,h,r);return G?(G.stderr=P+G.stderr,G):(await fo(e,t,n,s,r,a,d,s),{stdout:"",stderr:P+m,exitCode:0})}let k=[];for(let G of y){let N={hash:G.hash,subject:me(G.commit.message)};await ly(e,G.commit)&&(N.empty=!0),k.push(N)}let E=s,O=0;for(let G of k){let N=await M(e,G.hash);if(N.parents.length>1||N.parents.length===0||N.parents[0]!==E)break;E=G.hash,O++}let $=k.splice(0,O);if(k.length===0){if(E!==n){let G=await Li(e,E,h,r);if(G)return G.stderr=P+G.stderr,G}return await fo(e,t,n,E,r,a,d,s),{stdout:"",stderr:P+m,exitCode:0}}let T=await Li(e,E,h,"detached HEAD");if(T)return T.stderr=P+T.stderr,T;await ke(e,"CHERRY_PICK_HEAD"),await ke(e,"REVERT_HEAD"),await Ce(e,"MERGE_MSG"),await Ce(e,"MERGE_MODE"),await ee(e,t,"HEAD",n,E,`${d} (start): checkout ${a}`);let j={headName:r,origHead:n,onto:s,todo:k,done:$,msgnum:O,end:O+k.length,reflogAction:d,...u?{quiet:u}:{}};await Ya(e,j),await Q(e,"ORIG_HEAD",n);let U=await Mc(e,t,c?.mergeDriver);return P&&(U.stderr=P+U.stderr),U}async function Mc(e,t,n){let r=[],o=[];for(;;){let s=await Bt(e);if(!s||s.todo.length===0)break;let i=s.todo[0];if(!i)break;s.quiet||r.push(`Rebasing (${s.msgnum+1}/${s.end})\r`),await Zl(e);let a=await gy(e,i,t,n);if(a.conflict){if(a.rescheduleCurrent){let c=await Bt(e);c&&(c.todo=[i,...c.todo],await Ya(e,c))}return a.stdout&&o.push(a.stdout),r.push(a.stderr),{stdout:o.join(""),stderr:r.join(""),exitCode:1}}a.stdout&&o.push(a.stdout),a.stderr&&r.push(a.stderr)}return wy(e,r,t)}async function gy(e,t,n,r){let o=t.hash,s=await M(e,o),i=s.parents.length>0?s.parents[0]:null,a=i?await M(e,i):null,c=await Z(e);if(!c)return{conflict:!0,stdout:"",stderr:`fatal: no HEAD commit during rebase +-`};if(i&&i===c){let N=await X(e);if(!a)return{conflict:!0,stdout:"",stderr:`fatal: missing parent commit during rebase +-`};let A=await ze(e,a.tree),H=await ze(e,s.tree),B=new Map(A.map(Y=>[Y.path,Y.hash])),L=new Map;for(let Y of H){let fe=B.get(Y.path);(!fe||fe!==Y.hash)&&L.set(Y.path,Y.hash)}let _=await sm(e,N,L);if(_)return await Q(e,"REBASE_HEAD",o),await ti(e,o,s.author),{conflict:!0,stdout:"",stderr:om(_,t),rescheduleCurrent:!0};let V=await _n(e,s.tree,N);return V.success&&(await ie(e,{version:2,entries:V.newEntries}),await je(e,V.worktreeOps)),await or(e,o),await ee(e,n,"HEAD",c,o,"rebase: fast-forward"),{conflict:!1,stdout:"",stderr:""}}let f=await M(e,c),l=a?a.tree:null,d=await ue(e,o),u=me(s.message),m=await Re(e,"merge.conflictstyle")??"merge",h={a:"HEAD",b:u?`${d} (${u})`:d,conflictStyle:m},p=await sn(e,l,f.tree,s.tree,h,r),g=await X(e),[w,b,R]=await Promise.all([ze(e,f.tree),l?ze(e,l):Promise.resolve([]),ze(e,s.tree)]),C=new Set;for(let N of b)C.add(N.path);for(let N of w)C.add(N.path);for(let N of R)C.add(N.path);let x=g.entries.filter(N=>!C.has(N.path)),y=[...p.entries,...x];y.sort((N,A)=>Te(N.path,A.path)||N.stage-A.stage);let P={version:2,entries:y},k=y.filter(N=>N.stage===0),E=await Ye(e,k),O=new Map(w.map(N=>[N.path,N])),$=new Map;for(let N of k){let A=O.get(N.path);(!A||A.hash!==N.hash)&&$.set(N.path,N.hash)}for(let N of p.conflicts){if(N.reason==="content"||N.reason==="add-add"){$.set(N.path,null);continue}if(N.reason==="delete-modify"){let A=p.entries.filter(L=>L.path===N.path&&L.stage>0),H=A.find(L=>L.stage===2),B=A.find(L=>L.stage===3);B&&!H&&$.set(N.path,B.hash)}}let T=await sm(e,g,$);if(T)return await Q(e,"REBASE_HEAD",o),await ti(e,o,s.author),{conflict:!0,stdout:"",stderr:om(T,t),rescheduleCurrent:!0};if(await ie(e,P),e.workTree){let N=await On(e,f.tree,p.resultTree,g);N.success&&await je(e,N.worktreeOps)}if(p.conflicts.length>0){await Q(e,"REBASE_HEAD",o),await ti(e,o,s.author),await Ue(e,"MERGE_MSG",s.message),await Ue(e,"rebase-merge/message",s.message);let N=p.messages.join(` +-`);return{conflict:!0,stdout:N?`${N} ++`),k.length===0){if(await Vt(e,o,n))return await bo(e,t,n,n,r,a,d,o),{stdout:"",stderr:P+m,exitCode:0};let G=await Ki(e,o,h,r);return G?(G.stderr=P+G.stderr,G):(await bo(e,t,n,o,r,a,d,o),{stdout:"",stderr:P+m,exitCode:0})}let E=[];for(let G of k){let L={hash:G.hash,subject:he(G.commit.message)};await Ny(e,G.commit)&&(L.empty=!0),E.push(L)}let R=o,O=0;for(let G of E){let L=await M(e,G.hash);if(L.parents.length>1||L.parents.length===0||L.parents[0]!==R)break;R=G.hash,O++}let $=E.splice(0,O);if(E.length===0){if(R!==n){let G=await Ki(e,R,h,r);if(G)return G.stderr=P+G.stderr,G}return await bo(e,t,n,R,r,a,d,o),{stdout:"",stderr:P+m,exitCode:0}}let T=await Ki(e,R,h,"detached HEAD");if(T)return T.stderr=P+T.stderr,T;await Ee(e,"CHERRY_PICK_HEAD"),await Ee(e,"REVERT_HEAD"),await xe(e,"MERGE_MSG"),await xe(e,"MERGE_MODE"),await ee(e,t,"HEAD",n,R,`${d} (start): checkout ${a}`);let j={headName:r,origHead:n,onto:o,todo:E,done:$,msgnum:O,end:O+E.length,reflogAction:d,...u?{quiet:u}:{}};await sc(e,j),await Q(e,"ORIG_HEAD",n);let U=await zc(e,t,c?.mergeDriver);return P&&(U.stderr=P+U.stderr),U}async function zc(e,t,n){let r=[],s=[];for(;;){let o=await zt(e);if(!o||o.todo.length===0)break;let i=o.todo[0];if(!i)break;o.quiet||r.push(`Rebasing (${o.msgnum+1}/${o.end})\r`),await ad(e);let a=await zy(e,i,t,n);if(a.conflict){if(a.rescheduleCurrent){let c=await zt(e);c&&(c.todo=[i,...c.todo],await sc(e,c))}return a.stdout&&s.push(a.stdout),r.push(a.stderr),{stdout:s.join(""),stderr:r.join(""),exitCode:1}}a.stdout&&s.push(a.stdout),a.stderr&&r.push(a.stderr)}return Ky(e,r,t)}async function zy(e,t,n,r){let s=t.hash,o=await M(e,s),i=o.parents.length>0?o.parents[0]:null,a=i?await M(e,i):null,c=await Z(e);if(!c)return{conflict:!0,stdout:"",stderr:`fatal: no HEAD commit during rebase ++`};if(i&&i===c){let L=await X(e);if(!a)return{conflict:!0,stdout:"",stderr:`fatal: missing parent commit during rebase ++`};let A=await Ke(e,a.tree),H=await Ke(e,o.tree),q=new Map(A.map(V=>[V.path,V.hash])),F=new Map;for(let V of H){let ue=q.get(V.path);(!ue||ue!==V.hash)&&F.set(V.path,V.hash)}let _=await bm(e,L,F);if(_)return await Q(e,"REBASE_HEAD",s),await di(e,s,o.author),{conflict:!0,stdout:"",stderr:ym(_,t),rescheduleCurrent:!0};let Y=await Bn(e,o.tree,L);return Y.success&&(await oe(e,{version:2,entries:Y.newEntries}),await Me(e,Y.worktreeOps)),await or(e,s),await ee(e,n,"HEAD",c,s,"rebase: fast-forward"),{conflict:!1,stdout:"",stderr:""}}let f=await M(e,c),l=a?a.tree:null,d=await fe(e,s),u=he(o.message),m=await Re(e,"merge.conflictstyle")??"merge",h={a:"HEAD",b:u?`${d} (${u})`:d,conflictStyle:m},p=await fn(e,l,f.tree,o.tree,h,r),g=await X(e),[w,b,y]=await Promise.all([Ke(e,f.tree),l?Ke(e,l):Promise.resolve([]),Ke(e,o.tree)]),C=new Set;for(let L of b)C.add(L.path);for(let L of w)C.add(L.path);for(let L of y)C.add(L.path);let x=g.entries.filter(L=>!C.has(L.path)),k=[...p.entries,...x];k.sort((L,A)=>Ae(L.path,A.path)||L.stage-A.stage);let P={version:2,entries:k},E=k.filter(L=>L.stage===0),R=await Ze(e,E),O=new Map(w.map(L=>[L.path,L])),$=new Map;for(let L of E){let A=O.get(L.path);(!A||A.hash!==L.hash)&&$.set(L.path,L.hash)}for(let L of p.conflicts){if(L.reason==="content"||L.reason==="add-add"){$.set(L.path,null);continue}if(L.reason==="delete-modify"){let A=p.entries.filter(F=>F.path===L.path&&F.stage>0),H=A.find(F=>F.stage===2),q=A.find(F=>F.stage===3);q&&!H&&$.set(L.path,q.hash)}}let T=await bm(e,g,$);if(T)return await Q(e,"REBASE_HEAD",s),await di(e,s,o.author),{conflict:!0,stdout:"",stderr:ym(T,t),rescheduleCurrent:!0};if(await oe(e,P),e.workTree){let L=await Tn(e,f.tree,p.resultTree,g);L.success&&await Me(e,L.worktreeOps)}if(p.conflicts.length>0){await Q(e,"REBASE_HEAD",s),await di(e,s,o.author),await Ne(e,"MERGE_MSG",o.message),await Ne(e,"rebase-merge/message",o.message);let L=p.messages.join(` ++`);return{conflict:!0,stdout:L?`${L} + `:"",stderr:`error: could not apply ${d}... ${t.subject} + hint: Resolve all conflicts manually, mark them as resolved with + hint: "git add/rm ", then run "git rebase --continue". +@@ -562,15 +569,15 @@ hint: You can instead skip this commit: run "git rebase --skip". + hint: To abort and get back to the state before "git rebase", run "git rebase --abort". + hint: Disable this message with "git config set advice.mergeConflict false" + Could not apply ${d}... # ${t.subject} +-`}}let j=i===null?s.tree===im:s.tree===l;if(E===f.tree&&!j)return{conflict:!1,stdout:"",stderr:`dropping ${o} ${t.subject} -- patch contents already upstream +-`};let U=await ct(e,n);if(D(U))return{conflict:!0,stdout:"",stderr:U.stderr};let G=await Gt(e,E,[c],s.author,U,s.message);return await ee(e,n,"HEAD",c,G,`rebase (pick): ${t.subject}`),{conflict:!1,stdout:"",stderr:""}}async function wy(e,t,n){let r=await Bt(e);if(!r)return v("no rebase in progress");let o=await Z(e);if(!o)return v("no HEAD during rebase finish");if(r.headName!=="detached HEAD"){let a=await z(e,r.headName);if(a!==r.origHead)return{stdout:"",stderr:t.join("")+`error: update_ref failed for ref '${r.headName}': cannot lock ref '${r.headName}': is at ${a??"(null)"} but expected ${r.origHead} ++`}}let j=i===null?o.tree===km:o.tree===l;if(R===f.tree&&!j)return{conflict:!1,stdout:"",stderr:`dropping ${s} ${t.subject} -- patch contents already upstream ++`};let U=await dt(e,n);if(D(U))return{conflict:!0,stdout:"",stderr:U.stderr};let G=await Ut(e,R,[c],o.author,U,o.message);return await ee(e,n,"HEAD",c,G,`rebase (pick): ${t.subject}`),{conflict:!1,stdout:"",stderr:""}}async function Ky(e,t,n){let r=await zt(e);if(!r)return v("no rebase in progress");let s=await Z(e);if(!s)return v("no HEAD during rebase finish");if(r.headName!=="detached HEAD"){let a=await z(e,r.headName);if(a!==r.origHead)return{stdout:"",stderr:t.join("")+`error: update_ref failed for ref '${r.headName}': cannot lock ref '${r.headName}': is at ${a??"(null)"} but expected ${r.origHead} + error: could not update ${r.headName} +-`,exitCode:1};await Q(e,r.headName,o),await ot(e,"HEAD",r.headName),await Tt(e),r.origHead!==o&&await ee(e,n,r.headName,r.origHead,o,`${r.reflogAction??"rebase"} (finish): ${r.headName} onto ${r.onto}`),await ee(e,n,"HEAD",o,o,`${r.reflogAction??"rebase"} (finish): returning to ${r.headName}`)}let s=r.headName,i=r.quiet?"":`Successfully rebased and updated ${s}. +-`;return await ke(e,"REBASE_HEAD"),await lr(e),await Xa(e),{stdout:"",stderr:t.join("")+i,exitCode:0}}async function am(e,t){let n=await Bt(e);if(!n)return v("no rebase in progress");let r=await Z(e),o=n.origHead,s=await M(e,o),i=await X(e),a=await py(e,s.tree,i,o);if(a)return a;let c=await _n(e,s.tree,i);c.success&&(await ie(e,{version:2,entries:c.newEntries}),await je(e,c.worktreeOps)),n.headName!=="detached HEAD"?(await Q(e,n.headName,o),await ot(e,"HEAD",n.headName),await Tt(e)):await or(e,o);let f=n.headName==="detached HEAD"?o:n.headName;return await ee(e,t,"HEAD",r,o,`rebase (abort): returning to ${f}`),await ke(e,"REBASE_HEAD"),await lr(e),await Xa(e),{stdout:"",stderr:"",exitCode:0}}async function cm(e,t,n){let r="",o=await Bt(e);if(!o)return v("no rebase in progress");let s=await X(e);if(kn(s))return F(`error: Committing is not possible because you have unmerged files. ++`,exitCode:1};await Q(e,r.headName,s),await ct(e,"HEAD",r.headName),await Ht(e),r.origHead!==s&&await ee(e,n,r.headName,r.origHead,s,`${r.reflogAction??"rebase"} (finish): ${r.headName} onto ${r.onto}`),await ee(e,n,"HEAD",s,s,`${r.reflogAction??"rebase"} (finish): returning to ${r.headName}`)}let o=r.headName,i=r.quiet?"":`Successfully rebased and updated ${o}. ++`;return await Ee(e,"REBASE_HEAD"),await lr(e),await oc(e),{stdout:"",stderr:t.join("")+i,exitCode:0}}async function Em(e,t){let n=await zt(e);if(!n)return v("no rebase in progress");let r=await Z(e),s=n.origHead,o=await M(e,s),i=await X(e),a=await qy(e,o.tree,i,s);if(a)return a;let c=await Bn(e,o.tree,i);c.success&&(await oe(e,{version:2,entries:c.newEntries}),await Me(e,c.worktreeOps)),n.headName!=="detached HEAD"?(await Q(e,n.headName,s),await ct(e,"HEAD",n.headName),await Ht(e)):await or(e,s);let f=n.headName==="detached HEAD"?s:n.headName;return await ee(e,t,"HEAD",r,s,`rebase (abort): returning to ${f}`),await Ee(e,"REBASE_HEAD"),await lr(e),await oc(e),{stdout:"",stderr:"",exitCode:0}}async function Rm(e,t,n){let r="",s=await zt(e);if(!s)return v("no rebase in progress");let o=await X(e);if(xn(o))return N(`error: Committing is not possible because you have unmerged files. + hint: Fix them up in the work tree, and then use 'git add ' + hint: as appropriate to mark resolution and make a commit. + fatal: Exiting because of an unresolved conflict. +-`,128);let i=await z(e,"REBASE_HEAD");if(i){let c=await Z(e);if(!c)return v("Cannot read HEAD");let f=await M(e,c),l=qe(s),d=await Ye(e,l),u=d!==f.tree,m=await Ae(e,"rebase-merge/message")!==null;if(u&&!m)return F(`error: you have staged changes in your working tree ++`,128);let i=await z(e,"REBASE_HEAD");if(i){let c=await Z(e);if(!c)return v("Cannot read HEAD");let f=await M(e,c),l=ze(o),d=await Ze(e,l),u=d!==f.tree,m=await He(e,"rebase-merge/message")!==null;if(u&&!m)return N(`error: you have staged changes in your working tree + If these changes are meant to be squashed into the previous commit, run: + + git commit --amend +@@ -583,26 +590,26 @@ In both cases, once you're done, continue with: + + git rebase --continue + +-`);if(u){let p=await M(e,i),g=await z(e,"CHERRY_PICK_HEAD"),w=g?await M(e,g):p,b;b=await Ae(e,"rebase-merge/message")??await Ae(e,"MERGE_MSG")??void 0,b&&(b=Ft(b)),b||(b=p.message);let R=await ct(e,t);if(D(R))return R;let C=Nt(b),x=[c],y=await z(e,"MERGE_HEAD");y&&x.push(y);let P=await Gt(e,d,x,w.author,R,C);y&&(await ke(e,"MERGE_HEAD"),await Ce(e,"MERGE_MODE"));let k=me(C);await ee(e,t,"HEAD",c,P,`rebase (continue): ${k}`);let E=await fy(e),O=w.author.timestamp!==R.timestamp||w.author.timezone!==R.timezone,$=await zn(e,f.tree,d,w.author,R,O);r=`${await pn(e,E,P,C)} +-${$}`}o.todo.length===0||await ke(e,"REBASE_HEAD"),await ke(e,"CHERRY_PICK_HEAD"),await ke(e,"REVERT_HEAD"),await Ce(e,"MERGE_MSG"),await Ce(e,"rebase-merge/message")}let a=await Mc(e,t,n);return r&&(a.stdout=r+a.stdout),a}async function fm(e,t,n){if(!await Bt(e))return v("no rebase in progress");let o=await Z(e);if(!o)return{stdout:"",stderr:`error: could not determine HEAD revision ++`);if(u){let p=await M(e,i),g=await z(e,"CHERRY_PICK_HEAD"),w=g?await M(e,g):p,b;b=await He(e,"rebase-merge/message")??await He(e,"MERGE_MSG")??void 0,b&&(b=_t(b)),b||(b=p.message);let y=await dt(e,t);if(D(y))return y;let C=Bt(b),x=[c],k=await z(e,"MERGE_HEAD");k&&x.push(k);let P=await Ut(e,d,x,w.author,y,C);k&&(await Ee(e,"MERGE_HEAD"),await xe(e,"MERGE_MODE"));let E=he(C);await ee(e,t,"HEAD",c,P,`rebase (continue): ${E}`);let R=await Fy(e),O=w.author.timestamp!==y.timestamp||w.author.timezone!==y.timezone,$=await Kn(e,f.tree,d,w.author,y,O);r=`${await yn(e,R,P,C)} ++${$}`}s.todo.length===0||await Ee(e,"REBASE_HEAD"),await Ee(e,"CHERRY_PICK_HEAD"),await Ee(e,"REVERT_HEAD"),await xe(e,"MERGE_MSG"),await xe(e,"rebase-merge/message")}let a=await zc(e,t,n);return r&&(a.stdout=r+a.stdout),a}async function Cm(e,t,n){if(!await zt(e))return v("no rebase in progress");let s=await Z(e);if(!s)return{stdout:"",stderr:`error: could not determine HEAD revision + fatal: could not discard worktree changes +-`,exitCode:128};let s=await M(e,o),i=await X(e),a=await _n(e,s.tree,i);return a.success&&(await ie(e,{version:2,entries:a.newEntries}),await je(e,a.worktreeOps)),await ke(e,"REBASE_HEAD"),await ke(e,"CHERRY_PICK_HEAD"),await ke(e,"REVERT_HEAD"),await ke(e,"MERGE_HEAD"),await Ce(e,"MERGE_MSG"),await Ce(e,"MERGE_MODE"),await Ce(e,"rebase-merge/message"),Mc(e,t,n)}function lm(e,t,n,r,o){if(t.useRebase&&!n&&r.length>0&&o){let s=e?.type==="symbolic"?Ie(e.target):"HEAD";return s==="HEAD"?`HEAD is up to date. +-`:`Current branch ${s} is up to date. ++`,exitCode:128};let o=await M(e,s),i=await X(e),a=await Bn(e,o.tree,i);return a.success&&(await oe(e,{version:2,entries:a.newEntries}),await Me(e,a.worktreeOps)),await Ee(e,"REBASE_HEAD"),await Ee(e,"CHERRY_PICK_HEAD"),await Ee(e,"REVERT_HEAD"),await Ee(e,"MERGE_HEAD"),await xe(e,"MERGE_MSG"),await xe(e,"MERGE_MODE"),await xe(e,"rebase-merge/message"),zc(e,t,n)}function xm(e,t,n,r,s){if(t.useRebase&&!n&&r.length>0&&s){let o=e?.type==="symbolic"?ve(e.target):"HEAD";return o==="HEAD"?`HEAD is up to date. ++`:`Current branch ${o} is up to date. + `}return`Already up to date. +-`}function dm(e,t){e.command("pull",{description:"Fetch from and integrate with another repository",args:[W.string().name("remote").describe("Remote to pull from").optional(),W.string().name("branch").describe("Remote branch").optional()],options:{rebase:S().alias("r").describe("Rebase instead of merge"),noRebase:S().describe("Merge instead of rebase"),ffOnly:S().describe("Only fast-forward"),noFf:S().describe("Create a merge commit even for fast-forwards"),depth:K.number().describe("Limit fetching to the specified number of commits"),unshallow:S().describe("Convert a shallow repository to a complete one"),quiet:ce("be more quiet")},handler:async(n,r)=>{let o=!!n.quiet,s=await q(r.fs,r.cwd,t);if(D(s))return s;let i=s,a=await Oi(i,n);if(D(a))return a;let{depth:c}=a,f=await nt(i);if(D(f))return f;let l=await te(i),d=await X(i);if(kn(d))return{stdout:"",stderr:`error: Pulling is not possible because you have unmerged files. ++`}function Pm(e,t){e.command("pull",{description:"Fetch from and integrate with another repository",args:[B.string().name("remote").describe("Remote to pull from").optional(),B.string().name("branch").describe("Remote branch").optional()],options:{rebase:S().alias("r").describe("Rebase instead of merge"),noRebase:S().describe("Merge instead of rebase"),ffOnly:S().describe("Only fast-forward"),noFf:S().describe("Create a merge commit even for fast-forwards"),depth:K.number().describe("Limit fetching to the specified number of commits"),unshallow:S().describe("Convert a shallow repository to a complete one"),quiet:ce("be more quiet")},handler:async(n,r)=>{let s=!!n.quiet,o=await W(r.fs,r.cwd,t);if(D(o))return o;let i=o,a=await Li(i,n);if(D(a))return a;let{depth:c}=a,f=await nt(i);if(D(f))return f;let l=await ne(i),d=await X(i);if(xn(d))return{stdout:"",stderr:`error: Pulling is not possible because you have unmerged files. + hint: Fix them up in the work tree, and then use 'git add/rm ' + hint: as appropriate to mark resolution and make a commit. + fatal: Exiting because of an unresolved conflict. +-`,exitCode:128};let u=n.remote,m=n.branch,h=null;if(!u&&l?.type==="symbolic"){let se=l.target.startsWith("refs/heads/")?l.target.slice(11):l.target,it=(await we(i))[`branch "${se}"`];it?(u=it.remote||"origin",!m&&it.merge&&(m=it.merge.startsWith("refs/heads/")?it.merge.slice(11):it.merge)):m||(h=se)}u=u||"origin";let p=await by(i,n,l);if(p.useRebase){let se=await zo(i,f,d);if(se)return Ko("pull with rebase",se,128)}let g=await Si(i,u,r.env,se=>({stdout:"",stderr:`fatal: ${se} +-`,exitCode:1}));if(D(g))return g;let{transport:w,config:b}=g,R=m??null,C=await t?.hooks?.prePull?.({repo:i,remote:u,branch:R});if(he(C))return{stdout:"",stderr:C.message??"",exitCode:1};let x=b.anonymous===!0,y=_r(b.fetchRefspec),P=await w.advertiseRefs(),k=await io(i),E=[],O=new Set,$=[];if(x){let se=m?P.find(_e=>_e.name===`refs/heads/${m}`):P.find(_e=>_e.name==="HEAD");se&&!O.has(se.hash)&&(O.add(se.hash),E.push(se.hash))}else for(let se of P){if(se.name==="HEAD")continue;let _e=ao(y,se.name);_e!==null&&($.push({remote:se,localRef:_e}),O.has(se.hash)||(O.add(se.hash),E.push(se.hash)))}let T=new Set(k),j=E.filter(se=>!T.has(se)),{existingShallows:U,shallowOpts:G}=await vi(i,c),N=j.length>0?j:G?E:[];if(N.length>0){let se=await w.fetch(N,k,G);se.shallowUpdates&&await ms(i,se.shallowUpdates,U)}let A=await Jn(i,r.env),H=[];for(let se of $){let _e=await z(i,se.localRef);H.push(_e),await Q(i,se.localRef,se.remote.hash),await rt(i,se.localRef,{oldHash:_e??oe,newHash:se.remote.hash,name:A.name,email:A.email,timestamp:A.timestamp,tz:A.tz,message:_e?"pull":"pull: storing head"})}let B=o?[]:Bs($.map((se,_e)=>({...se,oldHash:H[_e]})),Zt,await en(i,$.flatMap((se,_e)=>{let it=H[_e];return it?[it,se.remote.hash]:[se.remote.hash]}))),L=await Ii({gitCtx:i,transport:w,remoteRefs:P,ident:A,reflogAction:"pull"});o||B.push(...L);let _=B.length>0?`From ${b.url} +-${os(B,10)}`:"";if(x||await es(i,u,P,w.headTarget),l?.type!=="symbolic"&&!m){let se=p.useRebase?"rebase against":"merge with";return{stdout:"",stderr:_+`You are not currently on a branch. +-Please specify which branch you want to ${se}. ++`,exitCode:128};let u=n.remote,m=n.branch,h=null;if(!u&&l?.type==="symbolic"){let re=l.target.startsWith("refs/heads/")?l.target.slice(11):l.target,ft=(await be(i))[`branch "${re}"`];ft?(u=ft.remote||"origin",!m&&ft.merge&&(m=ft.merge.startsWith("refs/heads/")?ft.merge.slice(11):ft.merge)):m||(h=re)}u=u||"origin";let p=await Vy(i,n,l);if(p.useRebase){let re=await ti(i,f,d);if(re)return ni("pull with rebase",re,128)}let g=await Gi(i,u,r.env,re=>({stdout:"",stderr:`fatal: ${re} ++`,exitCode:1}));if(D(g))return g;let{transport:w,config:b}=g,y=m??null,C=await t?.hooks?.prePull?.({repo:i,remote:u,branch:y});if(pe(C))return{stdout:"",stderr:C.message??"",exitCode:1};let x=b.anonymous===!0,k=zr(b.fetchRefspec),P=await w.advertiseRefs(),E=await po(i),R=[],O=new Set,$=[];if(x){let re=m?P.find(Be=>Be.name===`refs/heads/${m}`):P.find(Be=>Be.name==="HEAD");re&&!O.has(re.hash)&&(O.add(re.hash),R.push(re.hash))}else for(let re of P){if(re.name==="HEAD")continue;let Be=go(k,re.name);Be!==null&&($.push({remote:re,localRef:Be}),O.has(re.hash)||(O.add(re.hash),R.push(re.hash)))}let T=new Set(E),j=R.filter(re=>!T.has(re)),{existingShallows:U,shallowOpts:G}=await Fi(i,c),L=j.length>0?j:G?R:[];if(L.length>0){let re=await w.fetch(L,E,G);re.shallowUpdates&&await ws(i,re.shallowUpdates,U)}let A=await Jn(i,r.env),H=[];for(let re of $){let Be=await z(i,re.localRef);H.push(Be),await Q(i,re.localRef,re.remote.hash),await st(i,re.localRef,{oldHash:Be??se,newHash:re.remote.hash,name:A.name,email:A.email,timestamp:A.timestamp,tz:A.tz,message:Be?"pull":"pull: storing head"})}let q=s?[]:Ys($.map((re,Be)=>({...re,oldHash:H[Be]})),nn,await sn(i,$.flatMap((re,Be)=>{let ft=H[Be];return ft?[ft,re.remote.hash]:[re.remote.hash]}))),F=await Ni({gitCtx:i,transport:w,remoteRefs:P,ident:A,reflogAction:"pull"});s||q.push(...F);let _=q.length>0?`From ${b.url} ++${cs(q,10)}`:"";if(x||await rs(i,u,P,w.headTarget),l?.type!=="symbolic"&&!m){let re=p.useRebase?"rebase against":"merge with";return{stdout:"",stderr:_+`You are not currently on a branch. ++Please specify which branch you want to ${re}. + See git-pull(1) for details. + + git pull + +-`,exitCode:1}}if(h){let se=p.useRebase?"rebase against":"merge with",_e=await we(i),it=[];for(let Cr of Object.keys(_e)){let po=Cr.match(/^remote "(.+)"$/);po?.[1]&&it.push(po[1])}let Qn=it.length===1?it[0]:"";return{stdout:"",stderr:_+`There is no tracking information for the current branch. +-Please specify which branch you want to ${se}. ++`,exitCode:1}}if(h){let re=p.useRebase?"rebase against":"merge with",Be=await be(i),ft=[];for(let Pr of Object.keys(Be)){let Co=Pr.match(/^remote "(.+)"$/);Co?.[1]&&ft.push(Co[1])}let Qn=ft.length===1?ft[0]:"";return{stdout:"",stderr:_+`There is no tracking information for the current branch. ++Please specify which branch you want to ${re}. + See git-pull(1) for details. + + git pull +@@ -611,10 +618,10 @@ If you wish to set tracking information for this branch you can do so with: + + git branch --set-upstream-to=${Qn}/ ${h} + +-`,exitCode:1}}let V=null;if(m){let se=P.find(_e=>_e.name===`refs/heads/${m}`);if(se)V=se.hash;else return{stdout:"",stderr:_+`Your configuration specifies to merge with the ref 'refs/heads/${m}' ++`,exitCode:1}}let Y=null;if(m){let re=P.find(Be=>Be.name===`refs/heads/${m}`);if(re)Y=re.hash;else return{stdout:"",stderr:_+`Your configuration specifies to merge with the ref 'refs/heads/${m}' + from the remote, but no such ref was fetched. +-`,exitCode:1}}else{let se=P.find(_e=>_e.name==="HEAD");se&&(V=se.hash)}if(V&&await r.fs.writeFile(I(i.gitDir,"FETCH_HEAD"),`${V} ${b.url} +-`),!V)return v("Could not determine remote HEAD");let Y=V;if(await Ce(i,"MERGE_MSG"),f===Y)return await t?.hooks?.postPull?.({repo:i,remote:u,branch:R,strategy:"up-to-date",commitHash:null}),{stdout:o?"":lm(l,p,!!n.ffOnly,_,!1),stderr:_,exitCode:0};if(p.useRebase&&!p.ffOnly){if(((await ft(i,f,Y))[0]??null)===f){let Cr=await Zs(i,f,Y,{quiet:o});if(Cr.exitCode===0){let po=l?.type==="symbolic"?l.target:"HEAD",Jc=`pull${p.noFf?" --no-ff":""}: Fast-forward`;await rt(i,po,{oldHash:f,newHash:Y,name:A.name,email:A.email,timestamp:A.timestamp,tz:A.tz,message:Jc}),l?.type==="symbolic"&&await rt(i,"HEAD",{oldHash:f,newHash:Y,name:A.name,email:A.email,timestamp:A.timestamp,tz:A.tz,message:Jc}),await t?.hooks?.postMerge?.({repo:i,headHash:f,theirsHash:Y,strategy:"fast-forward",commitHash:null}),await t?.hooks?.postPull?.({repo:i,remote:u,branch:R,strategy:"fast-forward",commitHash:Y})}return{...Cr,stderr:_+Cr.stderr}}let _e=l?.type==="symbolic"?l.target:"detached HEAD",it=m?`${u}/${m}`:u,Qn=await Gi(i,r.env,f,_e,Y,Y,it,Y,t,{reflogAction:"pull",quiet:o});if(Qn.exitCode===0){let Cr=await Z(i);await t?.hooks?.postPull?.({repo:i,remote:u,branch:R,strategy:"rebase",commitHash:Cr})}return{...Qn,stderr:_+Qn.stderr}}let fe=await ft(i,f,Y),J=fe[0]??null;if(J===Y)return await t?.hooks?.postPull?.({repo:i,remote:u,branch:R,strategy:"up-to-date",commitHash:null}),{stdout:o?"":lm(l,p,!!n.ffOnly,_,!0),stderr:_,exitCode:0};let{noFf:re,ffOnly:Oe,ffOnlySource:xe,hasReconciliationStrategy:Xe}=p,Ct=J===f;if(!Ct&&!Xe)return{stdout:"",stderr:_+`hint: You have divergent branches and need to specify how to reconcile them. ++`,exitCode:1}}else{let re=P.find(Be=>Be.name==="HEAD");re&&(Y=re.hash)}if(Y&&await r.fs.writeFile(I(i.gitDir,"FETCH_HEAD"),`${Y} ${b.url} ++`),!Y)return v("Could not determine remote HEAD");let V=Y;if(await xe(i,"MERGE_MSG"),f===V)return await t?.hooks?.postPull?.({repo:i,remote:u,branch:y,strategy:"up-to-date",commitHash:null}),{stdout:s?"":xm(l,p,!!n.ffOnly,_,!1),stderr:_,exitCode:0};if(p.useRebase&&!p.ffOnly){if(((await mt(i,f,V))[0]??null)===f){let Pr=await so(i,f,V,{quiet:s});if(Pr.exitCode===0){let Co=l?.type==="symbolic"?l.target:"HEAD",ff=`pull${p.noFf?" --no-ff":""}: Fast-forward`;await st(i,Co,{oldHash:f,newHash:V,name:A.name,email:A.email,timestamp:A.timestamp,tz:A.tz,message:ff}),l?.type==="symbolic"&&await st(i,"HEAD",{oldHash:f,newHash:V,name:A.name,email:A.email,timestamp:A.timestamp,tz:A.tz,message:ff}),await t?.hooks?.postMerge?.({repo:i,headHash:f,theirsHash:V,strategy:"fast-forward",commitHash:null}),await t?.hooks?.postPull?.({repo:i,remote:u,branch:y,strategy:"fast-forward",commitHash:V})}return{...Pr,stderr:_+Pr.stderr}}let Be=l?.type==="symbolic"?l.target:"detached HEAD",ft=m?`${u}/${m}`:u,Qn=await Vi(i,r.env,f,Be,V,V,ft,V,t,{reflogAction:"pull",quiet:s});if(Qn.exitCode===0){let Pr=await Z(i);await t?.hooks?.postPull?.({repo:i,remote:u,branch:y,strategy:"rebase",commitHash:Pr})}return{...Qn,stderr:_+Qn.stderr}}let ue=await mt(i,f,V),Ce=ue[0]??null;if(Ce===V)return await t?.hooks?.postPull?.({repo:i,remote:u,branch:y,strategy:"up-to-date",commitHash:null}),{stdout:s?"":xm(l,p,!!n.ffOnly,_,!0),stderr:_,exitCode:0};let{noFf:Qe,ffOnly:ae,ffOnlySource:J,hasReconciliationStrategy:je}=p,at=Ce===f;if(!at&&!je)return{stdout:"",stderr:_+`hint: You have divergent branches and need to specify how to reconcile them. + hint: You can do so by running one of the following commands sometime before + hint: your next pull: + hint: +@@ -627,8 +634,8 @@ hint: preference for all repositories. You can also pass --rebase, --no-rebase, + hint: or --ff-only on the command line to override the configured default per + hint: invocation. + fatal: Need to specify how to reconcile divergent branches. +-`,exitCode:128};if(fe.length===0&&xe!=="cli"&&xe!=="pull")return{stdout:"",stderr:_+`fatal: refusing to merge unrelated histories +-`,exitCode:128};if(Oe&&!Ct)return{stdout:"",stderr:_+`hint: Diverging branches can't be fast-forwarded, you need to either: ++`,exitCode:128};if(ue.length===0&&J!=="cli"&&J!=="pull")return{stdout:"",stderr:_+`fatal: refusing to merge unrelated histories ++`,exitCode:128};if(ae&&!at)return{stdout:"",stderr:_+`hint: Diverging branches can't be fast-forwarded, you need to either: + hint: + hint: git merge --no-ff + hint: +@@ -638,18 +645,18 @@ hint: git rebase + hint: + hint: Disable this message with "git config set advice.diverging false" + fatal: Not possible to fast-forward, aborting. +-`,exitCode:128};if(Ct&&!re){let se=await Zs(i,f,Y,{quiet:o});if(se.exitCode===0){let _e=l?.type==="symbolic"?l.target:"HEAD",Qn=`pull${Oe?" --ff-only":""}: Fast-forward`;await rt(i,_e,{oldHash:f,newHash:Y,name:A.name,email:A.email,timestamp:A.timestamp,tz:A.tz,message:Qn}),l?.type==="symbolic"&&await rt(i,"HEAD",{oldHash:f,newHash:Y,name:A.name,email:A.email,timestamp:A.timestamp,tz:A.tz,message:Qn}),await t?.hooks?.postMerge?.({repo:i,headHash:f,theirsHash:Y,strategy:"fast-forward",commitHash:null}),await t?.hooks?.postPull?.({repo:i,remote:u,branch:R,strategy:"fast-forward",commitHash:Y})}return{...se,stderr:_+se.stderr}}let an=l?.type==="symbolic"?Ie(l.target):"HEAD",Ze=Y,Zn=m||"HEAD",zc=await Re(i,"merge.conflictstyle")??"merge",Kc={a:"HEAD",b:Ze,conflictStyle:zc},Rr=await eo(i,f,Y,Kc,t?.mergeDriver),zi=mt("merge",Rr.neededRenameLimit),Vc=await M(i,f),Wr=await Kn(i,Rr,Vc.tree,{labels:Kc,errorExitCode:2,operationName:"merge"});if(!Wr.ok){if(Wr.failureKind==="staged"&&l?.type==="symbolic"){let se=re?" --no-ff":"";await rt(i,"HEAD",{oldHash:f,newHash:f,name:A.name,email:A.email,timestamp:A.timestamp,tz:A.tz,message:`pull${se}: updating HEAD`})}return{stdout:Wr.stdout,stderr:_+zi+Wr.stderr,exitCode:Wr.exitCode}}if(Rr.conflicts.length>0){await Q(i,"MERGE_HEAD",Y),await Q(i,"ORIG_HEAD",f);let se=await Lr(i,Zn,an,b.url),_e=fn({version:2,entries:Rr.entries}).sort();return se+=` ++`,exitCode:128};if(at&&!Qe){let re=await so(i,f,V,{quiet:s});if(re.exitCode===0){let Be=l?.type==="symbolic"?l.target:"HEAD",Qn=`pull${ae?" --ff-only":""}: Fast-forward`;await st(i,Be,{oldHash:f,newHash:V,name:A.name,email:A.email,timestamp:A.timestamp,tz:A.tz,message:Qn}),l?.type==="symbolic"&&await st(i,"HEAD",{oldHash:f,newHash:V,name:A.name,email:A.email,timestamp:A.timestamp,tz:A.tz,message:Qn}),await t?.hooks?.postMerge?.({repo:i,headHash:f,theirsHash:V,strategy:"fast-forward",commitHash:null}),await t?.hooks?.postPull?.({repo:i,remote:u,branch:y,strategy:"fast-forward",commitHash:V})}return{...re,stderr:_+re.stderr}}let vt=l?.type==="symbolic"?ve(l.target):"HEAD",_e=V,Zt=m||"HEAD",Cr=await Re(i,"merge.conflictstyle")??"merge",xs={a:"HEAD",b:_e,conflictStyle:Cr},xr=await co(i,f,V,xs,t?.mergeDriver),na=wt("merge",xr.neededRenameLimit),rf=await M(i,f),Vr=await Yn(i,xr,rf.tree,{labels:xs,errorExitCode:2,operationName:"merge"});if(!Vr.ok){if(Vr.failureKind==="staged"&&l?.type==="symbolic"){let re=Qe?" --no-ff":"";await st(i,"HEAD",{oldHash:f,newHash:f,name:A.name,email:A.email,timestamp:A.timestamp,tz:A.tz,message:`pull${re}: updating HEAD`})}return{stdout:Vr.stdout,stderr:_+na+Vr.stderr,exitCode:Vr.exitCode}}if(xr.conflicts.length>0){await Q(i,"MERGE_HEAD",V),await Q(i,"ORIG_HEAD",f);let re=await Ur(i,Zt,vt,b.url),Be=mn({version:2,entries:xr.entries}).sort();return re+=` + # Conflicts: +-${_e.map(it=>`# ${it}`).join(` ++${Be.map(ft=>`# ${ft}`).join(` + `)} +-`,await Ue(i,"MERGE_MSG",se),await Ue(i,"MERGE_MODE",re?"no-ff":""),{stdout:`${[...Rr.messages,"Automatic merge failed; fix conflicts and then commit the result."].join(` ++`,await Ne(i,"MERGE_MSG",re),await Ne(i,"MERGE_MODE",Qe?"no-ff":""),{stdout:`${[...xr.messages,"Automatic merge failed; fix conflicts and then commit the result."].join(` + `)} +-`,stderr:_+zi,exitCode:1}}let uo=Wr.mergedTreeHash,Ki=await Sn(i,r.env);if(D(Ki))return Ki;let Vi=await ct(i,r.env);if(D(Vi))return Vi;let mo=await Lr(i,Zn,an,b.url),Yc={repo:i,message:mo,treeHash:uo,headHash:f,theirsHash:Y},Xc=await t?.hooks?.mergeMsg?.(Yc);if(he(Xc))return{stdout:"",stderr:Xc.message??"",exitCode:1};mo=Yc.message;let Zc=await t?.hooks?.preMergeCommit?.({repo:i,message:mo,treeHash:uo,headHash:f,theirsHash:Y});if(he(Zc))return{stdout:"",stderr:Zc.message??"",exitCode:1};let ho=await Gt(i,uo,[f,Y],Ki,Vi,mo);await t?.hooks?.postMerge?.({repo:i,headHash:f,theirsHash:Y,strategy:"three-way",commitHash:ho}),await t?.hooks?.postPull?.({repo:i,remote:u,branch:R,strategy:"three-way",commitHash:ho});let Zm=l?.type==="symbolic"?l.target:"HEAD",Qc=`pull${re?" --no-ff":""}: Merge made by the 'ort' strategy.`;await rt(i,Zm,{oldHash:f,newHash:ho,name:A.name,email:A.email,timestamp:A.timestamp,tz:A.tz,message:Qc}),l?.type==="symbolic"&&await rt(i,"HEAD",{oldHash:f,newHash:ho,name:A.name,email:A.email,timestamp:A.timestamp,tz:A.tz,message:Qc});let Qm=Rr.messages.length>0?`${Rr.messages.join(` ++`,stderr:_+na,exitCode:1}}let ko=Vr.mergedTreeHash,ra=await An(i,r.env);if(D(ra))return ra;let sa=await dt(i,r.env);if(D(sa))return sa;let Eo=await Ur(i,Zt,vt,b.url),sf={repo:i,message:Eo,treeHash:ko,headHash:f,theirsHash:V},of=await t?.hooks?.mergeMsg?.(sf);if(pe(of))return{stdout:"",stderr:of.message??"",exitCode:1};Eo=sf.message;let af=await t?.hooks?.preMergeCommit?.({repo:i,message:Eo,treeHash:ko,headHash:f,theirsHash:V});if(pe(af))return{stdout:"",stderr:af.message??"",exitCode:1};let Ro=await Ut(i,ko,[f,V],ra,sa,Eo);await t?.hooks?.postMerge?.({repo:i,headHash:f,theirsHash:V,strategy:"three-way",commitHash:Ro}),await t?.hooks?.postPull?.({repo:i,remote:u,branch:y,strategy:"three-way",commitHash:Ro});let mh=l?.type==="symbolic"?l.target:"HEAD",cf=`pull${Qe?" --no-ff":""}: Merge made by the 'ort' strategy.`;await st(i,mh,{oldHash:f,newHash:Ro,name:A.name,email:A.email,timestamp:A.timestamp,tz:A.tz,message:cf}),l?.type==="symbolic"&&await st(i,"HEAD",{oldHash:f,newHash:Ro,name:A.name,email:A.email,timestamp:A.timestamp,tz:A.tz,message:cf});let hh=xr.messages.length>0?`${xr.messages.join(` + `)} +-`:"",Jm=o?"":`Merge made by the 'ort' strategy. +-${await Tn(i,Vc.tree,uo)}`;return{stdout:`${Qm}${Jm}`,stderr:_+zi,exitCode:0}}})}async function by(e,t,n){let r=!!t.noFf,o=!!t.ffOnly,s=t.ffOnly?"cli":null,i=!!t.rebase||!!t.noRebase||!!t.noFf||!!t.ffOnly,a=!1;if(t.rebase)a=!0;else if(!t.noRebase)if(n?.type==="symbolic"){let c=n.target.startsWith("refs/heads/")?n.target.slice(11):n.target,f=await Re(e,`branch.${c}.rebase`);if(f==="true")a=!0,i=!0;else if(f==="false")i=!0;else{let l=await Re(e,"pull.rebase");l==="true"?(a=!0,i=!0):l==="false"&&(i=!0)}}else{let c=await Re(e,"pull.rebase");c==="true"?(a=!0,i=!0):c==="false"&&(i=!0)}if(!t.noFf&&!t.ffOnly){let c=await Re(e,"pull.ff");if(c==="false")r=!0,i=!0;else if(c==="only")o=!0,s="pull",i=!0;else{let f=await Re(e,"merge.ff");f==="false"?r=!0:f==="only"&&(o=!0,s="merge")}}return{useRebase:a,noFf:r,ffOnly:o,ffOnlySource:s,hasReconciliationStrategy:i}}ne();Be();St();ye();Ee();function mm(e,t){e.command("push",{description:"Update remote refs along with associated objects",args:[W.string().name("remote").describe("Remote to push to").optional(),W.string().name("refspec").describe("Refspec(s) to push").optional().variadic()],options:{force:S().alias("f").describe("Force push"),"set-upstream":S().alias("u").describe("Set upstream tracking reference"),all:S().describe("Push all branches"),delete:S().alias("d").describe("Delete remote refs"),tags:S().describe("Push all tags"),quiet:ce("be more quiet")},handler:async(n,r)=>{let o=await q(r.fs,r.cwd,t);if(D(o))return o;let s=o,i=n.remote||"origin",a=n.refspec,c=!!n.quiet,f;try{f=await Ci(s,i,r.env)}catch(k){let E=k instanceof Error?k.message:"";if(E.startsWith("network"))return v(E);throw k}if(!f)return v(`'${i}' does not appear to be a git repository`);let{transport:l,config:d}=f,u=n.force,m=await l.advertiseRefs(),h=new Map;for(let k of m)h.set(k.name,k.hash);if(n.tags&&n.all)return v("options '--tags' and '--all/--branches' cannot be used together");if(n.tags&&n.delete)return v("options '--delete' and '--tags' cannot be used together");let p=[];if(n.delete){let k=a&&a.length>0?a:[];if(k.length===0)return v("--delete requires a ref argument");let E=[];for(let O of k){let $=O.startsWith("refs/")?O:h.has(`refs/heads/${O}`)?`refs/heads/${O}`:h.has(`refs/tags/${O}`)?`refs/tags/${O}`:`refs/heads/${O}`,T=h.get($)??null;if(!T){E.push(`error: unable to delete '${O}': remote ref does not exist +-`);continue}p.push({name:$,oldHash:T,newHash:oe,ok:u})}if(E.length>0&&p.length===0)return F(E.join("")+`error: failed to push some refs to '${d.url}' +-`)}else if(n.all){let k=await $e(s,"refs/heads");for(let E of k){let O=E.name,$=h.get(O)??null;p.push({name:O,oldHash:$,newHash:E.hash,ok:u})}}else if(a&&a.length>0)for(let k of a){let E=_r(k),O=k.replace(/^\+/,"").includes(":"),$=E.dst;if(!O&&E.src==="HEAD"){let G=await te(s);if(G?.type==="symbolic")$=G.target.startsWith("refs/heads/")?G.target.slice(11):G.target;else return{stdout:"",stderr:`error: The destination you provided is not a full refname (i.e., ++`:"",ph=s?"":`Merge made by the 'ort' strategy. ++${await Mn(i,rf.tree,ko)}`;return{stdout:`${hh}${ph}`,stderr:_+na,exitCode:0}}})}async function Vy(e,t,n){let r=!!t.noFf,s=!!t.ffOnly,o=t.ffOnly?"cli":null,i=!!t.rebase||!!t.noRebase||!!t.noFf||!!t.ffOnly,a=!1;if(t.rebase)a=!0;else if(!t.noRebase)if(n?.type==="symbolic"){let c=n.target.startsWith("refs/heads/")?n.target.slice(11):n.target,f=await Re(e,`branch.${c}.rebase`);if(f==="true")a=!0,i=!0;else if(f==="false")i=!0;else{let l=await Re(e,"pull.rebase");l==="true"?(a=!0,i=!0):l==="false"&&(i=!0)}}else{let c=await Re(e,"pull.rebase");c==="true"?(a=!0,i=!0):c==="false"&&(i=!0)}if(!t.noFf&&!t.ffOnly){let c=await Re(e,"pull.ff");if(c==="false")r=!0,i=!0;else if(c==="only")s=!0,o="pull",i=!0;else{let f=await Re(e,"merge.ff");f==="false"?r=!0:f==="only"&&(s=!0,o="merge")}}return{useRebase:a,noFf:r,ffOnly:s,ffOnlySource:o,hasReconciliationStrategy:i}}te();We();It();ye();ke();function Om(e,t){e.command("push",{description:"Update remote refs along with associated objects",args:[B.string().name("remote").describe("Remote to push to").optional(),B.string().name("refspec").describe("Refspec(s) to push").optional().variadic()],options:{force:S().alias("f").describe("Force push"),"set-upstream":S().alias("u").describe("Set upstream tracking reference"),all:S().describe("Push all branches"),delete:S().alias("d").describe("Delete remote refs"),tags:S().describe("Push all tags"),quiet:ce("be more quiet")},handler:async(n,r)=>{let s=await W(r.fs,r.cwd,t);if(D(s))return s;let o=s,i=n.remote||"origin",a=n.refspec,c=!!n.quiet,f;try{f=await Hi(o,i,r.env)}catch(E){let R=E instanceof Error?E.message:"";if(R.startsWith("network"))return v(R);throw E}if(!f)return v(`'${i}' does not appear to be a git repository`);let{transport:l,config:d}=f,u=n.force,m=await l.advertiseRefs(),h=new Map;for(let E of m)h.set(E.name,E.hash);if(n.tags&&n.all)return v("options '--tags' and '--all/--branches' cannot be used together");if(n.tags&&n.delete)return v("options '--delete' and '--tags' cannot be used together");let p=[];if(n.delete){let E=a&&a.length>0?a:[];if(E.length===0)return v("--delete requires a ref argument");let R=[];for(let O of E){let $=O.startsWith("refs/")?O:h.has(`refs/heads/${O}`)?`refs/heads/${O}`:h.has(`refs/tags/${O}`)?`refs/tags/${O}`:`refs/heads/${O}`,T=h.get($)??null;if(!T){R.push(`error: unable to delete '${O}': remote ref does not exist ++`);continue}p.push({name:$,oldHash:T,newHash:se,ok:u})}if(R.length>0&&p.length===0)return N(R.join("")+`error: failed to push some refs to '${d.url}' ++`)}else if(n.all){let E=await $e(o,"refs/heads");for(let R of E){let O=R.name,$=h.get(O)??null;p.push({name:O,oldHash:$,newHash:R.hash,ok:u})}}else if(a&&a.length>0)for(let E of a){let R=zr(E),O=E.replace(/^\+/,"").includes(":"),$=R.dst;if(!O&&R.src==="HEAD"){let G=await ne(o);if(G?.type==="symbolic")$=G.target.startsWith("refs/heads/")?G.target.slice(11):G.target;else return{stdout:"",stderr:`error: The destination you provided is not a full refname (i.e., + starting with "refs/"). We tried to guess what you meant by: + + - Looking for a ref that matches 'HEAD' on the remote side. +@@ -662,20 +669,20 @@ hint: The part of the refspec is a commit object. + hint: Did you mean to create a new branch by pushing to + hint: 'HEAD:refs/heads/HEAD'? + error: failed to push some refs to '${d.url}' +-`,exitCode:1}}let T=await Ey(s,E.src);if(!T)return F(`error: src refspec ${E.src} does not match any ++`,exitCode:1}}let T=await Zy(o,R.src);if(!T)return N(`error: src refspec ${R.src} does not match any + error: failed to push some refs to '${d.url}' +-`);let j;$.startsWith("refs/")?j=$:!O&&T.fullRef.startsWith("refs/")?j=T.fullRef.slice(0,T.fullRef.indexOf("/",5)+1)+$:j=`refs/heads/${$}`;let U=h.get(j)??null;p.push({name:j,oldHash:U,newHash:T.hash,ok:u||E.force})}else if(!n.tags){let k=(await Re(s,"push.default"))?.toLowerCase()??"simple";if(k==="nothing")return v(`You didn't specify any refspecs to push, and push.default is "nothing".`);let E=await te(s);if(!E||E.type!=="symbolic")return v(`You are not currently on a branch. ++`);let j;$.startsWith("refs/")?j=$:!O&&T.fullRef.startsWith("refs/")?j=T.fullRef.slice(0,T.fullRef.indexOf("/",5)+1)+$:j=`refs/heads/${$}`;let U=h.get(j)??null;p.push({name:j,oldHash:U,newHash:T.hash,ok:u||R.force})}else if(!n.tags){let E=(await Re(o,"push.default"))?.toLowerCase()??"simple";if(E==="nothing")return v(`You didn't specify any refspecs to push, and push.default is "nothing".`);let R=await ne(o);if(!R||R.type!=="symbolic")return v(`You are not currently on a branch. + To push the history leading to the current (detached HEAD) + state now, use + + git push origin HEAD: +-`);let O=E.target,$=O.startsWith("refs/heads/")?O.slice(11):O,T=await Z(s);if(!T)return F(`error: src refspec does not match any +-`);let j=await yy(s,k,O,$,T,i,h,u);if("exitCode"in j)return j;p.push(j)}if(n.tags){let k=await $e(s,"refs/tags");for(let E of k){let O=h.get(E.name)??null;O!==E.hash&&(p.some($=>$.name===E.name)||p.push({name:E.name,oldHash:O,newHash:E.hash,ok:u}))}}let g=p.filter(k=>k.oldHash!==k.newHash);if(g.length===0){let k="";if(n["set-upstream"]){let E=await te(s);if(E?.type==="symbolic"){let O=E.target.startsWith("refs/heads/")?E.target.slice(11):E.target,$=await we(s);$[`branch "${O}"`]={remote:i,merge:`refs/heads/${O}`},await et(s,$),c||(k=`branch '${O}' set up to track '${i}/${O}'. +-`)}}return{stdout:k,stderr:c?"":`Everything up-to-date +-`,exitCode:0}}let w=await t?.hooks?.prePush?.({repo:s,remote:i,url:d.url,refs:g.map(k=>({srcRef:k.newHash===oe?null:k.name,srcHash:k.newHash===oe?null:k.newHash,dstRef:k.name,dstHash:k.oldHash,force:!!k.ok,delete:k.newHash===oe}))});if(he(w))return F(w.message??"");let b=new Set(g.filter(k=>k.ok).map(k=>k.name)),R=await l.push(g),C=R.updates.some(k=>!k.ok),x=[];if(!c||C){let k=await ky(s,R.updates,b);x.push(`To ${d.url} +-`),x.push(os(k,0,!1))}if(C){let k=R.updates.some($=>!$.ok&&$.name.startsWith("refs/tags/")&&$.error?.includes("non-fast-forward"));x.push(`error: failed to push some refs to '${d.url}' +-`);let E=R.updates.some($=>!$.ok&&$.error?.includes("fetch first")),O=R.updates.some($=>!$.ok&&$.error?.includes("non-fast-forward"));k?x.push(`hint: Updates were rejected because the tag already exists in the remote. +-`):E?x.push(`hint: Updates were rejected because the remote contains work that you do not ++`);let O=R.target,$=O.startsWith("refs/heads/")?O.slice(11):O,T=await Z(o);if(!T)return N(`error: src refspec does not match any ++`);let j=await Yy(o,E,O,$,T,i,h,u);if("exitCode"in j)return j;p.push(j)}if(n.tags){let E=await $e(o,"refs/tags");for(let R of E){let O=h.get(R.name)??null;O!==R.hash&&(p.some($=>$.name===R.name)||p.push({name:R.name,oldHash:O,newHash:R.hash,ok:u}))}}let g=p.filter(E=>E.oldHash!==E.newHash);if(g.length===0){let E="";if(n["set-upstream"]){let R=await ne(o);if(R?.type==="symbolic"){let O=R.target.startsWith("refs/heads/")?R.target.slice(11):R.target,$=await be(o);$[`branch "${O}"`]={remote:i,merge:`refs/heads/${O}`},await et(o,$),c||(E=`branch '${O}' set up to track '${i}/${O}'. ++`)}}return{stdout:E,stderr:c?"":`Everything up-to-date ++`,exitCode:0}}let w=await t?.hooks?.prePush?.({repo:o,remote:i,url:d.url,refs:g.map(E=>({srcRef:E.newHash===se?null:E.name,srcHash:E.newHash===se?null:E.newHash,dstRef:E.name,dstHash:E.oldHash,force:!!E.ok,delete:E.newHash===se}))});if(pe(w))return N(w.message??"");let b=new Set(g.filter(E=>E.ok).map(E=>E.name)),y=await l.push(g),C=y.updates.some(E=>!E.ok),x=[];if(!c||C){let E=await Xy(o,y.updates,b);x.push(`To ${d.url} ++`),x.push(cs(E,0,!1))}if(C){let E=y.updates.some($=>!$.ok&&$.name.startsWith("refs/tags/")&&$.error?.includes("non-fast-forward"));x.push(`error: failed to push some refs to '${d.url}' ++`);let R=y.updates.some($=>!$.ok&&$.error?.includes("fetch first")),O=y.updates.some($=>!$.ok&&$.error?.includes("non-fast-forward"));E?x.push(`hint: Updates were rejected because the tag already exists in the remote. ++`):R?x.push(`hint: Updates were rejected because the remote contains work that you do not + hint: have locally. This is usually caused by another repository pushing to + hint: the same ref. If you want to integrate the remote changes, use + hint: 'git pull' before pushing again. +@@ -684,37 +691,37 @@ hint: See the 'Note about fast-forwards' in 'git push --help' for details. + hint: its remote counterpart. If you want to integrate the remote changes, + hint: use 'git pull' before pushing again. + hint: See the 'Note about fast-forwards' in 'git push --help' for details. +-`)}let y="";for(let k of R.updates){if(!k.ok||!k.name.startsWith("refs/heads/"))continue;let E=`refs/remotes/${i}/${k.name.slice(11)}`;k.newHash===oe?await ke(s,E):await Q(s,E,k.newHash)}if(n["set-upstream"]&&!C){let k=await te(s);if(k?.type==="symbolic"){let E=k.target.startsWith("refs/heads/")?k.target.slice(11):k.target,O=await we(s);O[`branch "${E}"`]={remote:i,merge:`refs/heads/${E}`},await et(s,O),c||(y=`branch '${E}' set up to track '${i}/${E}'. +-`)}}let P={stdout:y,stderr:x.join(""),exitCode:C?1:0};return C||await t?.hooks?.postPush?.({repo:s,remote:i,url:d.url,refs:g.map(k=>({srcRef:k.newHash===oe?null:k.name,srcHash:k.newHash===oe?null:k.newHash,dstRef:k.name,dstHash:k.oldHash,force:!!k.ok,delete:k.newHash===oe}))}),P}})}async function yy(e,t,n,r,o,s,i,a){if(t==="nothing")return v(`You didn't specify any refspecs to push, and push.default is "nothing".`);if(t==="current")return{name:n,oldHash:i.get(n)??null,newHash:o,ok:a};if(t==="upstream"){let d=(await we(e))[`branch "${r}"`];if(!d?.remote||!d?.merge)return v(`The current branch ${r} has no upstream branch. ++`)}let k="";for(let E of y.updates){if(!E.ok||!E.name.startsWith("refs/heads/"))continue;let R=`refs/remotes/${i}/${E.name.slice(11)}`;E.newHash===se?await Ee(o,R):await Q(o,R,E.newHash)}if(n["set-upstream"]&&!C){let E=await ne(o);if(E?.type==="symbolic"){let R=E.target.startsWith("refs/heads/")?E.target.slice(11):E.target,O=await be(o);O[`branch "${R}"`]={remote:i,merge:`refs/heads/${R}`},await et(o,O),c||(k=`branch '${R}' set up to track '${i}/${R}'. ++`)}}let P={stdout:k,stderr:x.join(""),exitCode:C?1:0};return C||await t?.hooks?.postPush?.({repo:o,remote:i,url:d.url,refs:g.map(E=>({srcRef:E.newHash===se?null:E.name,srcHash:E.newHash===se?null:E.newHash,dstRef:E.name,dstHash:E.oldHash,force:!!E.ok,delete:E.newHash===se}))}),P}})}async function Yy(e,t,n,r,s,o,i,a){if(t==="nothing")return v(`You didn't specify any refspecs to push, and push.default is "nothing".`);if(t==="current")return{name:n,oldHash:i.get(n)??null,newHash:s,ok:a};if(t==="upstream"){let d=(await be(e))[`branch "${r}"`];if(!d?.remote||!d?.merge)return v(`The current branch ${r} has no upstream branch. + To push the current branch and set the remote as upstream, use + +- git push --set-upstream ${s} ${r} +-`);let u=d.merge;return{name:u,oldHash:i.get(u)??null,newHash:o,ok:a}}let c=await we(e),f=c[`branch "${r}"`];if(f?.remote&&f?.merge){let l=f.remote,d=f.merge,u=c.push?.default?.toLowerCase();if(l===s){let m=d.startsWith("refs/heads/")?d.slice(11):d;if(m!==r){let h=u==="simple"?"":`To choose either option permanently, see push.default in 'git help config'. ++ git push --set-upstream ${o} ${r} ++`);let u=d.merge;return{name:u,oldHash:i.get(u)??null,newHash:s,ok:a}}let c=await be(e),f=c[`branch "${r}"`];if(f?.remote&&f?.merge){let l=f.remote,d=f.merge,u=c.push?.default?.toLowerCase();if(l===o){let m=d.startsWith("refs/heads/")?d.slice(11):d;if(m!==r){let h=u==="simple"?"":`To choose either option permanently, see push.default in 'git help config'. + + `;return v(`The upstream branch of your current branch does not match + the name of your current branch. To push to the upstream branch + on the remote, use + +- git push ${s} HEAD:${m} ++ git push ${o} HEAD:${m} + + To push to the branch of the same name on the remote, use + +- git push ${s} HEAD ++ git push ${o} HEAD + + `+h+`To avoid automatically configuring an upstream branch when its name + won't match the local branch, see option 'simple' of branch.autoSetupMerge + in 'git help config'. +-`)}return{name:d,oldHash:i.get(d)??null,newHash:o,ok:a}}return{name:n,oldHash:i.get(n)??null,newHash:o,ok:a}}return v(`The current branch ${r} has no upstream branch. ++`)}return{name:d,oldHash:i.get(d)??null,newHash:s,ok:a}}return{name:n,oldHash:i.get(n)??null,newHash:s,ok:a}}return v(`The current branch ${r} has no upstream branch. + To push the current branch and set the remote as upstream, use + +- git push --set-upstream ${s} ${r} ++ git push --set-upstream ${o} ${r} + + To have this happen automatically for branches without a tracking + upstream, see 'push.autoSetupRemote' in 'git help config'. +-`)}async function ky(e,t,n){let r=t.filter(a=>a.ok&&a.oldHash&&a.newHash!==oe&&n.has(a.name)),o=await Promise.all(r.map(a=>qt(e,a.oldHash,a.newHash))),s=new Set;r.forEach((a,c)=>{o[c]||s.add(a.name)});let i=[];for(let a of t){let c=a.name.startsWith("refs/tags/"),f=Zt(a.name);if(a.ok)if(a.oldHash)if(a.newHash===oe)i.push({prefix:" - [deleted]",from:f,to:""});else{let l=await ue(e,a.oldHash),d=await ue(e,a.newHash);s.has(a.name)?i.push({prefix:` + ${l}...${d}`,from:f,to:f,suffix:"(forced update)"}):i.push({prefix:` ${l}..${d}`,from:f,to:f})}else{let l=c?"[new tag]":"[new branch]";i.push({prefix:` * ${l}`,from:f,to:f})}else{let l=a.error?.includes("fetch first"),d=a.error?.includes("non-fast-forward"),u=l?"fetch first":c&&d?"already exists":d?"non-fast-forward":a.error??"failed";i.push({prefix:" ! [rejected]",from:f,to:f,suffix:`(${u})`})}}return i.sort((a,c)=>um(a)-um(c)),i}function um(e){return e.prefix.startsWith(" ")||e.prefix.startsWith(" + ")?0:e.prefix.includes("[new ")?1:e.prefix.includes("[deleted]")?2:e.prefix.includes("[rejected]")?3:4}async function Ey(e,t){if(t.startsWith("refs/")){let o=await z(e,t);return o?{hash:o,fullRef:t}:null}let n=await z(e,`refs/heads/${t}`);if(n)return{hash:n,fullRef:`refs/heads/${t}`};let r=await z(e,`refs/tags/${t}`);if(r)return{hash:r,fullRef:`refs/tags/${t}`};if(t==="HEAD"){let o=await Z(e);return o?{hash:o,fullRef:"HEAD"}:null}return null}ne();ye();Ee();var Ry=`usage: git rebase [-i] [options] [--exec ] [--onto | --keep-base] [ []] ++`)}async function Xy(e,t,n){let r=t.filter(a=>a.ok&&a.oldHash&&a.newHash!==se&&n.has(a.name)),s=await Promise.all(r.map(a=>Vt(e,a.oldHash,a.newHash))),o=new Set;r.forEach((a,c)=>{s[c]||o.add(a.name)});let i=[];for(let a of t){let c=a.name.startsWith("refs/tags/"),f=nn(a.name);if(a.ok)if(a.oldHash)if(a.newHash===se)i.push({prefix:" - [deleted]",from:f,to:""});else{let l=await fe(e,a.oldHash),d=await fe(e,a.newHash);o.has(a.name)?i.push({prefix:` + ${l}...${d}`,from:f,to:f,suffix:"(forced update)"}):i.push({prefix:` ${l}..${d}`,from:f,to:f})}else{let l=c?"[new tag]":"[new branch]";i.push({prefix:` * ${l}`,from:f,to:f})}else{let l=a.error?.includes("fetch first"),d=a.error?.includes("non-fast-forward"),u=l?"fetch first":c&&d?"already exists":d?"non-fast-forward":a.error??"failed";i.push({prefix:" ! [rejected]",from:f,to:f,suffix:`(${u})`})}}return i.sort((a,c)=>$m(a)-$m(c)),i}function $m(e){return e.prefix.startsWith(" ")||e.prefix.startsWith(" + ")?0:e.prefix.includes("[new ")?1:e.prefix.includes("[deleted]")?2:e.prefix.includes("[rejected]")?3:4}async function Zy(e,t){if(t.startsWith("refs/")){let s=await z(e,t);return s?{hash:s,fullRef:t}:null}let n=await z(e,`refs/heads/${t}`);if(n)return{hash:n,fullRef:`refs/heads/${t}`};let r=await z(e,`refs/tags/${t}`);if(r)return{hash:r,fullRef:`refs/tags/${t}`};if(t==="HEAD"){let s=await Z(e);return s?{hash:s,fullRef:"HEAD"}:null}return null}te();ye();ke();var Qy=`usage: git rebase [-i] [options] [--exec ] [--onto | --keep-base] [ []] + or: git rebase [-i] [options] [--exec ] [--onto ] --root [] + or: git rebase --continue | --abort | --skip | --edit-todo +-`;function hm(e,t){e.command("rebase",{description:"Reapply commits on top of another base tip",args:[W.string().name("upstream").describe("Upstream branch to rebase onto").optional()],options:{onto:K.string().describe("Starting point at which to create new commits"),abort:S().describe("Abort the current rebase operation"),continue:S().describe("Continue the rebase after conflict resolution"),skip:S().describe("Skip the current patch and continue"),"reapply-cherry-picks":S().describe("Do not skip commits that are cherry-pick equivalents"),"no-reapply-cherry-picks":S().describe("Skip commits that are cherry-pick equivalents (default)"),quiet:ce("be quiet. implies --no-stat")},handler:async(n,r)=>{let o=await q(r.fs,r.cwd,t);if(D(o))return o;let s=o,i=[n.abort,n.continue,n.skip].filter(Boolean).length;if(i>1||i===1&&(n.upstream!==void 0||n.onto!==void 0||n.quiet||n["reapply-cherry-picks"]||n["no-reapply-cherry-picks"]))return{stdout:"",stderr:Ry,exitCode:129};if(n.abort)return am(s,r.env);if(n.continue)return cm(s,r.env,t?.mergeDriver);if(n.skip)return fm(s,r.env,t?.mergeDriver);let a=n.upstream;if(!a)return v("no upstream configured and no upstream argument given");if(await wn(s)){let g=s.gitDir===s.commonDir?".git/rebase-merge":dr(s);return v(`It seems that there is already a rebase-merge directory, and ++`;function Sm(e,t){e.command("rebase",{description:"Reapply commits on top of another base tip",args:[B.string().name("upstream").describe("Upstream branch to rebase onto").optional()],options:{onto:K.string().describe("Starting point at which to create new commits"),abort:S().describe("Abort the current rebase operation"),continue:S().describe("Continue the rebase after conflict resolution"),skip:S().describe("Skip the current patch and continue"),"reapply-cherry-picks":S().describe("Do not skip commits that are cherry-pick equivalents"),"no-reapply-cherry-picks":S().describe("Skip commits that are cherry-pick equivalents (default)"),quiet:ce("be quiet. implies --no-stat")},handler:async(n,r)=>{let s=await W(r.fs,r.cwd,t);if(D(s))return s;let o=s,i=[n.abort,n.continue,n.skip].filter(Boolean).length;if(i>1||i===1&&(n.upstream!==void 0||n.onto!==void 0||n.quiet||n["reapply-cherry-picks"]||n["no-reapply-cherry-picks"]))return{stdout:"",stderr:Qy,exitCode:129};if(n.abort)return Em(o,r.env);if(n.continue)return Rm(o,r.env,t?.mergeDriver);if(n.skip)return Cm(o,r.env,t?.mergeDriver);let a=n.upstream;if(!a)return v("no upstream configured and no upstream argument given");if(await En(o)){let g=o.gitDir===o.commonDir?".git/rebase-merge":dr(o);return v(`It seems that there is already a rebase-merge directory, and + I wonder if you are in the middle of another rebase. If that is the + case, please try + git rebase (--continue | --abort | --skip) +@@ -722,75 +729,75 @@ If that is not the case, please + rm -fr "${g}" + and run me again. I am stopping in case you still have something + valuable there. +-`)}let c=await nt(s);if(D(c))return c;let f=await te(s),l=f?.type==="symbolic"?f.target:"detached HEAD",d=await Ge(s,a,`invalid upstream '${a}'`);if(D(d))return d;let u=d.hash,m,h=n.onto;if(h){let g=await Ge(s,h,`Does not point to a valid commit: '${h}'`);if(D(g))return g;m=g.hash}else m=u;let p=h??a;return Gi(s,r.env,c,l,u,m,a,p,t,{reapplyCherryPicks:!!n["reapply-cherry-picks"],quiet:!!n.quiet})}})}ne();Ve();ye();Ee();async function Cy(e,t,n,r,o){return`${await ue(e,r)} ${t}@{${n}}: ${o}`}async function Fi(e,t,n){let r=t==="HEAD"?"HEAD":`refs/heads/${t}`;if(!await z(e,r))return{stdout:"",stderr:`fatal: ambiguous argument '${t}': unknown revision or path not in the working tree. ++`)}let c=await nt(o);if(D(c))return c;let f=await ne(o),l=f?.type==="symbolic"?f.target:"detached HEAD",d=await Le(o,a,`invalid upstream '${a}'`);if(D(d))return d;let u=d.hash,m,h=n.onto;if(h){let g=await Le(o,h,`Does not point to a valid commit: '${h}'`);if(D(g))return g;m=g.hash}else m=u;let p=h??a;return Vi(o,r.env,c,l,u,m,a,p,t,{reapplyCherryPicks:!!n["reapply-cherry-picks"],quiet:!!n.quiet})}})}te();Xe();ye();ke();async function Jy(e,t,n,r,s){return`${await fe(e,r)} ${t}@{${n}}: ${s}`}async function Yi(e,t,n){let r=t==="HEAD"?"HEAD":`refs/heads/${t}`;if(!await z(e,r))return{stdout:"",stderr:`fatal: ambiguous argument '${t}': unknown revision or path not in the working tree. + Use '--' to separate paths from revisions, like this: + 'git [...] -- [...]' +-`,exitCode:128};let s=await vt(e,r),i=[],a=n!==void 0?n:s.length,c=0;for(let l=s.length-1;l>=0&&c0?`${i.join(` ++`,exitCode:128};let o=await Tt(e,r),i=[],a=n!==void 0?n:o.length,c=0;for(let l=o.length-1;l>=0&&c0?`${i.join(` + `)} +-`:"",stderr:"",exitCode:0}}function pm(e,t){return e.command("reflog",{description:"Manage reflog information",args:[W.string().name("args").variadic().optional()],options:{maxCount:K.number().alias("n").describe("Limit the number of entries to output")},handler:async(r,o)=>{let s=await q(o.fs,o.cwd,t);if(D(s))return s;let i=s,a=r.args;if(a.length===0)return Fi(i,"HEAD",r.maxCount);let c=a[0];if(!c)return Fi(i,"HEAD",r.maxCount);if(c==="show"){let f=a[1]??"HEAD";return Fi(i,f,r.maxCount)}if(c==="exists"){let f=a[1];if(!f)return{stdout:"",stderr:`fatal: reflog exists requires a ref argument +-`,exitCode:128};let l=ts(i,f);return{stdout:"",stderr:"",exitCode:await i.fs.exists(l)?0:1}}return Fi(i,c,r.maxCount)}})}ne();Be();Ve();ye();Ee();function xy(e){let t=[];for(let n of Object.keys(e)){let r=n.match(/^remote "(.+)"$/);r?.[1]&&t.push(r[1])}return t.sort()}function gm(e,t){let n=e.command("remote",{description:"Manage set of tracked repositories",options:{verbose:S().alias("v").describe("Show remote URLs")},handler:async(s,i)=>{let a=await q(i.fs,i.cwd,t);if(D(a))return a;let c=await we(a),f=xy(c);if(f.length===0)return{stdout:"",stderr:"",exitCode:0};if(s.verbose){let l=[];for(let d of f){let m=c[`remote "${d}"`]?.url??"";l.push(`${d} ${m} (fetch)`),l.push(`${d} ${m} (push)`)}return{stdout:`${l.join(` ++`:"",stderr:"",exitCode:0}}function vm(e,t){return e.command("reflog",{description:"Manage reflog information",args:[B.string().name("args").variadic().optional()],options:{maxCount:K.number().alias("n").describe("Limit the number of entries to output")},handler:async(r,s)=>{let o=await W(s.fs,s.cwd,t);if(D(o))return o;let i=o,a=r.args;if(a.length===0)return Yi(i,"HEAD",r.maxCount);let c=a[0];if(!c)return Yi(i,"HEAD",r.maxCount);if(c==="show"){let f=a[1]??"HEAD";return Yi(i,f,r.maxCount)}if(c==="exists"){let f=a[1];if(!f)return{stdout:"",stderr:`fatal: reflog exists requires a ref argument ++`,exitCode:128};let l=ss(i,f);return{stdout:"",stderr:"",exitCode:await i.fs.exists(l)?0:1}}return Yi(i,c,r.maxCount)}})}te();We();Xe();ye();ke();function e0(e){let t=[];for(let n of Object.keys(e)){let r=n.match(/^remote "(.+)"$/);r?.[1]&&t.push(r[1])}return t.sort()}function Im(e,t){let n=e.command("remote",{description:"Manage set of tracked repositories",options:{verbose:S().alias("v").describe("Show remote URLs")},handler:async(o,i)=>{let a=await W(i.fs,i.cwd,t);if(D(a))return a;let c=await be(a),f=e0(c);if(f.length===0)return{stdout:"",stderr:"",exitCode:0};if(o.verbose){let l=[];for(let d of f){let m=c[`remote "${d}"`]?.url??"";l.push(`${d} ${m} (fetch)`),l.push(`${d} ${m} (push)`)}return{stdout:`${l.join(` + `)} + `,stderr:"",exitCode:0}}return{stdout:`${f.join(` + `)} +-`,stderr:"",exitCode:0}}});n.command("add",{description:"Add a remote named for the repository at ",args:[W.string().name("name").describe("Remote name"),W.string().name("url").describe("Remote URL")],handler:async(s,i)=>{if(!Ds(`refs/remotes/${s.name}`,0))return v(`'${s.name}' is not a valid remote name`);let a=await q(i.fs,i.cwd,t);if(D(a))return a;let c=await we(a),f=`remote "${s.name}"`;if(f in c)return F(`error: remote ${s.name} already exists. +-`,3);let l=Ur(s.url,t?.credentialCache).url;return c[f]={url:l,fetch:`+refs/heads/*:refs/remotes/${s.name}/*`},await et(a,c),{stdout:"",stderr:"",exitCode:0}}});let r=async(s,i)=>{let a=await q(i.fs,i.cwd,t);if(D(a))return a;let c=await we(a),f=`remote "${s.name}"`;return f in c?(delete c[f],$y(c,s.name),await et(a,c),await Oy(a,s.name),{stdout:"",stderr:"",exitCode:0}):F(`error: No such remote: '${s.name}' +-`,2)},o=[W.string().name("name").describe("Remote name")];n.command("remove",{description:"Remove the remote named ",args:o,handler:r}),n.command("rm",{description:"Remove the remote named ",args:o,handler:r}),n.command("rename",{description:"Rename the remote named to ",args:[W.string().name("old").describe("Current remote name"),W.string().name("new").describe("New remote name")],handler:async(s,i)=>{let a=await q(i.fs,i.cwd,t);if(D(a))return a;let c=await we(a);return Py(a,c,s.old,s.new)}}),n.command("set-url",{description:"Change the URL for an existing remote",args:[W.string().name("name").describe("Remote name"),W.string().name("url").describe("New remote URL")],handler:async(s,i)=>{let a=await q(i.fs,i.cwd,t);if(D(a))return a;let c=await we(a),f=`remote "${s.name}"`;if(!(f in c))return F(`error: No such remote '${s.name}' +-`,2);let l=Ur(s.url,t?.credentialCache).url,d=c[f];return d&&(d.url=l),await et(a,c),{stdout:"",stderr:"",exitCode:0}}}),n.command("get-url",{description:"Retrieve the URL for an existing remote",args:[W.string().name("name").describe("Remote name")],handler:async(s,i)=>{let a=await q(i.fs,i.cwd,t);if(D(a))return a;let c=await we(a),f=`remote "${s.name}"`;return f in c?{stdout:`${c[f]?.url??""} +-`,stderr:"",exitCode:0}:F(`error: No such remote '${s.name}' +-`,2)}})}async function Py(e,t,n,r){if(!Ds(`refs/remotes/${r}`,0))return v(`'${r}' is not a valid remote name`);let o=`remote "${n}"`;if(!(o in t))return F(`error: No such remote: '${n}' +-`,2);let s=`remote "${r}"`;if(s in t)return v(`remote ${r} already exists.`);let i={...t[o]};i.fetch&&(i.fetch=i.fetch.replace(`refs/remotes/${n}/`,`refs/remotes/${r}/`)),t[s]=i,delete t[o];for(let f of Object.keys(t))f.match(/^branch "(.+)"$/)&&t[f]?.remote===n&&(t[f].remote=r);await et(e,t);let a=`refs/remotes/${n}`,c=await $e(e,a);for(let f of c){let l=f.name.replace(a,`refs/remotes/${r}`),d=await vt(e,f.name);await Q(e,l,f.hash),await ke(e,f.name),d.length>0&&await ns(e,l,d)}return{stdout:"",stderr:"",exitCode:0}}function $y(e,t){for(let n of Object.keys(e))n.match(/^branch "(.+)"$/)&&e[n]?.remote===t&&(delete e[n].remote,delete e[n].merge,Object.keys(e[n]).length===0&&delete e[n])}async function Oy(e,t){let n=`refs/remotes/${t}`,r=await $e(e,n);for(let o of r)await ke(e,o.name)}ne();Ee();function wm(e,t){e.command("repack",{description:"Pack unpacked objects in a repository",options:{all:S().alias("a").describe("Pack all objects, including already-packed"),delete:S().alias("d").describe("After packing, remove redundant packs and loose objects"),quiet:ce("be quiet")},handler:async(n,r)=>{let o=await q(r.fs,r.cwd,t);if(D(o))return o;let s=o,i=await Ti(s),a=await Ai({gitCtx:s,fs:r.fs,tips:i,cleanup:n.delete,all:n.all});return n.quiet?{stdout:"",stderr:"",exitCode:0}:a?{stdout:"",stderr:`${Hi(a.totalCount,a.deltaCount)} ++`,stderr:"",exitCode:0}}});n.command("add",{description:"Add a remote named for the repository at ",args:[B.string().name("name").describe("Remote name"),B.string().name("url").describe("Remote URL")],handler:async(o,i)=>{if(!Fs(`refs/remotes/${o.name}`,0))return v(`'${o.name}' is not a valid remote name`);let a=await W(i.fs,i.cwd,t);if(D(a))return a;let c=await be(a),f=`remote "${o.name}"`;if(f in c)return N(`error: remote ${o.name} already exists. ++`,3);let l=qr(o.url,t?.credentialCache).url;return c[f]={url:l,fetch:`+refs/heads/*:refs/remotes/${o.name}/*`},await et(a,c),{stdout:"",stderr:"",exitCode:0}}});let r=async(o,i)=>{let a=await W(i.fs,i.cwd,t);if(D(a))return a;let c=await be(a),f=`remote "${o.name}"`;return f in c?(delete c[f],n0(c,o.name),await et(a,c),await r0(a,o.name),{stdout:"",stderr:"",exitCode:0}):N(`error: No such remote: '${o.name}' ++`,2)},s=[B.string().name("name").describe("Remote name")];n.command("remove",{description:"Remove the remote named ",args:s,handler:r}),n.command("rm",{description:"Remove the remote named ",args:s,handler:r}),n.command("rename",{description:"Rename the remote named to ",args:[B.string().name("old").describe("Current remote name"),B.string().name("new").describe("New remote name")],handler:async(o,i)=>{let a=await W(i.fs,i.cwd,t);if(D(a))return a;let c=await be(a);return t0(a,c,o.old,o.new)}}),n.command("set-url",{description:"Change the URL for an existing remote",args:[B.string().name("name").describe("Remote name"),B.string().name("url").describe("New remote URL")],handler:async(o,i)=>{let a=await W(i.fs,i.cwd,t);if(D(a))return a;let c=await be(a),f=`remote "${o.name}"`;if(!(f in c))return N(`error: No such remote '${o.name}' ++`,2);let l=qr(o.url,t?.credentialCache).url,d=c[f];return d&&(d.url=l),await et(a,c),{stdout:"",stderr:"",exitCode:0}}}),n.command("get-url",{description:"Retrieve the URL for an existing remote",args:[B.string().name("name").describe("Remote name")],handler:async(o,i)=>{let a=await W(i.fs,i.cwd,t);if(D(a))return a;let c=await be(a),f=`remote "${o.name}"`;return f in c?{stdout:`${c[f]?.url??""} ++`,stderr:"",exitCode:0}:N(`error: No such remote '${o.name}' ++`,2)}})}async function t0(e,t,n,r){if(!Fs(`refs/remotes/${r}`,0))return v(`'${r}' is not a valid remote name`);let s=`remote "${n}"`;if(!(s in t))return N(`error: No such remote: '${n}' ++`,2);let o=`remote "${r}"`;if(o in t)return v(`remote ${r} already exists.`);let i={...t[s]};i.fetch&&(i.fetch=i.fetch.replace(`refs/remotes/${n}/`,`refs/remotes/${r}/`)),t[o]=i,delete t[s];for(let f of Object.keys(t))f.match(/^branch "(.+)"$/)&&t[f]?.remote===n&&(t[f].remote=r);await et(e,t);let a=`refs/remotes/${n}`,c=await $e(e,a);for(let f of c){let l=f.name.replace(a,`refs/remotes/${r}`),d=await Tt(e,f.name);await Q(e,l,f.hash),await Ee(e,f.name),d.length>0&&await os(e,l,d)}return{stdout:"",stderr:"",exitCode:0}}function n0(e,t){for(let n of Object.keys(e))n.match(/^branch "(.+)"$/)&&e[n]?.remote===t&&(delete e[n].remote,delete e[n].merge,Object.keys(e[n]).length===0&&delete e[n])}async function r0(e,t){let n=`refs/remotes/${t}`,r=await $e(e,n);for(let s of r)await Ee(e,s.name)}te();ke();function Tm(e,t){e.command("repack",{description:"Pack unpacked objects in a repository",options:{all:S().alias("a").describe("Pack all objects, including already-packed"),delete:S().alias("d").describe("After packing, remove redundant packs and loose objects"),quiet:ce("be quiet")},handler:async(n,r)=>{let s=await W(r.fs,r.cwd,t);if(D(s))return s;let o=s,i=await Ui(o),a=await _i({gitCtx:o,fs:r.fs,tips:i,cleanup:n.delete,all:n.all});return n.quiet?{stdout:"",stderr:"",exitCode:0}:a?{stdout:"",stderr:`${Bi(a.totalCount,a.deltaCount)} + `,exitCode:0}:{stdout:`Nothing new to pack. +-`,stderr:"",exitCode:0}}})}ne();ve();ae();ge();Ve();ye();Qt();De();Jt();st();Ee();function ym(e,t){e.command("reset",{description:"Reset current HEAD to the specified state",args:[W.string().name("args").variadic().optional()],options:{soft:S().describe("Only move HEAD"),mixed:S().describe("Move HEAD and reset index (default)"),hard:S().describe("Move HEAD, reset index, and reset working tree"),quiet:ce("be quiet, only report errors")},handler:async(n,r,o)=>{let s=await q(r.fs,r.cwd,t);if(D(s))return s;let i=s,a=n.args,c=!!n.quiet;if([n.soft,n.mixed,n.hard].filter(Boolean).length>1)return v("--soft, --mixed, and --hard are mutually exclusive");let l=n.soft||n.mixed||n.hard,d=kt(i,r.cwd);if(o.passthrough.length>0){let h=a.length>0?a[0]:void 0;return jc(i,o.passthrough,d,h,t,c)}if(!l&&a.length>0){let h=a[0],p=await Le(i,h);return a.length===1&&p?bm(i,h,"mixed",r.env,t,c):p?jc(i,a.slice(1),d,h,t,c):jc(i,a,d,void 0,t,c)}let u=n.soft?"soft":n.hard?"hard":"mixed",m=a.length>0?a[0]:"HEAD";return bm(i,m,u,r.env,t,c)}})}async function jc(e,t,n,r,o,s=!1){let i=await o?.hooks?.preReset?.({repo:e,mode:"paths",targetRef:r??null});if(he(i))return{stdout:"",stderr:i.message??"",exitCode:1};let a=null;if(r){let u=await Le(e,r);if(!u)return Et(r);let m=await Se(e,u);a=(await M(e,m)).tree}else{let u=await Z(e);u&&(a=(await M(e,u)).tree)}let c=await de(e,a??null),f=await X(e);if(t.some(Dr)){let u=t.map(h=>We(h,n)),m=new Set;for(let[h]of c)m.add(h);for(let h of f.entries)m.add(h.path);for(let h of m){if(!Pe(u,h))continue;let p=c.get(h);p?f=Mt(f,{path:p.path,mode:parseInt(p.mode,8),hash:p.hash,stage:0,stat:Fe()}):f=yt(f,h)}}else for(let u of t){let m=c.get(u);if(m)f=Mt(f,{path:m.path,mode:parseInt(m.mode,8),hash:m.hash,stage:0,stat:Fe()});else if(f.entries.some(p=>p.path===u))f=yt(f,u);else if(!(e.workTree&&await e.fs.exists(I(e.workTree,u))))return Et(u)}await ie(e,f);let d={stdout:s?nc(f):await km(e,f),stderr:"",exitCode:0};return await o?.hooks?.postReset?.({repo:e,mode:"paths",targetHash:null}),d}async function km(e,t){if(!e.workTree)return"";let n=new Set;for(let i of t.entries)i.stage>0&&n.add(i.path);let o=(await dt(e,t,{includeUntracked:!1})).filter(i=>i.status==="modified"||i.status==="deleted");if(o.length===0&&n.size===0)return"";let s=["Unstaged changes after reset:"];for(let i of o){let a=i.status==="modified"?"M":"D";s.push(`${a} ${i.path}`)}for(let i of[...n].sort())s.push(`U ${i}`);return s.sort((i,a)=>{if(i==="Unstaged changes after reset:")return-1;if(a==="Unstaged changes after reset:")return 1;let c=i.slice(2),f=a.slice(2);return cf?1:0}),`${s.join(` +-`)} +-`}async function bm(e,t,n,r,o,s=!1){let i=await o?.hooks?.preReset?.({repo:e,mode:n,targetRef:t});if(he(i))return{stdout:"",stderr:i.message??"",exitCode:1};let a=await Le(e,t);if(!a)return Et(t);let c=await Se(e,a),f=await M(e,c);if(n==="soft"){let h=await z(e,"MERGE_HEAD"),p=await X(e);if(h||kn(p))return v("Cannot do a soft reset in the middle of a merge.")}let l=await Z(e),d=await te(e);d?.type==="symbolic"?await Q(e,d.target,c):await Q(e,"HEAD",c);let u=`reset: moving to ${t}`;if(d?.type==="symbolic"&&l!==c?await ee(e,r,d.target,l,c,u,!0):(d?.type==="symbolic"||l!==c)&&await ee(e,r,"HEAD",l,c,u),await lr(e),n==="mixed"){let h=await ze(e,f.tree),p=Vr(h.map(w=>({path:w.path,mode:parseInt(w.mode,8),hash:w.hash,stage:0,stat:Fe()})));await ie(e,p);let g=s?"":await km(e,p);if(g)return await o?.hooks?.postReset?.({repo:e,mode:n,targetHash:c}),{stdout:g,stderr:"",exitCode:0}}if(n==="hard"){let h=tt(e);if(h)return h;let p=await X(e),g=await _n(e,f.tree,p);await ie(e,{version:2,entries:g.newEntries}),await je(e,g.worktreeOps)}let m=n==="hard"&&!s?`HEAD is now at ${await ue(e,c)} ${me(f.message)} +-`:"";return await o?.hooks?.postReset?.({repo:e,mode:n,targetHash:c}),{stdout:m,stderr:"",exitCode:0}}ne();ve();ae();ye();De();st();Ee();function Em(e,t){e.command("restore",{description:"Restore working tree files",args:[W.string().name("pathspec").variadic().optional()],options:{source:K.string().alias("s").describe("Restore from tree-ish"),staged:S().alias("S").describe("Restore the index"),worktree:S().alias("W").describe("Restore the working tree (default)"),ours:S().describe("Checkout our version for unmerged files"),theirs:S().describe("Checkout their version for unmerged files"),quiet:ce("suppress progress reporting")},handler:async(n,r,o)=>{let s=await q(r.fs,r.cwd,t);if(D(s))return s;let i=s,a=[...n.pathspec??[],...o.passthrough];if(a.length===0)return v("you must specify path(s) to restore");if(n.ours&&n.theirs)return v("--ours and --theirs are incompatible");let c=!!n.staged,f=n.worktree!==void 0?!!n.worktree:!c,l=kt(i,r.cwd);if(n.ours||n.theirs)return n.source?v("cannot specify both --source and --ours/--theirs"):c?v("cannot use --ours/--theirs with --staged"):oi(i,a,l,n.theirs?3:2,{deleteOnMissing:!0});let d=null;if(n.source){let u=await Ge(i,n.source,`could not resolve '${n.source}'`);if(D(u))return u;d=u.commit.tree}else if(c){let u=await Z(i);u&&(d=(await M(i,u)).tree)}return c&&f?Iy(i,a,l,d):c?Sy(i,a,l,d):d?vy(i,a,l,d):si(i,a,l)}})}async function Sy(e,t,n,r){let o=await de(e,r),s=await X(e),i=t.map(f=>We(f,n)),a=new Set;for(let[f]of o)a.add(f);for(let f of s.entries)a.add(f.path);let c=!1;for(let f of a){if(!Pe(i,f))continue;c=!0;let l=o.get(f);if(l)s=Mt(s,{path:l.path,mode:parseInt(l.mode,8),hash:l.hash,stage:0,stat:Fe()});else{if(s.entries.some(u=>u.path===f&&u.stage>0))return{stdout:"",stderr:`error: path '${f}' is unmerged +-`,exitCode:1};s=yt(s,f)}}return c?(await ie(e,s),{stdout:"",stderr:"",exitCode:0}):F(`error: pathspec '${t[0]}' did not match any file(s) known to git +-`)}async function vy(e,t,n,r){if(!e.workTree)return v("this operation must be run in a work tree");let o=await de(e,r),s=t.map(f=>We(f,n)),i=[],a=await X(e),c=new Set;for(let[f]of o)c.add(f);for(let f of a.entries)c.add(f.path);for(let f of c)if(Pe(s,f)){if(!o.has(f)&&a.entries.some(d=>d.path===f&&d.stage!==0))return{stdout:"",stderr:`error: path '${f}' is unmerged +-`,exitCode:1};i.push(f)}if(i.length===0)return F(`error: pathspec '${t[0]}' did not match any file(s) known to git +-`);for(let f of i){let l=o.get(f);if(l)await at(e,{path:l.path,hash:l.hash,mode:l.mode});else{let d=`${e.workTree}/${f}`;await e.fs.exists(d)&&await e.fs.rm(d)}}return{stdout:"",stderr:"",exitCode:0}}async function Iy(e,t,n,r){if(!e.workTree)return v("this operation must be run in a work tree");let o=await de(e,r),s=await X(e),i=t.map(f=>We(f,n)),a=[],c=new Set;for(let[f]of o)c.add(f);for(let f of s.entries)c.add(f.path);for(let f of c)Pe(i,f)&&a.push(f);if(a.length===0)return F(`error: pathspec '${t[0]}' did not match any file(s) known to git +-`);for(let f of a){let l=o.get(f);if(l)s=Mt(s,{path:l.path,mode:parseInt(l.mode,8),hash:l.hash,stage:0,stat:Fe()}),await at(e,{path:l.path,hash:l.hash,mode:l.mode});else{if(s.entries.some(m=>m.path===f&&m.stage>0))return{stdout:"",stderr:`error: path '${f}' is unmerged +-`,exitCode:1};s=yt(s,f);let u=`${e.workTree}/${f}`;await e.fs.exists(u)&&await e.fs.rm(u)}}return s=await rr(e,s,a),await ie(e,s),{stdout:"",stderr:"",exitCode:0}}ne();ae();ge();ye();Qt();De();Ee();function Rm(e,t){e.command("rev-parse",{description:"Pick out and massage parameters",args:[W.string().name("args").describe("Refs or revision expressions to resolve").optional().variadic()],options:{verify:S().describe("Verify that exactly one parameter is provided and resolves to an object"),short:S().describe("Abbreviate object name (default 7 chars)"),"abbrev-ref":S().describe("Output abbreviated ref name instead of object hash"),"symbolic-full-name":S().describe("Output the full symbolic ref name"),"show-toplevel":S().describe("Show the absolute path of the top-level directory"),"git-dir":S().describe("Show the path to the .git directory"),"is-inside-work-tree":S().describe("Output whether cwd is inside the work tree"),"is-bare-repository":S().describe("Output whether the repository is bare"),"show-prefix":S().describe("Show path of cwd relative to top-level directory"),"show-cdup":S().describe("Show relative path from cwd up to top-level directory"),quiet:ce("With --verify, exit non-zero silently instead of erroring on an invalid object name")},handler:async(n,r)=>{let o=n.args.filter(x=>x!==""),s=n.verify,i=n.short,a=n["abbrev-ref"],c=n["symbolic-full-name"],f=n["show-toplevel"],l=n["git-dir"],d=n["is-inside-work-tree"],u=n["is-bare-repository"],m=n["show-prefix"],h=n["show-cdup"],p=f||l||d||u||m||h,g=await q(r.fs,r.cwd,t);if(D(g))return g;let w=g,b=[];if(f){if(!w.workTree)return v("this operation must be run in a work tree");b.push(w.workTree)}if(l&&b.push(w.gitDir),d&&b.push(w.workTree?"true":"false"),u&&b.push(w.workTree?"false":"true"),m){if(!w.workTree)return v("this operation must be run in a work tree");let x=lt(w.workTree,r.cwd);b.push(x===""?"":`${x}/`)}if(h){if(!w.workTree)return v("this operation must be run in a work tree");let x=lt(r.cwd,w.workTree);b.push(x===""?"":`${x}/`)}if(p&&o.length===0)return{stdout:b.map(y=>`${y} +-`).join(""),stderr:"",exitCode:0};let R=s&&n.quiet;if(s&&o.length!==1)return R?{stdout:"",stderr:"",exitCode:1}:v("Needed a single revision");for(let x of o){if(a){let k=await Ty(w,x);if(k===null)return Ni(x,s,R);b.push(k);continue}if(c){let k=await Ay(w,x);if(k===null)return Ni(x,s,R);b.push(k);continue}let y=Lo(x);if(y){let k=await Hy(w,y.rev,y.path);if(k===null){if(s)return Ni(x,s,R);let E=y.path.replace(/^\//,"");return v(`path '${E}' does not exist in '${y.rev}'`)}b.push(i?await ue(w,k):k);continue}let P=await Le(w,x);if(!P)return Ni(x,s,R);b.push(i?await ue(w,P):P)}return{stdout:b.map(x=>`${x} +-`).join(""),stderr:"",exitCode:0}}})}function Ni(e,t,n){return n?{stdout:"",stderr:"",exitCode:1}:t?v("Needed a single revision"):Et(e)}async function Ty(e,t){if(t==="HEAD"||t==="@"){let r=await te(e);if(!r)return null;if(r.type==="symbolic"){let o=r.target;return o.startsWith("refs/heads/")?o.slice(11):o}return"HEAD"}return await Le(e,t)?t:null}async function Ay(e,t){if(t==="HEAD"||t==="@"){let r=await te(e);return r?r.type==="symbolic"?r.target:"HEAD":null}if(!await Le(e,t))return null;if(t.startsWith("refs/"))return t;for(let r of["refs/heads/","refs/tags/","refs/remotes/"]){let o=`${r}${t}`;if(await z(e,o))return o}return t}async function Hy(e,t,n){let r=await Le(e,t);if(!r)return null;let o=await M(e,r),s=n.replace(/^\//,"");return s===""?o.tree:(await de(e,o.tree)).get(s)?.hash??null}ne();Be();ve();ae();Ve();ye();De();Jt();Ee();function Cm(e,t){e.command("revert",{description:"Revert some existing commits",args:[W.string().name("commit").describe("The commit to revert").optional()],options:{abort:S().describe("Abort the current revert operation"),continue:S().describe("Continue the revert after conflict resolution"),skip:S().describe("Skip the current commit and continue"),"no-commit":S().alias("n").describe("Apply changes without creating a commit"),"no-edit":S().describe("Do not edit the commit message"),mainline:K.number().alias("m").describe("Select the parent number for reverting merges")},handler:async(n,r)=>{let o=await q(r.fs,r.cwd,t);if(D(o))return o;let s=o;if(n.abort){let G=await t?.hooks?.preRevert?.({repo:s,mode:"abort",commitRef:null});if(he(G))return{stdout:"",stderr:G.message??"",exitCode:1};let N=await Dy(s,r.env);return N.exitCode===0&&await t?.hooks?.postRevert?.({repo:s,mode:"abort",commitHash:null,hadConflicts:!1}),N}if(n.continue){let G=await t?.hooks?.preRevert?.({repo:s,mode:"continue",commitRef:null});if(he(G))return{stdout:"",stderr:G.message??"",exitCode:1};let N=await jy(s,r.env);if(N.exitCode===0){let A=await Z(s);await t?.hooks?.postRevert?.({repo:s,mode:"continue",commitHash:A,hadConflicts:!1})}return N}if(n.skip)return My(s,r.env);let i=n.commit;if(!i)return v("you must specify a commit to revert");let a=await t?.hooks?.preRevert?.({repo:s,mode:"revert",commitRef:i});if(he(a))return{stdout:"",stderr:a.message??"",exitCode:1};let c=await Ge(s,i);if(D(c))return c;let f=c.hash,l=c.commit,d=await nt(s);if(D(d))return d;let u=n["no-commit"]?"no-commit":"commit",m=await X(s),h=Ly(m,u);if(h)return h;let p=await M(s,d);if(s.workTree&&u==="commit"){let G=await de(s,p.tree);if(Bn(m,G))return F(`error: your local changes would be overwritten by revert. ++`,stderr:"",exitCode:0}}})}te();Se();ie();ge();Xe();ye();Ft();Te();rn();ot();ke();function Hm(e,t){e.command("reset",{description:"Reset current HEAD to the specified state",args:[B.string().name("args").variadic().optional()],options:{soft:S().describe("Only move HEAD"),mixed:S().describe("Move HEAD and reset index (default)"),hard:S().describe("Move HEAD, reset index, and reset working tree"),quiet:ce("be quiet, only report errors")},handler:async(n,r,s)=>{let o=await W(r.fs,r.cwd,t);if(D(o))return o;let i=o,a=n.args,c=!!n.quiet;if([n.soft,n.mixed,n.hard].filter(Boolean).length>1)return v("--soft, --mixed, and --hard are mutually exclusive");let l=n.soft||n.mixed||n.hard,d=ut(i,r.cwd);if(s.passthrough.length>0){let h=a.length>0?a[0]:void 0;return Kc(i,s.passthrough,d,h,t,c)}if(!l&&a.length>0){let h=a[0],p=await Ie(i,h);return a.length===1&&p?Am(i,h,"mixed",r.env,t,c):p?Kc(i,a.slice(1),d,h,t,c):Kc(i,a,d,void 0,t,c)}let u=n.soft?"soft":n.hard?"hard":"mixed",m=a.length>0?a[0]:"HEAD";return Am(i,m,u,r.env,t,c)}})}async function Kc(e,t,n,r,s,o=!1){let i=await s?.hooks?.preReset?.({repo:e,mode:"paths",targetRef:r??null});if(pe(i))return{stdout:"",stderr:i.message??"",exitCode:1};let a=null;if(r){let u=await Ie(e,r);if(!u)return Ct(r);let m=await Oe(e,u);a=(await M(e,m)).tree}else{let u=await Z(e);u&&(a=(await M(e,u)).tree)}let c=await de(e,a??null),f=await X(e);if(t.some(Gr)){let u=t.map(h=>qe(h,n)),m=new Set;for(let[h]of c)m.add(h);for(let h of f.entries)m.add(h.path);for(let h of m){if(!Pe(u,h))continue;let p=c.get(h);p?f=jt(f,{path:p.path,mode:parseInt(p.mode,8),hash:p.hash,stage:0,stat:Ge()}):f=Rt(f,h)}}else for(let u of t){let m=c.get(u);if(m)f=jt(f,{path:m.path,mode:parseInt(m.mode,8),hash:m.hash,stage:0,stat:Ge()});else if(f.entries.some(p=>p.path===u))f=Rt(f,u);else if(!(e.workTree&&await e.fs.exists(I(e.workTree,u))))return Ct(u)}await oe(e,f);let d={stdout:o?dc(f):await Dm(e,f),stderr:"",exitCode:0};return await s?.hooks?.postReset?.({repo:e,mode:"paths",targetHash:null}),d}async function Dm(e,t){if(!e.workTree)return"";let n=new Set;for(let i of t.entries)i.stage>0&&n.add(i.path);let s=(await pt(e,t,{includeUntracked:!1})).filter(i=>i.status==="modified"||i.status==="deleted");if(s.length===0&&n.size===0)return"";let o=["Unstaged changes after reset:"];for(let i of s){let a=i.status==="modified"?"M":"D";o.push(`${a} ${i.path}`)}for(let i of[...n].sort())o.push(`U ${i}`);return o.sort((i,a)=>{if(i==="Unstaged changes after reset:")return-1;if(a==="Unstaged changes after reset:")return 1;let c=i.slice(2),f=a.slice(2);return cf?1:0}),`${o.join(` ++`)} ++`}async function Am(e,t,n,r,s,o=!1){let i=await s?.hooks?.preReset?.({repo:e,mode:n,targetRef:t});if(pe(i))return{stdout:"",stderr:i.message??"",exitCode:1};let a=await Ie(e,t);if(!a)return Ct(t);let c=await Oe(e,a),f=await M(e,c);if(n==="soft"){let h=await z(e,"MERGE_HEAD"),p=await X(e);if(h||xn(p))return v("Cannot do a soft reset in the middle of a merge.")}let l=await Z(e),d=await ne(e);d?.type==="symbolic"?await Q(e,d.target,c):await Q(e,"HEAD",c);let u=`reset: moving to ${t}`;if(d?.type==="symbolic"&&l!==c?await ee(e,r,d.target,l,c,u,!0):(d?.type==="symbolic"||l!==c)&&await ee(e,r,"HEAD",l,c,u),await lr(e),n==="mixed"){let h=await Ke(e,f.tree),p=Qr(h.map(w=>({path:w.path,mode:parseInt(w.mode,8),hash:w.hash,stage:0,stat:Ge()})));await oe(e,p);let g=o?"":await Dm(e,p);if(g)return await s?.hooks?.postReset?.({repo:e,mode:n,targetHash:c}),{stdout:g,stderr:"",exitCode:0}}if(n==="hard"){let h=tt(e);if(h)return h;let p=await X(e),g=await Bn(e,f.tree,p);await oe(e,{version:2,entries:g.newEntries}),await Me(e,g.worktreeOps)}let m=n==="hard"&&!o?`HEAD is now at ${await fe(e,c)} ${he(f.message)} ++`:"";return await s?.hooks?.postReset?.({repo:e,mode:n,targetHash:c}),{stdout:m,stderr:"",exitCode:0}}te();Se();ie();ye();Te();ot();ke();function Mm(e,t){e.command("restore",{description:"Restore working tree files",args:[B.string().name("pathspec").variadic().optional()],options:{source:K.string().alias("s").describe("Restore from tree-ish"),staged:S().alias("S").describe("Restore the index"),worktree:S().alias("W").describe("Restore the working tree (default)"),ours:S().describe("Checkout our version for unmerged files"),theirs:S().describe("Checkout their version for unmerged files"),quiet:ce("suppress progress reporting")},handler:async(n,r,s)=>{let o=await W(r.fs,r.cwd,t);if(D(o))return o;let i=o,a=[...n.pathspec??[],...s.passthrough];if(a.length===0)return v("you must specify path(s) to restore");if(n.ours&&n.theirs)return v("--ours and --theirs are incompatible");let c=!!n.staged,f=n.worktree!==void 0?!!n.worktree:!c,l=ut(i,r.cwd);if(n.ours||n.theirs)return n.source?v("cannot specify both --source and --ours/--theirs"):c?v("cannot use --ours/--theirs with --staged"):pi(i,a,l,n.theirs?3:2,{deleteOnMissing:!0});let d=null;if(n.source){let u=await Le(i,n.source,`could not resolve '${n.source}'`);if(D(u))return u;d=u.commit.tree}else if(c){let u=await Z(i);u&&(d=(await M(i,u)).tree)}return c&&f?i0(i,a,l,d):c?s0(i,a,l,d):d?o0(i,a,l,d):hi(i,a,l)}})}async function s0(e,t,n,r){let s=await de(e,r),o=await X(e),i=t.map(f=>qe(f,n)),a=new Set;for(let[f]of s)a.add(f);for(let f of o.entries)a.add(f.path);let c=!1;for(let f of a){if(!Pe(i,f))continue;c=!0;let l=s.get(f);if(l)o=jt(o,{path:l.path,mode:parseInt(l.mode,8),hash:l.hash,stage:0,stat:Ge()});else{if(o.entries.some(u=>u.path===f&&u.stage>0))return{stdout:"",stderr:`error: path '${f}' is unmerged ++`,exitCode:1};o=Rt(o,f)}}return c?(await oe(e,o),{stdout:"",stderr:"",exitCode:0}):N(`error: pathspec '${t[0]}' did not match any file(s) known to git ++`)}async function o0(e,t,n,r){if(!e.workTree)return v("this operation must be run in a work tree");let s=await de(e,r),o=t.map(f=>qe(f,n)),i=[],a=await X(e),c=new Set;for(let[f]of s)c.add(f);for(let f of a.entries)c.add(f.path);for(let f of c)if(Pe(o,f)){if(!s.has(f)&&a.entries.some(d=>d.path===f&&d.stage!==0))return{stdout:"",stderr:`error: path '${f}' is unmerged ++`,exitCode:1};i.push(f)}if(i.length===0)return N(`error: pathspec '${t[0]}' did not match any file(s) known to git ++`);for(let f of i){let l=s.get(f);if(l)await lt(e,{path:l.path,hash:l.hash,mode:l.mode});else{let d=`${e.workTree}/${f}`;await e.fs.exists(d)&&await e.fs.rm(d)}}return{stdout:"",stderr:"",exitCode:0}}async function i0(e,t,n,r){if(!e.workTree)return v("this operation must be run in a work tree");let s=await de(e,r),o=await X(e),i=t.map(f=>qe(f,n)),a=[],c=new Set;for(let[f]of s)c.add(f);for(let f of o.entries)c.add(f.path);for(let f of c)Pe(i,f)&&a.push(f);if(a.length===0)return N(`error: pathspec '${t[0]}' did not match any file(s) known to git ++`);for(let f of a){let l=s.get(f);if(l)o=jt(o,{path:l.path,mode:parseInt(l.mode,8),hash:l.hash,stage:0,stat:Ge()}),await lt(e,{path:l.path,hash:l.hash,mode:l.mode});else{if(o.entries.some(m=>m.path===f&&m.stage>0))return{stdout:"",stderr:`error: path '${f}' is unmerged ++`,exitCode:1};o=Rt(o,f);let u=`${e.workTree}/${f}`;await e.fs.exists(u)&&await e.fs.rm(u)}}return o=await rr(e,o,a),await oe(e,o),{stdout:"",stderr:"",exitCode:0}}te();ie();ge();ye();Ft();Te();ke();function jm(e,t){e.command("rev-parse",{description:"Pick out and massage parameters",args:[B.string().name("args").describe("Refs or revision expressions to resolve").optional().variadic()],options:{verify:S().describe("Verify that exactly one parameter is provided and resolves to an object"),short:S().describe("Abbreviate object name (default 7 chars)"),"abbrev-ref":S().describe("Output abbreviated ref name instead of object hash"),"symbolic-full-name":S().describe("Output the full symbolic ref name"),"show-toplevel":S().describe("Show the absolute path of the top-level directory"),"git-dir":S().describe("Show the path to the .git directory"),"is-inside-work-tree":S().describe("Output whether cwd is inside the work tree"),"is-bare-repository":S().describe("Output whether the repository is bare"),"show-prefix":S().describe("Show path of cwd relative to top-level directory"),"show-cdup":S().describe("Show relative path from cwd up to top-level directory"),quiet:ce("With --verify, exit non-zero silently instead of erroring on an invalid object name")},handler:async(n,r)=>{let s=n.args.filter(x=>x!==""),o=n.verify,i=n.short,a=n["abbrev-ref"],c=n["symbolic-full-name"],f=n["show-toplevel"],l=n["git-dir"],d=n["is-inside-work-tree"],u=n["is-bare-repository"],m=n["show-prefix"],h=n["show-cdup"],p=f||l||d||u||m||h,g=await W(r.fs,r.cwd,t);if(D(g))return g;let w=g,b=[];if(f){if(!w.workTree)return v("this operation must be run in a work tree");b.push(w.workTree)}if(l&&b.push(w.gitDir),d&&b.push(w.workTree?"true":"false"),u&&b.push(w.workTree?"false":"true"),m){if(!w.workTree)return v("this operation must be run in a work tree");let x=rt(w.workTree,r.cwd);b.push(x===""?"":`${x}/`)}if(h){if(!w.workTree)return v("this operation must be run in a work tree");let x=rt(r.cwd,w.workTree);b.push(x===""?"":`${x}/`)}if(p&&s.length===0)return{stdout:b.map(k=>`${k} ++`).join(""),stderr:"",exitCode:0};let y=o&&n.quiet;if(o&&s.length!==1)return y?{stdout:"",stderr:"",exitCode:1}:v("Needed a single revision");for(let x of s){if(a){let E=await a0(w,x);if(E===null)return Xi(x,o,y);b.push(E);continue}if(c){let E=await c0(w,x);if(E===null)return Xi(x,o,y);b.push(E);continue}let k=qo(x);if(k){let E=await f0(w,k.rev,k.path);if(E===null){if(o)return Xi(x,o,y);let R=k.path.replace(/^\//,"");return v(`path '${R}' does not exist in '${k.rev}'`)}b.push(i?await fe(w,E):E);continue}let P=await Ie(w,x);if(!P)return Xi(x,o,y);b.push(i?await fe(w,P):P)}return{stdout:b.map(x=>`${x} ++`).join(""),stderr:"",exitCode:0}}})}function Xi(e,t,n){return n?{stdout:"",stderr:"",exitCode:1}:t?v("Needed a single revision"):Ct(e)}async function a0(e,t){if(t==="HEAD"||t==="@"){let r=await ne(e);if(!r)return null;if(r.type==="symbolic"){let s=r.target;return s.startsWith("refs/heads/")?s.slice(11):s}return"HEAD"}return await Ie(e,t)?t:null}async function c0(e,t){if(t==="HEAD"||t==="@"){let r=await ne(e);return r?r.type==="symbolic"?r.target:"HEAD":null}if(!await Ie(e,t))return null;if(t.startsWith("refs/"))return t;for(let r of["refs/heads/","refs/tags/","refs/remotes/"]){let s=`${r}${t}`;if(await z(e,s))return s}return t}async function f0(e,t,n){let r=await Ie(e,t);if(!r)return null;let s=await M(e,r),o=n.replace(/^\//,"");return o===""?s.tree:(await de(e,s.tree)).get(o)?.hash??null}te();We();Se();ie();Xe();ye();Te();rn();ke();function Lm(e,t){e.command("revert",{description:"Revert some existing commits",args:[B.string().name("commit").describe("The commit to revert").optional()],options:{abort:S().describe("Abort the current revert operation"),continue:S().describe("Continue the revert after conflict resolution"),skip:S().describe("Skip the current commit and continue"),"no-commit":S().alias("n").describe("Apply changes without creating a commit"),"no-edit":S().describe("Do not edit the commit message"),mainline:K.number().alias("m").describe("Select the parent number for reverting merges")},handler:async(n,r)=>{let s=await W(r.fs,r.cwd,t);if(D(s))return s;let o=s;if(n.abort){let G=await t?.hooks?.preRevert?.({repo:o,mode:"abort",commitRef:null});if(pe(G))return{stdout:"",stderr:G.message??"",exitCode:1};let L=await l0(o,r.env);return L.exitCode===0&&await t?.hooks?.postRevert?.({repo:o,mode:"abort",commitHash:null,hadConflicts:!1}),L}if(n.continue){let G=await t?.hooks?.preRevert?.({repo:o,mode:"continue",commitRef:null});if(pe(G))return{stdout:"",stderr:G.message??"",exitCode:1};let L=await u0(o,r.env);if(L.exitCode===0){let A=await Z(o);await t?.hooks?.postRevert?.({repo:o,mode:"continue",commitHash:A,hadConflicts:!1})}return L}if(n.skip)return d0(o,r.env);let i=n.commit;if(!i)return v("you must specify a commit to revert");let a=await t?.hooks?.preRevert?.({repo:o,mode:"revert",commitRef:i});if(pe(a))return{stdout:"",stderr:a.message??"",exitCode:1};let c=await Le(o,i);if(D(c))return c;let f=c.hash,l=c.commit,d=await nt(o);if(D(d))return d;let u=n["no-commit"]?"no-commit":"commit",m=await X(o),h=m0(m,u);if(h)return h;let p=await M(o,d);if(o.workTree&&u==="commit"){let G=await de(o,p.tree);if(Wn(m,G))return N(`error: your local changes would be overwritten by revert. + hint: commit your changes or stash them to proceed. + fatal: revert failed +-`,128)}let g=n.mainline,w;if(l.parents.length>1){if(g===void 0)return F(`error: commit ${f} is a merge but no -m option was given. ++`,128)}let g=n.mainline,w;if(l.parents.length>1){if(g===void 0)return N(`error: commit ${f} is a merge but no -m option was given. + fatal: revert failed +-`,128);if(g<1||g>l.parents.length)return F(`error: commit ${f} does not have parent ${g} ++`,128);if(g<1||g>l.parents.length)return N(`error: commit ${f} does not have parent ${g} + fatal: revert failed +-`,128);let G=l.parents[g-1];w=(await M(s,G)).tree}else if(l.parents.length===0)w=await Ye(s,[]);else{let G=l.parents[0];w=(await M(s,G)).tree}let b=await ue(s,f),R=me(l.message),C=Fy(l,f,g),x=Nt(C),y=await Re(s,"merge.conflictstyle")??"merge",P={a:"HEAD",b:R?`parent of ${b} (${R})`:`parent of ${b}`,conflictStyle:y},k=await sn(s,l.tree,p.tree,w,P,t?.mergeDriver);if(k.conflicts.length===0&&k.resultTree===p.tree){if(u==="no-commit")return await Lc(s,f,C),{stdout:"",stderr:"",exitCode:0};let G=k.messages.length>0?`${k.messages.join(` ++`,128);let G=l.parents[g-1];w=(await M(o,G)).tree}else if(l.parents.length===0)w=await Ze(o,[]);else{let G=l.parents[0];w=(await M(o,G)).tree}let b=await fe(o,f),y=he(l.message),C=p0(l,f,g),x=Bt(C),k=await Re(o,"merge.conflictstyle")??"merge",P={a:"HEAD",b:y?`parent of ${b} (${y})`:`parent of ${b}`,conflictStyle:k},E=await fn(o,l.tree,p.tree,w,P,t?.mergeDriver);if(E.conflicts.length===0&&E.resultTree===p.tree){if(u==="no-commit")return await Vc(o,f,C),{stdout:"",stderr:"",exitCode:0};let G=E.messages.length>0?`${E.messages.join(` + `)} +-`:"",N=await pt(s,{fromCommit:!0}),A=await z(s,"CHERRY_PICK_HEAD");return{stdout:`${G}${N}`,stderr:A?`The previous cherry-pick is now empty, possibly due to conflict resolution. ++`:"",L=await yt(o,{fromCommit:!0}),A=await z(o,"CHERRY_PICK_HEAD");return{stdout:`${G}${L}`,stderr:A?`The previous cherry-pick is now empty, possibly due to conflict resolution. + If you wish to commit it anyway, use: + + git commit --allow-empty + + Otherwise, please use 'git cherry-pick --skip' +-`:"",exitCode:1}}let E=await Kn(s,k,p.tree,{labels:P,errorExitCode:128,operationName:"merge",callerCommand:"revert",skipStagedChangeCheck:!0});if(!E.ok)return E;if(k.conflicts.length>0){await Lc(s,f,C,d);let G=k.messages.join(` +-`);return await t?.hooks?.postRevert?.({repo:s,mode:"revert",commitHash:null,hadConflicts:!0}),{stdout:G?`${G} +-`:"",stderr:Gy(b,me(l.message),u),exitCode:1}}if(u==="no-commit")return await Lc(s,f,C),{stdout:"",stderr:"",exitCode:0};let O=E.mergedTreeHash,$=await Sn(s,r.env);if(D($))return $;let T=await ct(s,r.env);if(D(T))return T;let j=await xm({gitCtx:s,env:r.env,headHash:d,headTreeHash:p.tree,treeHash:O,author:$,committer:T,commitMessage:x,displayMessage:C,reflogMessage:`revert: ${me(C)}`}),U=k.messages.length>0?`${k.messages.join(` ++`:"",exitCode:1}}let R=await Yn(o,E,p.tree,{labels:P,errorExitCode:128,operationName:"merge",callerCommand:"revert",skipStagedChangeCheck:!0});if(!R.ok)return R;if(E.conflicts.length>0){await Vc(o,f,C,d);let G=E.messages.join(` ++`);return await t?.hooks?.postRevert?.({repo:o,mode:"revert",commitHash:null,hadConflicts:!0}),{stdout:G?`${G} ++`:"",stderr:h0(b,he(l.message),u),exitCode:1}}if(u==="no-commit")return await Vc(o,f,C),{stdout:"",stderr:"",exitCode:0};let O=R.mergedTreeHash,$=await An(o,r.env);if(D($))return $;let T=await dt(o,r.env);if(D(T))return T;let j=await Gm({gitCtx:o,env:r.env,headHash:d,headTreeHash:p.tree,treeHash:O,author:$,committer:T,commitMessage:x,displayMessage:C,reflogMessage:`revert: ${he(C)}`}),U=E.messages.length>0?`${E.messages.join(` + `)} +-`:"";return await t?.hooks?.postRevert?.({repo:s,mode:"revert",commitHash:j.commitHash,hadConflicts:!1}),{stdout:`${U}${j.stdout}`,stderr:"",exitCode:0}}})}async function Dy(e,t){return await z(e,"REVERT_HEAD")?cr(e,t,{operationRef:"REVERT_HEAD",noOpError:F(`error: no cherry-pick or revert in progress ++`:"";return await t?.hooks?.postRevert?.({repo:o,mode:"revert",commitHash:j.commitHash,hadConflicts:!1}),{stdout:`${U}${j.stdout}`,stderr:"",exitCode:0}}})}async function l0(e,t){return await z(e,"REVERT_HEAD")?cr(e,t,{operationRef:"REVERT_HEAD",noOpError:N(`error: no cherry-pick or revert in progress + fatal: revert failed +-`,128),operationName:"revert",clearState:async o=>{await tn(o),await gn(o)},origHeadAsTargetRev:!0}):await z(e,"CHERRY_PICK_HEAD")?cr(e,t,{operationRef:"CHERRY_PICK_HEAD",noOpError:F(`error: no cherry-pick or revert in progress ++`,128),operationName:"revert",clearState:async s=>{await on(s),await kn(s)},origHeadAsTargetRev:!0}):await z(e,"CHERRY_PICK_HEAD")?cr(e,t,{operationRef:"CHERRY_PICK_HEAD",noOpError:N(`error: no cherry-pick or revert in progress + fatal: revert failed +-`,128),operationName:"revert",clearState:gn,origHeadAsTargetRev:!0}):F(`error: no cherry-pick or revert in progress ++`,128),operationName:"revert",clearState:kn,origHeadAsTargetRev:!0}):N(`error: no cherry-pick or revert in progress + fatal: revert failed +-`,128)}async function My(e,t){if(!await z(e,"REVERT_HEAD"))return F(`error: no revert in progress ++`,128)}async function d0(e,t){if(!await z(e,"REVERT_HEAD"))return N(`error: no revert in progress + fatal: revert failed +-`,128);let r=await Z(e);if(!r)return v("unable to resolve HEAD");let o=await M(e,r),s=await X(e),i=await ss(e,o.tree,s,r);if(!i.success){let a=i.errorOutput;return{...a,stderr:a.stderr+`error: failed to skip the commit ++`,128);let r=await Z(e);if(!r)return v("unable to resolve HEAD");let s=await M(e,r),o=await X(e),i=await as(e,s.tree,o,r);if(!i.success){let a=i.errorOutput;return{...a,stderr:a.stderr+`error: failed to skip the commit + fatal: revert failed +-`}}return await ie(e,{version:2,entries:i.newEntries}),await je(e,i.worktreeOps),await ee(e,t,"HEAD",r,r,`reset: moving to ${r}`),await tn(e),{stdout:"",stderr:"",exitCode:0}}async function jy(e,t){if(!await z(e,"REVERT_HEAD"))return F(`error: no cherry-pick or revert in progress ++`}}return await oe(e,{version:2,entries:i.newEntries}),await Me(e,i.worktreeOps),await ee(e,t,"HEAD",r,r,`reset: moving to ${r}`),await on(e),{stdout:"",stderr:"",exitCode:0}}async function u0(e,t){if(!await z(e,"REVERT_HEAD"))return N(`error: no cherry-pick or revert in progress + fatal: revert failed +-`,128);let r=await X(e),o=ar(r);if(o)return o;let s=await Ae(e,"MERGE_MSG");if(!s)return F(`Aborting commit due to empty commit message. +-`,1);let i=await Ae(e,"SQUASH_MSG");if(i&&(s=i+s),s=Ft(s),!s)return F(`Aborting commit due to empty commit message. +-`,1);let a=qe(r),c=await Ye(e,a),f=await nt(e);if(D(f))return f;let l=await M(e,f),d=await Sn(e,t);if(D(d))return d;let u=await ct(e,t);if(D(u))return u;let m=await z(e,"CHERRY_PICK_HEAD");m&&(d=(await M(e,m)).author);let h=Nt(s);return{stdout:(await xm({gitCtx:e,env:t,headHash:f,headTreeHash:l.tree,treeHash:c,author:d,committer:u,commitMessage:h,displayMessage:s,reflogMessage:`commit: ${me(h)}`})).stdout,stderr:"",exitCode:0}}function Ly(e,t){if(t==="commit")return Hr(e,"Reverting",`fatal: revert failed +-`);let n=e.entries.filter(a=>a.stage>0);if(n.length===0)return null;let r=10,s=n.slice(0,r).map(a=>`${a.path}: unmerged (${a.hash})`).join(` ++`,128);let r=await X(e),s=ar(r);if(s)return s;let o=await He(e,"MERGE_MSG");if(!o)return N(`Aborting commit due to empty commit message. ++`,1);let i=await He(e,"SQUASH_MSG");if(i&&(o=i+o),o=_t(o),!o)return N(`Aborting commit due to empty commit message. ++`,1);let a=ze(r),c=await Ze(e,a),f=await nt(e);if(D(f))return f;let l=await M(e,f),d=await An(e,t);if(D(d))return d;let u=await dt(e,t);if(D(u))return u;let m=await z(e,"CHERRY_PICK_HEAD");m&&(d=(await M(e,m)).author);let h=Bt(o);return{stdout:(await Gm({gitCtx:e,env:t,headHash:f,headTreeHash:l.tree,treeHash:c,author:d,committer:u,commitMessage:h,displayMessage:o,reflogMessage:`commit: ${he(h)}`})).stdout,stderr:"",exitCode:0}}function m0(e,t){if(t==="commit")return Lr(e,"Reverting",`fatal: revert failed ++`);let n=e.entries.filter(a=>a.stage>0);if(n.length===0)return null;let r=10,o=n.slice(0,r).map(a=>`${a.path}: unmerged (${a.hash})`).join(` + `),i=n.length>r?` +-...`:"";return F(`${s}${i} ++...`:"";return N(`${o}${i} + error: your index file is unmerged. + fatal: revert failed +-`,128)}async function Lc(e,t,n,r){await Q(e,"REVERT_HEAD",t),r&&await Q(e,"ORIG_HEAD",r),await Ue(e,"MERGE_MSG",n)}function Gy(e,t,n){let r=`error: could not revert ${e}... ${t} ++`,128)}async function Vc(e,t,n,r){await Q(e,"REVERT_HEAD",t),r&&await Q(e,"ORIG_HEAD",r),await Ne(e,"MERGE_MSG",n)}function h0(e,t,n){let r=`error: could not revert ${e}... ${t} + `;return n==="no-commit"?r+`hint: after resolving the conflicts, mark the corrected paths + hint: with 'git add ' or 'git rm ' + hint: Disable this message with "git config set advice.mergeConflict false" +@@ -801,118 +808,118 @@ hint: You can instead skip this commit with "git revert --skip". + hint: To abort and get back to the state before "git revert", + hint: run "git revert --abort". + hint: Disable this message with "git config set advice.mergeConflict false" +-`}async function xm(e){let{gitCtx:t,env:n,headHash:r,headTreeHash:o,treeHash:s,author:i,committer:a,commitMessage:c,displayMessage:f,reflogMessage:l}=e,d=await Gt(t,s,[r],i,a,c);await tn(t),await gn(t);let u=await te(t),m=u?.type==="symbolic"?u.target:"HEAD";await ee(t,n,m,r,d,l,u?.type==="symbolic");let h=u?.type==="symbolic"?Ie(u.target):"detached HEAD",p=await zn(t,o,s,i,a,i.name!==a.name||i.email!==a.email||i.timestamp!==a.timestamp||i.timezone!==a.timezone),g=await pn(t,h,d,f);return{commitHash:d,stdout:`${g} +-${p}`}}function Fy(e,t,n){let r=me(e.message),o='Revert "',a=`${r.startsWith(o)&&r.endsWith('"')?`Reapply "${r.slice(o.length,-1)}"`:`Revert "${r}"`} ++`}async function Gm(e){let{gitCtx:t,env:n,headHash:r,headTreeHash:s,treeHash:o,author:i,committer:a,commitMessage:c,displayMessage:f,reflogMessage:l}=e,d=await Ut(t,o,[r],i,a,c);await on(t),await kn(t);let u=await ne(t),m=u?.type==="symbolic"?u.target:"HEAD";await ee(t,n,m,r,d,l,u?.type==="symbolic");let h=u?.type==="symbolic"?ve(u.target):"detached HEAD",p=await Kn(t,s,o,i,a,i.name!==a.name||i.email!==a.email||i.timestamp!==a.timestamp||i.timezone!==a.timezone),g=await yn(t,h,d,f);return{commitHash:d,stdout:`${g} ++${p}`}}function p0(e,t,n){let r=he(e.message),s='Revert "',a=`${r.startsWith(s)&&r.endsWith('"')?`Reapply "${r.slice(s.length,-1)}"`:`Revert "${r}"`} + + This reverts commit ${t}`;if(n!==void 0&&e.parents.length>1&&n>=1){let c=e.parents[n-1]??e.parents[0];a+=`, reversing + changes made to ${c}`}return a+=`. +-`,a}ne();ve();ae();ge();ye();ir();cn();De();Ee();function Pm(e,t){e.command("rm",{description:"Remove files from the working tree and from the index",args:[W.string().name("paths").describe("Files to remove").optional().variadic()],options:{cached:S().describe("Only remove from the index"),recursive:S().alias("r").describe("Allow recursive removal when a directory name is given"),force:S().alias("f").describe("Override the up-to-date check"),dryRun:S().alias("n").describe("Don't actually remove any file(s)"),quiet:ce("do not list removed files")},handler:async(n,r)=>{let o=await q(r.fs,r.cwd,t);if(D(o))return o;let s=o,i=tt(s);if(i)return i;let a=s.workTree,c=n.paths;if(c.length===0)return F("usage: git rm [--cached] [-f] [-r] ...");let f=n.cached,l=n.recursive,d=n.force,u=await X(s),m=[],h=kt(s,r.cwd);for(let w of c){if(Dr(w)){let x=[We(w,h)],y=u.entries.filter(P=>Pe(x,P.path));if(y.length===0)return v(`pathspec '${w}' did not match any files`);for(let P of y)m.push(P.path);continue}let b=Qe(r.cwd,w),R=lt(a,b);if((R==="."||R==="")&&(R=""),R.startsWith(".."))return v(`'${w}' is outside repository at '${a}'`);if(await r.fs.exists(b)&&!(await Je(r.fs,b)).isSymbolicLink&&(await Je(r.fs,b)).isDirectory){if(!l)return v(`not removing '${R}' recursively without -r`);let x=R===""?"":`${R}/`,y=u.entries.filter(P=>x===""||P.path.startsWith(x));if(y.length===0)return v(`pathspec '${w}' did not match any files`);for(let P of y)m.push(P.path)}else{if(!u.entries.some(y=>y.path===R))return v(`pathspec '${w}' did not match any files`);m.push(R)}}if(!d){let w=await Ny(s,u,m,f);if(w)return w}if(n.dryRun){let w=n.quiet?[]:m.map(R=>`rm '${R}'`);return{stdout:w.length>0?`${w.join(` ++`,a}te();Se();ie();ge();ye();ir();un();Te();ke();function Fm(e,t){e.command("rm",{description:"Remove files from the working tree and from the index",args:[B.string().name("paths").describe("Files to remove").optional().variadic()],options:{cached:S().describe("Only remove from the index"),recursive:S().alias("r").describe("Allow recursive removal when a directory name is given"),force:S().alias("f").describe("Override the up-to-date check"),dryRun:S().alias("n").describe("Don't actually remove any file(s)"),quiet:ce("do not list removed files")},handler:async(n,r)=>{let s=await W(r.fs,r.cwd,t);if(D(s))return s;let o=s,i=tt(o);if(i)return i;let a=o.workTree,c=n.paths;if(c.length===0)return N("usage: git rm [--cached] [-f] [-r] ...");let f=n.cached,l=n.recursive,d=n.force,u=await X(o),m=[],h=ut(o,r.cwd);for(let w of c){if(Gr(w)){let x=[qe(w,h)],k=u.entries.filter(P=>Pe(x,P.path));if(k.length===0)return v(`pathspec '${w}' did not match any files`);for(let P of k)m.push(P.path);continue}let b=Je(r.cwd,w),y=rt(a,b);if((y==="."||y==="")&&(y=""),y.startsWith(".."))return v(`'${w}' is outside repository at '${a}'`);if(await r.fs.exists(b)&&!(await Ye(r.fs,b)).isSymbolicLink&&(await Ye(r.fs,b)).isDirectory){if(!l)return v(`not removing '${y}' recursively without -r`);let x=y===""?"":`${y}/`,k=u.entries.filter(P=>x===""||P.path.startsWith(x));if(k.length===0)return v(`pathspec '${w}' did not match any files`);for(let P of k)m.push(P.path)}else{if(!u.entries.some(k=>k.path===y))return v(`pathspec '${w}' did not match any files`);m.push(y)}}if(!d){let w=await g0(o,u,m,f);if(w)return w}if(n.dryRun){let w=n.quiet?[]:m.map(y=>`rm '${y}'`);return{stdout:w.length>0?`${w.join(` + `)} +-`:"",stderr:"",exitCode:0}}let p=[];for(let w of m){if(u=yt(u,w),!f){let b=I(a,w);await Je(r.fs,b).then(()=>!0).catch(()=>!1)&&await r.fs.rm(b)}n.quiet||p.push(`rm '${w}'`)}return await ie(s,u),{stdout:p.length>0?`${p.join(` ++`:"",stderr:"",exitCode:0}}let p=[];for(let w of m){if(u=Rt(u,w),!f){let b=I(a,w);await Ye(r.fs,b).then(()=>!0).catch(()=>!1)&&await r.fs.rm(b)}n.quiet||p.push(`rm '${w}'`)}return await oe(o,u),{stdout:p.length>0?`${p.join(` + `)} +-`:"",stderr:"",exitCode:0}}})}async function Ny(e,t,n,r){let o=await Z(e),s=new Map;if(o){let f=await M(e,o),l=await ze(e,f.tree);for(let d of l)s.set(d.path,d.hash)}let i=[],a=[],c=[];for(let f of n){let l=t.entries.find(h=>h.path===f&&h.stage===0);if(!l)continue;let u=s.get(f)!==l.hash,m=!1;if(e.workTree){let h=I(e.workTree,f),p=!1;try{await Je(e.fs,h),p=!0}catch{p=!1}p&&(m=await $t(e,h,l.hash)!==l.hash)}u&&m?i.push(f):u&&!r?a.push(f):m&&!r&&c.push(f)}if(i.length>0){let f=i.map(d=>` ${d}`).join(` +-`),l=i.length===1?"the following file has":"the following files have";return F(`error: ${l} staged content different from both the ++`:"",stderr:"",exitCode:0}}})}async function g0(e,t,n,r){let s=await Z(e),o=new Map;if(s){let f=await M(e,s),l=await Ke(e,f.tree);for(let d of l)o.set(d.path,d.hash)}let i=[],a=[],c=[];for(let f of n){let l=t.entries.find(h=>h.path===f&&h.stage===0);if(!l)continue;let u=o.get(f)!==l.hash,m=!1;if(e.workTree){let h=I(e.workTree,f),p=!1;try{await Ye(e.fs,h),p=!0}catch{p=!1}p&&(m=await Ot(e,h,l.hash)!==l.hash)}u&&m?i.push(f):u&&!r?a.push(f):m&&!r&&c.push(f)}if(i.length>0){let f=i.map(d=>` ${d}`).join(` ++`),l=i.length===1?"the following file has":"the following files have";return N(`error: ${l} staged content different from both the + file and the HEAD: + ${f} + (use -f to force removal) + `)}if(a.length>0){let f=a.map(d=>` ${d}`).join(` +-`),l=a.length===1?"the following file has":"the following files have";return F(`error: ${l} changes staged in the index: ++`),l=a.length===1?"the following file has":"the following files have";return N(`error: ${l} changes staged in the index: + ${f} + (use --cached to keep the file, or -f to force removal) + `)}if(c.length>0){let f=c.map(d=>` ${d}`).join(` +-`),l=c.length===1?"the following file has":"the following files have";return F(`error: ${l} local modifications: ++`),l=c.length===1?"the following file has":"the following files have";return N(`error: ${l} local modifications: + ${f} + (use --cached to keep the file, or -f to force removal) +-`)}return null}ne();fr();ae();ye();Qt();De();Ee();function Om(e,t){e.command("shortlog",{description:"Summarize git log output",args:[W.string().name("revisions").variadic().optional()],options:{summary:S().alias("s").describe("Suppress commit descriptions, only provide count"),numbered:S().alias("n").describe("Sort by number of commits per author"),email:S().alias("e").describe("Show the email address of each author"),group:K.string().describe("Group commits by author or committer"),format:K.string().describe("Format string for each commit line"),all:S().describe("Walk all refs"),noMerges:S().describe("Exclude merge commits"),author:K.string().describe("Filter by author"),grep:K.string().describe("Filter by commit message"),since:K.string().describe("Show commits after date"),after:K.string().describe("Synonym for --since"),until:K.string().describe("Show commits before date"),before:K.string().describe("Synonym for --until")},handler:async(n,r,o)=>{let s=await q(r.fs,r.cwd,t);if(D(s))return s;let i=s,a,c,f=n.revisions,l=f&&f.length===1?gs(f[0]):null;if(l){let O=async G=>{let N=await Le(i,G);if(!N)return Et(G);try{return await Se(i,N)}catch{return Et(G)}},$=await O(l.left);if(typeof $=="object"&&"exitCode"in $)return $;let T=await O(l.right);if(typeof T=="object"&&"exitCode"in T)return T;let j=$,U=T;if(l.type==="two-dot")a=[U],c=[j];else{a=[j,U];let G=await ft(i,j,U);c=G.length>0?G:void 0}}else if(n.all){let O=await $e(i),$=new Set;for(let j of O)try{$.add(await Se(i,j.hash))}catch{}let T=await Z(i);T&&$.add(T),a=[...$]}else if(f&&f.length>0){let O=[];for(let $ of f){let T=await Le(i,$);if(!T)return Et($);try{O.push(await Se(i,T))}catch{return Et($)}}a=O}else{let O=await nt(i);if(D(O))return O;a=[O]}if(a.length===0)return{stdout:"",stderr:"",exitCode:0};let d=o.passthrough.length>0?o.passthrough.map(O=>We(O,"")):null,u=n.author?$m(n.author):null,m=n.grep?$m(n.grep):null,h=n.since??n.after,p=n.until??n.before,g=h?ds(h):null,w=p?ds(p):null,b=n.noMerges,R=n.group==="committer",C=null;if(n.format!==void 0){let O=bs(n.format);C=O.formatStr??O.preset}let x=new Map,y=d?By(i,a,d,c?await _y(i,c):void 0):Ot(i,a,{exclude:c});for await(let O of y){let{commit:$}=O;if(b&&$.parents.length>1||w!==null&&$.committer.timestamp>w||g!==null&&$.committer.timestamp<=g)continue;if(u){let N=`${$.author.name} <${$.author.email}>`;if(!u(N))continue}if(m&&!m($.message))continue;let T=R?$.committer:$.author,j=n.email?`${T.name} <${T.email}>`:T.name,U=x.get(j);U||(U={name:j,lines:[]},x.set(j,U));let G;if(C!==null){let N={hash:O.hash,commit:$,abbrev:await en(i,[O.hash,$.tree,...$.parents])};G=Br(C,N)}else G=me($.message);U.lines.push(G)}for(let O of x.values())O.lines.reverse();let P=(O,$)=>O<$?-1:O>$?1:0,k=[...x.values()];return n.numbered?k.sort((O,$)=>{let T=$.lines.length-O.lines.length;return T!==0?T:P(O.name,$.name)}):k.sort((O,$)=>P(O.name,$.name)),n.summary?{stdout:k.map($=>`${String($.lines.length).padStart(6)} ${$.name} +-`).join(""),stderr:"",exitCode:0}:{stdout:k.length>0?Uy(k):"",stderr:"",exitCode:0}}})}function Uy(e){let t=[];for(let n of e){let r=`${n.name} (${n.lines.length}): +-`;for(let o of n.lines)r+=` ${o} ++`)}return null}te();fr();ie();ye();Ft();Te();ke();function Um(e,t){e.command("shortlog",{description:"Summarize git log output",args:[B.string().name("revisions").variadic().optional()],options:{summary:S().alias("s").describe("Suppress commit descriptions, only provide count"),numbered:S().alias("n").describe("Sort by number of commits per author"),email:S().alias("e").describe("Show the email address of each author"),group:K.string().describe("Group commits by author or committer"),format:K.string().describe("Format string for each commit line"),all:S().describe("Walk all refs"),noMerges:S().describe("Exclude merge commits"),author:K.string().describe("Filter by author"),grep:K.string().describe("Filter by commit message"),since:K.string().describe("Show commits after date"),after:K.string().describe("Synonym for --since"),until:K.string().describe("Show commits before date"),before:K.string().describe("Synonym for --until")},handler:async(n,r,s)=>{let o=await W(r.fs,r.cwd,t);if(D(o))return o;let i=o,a,c,f=n.revisions,l=f&&f.length===1?ks(f[0]):null;if(l){let O=async G=>{let L=await Ie(i,G);if(!L)return Ct(G);try{return await Oe(i,L)}catch{return Ct(G)}},$=await O(l.left);if(typeof $=="object"&&"exitCode"in $)return $;let T=await O(l.right);if(typeof T=="object"&&"exitCode"in T)return T;let j=$,U=T;if(l.type==="two-dot")a=[U],c=[j];else{a=[j,U];let G=await mt(i,j,U);c=G.length>0?G:void 0}}else if(n.all){let O=await $e(i),$=new Set;for(let j of O)try{$.add(await Oe(i,j.hash))}catch{}let T=await Z(i);T&&$.add(T),a=[...$]}else if(f&&f.length>0){let O=[];for(let $ of f){let T=await Ie(i,$);if(!T)return Ct($);try{O.push(await Oe(i,T))}catch{return Ct($)}}a=O}else{let O=await nt(i);if(D(O))return O;a=[O]}if(a.length===0)return{stdout:"",stderr:"",exitCode:0};let d=s.passthrough.length>0?s.passthrough.map(O=>qe(O,"")):null,u=n.author?Nm(n.author):null,m=n.grep?Nm(n.grep):null,h=n.since??n.after,p=n.until??n.before,g=h?hs(h):null,w=p?hs(p):null,b=n.noMerges,y=n.group==="committer",C=null;if(n.format!==void 0){let O=Rs(n.format);C=O.formatStr??O.preset}let x=new Map,k=d?y0(i,a,d,c?await b0(i,c):void 0):St(i,a,{exclude:c});for await(let O of k){let{commit:$}=O;if(b&&$.parents.length>1||w!==null&&$.committer.timestamp>w||g!==null&&$.committer.timestamp<=g)continue;if(u){let L=`${$.author.name} <${$.author.email}>`;if(!u(L))continue}if(m&&!m($.message))continue;let T=y?$.committer:$.author,j=n.email?`${T.name} <${T.email}>`:T.name,U=x.get(j);U||(U={name:j,lines:[]},x.set(j,U));let G;if(C!==null){let L={hash:O.hash,commit:$,abbrev:await sn(i,[O.hash,$.tree,...$.parents])};G=Kr(C,L)}else G=he($.message);U.lines.push(G)}for(let O of x.values())O.lines.reverse();let P=(O,$)=>O<$?-1:O>$?1:0,E=[...x.values()];return n.numbered?E.sort((O,$)=>{let T=$.lines.length-O.lines.length;return T!==0?T:P(O.name,$.name)}):E.sort((O,$)=>P(O.name,$.name)),n.summary?{stdout:E.map($=>`${String($.lines.length).padStart(6)} ${$.name} ++`).join(""),stderr:"",exitCode:0}:{stdout:E.length>0?w0(E):"",stderr:"",exitCode:0}}})}function w0(e){let t=[];for(let n of e){let r=`${n.name} (${n.lines.length}): ++`;for(let s of n.lines)r+=` ${s} + `;t.push(r)}return t.join(` + `)+` +-`}function $m(e){try{let t=new RegExp(e);return n=>t.test(n)}catch{return t=>t.includes(e)}}async function _y(e,t){let n=new Set;for await(let r of Ot(e,t))n.add(r.hash);return n}async function*By(e,t,n,r){let o=new Set(r),s=new vn,i=async a=>{if(!o.has(a))try{let c=await M(e,a);s.push({hash:a,commit:c})}catch{}};for(let a of t)await i(a);for(;s.size>0;){let a=s.pop();if(o.has(a.hash))continue;o.add(a.hash);let{commit:c}=a,f=c.parents;if(f.length===0){(await Ke(e,null,c.tree)).some(u=>Pe(n,u.path))&&(yield a);continue}if(f.length===1){let d=f[0];if(d){try{let u=await M(e,d);(await Ke(e,u.tree,c.tree)).some(h=>Pe(n,h.path))&&(yield a)}catch{yield a}await i(d)}continue}let l=[];for(let d of f)try{let u=await M(e,d);(await Ke(e,u.tree,c.tree)).some(h=>Pe(n,h.path))||l.push(d)}catch{}if(l.length>0&&l[0])await i(l[0]);else{yield a;for(let d of f)await i(d)}}}ne();ae();Qt();Go();ge();De();Ee();var Gc=new TextDecoder,Sm="options '--name-only', '--name-status', '--check', and '-s' cannot be used together";function vm(e,t){e.command("show",{description:"Show various types of objects",args:[W.string().name("object").variadic().optional()],options:{patch:S().alias("p").describe("Show diff in patch format"),noPatch:S().describe("Suppress diff output"),quiet:ce("suppress diff output"),stat:S().describe("Show diffstat summary"),nameOnly:S().describe("Show only names of changed files"),nameStatus:S().describe("Show names and status of changed files"),shortstat:S().describe("Show only the shortstat summary line"),numstat:S().describe("Machine-readable insertions/deletions per file"),format:K.string().describe("Pretty-print format string"),pretty:K.string().describe("Pretty-print format or preset name")},handler:async(n,r)=>{let o=await q(r.fs,r.cwd,t);if(D(o))return o;let s=o,a=n.object[0]??"HEAD",c=n.quiet&&(n.nameOnly||n.nameStatus),f=Lo(a);if(f)return Wy(s,f.rev,f.path,c);if(a==="HEAD"){let w=await nt(s);if(D(w))return w}let l=await It(s,a,`bad object '${a}'`);if(D(l))return l;if(c)return v(Sm);let d=await be(s,l),u={limit:await Rt(s,"diff")},m;n.noPatch?m=null:n.stat?m="stat":n.nameOnly?m="name-only":n.nameStatus?m="name-status":n.shortstat?m="shortstat":n.numstat?m="numstat":n.quiet&&!n.patch?m=null:m="patch";let h=n.format??n.pretty,p=null,g=null;if(h!==void 0){let w=bs(h);p=w.formatStr,g=w.preset}switch(d.type){case"commit":{let w=await M(s,l);return{stdout:await Im(s,l,w,u,m,p,g),stderr:mt("diff",u.needed),exitCode:0}}case"tag":{let w=await Mo(s,l);return{stdout:await qy(s,w,u,m,p,g),stderr:mt("diff",u.needed),exitCode:0}}case"tree":{let w=Nn(d.content);return{stdout:Tm(w),stderr:"",exitCode:0}}case"blob":return{stdout:Gc.decode(d.content),stderr:"",exitCode:0}}}})}async function Wy(e,t,n,r){let o=await Ge(e,t);if(D(o))return o;let s=o.commit.tree,i=n.replace(/^\//,""),c=(await de(e,s)).get(i);if(!c){let l=`path '${i}' does not exist in '${t}'`;if(e.workTree){let d=I(e.workTree,i);await e.fs.exists(d)&&(l=`path '${i}' exists on disk, but not in '${t}'`)}return v(l)}if(r)return v(Sm);let f=await be(e,c.hash);if(f.type==="blob")return{stdout:Gc.decode(f.content),stderr:"",exitCode:0};if(f.type==="tree"){let l=Nn(f.content);return{stdout:Tm(l),stderr:"",exitCode:0}}return{stdout:Gc.decode(f.content),stderr:"",exitCode:0}}async function Im(e,t,n,r,o="patch",s=null,i=null){let a=await en(e,[t,n.tree,...n.parents]),c;if(s!==null)c=Br(s,{hash:t,commit:n,abbrev:a});else if(i!==null)c=co(i,{hash:t,commit:n,abbrev:a},!0,!1);else{let l=[];if(l.push(`commit ${t}`),n.parents.length>=2){let u=n.parents.map(m=>a(m)).join(" ");l.push(`Merge: ${u}`)}l.push(`Author: ${n.author.name} <${n.author.email}>`),l.push(`Date: ${qn(n.author.timestamp,n.author.timezone)}`),l.push("");let d=n.message.replace(/\n$/,"");for(let u of d.split(` +-`))l.push(` ${u}`);c=l.join(` +-`)}if(!o)return`${c} +-`;let f="";if(n.parents.length<=1){let l=n.parents.length===1?(await M(e,n.parents[0])).tree:null,d=await Ke(e,l,n.tree),{remaining:u,renames:m,neededRenameLimit:h}=await ht(e,d,{limit:r.limit});r.needed=Math.max(r.needed??0,h??0)||void 0,f=await zy(e,u,m,o)}else o==="patch"&&(f=await t0(e,n)??"");return f?`${c} ++`}function Nm(e){try{let t=new RegExp(e);return n=>t.test(n)}catch{return t=>t.includes(e)}}async function b0(e,t){let n=new Set;for await(let r of St(e,t))n.add(r.hash);return n}async function*y0(e,t,n,r){let s=new Set(r),o=new Hn,i=async a=>{if(!s.has(a))try{let c=await M(e,a);o.push({hash:a,commit:c})}catch{}};for(let a of t)await i(a);for(;o.size>0;){let a=o.pop();if(s.has(a.hash))continue;s.add(a.hash);let{commit:c}=a,f=c.parents;if(f.length===0){(await Ve(e,null,c.tree)).some(u=>Pe(n,u.path))&&(yield a);continue}if(f.length===1){let d=f[0];if(d){try{let u=await M(e,d);(await Ve(e,u.tree,c.tree)).some(h=>Pe(n,h.path))&&(yield a)}catch{yield a}await i(d)}continue}let l=[];for(let d of f)try{let u=await M(e,d);(await Ve(e,u.tree,c.tree)).some(h=>Pe(n,h.path))||l.push(d)}catch{}if(l.length>0&&l[0])await i(l[0]);else{yield a;for(let d of f)await i(d)}}}te();ie();Ft();Bs();ge();Te();ke();var Yc=new TextDecoder,_m="options '--name-only', '--name-status', '--check', and '-s' cannot be used together";function Bm(e,t){e.command("show",{description:"Show various types of objects",args:[B.string().name("object").variadic().optional()],options:{patch:S().alias("p").describe("Show diff in patch format"),noPatch:S().describe("Suppress diff output"),quiet:ce("suppress diff output"),stat:S().describe("Show diffstat summary"),nameOnly:S().describe("Show only names of changed files"),nameStatus:S().describe("Show names and status of changed files"),shortstat:S().describe("Show only the shortstat summary line"),numstat:S().describe("Machine-readable insertions/deletions per file"),summary:S().describe("Show creations, deletions, renames and mode changes"),format:K.string().describe("Pretty-print format string"),pretty:K.string().describe("Pretty-print format or preset name")},handler:async(n,r)=>{let s=await W(r.fs,r.cwd,t);if(D(s))return s;let o=s,a=n.object[0]??"HEAD",c=n.quiet&&(n.nameOnly||n.nameStatus),f=qo(a);if(f)return k0(o,f.rev,f.path,c);if(a==="HEAD"){let y=await nt(o);if(D(y))return y}let l=await At(o,a,`bad object '${a}'`);if(D(l))return l;if(c)return v(_m);let d=await me(o,l),u={limit:await xt(o,"diff")},m;n.noPatch?m=null:n.stat?m="stat":n.nameOnly?m="name-only":n.nameStatus?m="name-status":n.shortstat?m="shortstat":n.numstat?m="numstat":(n.quiet||n.summary)&&!n.patch?m=null:m="patch";let h=n.summary&&!n.noPatch&&m!=="name-only"&&m!=="name-status",p=m||h?{format:m,summary:h}:null,g=n.format??n.pretty,w=null,b=null;if(g!==void 0){let y=Rs(g);w=y.formatStr,b=y.preset}switch(d.type){case"commit":{let y=await M(o,l);return{stdout:await Wm(o,l,y,u,p,w,b),stderr:wt("diff",u.needed),exitCode:0}}case"tag":{let y=await _o(o,l);return{stdout:await R0(o,y,u,p,w,b),stderr:wt("diff",u.needed),exitCode:0}}case"tree":{let y=bn(d.content);return{stdout:zm(y),stderr:"",exitCode:0}}case"blob":return{stdout:Yc.decode(d.content),stderr:"",exitCode:0}}}})}async function k0(e,t,n,r){let s=await Le(e,t);if(D(s))return s;let o=s.commit.tree,i=n.replace(/^\//,""),c=(await de(e,o)).get(i);if(!c){let l=`path '${i}' does not exist in '${t}'`;if(e.workTree){let d=I(e.workTree,i);await e.fs.exists(d)&&(l=`path '${i}' exists on disk, but not in '${t}'`)}return v(l)}if(r)return v(_m);let f=await me(e,c.hash);if(f.type==="blob")return{stdout:Yc.decode(f.content),stderr:"",exitCode:0};if(f.type==="tree"){let l=bn(f.content);return{stdout:zm(l),stderr:"",exitCode:0}}return{stdout:Yc.decode(f.content),stderr:"",exitCode:0}}async function Wm(e,t,n,r,s,o=null,i=null){let a=await sn(e,[t,n.tree,...n.parents]),c;if(o!==null)c=Kr(o,{hash:t,commit:n,abbrev:a});else if(i!==null)c=wo(i,{hash:t,commit:n,abbrev:a},!0,!1);else{let d=[];if(d.push(`commit ${t}`),n.parents.length>=2){let m=n.parents.map(h=>a(h)).join(" ");d.push(`Merge: ${m}`)}d.push(`Author: ${n.author.name} <${n.author.email}>`),d.push(`Date: ${zn(n.author.timestamp,n.author.timezone)}`),d.push("");let u=n.message.replace(/\n$/,"");for(let m of u.split(` ++`))d.push(` ${m}`);c=d.join(` ++`)}if(!s)return`${c} ++`;let f="",l=!1;if(n.parents.length<=1){let d=n.parents.length===1?(await M(e,n.parents[0])).tree:null,{diffs:u,renames:m}=await qm(e,d,n.tree,r);l=u.length>0||m.length>0,f=await Km(e,u,m,s)}else f=await E0(e,n,r,s);return f?`${c} + + ${f.replace(/\n$/,"")} +-`:n.parents.length>=2?`${c} ++`:l||n.parents.length>=2?`${c} + + `:`${c} +-`}async function qy(e,t,n,r="patch",o=null,s=null){let i=[];i.push(`tag ${t.name}`),i.push(`Tagger: ${t.tagger.name} <${t.tagger.email}>`),i.push(`Date: ${qn(t.tagger.timestamp,t.tagger.timezone)}`),i.push("");let a=t.message.replace(/\n$/,"");for(let c of a.split(` +-`))i.push(` ${c}`);if(t.objectType==="commit"){let c=await M(e,t.object),f=await Im(e,t.object,c,n,r,o,s);i.push(""),i.push(f.replace(/\n$/,""))}return`${i.join(` ++`}async function qm(e,t,n,r){let s=await Ve(e,t,n),{remaining:o,renames:i,neededRenameLimit:a}=await bt(e,s,{limit:r.limit});return r.needed=Math.max(r.needed??0,a??0)||void 0,{diffs:o,renames:i}}async function E0(e,t,n,r){let s=r.format==="stat"||r.format==="shortstat"||r.format==="numstat"?r.format:null,o="";if(s||r.summary){let a=(await M(e,t.parents[0])).tree,{diffs:c,renames:f}=await qm(e,a,t.tree,n);o=await Km(e,c,f,{format:s,summary:r.summary})}let i=r.format==="patch"?await A0(e,t):"";return ro(i,o,i!=="")}async function R0(e,t,n,r,s=null,o=null){let i=[];i.push(`tag ${t.name}`),i.push(`Tagger: ${t.tagger.name} <${t.tagger.email}>`),i.push(`Date: ${zn(t.tagger.timestamp,t.tagger.timezone)}`),i.push("");let a=t.message.replace(/\n$/,"");for(let c of a.split(` ++`))i.push(` ${c}`);if(t.objectType==="commit"){let c=await M(e,t.object),f=await Wm(e,t.object,c,n,r,s,o);i.push(""),i.push(f.replace(/\n$/,""))}return`${i.join(` + `)} +-`}function Tm(e){let t=[];for(let n of e.entries){let r=n.mode==="040000"?"tree":"blob";t.push(`${n.mode} ${r} ${n.hash} ${n.name}`)}return t.length>0?`${t.join(` ++`}function zm(e){let t=[];for(let n of e.entries){let r=n.mode==="040000"?"tree":"blob";t.push(`${n.mode} ${r} ${n.hash} ${n.name}`)}return t.length>0?`${t.join(` + `)} +-`:""}async function zy(e,t,n,r){switch(r){case"patch":return e0(e,t,n);case"stat":return Yy(e,t,n);case"shortstat":return Xy(e,t,n);case"numstat":return Zy(e,t,n);case"name-only":return Ky(t,n);case"name-status":return Vy(t,n);default:return""}}function Ky(e,t){let n=[];for(let r of e)n.push(r.path);for(let r of t)n.push(r.newPath);return n.sort(),n.length>0?`${n.join(` ++`:""}async function Km(e,t,n,r){let s=await C0(e,t,n,r.format);return r.summary?ro(s,Er(t,n),r.format==="patch"):s}async function C0(e,t,n,r){switch(r){case"patch":return T0(e,t,n);case"stat":return $0(e,t,n);case"shortstat":return O0(e,t,n);case"numstat":return S0(e,t,n);case"name-only":return x0(t,n);case"name-status":return P0(t,n);default:return""}}function x0(e,t){let n=[];for(let r of e)n.push(r.path);for(let r of t)n.push(r.newPath);return n.sort(),n.length>0?`${n.join(` + `)} +-`:""}function Vy(e,t){let n=[];for(let r of e){let o=r.status==="added"?"A":r.status==="deleted"?"D":"M";n.push({key:r.path,line:`${o} ${r.path}`})}for(let r of t){let o=String(r.similarity??100).padStart(3,"0");n.push({key:r.newPath,line:`R${o} ${r.oldPath} ${r.newPath}`})}return n.sort((r,o)=>r.keyo.key?1:0),n.length>0?n.map(r=>`${r.line} +-`).join(""):""}async function Yy(e,t,n){let{fileStats:r}=await kr(e,t,n);return r.sort((o,s)=>o.sortKeys.sortKey?1:0),jr(r)}async function Xy(e,t,n){let{fileStats:r}=await kr(e,t,n),o=0,s=0;for(let a of r)o+=a.insertions,s+=a.deletions;let i=yr(r.length,o,s);return i?`${i} +-`:""}async function Zy(e,t,n){let r=[];for(let s of t)r.push({key:s.path,oldHash:s.oldHash,newHash:s.newHash,display:s.path});for(let s of n)r.push({key:s.newPath,oldHash:s.oldHash,newHash:s.newHash,display:In(s.oldPath,s.newPath)});r.sort((s,i)=>s.keyi.key?1:0);let o="";for(let s of r){let i=s.oldHash?await le(e,s.oldHash):"",a=s.newHash?await le(e,s.newHash):"";if(Ne(i)||Ne(a))o+=`- - ${s.display} +-`;else{let c=Ht(i),f=Ht(a),l=gt(c,f),d=0,u=0;for(let m of l)m.type==="insert"?d++:m.type==="delete"&&u++;o+=`${d} ${u} ${s.display} +-`}}return o}async function Qy(e,t){let n=t.oldHash?await le(e,t.oldHash):"",r=t.newHash?await le(e,t.newHash):"";return Wt({path:t.path,oldContent:n,newContent:r,oldMode:t.oldMode,newMode:t.newMode,oldHash:t.oldHash,newHash:t.newHash})}async function Jy(e,t){let n=t.oldHash?await le(e,t.oldHash):"",r=t.newHash?await le(e,t.newHash):"";return Wt({path:t.oldPath,oldContent:n,newContent:r,oldMode:t.oldMode,newMode:t.newMode,oldHash:t.oldHash,newHash:t.newHash,renameTo:t.newPath,similarity:t.similarity})}async function e0(e,t,n){let r=[];for(let s of t)r.push({type:"diff",entry:s});for(let s of n)r.push({type:"rename",entry:s});r.sort((s,i)=>{let a=s.type==="diff"?s.entry.path:s.entry.newPath,c=i.type==="diff"?i.entry.path:i.entry.newPath;return ac?1:0});let o="";for(let s of r)s.type==="rename"?o+=await Jy(e,s.entry):o+=await Qy(e,s.entry);return o}async function t0(e,t){if(t.parents.length<2)return"";let n=await Promise.all(t.parents.map(async a=>{let c=await M(e,a);return de(e,c.tree)})),r=await de(e,t.tree),o=new Set;for(let a of n)for(let c of a.keys())o.add(c);for(let a of r.keys())o.add(a);let s=[];for(let a of o){let f=r.get(a)?.hash??null;n.every(d=>(d.get(a)?.hash??null)!==f)&&s.push(a)}if(s.sort(),s.length===0)return"";let i="";for(let a of s)i+=await n0(e,a,n,r);return i}async function n0(e,t,n,r){let o=r.get(t),s=n.map(u=>u.get(t)??null),i=o?.hash??null,a=o?.mode??null,c=s.map(u=>u?.hash??null),f=s.map(u=>u?.mode??null),l=await Promise.all(c.map(async u=>u?await le(e,u):"")),d=i?await le(e,i):"";return xi({path:t,parentHashes:c,parentModes:f,parentContents:l,resultHash:i,resultMode:a,resultContent:d})}ne();ve();ae();ye();ne();ir();xr();ve();ae();Mn();ge();Ve();ye();cn();De();Jt();st();var yn="refs/stash";function Nc(e,t){return Te(e.replaceAll("/","\0"),t.replaceAll("/","\0"))}async function Am(e){let t=await vt(e,yn),n=[];for(let r=t.length-1;r>=0;r--){let o=t[r];o&&n.push({index:t.length-1-r,hash:o.newHash,message:o.message})}return n}async function ys(e,t){let n=await vt(e,yn);if(n.length===0)return null;let r=n.length-1-t;return r<0||r>=n.length?null:n[r]?.newHash??null}async function Hm(e,t,n,r){if(!e.workTree)throw new Error("Cannot stash in a bare repository");let o=e.workTree,s=await Z(e);if(!s)return null;let i=await M(e,s),a=await X(e),c=qe(a),f=await Ye(e,c),l=await Ke(e,i.tree,f),d=new Map(c.map(L=>[L.path,L])),u=await ut(e,o,"",{skipIgnore:!0}),m=!1;for(let L of u){let _=d.get(L);if(!_)continue;let V=I(o,L);if(await $t(e,V,_.hash)!==_.hash){m=!0;break}}if(!m)for(let[L]of d){let _=I(o,L);if(!await e.fs.exists(_)){m=!0;break}}let h=[];if(r?.includeUntracked){let L=await ut(e,o,"");for(let _ of L)d.has(_)||h.push(_)}if(l.length===0&&!m&&h.length===0)return null;let p=await Ro(e,t),g=await xs(e,t),w=await te(e),b=w?.type==="symbolic"?Ie(w.target):"(no branch)",R=await ue(e,s),C=me(i.message),x=`index on ${b}: ${R} ${C} +-`,y=Cn({type:"commit",tree:f,parents:[s],author:p,committer:g,message:x}),P=await Me(e,"commit",y),k=await de(e,i.tree),E=[],O=new Set;for(let L of u){let _=d.get(L),V=k.get(L);if(!_&&!V)continue;let Y=I(o,L),fe=await e.fs.readFileBuffer(Y),J=await Fs(e,fe,_?.hash??V?.hash),re=await Me(e,"blob",J),Oe=_?_.mode:parseInt(V?.mode??"100644",8);E.push({path:L,mode:Oe,hash:re,stage:0,stat:Fe()}),O.add(L)}for(let[L,_]of d)if(!O.has(L)){if(Yt(_.mode)){E.push({path:L,mode:_.mode,hash:_.hash,stage:0,stat:Fe()});continue}k.has(L)||E.push({path:L,mode:_.mode,hash:_.hash,stage:0,stat:Fe()})}let $=await Ye(e,E),T=null;if(r?.includeUntracked){let L=[];for(let fe of h){let J=I(o,fe),re=await e.fs.readFileBuffer(J),Oe=await Fs(e,re),xe=await Me(e,"blob",Oe);L.push({path:fe,mode:33188,hash:xe,stage:0,stat:Fe()})}let _=await Ye(e,L),V=`untracked files on ${b}: ${R} ${C} +-`,Y=Cn({type:"commit",tree:_,parents:[],author:p,committer:g,message:V});T=await Me(e,"commit",Y)}let j=n?`On ${b}: ${n}`:`WIP on ${b}: ${R} ${C}`,U=[s,P];T&&U.push(T);let G=Cn({type:"commit",tree:$,parents:U,author:p,committer:g,message:j}),N=await Me(e,"commit",G),A=await ys(e,0)??oe;await rt(e,yn,{oldHash:A,newHash:N,name:g.name,email:g.email,timestamp:g.timestamp,tz:g.timezone,message:j.trimEnd()}),await Q(e,yn,N);let H=await _n(e,i.tree,a);await ie(e,{version:2,entries:H.newEntries}),await je(e,H.worktreeOps),(await te(e))?.type==="symbolic"&&await ee(e,t,"HEAD",s,s,"reset: moving to HEAD");for(let L of["CHERRY_PICK_HEAD","MERGE_HEAD","ORIG_HEAD","REVERT_HEAD"])await ke(e,L);for(let L of["MERGE_MSG","MERGE_MODE","SQUASH_MSG"]){let _=I(e.gitDir,L);await e.fs.exists(_)&&await e.fs.rm(_)}if(h.length>0)for(let L of h){if(k.has(L))continue;let _=I(o,L);await e.fs.exists(_)&&(await e.fs.rm(_),await Tr(e.fs,bt(_),o))}return N}async function Fc(e,t){let n=e.workTree,r=await M(e,t),o=await ze(e,r.tree),s=[];for(let i of o){let a=I(n,i.path);await e.fs.exists(a)?s.push(i.path):await at(e,i)}return s.length>0?(s.sort(Nc),{ok:!1,stdout:"",stderr:`${s.map(i=>`${i} already exists, no checkout`).join(` ++`:""}function P0(e,t){let n=[];for(let r of e){let s=r.status==="added"?"A":r.status==="deleted"?"D":"M";n.push({key:r.path,line:`${s} ${r.path}`})}for(let r of t){let s=String(r.similarity??100).padStart(3,"0");n.push({key:r.newPath,line:`R${s} ${r.oldPath} ${r.newPath}`})}return n.sort((r,s)=>r.keys.key?1:0),n.length>0?n.map(r=>`${r.line} ++`).join(""):""}async function $0(e,t,n){let r=await kr(e,t,n);return r.sort((s,o)=>s.sortKeyo.sortKey?1:0),Nr(r)}async function O0(e,t,n){let r=await kr(e,t,n),s=0,o=0;for(let a of r)s+=a.insertions,o+=a.deletions;let i=yr(r.length,s,o);return i?`${i} ++`:""}async function S0(e,t,n){let r=[];for(let o of t)r.push({key:o.path,oldHash:o.oldHash,newHash:o.newHash,display:o.path});for(let o of n)r.push({key:o.newPath,oldHash:o.oldHash,newHash:o.newHash,display:Dn(o.oldPath,o.newPath)});r.sort((o,i)=>o.keyi.key?1:0);let s="";for(let o of r){let i=o.oldHash?await le(e,o.oldHash):"",a=o.newHash?await le(e,o.newHash):"";if(Fe(i)||Fe(a))s+=`- - ${o.display} ++`;else{let c=Mt(i),f=Mt(a),l=kt(c,f),d=0,u=0;for(let m of l)m.type==="insert"?d++:m.type==="delete"&&u++;s+=`${d} ${u} ${o.display} ++`}}return s}async function v0(e,t){let n=t.oldHash?await le(e,t.oldHash):"",r=t.newHash?await le(e,t.newHash):"";return Kt({path:t.path,oldContent:n,newContent:r,oldMode:t.oldMode,newMode:t.newMode,oldHash:t.oldHash,newHash:t.newHash})}async function I0(e,t){let n=t.oldHash?await le(e,t.oldHash):"",r=t.newHash?await le(e,t.newHash):"";return Kt({path:t.oldPath,oldContent:n,newContent:r,oldMode:t.oldMode,newMode:t.newMode,oldHash:t.oldHash,newHash:t.newHash,renameTo:t.newPath,similarity:t.similarity})}async function T0(e,t,n){let r=[];for(let o of t)r.push({type:"diff",entry:o});for(let o of n)r.push({type:"rename",entry:o});r.sort((o,i)=>{let a=o.type==="diff"?o.entry.path:o.entry.newPath,c=i.type==="diff"?i.entry.path:i.entry.newPath;return ac?1:0});let s="";for(let o of r)o.type==="rename"?s+=await I0(e,o.entry):s+=await v0(e,o.entry);return s}async function A0(e,t){if(t.parents.length<2)return"";let n=await Promise.all(t.parents.map(async a=>{let c=await M(e,a);return de(e,c.tree)})),r=await de(e,t.tree),s=new Set;for(let a of n)for(let c of a.keys())s.add(c);for(let a of r.keys())s.add(a);let o=[];for(let a of s){let f=r.get(a)?.hash??null;n.every(d=>(d.get(a)?.hash??null)!==f)&&o.push(a)}if(o.sort(),o.length===0)return"";let i="";for(let a of o)i+=await H0(e,a,n,r);return i}async function H0(e,t,n,r){let s=r.get(t),o=n.map(u=>u.get(t)??null),i=s?.hash??null,a=s?.mode??null,c=o.map(u=>u?.hash??null),f=o.map(u=>u?.mode??null),l=await Promise.all(c.map(async u=>u?await le(e,u):"")),d=i?await le(e,i):"";return Di({path:t,parentHashes:c,parentModes:f,parentContents:l,resultHash:i,resultMode:a,resultContent:d})}te();Se();ie();ye();te();ir();$r();Se();ie();On();ge();Xe();ye();un();Te();rn();ot();var Cn="refs/stash";function Zc(e,t){return Ae(e.replaceAll("/","\0"),t.replaceAll("/","\0"))}async function Vm(e){let t=await Tt(e,Cn),n=[];for(let r=t.length-1;r>=0;r--){let s=t[r];s&&n.push({index:t.length-1-r,hash:s.newHash,message:s.message})}return n}async function Cs(e,t){let n=await Tt(e,Cn);if(n.length===0)return null;let r=n.length-1-t;return r<0||r>=n.length?null:n[r]?.newHash??null}async function Ym(e,t,n,r){if(!e.workTree)throw new Error("Cannot stash in a bare repository");let s=e.workTree,o=await Z(e);if(!o)return null;let i=await M(e,o),a=await X(e),c=ze(a),f=await Ze(e,c),l=await Ve(e,i.tree,f),d=new Map(c.map(F=>[F.path,F])),u=await gt(e,s,"",{skipIgnore:!0}),m=!1;for(let F of u){let _=d.get(F);if(!_)continue;let Y=I(s,F);if(await Ot(e,Y,_.hash)!==_.hash){m=!0;break}}if(!m)for(let[F]of d){let _=I(s,F);if(!await e.fs.exists(_)){m=!0;break}}let h=[];if(r?.includeUntracked){let F=await gt(e,s,"");for(let _ of F)d.has(_)||h.push(_)}if(l.length===0&&!m&&h.length===0)return null;let p=await Io(e,t),g=await vs(e,t),w=await ne(e),b=w?.type==="symbolic"?ve(w.target):"(no branch)",y=await fe(e,o),C=he(i.message),x=`index on ${b}: ${y} ${C} ++`,k=$n({type:"commit",tree:f,parents:[o],author:p,committer:g,message:x}),P=await De(e,"commit",k),E=await de(e,i.tree),R=[],O=new Set;for(let F of u){let _=d.get(F),Y=E.get(F);if(!_&&!Y)continue;let V=I(s,F),ue=await e.fs.readFileBuffer(V),Ce=await qs(e,ue,_?.hash??Y?.hash),Qe=await De(e,"blob",Ce),ae=_?_.mode:parseInt(Y?.mode??"100644",8);R.push({path:F,mode:ae,hash:Qe,stage:0,stat:Ge()}),O.add(F)}for(let[F,_]of d)if(!O.has(F)){if(Jt(_.mode)){R.push({path:F,mode:_.mode,hash:_.hash,stage:0,stat:Ge()});continue}E.has(F)||R.push({path:F,mode:_.mode,hash:_.hash,stage:0,stat:Ge()})}let $=await Ze(e,R),T=null;if(r?.includeUntracked){let F=[];for(let ue of h){let Ce=I(s,ue),Qe=await e.fs.readFileBuffer(Ce),ae=await qs(e,Qe),J=await De(e,"blob",ae);F.push({path:ue,mode:33188,hash:J,stage:0,stat:Ge()})}let _=await Ze(e,F),Y=`untracked files on ${b}: ${y} ${C} ++`,V=$n({type:"commit",tree:_,parents:[],author:p,committer:g,message:Y});T=await De(e,"commit",V)}let j=n?`On ${b}: ${n}`:`WIP on ${b}: ${y} ${C}`,U=[o,P];T&&U.push(T);let G=$n({type:"commit",tree:$,parents:U,author:p,committer:g,message:j}),L=await De(e,"commit",G),A=await Cs(e,0)??se;await st(e,Cn,{oldHash:A,newHash:L,name:g.name,email:g.email,timestamp:g.timestamp,tz:g.timezone,message:j.trimEnd()}),await Q(e,Cn,L);let H=await Bn(e,i.tree,a);await oe(e,{version:2,entries:H.newEntries}),await Me(e,H.worktreeOps),(await ne(e))?.type==="symbolic"&&await ee(e,t,"HEAD",o,o,"reset: moving to HEAD");for(let F of["CHERRY_PICK_HEAD","MERGE_HEAD","ORIG_HEAD","REVERT_HEAD"])await Ee(e,F);for(let F of["MERGE_MSG","MERGE_MODE","SQUASH_MSG"]){let _=I(e.gitDir,F);await e.fs.exists(_)&&await e.fs.rm(_)}if(h.length>0)for(let F of h){if(E.has(F))continue;let _=I(s,F);await e.fs.exists(_)&&(await e.fs.rm(_),await Mr(e.fs,Et(_),s))}return L}async function Xc(e,t){let n=e.workTree,r=await M(e,t),s=await Ke(e,r.tree),o=[];for(let i of s){let a=I(n,i.path);await e.fs.exists(a)?o.push(i.path):await lt(e,i)}return o.length>0?(o.sort(Zc),{ok:!1,stdout:"",stderr:`${o.map(i=>`${i} already exists, no checkout`).join(` + `)} + error: could not restore untracked files from stash +-`,exitCode:1}):{ok:!0,hasConflicts:!1,messages:[]}}async function Uc(e,t=0,n){if(!e.workTree)return{ok:!1,stdout:"",stderr:`fatal: this operation must be run in a work tree +-`,exitCode:128};let r=await ys(e,t);if(!r)return{ok:!1,stdout:"",stderr:`error: stash@{${t}} is not a valid reference ++`,exitCode:1}):{ok:!0,hasConflicts:!1,messages:[]}}async function Qc(e,t=0,n){if(!e.workTree)return{ok:!1,stdout:"",stderr:`fatal: this operation must be run in a work tree ++`,exitCode:128};let r=await Cs(e,t);if(!r)return{ok:!1,stdout:"",stderr:`error: stash@{${t}} is not a valid reference + `,exitCode:1};if(!await Z(e))return{ok:!1,stdout:"",stderr:`error: your current branch does not have any commits yet +-`,exitCode:1};let s=await X(e),i=fn(s).sort();if(i.length>0)return{ok:!1,stdout:`${i.map(O=>`${O}: needs merge`).join(` ++`,exitCode:1};let o=await X(e),i=mn(o).sort();if(i.length>0)return{ok:!1,stdout:`${i.map(O=>`${O}: needs merge`).join(` + `)} + `,stderr:`error: could not write index + `,exitCode:1};let a=await M(e,r),c=a.parents[0];if(!c)return{ok:!1,stdout:"",stderr:`error: invalid stash commit (no parent) +-`,exitCode:1};let f=await M(e,c),l=a.parents[2],d=qe(s),u=await Ye(e,d),m={a:"Updated upstream",b:"Stashed changes"};if(f.tree===a.tree){if(l){let E=await Fc(e,l);if(!E.ok)return{...E,messages:["Already up to date."]}}return{ok:!0,hasConflicts:!1,messages:["Already up to date."]}}let h=await sn(e,f.tree,u,a.tree,m),p=await de(e,u),g=await de(e,h.resultTree),w=[];for(let[E,O]of g){let $=p.get(E);(!$||$.hash!==O.hash)&&w.push({path:E,type:"checkout",hash:O.hash,mode:parseInt(O.mode,8)})}for(let[E]of p)g.has(E)||w.push({path:E,type:"delete"});let b=new Map(d.map(E=>[E.path,E])),R=[],C=[];for(let E of w){let O=b.get(E.path),$=I(e.workTree,E.path);if(O){if(Yt(O.mode)||!await e.fs.exists($))continue;await $t(e,$,O.hash)!==O.hash&&R.push(E.path)}else E.type==="checkout"&&await e.fs.exists($)&&C.push(E.path)}if(R.length>0||C.length>0){R.sort(Nc),C.sort(Nc);let E="";if(R.length>0&&(E+=`error: Your local changes to the following files would be overwritten by merge: +-${R.map(O=>` ${O}`).join(` ++`,exitCode:1};let f=await M(e,c),l=a.parents[2],d=ze(o),u=await Ze(e,d),m={a:"Updated upstream",b:"Stashed changes"};if(f.tree===a.tree){if(l){let R=await Xc(e,l);if(!R.ok)return{...R,messages:["Already up to date."]}}return{ok:!0,hasConflicts:!1,messages:["Already up to date."]}}let h=await fn(e,f.tree,u,a.tree,m),p=await de(e,u),g=await de(e,h.resultTree),w=[];for(let[R,O]of g){let $=p.get(R);(!$||$.hash!==O.hash)&&w.push({path:R,type:"checkout",hash:O.hash,mode:parseInt(O.mode,8)})}for(let[R]of p)g.has(R)||w.push({path:R,type:"delete"});let b=new Map(d.map(R=>[R.path,R])),y=[],C=[];for(let R of w){let O=b.get(R.path),$=I(e.workTree,R.path);if(O){if(Jt(O.mode)||!await e.fs.exists($))continue;await Ot(e,$,O.hash)!==O.hash&&y.push(R.path)}else R.type==="checkout"&&await e.fs.exists($)&&C.push(R.path)}if(y.length>0||C.length>0){y.sort(Zc),C.sort(Zc);let R="";if(y.length>0&&(R+=`error: Your local changes to the following files would be overwritten by merge: ++${y.map(O=>` ${O}`).join(` + `)} + Please commit your changes or stash them before you merge. +-`),C.length>0&&(E+=`error: The following untracked working tree files would be overwritten by merge: ++`),C.length>0&&(R+=`error: The following untracked working tree files would be overwritten by merge: + ${C.map(O=>` ${O}`).join(` + `)} + Please move or remove them before you merge. +-`),E+=`Aborting +-`,l){let O=await Fc(e,l);O.ok||(E+=O.stderr)}return{ok:!1,stdout:"",stderr:E,exitCode:1}}await je(e,w);let x=new Set(h.conflicts.map(E=>E.path)),y=new Set;for(let E of h.entries)E.stage>0&&y.add(E.path);let P=x.size>0;if(P){let E=[];for(let[O,$]of g){if(x.has(O)||y.has(O))continue;let T=b.get(O);E.push({path:O,mode:parseInt($.mode,8),hash:$.hash,stage:0,stat:T?.stat??Fe()})}for(let O of h.entries)O.stage>0&&E.push(O);E.sort((O,$)=>Te(O.path,$.path)||O.stage-$.stage),await ie(e,{version:2,entries:E})}else{let E=[...s.entries],O=new Set(E.map($=>$.path));for(let[$,T]of g)p.has($)||O.has($)||E.push({path:$,mode:parseInt(T.mode,8),hash:T.hash,stage:0,stat:Fe()});E.sort(($,T)=>Te($.path,T.path)||$.stage-T.stage),await ie(e,{version:2,entries:E})}let k=n?.quiet?[]:h.messages;if(l){let E=await Fc(e,l);if(!E.ok)return{...E,messages:k}}return{ok:!0,hasConflicts:P,messages:k}}async function _c(e,t=0){let n=await vt(e,yn);if(n.length===0)return`error: stash@{${t}} is not a valid reference`;let r=n.length-1-t;if(r<0||r>=n.length)return`error: stash@{${t}} is not a valid reference`;if(n.splice(r,1),n.length===0)await ke(e,yn),await js(e,yn);else{await ns(e,yn,n);let o=n[n.length-1];o&&await Q(e,yn,o.newHash)}return null}async function Dm(e){await ke(e,yn),await js(e,yn)}De();Ee();function Ui(e){if(e===void 0)return 0;let t=e.match(/^(?:stash@\{)?(\d+)\}?$/);if(t?.[1]!==void 0)return parseInt(t[1],10);let n=parseInt(e,10);return!Number.isNaN(n)&&n>=0?n:-1}async function r0(e,t){let n=t.oldHash?await le(e,t.oldHash):"",r=t.newHash?await le(e,t.newHash):"";return Wt({path:t.path,oldContent:n,newContent:r,oldMode:t.oldMode,newMode:t.newMode})}function jm(e,t){let n=e.command("stash",{description:"Stash the changes in a dirty working directory away",args:[W.string().name("args").variadic().optional()],options:{message:K.string().alias("m").describe("Stash message"),"include-untracked":S().alias("u").describe("Also stash untracked files"),quiet:ce("quiet mode")},transformArgs:r=>{if(r[0]!=="save")return r;let o=r.slice(1),s=[],i=[];for(let a of o)a.startsWith("-")?s.push(a):i.push(a);return i.length>0?[...s,"-m",i.join(" ")]:s},handler:async(r,o)=>{let s=await q(o.fs,o.cwd,t);if(D(s))return s;let i=r.args[0];return i!==void 0?v(`subcommand wasn't specified; 'push' can't be assumed due to unexpected token '${i}'`):Mm(s,o.env,r.message,r["include-untracked"],r.quiet)}});n.command("push",{description:"Save your local modifications to a new stash entry",options:{message:K.string().alias("m").describe("Stash message"),"include-untracked":S().alias("u").describe("Also stash untracked files"),quiet:ce("quiet mode")},handler:async(r,o)=>{let s=await q(o.fs,o.cwd,t);return D(s)?s:Mm(s,o.env,r.message,r["include-untracked"],r.quiet)}}),n.command("pop",{description:"Remove a single stash entry and apply it on top of the current working tree",args:[W.string().name("stash").describe("Stash reference (e.g. stash@{0})").optional()],options:{quiet:ce("be quiet, only report errors")},handler:async(r,o)=>{let s=await q(o.fs,o.cwd,t);return D(s)?s:s0(s,r.stash,r.quiet)}}),n.command("apply",{description:"Apply a stash entry on top of the current working tree",args:[W.string().name("stash").describe("Stash reference (e.g. stash@{0})").optional()],options:{quiet:ce("be quiet, only report errors")},handler:async(r,o)=>{let s=await q(o.fs,o.cwd,t);return D(s)?s:o0(s,r.stash,r.quiet)}}),n.command("list",{description:"List the stash entries that you currently have",handler:async(r,o)=>{let s=await q(o.fs,o.cwd,t);return D(s)?s:i0(s)}}),n.command("drop",{description:"Remove a single stash entry from the list of stash entries",args:[W.string().name("stash").describe("Stash reference (e.g. stash@{0})").optional()],options:{quiet:ce("be quiet, only report errors")},handler:async(r,o)=>{let s=await q(o.fs,o.cwd,t);return D(s)?s:a0(s,r.stash,r.quiet)}}),n.command("show",{description:"Show the changes recorded in a stash entry as a diff",options:{patch:S().alias("p").describe("Show full diff (default is --stat)")},args:[W.string().name("stash").describe("Stash reference (e.g. stash@{0})").optional()],handler:async(r,o)=>{let s=await q(o.fs,o.cwd,t);return D(s)?s:c0(s,r.stash,r.patch)}}),n.command("clear",{description:"Remove all the stash entries",handler:async(r,o)=>{let s=await q(o.fs,o.cwd,t);return D(s)?s:f0(s)}})}async function Mm(e,t,n,r,o){if(!await Z(e))return F(`You do not have the initial commit yet +-`);let i=await X(e),a=fn(i).sort();if(a.length>0)return{stdout:`${a.map(d=>`${d}: needs merge`).join(` ++`),R+=`Aborting ++`,l){let O=await Xc(e,l);O.ok||(R+=O.stderr)}return{ok:!1,stdout:"",stderr:R,exitCode:1}}await Me(e,w);let x=new Set(h.conflicts.map(R=>R.path)),k=new Set;for(let R of h.entries)R.stage>0&&k.add(R.path);let P=x.size>0;if(P){let R=[];for(let[O,$]of g){if(x.has(O)||k.has(O))continue;let T=b.get(O);R.push({path:O,mode:parseInt($.mode,8),hash:$.hash,stage:0,stat:T?.stat??Ge()})}for(let O of h.entries)O.stage>0&&R.push(O);R.sort((O,$)=>Ae(O.path,$.path)||O.stage-$.stage),await oe(e,{version:2,entries:R})}else{let R=[...o.entries],O=new Set(R.map($=>$.path));for(let[$,T]of g)p.has($)||O.has($)||R.push({path:$,mode:parseInt(T.mode,8),hash:T.hash,stage:0,stat:Ge()});R.sort(($,T)=>Ae($.path,T.path)||$.stage-T.stage),await oe(e,{version:2,entries:R})}let E=n?.quiet?[]:h.messages;if(l){let R=await Xc(e,l);if(!R.ok)return{...R,messages:E}}return{ok:!0,hasConflicts:P,messages:E}}async function Jc(e,t=0){let n=await Tt(e,Cn);if(n.length===0)return`error: stash@{${t}} is not a valid reference`;let r=n.length-1-t;if(r<0||r>=n.length)return`error: stash@{${t}} is not a valid reference`;if(n.splice(r,1),n.length===0)await Ee(e,Cn),await Us(e,Cn);else{await os(e,Cn,n);let s=n[n.length-1];s&&await Q(e,Cn,s.newHash)}return null}async function Xm(e){await Ee(e,Cn),await Us(e,Cn)}Te();ke();function Zi(e){if(e===void 0)return 0;let t=e.match(/^(?:stash@\{)?(\d+)\}?$/);if(t?.[1]!==void 0)return parseInt(t[1],10);let n=parseInt(e,10);return!Number.isNaN(n)&&n>=0?n:-1}async function D0(e,t){let n=t.oldHash?await le(e,t.oldHash):"",r=t.newHash?await le(e,t.newHash):"";return Kt({path:t.path,oldContent:n,newContent:r,oldMode:t.oldMode,newMode:t.newMode})}function Qm(e,t){let n=e.command("stash",{description:"Stash the changes in a dirty working directory away",args:[B.string().name("args").variadic().optional()],options:{message:K.string().alias("m").describe("Stash message"),"include-untracked":S().alias("u").describe("Also stash untracked files"),quiet:ce("quiet mode")},transformArgs:r=>{if(r[0]!=="save")return r;let s=r.slice(1),o=[],i=[];for(let a of s)a.startsWith("-")?o.push(a):i.push(a);return i.length>0?[...o,"-m",i.join(" ")]:o},handler:async(r,s)=>{let o=await W(s.fs,s.cwd,t);if(D(o))return o;let i=r.args[0];return i!==void 0?v(`subcommand wasn't specified; 'push' can't be assumed due to unexpected token '${i}'`):Zm(o,s.env,r.message,r["include-untracked"],r.quiet)}});n.command("push",{description:"Save your local modifications to a new stash entry",options:{message:K.string().alias("m").describe("Stash message"),"include-untracked":S().alias("u").describe("Also stash untracked files"),quiet:ce("quiet mode")},handler:async(r,s)=>{let o=await W(s.fs,s.cwd,t);return D(o)?o:Zm(o,s.env,r.message,r["include-untracked"],r.quiet)}}),n.command("pop",{description:"Remove a single stash entry and apply it on top of the current working tree",args:[B.string().name("stash").describe("Stash reference (e.g. stash@{0})").optional()],options:{quiet:ce("be quiet, only report errors")},handler:async(r,s)=>{let o=await W(s.fs,s.cwd,t);return D(o)?o:M0(o,r.stash,r.quiet)}}),n.command("apply",{description:"Apply a stash entry on top of the current working tree",args:[B.string().name("stash").describe("Stash reference (e.g. stash@{0})").optional()],options:{quiet:ce("be quiet, only report errors")},handler:async(r,s)=>{let o=await W(s.fs,s.cwd,t);return D(o)?o:j0(o,r.stash,r.quiet)}}),n.command("list",{description:"List the stash entries that you currently have",handler:async(r,s)=>{let o=await W(s.fs,s.cwd,t);return D(o)?o:L0(o)}}),n.command("drop",{description:"Remove a single stash entry from the list of stash entries",args:[B.string().name("stash").describe("Stash reference (e.g. stash@{0})").optional()],options:{quiet:ce("be quiet, only report errors")},handler:async(r,s)=>{let o=await W(s.fs,s.cwd,t);return D(o)?o:G0(o,r.stash,r.quiet)}}),n.command("show",{description:"Show the changes recorded in a stash entry as a diff",options:{patch:S().alias("p").describe("Show full diff (default is --stat)")},args:[B.string().name("stash").describe("Stash reference (e.g. stash@{0})").optional()],handler:async(r,s)=>{let o=await W(s.fs,s.cwd,t);return D(o)?o:F0(o,r.stash,r.patch)}}),n.command("clear",{description:"Remove all the stash entries",handler:async(r,s)=>{let o=await W(s.fs,s.cwd,t);return D(o)?o:N0(o)}})}async function Zm(e,t,n,r,s){if(!await Z(e))return N(`You do not have the initial commit yet ++`);let i=await X(e),a=mn(i).sort();if(a.length>0)return{stdout:`${a.map(d=>`${d}: needs merge`).join(` + `)} + `,stderr:`error: could not write index +-`,exitCode:1};let c;try{c=await Hm(e,t,n,{includeUntracked:r})}catch(d){return v(d.message)}return o?{stdout:"",stderr:"",exitCode:0}:c?{stdout:`Saved working directory and index state ${(await M(e,c)).message.trim()} ++`,exitCode:1};let c;try{c=await Ym(e,t,n,{includeUntracked:r})}catch(d){return v(d.message)}return s?{stdout:"",stderr:"",exitCode:0}:c?{stdout:`Saved working directory and index state ${(await M(e,c)).message.trim()} + `,stderr:"",exitCode:0}:{stdout:`No local changes to save +-`,stderr:"",exitCode:0}}async function s0(e,t,n){let r=Ui(t);if(r<0)return F(`error: '${t}' is not a valid stash reference`);let o=await ys(e,r);if(!o)return F(`error: stash@{${r}} is not a valid reference`);let s=await Uc(e,r,{quiet:n});if(!s.ok){let l=s.messages?.length?`${s.messages.join(` ++`,stderr:"",exitCode:0}}async function M0(e,t,n){let r=Zi(t);if(r<0)return N(`error: '${t}' is not a valid stash reference`);let s=await Cs(e,r);if(!s)return N(`error: stash@{${r}} is not a valid reference`);let o=await Qc(e,r,{quiet:n});if(!o.ok){let l=o.messages?.length?`${o.messages.join(` + `)} +-`:"";if(s.stdout)return{stdout:`${l}${s.stdout}The stash entry is kept in case you need it again. +-`,stderr:s.stderr,exitCode:s.exitCode};let d=n?"":await pt(e);return{stdout:`${l}${d}The stash entry is kept in case you need it again. +-`,stderr:s.stderr,exitCode:s.exitCode}}if(s.hasConflicts){let l=s.messages.length>0?`${s.messages.join(` ++`:"";if(o.stdout)return{stdout:`${l}${o.stdout}The stash entry is kept in case you need it again. ++`,stderr:o.stderr,exitCode:o.exitCode};let d=n?"":await yt(e);return{stdout:`${l}${d}The stash entry is kept in case you need it again. ++`,stderr:o.stderr,exitCode:o.exitCode}}if(o.hasConflicts){let l=o.messages.length>0?`${o.messages.join(` + `)} +-`:"",d=n?"":await pt(e);return{stdout:`${l}${d}The stash entry is kept in case you need it again. +-`,stderr:"",exitCode:1}}let i=await _c(e,r);if(i)return F(i);let a=s.messages.length>0?`${s.messages.join(` ++`:"",d=n?"":await yt(e);return{stdout:`${l}${d}The stash entry is kept in case you need it again. ++`,stderr:"",exitCode:1}}let i=await Jc(e,r);if(i)return N(i);let a=o.messages.length>0?`${o.messages.join(` + `)} +-`:"";if(n)return{stdout:a,stderr:"",exitCode:0};let c=t?`stash@{${r}}`:`refs/stash@{${r}}`,f=await pt(e);return{stdout:`${a}${f}Dropped ${c} (${o}) +-`,stderr:"",exitCode:0}}async function o0(e,t,n){let r=Ui(t);if(r<0)return F(`error: '${t}' is not a valid stash reference`);let o=await Uc(e,r,{quiet:n});if(!o.ok){let c=o.messages?.length?`${o.messages.join(` ++`:"";if(n)return{stdout:a,stderr:"",exitCode:0};let c=t?`stash@{${r}}`:`refs/stash@{${r}}`,f=await yt(e);return{stdout:`${a}${f}Dropped ${c} (${s}) ++`,stderr:"",exitCode:0}}async function j0(e,t,n){let r=Zi(t);if(r<0)return N(`error: '${t}' is not a valid stash reference`);let s=await Qc(e,r,{quiet:n});if(!s.ok){let c=s.messages?.length?`${s.messages.join(` + `)} +-`:"",f=o.stdout;return!f&&!n&&(f=await pt(e)),{stdout:`${c}${f}`,stderr:o.stderr,exitCode:o.exitCode}}let s=o.messages.length>0?`${o.messages.join(` ++`:"",f=s.stdout;return!f&&!n&&(f=await yt(e)),{stdout:`${c}${f}`,stderr:s.stderr,exitCode:s.exitCode}}let o=s.messages.length>0?`${s.messages.join(` + `)} +-`:"",i=n?"":await pt(e),a=o.hasConflicts?1:0;return{stdout:`${s}${i}`,stderr:"",exitCode:a}}async function i0(e){let t=await Am(e);return t.length===0?{stdout:"",stderr:"",exitCode:0}:{stdout:`${t.map(r=>`stash@{${r.index}}: ${r.message}`).join(` ++`:"",i=n?"":await yt(e),a=s.hasConflicts?1:0;return{stdout:`${o}${i}`,stderr:"",exitCode:a}}async function L0(e){let t=await Vm(e);return t.length===0?{stdout:"",stderr:"",exitCode:0}:{stdout:`${t.map(r=>`stash@{${r.index}}: ${r.message}`).join(` + `)} +-`,stderr:"",exitCode:0}}async function a0(e,t,n){let r=Ui(t);if(r<0)return F(`error: '${t}' is not a valid stash reference`);let o=await ys(e,r);if(!o)return F(`error: stash@{${r}} is not a valid reference`);let s=await _c(e,r);return s?F(s):n?{stdout:"",stderr:"",exitCode:0}:{stdout:`Dropped ${t?`stash@{${r}}`:`refs/stash@{${r}}`} (${o}) +-`,stderr:"",exitCode:0}}async function c0(e,t,n){let r=Ui(t);if(r<0)return F(`error: '${t}' is not a valid stash reference`);let o=await ys(e,r);if(!o)return F(`error: stash@{${r}} is not a valid reference`);let s=await M(e,o),i=s.parents[0];if(!i)return F("error: invalid stash commit (no parent)");let a=await M(e,i);if(n){let f=await Ke(e,a.tree,s.tree),l="";for(let d of f)l+=await r0(e,d);return{stdout:l,stderr:"",exitCode:0}}return{stdout:await Tn(e,a.tree,s.tree),stderr:"",exitCode:0}}async function f0(e){return await Dm(e),{stdout:"",stderr:"",exitCode:0}}ne();Be();ve();ye();st();Ee();function Lm(e,t){e.command("status",{description:"Show the working tree status",options:{short:S().alias("s").describe("Give the output in the short-format"),porcelain:S().describe("Give the output in a machine-parseable format"),branch:S().alias("b").describe("Show the branch in short-format output"),untrackedFiles:K.string().alias("u").impliedValue("all").describe("Show untracked files: no, normal (default), or all (bare -u means all)")},handler:async(n,r)=>{let o=n.untrackedFiles??"normal";if(o!=="no"&&o!=="normal"&&o!=="all")return F(`fatal: Invalid untracked files mode '${n.untrackedFiles}' +-`,128);let s=await q(r.fs,r.cwd,t);if(D(s))return s;let i=s;if(!n.short&&!n.porcelain)return{stdout:await pt(i,{untrackedMode:o}),stderr:"",exitCode:0};let a=await te(i),c=await Z(i),f,l=null;if(a&&a.type==="symbolic"){if(f=Ie(a.target),n.branch){let C=await we(i),x=await nn(i,C,f);l=h0(f,x)}}else f="HEAD detached",n.branch&&(l="## HEAD (no branch)");let d=await X(i),u=Ja(d),m=await Qa(i,c,d,u),h=await dt(i,d,{includeUntracked:o!=="no"}),p=[],g=[];for(let C of h)C.status==="untracked"?g.push(C.path):p.push({path:C.path,status:C.status});p.sort((C,x)=>Te(C.path,x.path));let w=new Set(d.entries.map(C=>C.path)),b=o==="no"?[]:o==="all"?[...g].sort(Te):ec(g,w);return{stdout:m0(l,m,p,u,b),stderr:"",exitCode:0}}})}var l0={"both modified":"UU","both added":"AA","both deleted":"DD","deleted by us":"DU","deleted by them":"UD","added by us":"AU","added by them":"UA",unmerged:"UU"};function d0(e){switch(e){case"new file":return"A";case"modified":return"M";case"deleted":return"D";case"renamed":return"R";default:return" "}}function u0(e){switch(e){case"modified":return"M";case"deleted":return"D";default:return" "}}function m0(e,t,n,r,o){let s=[];e&&s.push(e);let i=new Map(r.map(d=>[d.path,d])),a=new Map(t.map(d=>[d.path,d])),c=new Map(n.map(d=>[d.path,d])),f=new Set;for(let d of r)f.add(d.path);for(let d of t)f.add(d.path);for(let d of n)f.add(d.path);let l=[...f].sort();for(let d of l){let u=i.get(d);if(u){let w=l0[u.status]??"UU";s.push(`${w} ${lo(d)}`);continue}let m=a.get(d),h=c.get(d),p=m?d0(m.status):" ",g=h?u0(h.status):" ";if(m?.status==="renamed"&&m.displayPath){let w=m.displayPath.indexOf(" -> "),b=m.displayPath.slice(0,w),R=m.displayPath.slice(w+4);s.push(`${p}${g} ${lo(b)} -> ${lo(R)}`)}else s.push(`${p}${g} ${lo(d)}`)}for(let d of o)s.push(`?? ${lo(d)}`);return s.length===0?"":`${s.join(` ++`,stderr:"",exitCode:0}}async function G0(e,t,n){let r=Zi(t);if(r<0)return N(`error: '${t}' is not a valid stash reference`);let s=await Cs(e,r);if(!s)return N(`error: stash@{${r}} is not a valid reference`);let o=await Jc(e,r);return o?N(o):n?{stdout:"",stderr:"",exitCode:0}:{stdout:`Dropped ${t?`stash@{${r}}`:`refs/stash@{${r}}`} (${s}) ++`,stderr:"",exitCode:0}}async function F0(e,t,n){let r=Zi(t);if(r<0)return N(`error: '${t}' is not a valid stash reference`);let s=await Cs(e,r);if(!s)return N(`error: stash@{${r}} is not a valid reference`);let o=await M(e,s),i=o.parents[0];if(!i)return N("error: invalid stash commit (no parent)");let a=await M(e,i);if(n){let f=await Ve(e,a.tree,o.tree),l="";for(let d of f)l+=await D0(e,d);return{stdout:l,stderr:"",exitCode:0}}return{stdout:await Mn(e,a.tree,o.tree),stderr:"",exitCode:0}}async function N0(e){return await Xm(e),{stdout:"",stderr:"",exitCode:0}}te();We();Se();ye();ot();ke();function Jm(e,t){e.command("status",{description:"Show the working tree status",options:{short:S().alias("s").describe("Give the output in the short-format"),porcelain:S().describe("Give the output in a machine-parseable format"),branch:S().alias("b").describe("Show the branch in short-format output"),untrackedFiles:K.string().alias("u").impliedValue("all").describe("Show untracked files: no, normal (default), or all (bare -u means all)")},handler:async(n,r)=>{let s=n.untrackedFiles??"normal";if(s!=="no"&&s!=="normal"&&s!=="all")return N(`fatal: Invalid untracked files mode '${n.untrackedFiles}' ++`,128);let o=await W(r.fs,r.cwd,t);if(D(o))return o;let i=o;if(!n.short&&!n.porcelain)return{stdout:await yt(i,{untrackedMode:s}),stderr:"",exitCode:0};let a=await ne(i),c=await Z(i),f,l=null;if(a&&a.type==="symbolic"){if(f=ve(a.target),n.branch){let C=await be(i),x=await an(i,C,f);l=q0(f,x)}}else f="HEAD detached",n.branch&&(l="## HEAD (no branch)");let d=await X(i),u=cc(d),m=await ac(i,c,d,u),h=await pt(i,d,{includeUntracked:s!=="no"}),p=[],g=[];for(let C of h)C.status==="untracked"?g.push(C.path):p.push({path:C.path,status:C.status});p.sort((C,x)=>Ae(C.path,x.path));let w=new Set(d.entries.map(C=>C.path)),b=s==="no"?[]:s==="all"?[...g].sort(Ae):fc(g,w);return{stdout:W0(l,m,p,u,b),stderr:"",exitCode:0}}})}var U0={"both modified":"UU","both added":"AA","both deleted":"DD","deleted by us":"DU","deleted by them":"UD","added by us":"AU","added by them":"UA",unmerged:"UU"};function _0(e){switch(e){case"new file":return"A";case"modified":return"M";case"deleted":return"D";case"renamed":return"R";default:return" "}}function B0(e){switch(e){case"modified":return"M";case"deleted":return"D";default:return" "}}function W0(e,t,n,r,s){let o=[];e&&o.push(e);let i=new Map(r.map(d=>[d.path,d])),a=new Map(t.map(d=>[d.path,d])),c=new Map(n.map(d=>[d.path,d])),f=new Set;for(let d of r)f.add(d.path);for(let d of t)f.add(d.path);for(let d of n)f.add(d.path);let l=[...f].sort();for(let d of l){let u=i.get(d);if(u){let w=U0[u.status]??"UU";o.push(`${w} ${yo(d)}`);continue}let m=a.get(d),h=c.get(d),p=m?_0(m.status):" ",g=h?B0(h.status):" ";if(m?.status==="renamed"&&m.displayPath){let w=m.displayPath.indexOf(" -> "),b=m.displayPath.slice(0,w),y=m.displayPath.slice(w+4);o.push(`${p}${g} ${yo(b)} -> ${yo(y)}`)}else o.push(`${p}${g} ${yo(d)}`)}for(let d of s)o.push(`?? ${yo(d)}`);return o.length===0?"":`${o.join(` + `)} +-`}function h0(e,t){if(!t)return`## ${e}`;let n=`## ${e}...${t.upstream}`,r=ri(t,!1);return r?`${n} ${r}`:n}function lo(e){return!/[ \t"\\]/.test(e)&&!/[^\x20-\x7E]/.test(e)?e:`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\t/g,"\\t").replace(/\n/g,"\\n")}"`}ne();Be();ve();ae();Ve();ye();De();Jt();Ee();function p0(e,t){return e?.type==="symbolic"?e.target.replace(/^refs\/heads\//,""):t??oe}function Fm(e,t){e.command("switch",{description:"Switch branches",args:[W.string().name("branch-or-start-point").describe("Branch to switch to, or start-point for -c/-C").optional()],options:{create:K.string().alias("c").describe("Create and switch to a new branch"),forceCreate:K.string().alias("C").describe("Create/reset and switch to a branch"),detach:S().alias("d").describe("Detach HEAD at named commit"),orphan:K.string().describe("Create a new orphan branch"),guess:S().default(!0).describe("Guess branch from remote tracking"),ignoreOtherWorktrees:S().describe("Allow checking out a branch used by another worktree"),quiet:ce("suppress progress reporting")},handler:async(n,r,o)=>{let s=await q(r.fs,r.cwd,t);if(D(s))return s;let i=s,a=n["branch-or-start-point"],c=!!n.quiet;if(n.orphan)return n.create||n.forceCreate?v("--orphan and -c/-C are incompatible"):n.detach?v("--orphan and --detach are incompatible"):b0(i,n.orphan,r.env,t,c);if(n.detach){if(n.create||n.forceCreate)return v("--detach and -c/-C are incompatible");let d=a??"HEAD",u=await Ge(i,d,`invalid reference: ${d}`);return D(u)?u:w0(i,d,u.hash,r.env,t,c)}if(n.create||n.forceCreate){let d=n.create||n.forceCreate,u=a??(o.passthrough.length>0?o.passthrough[0]:void 0);return Gm(i,d,!!n.forceCreate,u,r.env,t,void 0,!!n.ignoreOtherWorktrees,c)}if(!a)return v("missing branch or commit argument");if(a==="-")return g0(i,r.env,t,c);let f=`refs/heads/${a}`,l=await z(i,f);if(l)return Nm(i,a,f,l,r.env,t,!!n.ignoreOtherWorktrees,c);if(n.guess!==!1){let d=await fs(i,a);if(d)return Gm(i,a,!1,d.startPoint,r.env,t,d.trackingRef,!1,c)}return v(`invalid reference: ${a}`)}})}async function _i(e){return await Ae(e,"CHERRY_PICK_HEAD")?v(`cannot switch branch while cherry-picking +-Consider "git cherry-pick --quit" or "git worktree add".`):await Ae(e,"MERGE_HEAD")?v(`cannot switch branch while merging +-Consider "git merge --quit" or "git worktree add".`):await Ae(e,"REVERT_HEAD")?v(`cannot switch branch while reverting +-Consider "git revert --quit" or "git worktree add".`):await wn(e)?v(`cannot switch branch while rebasing +-Consider "git rebase --quit" or "git worktree add".`):null}async function g0(e,t,n,r=!1){let o=await tc(e);return o?o.kind==="commit"?{stdout:"",stderr:`fatal: a branch is expected, got commit '${o.target}' ++`}function q0(e,t){if(!t)return`## ${e}`;let n=`## ${e}...${t.upstream}`,r=mi(t,!1);return r?`${n} ${r}`:n}function yo(e){return!/[ \t"\\]/.test(e)&&!/[^\x20-\x7E]/.test(e)?e:`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\t/g,"\\t").replace(/\n/g,"\\n")}"`}te();We();Se();ie();Xe();ye();Te();rn();ke();function z0(e,t){return e?.type==="symbolic"?e.target.replace(/^refs\/heads\//,""):t??se}function th(e,t){e.command("switch",{description:"Switch branches",args:[B.string().name("branch-or-start-point").describe("Branch to switch to, or start-point for -c/-C").optional()],options:{create:K.string().alias("c").describe("Create and switch to a new branch"),forceCreate:K.string().alias("C").describe("Create/reset and switch to a branch"),detach:S().alias("d").describe("Detach HEAD at named commit"),orphan:K.string().describe("Create a new orphan branch"),guess:S().default(!0).describe("Guess branch from remote tracking"),ignoreOtherWorktrees:S().describe("Allow checking out a branch used by another worktree"),quiet:ce("suppress progress reporting")},handler:async(n,r,s)=>{let o=await W(r.fs,r.cwd,t);if(D(o))return o;let i=o,a=n["branch-or-start-point"],c=!!n.quiet;if(n.orphan)return n.create||n.forceCreate?v("--orphan and -c/-C are incompatible"):n.detach?v("--orphan and --detach are incompatible"):Y0(i,n.orphan,r.env,t,c);if(n.detach){if(n.create||n.forceCreate)return v("--detach and -c/-C are incompatible");let d=a??"HEAD",u=await Le(i,d,`invalid reference: ${d}`);return D(u)?u:V0(i,d,u.hash,r.env,t,c)}if(n.create||n.forceCreate){let d=n.create||n.forceCreate,u=a??(s.passthrough.length>0?s.passthrough[0]:void 0);return eh(i,d,!!n.forceCreate,u,r.env,t,void 0,!!n.ignoreOtherWorktrees,c)}if(!a)return v("missing branch or commit argument");if(a==="-")return K0(i,r.env,t,c);let f=`refs/heads/${a}`,l=await z(i,f);if(l)return nh(i,a,f,l,r.env,t,!!n.ignoreOtherWorktrees,c);if(n.guess!==!1){let d=await us(i,a);if(d)return eh(i,a,!1,d.startPoint,r.env,t,d.trackingRef,!1,c)}return v(`invalid reference: ${a}`)}})}async function Qi(e){return await He(e,"CHERRY_PICK_HEAD")?v(`cannot switch branch while cherry-picking ++Consider "git cherry-pick --quit" or "git worktree add".`):await He(e,"MERGE_HEAD")?v(`cannot switch branch while merging ++Consider "git merge --quit" or "git worktree add".`):await He(e,"REVERT_HEAD")?v(`cannot switch branch while reverting ++Consider "git revert --quit" or "git worktree add".`):await En(e)?v(`cannot switch branch while rebasing ++Consider "git rebase --quit" or "git worktree add".`):null}async function K0(e,t,n,r=!1){let s=await lc(e);return s?s.kind==="commit"?{stdout:"",stderr:`fatal: a branch is expected, got commit '${s.target}' + hint: If you want to detach HEAD at the commit, try again with the --detach option. +-`,exitCode:128}:Nm(e,o.name,o.refName,o.hash,t,n,!1,r):v("invalid reference: @{-1}")}async function Gm(e,t,n,r,o,s,i,a=!1,c=!1){if(!Ln(t))return v(`'${t}' is not a valid branch name`);let f=`refs/heads/${t}`,l=await z(e,f);if(l&&!n)return v(`a branch named '${t}' already exists`);let d;if(r){let $=await Ge(e,r,`invalid reference: ${r}`);if(D($))return $;d=$.hash}else{let $=await Z(e);if(!$){let T=await te(e),j=T?.type==="symbolic"?T.target.replace(/^refs\/heads\//,""):"";n&&l&&await ke(e,f),await ot(e,"HEAD",f),await Tt(e);let U=await Wn(e,c);return await ee(e,o,"HEAD",null,oe,`checkout: moving from ${j} to ${t}`),{stdout:"",stderr:c?"":`Switched to a new branch '${t}' +-${U}`,exitCode:0}}d=$}let u=await _i(e);if(u)return u;if(l&&!a){let $=await Hn(e,f,e.gitDir);if($)return v(`'${t}' is already used by worktree at '${$}'`)}let m=await s?.hooks?.preCheckout?.({repo:e,target:t,mode:"create-branch"});if(he(m))return{stdout:"",stderr:m.message??"",exitCode:1};let h=await Z(e),p=await X(e);if(r){let $=mr(p);if($)return $}let g=await M(e,d);if(h&&h!==d){let $=await M(e,h);if($.tree!==g.tree){let T=await On(e,$.tree,g.tree,p);if(!T.success)return T.errorOutput??F("error: checkout would overwrite local changes");p={version:2,entries:T.newEntries},await ie(e,p),await je(e,T.worktreeOps)}}let w=await te(e),b="";!c&&w?.type==="direct"&&h&&(b=await ii(e,h,d));let R=p0(w,h);await Q(e,f,d),await ot(e,"HEAD",f),await Tt(e);let C=await Wn(e,c),x=r??"HEAD";n&&l?l!==d&&await ee(e,o,f,l,d,`branch: Reset to ${x}`):await ee(e,o,f,null,d,`branch: Created from ${x}`),await ee(e,o,"HEAD",h,d,`checkout: moving from ${R} to ${t}`);let y="";if(i){let $=i.replace(/^refs\/remotes\//,"").split("/"),T=$[0]??"",j=`refs/heads/${$.slice(1).join("/")}`,U=await we(e);U[`branch "${t}"`]={...U[`branch "${t}"`],remote:T,merge:j},await et(e,U),y=`branch '${t}' set up to track '${T}/${$.slice(1).join("/")}'. +-`}else r&&(y=await cs(e,t,r));if(await s?.hooks?.postCheckout?.({repo:e,prevHead:h,newHead:d,isBranchCheckout:!0}),c)return{stdout:"",stderr:"",exitCode:0};let P=w?.type==="symbolic"&&w.target===f,k=n&&l?P?`Reset branch '${t}' ++`,exitCode:128}:nh(e,s.name,s.refName,s.hash,t,n,!1,r):v("invalid reference: @{-1}")}async function eh(e,t,n,r,s,o,i,a=!1,c=!1){if(!Fn(t))return v(`'${t}' is not a valid branch name`);let f=`refs/heads/${t}`,l=await z(e,f);if(l&&!n)return v(`a branch named '${t}' already exists`);let d;if(r){let $=await Le(e,r,`invalid reference: ${r}`);if(D($))return $;d=$.hash}else{let $=await Z(e);if(!$){let T=await ne(e),j=T?.type==="symbolic"?T.target.replace(/^refs\/heads\//,""):"";n&&l&&await Ee(e,f),await ct(e,"HEAD",f),await Ht(e);let U=await qn(e,c);return await ee(e,s,"HEAD",null,se,`checkout: moving from ${j} to ${t}`),{stdout:"",stderr:c?"":`Switched to a new branch '${t}' ++${U}`,exitCode:0}}d=$}let u=await Qi(e);if(u)return u;if(l&&!a){let $=await Ln(e,f,e.gitDir);if($)return v(`'${t}' is already used by worktree at '${$}'`)}let m=await o?.hooks?.preCheckout?.({repo:e,target:t,mode:"create-branch"});if(pe(m))return{stdout:"",stderr:m.message??"",exitCode:1};let h=await Z(e),p=await X(e);if(r){let $=mr(p);if($)return $}let g=await M(e,d);if(h&&h!==d){let $=await M(e,h);if($.tree!==g.tree){let T=await Tn(e,$.tree,g.tree,p);if(!T.success)return T.errorOutput??N("error: checkout would overwrite local changes");p={version:2,entries:T.newEntries},await oe(e,p),await Me(e,T.worktreeOps)}}let w=await ne(e),b="";!c&&w?.type==="direct"&&h&&(b=await gi(e,h,d));let y=z0(w,h);await Q(e,f,d),await ct(e,"HEAD",f),await Ht(e);let C=await qn(e,c),x=r??"HEAD";n&&l?l!==d&&await ee(e,s,f,l,d,`branch: Reset to ${x}`):await ee(e,s,f,null,d,`branch: Created from ${x}`),await ee(e,s,"HEAD",h,d,`checkout: moving from ${y} to ${t}`);let k="";if(i){let $=i.replace(/^refs\/remotes\//,"").split("/"),T=$[0]??"",j=`refs/heads/${$.slice(1).join("/")}`,U=await be(e);U[`branch "${t}"`]={...U[`branch "${t}"`],remote:T,merge:j},await et(e,U),k=`branch '${t}' set up to track '${T}/${$.slice(1).join("/")}'. ++`}else r&&(k=await ds(e,t,r));if(await o?.hooks?.postCheckout?.({repo:e,prevHead:h,newHead:d,isBranchCheckout:!0}),c)return{stdout:"",stderr:"",exitCode:0};let P=w?.type==="symbolic"&&w.target===f,E=n&&l?P?`Reset branch '${t}' + `:`Switched to and reset branch '${t}' + `:`Switched to a new branch '${t}' +-`,E=b+k+C,O="";if(y)O=await hr(e,g.tree,p)+y;else if(r){O=await hr(e,g.tree,p);let $=await we(e),T=await nn(e,$,t);T&&(O+=ur(T))}else if(n&&l){let $=await we(e),T=await nn(e,$,t);T&&(O=ur(T))}return{stdout:O,stderr:E,exitCode:0}}async function Nm(e,t,n,r,o,s,i=!1,a=!1){let c=await _i(e);if(c)return c;if(!i){let l=await Hn(e,n,e.gitDir);if(l)return v(`'${t}' is already used by worktree at '${l}'`)}let f=await s?.hooks?.preCheckout?.({repo:e,target:t,mode:"switch"});return he(f)?{stdout:"",stderr:f.message??"",exitCode:1}:Mr(e,t,n,r,o,s,{quiet:a})}async function w0(e,t,n,r,o,s=!1){let i=await _i(e);if(i)return i;let a=await o?.hooks?.preCheckout?.({repo:e,target:t,mode:"detach"});return he(a)?{stdout:"",stderr:a.message??"",exitCode:1}:pr(e,n,r,o,{quiet:s})}async function b0(e,t,n,r,o=!1){if(!Ln(t))return v(`'${t}' is not a valid branch name`);let s=await _i(e);if(s)return s;let i=`refs/heads/${t}`;if(await z(e,i))return v(`a branch named '${t}' already exists`);let c=await X(e),f=mr(c);if(f)return f;let l=await Z(e),d=await te(e),u="";if(!o&&d?.type==="direct"&&l&&(u=await rc(e,l)),e.workTree){let h=l?(await M(e,l)).tree:null,p=await Ye(e,[]),g=await On(e,h,p,c);if(!g.success)return g.errorOutput??F("error: checkout would overwrite local changes");await je(e,g.worktreeOps),await ie(e,{version:2,entries:g.newEntries})}else await ie(e,If());await ot(e,"HEAD",i),await Tt(e);let m=await Wn(e,o);return await r?.hooks?.postCheckout?.({repo:e,prevHead:l,newHead:oe,isBranchCheckout:!0}),{stdout:"",stderr:o?"":`${u}Switched to a new branch '${t}' +-${m}`,exitCode:0}}ne();ae();Jr();ye();Us();Ee();function _m(e,t){e.command("tag",{description:"Create, list, or delete tags",args:[W.string().name("name").describe("Tag name to create or delete").optional(),W.string().name("commit").describe("Commit to tag (defaults to HEAD)").optional()],options:{annotate:S().alias("a").describe("Make an annotated tag object"),message:K.string().alias("m").describe("Tag message"),delete:S().alias("d").describe("Delete a tag"),force:S().alias("f").describe("Replace an existing tag"),list:S().alias("l").describe("List tags matching pattern"),sort:K.string().describe("Sort order (e.g. creatordate, -creatordate, refname, -refname, version:refname, -version:refname)")},handler:async(n,r)=>{let o=await q(r.fs,r.cwd,t);if(D(o))return o;let s=o;if(n.delete){if(!n.name)return v("tag name required");let i=`refs/tags/${n.name}`,a=await z(s,i);return a?(await ke(s,i),{stdout:`Deleted tag '${n.name}' (was ${await ue(s,a)}) +-`,stderr:"",exitCode:0}):F(`error: tag '${n.name}' not found. +-`)}if(n.list)return Um(s,n.name||void 0,n.sort);if(n.name){if(!ul(n.name))return v(`'${n.name}' is not a valid tag name`);let i=n.commit,a;if(i){let m=await It(s,i,`Failed to resolve '${i}' as a valid ref.`);if(D(m))return m;a=m}else if(a=await Z(s),!a)return v("Failed to resolve 'HEAD' as a valid ref.");let c=`refs/tags/${n.name}`,f=await z(s,c);if(f&&!n.force)return v(`tag '${n.name}' already exists`);let l=n.annotate||n.message,d;if(l){if(!n.message)return v("no tag message specified (use -m)");let m=await ct(s,r.env);if(D(m))return m;let h=Nt(n.message),p=ll({type:"tag",object:a,objectType:"commit",name:n.name,tagger:m,message:h}),g=await Me(s,"tag",p);await Q(s,c,g),d=g}else await Q(s,c,a),d=a;return{stdout:f&&n.force&&f!==d?`Updated tag '${n.name}' (was ${await ue(s,f)}) +-`:"",stderr:"",exitCode:0}}return Um(s,void 0,n.sort)}})}async function Um(e,t,n){let r=await $e(e,"refs/tags");if(r.length===0)return{stdout:"",stderr:"",exitCode:0};let o=r.map(s=>({name:s.name.replace("refs/tags/",""),hash:s.hash}));if(t&&(o=o.filter(s=>xn(t,s.name,0)===0)),o.length===0)return{stdout:"",stderr:"",exitCode:0};if(n){let s=n.startsWith("-"),i=s?n.slice(1):n;if(i==="creatordate"){let a=await Promise.all(o.map(async c=>({...c,date:await y0(e,c.hash)})));a.sort((c,f)=>{let l=c.date-f.date;return l!==0?l:c.name.localeCompare(f.name)}),s&&a.reverse(),o=a}else i==="version:refname"||i==="v:refname"?(o.sort((a,c)=>k0(a.name,c.name)),s&&o.reverse()):i==="refname"&&(o.sort((a,c)=>a.name.localeCompare(c.name)),s&&o.reverse())}return{stdout:`${o.map(s=>s.name).join(` ++`,R=b+E+C,O="";if(k)O=await hr(e,g.tree,p)+k;else if(r){O=await hr(e,g.tree,p);let $=await be(e),T=await an(e,$,t);T&&(O+=ur(T))}else if(n&&l){let $=await be(e),T=await an(e,$,t);T&&(O=ur(T))}return{stdout:O,stderr:R,exitCode:0}}async function nh(e,t,n,r,s,o,i=!1,a=!1){let c=await Qi(e);if(c)return c;if(!i){let l=await Ln(e,n,e.gitDir);if(l)return v(`'${t}' is already used by worktree at '${l}'`)}let f=await o?.hooks?.preCheckout?.({repo:e,target:t,mode:"switch"});return pe(f)?{stdout:"",stderr:f.message??"",exitCode:1}:Fr(e,t,n,r,s,o,{quiet:a})}async function V0(e,t,n,r,s,o=!1){let i=await Qi(e);if(i)return i;let a=await s?.hooks?.preCheckout?.({repo:e,target:t,mode:"detach"});return pe(a)?{stdout:"",stderr:a.message??"",exitCode:1}:pr(e,n,r,s,{quiet:o})}async function Y0(e,t,n,r,s=!1){if(!Fn(t))return v(`'${t}' is not a valid branch name`);let o=await Qi(e);if(o)return o;let i=`refs/heads/${t}`;if(await z(e,i))return v(`a branch named '${t}' already exists`);let c=await X(e),f=mr(c);if(f)return f;let l=await Z(e),d=await ne(e),u="";if(!s&&d?.type==="direct"&&l&&(u=await uc(e,l)),e.workTree){let h=l?(await M(e,l)).tree:null,p=await Ze(e,[]),g=await Tn(e,h,p,c);if(!g.success)return g.errorOutput??N("error: checkout would overwrite local changes");await Me(e,g.worktreeOps),await oe(e,{version:2,entries:g.newEntries})}else await oe(e,Uf());await ct(e,"HEAD",i),await Ht(e);let m=await qn(e,s);return await r?.hooks?.postCheckout?.({repo:e,prevHead:l,newHead:se,isBranchCheckout:!0}),{stdout:"",stderr:s?"":`${u}Switched to a new branch '${t}' ++${m}`,exitCode:0}}te();ie();Ar();ye();Ks();ke();function sh(e,t){e.command("tag",{description:"Create, list, or delete tags",args:[B.string().name("name").describe("Tag name to create or delete").optional(),B.string().name("commit").describe("Commit to tag (defaults to HEAD)").optional()],options:{annotate:S().alias("a").describe("Make an annotated tag object"),message:K.string().alias("m").describe("Tag message"),delete:S().alias("d").describe("Delete a tag"),force:S().alias("f").describe("Replace an existing tag"),list:S().alias("l").describe("List tags matching pattern"),sort:K.string().describe("Sort order (e.g. creatordate, -creatordate, refname, -refname, version:refname, -version:refname)")},handler:async(n,r)=>{let s=await W(r.fs,r.cwd,t);if(D(s))return s;let o=s;if(n.delete){if(!n.name)return v("tag name required");let i=`refs/tags/${n.name}`,a=await z(o,i);return a?(await Ee(o,i),{stdout:`Deleted tag '${n.name}' (was ${await fe(o,a)}) ++`,stderr:"",exitCode:0}):N(`error: tag '${n.name}' not found. ++`)}if(n.list)return rh(o,n.name||void 0,n.sort);if(n.name){if(!Cl(n.name))return v(`'${n.name}' is not a valid tag name`);let i=n.commit,a;if(i){let m=await At(o,i,`Failed to resolve '${i}' as a valid ref.`);if(D(m))return m;a=m}else if(a=await Z(o),!a)return v("Failed to resolve 'HEAD' as a valid ref.");let c=`refs/tags/${n.name}`,f=await z(o,c);if(f&&!n.force)return v(`tag '${n.name}' already exists`);let l=n.annotate||n.message,d;if(l){if(!n.message)return v("no tag message specified (use -m)");let m=await dt(o,r.env);if(D(m))return m;let h=Bt(n.message),p=El({type:"tag",object:a,objectType:"commit",name:n.name,tagger:m,message:h}),g=await De(o,"tag",p);await Q(o,c,g),d=g}else await Q(o,c,a),d=a;return{stdout:f&&n.force&&f!==d?`Updated tag '${n.name}' (was ${await fe(o,f)}) ++`:"",stderr:"",exitCode:0}}return rh(o,void 0,n.sort)}})}async function rh(e,t,n){let r=await $e(e,"refs/tags");if(r.length===0)return{stdout:"",stderr:"",exitCode:0};let s=r.map(o=>({name:o.name.replace("refs/tags/",""),hash:o.hash}));if(t&&(s=s.filter(o=>Sn(t,o.name,0)===0)),s.length===0)return{stdout:"",stderr:"",exitCode:0};if(n){let o=n.startsWith("-"),i=o?n.slice(1):n;if(i==="creatordate"){let a=await Promise.all(s.map(async c=>({...c,date:await X0(e,c.hash)})));a.sort((c,f)=>{let l=c.date-f.date;return l!==0?l:c.name.localeCompare(f.name)}),o&&a.reverse(),s=a}else i==="version:refname"||i==="v:refname"?(s.sort((a,c)=>Z0(a.name,c.name)),o&&s.reverse()):i==="refname"&&(s.sort((a,c)=>a.name.localeCompare(c.name)),o&&s.reverse())}return{stdout:`${s.map(o=>o.name).join(` + `)} +-`,stderr:"",exitCode:0}}async function y0(e,t){if((await be(e,t)).type==="tag")return(await Mo(e,t)).tagger.timestamp;try{return(await M(e,t)).committer.timestamp}catch{return 0}}function k0(e,t){let n=e.replace(/^v/i,"").split(/[.\-+]/),r=t.replace(/^v/i,"").split(/[.\-+]/),o=Math.max(n.length,r.length);for(let s=0;s] [] ++`,stderr:"",exitCode:0}}async function X0(e,t){if((await me(e,t)).type==="tag")return(await _o(e,t)).tagger.timestamp;try{return(await M(e,t)).committer.timestamp}catch{return 0}}function Z0(e,t){let n=e.replace(/^v/i,"").split(/[.\-+]/),r=t.replace(/^v/i,"").split(/[.\-+]/),s=Math.max(n.length,r.length);for(let o=0;o] [] + or: git worktree list [] + or: git worktree lock [] + or: git worktree move +@@ -920,36 +927,36 @@ ${m}`,exitCode:0}}ne();ae();Jr();ye();Us();Ee();function _m(e,t){e.command("tag" + or: git worktree remove [] + or: git worktree repair [...] + or: git worktree unlock +-`;function Km(e,t){let n=e.command("worktree",{description:"Manage multiple working trees",handler:async()=>({stdout:"",stderr:R0,exitCode:129})});n.command("add",{description:"Create a new working tree",args:[W.string().name("path").describe("Path for the new worktree"),W.string().name("commitish").describe("Commit-ish to check out").optional()],options:{newBranch:K.string().alias("b").describe("Create a new branch"),forceNewBranch:K.string().alias("B").describe("Create or reset a branch"),detach:S().alias("d").describe("Detach HEAD in the new worktree"),force:S().alias("f").count().describe("Override safety checks"),lock:S().describe("Keep the worktree locked after creation"),reason:K.string().describe("Reason for locking"),noCheckout:S().describe("Do not populate the new worktree"),quiet:ce("Suppress progress output")},handler:async(r,o)=>{let s=await q(o.fs,o.cwd,t);return D(s)?s:C0(s,o,r)}}),n.command("list",{description:"List details of each working tree",options:{porcelain:S().describe("Machine-readable output")},handler:async(r,o)=>{let s=await q(o.fs,o.cwd,t);return D(s)?s:S0(s,!!r.porcelain)}}),n.command("remove",{description:"Remove a working tree",args:[W.string().name("worktree").describe("Worktree to remove")],options:{force:S().alias("f").count().describe("Override safety checks")},handler:async(r,o)=>{let s=await q(o.fs,o.cwd,t);return D(s)?s:v0(s,o,r.worktree,r.force??0)}}),n.command("prune",{description:"Prune working tree information",options:{dryRun:S().alias("n").describe("Do not remove, just report"),verbose:S().alias("v").describe("Report pruned worktrees")},handler:async(r,o)=>{let s=await q(o.fs,o.cwd,t);return D(s)?s:M0(s,!!r.dryRun,!!r.verbose)}}),n.command("lock",{description:"Lock a working tree to prevent pruning",args:[W.string().name("worktree").describe("Worktree to lock")],options:{reason:K.string().describe("Reason for locking")},handler:async(r,o)=>{let s=await q(o.fs,o.cwd,t);return D(s)?s:j0(s,o,r.worktree,r.reason)}}),n.command("unlock",{description:"Unlock a working tree",args:[W.string().name("worktree").describe("Worktree to unlock")],handler:async(r,o)=>{let s=await q(o.fs,o.cwd,t);return D(s)?s:L0(s,o,r.worktree)}}),n.command("move",{description:"Move a working tree to a new location",args:[W.string().name("worktree").describe("Worktree to move"),W.string().name("newPath").describe("New path for the worktree")],options:{force:S().alias("f").count().describe("Override safety checks")},handler:async(r,o)=>{let s=await q(o.fs,o.cwd,t);return D(s)?s:T0(s,o,r.worktree,r.newPath,r.force??0)}}),n.command("repair",{description:"Repair worktree administrative files",args:[W.string().name("paths").variadic().optional().describe("Worktree paths to relink")],handler:async(r,o)=>{let s=await q(o.fs,o.cwd,t);return D(s)?s:A0(s,o,r.paths??[])}})}async function C0(e,t,n){let r=Qe(t.cwd,n.path),o=(n.force??0)>0,s=n.commitish??"HEAD",i=await Le(e,s),a=n.newBranch??n.forceNewBranch,c=n.forceNewBranch!==void 0,f=await x0(e,{worktreePath:r,commitish:s,baseCommit:i,detach:!!n.detach,branchName:a,resetBranch:c,explicitCommitish:n.commitish!==void 0});if(D(f))return f;let l=!!n.quiet,d=f.orphan?`No possible source branch, inferring '--orphan' ++`;function fh(e,t){let n=e.command("worktree",{description:"Manage multiple working trees",handler:async()=>({stdout:"",stderr:J0,exitCode:129})});n.command("add",{description:"Create a new working tree",args:[B.string().name("path").describe("Path for the new worktree"),B.string().name("commitish").describe("Commit-ish to check out").optional()],options:{newBranch:K.string().alias("b").describe("Create a new branch"),forceNewBranch:K.string().alias("B").describe("Create or reset a branch"),detach:S().alias("d").describe("Detach HEAD in the new worktree"),force:S().alias("f").count().describe("Override safety checks"),lock:S().describe("Keep the worktree locked after creation"),reason:K.string().describe("Reason for locking"),noCheckout:S().describe("Do not populate the new worktree"),quiet:ce("Suppress progress output")},handler:async(r,s)=>{let o=await W(s.fs,s.cwd,t);return D(o)?o:ek(o,s,r)}}),n.command("list",{description:"List details of each working tree",options:{porcelain:S().describe("Machine-readable output")},handler:async(r,s)=>{let o=await W(s.fs,s.cwd,t);return D(o)?o:ok(o,!!r.porcelain)}}),n.command("remove",{description:"Remove a working tree",args:[B.string().name("worktree").describe("Worktree to remove")],options:{force:S().alias("f").count().describe("Override safety checks")},handler:async(r,s)=>{let o=await W(s.fs,s.cwd,t);return D(o)?o:ik(o,s,r.worktree,r.force??0)}}),n.command("prune",{description:"Prune working tree information",options:{dryRun:S().alias("n").describe("Do not remove, just report"),verbose:S().alias("v").describe("Report pruned worktrees")},handler:async(r,s)=>{let o=await W(s.fs,s.cwd,t);return D(o)?o:uk(o,!!r.dryRun,!!r.verbose)}}),n.command("lock",{description:"Lock a working tree to prevent pruning",args:[B.string().name("worktree").describe("Worktree to lock")],options:{reason:K.string().describe("Reason for locking")},handler:async(r,s)=>{let o=await W(s.fs,s.cwd,t);return D(o)?o:mk(o,s,r.worktree,r.reason)}}),n.command("unlock",{description:"Unlock a working tree",args:[B.string().name("worktree").describe("Worktree to unlock")],handler:async(r,s)=>{let o=await W(s.fs,s.cwd,t);return D(o)?o:hk(o,s,r.worktree)}}),n.command("move",{description:"Move a working tree to a new location",args:[B.string().name("worktree").describe("Worktree to move"),B.string().name("newPath").describe("New path for the worktree")],options:{force:S().alias("f").count().describe("Override safety checks")},handler:async(r,s)=>{let o=await W(s.fs,s.cwd,t);return D(o)?o:ck(o,s,r.worktree,r.newPath,r.force??0)}}),n.command("repair",{description:"Repair worktree administrative files",args:[B.string().name("paths").variadic().optional().describe("Worktree paths to relink")],handler:async(r,s)=>{let o=await W(s.fs,s.cwd,t);return D(o)?o:fk(o,s,r.paths??[])}})}async function ek(e,t,n){let r=Je(t.cwd,n.path),s=(n.force??0)>0,o=n.commitish??"HEAD",i=await Ie(e,o),a=n.newBranch??n.forceNewBranch,c=n.forceNewBranch!==void 0,f=await tk(e,{worktreePath:r,commitish:o,baseCommit:i,detach:!!n.detach,branchName:a,resetBranch:c,explicitCommitish:n.commitish!==void 0});if(D(f))return f;let l=!!n.quiet,d=f.orphan?`No possible source branch, inferring '--orphan' + `:"",u=l?"":`${d}Preparing worktree (${f.summary}) +-`,m=(b,R=128)=>({stdout:"",stderr:`${u}fatal: ${b} +-`,exitCode:R});if(f.requireBranchAbsent&&await z(e,f.requireBranchAbsent.ref))return m(`a branch named '${f.requireBranchAbsent.name}' already exists`,255);if(f.createBranchRef&&f.checkoutCommit&&(await Q(e,f.createBranchRef,f.checkoutCommit),await ee(e,t.env,f.createBranchRef,oe,f.checkoutCommit,`branch: Created from ${s}`),f.trackingRef&&await cs(e,xt(f.createBranchRef),f.trackingRef)),!o&&await O0(e,r))return m(`'${n.path}' already exists`);if(!o&&f.claimCheck){let b=await Hn(e,f.claimCheck.ref);if(b)return m(`'${f.claimCheck.name}' is already used by worktree at '${b}'`)}let h=await xd(e,r),p=await $d(e,h,r,f.head);await mi(e,r,p);let g=!!n.noCheckout;if(!g&&f.checkoutCommit&&await P0(e,p,r,f.checkoutCommit),await $0(e,t,p,r,f,g),n.lock&&await lc(e,p,n.reason),l)return{stdout:"",stderr:"",exitCode:0};let w="";if(f.checkoutCommit){let b=(await M(e,f.checkoutCommit)).message.split(` ++`,m=(b,y=128)=>({stdout:"",stderr:`${u}fatal: ${b} ++`,exitCode:y});if(f.requireBranchAbsent&&await z(e,f.requireBranchAbsent.ref))return m(`a branch named '${f.requireBranchAbsent.name}' already exists`,255);if(f.createBranchRef&&f.checkoutCommit&&(await Q(e,f.createBranchRef,f.checkoutCommit),await ee(e,t.env,f.createBranchRef,se,f.checkoutCommit,`branch: Created from ${o}`),f.trackingRef&&await ds(e,Pt(f.createBranchRef),f.trackingRef)),!s&&await sk(e,r))return m(`'${n.path}' already exists`);if(!s&&f.claimCheck){let b=await Ln(e,f.claimCheck.ref);if(b)return m(`'${f.claimCheck.name}' is already used by worktree at '${b}'`)}let h=await Md(e,r),p=await Ld(e,h,r,f.head);await Ci(e,r,p);let g=!!n.noCheckout;if(!g&&f.checkoutCommit&&await nk(e,p,r,f.checkoutCommit),await rk(e,t,p,r,f,g),n.lock&&await kc(e,p,n.reason),l)return{stdout:"",stderr:"",exitCode:0};let w="";if(f.checkoutCommit){let b=(await M(e,f.checkoutCommit)).message.split(` + `,1)[0];w=`HEAD is now at ${f.checkoutCommit.slice(0,7)} ${b} +-`}return{stdout:w,stderr:u,exitCode:0}}function qm(e,t){return{head:{type:"branch",ref:e},createBranchRef:null,checkoutCommit:null,summary:`new branch '${t}'`,orphan:!0}}async function x0(e,t){let{baseCommit:n,detach:r,branchName:o,resetBranch:s,explicitCommitish:i}=t;if(r)return n?{head:{type:"detached",hash:n},createBranchRef:null,checkoutCommit:n,summary:`detached HEAD ${n.slice(0,7)}`}:v(`invalid reference: ${t.commitish}`);if(o){let l=`refs/heads/${o}`;return n?{head:{type:"branch",ref:l},createBranchRef:l,checkoutCommit:n,summary:`new branch '${o}'`,requireBranchAbsent:s?void 0:{name:o,ref:l},claimCheck:{name:o,ref:l}}:i?v(`invalid reference: ${t.commitish}`):qm(l,o)}let a=i?t.commitish:xt(t.worktreePath),c=`refs/heads/${a}`,f=await z(e,c);if(f)return{head:{type:"branch",ref:c},createBranchRef:null,checkoutCommit:f,summary:`checking out '${a}'`,claimCheck:{name:a,ref:c}};if(i){let l=await fs(e,a);if(l){let d=await Le(e,l.startPoint);if(d)return{head:{type:"branch",ref:c},createBranchRef:c,checkoutCommit:d,summary:`new branch '${a}'`,trackingRef:l.trackingRef}}return n?{head:{type:"detached",hash:n},createBranchRef:null,checkoutCommit:n,summary:`detached HEAD ${n.slice(0,7)}`}:v(`invalid reference: ${t.commitish}`)}return n?{head:{type:"branch",ref:c},createBranchRef:c,checkoutCommit:n,summary:`new branch '${a}'`}:qm(c,a)}async function P0(e,t,n,r){let o={...e,gitDir:t,workTree:n,refStore:new Pt(e.fs,t,e.commonDir)},s=await M(o,r),i=await ze(o,s.tree);for(let c of i)await at(o,c);let a=await rr(o,Vr(i.map(c=>({path:c.path,mode:parseInt(c.mode,8),hash:c.hash,stage:0,stat:Fe()}))));await ie(o,a)}async function $0(e,t,n,r,o,s){if(!o.checkoutCommit)return;let i={...e,gitDir:n,workTree:r,refStore:new Pt(e.fs,n,e.commonDir)};await ee(i,t.env,"HEAD",oe,o.checkoutCommit,""),!s&&o.head.type==="branch"&&await ee(i,t.env,"HEAD",o.checkoutCommit,o.checkoutCommit,"reset: moving to HEAD")}async function O0(e,t){return await e.fs.exists(t)?(await e.fs.stat(t)).isDirectory?(await e.fs.readdir(t)).length>0:!0:!1}async function S0(e,t){let n=await An(e);if(t)return{stdout:n.map(i=>{let a=[`worktree ${i.path}`];return i.bare?a.push("bare"):(i.head&&a.push(`HEAD ${i.head}`),a.push(i.branch?`branch ${i.branch}`:"detached")),i.locked&&a.push(i.lockReason?`locked ${i.lockReason}`:"locked"),i.prunable&&a.push(`prunable ${i.prunable}`),`${a.join(` ++`}return{stdout:w,stderr:u,exitCode:0}}function ah(e,t){return{head:{type:"branch",ref:e},createBranchRef:null,checkoutCommit:null,summary:`new branch '${t}'`,orphan:!0}}async function tk(e,t){let{baseCommit:n,detach:r,branchName:s,resetBranch:o,explicitCommitish:i}=t;if(r)return n?{head:{type:"detached",hash:n},createBranchRef:null,checkoutCommit:n,summary:`detached HEAD ${n.slice(0,7)}`}:v(`invalid reference: ${t.commitish}`);if(s){let l=`refs/heads/${s}`;return n?{head:{type:"branch",ref:l},createBranchRef:l,checkoutCommit:n,summary:`new branch '${s}'`,requireBranchAbsent:o?void 0:{name:s,ref:l},claimCheck:{name:s,ref:l}}:i?v(`invalid reference: ${t.commitish}`):ah(l,s)}let a=i?t.commitish:Pt(t.worktreePath),c=`refs/heads/${a}`,f=await z(e,c);if(f)return{head:{type:"branch",ref:c},createBranchRef:null,checkoutCommit:f,summary:`checking out '${a}'`,claimCheck:{name:a,ref:c}};if(i){let l=await us(e,a);if(l){let d=await Ie(e,l.startPoint);if(d)return{head:{type:"branch",ref:c},createBranchRef:c,checkoutCommit:d,summary:`new branch '${a}'`,trackingRef:l.trackingRef}}return n?{head:{type:"detached",hash:n},createBranchRef:null,checkoutCommit:n,summary:`detached HEAD ${n.slice(0,7)}`}:v(`invalid reference: ${t.commitish}`)}return n?{head:{type:"branch",ref:c},createBranchRef:c,checkoutCommit:n,summary:`new branch '${a}'`}:ah(c,a)}async function nk(e,t,n,r){let s={...e,gitDir:t,workTree:n,refStore:new $t(e.fs,t,e.commonDir)},o=await M(s,r),i=await Ke(s,o.tree);for(let c of i)await lt(s,c);let a=await rr(s,Qr(i.map(c=>({path:c.path,mode:parseInt(c.mode,8),hash:c.hash,stage:0,stat:Ge()}))));await oe(s,a)}async function rk(e,t,n,r,s,o){if(!s.checkoutCommit)return;let i={...e,gitDir:n,workTree:r,refStore:new $t(e.fs,n,e.commonDir)};await ee(i,t.env,"HEAD",se,s.checkoutCommit,""),!o&&s.head.type==="branch"&&await ee(i,t.env,"HEAD",s.checkoutCommit,s.checkoutCommit,"reset: moving to HEAD")}async function sk(e,t){return await e.fs.exists(t)?(await e.fs.stat(t)).isDirectory?(await e.fs.readdir(t)).length>0:!0:!1}async function ok(e,t){let n=await jn(e);if(t)return{stdout:n.map(i=>{let a=[`worktree ${i.path}`];return i.bare?a.push("bare"):(i.head&&a.push(`HEAD ${i.head}`),a.push(i.branch?`branch ${i.branch}`:"detached")),i.locked&&a.push(i.lockReason?`locked ${i.lockReason}`:"locked"),i.prunable&&a.push(`prunable ${i.prunable}`),`${a.join(` + `)} + `}).map(i=>`${i} +-`).join(""),stderr:"",exitCode:0};let r=Math.max(0,...n.map(s=>s.path.length));return{stdout:`${n.map(s=>{if(s.bare)return`${s.path.padEnd(r)} (bare)`;let i=s.head?s.head.slice(0,7):"0000000",a=s.branch?`[${s.branch.replace("refs/heads/","")}]`:"(detached HEAD)",c=s.locked?" locked":s.prunable?" prunable":"";return`${s.path.padEnd(r)} ${i} ${a}${c}`}).join(` +-`)} +-`,stderr:"",exitCode:0}}async function Bi(e,t,n){let r=Qe(t.cwd,n);return(await An(e)).find(s=>s.path===r||s.path===n||xt(s.adminDir)===n)??null}async function v0(e,t,n,r){let o=await Bi(e,t,n);if(!o)return v(`'${n}' is not a working tree`);if(o.isMain)return v(`'${n}' is a main working tree`);if(o.locked&&r<2){let s=await pi(e,o.adminDir),i=s?`cannot remove a locked working tree, lock reason: ${s}`:"cannot remove a locked working tree;";return v(`${i} +-use 'remove -f -f' to override or unlock first`)}return r<1&&await I0(e,o)?v(`'${n}' contains modified or untracked files, use --force to delete it`):(await e.fs.rm(o.path,{recursive:!0,force:!0}),await e.fs.rm(o.adminDir,{recursive:!0,force:!0}),{stdout:"",stderr:"",exitCode:0})}async function I0(e,t){let n={...e,gitDir:t.adminDir,workTree:t.path,refStore:new Pt(e.fs,t.adminDir,e.commonDir)},r=await X(n);if(r.entries.some(i=>i.stage!==0)||(await dt(n,r,{stopAfterFirst:!0})).length>0)return!0;let o=await Z(n);if(!o)return r.entries.length>0;let s=await de(n,(await M(n,o)).tree);return Bn(r,s)}async function T0(e,t,n,r,o){let s=await Bi(e,t,n);if(!s)return v(`'${n}' is not a working tree`);if(s.isMain)return v(`'${n}' is a main working tree`);if(s.locked&&o<2){let d=await pi(e,s.adminDir),u=d?`cannot move a locked working tree, lock reason: ${d}`:"cannot move a locked working tree;";return v(`${u} +-use 'move -f -f' to override or unlock first`)}let i=Qe(t.cwd,r),a=await e.fs.exists(i)&&(await e.fs.stat(i)).isDirectory,c=xt(s.path),f=a?I(i,c):i,l=a?`${r.replace(/\/+$/,"")}/${c}`:r;return await e.fs.exists(f)?v(`'${l}' already exists`):f===s.path||f.startsWith(`${s.path}/`)?v(`failed to move '${s.path}' to '${r}': Invalid argument`):await e.fs.exists(bt(f))?(await Bm(e.fs,s.path,f),await e.fs.writeFile(I(s.adminDir,"gitdir"),`${I(f,".git")} +-`),{stdout:"",stderr:"",exitCode:0}):v(`failed to move '${s.path}' to '${r}': No such file or directory`)}async function A0(e,t,n){let r=e.fs,o=[],s=0;for(let i of n){let a=Qe(t.cwd,i);if(zm(a)===zm(e.commonDir))continue;if(!await r.exists(a)){o.push(`error: not a valid path: ${i} +-`),s=1;continue}let c=I(a,".git"),f=await Vm(r,c),l=await H0(r,e.commonDir,c),d;if(f!==null&&await D0(r,f))d=f;else if(f!==null&&l)d=l;else if(f!==null){o.push(`error: unable to locate repository; .git file does not reference a repository: ${c} +-`),s=1;continue}else{o.push(`error: unable to locate repository; .git file broken: ${c} +-`),s=1;continue}l&&d!==l&&(d=l);let u=I(d,"gitdir");(await r.exists(u)?(await r.readFile(u)).trim():null)!==c&&(await r.writeFile(u,`${c} +-`),await mi(e,a,d),o.push(`repair: gitdir incorrect: ${u} +-`))}for(let{privateDir:i}of await Gr(e)){let a=I(i,"gitdir");if(!await r.exists(a))continue;let c=(await r.readFile(a)).trim();if(!c)continue;let f=bt(c);if(!await r.exists(f))continue;let l=`gitdir: ${i}`;(await r.exists(c)?(await r.readFile(c)).trim():null)!==l&&(await mi(e,f,i),o.push(`repair: .git file broken: ${f} +-`))}return{stdout:"",stderr:o.join(""),exitCode:s}}function zm(e){return e.endsWith("/.git")?e.slice(0,-5):e}async function H0(e,t,n){let r=await Vm(e,n);if(!r)return null;let o=xt(r);if(!o)return null;let s=I(t,"worktrees",o);return await e.exists(s)&&(await e.stat(s)).isDirectory?s:null}async function Vm(e,t){if(!await e.exists(t))return null;let n;try{n=await e.readFile(t)}catch{return null}let r=n.trim();return r.startsWith("gitdir:")&&r.slice(7).trim()||null}async function D0(e,t){return!await e.exists(t)||!(await e.stat(t)).isDirectory?!1:e.exists(I(t,"gitdir"))}async function M0(e,t,n){let r=[];for(let o of await An(e))o.isMain||o.locked||!o.prunable||((n||t)&&r.push(`Removing worktrees/${xt(o.adminDir)}: ${o.prunable}`),t||await e.fs.rm(o.adminDir,{recursive:!0,force:!0}));return{stdout:r.length?`${r.join(` +-`)} +-`:"",stderr:"",exitCode:0}}async function j0(e,t,n,r){let o=await Bi(e,t,n);return o?o.isMain?v("The main working tree cannot be locked or unlocked"):await hi(e,o.adminDir)?v(`'${n}' is already locked`):(await lc(e,o.adminDir,r),{stdout:"",stderr:"",exitCode:0}):v(`'${n}' is not a working tree`)}async function L0(e,t,n){let r=await Bi(e,t,n);return r?r.isMain?v("The main working tree cannot be locked or unlocked"):await hi(e,r.adminDir)?(await Od(e,r.adminDir),{stdout:"",stderr:"",exitCode:0}):v(`'${n}' is not locked`):v(`'${n}' is not a working tree`)}var Ym=new Set(["am","annotate","apply","archive","bugreport","bundle","cat-file","check-ignore","check-mailmap","check-ref-format","checkout-index","cherry","commit-tree","count-objects","credential","daemon","diff-files","diff-index","diff-tree","difftool","fast-export","fast-import","filter-branch","for-each-ref","format-patch","fsck","hash-object","instaweb","interpret-trailers","log--hierarchical","ls-remote","ls-tree","maintenance","merge-base","merge-tree","mergetool","multi-pack-index","name-rev","notes","pack-objects","pack-refs","patch-id","prune","range-diff","read-tree","receive-pack","replace","request-pull","rerere","rev-list","send-email","send-pack","show-branch","show-ref","sparse-checkout","stash--helper","stripspace","submodule","symbolic-ref","unpack-objects","update-index","update-ref","upload-pack","var","verify-commit","verify-pack","verify-tag","whatchanged","write-tree"]),G0={init:(e,t)=>_u(e,t),clone:(e,t)=>wu(e,t),describe:(e,t)=>yu(e,t),fetch:(e,t)=>Mu(e,t),pull:(e,t)=>dm(e,t),push:(e,t)=>mm(e,t),add:(e,t)=>Nl(e,t),blame:(e,t)=>Ed(e,t),commit:(e,t)=>ku(e,t),status:(e,t)=>Lm(e,t),log:(e,t)=>Qu(e,t),branch:(e,t)=>Hd(e,t),tag:(e,t)=>_m(e,t),checkout:(e,t)=>Md(e,t),diff:(e,t)=>vu(e,t),reset:(e,t)=>ym(e,t),merge:(e,t)=>nm(e,t),"cherry-pick":(e,t)=>Yd(e,t),revert:(e,t)=>Cm(e,t),rebase:(e,t)=>hm(e,t),mv:(e,t)=>rm(e,t),rm:(e,t)=>Pm(e,t),remote:(e,t)=>gm(e,t),config:(e,t)=>xu(e,t),shortlog:(e,t)=>Om(e,t),show:(e,t)=>vm(e,t),stash:(e,t)=>jm(e,t),"rev-parse":(e,t)=>Rm(e,t),"ls-files":(e,t)=>em(e,t),clean:(e,t)=>Xd(e,t),switch:(e,t)=>Fm(e,t),restore:(e,t)=>Em(e,t),reflog:(e,t)=>pm(e,t),repack:(e,t)=>wm(e,t),gc:(e,t)=>Gu(e,t),bisect:(e,t)=>ad(e,t),grep:(e,t)=>Uu(e,t),worktree:(e,t)=>Km(e,t)};function Bc(e){let t=ta("git",{description:"Git command"});for(let n of Object.values(G0))n(t,e);return t.command("help",{description:"Display help information",args:[W.string().name("command").describe("Command to get help for").optional()],handler:async n=>{let r=n.command;if(!r)return{stdout:qr(t),stderr:"",exitCode:0};let o=t.children.get(r);return o?{stdout:qr(o),stderr:"",exitCode:0}:{stdout:"",stderr:`git: no help available for '${r}' +-`,exitCode:1}}}),t}ne();Be();ge();Gn();var F0="1.9.1";function N0(e,t){if(!e)return t;let n=e.locked?"locked":"defaults",r={"user.name":e.name,"user.email":e.email};return t?{...t,[n]:{...r,...t[n]}}:{[n]:r}}function U0(e){if(!e)return e;let t=n=>Object.fromEntries(Object.entries(n).map(([r,o])=>[Rs(r),o]));return{...e.locked?{locked:t(e.locked)}:{},...e.defaults?{defaults:t(e.defaults)}:{}}}var _0=`usage: git [--version] [--help] [-C ] [-c =] ++`).join(""),stderr:"",exitCode:0};let r=Math.max(0,...n.map(o=>o.path.length));return{stdout:`${n.map(o=>{if(o.bare)return`${o.path.padEnd(r)} (bare)`;let i=o.head?o.head.slice(0,7):"0000000",a=o.branch?`[${o.branch.replace("refs/heads/","")}]`:"(detached HEAD)",c=o.locked?" locked":o.prunable?" prunable":"";return`${o.path.padEnd(r)} ${i} ${a}${c}`}).join(` ++`)} ++`,stderr:"",exitCode:0}}async function Ji(e,t,n){let r=Je(t.cwd,n);return(await jn(e)).find(o=>o.path===r||o.path===n||Pt(o.adminDir)===n)??null}async function ik(e,t,n,r){let s=await Ji(e,t,n);if(!s)return v(`'${n}' is not a working tree`);if(s.isMain)return v(`'${n}' is a main working tree`);if(s.locked&&r<2){let o=await Pi(e,s.adminDir),i=o?`cannot remove a locked working tree, lock reason: ${o}`:"cannot remove a locked working tree;";return v(`${i} ++use 'remove -f -f' to override or unlock first`)}return r<1&&await ak(e,s)?v(`'${n}' contains modified or untracked files, use --force to delete it`):(await e.fs.rm(s.path,{recursive:!0,force:!0}),await e.fs.rm(s.adminDir,{recursive:!0,force:!0}),{stdout:"",stderr:"",exitCode:0})}async function ak(e,t){let n={...e,gitDir:t.adminDir,workTree:t.path,refStore:new $t(e.fs,t.adminDir,e.commonDir)},r=await X(n);if(r.entries.some(i=>i.stage!==0)||(await pt(n,r,{stopAfterFirst:!0})).length>0)return!0;let s=await Z(n);if(!s)return r.entries.length>0;let o=await de(n,(await M(n,s)).tree);return Wn(r,o)}async function ck(e,t,n,r,s){let o=await Ji(e,t,n);if(!o)return v(`'${n}' is not a working tree`);if(o.isMain)return v(`'${n}' is a main working tree`);if(o.locked&&s<2){let d=await Pi(e,o.adminDir),u=d?`cannot move a locked working tree, lock reason: ${d}`:"cannot move a locked working tree;";return v(`${u} ++use 'move -f -f' to override or unlock first`)}let i=Je(t.cwd,r),a=await e.fs.exists(i)&&(await e.fs.stat(i)).isDirectory,c=Pt(o.path),f=a?I(i,c):i,l=a?`${r.replace(/\/+$/,"")}/${c}`:r;return await e.fs.exists(f)?v(`'${l}' already exists`):f===o.path||f.startsWith(`${o.path}/`)?v(`failed to move '${o.path}' to '${r}': Invalid argument`):await e.fs.exists(Et(f))?(await oh(e.fs,o.path,f),await e.fs.writeFile(I(o.adminDir,"gitdir"),`${I(f,".git")} ++`),{stdout:"",stderr:"",exitCode:0}):v(`failed to move '${o.path}' to '${r}': No such file or directory`)}async function fk(e,t,n){let r=e.fs,s=[],o=0;for(let i of n){let a=Je(t.cwd,i);if(ch(a)===ch(e.commonDir))continue;if(!await r.exists(a)){s.push(`error: not a valid path: ${i} ++`),o=1;continue}let c=I(a,".git"),f=await lh(r,c),l=await lk(r,e.commonDir,c),d;if(f!==null&&await dk(r,f))d=f;else if(f!==null&&l)d=l;else if(f!==null){s.push(`error: unable to locate repository; .git file does not reference a repository: ${c} ++`),o=1;continue}else{s.push(`error: unable to locate repository; .git file broken: ${c} ++`),o=1;continue}l&&d!==l&&(d=l);let u=I(d,"gitdir");(await r.exists(u)?(await r.readFile(u)).trim():null)!==c&&(await r.writeFile(u,`${c} ++`),await Ci(e,a,d),s.push(`repair: gitdir incorrect: ${u} ++`))}for(let{privateDir:i}of await _r(e)){let a=I(i,"gitdir");if(!await r.exists(a))continue;let c=(await r.readFile(a)).trim();if(!c)continue;let f=Et(c);if(!await r.exists(f))continue;let l=`gitdir: ${i}`;(await r.exists(c)?(await r.readFile(c)).trim():null)!==l&&(await Ci(e,f,i),s.push(`repair: .git file broken: ${f} ++`))}return{stdout:"",stderr:s.join(""),exitCode:o}}function ch(e){return e.endsWith("/.git")?e.slice(0,-5):e}async function lk(e,t,n){let r=await lh(e,n);if(!r)return null;let s=Pt(r);if(!s)return null;let o=I(t,"worktrees",s);return await e.exists(o)&&(await e.stat(o)).isDirectory?o:null}async function lh(e,t){if(!await e.exists(t))return null;let n;try{n=await e.readFile(t)}catch{return null}let r=n.trim();return r.startsWith("gitdir:")&&r.slice(7).trim()||null}async function dk(e,t){return!await e.exists(t)||!(await e.stat(t)).isDirectory?!1:e.exists(I(t,"gitdir"))}async function uk(e,t,n){let r=[];for(let s of await jn(e))s.isMain||s.locked||!s.prunable||((n||t)&&r.push(`Removing worktrees/${Pt(s.adminDir)}: ${s.prunable}`),t||await e.fs.rm(s.adminDir,{recursive:!0,force:!0}));return{stdout:r.length?`${r.join(` ++`)} ++`:"",stderr:"",exitCode:0}}async function mk(e,t,n,r){let s=await Ji(e,t,n);return s?s.isMain?v("The main working tree cannot be locked or unlocked"):await xi(e,s.adminDir)?v(`'${n}' is already locked`):(await kc(e,s.adminDir,r),{stdout:"",stderr:"",exitCode:0}):v(`'${n}' is not a working tree`)}async function hk(e,t,n){let r=await Ji(e,t,n);return r?r.isMain?v("The main working tree cannot be locked or unlocked"):await xi(e,r.adminDir)?(await Gd(e,r.adminDir),{stdout:"",stderr:"",exitCode:0}):v(`'${n}' is not locked`):v(`'${n}' is not a working tree`)}var dh=new Set(["am","annotate","apply","archive","bugreport","bundle","cat-file","check-ignore","check-mailmap","check-ref-format","checkout-index","cherry","commit-tree","count-objects","credential","daemon","diff-files","diff-index","diff-tree","difftool","fast-export","fast-import","filter-branch","for-each-ref","format-patch","fsck","hash-object","instaweb","interpret-trailers","log--hierarchical","ls-remote","maintenance","merge-base","merge-tree","mergetool","multi-pack-index","name-rev","notes","pack-objects","pack-refs","patch-id","prune","range-diff","read-tree","receive-pack","replace","request-pull","rerere","rev-list","send-email","send-pack","show-branch","show-ref","sparse-checkout","stash--helper","stripspace","submodule","symbolic-ref","unpack-objects","update-index","update-ref","upload-pack","var","verify-commit","verify-pack","verify-tag","whatchanged","write-tree"]),pk={init:(e,t)=>Ju(e,t),clone:(e,t)=>Su(e,t),describe:(e,t)=>Iu(e,t),fetch:(e,t)=>zu(e,t),pull:(e,t)=>Pm(e,t),push:(e,t)=>Om(e,t),add:(e,t)=>Xl(e,t),blame:(e,t)=>Ad(e,t),commit:(e,t)=>Tu(e,t),status:(e,t)=>Jm(e,t),log:(e,t)=>fm(e,t),branch:(e,t)=>Wd(e,t),tag:(e,t)=>sh(e,t),checkout:(e,t)=>zd(e,t),diff:(e,t)=>Nu(e,t),reset:(e,t)=>Hm(e,t),merge:(e,t)=>gm(e,t),"cherry-pick":(e,t)=>iu(e,t),revert:(e,t)=>Lm(e,t),rebase:(e,t)=>Sm(e,t),mv:(e,t)=>wm(e,t),rm:(e,t)=>Fm(e,t),remote:(e,t)=>Im(e,t),config:(e,t)=>Mu(e,t),shortlog:(e,t)=>Um(e,t),show:(e,t)=>Bm(e,t),stash:(e,t)=>Qm(e,t),"rev-parse":(e,t)=>jm(e,t),"ls-files":(e,t)=>dm(e,t),"ls-tree":(e,t)=>um(e,t),clean:(e,t)=>au(e,t),switch:(e,t)=>th(e,t),restore:(e,t)=>Mm(e,t),reflog:(e,t)=>vm(e,t),repack:(e,t)=>Tm(e,t),gc:(e,t)=>Yu(e,t),bisect:(e,t)=>wd(e,t),grep:(e,t)=>Qu(e,t),worktree:(e,t)=>fh(e,t)};function ef(e){let t=da("git",{description:"Git command"});for(let n of Object.values(pk))n(t,e);return t.command("help",{description:"Display help information",args:[B.string().name("command").describe("Command to get help for").optional()],handler:async n=>{let r=n.command;if(!r)return{stdout:Yr(t),stderr:"",exitCode:0};let s=t.children.get(r);return s?{stdout:Yr(s),stderr:"",exitCode:0}:{stdout:"",stderr:`git: no help available for '${r}' ++`,exitCode:1}}}),t}te();We();ge();Nn();var gk="1.9.1";function wk(e,t){if(!e)return t;let n=e.locked?"locked":"defaults",r={"user.name":e.name,"user.email":e.email};return t?{...t,[n]:{...r,...t[n]}}:{[n]:r}}function bk(e){if(!e)return e;let t=n=>Object.fromEntries(Object.entries(n).map(([r,s])=>[Os(r),s]));return{...e.locked?{locked:t(e.locked)}:{},...e.defaults?{defaults:t(e.defaults)}:{}}}var yk=`usage: git [--version] [--help] [-C ] [-c =] + [-p | --paginate | -P | --no-pager] [] +-`;function Wc(e){return{stdout:"",stderr:`${e} +-${_0}`,exitCode:129}}function B0(e){return{stdout:"",stderr:`error: ${e} ++`;function tf(e){return{stdout:"",stderr:`${e} ++${yk}`,exitCode:129}}function kk(e){return{stdout:"",stderr:`error: ${e} + fatal: unable to parse command-line config +-`,exitCode:128}}var W0=/^[A-Za-z0-9-]$/,q0=/^[A-Za-z]$/;function z0(e){if(e==="")return"empty config key";let t=e.lastIndexOf(".");if(t<=0)return`key does not contain a section: ${e}`;if(t===e.length-1)return`key does not contain variable name: ${e}`;let n=!1;for(let r=0;rt){if(!W0.test(o)||r===t+1&&!q0.test(o))return`invalid key: ${e}`}else if(o===` +-`)return`invalid key (newline): ${e}`}return null}var K0=new Set(["-","-h","--help","-v","--version"]),V0=new Set(["","-v","--version","version","-h","--help","help"]);function Y0(e){return e.length>1||!V0.has(e[0]??"")}function X0(e){let t=[],n,r,o=0;for(;o{o=i});this.locks.set(t,s),await r;try{return await n()}finally{o()}}constructor(t){this.defaultFs=t?.fs,this.defaultCwd=t?.cwd??"/",this.hooks=t?.hooks,this.blocked=t?.disabled?.length?new Set(t.disabled):null;let n=t?.network,r=U0(N0(t?.identity,t?.config)),o=t?.gitDir?{gitDir:t.gitDir,workTree:this.defaultCwd,...t.commonDir?{commonDir:t.commonDir}:{}}:{},s={hooks:t?.hooks,credentialProvider:t?.credentials,identityOverride:t?.identity,fetchFn:typeof n=="object"?n.fetch:void 0,networkPolicy:n,resolveRemote:t?.resolveRemote,credentialCache:new Map,onProgress:t?.onProgress,mergeDriver:t?.mergeDriver,...t?.objectStore?{objectStore:t.objectStore}:{},...t?.refStore?{refStore:t.refStore}:{},...o,...r?{configOverrides:r}:{}};this.ext=s,this.inner=Bc(s).toCommand()}async findRepo(t){let n=t?.fs??this.defaultFs;if(!n)throw new Error("No filesystem: pass `fs` in findRepo() options or in createGit()");let r=t?.cwd??this.defaultCwd;if(this.ext.objectStore&&this.ext.refStore&&this.ext.gitDir)return _a(n,r,this.ext);let o=await Fn(n,r);return o?{...o,...this.ext,commonDir:this.ext.commonDir??o.commonDir}:null}exec=async(t,n)=>{let r=n?.fs??this.defaultFs;if(!r)throw new Error("No filesystem: pass `fs` in exec() options or in createGit()");let o=n?.cwd??this.defaultCwd,s=J0(t),i=new Map;if(n?.env)for(let[a,c]of Object.entries(n.env))i.set(a,c);return this.execute(s,{fs:r,cwd:o,env:i,stdin:n?.stdin??""})};execute=(t,n)=>this.withLock(n.fs,async()=>{let r=X0(t);if("exitCode"in r)return r;let{args:o,config:s,configError:i,chdirs:a}=r,c=o[0]??"",f=n.cwd;for(let u of a)if(f=Qe(f,u),!await Q0(n.fs,f))return{stdout:"",stderr:`fatal: cannot change to '${u}': No such file or directory +-`,exitCode:128};if(f!==n.cwd&&(n={...n,cwd:f}),i&&Y0(o))return B0(i);if(c==="--version"||c==="-v"||c==="version")return{stdout:`just-git version ${F0} (virtual git implementation) ++`,exitCode:128}}var Ek=/^[A-Za-z0-9-]$/,Rk=/^[A-Za-z]$/;function Ck(e){if(e==="")return"empty config key";let t=e.lastIndexOf(".");if(t<=0)return`key does not contain a section: ${e}`;if(t===e.length-1)return`key does not contain variable name: ${e}`;let n=!1;for(let r=0;rt){if(!Ek.test(s)||r===t+1&&!Rk.test(s))return`invalid key: ${e}`}else if(s===` ++`)return`invalid key (newline): ${e}`}return null}var xk=new Set(["-","-h","--help","-v","--version"]),Pk=new Set(["","-v","--version","version","-h","--help","help"]);function $k(e){return e.length>1||!Pk.has(e[0]??"")}function Ok(e){let t=[],n,r,s=0;for(;s{s=i});this.locks.set(t,o),await r;try{return await n()}finally{s()}}constructor(t){this.defaultFs=t?.fs,this.defaultCwd=t?.cwd??"/",this.hooks=t?.hooks,this.blocked=t?.disabled?.length?new Set(t.disabled):null;let n=t?.network,r=bk(wk(t?.identity,t?.config)),s=t?.gitDir?{gitDir:t.gitDir,workTree:this.defaultCwd,...t.commonDir?{commonDir:t.commonDir}:{}}:{},o={hooks:t?.hooks,credentialProvider:t?.credentials,identityOverride:t?.identity,fetchFn:typeof n=="object"?n.fetch:void 0,networkPolicy:n,resolveRemote:t?.resolveRemote,credentialCache:new Map,onProgress:t?.onProgress,mergeDriver:t?.mergeDriver,...t?.objectStore?{objectStore:t.objectStore}:{},...t?.refStore?{refStore:t.refStore}:{},...s,...r?{configOverrides:r}:{}};this.ext=o,this.inner=ef(o).toCommand()}async findRepo(t){let n=t?.fs??this.defaultFs;if(!n)throw new Error("No filesystem: pass `fs` in findRepo() options or in createGit()");let r=t?.cwd??this.defaultCwd;if(this.ext.objectStore&&this.ext.refStore&&this.ext.gitDir)return Za(n,r,this.ext);let s=await Un(n,r);return s?{...s,...this.ext,commonDir:this.ext.commonDir??s.commonDir}:null}exec=async(t,n)=>{let r=n?.fs??this.defaultFs;if(!r)throw new Error("No filesystem: pass `fs` in exec() options or in createGit()");let s=n?.cwd??this.defaultCwd,o=Ik(t),i=new Map;if(n?.env)for(let[a,c]of Object.entries(n.env))i.set(a,c);return this.execute(o,{fs:r,cwd:s,env:i,stdin:n?.stdin??""})};execute=(t,n)=>this.withLock(n.fs,async()=>{let r=Ok(t);if("exitCode"in r)return r;let{args:s,config:o,configError:i,chdirs:a}=r,c=s[0]??"",f=n.cwd;for(let u of a)if(f=Je(f,u),!await vk(n.fs,f))return{stdout:"",stderr:`fatal: cannot change to '${u}': No such file or directory ++`,exitCode:128};if(f!==n.cwd&&(n={...n,cwd:f}),i&&$k(s))return kk(i);if(c==="--version"||c==="-v"||c==="version")return{stdout:`just-git version ${gk} (virtual git implementation) + `,stderr:"",exitCode:0};if(this.blocked?.has(c))return{stdout:"",stderr:`git: '${c}' is not available in this environment +-`,exitCode:1};if(c&&Ym.has(c))return{stdout:"",stderr:`git: '${c}' is not implemented. Run 'git help' for available commands. +-`,exitCode:1};if(this.hooks?.beforeCommand){let u=await this.hooks.beforeCommand({command:c,args:o.slice(1),fs:n.fs,cwd:n.cwd,env:n.env});if(he(u))return{stdout:"",stderr:u.message??"",exitCode:1}}let d=await(s?Bc({...this.ext,configOverrides:Z0(this.ext.configOverrides,s)}).toCommand():this.inner).execute(o,n);return this.hooks?.afterCommand&&await this.hooks.afterCommand({command:c,args:o.slice(1),result:d}),d})};function J0(e){let t=[],n="",r=0;for(;r0&&(t.push(n),n=""),r++):(n+=o,r++)}return n.length>0&&t.push(n),t.length>0&&t[0]==="git"&&t.shift(),t}function ek(e){return new Wi(e)}var Xm=new TextEncoder,tk=new TextDecoder;function on(e){let t=[];for(let n of e.split("/"))n==="."||n===""||(n===".."?t.pop():t.push(n));return"/"+t.join("/")}function qi(e){let t=e.lastIndexOf("/");return t<=0?"/":e.slice(0,t)}var qc=class{data=new Map;constructor(t){if(this.data.set("/",{type:"directory",mode:16877,mtime:new Date}),t)for(let[n,r]of Object.entries(t)){let o=on(n);this.ensureParents(o),this.data.set(o,{type:"file",content:typeof r=="string"?Xm.encode(r):r,mode:33188,mtime:new Date})}}ensureParents(t){let n=qi(t);n!=="/"&&(this.data.has(n)||(this.ensureParents(n),this.data.set(n,{type:"directory",mode:16877,mtime:new Date})))}resolve(t){let n="",r=new Set;for(let o of on(t).slice(1).split("/")){n=`${n}/${o}`;let s=0,i=this.data.get(n);for(;i?.type==="symlink"&&s<40;){if(r.has(n))throw new Error(`ELOOP: too many levels of symbolic links, '${t}'`);r.add(n);let a=i.target;n=a.startsWith("/")?on(a):on(qi(n)+"/"+a),i=this.data.get(n),s++}if(s>=40)throw new Error(`ELOOP: too many levels of symbolic links, '${t}'`)}return n}resolveParent(t){let n=on(t);if(n==="/")return"/";let r=n.slice(1).split("/");if(r.length<=1)return n;let o="",s=new Set;for(let i=0;i0)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);let s=r==="/"?"/":`${r}/`;for(let i of[...this.data.keys()])i.startsWith(s)&&this.data.delete(i)}this.data.delete(r)}async mv(t,n){let r=on(t);if(!this.data.has(r))throw new Error(`ENOENT: no such file or directory, rename '${t}'`);let o=on(n);if(r===o)return;this.ensureParents(o);let s=r==="/"?"/":`${r}/`,i=o==="/"?"/":`${o}/`;for(let a of[...this.data.keys()])a===r?(this.data.set(o,this.data.get(a)),this.data.delete(a)):a.startsWith(s)&&(this.data.set(i+a.slice(s.length),this.data.get(a)),this.data.delete(a))}async readlink(t){let n=this.resolveParent(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return r.target}async symlink(t,n){let r=on(n);if(this.data.has(r))throw new Error(`EEXIST: file already exists, symlink '${n}'`);this.ensureParents(r),this.data.set(r,{type:"symlink",target:t,mode:40960,mtime:new Date})}};Gn();export{Wi as Git,qc as MemoryFileSystem,iw as composeGitHooks,ek as createGit,Fn as findRepo,he as isRejection}; ++`,exitCode:1};if(c&&dh.has(c))return{stdout:"",stderr:`git: '${c}' is not implemented. Run 'git help' for available commands. ++`,exitCode:1};if(this.hooks?.beforeCommand){let u=await this.hooks.beforeCommand({command:c,args:s.slice(1),fs:n.fs,cwd:n.cwd,env:n.env});if(pe(u))return{stdout:"",stderr:u.message??"",exitCode:1}}let d=await(o?ef({...this.ext,configOverrides:Sk(this.ext.configOverrides,o)}).toCommand():this.inner).execute(s,n);return this.hooks?.afterCommand&&await this.hooks.afterCommand({command:c,args:s.slice(1),result:d}),d})};function Ik(e){let t=[],n="",r=0;for(;r0&&(t.push(n),n=""),r++):(n+=s,r++)}return n.length>0&&t.push(n),t.length>0&&t[0]==="git"&&t.shift(),t}function Tk(e){return new ea(e)}var uh=new TextEncoder,Ak=new TextDecoder;function ln(e){let t=[];for(let n of e.split("/"))n==="."||n===""||(n===".."?t.pop():t.push(n));return"/"+t.join("/")}function ta(e){let t=e.lastIndexOf("/");return t<=0?"/":e.slice(0,t)}var nf=class{data=new Map;constructor(t){if(this.data.set("/",{type:"directory",mode:16877,mtime:new Date}),t)for(let[n,r]of Object.entries(t)){let s=ln(n);this.ensureParents(s),this.data.set(s,{type:"file",content:typeof r=="string"?uh.encode(r):r,mode:33188,mtime:new Date})}}ensureParents(t){let n=ta(t);n!=="/"&&(this.data.has(n)||(this.ensureParents(n),this.data.set(n,{type:"directory",mode:16877,mtime:new Date})))}resolve(t){let n="",r=new Set;for(let s of ln(t).slice(1).split("/")){n=`${n}/${s}`;let o=0,i=this.data.get(n);for(;i?.type==="symlink"&&o<40;){if(r.has(n))throw new Error(`ELOOP: too many levels of symbolic links, '${t}'`);r.add(n);let a=i.target;n=a.startsWith("/")?ln(a):ln(ta(n)+"/"+a),i=this.data.get(n),o++}if(o>=40)throw new Error(`ELOOP: too many levels of symbolic links, '${t}'`)}return n}resolveParent(t){let n=ln(t);if(n==="/")return"/";let r=n.slice(1).split("/");if(r.length<=1)return n;let s="",o=new Set;for(let i=0;i0)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);let o=r==="/"?"/":`${r}/`;for(let i of[...this.data.keys()])i.startsWith(o)&&this.data.delete(i)}this.data.delete(r)}async mv(t,n){let r=ln(t);if(!this.data.has(r))throw new Error(`ENOENT: no such file or directory, rename '${t}'`);let s=ln(n);if(r===s)return;this.ensureParents(s);let o=r==="/"?"/":`${r}/`,i=s==="/"?"/":`${s}/`;for(let a of[...this.data.keys()])a===r?(this.data.set(s,this.data.get(a)),this.data.delete(a)):a.startsWith(o)&&(this.data.set(i+a.slice(o.length),this.data.get(a)),this.data.delete(a))}async chmod(t,n){let r=this.data.get(this.resolve(t));if(!r)throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);r.mode=r.mode&-4096|n&4095}async readlink(t){let n=this.resolveParent(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return r.target}async symlink(t,n){let r=ln(n);if(this.data.has(r))throw new Error(`EEXIST: file already exists, symlink '${n}'`);this.ensureParents(r),this.data.set(r,{type:"symlink",target:t,mode:40960,mtime:new Date})}};Nn();export{ea as Git,nf as MemoryFileSystem,$w as composeGitHooks,Tk as createGit,Un as findRepo,pe as isRejection}; +diff --git a/dist/repo/index.js b/dist/repo/index.js +index b57f676f2a98aaf12ff7cb857c18e4b19d3299a5..708cd46ff34e58889540414269acdf99b6f85546 100644 +--- a/dist/repo/index.js ++++ b/dist/repo/index.js +@@ -1,41 +1,41 @@ +-var Ke=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,n)=>(typeof require<"u"?require:e)[n]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var Vt=(()=>{let t=new Array(256);for(let e=0;e<256;e++)t[e]=(e>>4).toString(16)+(e&15).toString(16);return t})();function Ae(t){let e="";for(let n=0;n<20;n++)e+=Vt[t[n]];return e}function ut(t,e){let n="";for(let r=0;r<20;r++)n+=Vt[t[e+r]];return n}function Ie(t){let e=new Uint8Array(20);for(let n=0;n<20;n++)e[n]=parseInt(t.slice(n*2,n*2+2),16);return e}var jr=new TextEncoder;function mt(t){return typeof t=="string"?jr.encode(t):t}function Mr(){if(typeof globalThis.Bun<"u")return()=>{let t=new Bun.CryptoHasher("sha1"),e={update(n){return t.update(mt(n)),e},hex:()=>Promise.resolve(t.digest("hex"))};return e};try{let t=Ke(["node","crypto"].join(":"));if(typeof t.createHash=="function")return()=>{let e=t.createHash("sha1"),n={update(r){return e.update(mt(r)),n},hex:()=>Promise.resolve(e.digest("hex"))};return n}}catch{}if(typeof globalThis.crypto?.subtle?.digest=="function")return()=>{let t=[],e={update(n){return t.push(mt(n)),e},async hex(){let n=0;for(let a of t)n+=a.byteLength;let r=new Uint8Array(n),i=0;for(let a of t)r.set(a,i),i+=a.byteLength;let s=await crypto.subtle.digest("SHA-1",r);return Ae(new Uint8Array(s))}};return e};throw new Error("No SHA-1 implementation available. Requires Bun, Node.js, Deno, or a browser with Web Crypto.")}var qt=Mr(),ht=qt;async function Ye(t){return qt().update(t).hex()}var te=Uint8Array,Ee=Uint16Array,Ar=Int32Array,Kt=new te([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),Yt=new te([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),Lr=new te([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Xt=(t,e)=>{let n=new Ee(31);for(let i=0;i<31;++i)n[i]=e+=1<>1|(t&21845)<<1;e=(e&52428)>>2|(e&13107)<<2,e=(e&61680)>>4|(e&3855)<<4,gt[t]=((e&65280)>>8|(e&255)<<8)>>1}var Le=(t,e,n)=>{let r=t.length,i=0,s=new Ee(e);for(;i>c]=f}}else for(o=new Ee(r),i=0;i>15-t[i]);return o},De=new te(288);for(let t=0;t<144;++t)De[t]=8;for(let t=144;t<256;++t)De[t]=9;for(let t=256;t<280;++t)De[t]=7;for(let t=280;t<288;++t)De[t]=8;var Jt=new te(32);for(let t=0;t<32;++t)Jt[t]=5;var Hr=Le(De,9,1),Br=Le(Jt,5,1),dt=t=>{let e=t[0];for(let n=1;ne&&(e=t[n]);return e},ee=(t,e,n)=>{let r=e/8|0;return(t[r]|t[r+1]<<8)>>(e&7)&n},pt=(t,e)=>{let n=e/8|0;return(t[n]|t[n+1]<<8|t[n+2]<<16)>>(e&7)},Qt=t=>(t+7)/8|0,Nr=(t,e,n)=>((e==null||e<0)&&(e=0),(n==null||n>t.length)&&(n=t.length),new te(t.subarray(e,n))),se=(t,e)=>{let n=["unexpected EOF","invalid block type","invalid length/literal","invalid distance"];throw new Error(e||n[t]||"unknown inflate error")},en=(t,e,n,r)=>{let i=t.length,s=r?r.length:0;if(!i||e.f&&!e.l)return n||new te(0);let a=!n,o=a||e.i!=2,c=e.i;a&&(n=new te(i*3));let f=E=>{let C=n.length;if(E>C){let v=new te(Math.max(C*2,E));v.set(n),n=v}},l=e.f||0,u=e.p||0,m=e.b||0,h=e.l,d=e.d,g=e.m,p=e.n,b=i*8;do{if(!h){l=ee(t,u,1);let k=ee(t,u+1,3);if(u+=3,k)if(k==1)h=Hr,d=Br,g=9,p=5;else if(k==2){let w=ee(t,u,31)+257,R=ee(t,u+10,15)+4,P=w+ee(t,u+5,31)+1;u+=14;let I=new te(P),T=new te(19);for(let W=0;W>4;if(y<16)I[W++]=y;else{let S=0,L=0;for(y==16?(L=3+ee(t,u,3),u+=2,S=I[W-1]):y==17?(L=3+ee(t,u,7),u+=3):y==18&&(L=11+ee(t,u,127),u+=7);L--;)I[W++]=S}}let ie=I.subarray(0,w),xe=I.subarray(w);g=dt(ie),p=dt(xe),h=Le(ie,g,1),d=Le(xe,p,1)}else se(1);else{let w=Qt(u)+4,R=t[w-4]|t[w-3]<<8,P=w+R;if(P>i){c&&se(0);break}o&&f(m+R),n.set(t.subarray(w,P),m),e.b=m+=R,e.p=u=P*8,e.f=l;continue}if(u>b){c&&se(0);break}}o&&f(m+131072);let E=(1<>4;if(u+=k&15,u>b){c&&se(0);break}if(k||se(2),w<256)n[m++]=w;else if(w==256){v=u,h=null;break}else{let R=w-254;if(w>264){let j=w-257,A=Kt[j];R=ee(t,u,(1<>4;P||se(3),u+=P&15;let T=Dr[I];if(I>3){let j=Yt[I];T+=pt(t,u)&(1<b){c&&se(0);break}o&&f(m+131072);let O=m+R;if(m(((t[0]&15)!=8||t[0]>>4>7||(t[0]<<8|t[1])%31)&&se(0,"invalid zlib data"),t[1]&32&&se(0,"zlib dictionaries are not supported"),2);function nn(t){let e=tn(t);return en(t.subarray(e,-4),{i:2})}function yt(t){let e=tn(t),n={i:2},r=en(t.subarray(e),n),i=Qt(n.p);return{result:r,bytesConsumed:e+i+4}}async function Gr(){let t;if(!(typeof document<"u"))try{t=Ke(["node","zlib"].join(":"))}catch{try{t=await import(["node","zlib"].join(":"))}catch{}}if(t&&typeof t.deflateSync=="function"&&typeof t.inflateSync=="function"){let r=null;try{let i=t.inflateSync(t.deflateSync(Buffer.from("x")),{info:!0});i?.engine&&typeof i.engine.bytesWritten=="number"&&(r=s=>{let a=t.inflateSync(s,{info:!0});return{result:new Uint8Array(a.buffer),bytesConsumed:a.engine.bytesWritten}})}catch{}return{deflateSync:i=>new Uint8Array(t.deflateSync(i)),inflateSync:i=>new Uint8Array(t.inflateSync(i)),inflateWithConsumed:r??yt}}let n;return typeof globalThis.CompressionStream=="function"?n=async r=>{let i=new CompressionStream("deflate"),s=i.writable.getWriter();return s.write(r),s.close(),new Uint8Array(await new Response(i.readable).arrayBuffer())}:n=()=>{throw new Error("No deflate implementation available. Requires node:zlib or CompressionStream.")},{deflateSync:n,inflateSync:nn,inflateWithConsumed:yt}}var Ur=null;function Fr(){return Ur??=Gr()}async function rn(t,e){let n=await Fr(),{result:r,bytesConsumed:i}=n.inflateWithConsumed(t);if(r.byteLength!==e)throw new Error(`Inflate size mismatch: got ${r.byteLength}, expected ${e}`);return{result:r,bytesConsumed:i}}var sn=1346454347,_r=2,Wr=1,zr=2,Vr=3,qr=4,Xe=6,wt=7,Kr={[Wr]:"commit",[zr]:"tree",[Vr]:"blob",[qr]:"tag"};async function fn(t,e){let n=new DataView(t.buffer,t.byteOffset,t.byteLength),r=n.getUint32(0);if(r!==sn)throw new Error(`Invalid pack signature: 0x${r.toString(16)} (expected 0x${sn.toString(16)})`);let i=n.getUint32(4);if(i!==_r)throw new Error(`Unsupported pack version: ${i}`);if(t.byteLength>=32){let f=ut(t,t.byteLength-20),l=ht();l.update(t.subarray(0,t.byteLength-20));let u=await l.hex();if(u!==f)throw new Error(`pack checksum mismatch: expected ${f}, computed ${u}`)}let s=n.getUint32(8),a=[],o=12;for(let f=0;f({...f,offset:a[l].headerOffset,nextOffset:a[l].nextOffset}))}async function Yr(t,e){let n=e,r=t[e++],i=r>>4&7,s=r&15,a=4;for(;r&128;)r=t[e++],s|=(r&127)<on)throw new Error(`delta chain depth ${a} exceeds limit of ${on}`);let o=r[s];if(o)return o;let c=t[s];if(c.typeNum!==Xe&&c.typeNum!==wt){let h=Kr[c.typeNum];if(!h)throw new Error(`Unknown object type: ${c.typeNum}`);let d={type:h,content:c.inflated,hash:await bt(h,c.inflated)};return r[s]=d,d}if(c.typeNum===Xe){let h=n.get(c.baseOffset);if(h===void 0)throw new Error(`OFS_DELTA base not found at offset ${c.baseOffset}`);let d=await i(h,a+1),g=an(d.content,c.inflated),p={type:d.type,content:g,hash:await bt(d.type,g)};return r[s]=p,p}let f=await Zr(t,r,c.baseHash,i),l;if(f!==void 0)l=await i(f,a+1);else if(e){let h=await e(c.baseHash);h&&(l=h)}if(!l)throw new Error(`REF_DELTA base not found for hash ${c.baseHash}`);let u=an(l.content,c.inflated),m={type:l.type,content:u,hash:await bt(l.type,u)};return r[s]=m,m}for(let s=0;s0)o.set(e.subarray(n,n+f),c),c+=f,n+=f;else throw new Error("Unexpected delta opcode 0x00 (reserved)")}if(c!==s)throw new Error(`Delta produced ${c} bytes, expected ${s}`);return o}function cn(t,e){let n=0,r=0,i;do i=t[e++],n|=(i&127)<0&&i[i.length-1]!==".."?i.pop():i.push(".."):i.push(a));let s=i.join("/");return e&&(s=`/${s}`),n&&s.length>1&&!s.endsWith("/")&&(s+="/"),s||(e?"/":n?"./":".")}function oe(...t){if(t.length===0)return".";let e=t.filter(n=>n!=="").join("/");return e===""?".":Qr(e)}function ln(t){if(t==="")return".";if(t==="/")return"/";let e=t.length;for(;e>1&&t.charCodeAt(e-1)===47;)e--;let n=t.slice(0,e),r=n.lastIndexOf("/");return r===-1?".":r===0?"/":n.slice(0,r)}var ei=new TextEncoder,Lo=new TextDecoder;function un(t,e){let n=ei.encode(`${t} ${e.byteLength}\0`),r=new Uint8Array(n.byteLength+e.byteLength);return r.set(n),r.set(e,n.byteLength),r}function He(t){let e=t.indexOf("<"),n=t.indexOf(">");if(e===-1||n===-1)throw new Error(`Malformed identity line: "${t}"`);let r=t.slice(0,e).trimEnd(),i=t.slice(e+1,n),s=t.slice(n+2),[a="0",o="+0000"]=s.split(" "),c=parseInt(a,10);return{name:r,email:i,timestamp:c,timezone:o}}function Be(t){return`${t.name} <${t.email}> ${t.timestamp} ${t.timezone}`}var ti=new TextEncoder,ni=new TextDecoder;function mn(t){let e=ni.decode(t),n=e.indexOf(` ++var Ze=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,n)=>(typeof require<"u"?require:e)[n]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var Jt=(()=>{let t=new Array(256);for(let e=0;e<256;e++)t[e]=(e>>4).toString(16)+(e&15).toString(16);return t})();function De(t){let e="";for(let n=0;n<20;n++)e+=Jt[t[n]];return e}function ht(t,e){let n="";for(let r=0;r<20;r++)n+=Jt[t[e+r]];return n}function Ee(t){let e=new Uint8Array(20);for(let n=0;n<20;n++)e[n]=parseInt(t.slice(n*2,n*2+2),16);return e}var Gr=new TextEncoder;function dt(t){return typeof t=="string"?Gr.encode(t):t}function Ur(){if(typeof globalThis.Bun<"u")return()=>{let t=new Bun.CryptoHasher("sha1"),e={update(n){return t.update(dt(n)),e},hex:()=>Promise.resolve(t.digest("hex"))};return e};try{let t=Ze(["node","crypto"].join(":"));if(typeof t.createHash=="function")return()=>{let e=t.createHash("sha1"),n={update(r){return e.update(dt(r)),n},hex:()=>Promise.resolve(e.digest("hex"))};return n}}catch{}if(typeof globalThis.crypto?.subtle?.digest=="function")return()=>{let t=[],e={update(n){return t.push(dt(n)),e},async hex(){let n=0;for(let a of t)n+=a.byteLength;let r=new Uint8Array(n),i=0;for(let a of t)r.set(a,i),i+=a.byteLength;let s=await crypto.subtle.digest("SHA-1",r);return De(new Uint8Array(s))}};return e};throw new Error("No SHA-1 implementation available. Requires Bun, Node.js, Deno, or a browser with Web Crypto.")}var Qt=Ur(),pt=Qt;async function Je(t){return Qt().update(t).hex()}var ne=Uint8Array,ke=Uint16Array,Fr=Int32Array,en=new ne([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),tn=new ne([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),_r=new ne([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),nn=(t,e)=>{let n=new ke(31);for(let i=0;i<31;++i)n[i]=e+=1<>1|(t&21845)<<1;e=(e&52428)>>2|(e&13107)<<2,e=(e&61680)>>4|(e&3855)<<4,bt[t]=((e&65280)>>8|(e&255)<<8)>>1}var He=(t,e,n)=>{let r=t.length,i=0,s=new ke(e);for(;i>c]=f}}else for(o=new ke(r),i=0;i>15-t[i]);return o},Be=new ne(288);for(let t=0;t<144;++t)Be[t]=8;for(let t=144;t<256;++t)Be[t]=9;for(let t=256;t<280;++t)Be[t]=7;for(let t=280;t<288;++t)Be[t]=8;var sn=new ne(32);for(let t=0;t<32;++t)sn[t]=5;var zr=He(Be,9,1),Vr=He(sn,5,1),gt=t=>{let e=t[0];for(let n=1;ne&&(e=t[n]);return e},te=(t,e,n)=>{let r=e/8|0;return(t[r]|t[r+1]<<8)>>(e&7)&n},yt=(t,e)=>{let n=e/8|0;return(t[n]|t[n+1]<<8|t[n+2]<<16)>>(e&7)},on=t=>(t+7)/8|0,qr=(t,e,n)=>((e==null||e<0)&&(e=0),(n==null||n>t.length)&&(n=t.length),new ne(t.subarray(e,n))),oe=(t,e)=>{let n=["unexpected EOF","invalid block type","invalid length/literal","invalid distance"];throw new Error(e||n[t]||"unknown inflate error")},an=(t,e,n,r)=>{let i=t.length,s=r?r.length:0;if(!i||e.f&&!e.l)return n||new ne(0);let a=!n,o=a||e.i!=2,c=e.i;a&&(n=new ne(i*3));let f=E=>{let C=n.length;if(E>C){let j=new ne(Math.max(C*2,E));j.set(n),n=j}},l=e.f||0,u=e.p||0,m=e.b||0,h=e.l,d=e.d,g=e.m,p=e.n,b=i*8;do{if(!h){l=te(t,u,1);let P=te(t,u+1,3);if(u+=3,P)if(P==1)h=zr,d=Vr,g=9,p=5;else if(P==2){let w=te(t,u,31)+257,R=te(t,u+10,15)+4,O=w+te(t,u+5,31)+1;u+=14;let I=new ne(O),T=new ne(19);for(let z=0;z>4;if(y<16)I[z++]=y;else{let S=0,D=0;for(y==16?(D=3+te(t,u,3),u+=2,S=I[z-1]):y==17?(D=3+te(t,u,7),u+=3):y==18&&(D=11+te(t,u,127),u+=7);D--;)I[z++]=S}}let J=I.subarray(0,w),he=I.subarray(w);g=gt(J),p=gt(he),h=He(J,g,1),d=He(he,p,1)}else oe(1);else{let w=on(u)+4,R=t[w-4]|t[w-3]<<8,O=w+R;if(O>i){c&&oe(0);break}o&&f(m+R),n.set(t.subarray(w,O),m),e.b=m+=R,e.p=u=O*8,e.f=l;continue}if(u>b){c&&oe(0);break}}o&&f(m+131072);let E=(1<>4;if(u+=P&15,u>b){c&&oe(0);break}if(P||oe(2),w<256)n[m++]=w;else if(w==256){j=u,h=null;break}else{let R=w-254;if(w>264){let $=w-257,A=en[$];R=te(t,u,(1<>4;O||oe(3),u+=O&15;let T=Wr[I];if(I>3){let $=tn[I];T+=yt(t,u)&(1<<$)-1,u+=$}if(u>b){c&&oe(0);break}o&&f(m+131072);let k=m+R;if(m(((t[0]&15)!=8||t[0]>>4>7||(t[0]<<8|t[1])%31)&&oe(0,"invalid zlib data"),t[1]&32&&oe(0,"zlib dictionaries are not supported"),2);function fn(t){let e=cn(t);return an(t.subarray(e,-4),{i:2})}function wt(t){let e=cn(t),n={i:2},r=an(t.subarray(e),n),i=on(n.p);return{result:r,bytesConsumed:e+i+4}}async function Kr(){let t;if(!(typeof document<"u"))try{t=Ze(["node","zlib"].join(":"))}catch{try{t=await import(["node","zlib"].join(":"))}catch{}}if(t&&typeof t.deflateSync=="function"&&typeof t.inflateSync=="function"){let r=null;try{let i=t.inflateSync(t.deflateSync(Buffer.from("x")),{info:!0});i?.engine&&typeof i.engine.bytesWritten=="number"&&(r=s=>{let a=t.inflateSync(s,{info:!0});return{result:new Uint8Array(a.buffer),bytesConsumed:a.engine.bytesWritten}})}catch{}return{deflateSync:i=>new Uint8Array(t.deflateSync(i)),inflateSync:i=>new Uint8Array(t.inflateSync(i)),inflateWithConsumed:r??wt}}let n;return typeof globalThis.CompressionStream=="function"?n=async r=>{let i=new CompressionStream("deflate"),s=i.writable.getWriter();return s.write(r),s.close(),new Uint8Array(await new Response(i.readable).arrayBuffer())}:n=()=>{throw new Error("No deflate implementation available. Requires node:zlib or CompressionStream.")},{deflateSync:n,inflateSync:fn,inflateWithConsumed:wt}}var Yr=null;function Xr(){return Yr??=Kr()}async function ln(t,e){let n=await Xr(),{result:r,bytesConsumed:i}=n.inflateWithConsumed(t);if(r.byteLength!==e)throw new Error(`Inflate size mismatch: got ${r.byteLength}, expected ${e}`);return{result:r,bytesConsumed:i}}var un=1346454347,Zr=2,Jr=1,Qr=2,ei=3,ti=4,Qe=6,xt=7,ni={[Jr]:"commit",[Qr]:"tree",[ei]:"blob",[ti]:"tag"};async function pn(t,e){let n=new DataView(t.buffer,t.byteOffset,t.byteLength),r=n.getUint32(0);if(r!==un)throw new Error(`Invalid pack signature: 0x${r.toString(16)} (expected 0x${un.toString(16)})`);let i=n.getUint32(4);if(i!==Zr)throw new Error(`Unsupported pack version: ${i}`);if(t.byteLength>=32){let f=ht(t,t.byteLength-20),l=pt();l.update(t.subarray(0,t.byteLength-20));let u=await l.hex();if(u!==f)throw new Error(`pack checksum mismatch: expected ${f}, computed ${u}`)}let s=n.getUint32(8),a=[],o=12;for(let f=0;f({...f,offset:a[l].headerOffset,nextOffset:a[l].nextOffset}))}async function ri(t,e){let n=e,r=t[e++],i=r>>4&7,s=r&15,a=4;for(;r&128;)r=t[e++],s|=(r&127)<mn)throw new Error(`delta chain depth ${a} exceeds limit of ${mn}`);let o=r[s];if(o)return o;let c=t[s];if(c.typeNum!==Qe&&c.typeNum!==xt){let h=ni[c.typeNum];if(!h)throw new Error(`Unknown object type: ${c.typeNum}`);let d={type:h,content:c.inflated,hash:await Rt(h,c.inflated)};return r[s]=d,d}if(c.typeNum===Qe){let h=n.get(c.baseOffset);if(h===void 0)throw new Error(`OFS_DELTA base not found at offset ${c.baseOffset}`);let d=await i(h,a+1),g=hn(d.content,c.inflated),p={type:d.type,content:g,hash:await Rt(d.type,g)};return r[s]=p,p}let f=await si(t,r,c.baseHash,i),l;if(f!==void 0)l=await i(f,a+1);else if(e){let h=await e(c.baseHash);h&&(l=h)}if(!l)throw new Error(`REF_DELTA base not found for hash ${c.baseHash}`);let u=hn(l.content,c.inflated),m={type:l.type,content:u,hash:await Rt(l.type,u)};return r[s]=m,m}for(let s=0;s0)o.set(e.subarray(n,n+f),c),c+=f,n+=f;else throw new Error("Unexpected delta opcode 0x00 (reserved)")}if(c!==s)throw new Error(`Delta produced ${c} bytes, expected ${s}`);return o}function dn(t,e){let n=0,r=0,i;do i=t[e++],n|=(i&127)<0&&i[i.length-1]!==".."?i.pop():i.push(".."):i.push(a));let s=i.join("/");return e&&(s=`/${s}`),n&&s.length>1&&!s.endsWith("/")&&(s+="/"),s||(e?"/":n?"./":".")}function ae(...t){if(t.length===0)return".";let e=t.filter(n=>n!=="").join("/");return e===""?".":ai(e)}function gn(t){if(t==="")return".";if(t==="/")return"/";let e=t.length;for(;e>1&&t.charCodeAt(e-1)===47;)e--;let n=t.slice(0,e),r=n.lastIndexOf("/");return r===-1?".":r===0?"/":n.slice(0,r)}var ci=new TextEncoder,Vo=new TextDecoder;function yn(t,e){let n=ci.encode(`${t} ${e.byteLength}\0`),r=new Uint8Array(n.byteLength+e.byteLength);return r.set(n),r.set(e,n.byteLength),r}function Ne(t){let e=t.indexOf("<"),n=t.indexOf(">");if(e===-1||n===-1)throw new Error(`Malformed identity line: "${t}"`);let r=t.slice(0,e).trimEnd(),i=t.slice(e+1,n),s=t.slice(n+2),[a="0",o="+0000"]=s.split(" "),c=parseInt(a,10);return{name:r,email:i,timestamp:c,timezone:o}}function Ge(t){return`${t.name} <${t.email}> ${t.timestamp} ${t.timezone}`}var fi=new TextEncoder,li=new TextDecoder;function bn(t){let e=li.decode(t),n=e.indexOf(` + + `),r=n===-1?e:e.slice(0,n),i=n===-1?"":e.slice(n+2),s="",a=[],o,c;for(let f of r.split(` +-`)){let l=f.indexOf(" ");if(l===-1)continue;let u=f.slice(0,l),m=f.slice(l+1);switch(u){case"tree":s=m;break;case"parent":a.push(m);break;case"author":o=He(m);break;case"committer":c=He(m);break}}if(!s)throw new Error("Commit missing tree field");if(!o)throw new Error("Commit missing author field");if(!c)throw new Error("Commit missing committer field");return{type:"commit",tree:s,parents:a,author:o,committer:c,message:i}}function Ne(t){let e=[];e.push(`tree ${t.tree}`);for(let n of t.parents)e.push(`parent ${n}`);return e.push(`author ${Be(t.author)}`),e.push(`committer ${Be(t.committer)}`),e.push(""),e.push(t.message),ti.encode(e.join(` +-`))}var ri=new TextEncoder,ii=new TextDecoder;function hn(t){let e=ii.decode(t),n=e.indexOf(` ++`)){let l=f.indexOf(" ");if(l===-1)continue;let u=f.slice(0,l),m=f.slice(l+1);switch(u){case"tree":s=m;break;case"parent":a.push(m);break;case"author":o=Ne(m);break;case"committer":c=Ne(m);break}}if(!s)throw new Error("Commit missing tree field");if(!o)throw new Error("Commit missing author field");if(!c)throw new Error("Commit missing committer field");return{type:"commit",tree:s,parents:a,author:o,committer:c,message:i}}function Ue(t){let e=[];e.push(`tree ${t.tree}`);for(let n of t.parents)e.push(`parent ${n}`);return e.push(`author ${Ge(t.author)}`),e.push(`committer ${Ge(t.committer)}`),e.push(""),e.push(t.message),fi.encode(e.join(` ++`))}var ui=new TextEncoder,mi=new TextDecoder;function wn(t){let e=mi.decode(t),n=e.indexOf(` + + `),r=n===-1?e:e.slice(0,n),i=n===-1?"":e.slice(n+2),s="",a="commit",o="",c;for(let f of r.split(` +-`)){let l=f.indexOf(" ");if(l===-1)continue;let u=f.slice(0,l),m=f.slice(l+1);switch(u){case"object":s=m;break;case"type":a=m;break;case"tag":o=m;break;case"tagger":c=He(m);break}}if(!s)throw new Error("Tag missing object field");if(!o)throw new Error("Tag missing tag name field");if(!c)throw new Error("Tag missing tagger field");return{type:"tag",object:s,objectType:a,name:o,tagger:c,message:i}}function dn(t){let e=[];return e.push(`object ${t.object}`),e.push(`type ${t.objectType}`),e.push(`tag ${t.name}`),e.push(`tagger ${Be(t.tagger)}`),e.push(""),e.push(t.message),ri.encode(e.join(` +-`))}async function N(t,e,n){let r=await t.objectStore.write(e,n);return t.hooks?.onObjectWrite?.({repo:t,type:e,hash:r}),r}async function F(t,e){return t.objectStore.read(e)}async function pn(t,e){return t.objectStore.exists(e)}async function gn(t,e){return t.objectStore.findByPrefix(e)}function J(t){let e=Math.min(t.length,8e3);for(let n=0;ns+a.byteLength,0),r=new Uint8Array(n),i=0;for(let s of e)r.set(s,i),i+=s.byteLength;return r}function li(t){let e=1,n="";for(;e=c.length||c[f+1]==="\r"&&f+2>=c.length){if(o++,o0;)r+=" ",s--}}function mi(t){let e={},n=null,r=t.split(` +-`),i=0;for(;i0;){let s=t.slice(0,n).match(/^(.+?)~(\d*)$/);if(s&&s[1]!==void 0&&s[2]!==void 0){let c=s[2]===""?1:parseInt(s[2],10);e.unshift({type:"tilde",n:c}),n=s[1].length;continue}let a=t.slice(0,n).match(/^(.+?)\^{([^}]*)}$/);if(a&&a[1]!==void 0&&a[2]!==void 0){e.unshift({type:"peel",target:a[2]}),n=a[1].length;continue}let o=t.slice(0,n).match(/^(.+?)\^(\d*)$/);if(o&&o[1]!==void 0&&o[2]!==void 0){let c=o[2]===""?1:parseInt(o[2],10);e.unshift({type:"caret",n:c}),n=o[1].length;continue}break}let r=t.slice(0,n),i=r.match(/^(.+?)@\{(\d+)\}$/);return i&&i[1]!==void 0&&i[2]!==void 0?{base:i[1],reflogIndex:parseInt(i[2],10),suffixes:e}:{base:r,suffixes:e}}var wi=["HEAD","FETCH_HEAD","ORIG_HEAD","MERGE_HEAD","CHERRY_PICK_HEAD","REBASE_HEAD"];async function Ri(t,e){let n=await gn(t,e);if(n.length===0)return null;if(n.length>1)throw new It(e);return n[0]}var It=class extends Error{constructor(n){super(`short object ID ${n} is ambiguous`);this.prefix=n}};async function xi(t,e){if(e==="HEAD"||e==="@")return ne(t,"HEAD");if(wi.includes(e))return ne(t,e);if(/^[0-9a-f]{40}$/.test(e))return await pn(t,e)?e:null;if(/^[0-9a-f]{4,39}$/.test(e)){let s=await Ri(t,e);if(s)return s}if(e.startsWith("refs/")){let s=await ne(t,e);if(s)return s}let n=await ne(t,`refs/heads/${e}`);if(n)return n;let r=await ne(t,`refs/tags/${e}`);if(r)return r;let i=await ne(t,`refs/remotes/${e}`);return i||null}async function Ii(t,e,n){if(n===""||n==="commit")try{return await Ge(t,e)}catch{return null}if(n==="tree"){let i;try{i=await Ge(t,e)}catch{return null}return(await $(t,i)).tree}return(await F(t,e)).type!==n?null:e}async function Ei(t,e,n){let r=e;n.some(s=>s.type==="tilde"||s.type==="caret")&&(r=await Ge(t,r));for(let s of n)if(s.type==="peel"){if(!r)return null;r=await Ii(t,r,s.target)}else if(s.type==="tilde")for(let a=0;aa.parents.length||(r=a.parents[s.n-1]??null,!r))return null}return r}async function Rn(t,e){let{base:n,reflogIndex:r,suffixes:i}=bi(e);if(r!==void 0)return null;let s=await xi(t,n);return s?Ei(t,s,i):null}function xn(t){return t.length===4&&t.toLowerCase()===".git"}function In(t){if(t.length===0||t.includes("\0")||t.charCodeAt(0)===47||t.charCodeAt(t.length-1)===47)return!1;let e=t.split("/");for(let n of e)if(n.length===0||n==="."||n===".."||xn(n))return!1;return!0}function En(t,e){return e===t?!1:t==="/"?e.startsWith("/")&&e.length>1:e.startsWith(t+"/")}function On(t){if(t.length===0||t.charCodeAt(0)===47)return!1;let e=t.split("/");for(let n of e)if(n===".."||xn(n))return!1;return!0}var ta=new TextEncoder;function kn(t,e){return t.lstat?t.lstat(e):t.stat(e)}function fe(t){return typeof t=="string"?t==="120000":t===40960}function Je(t){return typeof t=="string"?t==="160000":t===57344}var Oi=1145655875,ki=2,Ue=new WeakMap;async function Qe(t,e){let n=oe(t.gitDir,"index");await t.fs.writeFile(n,await Cn(e));let r=await Tn(t,n);if(r===null){Ue.delete(e);return}if(vi(e,r)&&(await t.fs.writeFile(n,await Cn(e)),r=await Tn(t,n),r===null)){Ue.delete(e);return}Ue.set(e,r)}function Sn(t){let e=[...t].sort($n);return{version:ki,entries:e}}function me(){return{ctimeSeconds:0,ctimeNanoseconds:0,mtimeSeconds:0,mtimeNanoseconds:0,dev:0,ino:0,uid:0,gid:0,size:0}}function Ci(t,e=t.size){let n=Pn(t.mtime),r=t.ctime?Pn(t.ctime):{seconds:0,nanoseconds:0};return{ctimeSeconds:r.seconds,ctimeNanoseconds:r.nanoseconds,mtimeSeconds:n.seconds,mtimeNanoseconds:n.nanoseconds,dev:Oe(t.dev),ino:Oe(t.ino),uid:Oe(t.uid),gid:Oe(t.gid),size:Oe(e)}}function Pi(t){return t.isSymbolicLink?40960:t.isDirectory?16384:t.mode&73?33261:33188}async function vn(t,e,n){if(!t.workTree)return e;let r=n?new Set(n):null,i=[];for(let s of e.entries){if(s.stage!==0||Je(s.mode)||r&&!r.has(s.path)){i.push(s);continue}let a=await kn(t.fs,oe(t.workTree,s.path)).catch(()=>null);if(!a||Pi(a)!==s.mode){i.push(s);continue}i.push({...s,stat:Ci(a)})}return Si(e,i)}async function Cn(t){let e=new TextEncoder,n=[...t.entries].sort($n),r=[],i=12;for(let m of n){let h=e.encode(m.path);r.push(h);let d=62+h.byteLength+1;i+=Math.ceil(d/8)*8}i+=20;let s=new ArrayBuffer(i),a=new Uint8Array(s),o=new DataView(s),c=0;o.setUint32(c,Oi),c+=4,o.setUint32(c,t.version),c+=4,o.setUint32(c,n.length),c+=4;for(let m=0;me.path?1:t.stage-e.stage}function Pn(t){let e=jn(t);if(e===null)return{seconds:0,nanoseconds:0};let n=Math.floor(e/1e3);return{seconds:Oe(n),nanoseconds:(e-n*1e3)*1e6}}function jn(t){if(!(t instanceof Date))return null;let e=Math.trunc(t.getTime());return Number.isFinite(e)?e:null}function Oe(t){return t===void 0||!Number.isFinite(t)||t<0?0:Math.trunc(t)>>>0}function Ti(t){return t.mtimeSeconds*1e3+Math.floor(t.mtimeNanoseconds/1e6)}function Si(t,e){let n={...t,entries:e},r=Ue.get(t);return r&&Ue.set(n,r),n}async function Tn(t,e){let{mtime:n}=await t.fs.stat(e);return jn(n)===null?null:n}function vi(t,e){let n=Math.trunc(e.getTime()),r=!1;for(let i=0;ie?1:0}var $i=7;function An(t){return t.slice(0,$i)}function Ln(t){let e=t.indexOf(` +-`);return e===-1?t:t.slice(0,e)}async function Et(t,e){return Hn(t,e,"")}async function Hn(t,e,n){let r=[],i=new Map;for(let a of e){let o=n?a.path.slice(n.length+1):a.path,c=o.indexOf("/");if(c===-1)r.push({mode:ji(a.mode),name:o,hash:a.hash});else{let f=o.slice(0,c),l=i.get(f);l||(l=[],i.set(f,l)),l.push(a)}}for(let[a,o]of i){let c=n?`${n}/${a}`:a,f=await Hn(t,o,c);r.push({mode:G.DIRECTORY,name:a,hash:f})}r.sort((a,o)=>{let c=a.mode===G.DIRECTORY?`${a.name}/`:a.name,f=o.mode===G.DIRECTORY?`${o.name}/`:o.name;return cf?1:0});let s=ge({type:"tree",entries:r});return N(t,"tree",s)}async function V(t,e,n=""){let r=await F(t,e);if(r.type!=="tree")throw new Error(`Expected tree object, got ${r.type}`);let i=ae(r.content),s=[];for(let a of i.entries){let o=n?`${n}/${a.name}`:a.name;if(a.mode===G.DIRECTORY){let c=await V(t,a.hash,o);s.push(...c)}else s.push({path:o,mode:a.mode,hash:a.hash})}return s}async function ke(t,e){if(!e)return new Map;let n=await V(t,e);return new Map(n.map(r=>[r.path,r]))}async function le(t,e,n){if(e===n)return[];let r=[];return await Bn(t,e,n,"",r),r.sort((i,s)=>Fe(i.path,s.path))}async function Dn(t,e){let n=await F(t,e);if(n.type!=="tree")throw new Error(`Expected tree object, got ${n.type}`);return ae(n.content).entries}async function Bn(t,e,n,r,i){if(e===n)return;let s=e?await Dn(t,e):[],a=n?await Dn(t,n):[],o=new Map;for(let l of s)o.set(l.name,l);let c=new Map;for(let l of a)c.set(l.name,l);let f=new Set;for(let l of s)f.add(l.name);for(let l of a)f.add(l.name);for(let l of f){let u=o.get(l),m=c.get(l),h=r?`${r}/${l}`:l;if(u&&m){if(u.hash===m.hash&&u.mode===m.mode)continue;let d=u.mode===G.DIRECTORY,g=m.mode===G.DIRECTORY;d&&g?await Bn(t,u.hash,m.hash,h,i):d?(await et(t,u.hash,h,"deleted",i),i.push({path:h,status:"added",newHash:m.hash,newMode:m.mode})):g?(i.push({path:h,status:"deleted",oldHash:u.hash,oldMode:u.mode}),await et(t,m.hash,h,"added",i)):i.push({path:h,status:"modified",oldHash:u.hash,newHash:m.hash,oldMode:u.mode,newMode:m.mode})}else if(u)u.mode===G.DIRECTORY?await et(t,u.hash,h,"deleted",i):i.push({path:h,status:"deleted",oldHash:u.hash,oldMode:u.mode});else{let d=m;d.mode===G.DIRECTORY?await et(t,d.hash,h,"added",i):i.push({path:h,status:"added",newHash:d.hash,newMode:d.mode})}}}async function et(t,e,n,r,i){let s=await V(t,e,n);for(let a of s)r==="added"?i.push({path:a.path,status:"added",newHash:a.hash,newMode:a.mode}):i.push({path:a.path,status:"deleted",oldHash:a.hash,oldMode:a.mode})}function ji(t){return t.toString(8).padStart(6,"0")}function Mi(t){let e=Math.min(t.length,8e3),n=0;for(let r=0;re*.01}function Nn(t,e,n,r){if(Mi(t)){let a=e.some(o=>o.test(t));return{matches:[],binary:a}}let i=t.split(` +-`);if(i.length>0&&i[i.length-1]===""&&i.pop(),n&&e.length>1&&!e.every(o=>i.some(c=>o.test(c))))return{matches:[],binary:!1};let s=[];for(let a=0;af.test(o));(r?!c:c)&&s.push({lineNo:a+1,line:o})}return{matches:s,binary:!1}}function Ai(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Gn(t,e){let n=e?.fixed?Ai(t):t;e?.wordRegexp&&(n=`\\b${n}\\b`);let r=e?.ignoreCase?"i":"";try{return new RegExp(n,r)}catch{return null}}var Li=new TextEncoder,Un=new TextDecoder,Ce=16877,Wn=33188,Di=33261,zn=40960;function q(t){let e=[];for(let n of t.split("/"))n==="."||n===""||(n===".."?e.pop():e.push(n));return"/"+e.join("/")}function Fn(t){let e=t.lastIndexOf("/");return e<=0?"/":t.slice(0,e)}function _n(t){switch(t){case G.EXECUTABLE:return Di;case G.SYMLINK:return zn;case G.DIRECTORY:return Ce;default:return Wn}}var Pe=class{constructor(e,n,r="/"){this.objectStore=e;this.rootTreeHash=n;this.rootPath=r;let i=q(r);this.overlay.set(i,{type:"directory",mode:Ce,mtime:this.epoch})}treeCache=new Map;overlay=new Map;removals=new Set;epoch=new Date(0);toRelative(e){let n=q(e),r=q(this.rootPath);if(n===r)return"";let i=r==="/"?"/":`${r}/`;return n.startsWith(i)?n.slice(i.length):null}async loadTreeDir(e){let n=this.treeCache.get(e);if(n)return n;if(e===""){let a=await this.objectStore.read(this.rootTreeHash);if(a.type!=="tree")return null;let o=ae(a.content);return this.treeCache.set("",o.entries),o.entries}let r=e.split("/"),i=await this.loadTreeDir("");if(!i)return null;let s="";for(let a of r){let o=i.find(u=>u.name===a);if(!o||o.mode!==G.DIRECTORY)return null;s=s?`${s}/${a}`:a;let c=this.treeCache.get(s);if(c){i=c;continue}let f=await this.objectStore.read(o.hash);if(f.type!=="tree")return null;let l=ae(f.content);this.treeCache.set(s,l.entries),i=l.entries}return i}async lookupTreeEntry(e){if(e==="")return null;let n=e.lastIndexOf("/"),r=n===-1?"":e.slice(0,n),i=n===-1?e:e.slice(n+1),s=await this.loadTreeDir(r);if(!s)return null;let a=s.find(o=>o.name===i);return a?{entry:a,dirEntries:s}:null}async isTreeDirectory(e){return e===""?!0:(await this.lookupTreeEntry(e))?.entry.mode===G.DIRECTORY}ensureOverlayParents(e){let n=Fn(e);n===q(this.rootPath)||n==="/"||this.overlay.has(n)||(this.ensureOverlayParents(n),this.overlay.set(n,{type:"directory",mode:Ce,mtime:new Date}))}async readFile(e){return Un.decode(await this.readFileBuffer(e))}async readFileBuffer(e){let n=q(e);if(this.removals.has(n))throw new Error(`ENOENT: no such file or directory, open '${e}'`);let r=this.overlay.get(n);if(r){if(r.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${e}'`);return r.content}let i=this.toRelative(n);if(i===null||i==="")throw new Error(`ENOENT: no such file or directory, open '${e}'`);let s=await this.lookupTreeEntry(i);if(!s)throw new Error(`ENOENT: no such file or directory, open '${e}'`);if(s.entry.mode===G.DIRECTORY)throw new Error(`EISDIR: illegal operation on a directory, read '${e}'`);let a=await this.objectStore.read(s.entry.hash);if(a.type!=="blob")throw new Error(`ENOENT: no such file or directory, open '${e}'`);return a.content}async writeFile(e,n){let r=q(e);this.removals.delete(r),this.ensureOverlayParents(r),this.overlay.set(r,{type:"file",content:typeof n=="string"?Li.encode(n):new Uint8Array(n),mode:Wn,mtime:new Date})}async exists(e){let n=q(e);if(this.removals.has(n))return!1;if(this.overlay.has(n))return!0;let r=this.toRelative(n);return r===null?!1:r===""||await this.isTreeDirectory(r)?!0:await this.lookupTreeEntry(r)!==null}async stat(e){let n=q(e);if(this.removals.has(n))throw new Error(`ENOENT: no such file or directory, stat '${e}'`);let r=this.overlay.get(n);if(r)return{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:r.type==="file"?r.content.byteLength:0,mtime:r.mtime};let i=this.toRelative(n);if(i===null)throw new Error(`ENOENT: no such file or directory, stat '${e}'`);if(i==="")return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:Ce,size:0,mtime:this.epoch};let s=await this.lookupTreeEntry(i);if(!s)throw new Error(`ENOENT: no such file or directory, stat '${e}'`);let{entry:a}=s,o=a.mode===G.DIRECTORY,c=a.mode===G.SYMLINK,f=0;return o||(f=(await this.objectStore.read(a.hash)).content.byteLength),{isFile:!o&&!c,isDirectory:o,isSymbolicLink:!1,mode:_n(a.mode),size:f,mtime:this.epoch}}async lstat(e){let n=q(e);if(this.removals.has(n))throw new Error(`ENOENT: no such file or directory, lstat '${e}'`);let r=this.overlay.get(n);if(r)return{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:r.type==="symlink",mode:r.mode,size:r.type==="file"?r.content.byteLength:r.type==="symlink"?r.target.length:0,mtime:r.mtime};let i=this.toRelative(n);if(i===null)throw new Error(`ENOENT: no such file or directory, lstat '${e}'`);if(i==="")return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:Ce,size:0,mtime:this.epoch};let s=await this.lookupTreeEntry(i);if(!s)throw new Error(`ENOENT: no such file or directory, lstat '${e}'`);let{entry:a}=s,o=a.mode===G.DIRECTORY,c=a.mode===G.SYMLINK,f=0;return o||(f=(await this.objectStore.read(a.hash)).content.byteLength),{isFile:!o&&!c,isDirectory:o,isSymbolicLink:c,mode:_n(a.mode),size:f,mtime:this.epoch}}async mkdir(e,n){let r=q(e);if(this.overlay.has(r)){if(this.overlay.get(r).type!=="directory")throw new Error(`EEXIST: file already exists, mkdir '${e}'`);if(!n?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${e}'`);return}let i=this.toRelative(r);if(i!==null&&!this.removals.has(r)&&(i===""||await this.isTreeDirectory(i))){if(!n?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${e}'`);return}let s=Fn(r);if(!(this.overlay.has(s)||await this.exists(s)))if(n?.recursive)await this.mkdir(s,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${e}'`);this.removals.delete(r),this.overlay.set(r,{type:"directory",mode:Ce,mtime:new Date})}async readdir(e){let n=q(e);if(this.removals.has(n))throw new Error(`ENOENT: no such file or directory, scandir '${e}'`);let r=new Set,i=this.toRelative(n);if(i!==null){let a=await this.loadTreeDir(i);if(a)for(let o of a){let c=n==="/"?`/${o.name}`:`${n}/${o.name}`;this.removals.has(c)||r.add(o.name)}}let s=n==="/"?"/":`${n}/`;for(let a of this.overlay.keys())if(a!==n&&a.startsWith(s)){let c=a.slice(s.length).split("/")[0];c&&!this.removals.has(n==="/"?`/${c}`:`${n}/${c}`)&&r.add(c)}if(r.size===0){if(this.overlay.get(n)?.type==="directory")return[];if(i!==null&&(i===""||await this.isTreeDirectory(i)))return[];throw new Error(`ENOENT: no such file or directory, scandir '${e}'`)}return[...r].sort()}async rm(e,n){let r=q(e);if(!await this.exists(r)){if(n?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${e}'`)}let s=r==="/"?"/":`${r}/`;if(n?.recursive)for(let a of[...this.overlay.keys()])a.startsWith(s)&&(this.overlay.delete(a),this.removals.add(a));if(this.overlay.delete(r),this.removals.add(r),n?.recursive){let a=this.toRelative(r);a!==null&&await this.markTreeChildrenRemoved(a,r)}}async markTreeChildrenRemoved(e,n){let r=await this.loadTreeDir(e);if(r)for(let i of r){let s=n==="/"?`/${i.name}`:`${n}/${i.name}`;if(this.removals.add(s),i.mode===G.DIRECTORY){let a=e?`${e}/${i.name}`:i.name;await this.markTreeChildrenRemoved(a,s)}}}async readlink(e){let n=q(e);if(this.removals.has(n))throw new Error(`ENOENT: no such file or directory, readlink '${e}'`);let r=this.overlay.get(n);if(r){if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${e}'`);return r.target}let i=this.toRelative(n);if(i===null||i==="")throw new Error(`EINVAL: invalid argument, readlink '${e}'`);let s=await this.lookupTreeEntry(i);if(!s||s.entry.mode!==G.SYMLINK)throw new Error(`EINVAL: invalid argument, readlink '${e}'`);let a=await this.objectStore.read(s.entry.hash);return Un.decode(a.content)}async symlink(e,n){let r=q(n);if(await this.exists(r))throw new Error(`EEXIST: file already exists, symlink '${n}'`);this.ensureOverlayParents(r),this.removals.delete(r),this.overlay.set(r,{type:"symlink",target:e,mode:zn,mtime:new Date})}};async function _e(t,e,n,r){let i=new Set,s=0;for(let a of e){if(!In(a.path))throw new Error(`refusing to check out unsafe path '${a.path}'`);let o=oe(r,a.path);if(!En(r,o))throw new Error(`refusing to check out path outside target directory: '${a.path}'`);let c=ln(o);if(c!==r&&!i.has(c)&&(await n.mkdir(c,{recursive:!0}),i.add(c)),Je(a.mode))await n.mkdir(o,{recursive:!0});else if(fe(a.mode)){let f=await B(t,a.hash);if(!On(f))throw new Error(`refusing to create symlink with unsafe target '${f}'`);n.symlink?await n.symlink(f,o):await n.writeFile(o,f)}else{let f=await ce(t,a.hash);await n.writeFile(o,f)}s++}return s}function We(t,e){let n=null,r;function i(s="/"){return n&&r===s||(n=new Pe(t.objectStore,e,s),r=s),n}return{treeHash:e,async readFile(s){let a=i(),o=s.startsWith("/")?s:"/"+s;return await a.exists(o)?a.readFile(o):null},async readFileBytes(s){let a=i(),o=s.startsWith("/")?s:"/"+s;return await a.exists(o)?a.readFileBuffer(o):null},async files(){return(await V(t,e)).map(a=>a.path)},fs(s="/"){return i(s)},async materialize(s,a="/"){let o=await V(t,e);return _e(t,o,s,a)}}}async function Hi(t,e){return ne(t,e)}async function ye(t,e){return Rn(t,e)}async function Bi(t){return Rt(t,"refs/heads")}async function Ni(t){return Rt(t,"refs/tags")}async function Gi(t){let e=await t.refStore.readRef("HEAD");if(!e)return{branch:null,ref:null,hash:null};if(e.type==="symbolic"){let n=await t.refStore.readRef(e.target),r=n?.type==="direct"?n.hash:null;return{branch:e.target.startsWith("refs/heads/")?xt(e.target):null,ref:e.target,hash:r}}return{branch:null,ref:null,hash:e.hash}}async function Ui(t,e){return $(t,e)}async function Fi(t,e){return ce(t,e)}async function _i(t,e){return B(t,e)}async function Wi(t,e){let n=await F(t,e);if(n.type!=="tree")throw new Error(`Expected tree object, got ${n.type}`);return ae(n.content).entries}async function zi(t,e,n){let r=await $(t,e);return We(t,r.tree).readFile(n)}function Vi(t){let e=0;for(let n=0;n!d.mode.startsWith("120")).sort((d,g)=>d.pathg.path?1:0),c=r?.allMatch??!1,f=r?.invert??!1,l=r?.maxCount,u=r?.maxDepth,m=r?.paths,h=[];for(let d of o){if(u!==void 0&&Vi(d.path)>u||m&&!m.some(E=>qi(E,d.path)))continue;let g=await B(t,d.hash),p=Nn(g,i,c,f);if(p.binary){h.push({path:d.path,matches:[],binary:!0});continue}if(p.matches.length===0)continue;let b=l!==void 0?p.matches.slice(0,l):p.matches;h.push({path:d.path,matches:b,binary:!1})}return h}function Q(t){if(t.length===0)return[];let e=t.split(` +-`);return e[e.length-1]===""&&e.pop(),e}var Yi=4,Vn=1024,tt=100,it=0,nt=1,Te=2;function kt(t){let e=1;for(;e*ett&&(n=e-tt),r-e>tt&&(r=e+tt);let i=0,s=1;for(let c=1;e-c>=n;c++){let f=t[e-c];if(f===it)i++;else if(f===Te)s++;else break}if(i===0)return!1;let a=0,o=1;for(let c=1;e+c<=r;c++){let f=t[e+c];if(f===it)a++;else if(f===Te)o++;else break}return a===0?!1:(a+=i,o+=s,o*Yi=m?l[p]=Te:l[p]=nt}let h=Math.min(kt(r),Vn);for(let p=s;p<=o;p++){let b=i[n[p]].len1;b===0?u[p]=it:b>=h?u[p]=Te:u[p]=nt}let d=[];for(let p=s;p<=a;p++)l[p]===nt||l[p]===Te&&!qn(l,p,s,a)?d.push(p):c[p]=1;let g=[];for(let p=s;p<=o;p++)u[p]===nt||u[p]===Te&&!qn(u,p,s,o)?g.push(p):f[p]=1;return{refIndex1:d,nreff1:d.length,refIndex2:g,nreff2:g.length}}var he=20,Kn=4,Qi=256,es=256,rt=2147483647;function K(t,e){return t[e]??0}function ts(t,e,n,r,i,s,a,o,c,f){let l=e-s,u=n-i,m=e-i,h=n-s,d=m-h&1,g=m,p=m,b=h,E=h;a[m]=e,o[h]=n;for(let C=1;;C++){let v=!1;g>l?a[--g-1]=-1:++g,p=g;k-=2){let w;K(a,k-1)>=K(a,k+1)?w=K(a,k-1)+1:w=K(a,k+1);let R=w,P=w-k;for(;whe&&(v=!0),a[k]=w,d&&b<=k&&k<=E&&K(o,k)<=w)return{i1:w,i2:P,minLo:!0,minHi:!0}}b>l?o[--b-1]=rt:++b,E=b;k-=2){let w;K(o,k-1)e&&P>i&&t[w-1]===r[P-1];)w--,P--;if(R-w>he&&(v=!0),o[k]=w,!d&&g<=k&&k<=p&&w<=K(a,k))return{i1:w,i2:P,minLo:!0,minHi:!0}}if(!c){if(v&&C>Qi){let k=0,w=null;for(let R=p;R>=g;R-=2){let P=R>m?R-m:m-R,I=K(a,R),T=I-R,O=I-e+(T-i)-P;if(O>Kn*C&&O>k&&e+he<=I&&I=b;R-=2){let P=R>h?R-h:h-R,I=K(o,R),T=I-R,O=n-I+(s-T)-P;if(O>Kn*C&&O>k&&e=f){let k=-1,w=-1;for(let I=p;I>=g;I-=2){let T=Math.min(K(a,I),n),O=T-I;s=b;I-=2){let T=Math.max(e,K(o,I)),O=T-I;O=Yn)return Yn}return-1}function Jn(t,e,n){let r={endOfFile:!1,indent:-1,preBlank:0,preIndent:-1,postBlank:0,postIndent:-1};n>=e?(r.endOfFile=!0,r.indent=-1):(r.endOfFile=!1,r.indent=Ot(t[n]));for(let i=n-1;i>=0&&(r.preIndent=Ot(t[i]),r.preIndent===-1);i--)if(r.preBlank+=1,r.preBlank===Xn){r.preIndent=0;break}for(let i=n+1;it.preIndent?e.penalty+=s?cs:as:i===t.preIndent||(t.postIndent!==-1&&t.postIndent>i?e.penalty+=s?ls:fs:e.penalty+=s?ms:us))}function ds(t,e){let n=(t.effectiveIndent>e.effectiveIndent?1:0)-(t.effectiveIndente[u]===e[m];for(;;){if(o!==a){let u,m,h;do{for(u=o-a,m=-1;a>0&&l(a-1,o-1);){for(t[--a]=1,t[--o]=0;t[a-1];)a--;if(c===0)break;for(f=c-1,c=f;i[c-1];c--);}for(h=o,f>c&&(m=o);!(o>=r||!l(a,o));){for(t[a++]=0,t[o++]=1;t[o];)o++;if(f>=s)break;for(c=f+1,f=c;i[f];f++);f>c&&(m=o)}}while(u!==o-a);if(o!==h)if(m!==-1)for(;f===c;){for(t[--o]=0,t[--a]=1;t[a-1];)a--;for(f=c-1,c=f;i[c-1];c--);}else{let d=-1,g={effectiveIndent:0,penalty:0},p=h;for(o-u-1>p&&(p=o-u-1),o-Zn>p&&(p=o-Zn);p<=o;p++){let b={effectiveIndent:0,penalty:0},E=Jn(n,r,p);Qn(E,b);let C=Jn(n,r,p-u);Qn(C,b),(d===-1||ds(b,g)<=0)&&(g={effectiveIndent:b.effectiveIndent,penalty:b.penalty},d=p)}for(;o>d;){for(t[--o]=0,t[--a]=1;t[a-1];)a--;for(f=c-1,c=f;i[c-1];c--);}}}if(o>=r)break;for(a=o+1,o=a;t[o];o++);if(f>=s)break;for(c=f+1,f=c;i[f];f++);}}function Pt(t,e){let n=t.length,r=e.length,i=new Uint8Array(n),s=new Uint8Array(r);if(n>0&&r>0){let{classes1:a,classes2:o,classInfo:c}=Xi(t,e),{dstart:f,dend1:l,dend2:u}=Zi(a,n,o,r);if(f>l)for(let m=f;mu)for(let m=f;m0&&g>0){let p=new Array(h);for(let w=0;w({type:"insert",line:a,oldLineNo:0,newLineNo:o+1}));if(r===0)return t.map((a,o)=>({type:"delete",line:a,oldLineNo:o+1,newLineNo:0}));let{changedOld:i,changedNew:s}=Pt(t,e);return ns(t,e,i,s)}var ps=3;function Tt(t,e=ps){if(e=Math.max(0,e),t.length===0)return[];let n=[];for(let o=0;ogs(t,o.start,o.end))}function gs(t,e,n){let r=0,i=0,s=0,a=0,o=[],c=!1,f=!1;for(let l=e;l<=n;l++){let u=t[l];if(u)switch(u.type){case"keep":c||(r=u.oldLineNo,c=!0),f||(s=u.newLineNo,f=!0),i++,a++,o.push({type:"context",content:u.line});break;case"delete":c||(r=u.oldLineNo,c=!0),i++,o.push({type:"delete",content:u.line});break;case"insert":f||(s=u.newLineNo,f=!0),a++,o.push({type:"insert",content:u.line});break}}if(c||(r=s>0?s:1),f||(s=r>0?r:1),i===0)for(let l=e;l<=n;l++){let u=t[l];if(u&&u.type==="insert"){r=u.newLineNo>1?u.newLineNo-1:0;break}}if(a===0)for(let l=e;l<=n;l++){let u=t[l];if(u&&u.type==="delete"){s=u.oldLineNo>1?u.oldLineNo-1:0;break}}return{oldStart:r,oldCount:i,newStart:s,newCount:a,lines:o}}function st(t){return t?t.length<40?t:An(t):"0000000"}function tr(t,e,n,r,i,s){let{path:a,oldMode:o,newMode:c}=e;t.push(`diff --git a/${a} b/${n}`),s?(t.push(`similarity index ${e.similarity??100}%`),t.push(`rename from ${a}`),t.push(`rename to ${n}`)):r?t.push(`new file mode ${c||"100644"}`):i?t.push(`deleted file mode ${o||"100644"}`):o&&c&&o!==c&&(t.push(`old mode ${o}`),t.push(`new mode ${c}`))}function ys(t,e,n){let{path:r,oldContent:i,newContent:s,oldMode:a,oldHash:o,newHash:c}=t,f=t.renameTo!==void 0,l=t.renameTo??r,u=t.isNew??i==="",m=t.isDeleted??s==="";if(i===s&&!f)return"";let h=[];if(tr(h,t,l,u,m,f),i!==s){if(o||c){let d=st(o),g=st(c);u||m||f?h.push(`index ${d}..${g}`):h.push(`index ${d}..${g} ${a||"100644"}`)}e&&n?h.push(`Binary files a/${r} and b/${l} differ`):u?h.push(`Binary files /dev/null and b/${l} differ`):m?h.push(`Binary files a/${r} and /dev/null differ`):h.push(`Binary files a/${r} and b/${l} differ`)}return`${h.join(` ++`)){let l=f.indexOf(" ");if(l===-1)continue;let u=f.slice(0,l),m=f.slice(l+1);switch(u){case"object":s=m;break;case"type":a=m;break;case"tag":o=m;break;case"tagger":c=Ne(m);break}}if(!s)throw new Error("Tag missing object field");if(!o)throw new Error("Tag missing tag name field");if(!c)throw new Error("Tag missing tagger field");return{type:"tag",object:s,objectType:a,name:o,tagger:c,message:i}}function Rn(t){let e=[];return e.push(`object ${t.object}`),e.push(`type ${t.objectType}`),e.push(`tag ${t.name}`),e.push(`tagger ${Ge(t.tagger)}`),e.push(""),e.push(t.message),ui.encode(e.join(` ++`))}async function N(t,e,n){let r=await t.objectStore.write(e,n);return t.hooks?.onObjectWrite?.({repo:t,type:e,hash:r}),r}async function F(t,e){return t.objectStore.read(e)}async function xn(t,e){return t.objectStore.exists(e)}async function In(t,e){return t.objectStore.findByPrefix(e)}function Q(t){let e=Math.min(t.length,8e3);for(let n=0;ns+a.byteLength,0),r=new Uint8Array(n),i=0;for(let s of e)r.set(s,i),i+=s.byteLength;return r}function bi(t){let e=1,n="";for(;e=c.length||c[f+1]==="\r"&&f+2>=c.length){if(o++,o0;)r+=" ",s--}}function Ri(t){let e={},n=null,r=t.split(` ++`),i=0;for(;i0;){let s=t.slice(0,n).match(/^(.+?)~(\d*)$/);if(s&&s[1]!==void 0&&s[2]!==void 0){let c=s[2]===""?1:parseInt(s[2],10);e.unshift({type:"tilde",n:c}),n=s[1].length;continue}let a=t.slice(0,n).match(/^(.+?)\^{([^}]*)}$/);if(a&&a[1]!==void 0&&a[2]!==void 0){e.unshift({type:"peel",target:a[2]}),n=a[1].length;continue}let o=t.slice(0,n).match(/^(.+?)\^(\d*)$/);if(o&&o[1]!==void 0&&o[2]!==void 0){let c=o[2]===""?1:parseInt(o[2],10);e.unshift({type:"caret",n:c}),n=o[1].length;continue}break}let r=t.slice(0,n),i=r.match(/^(.+?)@\{(\d+)\}$/);return i&&i[1]!==void 0&&i[2]!==void 0?{base:i[1],reflogIndex:parseInt(i[2],10),suffixes:e}:{base:r,suffixes:e}}var Ci=["HEAD","FETCH_HEAD","ORIG_HEAD","MERGE_HEAD","CHERRY_PICK_HEAD","REBASE_HEAD"];async function Ti(t,e){let n=await In(t,e);if(n.length===0)return null;if(n.length>1)throw new kt(e);return n[0]}var kt=class extends Error{constructor(n){super(`short object ID ${n} is ambiguous`);this.prefix=n}};async function Si(t,e){if(e==="HEAD"||e==="@")return re(t,"HEAD");if(Ci.includes(e))return re(t,e);if(/^[0-9a-f]{40}$/.test(e))return await xn(t,e)?e:null;if(/^[0-9a-f]{4,39}$/.test(e)){let s=await Ti(t,e);if(s)return s}if(e.startsWith("refs/")){let s=await re(t,e);if(s)return s}let n=await re(t,`refs/heads/${e}`);if(n)return n;let r=await re(t,`refs/tags/${e}`);if(r)return r;let i=await re(t,`refs/remotes/${e}`);return i||null}async function vi(t,e,n){if(n===""||n==="commit")try{return await Fe(t,e)}catch{return null}if(n==="tree"){let i;try{i=await Fe(t,e)}catch{return null}return(await v(t,i)).tree}return(await F(t,e)).type!==n?null:e}async function $i(t,e,n){let r=e;n.some(s=>s.type==="tilde"||s.type==="caret")&&(r=await Fe(t,r));for(let s of n)if(s.type==="peel"){if(!r)return null;r=await vi(t,r,s.target)}else if(s.type==="tilde")for(let a=0;aa.parents.length||(r=a.parents[s.n-1]??null,!r))return null}return r}async function Pn(t,e){let{base:n,reflogIndex:r,suffixes:i}=Pi(e);if(r!==void 0)return null;let s=await Si(t,n);return s?$i(t,s,i):null}function Cn(t){return t.length===4&&t.toLowerCase()===".git"}function Tn(t){if(t.length===0||t.includes("\0")||t.charCodeAt(0)===47||t.charCodeAt(t.length-1)===47)return!1;let e=t.split("/");for(let n of e)if(n.length===0||n==="."||n===".."||Cn(n))return!1;return!0}function Sn(t,e){return e===t?!1:t==="/"?e.startsWith("/")&&e.length>1:e.startsWith(t+"/")}function vn(t){if(t.length===0||t.charCodeAt(0)===47)return!1;let e=t.split("/");for(let n of e)if(n===".."||Cn(n))return!1;return!0}var ma=new TextEncoder;function $n(t,e){return t.lstat?t.lstat(e):t.stat(e)}function ie(t){return typeof t=="string"?t==="120000":t===40960}function jn(t){return typeof t=="string"?t==="100644"||t==="100755":t===33188||t===33261}function tt(t){return typeof t=="string"?t==="160000":t===57344}var ji=1145655875,Mi=2,_e=new WeakMap;async function nt(t,e){let n=ae(t.gitDir,"index");await t.fs.writeFile(n,await Mn(e));let r=await Ln(t,n);if(r===null){_e.delete(e);return}if(Ui(e,r)&&(await t.fs.writeFile(n,await Mn(e)),r=await Ln(t,n),r===null)){_e.delete(e);return}_e.set(e,r)}function Dn(t){let e=[...t].sort(Bn);return{version:Mi,entries:e}}function de(){return{ctimeSeconds:0,ctimeNanoseconds:0,mtimeSeconds:0,mtimeNanoseconds:0,dev:0,ino:0,uid:0,gid:0,size:0}}function Ai(t,e=t.size){let n=An(t.mtime),r=t.ctime?An(t.ctime):{seconds:0,nanoseconds:0};return{ctimeSeconds:r.seconds,ctimeNanoseconds:r.nanoseconds,mtimeSeconds:n.seconds,mtimeNanoseconds:n.nanoseconds,dev:Oe(t.dev),ino:Oe(t.ino),uid:Oe(t.uid),gid:Oe(t.gid),size:Oe(e)}}function Li(t){return t.isSymbolicLink?40960:t.isDirectory?16384:t.mode&73?33261:33188}function Di(t,e,n){return n.isFile&&ie(e.mode)&&!t.symlink}function Hi(t){return t.chmod!==void 0}function Bi(t,e,n){return e&&Di(t,e,n)?e.mode:n.isFile&&!Hi(t)?e&&jn(e.mode)?e.mode:33188:Li(n)}async function Hn(t,e,n){if(!t.workTree)return e;let r=n?new Set(n):null,i=[];for(let s of e.entries){if(s.stage!==0||tt(s.mode)||r&&!r.has(s.path)){i.push(s);continue}let a=await $n(t.fs,ae(t.workTree,s.path)).catch(()=>null);if(!a||Bi(t.fs,s,a)!==s.mode){i.push(s);continue}i.push({...s,stat:Ai(a)})}return Gi(e,i)}async function Mn(t){let e=new TextEncoder,n=[...t.entries].sort(Bn),r=[],i=12;for(let m of n){let h=e.encode(m.path);r.push(h);let d=62+h.byteLength+1;i+=Math.ceil(d/8)*8}i+=20;let s=new ArrayBuffer(i),a=new Uint8Array(s),o=new DataView(s),c=0;o.setUint32(c,ji),c+=4,o.setUint32(c,t.version),c+=4,o.setUint32(c,n.length),c+=4;for(let m=0;me.path?1:t.stage-e.stage}function An(t){let e=Nn(t);if(e===null)return{seconds:0,nanoseconds:0};let n=Math.floor(e/1e3);return{seconds:Oe(n),nanoseconds:(e-n*1e3)*1e6}}function Nn(t){if(!(t instanceof Date))return null;let e=Math.trunc(t.getTime());return Number.isFinite(e)?e:null}function Oe(t){return t===void 0||!Number.isFinite(t)||t<0?0:Math.trunc(t)>>>0}function Ni(t){return t.mtimeSeconds*1e3+Math.floor(t.mtimeNanoseconds/1e6)}function Gi(t,e){let n={...t,entries:e},r=_e.get(t);return r&&_e.set(n,r),n}async function Ln(t,e){let{mtime:n}=await t.fs.stat(e);return Nn(n)===null?null:n}function Ui(t,e){let n=Math.trunc(e.getTime()),r=!1;for(let i=0;ie?1:0}var Fi=7;function Un(t){return t.slice(0,Fi)}function Fn(t){let e=t.indexOf(` ++`);return e===-1?t:t.slice(0,e)}async function Ot(t,e){return Wn(t,e,"")}async function Wn(t,e,n){let r=[],i=new Map;for(let a of e){let o=n?a.path.slice(n.length+1):a.path,c=o.indexOf("/");if(c===-1)r.push({mode:_i(a.mode),name:o,hash:a.hash});else{let f=o.slice(0,c),l=i.get(f);l||(l=[],i.set(f,l)),l.push(a)}}for(let[a,o]of i){let c=n?`${n}/${a}`:a,f=await Wn(t,o,c);r.push({mode:U.DIRECTORY,name:a,hash:f})}r.sort((a,o)=>{let c=a.mode===U.DIRECTORY?`${a.name}/`:a.name,f=o.mode===U.DIRECTORY?`${o.name}/`:o.name;return cf?1:0});let s=be({type:"tree",entries:r});return N(t,"tree",s)}async function K(t,e,n=""){let r=await F(t,e);if(r.type!=="tree")throw new Error(`Expected tree object, got ${r.type}`);let i=ce(r.content),s=[];for(let a of i.entries){let o=n?`${n}/${a.name}`:a.name;if(a.mode===U.DIRECTORY){let c=await K(t,a.hash,o);s.push(...c)}else s.push({path:o,mode:a.mode,hash:a.hash})}return s}async function Pe(t,e){if(!e)return new Map;let n=await K(t,e);return new Map(n.map(r=>[r.path,r]))}async function le(t,e,n){if(e===n)return[];let r=[];return await zn(t,e,n,"",r),r.sort((i,s)=>We(i.path,s.path))}async function _n(t,e){let n=await F(t,e);if(n.type!=="tree")throw new Error(`Expected tree object, got ${n.type}`);return ce(n.content).entries}async function zn(t,e,n,r,i){if(e===n)return;let s=e?await _n(t,e):[],a=n?await _n(t,n):[],o=new Map;for(let l of s)o.set(l.name,l);let c=new Map;for(let l of a)c.set(l.name,l);let f=new Set;for(let l of s)f.add(l.name);for(let l of a)f.add(l.name);for(let l of f){let u=o.get(l),m=c.get(l),h=r?`${r}/${l}`:l;if(u&&m){if(u.hash===m.hash&&u.mode===m.mode)continue;let d=u.mode===U.DIRECTORY,g=m.mode===U.DIRECTORY;d&&g?await zn(t,u.hash,m.hash,h,i):d?(await rt(t,u.hash,h,"deleted",i),i.push({path:h,status:"added",newHash:m.hash,newMode:m.mode})):g?(i.push({path:h,status:"deleted",oldHash:u.hash,oldMode:u.mode}),await rt(t,m.hash,h,"added",i)):i.push({path:h,status:"modified",oldHash:u.hash,newHash:m.hash,oldMode:u.mode,newMode:m.mode})}else if(u)u.mode===U.DIRECTORY?await rt(t,u.hash,h,"deleted",i):i.push({path:h,status:"deleted",oldHash:u.hash,oldMode:u.mode});else{let d=m;d.mode===U.DIRECTORY?await rt(t,d.hash,h,"added",i):i.push({path:h,status:"added",newHash:d.hash,newMode:d.mode})}}}async function rt(t,e,n,r,i){let s=await K(t,e,n);for(let a of s)r==="added"?i.push({path:a.path,status:"added",newHash:a.hash,newMode:a.mode}):i.push({path:a.path,status:"deleted",oldHash:a.hash,oldMode:a.mode})}function _i(t){return t.toString(8).padStart(6,"0")}function Wi(t){let e=Math.min(t.length,8e3),n=0;for(let r=0;re*.01}function Vn(t,e,n,r){if(Wi(t)){let a=e.some(o=>o.test(t));return{matches:[],binary:a}}let i=t.split(` ++`);if(i.length>0&&i[i.length-1]===""&&i.pop(),n&&e.length>1&&!e.every(o=>i.some(c=>o.test(c))))return{matches:[],binary:!1};let s=[];for(let a=0;af.test(o));(r?!c:c)&&s.push({lineNo:a+1,line:o})}return{matches:s,binary:!1}}function zi(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function qn(t,e){let n=e?.fixed?zi(t):t;e?.wordRegexp&&(n=`\\b${n}\\b`);let r=e?.ignoreCase?"i":"";try{return new RegExp(n,r)}catch{return null}}var Vi=new TextEncoder,Kn=new TextDecoder,Ce=16877,Zn=33188,qi=33261,Jn=40960;function q(t){let e=[];for(let n of t.split("/"))n==="."||n===""||(n===".."?e.pop():e.push(n));return"/"+e.join("/")}function Ct(t){let e=t.lastIndexOf("/");return e<=0?"/":t.slice(0,e)}function Pt(t,e){return t&-4096|e&4095}function Yn(t,e){return q(e.startsWith("/")?e:`${Ct(t)}/${e}`)}function Xn(t){switch(t){case U.EXECUTABLE:return qi;case U.SYMLINK:return Jn;case U.DIRECTORY:return Ce;default:return Zn}}var Te=class{constructor(e,n,r="/"){this.objectStore=e;this.rootTreeHash=n;this.rootPath=r;let i=q(r);this.overlay.set(i,{type:"directory",mode:Ce,mtime:this.epoch})}treeCache=new Map;overlay=new Map;removals=new Set;epoch=new Date(0);toRelative(e){let n=q(e),r=q(this.rootPath);if(n===r)return"";let i=r==="/"?"/":`${r}/`;return n.startsWith(i)?n.slice(i.length):null}async loadTreeDir(e){let n=this.treeCache.get(e);if(n)return n;if(e===""){let a=await this.objectStore.read(this.rootTreeHash);if(a.type!=="tree")return null;let o=ce(a.content);return this.treeCache.set("",o.entries),o.entries}let r=e.split("/"),i=await this.loadTreeDir("");if(!i)return null;let s="";for(let a of r){let o=i.find(u=>u.name===a);if(!o||o.mode!==U.DIRECTORY)return null;s=s?`${s}/${a}`:a;let c=this.treeCache.get(s);if(c){i=c;continue}let f=await this.objectStore.read(o.hash);if(f.type!=="tree")return null;let l=ce(f.content);this.treeCache.set(s,l.entries),i=l.entries}return i}async lookupTreeEntry(e){if(e==="")return null;let n=e.lastIndexOf("/"),r=n===-1?"":e.slice(0,n),i=n===-1?e:e.slice(n+1),s=await this.loadTreeDir(r);if(!s)return null;let a=s.find(o=>o.name===i);return a?{entry:a,dirEntries:s}:null}async isTreeDirectory(e){return e===""?!0:(await this.lookupTreeEntry(e))?.entry.mode===U.DIRECTORY}ensureOverlayParents(e){let n=Ct(e);n===q(this.rootPath)||n==="/"||this.overlay.has(n)||(this.ensureOverlayParents(n),this.overlay.set(n,{type:"directory",mode:Ce,mtime:new Date}))}async readFile(e){return Kn.decode(await this.readFileBuffer(e))}async readFileBuffer(e){let n=q(e);if(this.removals.has(n))throw new Error(`ENOENT: no such file or directory, open '${e}'`);let r=this.overlay.get(n);if(r){if(r.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${e}'`);return r.content}let i=this.toRelative(n);if(i===null||i==="")throw new Error(`ENOENT: no such file or directory, open '${e}'`);let s=await this.lookupTreeEntry(i);if(!s)throw new Error(`ENOENT: no such file or directory, open '${e}'`);if(s.entry.mode===U.DIRECTORY)throw new Error(`EISDIR: illegal operation on a directory, read '${e}'`);let a=await this.objectStore.read(s.entry.hash);if(a.type!=="blob")throw new Error(`ENOENT: no such file or directory, open '${e}'`);return a.content}async writeFile(e,n){let r=q(e);this.removals.delete(r),this.ensureOverlayParents(r),this.overlay.set(r,{type:"file",content:typeof n=="string"?Vi.encode(n):new Uint8Array(n),mode:Zn,mtime:new Date})}async exists(e){let n=q(e);if(this.removals.has(n))return!1;if(this.overlay.has(n))return!0;let r=this.toRelative(n);return r===null?!1:r===""||await this.isTreeDirectory(r)?!0:await this.lookupTreeEntry(r)!==null}async stat(e){let n=q(e);if(this.removals.has(n))throw new Error(`ENOENT: no such file or directory, stat '${e}'`);let r=this.overlay.get(n);if(r)return{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:r.type==="file"?r.content.byteLength:0,mtime:r.mtime};let i=this.toRelative(n);if(i===null)throw new Error(`ENOENT: no such file or directory, stat '${e}'`);if(i==="")return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:Ce,size:0,mtime:this.epoch};let s=await this.lookupTreeEntry(i);if(!s)throw new Error(`ENOENT: no such file or directory, stat '${e}'`);let{entry:a}=s,o=a.mode===U.DIRECTORY,c=a.mode===U.SYMLINK,f=0;return o||(f=(await this.objectStore.read(a.hash)).content.byteLength),{isFile:!o&&!c,isDirectory:o,isSymbolicLink:!1,mode:Xn(a.mode),size:f,mtime:this.epoch}}async lstat(e){let n=q(e);if(this.removals.has(n))throw new Error(`ENOENT: no such file or directory, lstat '${e}'`);let r=this.overlay.get(n);if(r)return{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:r.type==="symlink",mode:r.mode,size:r.type==="file"?r.content.byteLength:r.type==="symlink"?r.target.length:0,mtime:r.mtime};let i=this.toRelative(n);if(i===null)throw new Error(`ENOENT: no such file or directory, lstat '${e}'`);if(i==="")return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:Ce,size:0,mtime:this.epoch};let s=await this.lookupTreeEntry(i);if(!s)throw new Error(`ENOENT: no such file or directory, lstat '${e}'`);let{entry:a}=s,o=a.mode===U.DIRECTORY,c=a.mode===U.SYMLINK,f=0;return o||(f=(await this.objectStore.read(a.hash)).content.byteLength),{isFile:!o&&!c,isDirectory:o,isSymbolicLink:c,mode:Xn(a.mode),size:f,mtime:this.epoch}}async mkdir(e,n){let r=q(e);if(this.overlay.has(r)){if(this.overlay.get(r).type!=="directory")throw new Error(`EEXIST: file already exists, mkdir '${e}'`);if(!n?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${e}'`);return}let i=this.toRelative(r);if(i!==null&&!this.removals.has(r)&&(i===""||await this.isTreeDirectory(i))){if(!n?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${e}'`);return}let s=Ct(r);if(!(this.overlay.has(s)||await this.exists(s)))if(n?.recursive)await this.mkdir(s,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${e}'`);this.removals.delete(r),this.overlay.set(r,{type:"directory",mode:Ce,mtime:new Date})}async readdir(e){let n=q(e);if(this.removals.has(n))throw new Error(`ENOENT: no such file or directory, scandir '${e}'`);let r=new Set,i=this.toRelative(n);if(i!==null){let a=await this.loadTreeDir(i);if(a)for(let o of a){let c=n==="/"?`/${o.name}`:`${n}/${o.name}`;this.removals.has(c)||r.add(o.name)}}let s=n==="/"?"/":`${n}/`;for(let a of this.overlay.keys())if(a!==n&&a.startsWith(s)){let c=a.slice(s.length).split("/")[0];c&&!this.removals.has(n==="/"?`/${c}`:`${n}/${c}`)&&r.add(c)}if(r.size===0){if(this.overlay.get(n)?.type==="directory")return[];if(i!==null&&(i===""||await this.isTreeDirectory(i)))return[];throw new Error(`ENOENT: no such file or directory, scandir '${e}'`)}return[...r].sort()}async rm(e,n){let r=q(e);if(!await this.exists(r)){if(n?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${e}'`)}let s=r==="/"?"/":`${r}/`;if(n?.recursive)for(let a of[...this.overlay.keys()])a.startsWith(s)&&(this.overlay.delete(a),this.removals.add(a));if(this.overlay.delete(r),this.removals.add(r),n?.recursive){let a=this.toRelative(r);a!==null&&await this.markTreeChildrenRemoved(a,r)}}async markTreeChildrenRemoved(e,n){let r=await this.loadTreeDir(e);if(r)for(let i of r){let s=n==="/"?`/${i.name}`:`${n}/${i.name}`;if(this.removals.add(s),i.mode===U.DIRECTORY){let a=e?`${e}/${i.name}`:i.name;await this.markTreeChildrenRemoved(a,s)}}}async chmod(e,n){let r=q(e),i=this.overlay.get(r);if(i?.type==="symlink")return this.chmod(Yn(r,i.target),n);if(i){i.mode=Pt(i.mode,n);return}if(this.removals.has(r)||!await this.exists(r))throw new Error(`ENOENT: no such file or directory, chmod '${e}'`);let s=await this.lstat(r);if(s.isSymbolicLink)return this.chmod(Yn(r,await this.readlink(r)),n);this.ensureOverlayParents(r),this.overlay.set(r,s.isDirectory?{type:"directory",mode:Pt(s.mode,n),mtime:this.epoch}:{type:"file",content:await this.readFileBuffer(r),mode:Pt(s.mode,n),mtime:this.epoch})}async readlink(e){let n=q(e);if(this.removals.has(n))throw new Error(`ENOENT: no such file or directory, readlink '${e}'`);let r=this.overlay.get(n);if(r){if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${e}'`);return r.target}let i=this.toRelative(n);if(i===null||i==="")throw new Error(`EINVAL: invalid argument, readlink '${e}'`);let s=await this.lookupTreeEntry(i);if(!s||s.entry.mode!==U.SYMLINK)throw new Error(`EINVAL: invalid argument, readlink '${e}'`);let a=await this.objectStore.read(s.entry.hash);return Kn.decode(a.content)}async symlink(e,n){let r=q(n);if(await this.exists(r))throw new Error(`EEXIST: file already exists, symlink '${n}'`);this.ensureOverlayParents(r),this.removals.delete(r),this.overlay.set(r,{type:"symlink",target:e,mode:Jn,mtime:new Date})}};async function ze(t,e,n,r){let i=new Set,s=0;for(let a of e){if(!Tn(a.path))throw new Error(`refusing to check out unsafe path '${a.path}'`);let o=ae(r,a.path);if(!Sn(r,o))throw new Error(`refusing to check out path outside target directory: '${a.path}'`);let c=gn(o);if(c!==r&&!i.has(c)&&(await n.mkdir(c,{recursive:!0}),i.add(c)),tt(a.mode))await n.mkdir(o,{recursive:!0});else if(ie(a.mode)){let f=await H(t,a.hash);if(!vn(f))throw new Error(`refusing to create symlink with unsafe target '${f}'`);n.symlink?await n.symlink(f,o):await n.writeFile(o,f)}else{let f=await fe(t,a.hash);await n.writeFile(o,f)}s++}return s}function Ve(t,e){let n=null,r;function i(s="/"){return n&&r===s||(n=new Te(t.objectStore,e,s),r=s),n}return{treeHash:e,async readFile(s){let a=i(),o=s.startsWith("/")?s:"/"+s;return await a.exists(o)?a.readFile(o):null},async readFileBytes(s){let a=i(),o=s.startsWith("/")?s:"/"+s;return await a.exists(o)?a.readFileBuffer(o):null},async files(){return(await K(t,e)).map(a=>a.path)},fs(s="/"){return i(s)},async materialize(s,a="/"){let o=await K(t,e);return ze(t,o,s,a)}}}async function Ki(t,e){return re(t,e)}async function we(t,e){return Pn(t,e)}async function Yi(t){return It(t,"refs/heads")}async function Xi(t){return It(t,"refs/tags")}async function Zi(t){let e=await t.refStore.readRef("HEAD");if(!e)return{branch:null,ref:null,hash:null};if(e.type==="symbolic"){let n=await t.refStore.readRef(e.target),r=n?.type==="direct"?n.hash:null;return{branch:e.target.startsWith("refs/heads/")?Et(e.target):null,ref:e.target,hash:r}}return{branch:null,ref:null,hash:e.hash}}async function Ji(t,e){return v(t,e)}async function Qi(t,e){return fe(t,e)}async function es(t,e){return H(t,e)}async function ts(t,e){let n=await F(t,e);if(n.type!=="tree")throw new Error(`Expected tree object, got ${n.type}`);return ce(n.content).entries}async function ns(t,e,n){let r=await v(t,e);return Ve(t,r.tree).readFile(n)}function rs(t){let e=0;for(let n=0;n!d.mode.startsWith("120")).sort((d,g)=>d.pathg.path?1:0),c=r?.allMatch??!1,f=r?.invert??!1,l=r?.maxCount,u=r?.maxDepth,m=r?.paths,h=[];for(let d of o){if(u!==void 0&&rs(d.path)>u||m&&!m.some(E=>is(E,d.path)))continue;let g=await H(t,d.hash),p=Vn(g,i,c,f);if(p.binary){h.push({path:d.path,matches:[],binary:!0});continue}if(p.matches.length===0)continue;let b=l!==void 0?p.matches.slice(0,l):p.matches;h.push({path:d.path,matches:b,binary:!1})}return h}function ee(t){if(t.length===0)return[];let e=t.split(` ++`);return e[e.length-1]===""&&e.pop(),e}var os=4,Qn=1024,it=100,at=0,st=1,Se=2;function St(t){let e=1;for(;e*eit&&(n=e-it),r-e>it&&(r=e+it);let i=0,s=1;for(let c=1;e-c>=n;c++){let f=t[e-c];if(f===at)i++;else if(f===Se)s++;else break}if(i===0)return!1;let a=0,o=1;for(let c=1;e+c<=r;c++){let f=t[e+c];if(f===at)a++;else if(f===Se)o++;else break}return a===0?!1:(a+=i,o+=s,o*os=m?l[p]=Se:l[p]=st}let h=Math.min(St(r),Qn);for(let p=s;p<=o;p++){let b=i[n[p]].len1;b===0?u[p]=at:b>=h?u[p]=Se:u[p]=st}let d=[];for(let p=s;p<=a;p++)l[p]===st||l[p]===Se&&!er(l,p,s,a)?d.push(p):c[p]=1;let g=[];for(let p=s;p<=o;p++)u[p]===st||u[p]===Se&&!er(u,p,s,o)?g.push(p):f[p]=1;return{refIndex1:d,nreff1:d.length,refIndex2:g,nreff2:g.length}}var pe=20,tr=4,ls=256,us=256,ot=2147483647;function Y(t,e){return t[e]??0}function ms(t,e,n,r,i,s,a,o,c,f){let l=e-s,u=n-i,m=e-i,h=n-s,d=m-h&1,g=m,p=m,b=h,E=h;a[m]=e,o[h]=n;for(let C=1;;C++){let j=!1;g>l?a[--g-1]=-1:++g,p=g;P-=2){let w;Y(a,P-1)>=Y(a,P+1)?w=Y(a,P-1)+1:w=Y(a,P+1);let R=w,O=w-P;for(;wpe&&(j=!0),a[P]=w,d&&b<=P&&P<=E&&Y(o,P)<=w)return{i1:w,i2:O,minLo:!0,minHi:!0}}b>l?o[--b-1]=ot:++b,E=b;P-=2){let w;Y(o,P-1)e&&O>i&&t[w-1]===r[O-1];)w--,O--;if(R-w>pe&&(j=!0),o[P]=w,!d&&g<=P&&P<=p&&w<=Y(a,P))return{i1:w,i2:O,minLo:!0,minHi:!0}}if(!c){if(j&&C>ls){let P=0,w=null;for(let R=p;R>=g;R-=2){let O=R>m?R-m:m-R,I=Y(a,R),T=I-R,k=I-e+(T-i)-O;if(k>tr*C&&k>P&&e+pe<=I&&I=b;R-=2){let O=R>h?R-h:h-R,I=Y(o,R),T=I-R,k=n-I+(s-T)-O;if(k>tr*C&&k>P&&e=f){let P=-1,w=-1;for(let I=p;I>=g;I-=2){let T=Math.min(Y(a,I),n),k=T-I;s=b;I-=2){let T=Math.max(e,Y(o,I)),k=T-I;k=nr)return nr}return-1}function sr(t,e,n){let r={endOfFile:!1,indent:-1,preBlank:0,preIndent:-1,postBlank:0,postIndent:-1};n>=e?(r.endOfFile=!0,r.indent=-1):(r.endOfFile=!1,r.indent=Tt(t[n]));for(let i=n-1;i>=0&&(r.preIndent=Tt(t[i]),r.preIndent===-1);i--)if(r.preBlank+=1,r.preBlank===rr){r.preIndent=0;break}for(let i=n+1;it.preIndent?e.penalty+=s?ws:bs:i===t.preIndent||(t.postIndent!==-1&&t.postIndent>i?e.penalty+=s?xs:Rs:e.penalty+=s?Es:Is))}function Os(t,e){let n=(t.effectiveIndent>e.effectiveIndent?1:0)-(t.effectiveIndente[u]===e[m];for(;;){if(o!==a){let u,m,h;do{for(u=o-a,m=-1;a>0&&l(a-1,o-1);){for(t[--a]=1,t[--o]=0;t[a-1];)a--;if(c===0)break;for(f=c-1,c=f;i[c-1];c--);}for(h=o,f>c&&(m=o);!(o>=r||!l(a,o));){for(t[a++]=0,t[o++]=1;t[o];)o++;if(f>=s)break;for(c=f+1,f=c;i[f];f++);f>c&&(m=o)}}while(u!==o-a);if(o!==h)if(m!==-1)for(;f===c;){for(t[--o]=0,t[--a]=1;t[a-1];)a--;for(f=c-1,c=f;i[c-1];c--);}else{let d=-1,g={effectiveIndent:0,penalty:0},p=h;for(o-u-1>p&&(p=o-u-1),o-ir>p&&(p=o-ir);p<=o;p++){let b={effectiveIndent:0,penalty:0},E=sr(n,r,p);or(E,b);let C=sr(n,r,p-u);or(C,b),(d===-1||Os(b,g)<=0)&&(g={effectiveIndent:b.effectiveIndent,penalty:b.penalty},d=p)}for(;o>d;){for(t[--o]=0,t[--a]=1;t[a-1];)a--;for(f=c-1,c=f;i[c-1];c--);}}}if(o>=r)break;for(a=o+1,o=a;t[o];o++);if(f>=s)break;for(c=f+1,f=c;i[f];f++);}}function $t(t,e){let n=t.length,r=e.length,i=new Uint8Array(n),s=new Uint8Array(r);if(n>0&&r>0){let{classes1:a,classes2:o,classInfo:c}=as(t,e),{dstart:f,dend1:l,dend2:u}=cs(a,n,o,r);if(f>l)for(let m=f;mu)for(let m=f;m0&&g>0){let p=new Array(h);for(let w=0;w({type:"insert",line:a,oldLineNo:0,newLineNo:o+1}));if(r===0)return t.map((a,o)=>({type:"delete",line:a,oldLineNo:o+1,newLineNo:0}));let{changedOld:i,changedNew:s}=$t(t,e);return hs(t,e,i,s)}var Ps=3;function jt(t,e=Ps){if(e=Math.max(0,e),t.length===0)return[];let n=[];for(let o=0;oCs(t,o.start,o.end))}function Cs(t,e,n){let r=0,i=0,s=0,a=0,o=[],c=!1,f=!1;for(let l=e;l<=n;l++){let u=t[l];if(u)switch(u.type){case"keep":c||(r=u.oldLineNo,c=!0),f||(s=u.newLineNo,f=!0),i++,a++,o.push({type:"context",content:u.line});break;case"delete":c||(r=u.oldLineNo,c=!0),i++,o.push({type:"delete",content:u.line});break;case"insert":f||(s=u.newLineNo,f=!0),a++,o.push({type:"insert",content:u.line});break}}if(c||(r=s>0?s:1),f||(s=r>0?r:1),i===0)for(let l=e;l<=n;l++){let u=t[l];if(u&&u.type==="insert"){r=u.newLineNo>1?u.newLineNo-1:0;break}}if(a===0)for(let l=e;l<=n;l++){let u=t[l];if(u&&u.type==="delete"){s=u.oldLineNo>1?u.oldLineNo-1:0;break}}return{oldStart:r,oldCount:i,newStart:s,newCount:a,lines:o}}function ct(t){return t?t.length<40?t:Un(t):"0000000"}function cr(t){return!!t.oldMode&&!!t.newMode&&t.oldMode!==t.newMode}function fr(t,e,n,r,i,s){let{path:a,oldMode:o,newMode:c}=e;t.push(`diff --git a/${a} b/${n}`),s?(t.push(`similarity index ${e.similarity??100}%`),t.push(`rename from ${a}`),t.push(`rename to ${n}`)):r?t.push(`new file mode ${c||"100644"}`):i?t.push(`deleted file mode ${o||"100644"}`):o&&c&&o!==c&&(t.push(`old mode ${o}`),t.push(`new mode ${c}`))}function Ts(t,e,n){let{path:r,oldContent:i,newContent:s,oldMode:a,oldHash:o,newHash:c}=t,f=t.renameTo!==void 0,l=t.renameTo??r,u=t.isNew??i==="",m=t.isDeleted??s==="";if(i===s&&!f&&!cr(t))return"";let h=[];if(fr(h,t,l,u,m,f),i!==s){if(o||c){let d=ct(o),g=ct(c);u||m||f?h.push(`index ${d}..${g}`):h.push(`index ${d}..${g} ${a||"100644"}`)}e&&n?h.push(`Binary files a/${r} and b/${l} differ`):u?h.push(`Binary files /dev/null and b/${l} differ`):m?h.push(`Binary files a/${r} and /dev/null differ`):h.push(`Binary files a/${r} and b/${l} differ`)}return`${h.join(` + `)} +-`}function nr(t){let{path:e,oldContent:n,newContent:r,oldMode:i,newMode:s,oldHash:a,newHash:o}=t,c=t.renameTo!==void 0,f=t.renameTo??e,l=J(n),u=J(r);if(l||u)return ys(t,l,u);let m=Q(n),h=Q(r),d=n.length>0&&n.endsWith(` ++`}function lr(t){let{path:e,oldContent:n,newContent:r,oldMode:i,newMode:s,oldHash:a,newHash:o}=t,c=t.renameTo!==void 0,f=t.renameTo??e,l=Q(n),u=Q(r);if(l||u)return Ts(t,l,u);let m=ee(n),h=ee(r),d=n.length>0&&n.endsWith(` + `),g=r.length>0&&r.endsWith(` +-`),p="\0NOEOL",b=m;!d&&m.length>0&&(b=m.slice(),b[b.length-1]+=p);let E=h;!g&&h.length>0&&(E=h.slice(),E[E.length-1]+=p);let C=be(b,E);if(!d||!g)for(let O of C)O.line.includes(p)&&(O.line=O.line.replace(p,""));let v=Tt(C,t.contextLines);if(v.length===0&&!c)return"";let k=t.isNew??n==="",w=t.isDeleted??r==="",R=[];if(tr(R,t,f,k,w,c),v.length===0)return`${R.join(` ++`),p="\0NOEOL",b=m;!d&&m.length>0&&(b=m.slice(),b[b.length-1]+=p);let E=h;!g&&h.length>0&&(E=h.slice(),E[E.length-1]+=p);let C=Re(b,E);if(!d||!g)for(let k of C)k.line.includes(p)&&(k.line=k.line.replace(p,""));let j=jt(C,t.contextLines);if(j.length===0&&!c&&!cr(t))return"";let P=t.isNew??n==="",w=t.isDeleted??r==="",R=[];if(fr(R,t,f,P,w,c),j.length===0)return`${R.join(` + `)} +-`;if(a||o){let O=st(a),j=st(o);k||w?R.push(`index ${O}..${j}`):c?R.push(`index ${O}..${j} ${i||"100644"}`):i&&s&&i!==s?R.push(`index ${O}..${j}`):R.push(`index ${O}..${j} ${i||"100644"}`)}let P=O=>O.includes(" ")?" ":"";k?(R.push("--- /dev/null"),R.push(`+++ b/${f}${P(f)}`)):w?(R.push(`--- a/${e}${P(e)}`),R.push("+++ /dev/null")):(R.push(`--- a/${e}${P(e)}`),R.push(`+++ b/${f}${P(f)}`));let I=m.length,T=h.length;for(let O of v){let j=O.oldCount===1?`${O.oldStart}`:`${O.oldStart},${O.oldCount}`,A=O.newCount===1?`${O.newStart}`:`${O.newStart},${O.newCount}`,ie="",xe=O.oldCount===0?O.oldStart-1:O.oldStart-2;for(let y=xe;y>=0;y--){let S=m[y];if(S&&/^[a-zA-Z$_]/.test(S)){ie=` ${S.trimEnd().slice(0,79)}`;break}}R.push(`@@ -${j} +${A} @@${ie}`);let W=O.oldStart,x=O.newStart;for(let y of O.lines)switch(y.type){case"context":R.push(` ${y.content}`),(!d&&W===I||!g&&x===T)&&R.push("\\ No newline at end of file"),W++,x++;break;case"delete":R.push(`-${y.content}`),!d&&W===I&&R.push("\\ No newline at end of file"),W++;break;case"insert":R.push(`+${y.content}`),!g&&x===T&&R.push("\\ No newline at end of file"),x++;break}}return`${R.join(` ++`;if(a||o){let k=ct(a),$=ct(o);P||w?R.push(`index ${k}..${$}`):c?R.push(`index ${k}..${$} ${i||"100644"}`):i&&s&&i!==s?R.push(`index ${k}..${$}`):R.push(`index ${k}..${$} ${i||"100644"}`)}let O=k=>k.includes(" ")?" ":"";P?(R.push("--- /dev/null"),R.push(`+++ b/${f}${O(f)}`)):w?(R.push(`--- a/${e}${O(e)}`),R.push("+++ /dev/null")):(R.push(`--- a/${e}${O(e)}`),R.push(`+++ b/${f}${O(f)}`));let I=m.length,T=h.length;for(let k of j){let $=k.oldCount===1?`${k.oldStart}`:`${k.oldStart},${k.oldCount}`,A=k.newCount===1?`${k.newStart}`:`${k.newStart},${k.newCount}`,J="",he=k.oldCount===0?k.oldStart-1:k.oldStart-2;for(let y=he;y>=0;y--){let S=m[y];if(S&&/^[a-zA-Z$_]/.test(S)){J=` ${S.trimEnd().slice(0,79)}`;break}}R.push(`@@ -${$} +${A} @@${J}`);let z=k.oldStart,x=k.newStart;for(let y of k.lines)switch(y.type){case"context":R.push(` ${y.content}`),(!d&&z===I||!g&&x===T)&&R.push("\\ No newline at end of file"),z++,x++;break;case"delete":R.push(`-${y.content}`),!d&&z===I&&R.push("\\ No newline at end of file"),z++;break;case"insert":R.push(`+${y.content}`),!g&&x===T&&R.push("\\ No newline at end of file"),x++;break}}return`${R.join(` + `)} +-`}function Se(t){let e=t.lastIndexOf("/");return e>=0?t.slice(e+1):t}function bs(t,e){if(t.length===0)return;if(t.length===1)return t.shift();let n=Se(e),r=0;for(let i=0;i0){let g=bs(d,m.path);g&&f.push({oldPath:g.path,newPath:m.path,oldHash:g.oldHash??h,newHash:h,similarity:100,oldMode:g.oldMode,newMode:m.newMode})}else l.push(m)}let u=[...s.values()].flat();if(u.length>0&&l.length>0){let m=await xs(t,u,l,r);if(m.length>0){let h=new Set(m.map(g=>g.oldPath)),d=new Set(m.map(g=>g.newPath));u=u.filter(g=>!h.has(g.path)),l=l.filter(g=>!d.has(g.path)),f.push(...m)}}if(i>0&&u.length*l.length>i*i)return{remaining:[...c,...u,...l],renames:f,neededRenameLimit:Math.max(u.length,l.length)};if(u.length>0&&l.length>0){let m=await Os(t,u,l,r);if(m.length>0){let h=new Set(m.map(g=>g.oldPath)),d=new Set(m.map(g=>g.newPath));u=u.filter(g=>!h.has(g.path)),l=l.filter(g=>!d.has(g.path)),f.push(...m)}}return{remaining:[...c,...u,...l],renames:f}}async function xs(t,e,n,r){let i=new Map;for(let o=0;o>>25)>>>0,i=(i<<7^c>>>25)>>>0,r=r+o>>>0,n++,n<64&&o!==10)continue;let f=(r+Math.imul(i,97))%ir;e.set(f,(e.get(f)??0)+n),n=0,r=0,i=0}if(n>0){let a=(r+Math.imul(i,97))%ir;e.set(a,(e.get(a)??0)+n)}let s=[];for(let[a,o]of e)s.push({hash:a,count:o});return s.sort((a,o)=>a.hash-o.hash),s}function Is(t,e){let n=0,r=0,i=0,s=0;for(;i=a.hash)break;r+=f.count,s++}let o=a.count,c=0;if(s=r){let b=Se(u.path)===Se(d.path)?1:0;a.push({similarity:p,nameScore:b,delIdx:l,addIdx:h})}}}a.sort((l,u)=>u.similarity-l.similarity||u.nameScore-l.nameScore);let o=new Set,c=new Set,f=[];for(let{similarity:l,delIdx:u,addIdx:m}of a){if(o.has(u)||c.has(m))continue;o.add(u),c.add(m);let h=e[u],d=n[m];!h||!d||f.push({oldPath:h.path,newPath:d.path,oldHash:h.oldHash??"",newHash:d.newHash??"",similarity:l,oldMode:h.oldMode,newMode:d.newMode})}return f}async function de(t,e,n){return(await ke(t,e)).get(n)?.hash??null}async function or(t,e,n,r){let i=await le(t,e,n);if(!i.find(f=>f.status==="added"&&f.path===r))return null;let a=await at(t,"diff"),{renames:o}=await we(t,i,{limit:a});return o.find(f=>f.newPath===r)?.oldPath??null}async function ks(t,e,n,r,i,s){let a=await de(t,(await $(t,e)).tree,n);if(!a){let g=new Map,p=await $(t,e);for(let b of r)g.set(b.finalIdx,pe(e,n,b.currentLine,s+b.finalIdx,i[b.finalIdx],p,!1,void 0));return g}let o=await B(t,a),c=Q(o),f=new Array(i.length),l=[...r],u=e,m=n,h=c;for(;l.length>0;){let g=await $(t,u);if(g.parents.length===0){for(let I of l)f[I.finalIdx]=pe(u,m,I.currentLine,s+I.finalIdx,i[I.finalIdx],g,!0,void 0);break}let p=await de(t,g.tree,m),b=null,E=[];for(let I of g.parents){let T=await $(t,I),O=m,j=await de(t,T.tree,O);if(!j){let A=await or(t,T.tree,g.tree,m);A&&(O=A,j=await de(t,T.tree,O))}if(j&&(E.push({hash:I,path:O,blobHash:j}),j===p)){b={hash:I,path:O};break}}if(b){u=b.hash,m=b.path;continue}if(E.length===0){for(let I of l)f[I.finalIdx]=pe(u,m,I.currentLine,s+I.finalIdx,i[I.finalIdx],g,!1,void 0);break}let C=E[0],v=await B(t,C.blobHash),k=Q(v),w=be(k,h),R=new Map;for(let I of w)I.type==="keep"&&R.set(I.newLineNo,I.oldLineNo);let P=[];for(let I of l){let T=R.get(I.currentLine);T!==void 0?P.push({finalIdx:I.finalIdx,currentLine:T}):f[I.finalIdx]=pe(u,m,I.currentLine,s+I.finalIdx,i[I.finalIdx],g,!1,{hash:C.hash,path:C.path})}l=P,u=C.hash,m=C.path,h=k}let d=new Map;for(let g of r)f[g.finalIdx]&&d.set(g.finalIdx,f[g.finalIdx]);return d}async function ar(t,e,n,r){let i=await $(t,e),s=await de(t,i.tree,n);if(!s)throw new Error(`no such path '${n}' in ${e.slice(0,7)}`);let a=await B(t,s),o=Q(a),c=r?.startLine??1,f=r?.endLine??o.length,l=o.slice(c-1,f),u=new Array(l.length),m=l.map((p,b)=>({finalIdx:b,currentLine:c+b})),h=e,d=n,g=o;for(;m.length>0;){let p=await $(t,h);if(p.parents.length===0){for(let R of m)u[R.finalIdx]=pe(h,d,R.currentLine,c+R.finalIdx,l[R.finalIdx],p,!0,void 0);break}let b=await de(t,p.tree,d),E=[],C=null;for(let R of p.parents){let P=await $(t,R),I=d,T=await de(t,P.tree,I);if(!T){let O=await or(t,P.tree,p.tree,d);O&&(I=O,T=await de(t,P.tree,I))}if(T){let O={hash:R,path:I,blobHash:T};if(E.push(O),T===b){C=O;break}}}if(C){h=C.hash,d=C.path;continue}if(E.length===0){for(let R of m)u[R.finalIdx]=pe(h,d,R.currentLine,c+R.finalIdx,l[R.finalIdx],p,!1,void 0);break}if(E.length===1){let R=E[0],P=await B(t,R.blobHash),I=Q(P),T=be(I,g),O=new Map;for(let A of T)A.type==="keep"&&O.set(A.newLineNo,A.oldLineNo);let j=[];for(let A of m){let ie=O.get(A.currentLine);ie!==void 0?j.push({finalIdx:A.finalIdx,currentLine:ie}):u[A.finalIdx]=pe(h,d,A.currentLine,c+A.finalIdx,l[A.finalIdx],p,!1,{hash:R.hash,path:R.path})}m=j,h=R.hash,d=R.path,g=I;continue}let v=[];for(let R of E){let P=await B(t,R.blobHash),I=Q(P),T=be(I,g),O=new Map;for(let j of T)j.type==="keep"&&O.set(j.newLineNo,j.oldLineNo);v.push({info:R,newToOld:O})}let k=new Map;for(let R of m){let P=!1;for(let I=0;I0){m=w.lines,h=w.info.hash,d=w.info.path;let R=await B(t,w.info.blobHash);g=Q(R)}else break}return u}function pe(t,e,n,r,i,s,a,o){return{hash:t,origPath:e,origLine:n,finalLine:r,content:i,author:s.author,committer:s.committer,summary:s.message.split(` +-`)[0],boundary:a,previous:o}}var ve=class{heap=[];nextEpoch=0;get size(){return this.heap.length}push(e){this.heap.push({entry:e,epoch:this.nextEpoch++}),this.siftUp(this.heap.length-1)}pop(){let{heap:e}=this;if(e.length===0)return;let n=e[0],r=e.pop();return e.length>0&&(e[0]=r,this.siftDown(0)),n.entry}higher(e,n){let r=e.entry.commit.committer.timestamp,i=n.entry.commit.committer.timestamp;return r>i||r===i&&e.epoch0;){let r=e-1>>1;if(!this.higher(n[e],n[r]))break;[n[r],n[e]]=[n[e],n[r]],e=r}}siftDown(e){let{heap:n}=this,r=n.length;for(;;){let i=e,s=2*e+1,a=2*e+2;if(s0;){let l=s.pop();if(i.has(l.hash))continue;if(i.add(l.hash),yield l,o!==void 0&&++c>=o)return;if(a?.has(l.hash))continue;let u=n?.firstParent?l.commit.parents.slice(0,1):l.commit.parents;for(let m of u)if(!i.has(m))try{s.push(await ct(t,m))}catch{}}}async function*Cs(t,e,n){let r=await fr(t,n?.exclude),i=new Set(r),s=new ve,a=n?.shallowBoundary,o=Array.isArray(e)?e:[e];for(let h of o)i.has(h)||s.push(await ct(t,h));let c=[],f=new Map;for(;s.size>0;){let h=s.pop();if(i.has(h.hash)||(i.add(h.hash),f.set(h.hash,c.length),c.push(h),a?.has(h.hash)))continue;let d=n?.firstParent?h.commit.parents.slice(0,1):h.commit.parents;for(let g of d)if(!i.has(g))try{s.push(await ct(t,g))}catch{}}let l=c.length;if(l===0)return;let u=new Int32Array(l);for(let h of c){let d=n?.firstParent?h.commit.parents.slice(0,1):h.commit.parents;for(let g of d){let p=f.get(g);p!==void 0&&(u[p]=(u[p]??0)+1)}}let m=[];for(let h=l-1;h>=0;h--)u[h]===0&&m.push(h);for(;m.length>0;){let h=m.pop();yield c[h];let d=n?.firstParent?c[h].commit.parents.slice(0,1):c[h].commit.parents;for(let g of d){let p=f.get(g);if(p!==void 0){let b=(u[p]??0)-1;u[p]=b,b===0&&m.push(p)}}}}async function cr(t,e,n){if(e===n)return{ahead:0,behind:0};let r=new Set;for await(let o of ue(t,e))r.add(o.hash);let i=new Set;for await(let o of ue(t,n))i.add(o.hash);let s=0;for(let o of r)i.has(o)||s++;let a=0;for(let o of i)r.has(o)||a++;return{ahead:s,behind:a}}async function fr(t,e){if(!e||e.length===0)return new Set;let n=new Set;for await(let r of ue(t,e))n.add(r.hash);return n}async function ct(t,e){return{hash:e,commit:await $(t,e)}}async function Ps(t,e){let n=new Set,r=[e],i=0;for(;i0;){let m=0,h=await u(l[0].hash);for(let E=1;Eh||v===h&&C.seqHs(e.type)+e.content)}}function Ns(t,e,n){let r=Q(t),i=Q(e),s=be(r,i);return Tt(s,n).map(Bs)}async function lr(t,e){let n=await ye(t,e);if(n)return n;throw new Error(`ref or commit '${e}' not found`)}async function ur(t,e,n,r){let i=await lr(t,e),s=await lr(t,n),a=await $(t,i),o=await $(t,s),c=await le(t,a.tree,o.tree),f=r?.renames!==!1,l=r?.paths,u=[];if(f){let h=await we(t,c,{limit:r?.renameLimit});c=h.remaining,u=h.renames}let m=[];for(let h of c)l&&!l.some(d=>h.path.startsWith(d))||m.push({path:h.path,status:h.status,oldContent:h.oldHash?await B(t,h.oldHash):"",newContent:h.newHash?await B(t,h.newHash):"",oldHash:h.oldHash??void 0,newHash:h.newHash??void 0,oldMode:h.oldMode,newMode:h.newMode});for(let h of u)l&&!l.some(d=>h.newPath.startsWith(d)||h.oldPath.startsWith(d))||m.push({path:h.newPath,oldPath:h.oldPath,status:"renamed",oldContent:await B(t,h.oldHash),newContent:await B(t,h.newHash),oldHash:h.oldHash,newHash:h.newHash,oldMode:h.oldMode,newMode:h.newMode,similarity:h.similarity});return m.sort((h,d)=>h.path.localeCompare(d.path)),m}async function Gs(t,e,n,r){let i=await ur(t,e,n,r),s=r?.contextLines;return i.map(a=>({path:a.path,status:a.status,oldPath:a.oldPath,similarity:a.similarity,hunks:Ns(a.oldContent,a.newContent,s)}))}async function Us(t,e,n,r){let i=await ur(t,e,n,r),s=r?.contextLines,a="";for(let o of i)a+=nr({path:o.oldPath??o.path,oldContent:o.oldContent,newContent:o.newContent,oldHash:o.oldHash,newHash:o.newHash,oldMode:o.oldMode,newMode:o.newMode,isNew:o.status==="added",isDeleted:o.status==="deleted",renameTo:o.status==="renamed"?o.path:void 0,similarity:o.similarity,contextLines:s});return a}async function*Fs(t,e,n){if(n?.paths&&n.paths.length>0){let r=n?.limit,i=0;for await(let s of _s(t,e,n.paths,n))if(yield s,r!==void 0&&++i>=r)return;return}for await(let r of ue(t,e,n))yield{hash:r.hash,message:r.commit.message,tree:r.commit.tree,parents:r.commit.parents,author:r.commit.author,committer:r.commit.committer}}function $t(t,e){return e.some(n=>t===n||t.startsWith(n.endsWith("/")?n:n+"/"))}async function*_s(t,e,n,r){let i=new Set;if(r?.exclude)for await(let f of ue(t,r.exclude))i.add(f.hash);let s=new Set(i),a=new ve,o=async f=>{if(!s.has(f))try{let l=await $(t,f);a.push({hash:f,commit:l})}catch{}},c=Array.isArray(e)?e:[e];for(let f of c)await o(f);for(;a.size>0;){let f=a.pop();if(s.has(f.hash))continue;s.add(f.hash);let{commit:l}=f,u=r?.firstParent?l.parents.slice(0,1):l.parents,m=()=>({hash:f.hash,message:l.message,tree:l.tree,parents:l.parents,author:l.author,committer:l.committer});if(u.length===0){(await le(t,null,l.tree)).some(g=>$t(g.path,n))&&(yield m());continue}if(u.length===1){let d=u[0];try{let g=await $(t,d);(await le(t,g.tree,l.tree)).some(b=>$t(b.path,n))&&(yield m())}catch{yield m()}await o(d);continue}let h=[];for(let d of u)try{let g=await $(t,d);(await le(t,g.tree,l.tree)).some(b=>$t(b.path,n))||h.push(d)}catch{}if(h.length>0)await o(h[0]);else{yield m();for(let d of u)await o(d)}}}function Ws(t){let e=Math.abs(t),n=t<=0?"+":"-",r=String(Math.floor(e/60)).padStart(2,"0"),i=String(e%60).padStart(2,"0");return`${n}${r}${i}`}function Ve(t){if("timestamp"in t)return t;let e=t.date??new Date;return{name:t.name,email:t.email,timestamp:Math.floor(e.getTime()/1e3),timezone:Ws(e.getTimezoneOffset())}}async function jt(t,e){let n=Ve(e.author),r=e.committer?Ve(e.committer):n,i=Ne({type:"commit",tree:e.tree,parents:e.parents,author:n,committer:r,message:e.message}),s=await N(t,"commit",i);return e.branch&&await dr(t,e.branch,s),s}async function zs(t,e){let n=Ve(e.tagger),r=dn({type:"tag",object:e.target,objectType:e.targetType??"commit",name:e.name,tagger:n,message:e.message}),i=await N(t,"tag",r);return await t.refStore.writeRef(`refs/tags/${e.name}`,{type:"direct",hash:i}),i}async function hr(t,e){let n=e.branch?`refs/heads/${e.branch}`:null,r=n?await ne(t,n):null,i=null;r&&(i=(await $(t,r)).tree);let s=[];for(let[m,h]of Object.entries(e.files))if(h===null)s.push({path:m,hash:null});else{let d=typeof h=="string"?new TextEncoder().encode(h):h,g=await N(t,"blob",d);s.push({path:m,hash:g})}let a;i?a=await pr(t,i,s):a=await At(t,null,Mt(s));let o=Ve(e.author),c=e.committer?Ve(e.committer):o,l=Ne({type:"commit",tree:a,parents:r?[r]:[],author:o,committer:c,message:e.message});return{hash:await N(t,"commit",l),parentHash:r}}async function Vs(t,e){let{hash:n}=await hr(t,e);return await dr(t,e.branch,n),n}async function dr(t,e,n){let r=`refs/heads/${e}`;await t.refStore.writeRef(r,{type:"direct",hash:n}),await t.refStore.readRef("HEAD")||await t.refStore.writeRef("HEAD",{type:"symbolic",target:r})}async function qs(t,e){let n=[...e].sort((s,a)=>s.name.localeCompare(a.name)),r=await Promise.all(n.map(async s=>{let a=s.mode;return a||(a=(await t.objectStore.read(s.hash)).type==="tree"?"040000":"100644"),{mode:a,name:s.name,hash:s.hash}})),i=ge({type:"tree",entries:r});return N(t,"tree",i)}async function Ks(t,e){return N(t,"blob",new TextEncoder().encode(e))}async function pr(t,e,n){return At(t,e,Mt(n))}function Mt(t){let e=new Map,n=new Map;for(let r of t){let i=r.path.indexOf("/");if(i===-1)e.set(r.path,{hash:r.hash,mode:r.mode??"100644"});else{let s=r.path.slice(0,i),a=r.path.slice(i+1),o=n.get(s);o||(o=[],n.set(s,o)),o.push({...r,path:a})}}return{files:e,dirs:n}}async function mr(t,e){let n=await F(t,e);if(n.type!=="tree")throw new Error(`Expected tree object, got ${n.type}`);return ae(n.content).entries}async function At(t,e,n){let r=new Map;if(e)for(let a of await mr(t,e))r.set(a.name,a);for(let[a,{hash:o,mode:c}]of n.files)o===null?r.delete(a):r.set(a,{name:a,hash:o,mode:c});for(let[a,o]of n.dirs){let c=r.get(a),f=c?.mode==="040000"?c.hash:null,l=Mt(o),u=await At(t,f,l);(await mr(t,u)).length===0?r.delete(a):r.set(a,{name:a,hash:u,mode:"040000"})}let i=[...r.values()].sort((a,o)=>{let c=a.mode==="040000"?`${a.name}/`:a.name,f=o.mode==="040000"?`${o.name}/`:o.name;return cf?1:0}),s=ge({type:"tree",entries:i});return N(t,"tree",s)}function Lt(t,e){let n=t.length,r=e.length;if(n===0&&r===0)return[];if(n===0)return[{buffer1:[0,0],buffer2:[0,r]}];if(r===0)return[{buffer1:[0,n],buffer2:[0,0]}];let{changedOld:i,changedNew:s}=Pt(t,e);return Ys(i,n,s,r)}function Ys(t,e,n,r){let i=[],s=0,a=0;for(;s=e&&a>=r)break;let o=s,c=a;for(;so||a>c)&&i.push({buffer1:[o,s-o],buffer2:[c,a-c]})}return i}function Xs(t,e,n){let r=[];for(let c of Lt(e,t))r.push({ab:"a",oStart:c.buffer1[0],oLength:c.buffer1[1],abStart:c.buffer2[0],abLength:c.buffer2[1]});for(let c of Lt(e,n))r.push({ab:"b",oStart:c.buffer1[0],oLength:c.buffer1[1],abStart:c.buffer2[0],abLength:c.buffer2[1]});r.sort((c,f)=>c.oStart-f.oStart);let i=[],s=0;function a(c){c>s&&(i.push({stable:!0,buffer:"o",bufferStart:s,bufferLength:c-s,content:e.slice(s,c)}),s=c)}let o=0;for(;ol)break;l=Math.max(l,m.oStart+m.oLength),u.push(m),o++}if(u.length===1){if(c.abLength>0){let m=c.ab==="a"?t:n;i.push({stable:!0,buffer:c.ab,bufferStart:c.abStart,bufferLength:c.abLength,content:m.slice(c.abStart,c.abStart+c.abLength)})}}else{let m={a:{abMin:t.length,abMax:-1,oMin:e.length,oMax:-1},b:{abMin:n.length,abMax:-1,oMin:e.length,oMax:-1}};for(let b of u){let E=b.oStart,C=E+b.oLength,v=b.abStart,k=v+b.abLength,w=m[b.ab];w.abMin=Math.min(v,w.abMin),w.abMax=Math.max(k,w.abMax),w.oMin=Math.min(E,w.oMin),w.oMax=Math.max(C,w.oMax)}let h=m.a.abMin+(f-m.a.oMin),d=m.a.abMax+(l-m.a.oMax),g=m.b.abMin+(f-m.b.oMin),p=m.b.abMax+(l-m.b.oMax);i.push({stable:!1,a:t.slice(h,d),o:e.slice(f,l),b:n.slice(g,p)})}s=l}return a(e.length),i}function Zs(t,e,n,r){let i=r?.excludeFalseConflicts??!0,s=Xs(t,e,n),a=[],o=[];function c(){o.length&&(a.push({type:"ok",lines:o}),o=[])}for(let f of s)f.stable?o.push(...f.content):i&&yr(f.a,f.b)?o.push(...f.a):(c(),a.push({type:"conflict",a:f.a,o:f.o,b:f.b}));return c(),r?.conflictStyle==="diff3"?gr(a):gr(Js(a))}function qe(t,e,n,r){let i=r?.markerSize??7,s=r?.conflictStyle??"merge",a=`${"<".repeat(i)}${r?.a?` ${r.a}`:""}`,o=`${"|".repeat(i)}${r?.o?` ${r.o}`:""}`,c="=".repeat(i),f=`${">".repeat(i)}${r?.b?` ${r.b}`:""}`,l=Zs(t,e,n,{conflictStyle:s}),u=!1,m=[];for(let h of l)h.type==="ok"?m.push(...h.lines):(u=!0,s==="diff3"?m.push(a,...h.a,o,...h.o,c,...h.b,f):m.push(a,...h.a,c,...h.b,f));return{conflict:u,result:m}}function Js(t){let e=[];for(let n of t)n.type==="ok"?e.push(n):e.push(...Qs(n));return e}function Qs(t){let{a:e,b:n}=t;if(e.length===0||n.length===0)return[t];if(yr(e,n))return[t];let r=Lt(e,n);if(r.length===0)return[{type:"ok",lines:e}];let i=[],s=0;for(let o of r){let c=o.buffer1[0];c-s>0&&i.push({type:"ok",lines:e.slice(s,c)});let l=c+o.buffer1[1],u=o.buffer2[0]+o.buffer2[1];i.push({type:"conflict",a:e.slice(c,l),o:[],b:n.slice(o.buffer2[0],u)}),s=l}return e.length-s>0&&i.push({type:"ok",lines:e.slice(s)}),i.length===1&&i[0].type==="conflict"?[t]:i}function gr(t){if(t.length<3)return t;let e=[t[0]];for(let r=1;r>>>>>>")||!a?`${o.join(` ++`}function ve(t){let e=t.lastIndexOf("/");return e>=0?t.slice(e+1):t}function Ss(t,e){if(t.length===0)return;if(t.length===1)return t.shift();let n=ve(e),r=0;for(let i=0;i0){let g=Ss(d,m.path);g&&f.push({oldPath:g.path,newPath:m.path,oldHash:g.oldHash??h,newHash:h,similarity:100,oldMode:g.oldMode,newMode:m.newMode})}else l.push(m)}let u=[...s.values()].flat();if(u.length>0&&l.length>0){let m=await js(t,u,l,r);if(m.length>0){let h=new Set(m.map(g=>g.oldPath)),d=new Set(m.map(g=>g.newPath));u=u.filter(g=>!h.has(g.path)),l=l.filter(g=>!d.has(g.path)),f.push(...m)}}if(i>0&&u.length*l.length>i*i)return{remaining:[...c,...u,...l],renames:f,neededRenameLimit:Math.max(u.length,l.length)};if(u.length>0&&l.length>0){let m=await Ls(t,u,l,r);if(m.length>0){let h=new Set(m.map(g=>g.oldPath)),d=new Set(m.map(g=>g.newPath));u=u.filter(g=>!h.has(g.path)),l=l.filter(g=>!d.has(g.path)),f.push(...m)}}return{remaining:[...c,...u,...l],renames:f}}async function js(t,e,n,r){let i=new Map;for(let o=0;o>>25)>>>0,i=(i<<7^c>>>25)>>>0,r=r+o>>>0,n++,n<64&&o!==10)continue;let f=(r+Math.imul(i,97))%mr;e.set(f,(e.get(f)??0)+n),n=0,r=0,i=0}if(n>0){let a=(r+Math.imul(i,97))%mr;e.set(a,(e.get(a)??0)+n)}let s=[];for(let[a,o]of e)s.push({hash:a,count:o});return s.sort((a,o)=>a.hash-o.hash),s}function Ms(t,e){let n=0,r=0,i=0,s=0;for(;i=a.hash)break;r+=f.count,s++}let o=a.count,c=0;if(s=r){let b=ve(u.path)===ve(d.path)?1:0;a.push({similarity:p,nameScore:b,delIdx:l,addIdx:h})}}}a.sort((l,u)=>u.similarity-l.similarity||u.nameScore-l.nameScore);let o=new Set,c=new Set,f=[];for(let{similarity:l,delIdx:u,addIdx:m}of a){if(o.has(u)||c.has(m))continue;o.add(u),c.add(m);let h=e[u],d=n[m];!h||!d||f.push({oldPath:h.path,newPath:d.path,oldHash:h.oldHash??"",newHash:d.newHash??"",similarity:l,oldMode:h.oldMode,newMode:d.newMode})}return f}async function ge(t,e,n){return(await Pe(t,e)).get(n)?.hash??null}async function dr(t,e,n,r){let i=await le(t,e,n);if(!i.find(f=>f.status==="added"&&f.path===r))return null;let a=await lt(t,"diff"),{renames:o}=await xe(t,i,{limit:a});return o.find(f=>f.newPath===r)?.oldPath??null}async function Ds(t,e,n,r,i,s){let a=await ge(t,(await v(t,e)).tree,n);if(!a){let g=new Map,p=await v(t,e);for(let b of r)g.set(b.finalIdx,ye(e,n,b.currentLine,s+b.finalIdx,i[b.finalIdx],p,!1,void 0));return g}let o=await H(t,a),c=ee(o),f=new Array(i.length),l=[...r],u=e,m=n,h=c;for(;l.length>0;){let g=await v(t,u);if(g.parents.length===0){for(let I of l)f[I.finalIdx]=ye(u,m,I.currentLine,s+I.finalIdx,i[I.finalIdx],g,!0,void 0);break}let p=await ge(t,g.tree,m),b=null,E=[];for(let I of g.parents){let T=await v(t,I),k=m,$=await ge(t,T.tree,k);if(!$){let A=await dr(t,T.tree,g.tree,m);A&&(k=A,$=await ge(t,T.tree,k))}if($&&(E.push({hash:I,path:k,blobHash:$}),$===p)){b={hash:I,path:k};break}}if(b){u=b.hash,m=b.path;continue}if(E.length===0){for(let I of l)f[I.finalIdx]=ye(u,m,I.currentLine,s+I.finalIdx,i[I.finalIdx],g,!1,void 0);break}let C=E[0],j=await H(t,C.blobHash),P=ee(j),w=Re(P,h),R=new Map;for(let I of w)I.type==="keep"&&R.set(I.newLineNo,I.oldLineNo);let O=[];for(let I of l){let T=R.get(I.currentLine);T!==void 0?O.push({finalIdx:I.finalIdx,currentLine:T}):f[I.finalIdx]=ye(u,m,I.currentLine,s+I.finalIdx,i[I.finalIdx],g,!1,{hash:C.hash,path:C.path})}l=O,u=C.hash,m=C.path,h=P}let d=new Map;for(let g of r)f[g.finalIdx]&&d.set(g.finalIdx,f[g.finalIdx]);return d}async function pr(t,e,n,r){let i=await v(t,e),s=await ge(t,i.tree,n);if(!s)throw new Error(`no such path '${n}' in ${e.slice(0,7)}`);let a=await H(t,s),o=ee(a),c=r?.startLine??1,f=r?.endLine??o.length,l=o.slice(c-1,f),u=new Array(l.length),m=l.map((p,b)=>({finalIdx:b,currentLine:c+b})),h=e,d=n,g=o;for(;m.length>0;){let p=await v(t,h);if(p.parents.length===0){for(let R of m)u[R.finalIdx]=ye(h,d,R.currentLine,c+R.finalIdx,l[R.finalIdx],p,!0,void 0);break}let b=await ge(t,p.tree,d),E=[],C=null;for(let R of p.parents){let O=await v(t,R),I=d,T=await ge(t,O.tree,I);if(!T){let k=await dr(t,O.tree,p.tree,d);k&&(I=k,T=await ge(t,O.tree,I))}if(T){let k={hash:R,path:I,blobHash:T};if(E.push(k),T===b){C=k;break}}}if(C){h=C.hash,d=C.path;continue}if(E.length===0){for(let R of m)u[R.finalIdx]=ye(h,d,R.currentLine,c+R.finalIdx,l[R.finalIdx],p,!1,void 0);break}if(E.length===1){let R=E[0],O=await H(t,R.blobHash),I=ee(O),T=Re(I,g),k=new Map;for(let A of T)A.type==="keep"&&k.set(A.newLineNo,A.oldLineNo);let $=[];for(let A of m){let J=k.get(A.currentLine);J!==void 0?$.push({finalIdx:A.finalIdx,currentLine:J}):u[A.finalIdx]=ye(h,d,A.currentLine,c+A.finalIdx,l[A.finalIdx],p,!1,{hash:R.hash,path:R.path})}m=$,h=R.hash,d=R.path,g=I;continue}let j=[];for(let R of E){let O=await H(t,R.blobHash),I=ee(O),T=Re(I,g),k=new Map;for(let $ of T)$.type==="keep"&&k.set($.newLineNo,$.oldLineNo);j.push({info:R,newToOld:k})}let P=new Map;for(let R of m){let O=!1;for(let I=0;I0){m=w.lines,h=w.info.hash,d=w.info.path;let R=await H(t,w.info.blobHash);g=ee(R)}else break}return u}function ye(t,e,n,r,i,s,a,o){return{hash:t,origPath:e,origLine:n,finalLine:r,content:i,author:s.author,committer:s.committer,summary:s.message.split(` ++`)[0],boundary:a,previous:o}}var $e=class{heap=[];nextEpoch=0;get size(){return this.heap.length}push(e){this.heap.push({entry:e,epoch:this.nextEpoch++}),this.siftUp(this.heap.length-1)}pop(){let{heap:e}=this;if(e.length===0)return;let n=e[0],r=e.pop();return e.length>0&&(e[0]=r,this.siftDown(0)),n.entry}higher(e,n){let r=e.entry.commit.committer.timestamp,i=n.entry.commit.committer.timestamp;return r>i||r===i&&e.epoch0;){let r=e-1>>1;if(!this.higher(n[e],n[r]))break;[n[r],n[e]]=[n[e],n[r]],e=r}}siftDown(e){let{heap:n}=this,r=n.length;for(;;){let i=e,s=2*e+1,a=2*e+2;if(s0;){let l=s.pop();if(i.has(l.hash))continue;if(i.add(l.hash),yield l,o!==void 0&&++c>=o)return;if(a?.has(l.hash))continue;let u=n?.firstParent?l.commit.parents.slice(0,1):l.commit.parents;for(let m of u)if(!i.has(m))try{s.push(await ut(t,m))}catch{}}}async function*Hs(t,e,n){let r=await yr(t,n?.exclude),i=new Set(r),s=new $e,a=n?.shallowBoundary,o=Array.isArray(e)?e:[e];for(let h of o)i.has(h)||s.push(await ut(t,h));let c=[],f=new Map;for(;s.size>0;){let h=s.pop();if(i.has(h.hash)||(i.add(h.hash),f.set(h.hash,c.length),c.push(h),a?.has(h.hash)))continue;let d=n?.firstParent?h.commit.parents.slice(0,1):h.commit.parents;for(let g of d)if(!i.has(g))try{s.push(await ut(t,g))}catch{}}let l=c.length;if(l===0)return;let u=new Int32Array(l);for(let h of c){let d=n?.firstParent?h.commit.parents.slice(0,1):h.commit.parents;for(let g of d){let p=f.get(g);p!==void 0&&(u[p]=(u[p]??0)+1)}}let m=[];for(let h=l-1;h>=0;h--)u[h]===0&&m.push(h);for(;m.length>0;){let h=m.pop();yield c[h];let d=n?.firstParent?c[h].commit.parents.slice(0,1):c[h].commit.parents;for(let g of d){let p=f.get(g);if(p!==void 0){let b=(u[p]??0)-1;u[p]=b,b===0&&m.push(p)}}}}async function gr(t,e,n){if(e===n)return{ahead:0,behind:0};let r=new Set;for await(let o of ue(t,e))r.add(o.hash);let i=new Set;for await(let o of ue(t,n))i.add(o.hash);let s=0;for(let o of r)i.has(o)||s++;let a=0;for(let o of i)r.has(o)||a++;return{ahead:s,behind:a}}async function yr(t,e){if(!e||e.length===0)return new Set;let n=new Set;for await(let r of ue(t,e))n.add(r.hash);return n}async function ut(t,e){return{hash:e,commit:await v(t,e)}}async function Bs(t,e){let n=new Set,r=[e],i=0;for(;i0;){let m=0,h=await u(l[0].hash);for(let E=1;Eh||j===h&&C.seqKs(e.type)+e.content)}}function Xs(t,e,n){let r=ee(t),i=ee(e),s=Re(r,i);return jt(s,n).map(Ys)}async function br(t,e){let n=await we(t,e);if(n)return n;throw new Error(`ref or commit '${e}' not found`)}async function wr(t,e,n,r){let i=await br(t,e),s=await br(t,n),a=await v(t,i),o=await v(t,s),c=await le(t,a.tree,o.tree),f=r?.renames!==!1,l=r?.paths,u=[];if(f){let h=await xe(t,c,{limit:r?.renameLimit});c=h.remaining,u=h.renames}let m=[];for(let h of c)l&&!l.some(d=>h.path.startsWith(d))||m.push({path:h.path,status:h.status,oldContent:h.oldHash?await H(t,h.oldHash):"",newContent:h.newHash?await H(t,h.newHash):"",oldHash:h.oldHash??void 0,newHash:h.newHash??void 0,oldMode:h.oldMode,newMode:h.newMode});for(let h of u)l&&!l.some(d=>h.newPath.startsWith(d)||h.oldPath.startsWith(d))||m.push({path:h.newPath,oldPath:h.oldPath,status:"renamed",oldContent:await H(t,h.oldHash),newContent:await H(t,h.newHash),oldHash:h.oldHash,newHash:h.newHash,oldMode:h.oldMode,newMode:h.newMode,similarity:h.similarity});return m.sort((h,d)=>h.path.localeCompare(d.path)),m}async function Zs(t,e,n,r){let i=await wr(t,e,n,r),s=r?.contextLines;return i.map(a=>({path:a.path,status:a.status,oldPath:a.oldPath,similarity:a.similarity,hunks:Xs(a.oldContent,a.newContent,s)}))}async function Js(t,e,n,r){let i=await wr(t,e,n,r),s=r?.contextLines,a="";for(let o of i)a+=lr({path:o.oldPath??o.path,oldContent:o.oldContent,newContent:o.newContent,oldHash:o.oldHash,newHash:o.newHash,oldMode:o.oldMode,newMode:o.newMode,isNew:o.status==="added",isDeleted:o.status==="deleted",renameTo:o.status==="renamed"?o.path:void 0,similarity:o.similarity,contextLines:s});return a}async function*Qs(t,e,n){if(n?.paths&&n.paths.length>0){let r=n?.limit,i=0;for await(let s of eo(t,e,n.paths,n))if(yield s,r!==void 0&&++i>=r)return;return}for await(let r of ue(t,e,n))yield{hash:r.hash,message:r.commit.message,tree:r.commit.tree,parents:r.commit.parents,author:r.commit.author,committer:r.commit.committer}}function Lt(t,e){return e.some(n=>t===n||t.startsWith(n.endsWith("/")?n:n+"/"))}async function*eo(t,e,n,r){let i=new Set;if(r?.exclude)for await(let f of ue(t,r.exclude))i.add(f.hash);let s=new Set(i),a=new $e,o=async f=>{if(!s.has(f))try{let l=await v(t,f);a.push({hash:f,commit:l})}catch{}},c=Array.isArray(e)?e:[e];for(let f of c)await o(f);for(;a.size>0;){let f=a.pop();if(s.has(f.hash))continue;s.add(f.hash);let{commit:l}=f,u=r?.firstParent?l.parents.slice(0,1):l.parents,m=()=>({hash:f.hash,message:l.message,tree:l.tree,parents:l.parents,author:l.author,committer:l.committer});if(u.length===0){(await le(t,null,l.tree)).some(g=>Lt(g.path,n))&&(yield m());continue}if(u.length===1){let d=u[0];try{let g=await v(t,d);(await le(t,g.tree,l.tree)).some(b=>Lt(b.path,n))&&(yield m())}catch{yield m()}await o(d);continue}let h=[];for(let d of u)try{let g=await v(t,d);(await le(t,g.tree,l.tree)).some(b=>Lt(b.path,n))||h.push(d)}catch{}if(h.length>0)await o(h[0]);else{yield m();for(let d of u)await o(d)}}}function to(t){let e=Math.abs(t),n=t<=0?"+":"-",r=String(Math.floor(e/60)).padStart(2,"0"),i=String(e%60).padStart(2,"0");return`${n}${r}${i}`}function Ke(t){if("timestamp"in t)return t;let e=t.date??new Date;return{name:t.name,email:t.email,timestamp:Math.floor(e.getTime()/1e3),timezone:to(e.getTimezoneOffset())}}async function Dt(t,e){let n=Ke(e.author),r=e.committer?Ke(e.committer):n,i=Ue({type:"commit",tree:e.tree,parents:e.parents,author:n,committer:r,message:e.message}),s=await N(t,"commit",i);return e.branch&&await Ir(t,e.branch,s),s}async function no(t,e){let n=Ke(e.tagger),r=Rn({type:"tag",object:e.target,objectType:e.targetType??"commit",name:e.name,tagger:n,message:e.message}),i=await N(t,"tag",r);return await t.refStore.writeRef(`refs/tags/${e.name}`,{type:"direct",hash:i}),i}async function xr(t,e){let n=e.branch?`refs/heads/${e.branch}`:null,r=n?await re(t,n):null,i=null;r&&(i=(await v(t,r)).tree);let s=[];for(let[m,h]of Object.entries(e.files))if(h===null)s.push({path:m,hash:null});else{let d=typeof h=="string"?new TextEncoder().encode(h):h,g=await N(t,"blob",d);s.push({path:m,hash:g})}let a;i?a=await Er(t,i,s):a=await Bt(t,null,Ht(s));let o=Ke(e.author),c=e.committer?Ke(e.committer):o,l=Ue({type:"commit",tree:a,parents:r?[r]:[],author:o,committer:c,message:e.message});return{hash:await N(t,"commit",l),parentHash:r}}async function ro(t,e){let{hash:n}=await xr(t,e);return await Ir(t,e.branch,n),n}async function Ir(t,e,n){let r=`refs/heads/${e}`;await t.refStore.writeRef(r,{type:"direct",hash:n}),await t.refStore.readRef("HEAD")||await t.refStore.writeRef("HEAD",{type:"symbolic",target:r})}async function io(t,e){let n=[...e].sort((s,a)=>s.name.localeCompare(a.name)),r=await Promise.all(n.map(async s=>{let a=s.mode;return a||(a=(await t.objectStore.read(s.hash)).type==="tree"?"040000":"100644"),{mode:a,name:s.name,hash:s.hash}})),i=be({type:"tree",entries:r});return N(t,"tree",i)}async function so(t,e){return N(t,"blob",new TextEncoder().encode(e))}async function Er(t,e,n){return Bt(t,e,Ht(n))}function Ht(t){let e=new Map,n=new Map;for(let r of t){let i=r.path.indexOf("/");if(i===-1)e.set(r.path,{hash:r.hash,mode:r.mode??"100644"});else{let s=r.path.slice(0,i),a=r.path.slice(i+1),o=n.get(s);o||(o=[],n.set(s,o)),o.push({...r,path:a})}}return{files:e,dirs:n}}async function Rr(t,e){let n=await F(t,e);if(n.type!=="tree")throw new Error(`Expected tree object, got ${n.type}`);return ce(n.content).entries}async function Bt(t,e,n){let r=new Map;if(e)for(let a of await Rr(t,e))r.set(a.name,a);for(let[a,{hash:o,mode:c}]of n.files)o===null?r.delete(a):r.set(a,{name:a,hash:o,mode:c});for(let[a,o]of n.dirs){let c=r.get(a),f=c?.mode==="040000"?c.hash:null,l=Ht(o),u=await Bt(t,f,l);(await Rr(t,u)).length===0?r.delete(a):r.set(a,{name:a,hash:u,mode:"040000"})}let i=[...r.values()].sort((a,o)=>{let c=a.mode==="040000"?`${a.name}/`:a.name,f=o.mode==="040000"?`${o.name}/`:o.name;return cf?1:0}),s=be({type:"tree",entries:i});return N(t,"tree",s)}function Nt(t,e){let n=t.length,r=e.length;if(n===0&&r===0)return[];if(n===0)return[{buffer1:[0,0],buffer2:[0,r]}];if(r===0)return[{buffer1:[0,n],buffer2:[0,0]}];let{changedOld:i,changedNew:s}=$t(t,e);return oo(i,n,s,r)}function oo(t,e,n,r){let i=[],s=0,a=0;for(;s=e&&a>=r)break;let o=s,c=a;for(;so||a>c)&&i.push({buffer1:[o,s-o],buffer2:[c,a-c]})}return i}function ao(t,e,n){let r=[];for(let c of Nt(e,t))r.push({ab:"a",oStart:c.buffer1[0],oLength:c.buffer1[1],abStart:c.buffer2[0],abLength:c.buffer2[1]});for(let c of Nt(e,n))r.push({ab:"b",oStart:c.buffer1[0],oLength:c.buffer1[1],abStart:c.buffer2[0],abLength:c.buffer2[1]});r.sort((c,f)=>c.oStart-f.oStart);let i=[],s=0;function a(c){c>s&&(i.push({stable:!0,buffer:"o",bufferStart:s,bufferLength:c-s,content:e.slice(s,c)}),s=c)}let o=0;for(;ol)break;l=Math.max(l,m.oStart+m.oLength),u.push(m),o++}if(u.length===1){if(c.abLength>0){let m=c.ab==="a"?t:n;i.push({stable:!0,buffer:c.ab,bufferStart:c.abStart,bufferLength:c.abLength,content:m.slice(c.abStart,c.abStart+c.abLength)})}}else{let m={a:{abMin:t.length,abMax:-1,oMin:e.length,oMax:-1},b:{abMin:n.length,abMax:-1,oMin:e.length,oMax:-1}};for(let b of u){let E=b.oStart,C=E+b.oLength,j=b.abStart,P=j+b.abLength,w=m[b.ab];w.abMin=Math.min(j,w.abMin),w.abMax=Math.max(P,w.abMax),w.oMin=Math.min(E,w.oMin),w.oMax=Math.max(C,w.oMax)}let h=m.a.abMin+(f-m.a.oMin),d=m.a.abMax+(l-m.a.oMax),g=m.b.abMin+(f-m.b.oMin),p=m.b.abMax+(l-m.b.oMax);i.push({stable:!1,a:t.slice(h,d),o:e.slice(f,l),b:n.slice(g,p)})}s=l}return a(e.length),i}function co(t,e,n,r){let i=r?.excludeFalseConflicts??!0,s=ao(t,e,n),a=[],o=[];function c(){o.length&&(a.push({type:"ok",lines:o}),o=[])}for(let f of s)f.stable?o.push(...f.content):i&&Or(f.a,f.b)?o.push(...f.a):(c(),a.push({type:"conflict",a:f.a,o:f.o,b:f.b}));return c(),r?.conflictStyle==="diff3"?kr(a):kr(fo(a))}function Ye(t,e,n,r){let i=r?.markerSize??7,s=r?.conflictStyle??"merge",a=`${"<".repeat(i)}${r?.a?` ${r.a}`:""}`,o=`${"|".repeat(i)}${r?.o?` ${r.o}`:""}`,c="=".repeat(i),f=`${">".repeat(i)}${r?.b?` ${r.b}`:""}`,l=co(t,e,n,{conflictStyle:s}),u=!1,m=[];for(let h of l)h.type==="ok"?m.push(...h.lines):(u=!0,s==="diff3"?m.push(a,...h.a,o,...h.o,c,...h.b,f):m.push(a,...h.a,c,...h.b,f));return{conflict:u,result:m}}function fo(t){let e=[];for(let n of t)n.type==="ok"?e.push(n):e.push(...lo(n));return e}function lo(t){let{a:e,b:n}=t;if(e.length===0||n.length===0)return[t];if(Or(e,n))return[t];let r=Nt(e,n);if(r.length===0)return[{type:"ok",lines:e}];let i=[],s=0;for(let o of r){let c=o.buffer1[0];c-s>0&&i.push({type:"ok",lines:e.slice(s,c)});let l=c+o.buffer1[1],u=o.buffer2[0]+o.buffer2[1];i.push({type:"conflict",a:e.slice(c,l),o:[],b:n.slice(o.buffer2[0],u)}),s=l}return e.length-s>0&&i.push({type:"ok",lines:e.slice(s)}),i.length===1&&i[0].type==="conflict"?[t]:i}function kr(t){if(t.length<3)return t;let e=[t[0]];for(let r=1;r>>>>>>")||!a?`${o.join(` + `)} + `:o.join(` + `)}function X(t){if(t==="")return[];let e=t.split(` +-`);if(e[e.length-1]==="")e.pop();else{let n=e[e.length-1]??"";e[e.length-1]=`${n}\0`}return e}function Dt(t){return t.endsWith("\0")?t.slice(0,-1):t}function yr(t,e){if(t.length!==e.length)return!1;for(let n=0;nx.newPath)),k=new Set(m.renames.map(x=>x.newPath)),w=wr(n,r),R=wr(n,i),P=Rr(w,i,n),I=Rr(R,r,n),T=xr(u.renames,P),O=xr(m.renames,I),j=Ir(T),A=Ir(O);for(let x of[...j.keys()])A.has(x)&&(j.delete(x),A.delete(x));let ie=new Set(j.keys()),xe=new Set(A.keys());if(A.size>0)for(let x of c){if(x.status!=="added"||v.has(x.path))continue;let y=Er(x.path,A,ie);if(!y)continue;if(e.has(y)||n.has(y)||r.has(y)||i.has(y)){if(r.has(y)){C(y,`CONFLICT (implicit dir rename): Existing file/dir at ${y} in the way of implicit directory rename(s) putting the following path(s) there: ${x.path}.`,1);continue}let D=r.get(x.path),M=i.get(y)??n.get(y);o.entries.push(z(y,D.mode,D.hash,2)),M&&o.entries.push(z(y,M.mode,M.hash,3)),o.worktreeBlobs.set(y,{hash:D.hash,mode:D.mode}),o.conflicts.push({path:y,reason:"add-add"}),C(y,`CONFLICT (file location): ${x.path} added in ${b} inside a directory that was renamed in ${E}, suggesting it should perhaps be moved to ${y}.`,1);let U=e.get(x.path);U&&(U.merged={result:null,clean:!0}),p.add(x.path);continue}let S=r.get(x.path);o.entries.push(z(y,S.mode,S.hash,2)),o.worktreeBlobs.set(y,{hash:S.hash,mode:S.mode}),o.conflicts.push({path:y,reason:"directory-rename"}),C(y,`CONFLICT (file location): ${x.path} added in ${b} inside a directory that was renamed in ${E}, suggesting it should perhaps be moved to ${y}.`,1);let L=e.get(x.path);L&&(L.merged={result:null,clean:!0}),p.add(x.path)}if(j.size>0)for(let x of f){if(x.status!=="added"||k.has(x.path))continue;let y=Er(x.path,j,xe);if(!y)continue;if(e.has(y)||n.has(y)||r.has(y)||i.has(y)){if(i.has(y)){C(y,`CONFLICT (implicit dir rename): Existing file/dir at ${y} in the way of implicit directory rename(s) putting the following path(s) there: ${x.path}.`,1);continue}let D=i.get(x.path),M=r.get(y)??n.get(y);M&&o.entries.push(z(y,M.mode,M.hash,2)),o.entries.push(z(y,D.mode,D.hash,3)),o.worktreeBlobs.set(y,{hash:D.hash,mode:D.mode}),o.conflicts.push({path:y,reason:"add-add"}),C(y,`CONFLICT (file location): ${x.path} added in ${E} inside a directory that was renamed in ${b}, suggesting it should perhaps be moved to ${y}.`,1);let U=e.get(x.path);U&&(U.merged={result:null,clean:!0}),p.add(x.path);continue}let S=i.get(x.path);o.entries.push(z(y,S.mode,S.hash,3)),o.worktreeBlobs.set(y,{hash:S.hash,mode:S.mode}),o.conflicts.push({path:y,reason:"directory-rename"}),C(y,`CONFLICT (file location): ${x.path} added in ${E} inside a directory that was renamed in ${b}, suggesting it should perhaps be moved to ${y}.`,1);let L=e.get(x.path);L&&(L.merged={result:null,clean:!0}),p.add(x.path)}let W=new Set(o.entries.map(x=>x.path));for(let x of W){let y=e.get(x);y&&(y.merged={result:null,clean:!0})}for(let x of p){if(W.has(x))continue;let y=e.get(x);if(!y||y.merged.clean)continue;y.filemask===7&&!y.pathConflict||(y.merged={result:null,clean:!0})}return o}function wr(t,e){let n=new Set;for(let s of t.keys()){let a=Z(s);for(;a;)n.add(a),a=Z(a)}let r=new Set;for(let s of e.keys()){let a=Z(s);for(;a;)r.add(a),a=Z(a)}let i=new Set;for(let s of n)r.has(s)||i.add(s);return i}function Rr(t,e,n){if(t.size===0)return t;let r=new Set;for(let i of e.keys()){if(n.has(i))continue;let s=Z(i)??"";t.has(s)&&r.add(s)}for(let i of[...r]){let s=Z(i);for(;s;)t.has(s)&&!r.has(s)&&r.add(s),s=Z(s)}return r}function xr(t,e){let n=new Map;for(let r of t){let i=Z(r.oldPath),s=Z(r.newPath),a=!0;for(;;){if(!a){let o=i.length+(i?1:0),c=s.length+(s?1:0),f=r.oldPath.slice(o,r.oldPath.indexOf("/",o)),l=r.newPath.slice(c,r.newPath.indexOf("/",c));if(f!==l)break}if(e.has(i)){let o=n.get(i);o||(o=new Map,n.set(i,o)),o.set(s,(o.get(s)??0)+1)}if(a=!1,!i||!s)break;i=Z(i),s=Z(s)}}return n}function Ir(t){let e=new Map;for(let[n,r]of t){let i=0,s=0,a=null;for(let[o,c]of r)c===i?s=i:c>i&&(i=c,a=o);i>0&&s!==i&&a!==null&&e.set(n,a)}return e}function Er(t,e,n){let r=Z(t);for(;r;){let s=e.get(r);if(s!==void 0){if(n.has(s))return null;let a=t.slice(r.length+1);return s?`${s}/${a}`:a}r=Z(r)}let i=e.get("");return i!==void 0&&!n.has(i)?`${i}/${t}`:null}function Z(t){let e=t.lastIndexOf("/");return e===-1?"":t.slice(0,e)}async function Or(t,e,n,r,i,s,a,o,c,f=!1,l,u){let m=f?o.get(n):c.get(n),h=f?a:s;if(m.hash===h.hash){e.entries.push(z(n,m.mode,m.hash)),e.msgBuf.push({sortKey:r,subOrder:0,text:`Auto-merging ${r}`});return}let g=await Cr(t,i,s,a,l,f?{oursPath:r,theirsPath:n}:{oursPath:n,theirsPath:r},8,u);if(m.hash===g.hash)e.entries.push(z(n,m.mode,g.hash));else if(e.conflicts.push({path:n,reason:"add-add"}),e.msgBuf.push({sortKey:n,subOrder:0,text:`Auto-merging ${n}`}),e.msgBuf.push({sortKey:n,subOrder:1,text:`CONFLICT (add/add): Merge conflict in ${n}`}),f){e.entries.push(Y(n,m,2)),e.entries.push(z(n,a.mode,g.hash,3));let p=await ft(t,m.hash,g.hash,m.mode,l);e.worktreeBlobs.set(n,{hash:p,mode:m.mode})}else{e.entries.push(z(n,s.mode,g.hash,2)),e.entries.push(Y(n,m,3));let p=await ft(t,g.hash,m.hash,s.mode,l);e.worktreeBlobs.set(n,{hash:p,mode:s.mode})}}async function Cr(t,e,n,r,i,s,a,o){if(n.hash===e.hash)return{hash:r.hash,conflict:!1};if(r.hash===e.hash)return{hash:n.hash,conflict:!1};if(n.hash===r.hash)return{hash:n.hash,conflict:!1};if(fe(e.mode)||fe(n.mode)||fe(r.mode))return{hash:n.hash,conflict:!0};let c=await B(t,e.hash),f=await B(t,n.hash),l=await B(t,r.hash);if(J(f)||J(l)||J(c))return{hash:n.hash,conflict:!0};if(o){let w=await o({path:e.path??n.path??r.path??"",base:c,ours:f,theirs:l});if(w!==null)return{hash:await N(t,"blob",re.encode(w.content)),conflict:w.conflict}}let u=X(c),m=X(f),h=X(l),d=i?.conflictStyle,g=qe(m,u,h,{conflictStyle:d});if(!g.conflict)return{hash:await Bt(t,g.result),conflict:!1};let p=i?.a??"HEAD",b=i?.b??"theirs",E=s?.oursPath?`${p}:${s.oursPath}`:p,C=s?.theirsPath?`${b}:${s.theirsPath}`:b,v=Re(f,c,l,{a:E,b:C,markerSize:a??7,conflictStyle:d});return{hash:await N(t,"blob",re.encode(v)),conflict:!0}}async function ft(t,e,n,r,i){let s=await B(t,e),a=await B(t,n),o=Re(s,"",a,{a:i?.a??"HEAD",b:i?.b??"theirs",conflictStyle:i?.conflictStyle});return N(t,"blob",re.encode(o))}function Y(t,e,n=0){return z(t,e.mode,e.hash,n)}function z(t,e,n,r=0){return{path:t,mode:parseInt(e,8),hash:n,stage:r,stat:me()}}async function ro(t,e,n,r,i){let s=[...r.entries],a=[...r.conflicts],o=[...r.msgBuf],c=new Map(r.worktreeBlobs);function f(d,g,p=0){o.push({sortKey:d,subOrder:p,text:g})}for(let d of[...e.keys()].sort()){let g=e.get(d);if(g.merged.clean){g.merged.result?.hash&&s.push(H(d,g.merged.result.hash,g.merged.result.mode));continue}await io(t,g,n,s,a,f,c,i)}o.sort((d,g)=>(d.sortKeyg.sortKey?1:0)||d.subOrder-g.subOrder);let l=o.map(d=>d.text),u=[],m=new Set;for(let d of s)d.stage===0&&(u.push(d),m.add(d.path));for(let[d,g]of c)m.has(d)||u.push(H(d,g.hash,g.mode));u.sort((d,g)=>Fe(d.path,g.path));let h=await Et(t,u);return{entries:s,conflicts:a,messages:l,resultTree:h,neededRenameLimit:r.neededRenameLimit}}async function io(t,e,n,r,i,s,a,o){let c=e.path,[f,l,u]=e.stages,m=f?.hash??null,h=l?.hash??null,d=u?.hash??null;if(h===null&&d!==null&&m!==null){i.push({path:c,reason:"delete-modify",deletedBy:"ours"});let g=n?.a??"HEAD",p=n?.b??"theirs";s(c,`CONFLICT (modify/delete): ${c} deleted in ${g} and modified in ${p}. Version ${p} of ${c} left in tree.`),f&&r.push(H(c,m,f.mode,1)),r.push(H(c,d,u.mode,3)),a.set(c,{hash:d,mode:u.mode});return}if(d===null&&h!==null&&m!==null){i.push({path:c,reason:"delete-modify",deletedBy:"theirs"});let g=n?.b??"theirs",p=n?.a??"HEAD";s(c,`CONFLICT (modify/delete): ${c} deleted in ${g} and modified in ${p}. Version ${p} of ${c} left in tree.`),f&&r.push(H(c,m,f.mode,1)),r.push(H(c,h,l.mode,2)),a.set(c,{hash:h,mode:l.mode});return}if(m===null&&h!==null&&d!==null){if(h===d){r.push(H(c,h,l.mode));return}s(c,`Auto-merging ${c}`,0);let g=await B(t,h),p=await B(t,d);if(J(g)||J(p)){i.push({path:c,reason:"add-add"}),s(c,`warning: Cannot merge binary files: ${c} (${n?.a??"HEAD"} vs. ${n?.b??"theirs"})`,-1),s(c,`CONFLICT (add/add): Merge conflict in ${c}`,1),r.push(H(c,h,l.mode,2)),r.push(H(c,d,u.mode,3)),a.set(c,{hash:h,mode:l.mode});return}if(o){let R=await o({path:c,base:null,ours:g,theirs:p});if(R!==null){let P=await N(t,"blob",re.encode(R.content));if(!R.conflict){r.push(H(c,P,l.mode));return}i.push({path:c,reason:"add-add"}),s(c,`CONFLICT (add/add): Merge conflict in ${c}`,1),r.push(H(c,h,l.mode,2)),r.push(H(c,d,u.mode,3)),a.set(c,{hash:P,mode:l.mode});return}}let b=X(""),E=X(g),C=X(p),v=qe(E,b,C,{conflictStyle:n?.conflictStyle});if(!v.conflict){let R=await Bt(t,v.result);r.push(H(c,R,l.mode));return}i.push({path:c,reason:"add-add"}),s(c,`CONFLICT (add/add): Merge conflict in ${c}`,1),r.push(H(c,h,l.mode,2)),r.push(H(c,d,u.mode,3));let k=Re(g,"",p,{a:n?.a??"HEAD",b:n?.b??"theirs",conflictStyle:n?.conflictStyle}),w=await N(t,"blob",re.encode(k));a.set(c,{hash:w,mode:l.mode});return}if(m!==null&&h!==null&&d!==null){if(h===m){r.push(H(c,d,u.mode));return}if(d===m){r.push(H(c,h,l.mode));return}if(h===d){r.push(H(c,h,l.mode));return}if(s(c,`Auto-merging ${c}`,0),fe(f.mode)||fe(l.mode)||fe(u.mode)){i.push({path:c,reason:"content"}),s(c,`CONFLICT (content): Merge conflict in ${c}`,1),r.push(H(c,m,f.mode,1)),r.push(H(c,h,l.mode,2)),r.push(H(c,d,u.mode,3)),a.set(c,{hash:h,mode:l.mode});return}let g=await B(t,m),p=await B(t,h),b=await B(t,d);if(J(p)||J(b)||J(g)){i.push({path:c,reason:"content"}),s(c,`warning: Cannot merge binary files: ${c} (${n?.a??"HEAD"} vs. ${n?.b??"theirs"})`,-1),s(c,`CONFLICT (content): Merge conflict in ${c}`,1),r.push(H(c,m,f.mode,1)),r.push(H(c,h,l.mode,2)),r.push(H(c,d,u.mode,3)),a.set(c,{hash:h,mode:l.mode});return}if(o){let w=await o({path:c,base:g,ours:p,theirs:b});if(w!==null){let R=await N(t,"blob",re.encode(w.content));if(!w.conflict){r.push(H(c,R,l.mode));return}let P=e.pathnames[1],I=e.pathnames[2],T=P!==c||I!==c,O={path:c,reason:"content"};T&&(P!==c&&(O.oursOrigPath=P),I!==c&&(O.theirsOrigPath=I)),i.push(O),s(c,`CONFLICT (content): Merge conflict in ${c}`,1),r.push(H(c,m,f.mode,1)),r.push(H(c,h,l.mode,2)),r.push(H(c,d,u.mode,3)),a.set(c,{hash:R,mode:l.mode});return}}let E=X(g),C=X(p),v=X(b),k=qe(C,E,v,{conflictStyle:n?.conflictStyle});if(k.conflict){let w=e.pathnames[1],R=e.pathnames[2],P=w!==c||R!==c,I={path:c,reason:"content"};P&&(w!==c&&(I.oursOrigPath=w),R!==c&&(I.theirsOrigPath=R)),i.push(I),s(c,`CONFLICT (content): Merge conflict in ${c}`,1),r.push(H(c,m,f.mode,1)),r.push(H(c,h,l.mode,2)),r.push(H(c,d,u.mode,3));let T=P?`${n?.a??"HEAD"}:${w}`:n?.a??"HEAD",O=P?`${n?.b??"theirs"}:${R}`:n?.b??"theirs",j=Re(p,g,b,{a:T,b:O,conflictStyle:n?.conflictStyle}),A=await N(t,"blob",re.encode(j));a.set(c,{hash:A,mode:l.mode})}else{let w=await Bt(t,k.result);r.push(H(c,w,l.mode))}return}}var so=200;async function Pr(t,e,n,r,i,s){let a=await Promise.all(r.map(async m=>({hash:m,timestamp:(await $(t,m)).committer.timestamp})));a.sort((m,h)=>m.timestamp-h.timestamp);let o=a.map(m=>m.hash),c=o[0],f=c,l=(await $(t,c)).tree,u;for(let m=1;m=so)g=l;else{let E=await ze(t,f,h);if(E.length===0)g=null;else if(E.length===1)g=(await $(t,E[0])).tree;else{let C=await Pr(t,f,h,E,i+1,s);g=C.tree,u=Math.max(u??0,C.neededRenameLimit??0)||void 0}}let p=await je(t,g,l,d,void 0,s);u=Math.max(u??0,p.neededRenameLimit??0)||void 0,l=await oo(t,p,i);let b=Ne({type:"commit",tree:l,parents:[f,h],author:br,committer:br,message:"merged common ancestors"});f=await N(t,"commit",b)}return{tree:l,neededRenameLimit:u}}async function oo(t,e,n){let r=e.entries.filter(o=>o.stage===0),i=new Map;for(let o of e.entries)o.stage>0&&i.set(`${o.path}\0${o.stage}`,o);let s=(o,c)=>i.get(`${o}\0${c}`),a={a:"Temporary merge branch 1",b:"Temporary merge branch 2",markerSize:7+n*2};for(let o of e.conflicts){if(o.reason==="delete-modify"||o.reason==="rename-delete"){let l=s(o.path,1);if(l){r.push({...l,stage:0});continue}}if(o.reason==="rename-rename"){let l=o.oursPath??o.path,u=o.theirsPath??o.path,m=s(o.path,1),h=s(l,2),d=s(u,3);if(h&&d){let g=$e.decode((await F(t,h.hash)).content),p=$e.decode((await F(t,d.hash)).content),b=m?$e.decode((await F(t,m.hash)).content):"",E=8+n*2,C=a.a??"Temporary merge branch 1",v=a.b??"Temporary merge branch 2",k=Re(g,b,p,{a:`${C}:${l}`,o:a.o,b:`${v}:${u}`,markerSize:E}),w=await N(t,"blob",re.encode(k));r.push({path:l,mode:h.mode,hash:w,stage:0,stat:me()}),r.push({path:u,mode:d.mode,hash:w,stage:0,stat:me()});continue}else if(h){r.push({...h,stage:0});continue}}let c=s(o.path,2),f=s(o.path,3);if(c&&f&&(o.reason==="content"||o.reason==="add-add")){let l=$e.decode((await F(t,c.hash)).content),u=$e.decode((await F(t,f.hash)).content),m=o.reason==="content"?s(o.path,1):null,h=m?$e.decode((await F(t,m.hash)).content):"",d=o.oursOrigPath||o.theirsOrigPath,g=a.a??"Temporary merge branch 1",p=a.b??"Temporary merge branch 2",b=d?`${g}:${o.oursOrigPath??o.path}`:g,E=d?`${p}:${o.theirsOrigPath??o.path}`:p,C=Re(l,h,u,{a:b,o:a.o,b:E,markerSize:a.markerSize}),v=await N(t,"blob",re.encode(C));r.push({path:o.path,mode:c.mode,hash:v,stage:0,stat:me()})}else c?r.push({...c,stage:0}):f&&r.push({...f,stage:0})}return r.sort((o,c)=>Fe(o.path,c.path)),Et(t,r)}async function Bt(t,e){let n=e.map(Dt);if(n.length===0)return N(t,"blob",re.encode(""));let s=(e[e.length-1]??"").endsWith("\0")?n.join(` ++`);if(e[e.length-1]==="")e.pop();else{let n=e[e.length-1]??"";e[e.length-1]=`${n}\0`}return e}function Gt(t){return t.endsWith("\0")?t.slice(0,-1):t}function Or(t,e){if(t.length!==e.length)return!1;for(let n=0;nFt.has(r))?e===t?n:e:null}async function ho(t,e,n,r,i,s,a){let o={entries:[],conflicts:[],msgBuf:[],worktreeBlobs:new Map},c=[],f=[];for(let[x,y]of n)r.has(x)||c.push({path:x,status:"deleted",oldHash:y.hash,oldMode:y.mode}),i.has(x)||f.push({path:x,status:"deleted",oldHash:y.hash,oldMode:y.mode});for(let[x,y]of r)n.has(x)||c.push({path:x,status:"added",newHash:y.hash,newMode:y.mode});for(let[x,y]of i)n.has(x)||f.push({path:x,status:"added",newHash:y.hash,newMode:y.mode});let l=await lt(t,"merge"),u=await xe(t,c,{limit:l}),m=await xe(t,f,{limit:l});if(o.neededRenameLimit=Math.max(u.neededRenameLimit??0,m.neededRenameLimit??0)||void 0,u.renames.length===0&&m.renames.length===0)return o;let h=new Map,d=new Map;for(let x of u.renames)h.set(x.oldPath,x);for(let x of m.renames)d.set(x.oldPath,x);let g=new Set;for(let[x]of r)!n.has(x)&&i.has(x)&&g.add(x);let p=new Set,b=s?.a??"HEAD",E=s?.b??"theirs";function C(x,y,S=0){o.msgBuf.push({sortKey:x,subOrder:S,text:y})}for(let x of[...n.keys()].sort()){let y=h.get(x),S=d.get(x);if(!y&&!S)continue;let D=n.get(x);if(p.add(x),y&&S)if(p.add(y.newPath),p.add(S.newPath),y.newPath===S.newPath){let L=r.get(y.newPath),M=i.get(S.newPath);if(L.hash===M.hash){let G=Xe(D.mode,L.mode,M.mode);o.entries.push(_(y.newPath,G??L.mode,L.hash))}else{let G=Ut(e,y.newPath);G.stages=[{hash:D.hash,mode:D.mode},{hash:L.hash,mode:L.mode},{hash:M.hash,mode:M.mode}],G.pathnames=[x,y.newPath,S.newPath],G.filemask=7,G.merged={result:null,clean:!1}}}else{let L=r.get(y.newPath),M=i.get(S.newPath),G=await Ar(t,D,L,M,s,void 0,void 0,a);G.conflict&&C(x,`Auto-merging ${x}`,-1),o.conflicts.push({path:x,reason:"rename-rename",oursPath:y.newPath,theirsPath:S.newPath}),C(x,`CONFLICT (rename/rename): ${x} renamed to ${y.newPath} in ${b} and to ${S.newPath} in ${E}.`);let W=Xe(D.mode,L.mode,M.mode),V=W??L.mode,Zt=W??M.mode;o.entries.push(me(x,D,1)),o.entries.push(_(y.newPath,V,G.hash,2)),o.entries.push(_(S.newPath,Zt,G.hash,3)),o.worktreeBlobs.set(y.newPath,{hash:G.hash,mode:V}),o.worktreeBlobs.set(S.newPath,{hash:G.hash,mode:Zt})}else if(y){p.add(y.newPath);let L=i.get(x),M=r.get(y.newPath),G=g.has(y.newPath);if(L)if(G)await jr(t,o,y.newPath,x,D,M,L,r,i,!1,s,a);else{let W=Xe(D.mode,M.mode,L.mode)??M.mode;if(L.hash===D.hash)o.entries.push(_(y.newPath,W,M.hash));else if(M.hash===D.hash)o.entries.push(_(y.newPath,W,L.hash));else{let V=Ut(e,y.newPath);V.stages=[{hash:D.hash,mode:D.mode},{hash:M.hash,mode:M.mode},{hash:L.hash,mode:L.mode}],V.pathnames=[x,y.newPath,x],V.filemask=7,V.merged={result:null,clean:!1}}}else{let W=i.get(y.newPath);if(o.conflicts.push({path:y.newPath,reason:"rename-delete",deletedBy:"theirs",oldPath:x}),C(y.newPath,`CONFLICT (rename/delete): ${x} renamed to ${y.newPath} in ${b}, but deleted in ${E}.`),W){o.conflicts.push({path:y.newPath,reason:"add-add"}),C(y.newPath,`Auto-merging ${y.newPath}`,0),C(y.newPath,`CONFLICT (add/add): Merge conflict in ${y.newPath}`,1),o.entries.push(me(y.newPath,M,2)),o.entries.push(me(y.newPath,W,3));let V=await mt(t,M.hash,W.hash,M.mode,s);o.worktreeBlobs.set(y.newPath,{hash:V,mode:M.mode})}else o.entries.push(_(y.newPath,D.mode,D.hash,1)),o.entries.push(me(y.newPath,M,2)),o.worktreeBlobs.set(y.newPath,{hash:M.hash,mode:M.mode}),M.hash!==D.hash&&C(y.newPath,`CONFLICT (modify/delete): ${y.newPath} deleted in ${E} and modified in ${b}. Version ${b} of ${y.newPath} left in tree.`,1)}}else if(S){p.add(S.newPath);let L=r.get(x),M=i.get(S.newPath),G=g.has(S.newPath);if(L)if(G)await jr(t,o,S.newPath,x,D,L,M,r,i,!0,s,a);else{let W=Xe(D.mode,L.mode,M.mode)??M.mode;if(L.hash===D.hash)o.entries.push(_(S.newPath,W,M.hash));else if(M.hash===D.hash)o.entries.push(_(S.newPath,W,L.hash));else{let V=Ut(e,S.newPath);V.stages=[{hash:D.hash,mode:D.mode},{hash:L.hash,mode:L.mode},{hash:M.hash,mode:M.mode}],V.pathnames=[x,x,S.newPath],V.filemask=7,V.merged={result:null,clean:!1}}}else{let W=r.get(S.newPath);if(o.conflicts.push({path:S.newPath,reason:"rename-delete",deletedBy:"ours",oldPath:x}),C(S.newPath,`CONFLICT (rename/delete): ${x} renamed to ${S.newPath} in ${E}, but deleted in ${b}.`),W){o.conflicts.push({path:S.newPath,reason:"add-add"}),C(S.newPath,`Auto-merging ${S.newPath}`,0),C(S.newPath,`CONFLICT (add/add): Merge conflict in ${S.newPath}`,1),o.entries.push(me(S.newPath,W,2)),o.entries.push(me(S.newPath,M,3));let V=await mt(t,W.hash,M.hash,W.mode,s);o.worktreeBlobs.set(S.newPath,{hash:V,mode:W.mode})}else o.entries.push(_(S.newPath,D.mode,D.hash,1)),o.entries.push(me(S.newPath,M,3)),o.worktreeBlobs.set(S.newPath,{hash:M.hash,mode:M.mode}),M.hash!==D.hash&&C(S.newPath,`CONFLICT (modify/delete): ${S.newPath} deleted in ${b} and modified in ${E}. Version ${E} of ${S.newPath} left in tree.`,1)}}}let j=new Set(u.renames.map(x=>x.newPath)),P=new Set(m.renames.map(x=>x.newPath)),w=Cr(n,r),R=Cr(n,i),O=Tr(w,i,n),I=Tr(R,r,n),T=Sr(u.renames,O),k=Sr(m.renames,I),$=vr(T),A=vr(k);for(let x of[...$.keys()])A.has(x)&&($.delete(x),A.delete(x));let J=new Set($.keys()),he=new Set(A.keys());if(A.size>0)for(let x of c){if(x.status!=="added"||j.has(x.path))continue;let y=$r(x.path,A,J);if(!y)continue;if(e.has(y)||n.has(y)||r.has(y)||i.has(y)){if(r.has(y)){C(y,`CONFLICT (implicit dir rename): Existing file/dir at ${y} in the way of implicit directory rename(s) putting the following path(s) there: ${x.path}.`,1);continue}let L=r.get(x.path),M=i.get(y)??n.get(y);o.entries.push(_(y,L.mode,L.hash,2)),M&&o.entries.push(_(y,M.mode,M.hash,3)),o.worktreeBlobs.set(y,{hash:L.hash,mode:L.mode}),o.conflicts.push({path:y,reason:"add-add"}),C(y,`CONFLICT (file location): ${x.path} added in ${b} inside a directory that was renamed in ${E}, suggesting it should perhaps be moved to ${y}.`,1);let G=e.get(x.path);G&&(G.merged={result:null,clean:!0}),p.add(x.path);continue}let S=r.get(x.path);o.entries.push(_(y,S.mode,S.hash,2)),o.worktreeBlobs.set(y,{hash:S.hash,mode:S.mode}),o.conflicts.push({path:y,reason:"directory-rename"}),C(y,`CONFLICT (file location): ${x.path} added in ${b} inside a directory that was renamed in ${E}, suggesting it should perhaps be moved to ${y}.`,1);let D=e.get(x.path);D&&(D.merged={result:null,clean:!0}),p.add(x.path)}if($.size>0)for(let x of f){if(x.status!=="added"||P.has(x.path))continue;let y=$r(x.path,$,he);if(!y)continue;if(e.has(y)||n.has(y)||r.has(y)||i.has(y)){if(i.has(y)){C(y,`CONFLICT (implicit dir rename): Existing file/dir at ${y} in the way of implicit directory rename(s) putting the following path(s) there: ${x.path}.`,1);continue}let L=i.get(x.path),M=r.get(y)??n.get(y);M&&o.entries.push(_(y,M.mode,M.hash,2)),o.entries.push(_(y,L.mode,L.hash,3)),o.worktreeBlobs.set(y,{hash:L.hash,mode:L.mode}),o.conflicts.push({path:y,reason:"add-add"}),C(y,`CONFLICT (file location): ${x.path} added in ${E} inside a directory that was renamed in ${b}, suggesting it should perhaps be moved to ${y}.`,1);let G=e.get(x.path);G&&(G.merged={result:null,clean:!0}),p.add(x.path);continue}let S=i.get(x.path);o.entries.push(_(y,S.mode,S.hash,3)),o.worktreeBlobs.set(y,{hash:S.hash,mode:S.mode}),o.conflicts.push({path:y,reason:"directory-rename"}),C(y,`CONFLICT (file location): ${x.path} added in ${E} inside a directory that was renamed in ${b}, suggesting it should perhaps be moved to ${y}.`,1);let D=e.get(x.path);D&&(D.merged={result:null,clean:!0}),p.add(x.path)}let z=new Set(o.entries.map(x=>x.path));for(let x of z){let y=e.get(x);y&&(y.merged={result:null,clean:!0})}for(let x of p){if(z.has(x))continue;let y=e.get(x);if(!y||y.merged.clean)continue;y.filemask===7&&!y.pathConflict||(y.merged={result:null,clean:!0})}return o}function Cr(t,e){let n=new Set;for(let s of t.keys()){let a=Z(s);for(;a;)n.add(a),a=Z(a)}let r=new Set;for(let s of e.keys()){let a=Z(s);for(;a;)r.add(a),a=Z(a)}let i=new Set;for(let s of n)r.has(s)||i.add(s);return i}function Tr(t,e,n){if(t.size===0)return t;let r=new Set;for(let i of e.keys()){if(n.has(i))continue;let s=Z(i)??"";t.has(s)&&r.add(s)}for(let i of[...r]){let s=Z(i);for(;s;)t.has(s)&&!r.has(s)&&r.add(s),s=Z(s)}return r}function Sr(t,e){let n=new Map;for(let r of t){let i=Z(r.oldPath),s=Z(r.newPath),a=!0;for(;;){if(!a){let o=i.length+(i?1:0),c=s.length+(s?1:0),f=r.oldPath.slice(o,r.oldPath.indexOf("/",o)),l=r.newPath.slice(c,r.newPath.indexOf("/",c));if(f!==l)break}if(e.has(i)){let o=n.get(i);o||(o=new Map,n.set(i,o)),o.set(s,(o.get(s)??0)+1)}if(a=!1,!i||!s)break;i=Z(i),s=Z(s)}}return n}function vr(t){let e=new Map;for(let[n,r]of t){let i=0,s=0,a=null;for(let[o,c]of r)c===i?s=i:c>i&&(i=c,a=o);i>0&&s!==i&&a!==null&&e.set(n,a)}return e}function $r(t,e,n){let r=Z(t);for(;r;){let s=e.get(r);if(s!==void 0){if(n.has(s))return null;let a=t.slice(r.length+1);return s?`${s}/${a}`:a}r=Z(r)}let i=e.get("");return i!==void 0&&!n.has(i)?`${i}/${t}`:null}function Z(t){let e=t.lastIndexOf("/");return e===-1?"":t.slice(0,e)}async function jr(t,e,n,r,i,s,a,o,c,f=!1,l,u){let m=f?o.get(n):c.get(n),h=f?a:s;if(m.hash===h.hash){e.entries.push(_(n,m.mode,m.hash)),e.msgBuf.push({sortKey:r,subOrder:0,text:`Auto-merging ${r}`});return}let g=await Ar(t,i,s,a,l,f?{oursPath:r,theirsPath:n}:{oursPath:n,theirsPath:r},8,u);if(m.hash===g.hash)e.entries.push(_(n,m.mode,g.hash));else if(e.conflicts.push({path:n,reason:"add-add"}),e.msgBuf.push({sortKey:n,subOrder:0,text:`Auto-merging ${n}`}),e.msgBuf.push({sortKey:n,subOrder:1,text:`CONFLICT (add/add): Merge conflict in ${n}`}),f){e.entries.push(me(n,m,2)),e.entries.push(_(n,a.mode,g.hash,3));let p=await mt(t,m.hash,g.hash,m.mode,l);e.worktreeBlobs.set(n,{hash:p,mode:m.mode})}else{e.entries.push(_(n,s.mode,g.hash,2)),e.entries.push(me(n,m,3));let p=await mt(t,g.hash,m.hash,s.mode,l);e.worktreeBlobs.set(n,{hash:p,mode:s.mode})}}async function Ar(t,e,n,r,i,s,a,o){if(n.hash===e.hash)return{hash:r.hash,conflict:!1};if(r.hash===e.hash)return{hash:n.hash,conflict:!1};if(n.hash===r.hash)return{hash:n.hash,conflict:!1};if(ie(e.mode)||ie(n.mode)||ie(r.mode))return{hash:n.hash,conflict:!0};let c=await H(t,e.hash),f=await H(t,n.hash),l=await H(t,r.hash);if(Q(f)||Q(l)||Q(c))return{hash:n.hash,conflict:!0};if(o){let w=await o({path:e.path??n.path??r.path??"",base:c,ours:f,theirs:l});if(w!==null)return{hash:await N(t,"blob",se.encode(w.content)),conflict:w.conflict}}let u=X(c),m=X(f),h=X(l),d=i?.conflictStyle,g=Ye(m,u,h,{conflictStyle:d});if(!g.conflict)return{hash:await _t(t,g.result),conflict:!1};let p=i?.a??"HEAD",b=i?.b??"theirs",E=s?.oursPath?`${p}:${s.oursPath}`:p,C=s?.theirsPath?`${b}:${s.theirsPath}`:b,j=Ie(f,c,l,{a:E,b:C,markerSize:a??7,conflictStyle:d});return{hash:await N(t,"blob",se.encode(j)),conflict:!0}}async function mt(t,e,n,r,i){let s=await H(t,e),a=await H(t,n),o=Ie(s,"",a,{a:i?.a??"HEAD",b:i?.b??"theirs",conflictStyle:i?.conflictStyle});return N(t,"blob",se.encode(o))}function me(t,e,n=0){return _(t,e.mode,e.hash,n)}function _(t,e,n,r=0){return{path:t,mode:parseInt(e,8),hash:n,stage:r,stat:de()}}async function po(t,e,n,r,i){let s=[...r.entries],a=[...r.conflicts],o=[...r.msgBuf],c=new Map(r.worktreeBlobs);function f(d,g,p=0){o.push({sortKey:d,subOrder:p,text:g})}for(let d of[...e.keys()].sort()){let g=e.get(d);if(g.merged.clean){g.merged.result?.hash&&s.push(B(d,g.merged.result.hash,g.merged.result.mode));continue}await go(t,g,n,s,a,f,c,i)}o.sort((d,g)=>(d.sortKeyg.sortKey?1:0)||d.subOrder-g.subOrder);let l=o.map(d=>d.text),u=[],m=new Set;for(let d of s)d.stage===0&&(u.push(d),m.add(d.path));for(let[d,g]of c)m.has(d)||u.push(B(d,g.hash,g.mode));u.sort((d,g)=>We(d.path,g.path));let h=await Ot(t,u);return{entries:s,conflicts:a,messages:l,resultTree:h,neededRenameLimit:r.neededRenameLimit}}async function go(t,e,n,r,i,s,a,o){let c=e.path,[f,l,u]=e.stages,m=f?.hash??null,h=l?.hash??null,d=u?.hash??null;if(h===null&&d!==null&&m!==null){i.push({path:c,reason:"delete-modify",deletedBy:"ours"});let g=n?.a??"HEAD",p=n?.b??"theirs";s(c,`CONFLICT (modify/delete): ${c} deleted in ${g} and modified in ${p}. Version ${p} of ${c} left in tree.`),f&&r.push(B(c,m,f.mode,1)),r.push(B(c,d,u.mode,3)),a.set(c,{hash:d,mode:u.mode});return}if(d===null&&h!==null&&m!==null){i.push({path:c,reason:"delete-modify",deletedBy:"theirs"});let g=n?.b??"theirs",p=n?.a??"HEAD";s(c,`CONFLICT (modify/delete): ${c} deleted in ${g} and modified in ${p}. Version ${p} of ${c} left in tree.`),f&&r.push(B(c,m,f.mode,1)),r.push(B(c,h,l.mode,2)),a.set(c,{hash:h,mode:l.mode});return}if(m===null&&h!==null&&d!==null){let g=l.mode!==u.mode&&Ft.has(l.mode)&&Ft.has(u.mode),p=O=>{i.push({path:c,reason:"add-add"}),s(c,`CONFLICT (add/add): Merge conflict in ${c}`,1),r.push(B(c,h,l.mode,2)),r.push(B(c,d,u.mode,3)),a.set(c,{hash:O,mode:l.mode})};if(h===d){g?p(h):r.push(B(c,h,l.mode));return}s(c,`Auto-merging ${c}`,0);let b=await H(t,h),E=await H(t,d);if(Q(b)||Q(E)){s(c,`warning: Cannot merge binary files: ${c} (${n?.a??"HEAD"} vs. ${n?.b??"theirs"})`,-1),p(h);return}if(o){let O=await o({path:c,base:null,ours:b,theirs:E});if(O!==null){let I=await N(t,"blob",se.encode(O.content));O.conflict||g?p(I):r.push(B(c,I,l.mode));return}}let C=X(""),j=X(b),P=X(E),w=Ye(j,C,P,{conflictStyle:n?.conflictStyle});if(!w.conflict){let O=await _t(t,w.result);g?p(O):r.push(B(c,O,l.mode));return}let R=Ie(b,"",E,{a:n?.a??"HEAD",b:n?.b??"theirs",conflictStyle:n?.conflictStyle});p(await N(t,"blob",se.encode(R)));return}if(m!==null&&h!==null&&d!==null){let g=Xe(f.mode,l.mode,u.mode);if(h===m){r.push(B(c,d,g??u.mode));return}if(d===m){r.push(B(c,h,g??l.mode));return}if(h===d){r.push(B(c,h,g??l.mode));return}if(s(c,`Auto-merging ${c}`,0),ie(f.mode)||ie(l.mode)||ie(u.mode)){i.push({path:c,reason:"content"}),s(c,`CONFLICT (content): Merge conflict in ${c}`,1),r.push(B(c,m,f.mode,1)),r.push(B(c,h,l.mode,2)),r.push(B(c,d,u.mode,3)),a.set(c,{hash:h,mode:l.mode});return}let p=g??l.mode,b=await H(t,m),E=await H(t,h),C=await H(t,d);if(Q(E)||Q(C)||Q(b)){i.push({path:c,reason:"content"}),s(c,`warning: Cannot merge binary files: ${c} (${n?.a??"HEAD"} vs. ${n?.b??"theirs"})`,-1),s(c,`CONFLICT (content): Merge conflict in ${c}`,1),r.push(B(c,m,f.mode,1)),r.push(B(c,h,l.mode,2)),r.push(B(c,d,u.mode,3)),a.set(c,{hash:h,mode:p});return}if(o){let O=await o({path:c,base:b,ours:E,theirs:C});if(O!==null){let I=await N(t,"blob",se.encode(O.content));if(!O.conflict){r.push(B(c,I,p));return}let T=e.pathnames[1],k=e.pathnames[2],$=T!==c||k!==c,A={path:c,reason:"content"};$&&(T!==c&&(A.oursOrigPath=T),k!==c&&(A.theirsOrigPath=k)),i.push(A),s(c,`CONFLICT (content): Merge conflict in ${c}`,1),r.push(B(c,m,f.mode,1)),r.push(B(c,h,l.mode,2)),r.push(B(c,d,u.mode,3)),a.set(c,{hash:I,mode:p});return}}let j=X(b),P=X(E),w=X(C),R=Ye(P,j,w,{conflictStyle:n?.conflictStyle});if(R.conflict){let O=e.pathnames[1],I=e.pathnames[2],T=O!==c||I!==c,k={path:c,reason:"content"};T&&(O!==c&&(k.oursOrigPath=O),I!==c&&(k.theirsOrigPath=I)),i.push(k),s(c,`CONFLICT (content): Merge conflict in ${c}`,1),r.push(B(c,m,f.mode,1)),r.push(B(c,h,l.mode,2)),r.push(B(c,d,u.mode,3));let $=T?`${n?.a??"HEAD"}:${O}`:n?.a??"HEAD",A=T?`${n?.b??"theirs"}:${I}`:n?.b??"theirs",J=Ie(E,b,C,{a:$,b:A,conflictStyle:n?.conflictStyle}),he=await N(t,"blob",se.encode(J));a.set(c,{hash:he,mode:p})}else{let O=await _t(t,R.result);r.push(B(c,O,p))}return}}var yo=200;async function Lr(t,e,n,r,i,s){let a=await Promise.all(r.map(async m=>({hash:m,timestamp:(await v(t,m)).committer.timestamp})));a.sort((m,h)=>m.timestamp-h.timestamp);let o=a.map(m=>m.hash),c=o[0],f=c,l=(await v(t,c)).tree,u;for(let m=1;m=yo)g=l;else{let E=await qe(t,f,h);if(E.length===0)g=null;else if(E.length===1)g=(await v(t,E[0])).tree;else{let C=await Lr(t,f,h,E,i+1,s);g=C.tree,u=Math.max(u??0,C.neededRenameLimit??0)||void 0}}let p=await Me(t,g,l,d,void 0,s);u=Math.max(u??0,p.neededRenameLimit??0)||void 0,l=await bo(t,p,i);let b=Ue({type:"commit",tree:l,parents:[f,h],author:Pr,committer:Pr,message:"merged common ancestors"});f=await N(t,"commit",b)}return{tree:l,neededRenameLimit:u}}async function bo(t,e,n){let r=e.entries.filter(o=>o.stage===0),i=new Map;for(let o of e.entries)o.stage>0&&i.set(`${o.path}\0${o.stage}`,o);let s=(o,c)=>i.get(`${o}\0${c}`),a={a:"Temporary merge branch 1",b:"Temporary merge branch 2",markerSize:7+n*2};for(let o of e.conflicts){if(o.reason==="delete-modify"||o.reason==="rename-delete"){let l=s(o.path,1);if(l){r.push({...l,stage:0});continue}}if(o.reason==="rename-rename"){let l=o.oursPath??o.path,u=o.theirsPath??o.path,m=s(o.path,1),h=s(l,2),d=s(u,3);if(h&&d){let g=je.decode((await F(t,h.hash)).content),p=je.decode((await F(t,d.hash)).content),b=m?je.decode((await F(t,m.hash)).content):"",E=8+n*2,C=a.a??"Temporary merge branch 1",j=a.b??"Temporary merge branch 2",P=Ie(g,b,p,{a:`${C}:${l}`,o:a.o,b:`${j}:${u}`,markerSize:E}),w=await N(t,"blob",se.encode(P));r.push({path:l,mode:h.mode,hash:w,stage:0,stat:de()}),r.push({path:u,mode:d.mode,hash:w,stage:0,stat:de()});continue}else if(h){r.push({...h,stage:0});continue}}let c=s(o.path,2),f=s(o.path,3);if(c&&f&&(o.reason==="content"||o.reason==="add-add")){let l=je.decode((await F(t,c.hash)).content),u=je.decode((await F(t,f.hash)).content),m=o.reason==="content"?s(o.path,1):null,h=m?je.decode((await F(t,m.hash)).content):"",d=o.oursOrigPath||o.theirsOrigPath,g=a.a??"Temporary merge branch 1",p=a.b??"Temporary merge branch 2",b=d?`${g}:${o.oursOrigPath??o.path}`:g,E=d?`${p}:${o.theirsOrigPath??o.path}`:p,C=Ie(l,h,u,{a:b,o:a.o,b:E,markerSize:a.markerSize}),j=await N(t,"blob",se.encode(C));r.push({path:o.path,mode:c.mode,hash:j,stage:0,stat:de()})}else c?r.push({...c,stage:0}):f&&r.push({...f,stage:0})}return r.sort((o,c)=>We(o.path,c.path)),Ot(t,r)}async function _t(t,e){let n=e.map(Gt);if(n.length===0)return N(t,"blob",se.encode(""));let s=(e[e.length-1]??"").endsWith("\0")?n.join(` + `):`${n.join(` + `)} +-`;return N(t,"blob",re.encode(s))}function H(t,e,n,r=0){let i=typeof n=="string"?parseInt(n,8):n;return{path:t,mode:i,hash:e,stage:r,stat:me()}}function Ht(t,e){let n=t.get(e);return n||(n={path:e,stages:[null,null,null],pathnames:[e,e,e],filemask:0,matchMask:0,merged:{result:null,clean:!1},pathConflict:!1},t.set(e,n)),n}async function ao(t,e,n,r){let i=r?{a:r.ours??"ours",b:r.theirs??"theirs"}:void 0,s=await kr(t,e,n,i,r?.mergeDriver);return{treeHash:s.resultTree,clean:s.conflicts.length===0,conflicts:s.conflicts,messages:s.messages}}async function Nt(t,e,n,r,i){let s=i?{a:i.ours??"ours",b:i.theirs??"theirs"}:void 0,a=await je(t,e,n,r,s,i?.mergeDriver);return{treeHash:a.resultTree,clean:a.conflicts.length===0,conflicts:a.conflicts,messages:a.messages}}var Gt=class{constructor(e){this.inner=e}read(e){return this.inner.read(e)}write(e,n){throw new Error("cannot write: object store is read-only")}exists(e){return this.inner.exists(e)}ingestPack(e){throw new Error("cannot ingest pack: object store is read-only")}ingestPackStream(e){throw new Error("cannot ingest pack: object store is read-only")}findByPrefix(e){return this.inner.findByPrefix(e)}},Ut=class{constructor(e){this.inner=e}readRef(e){return this.inner.readRef(e)}writeRef(e,n){throw new Error("cannot write ref: ref store is read-only")}deleteRef(e){throw new Error("cannot delete ref: ref store is read-only")}listRefs(e){return this.inner.listRefs(e)}compareAndSwapRef(e,n,r){throw new Error("cannot update ref: ref store is read-only")}};function co(t){return{objectStore:new Gt(t.objectStore),refStore:new Ut(t.refStore),hooks:t.hooks}}var Ft=class{constructor(e){this.inner=e}overlay=new Map;async read(e){let n=this.overlay.get(e);return n?{type:n.type,content:new Uint8Array(n.content)}:this.inner.read(e)}async write(e,n){let r=await Ye(un(e,n));return this.overlay.has(r)||await this.inner.exists(r).catch(()=>!1)||this.overlay.set(r,{type:e,content:new Uint8Array(n)}),r}async exists(e){return this.overlay.has(e)?!0:this.inner.exists(e)}async ingestPack(e){if(e.byteLength<32)return 0;let n=new DataView(e.buffer,e.byteOffset,e.byteLength),r=n.getUint32(0);if(r!==1346454347)throw new Error(`invalid pack signature: 0x${r.toString(16)} (expected 0x5041434b)`);let i=n.getUint32(4);if(i!==2)throw new Error(`unsupported pack version: ${i}`);if(n.getUint32(8)===0)return 0;let a=this.overlay,o=this.inner,c=await fn(e,async f=>{let l=a.get(f);if(l)return{type:l.type,content:new Uint8Array(l.content)};try{return await o.read(f)}catch{return null}});for(let f of c)a.has(f.hash)||a.set(f.hash,{type:f.type,content:f.content});return c.length}async ingestPackStream(e){let n=this.overlay,r=0;for await(let i of e)n.has(i.hash)||n.set(i.hash,{type:i.type,content:i.content}),r++;return r}async findByPrefix(e){let n=await this.inner.findByPrefix(e),r=[];for(let s of this.overlay.keys())s.startsWith(e)&&r.push(s);return[...new Set([...n,...r])]}},_t=class{constructor(e){this.inner=e}overlay=new Map;deleted=new Set;async readRef(e){if(this.deleted.has(e))return null;let n=this.overlay.get(e);return n||this.inner.readRef(e)}async writeRef(e,n){this.deleted.delete(e),this.overlay.set(e,bn(n))}async deleteRef(e){this.overlay.delete(e),this.deleted.add(e)}async listRefs(e){let n=await this.inner.listRefs(e),r=new Map;for(let i of n)this.deleted.has(i.name)||r.set(i.name,i);for(let[i,s]of this.overlay)if(!(e&&!i.startsWith(e))){if(s.type==="direct")r.set(i,{name:i,hash:s.hash});else if(s.type==="symbolic"){let a=await this.resolveSymbolic(s.target);a&&r.set(i,{name:i,hash:a})}}return[...r.values()]}async compareAndSwapRef(e,n,r){let i=await this.readRef(e),s=null;if(i&&(i.type==="direct"?s=i.hash:i.type==="symbolic"&&(s=await this.resolveSymbolic(i.target))),n===null){if(i!==null)return!1}else if(s!==n)return!1;return r===null?(this.overlay.delete(e),this.deleted.add(e)):(this.deleted.delete(e),this.overlay.set(e,r)),!0}async resolveSymbolic(e,n=0){if(n>10)return null;let r=await this.readRef(e);return r?r.type==="direct"?r.hash:r.type==="symbolic"?this.resolveSymbolic(r.target,n+1):null:null}};function Wt(t){return{objectStore:new Ft(t.objectStore),refStore:new _t(t.refStore),hooks:t.hooks}}async function zt(t,e){let n=await ye(t,e);if(n)return n;throw new Error(`ref or commit '${e}' not found`)}function Tr(t){return Sn(t.map(e=>({path:e.path,mode:parseInt(e.mode,8),hash:e.hash,stage:0,stat:me()})))}async function fo(t,e,n,r="/"){let i=await zt(t,e),s=await $(t,i),a=await V(t,s.tree),o=await _e(t,a,n,r);return{commitHash:i,treeHash:s.tree,filesWritten:o}}async function lo(t,e,n){let r=n?.workTree??"/",i=n?.gitDir??oe(r,".git"),s=n?.ref??"HEAD";await e.mkdir(i,{recursive:!0});let a=await zt(t,s),o=await $(t,a),c=await V(t,o.tree),f={...t,fs:e,gitDir:i,commonDir:i,workTree:r},l=await _e(t,c,e,r),u=await vn(f,Tr(c));return await Qe(f,u),{ctx:f,commitHash:a,treeHash:o.tree,filesWritten:l}}async function uo(t,e){let n=Wt(t),r=e?.workTree??"/",i=e?.gitDir??oe(r,".git"),s=e?.ref??"HEAD",a=await zt(n,s),o=await $(n,a),c=new Pe(n.objectStore,o.tree,r),f="refs/heads/main";await n.refStore.writeRef("HEAD",{type:"symbolic",target:f}),await n.refStore.writeRef(f,{type:"direct",hash:a});let l={...n,fs:c,gitDir:i,commonDir:i,workTree:r},u=await V(n,o.tree);return await Qe(l,Tr(u)),{ctx:l,commitHash:a,treeHash:o.tree,filesWritten:0}}async function Sr(t,e,n,r,i){let s=[],a=new Map;for await(let p of ue(t,e,{exclude:n})){let b=i?p.commit.parents.slice(0,1):p.commit.parents;s.push({hash:p.hash,subject:Ln(p.commit.message)}),a.set(p.hash,b)}let o=s.length;if(o===0)return null;if(o===1)return{hash:s[0].hash,subject:s[0].subject,remaining:0,steps:0,found:!0,onlySkippedLeft:!1};let c=new Set(s.map(p=>p.hash)),f=new Map;for(let p of s){let b=new Set,E=[p.hash],C=0;for(;Cp.hash===l),d=mo(o),g=ho(o);return{hash:h.hash,subject:h.subject,remaining:d,steps:g,found:!1,onlySkippedLeft:m}}function mo(t){return Math.floor((t-1)/2)}function ho(t){return t<=1?0:Math.ceil(Math.log2(t))}async function Me(t,e){let n=await ye(t,e);if(!n)throw new Error(`revision '${e}' not found`);return n}async function po(t,e){let n=await Me(t,e.bad),r=Array.isArray(e.good)?e.good:[e.good],i=[];for(let c of r)i.push(await Me(t,c));let s=new Set,a=e.firstParent??!1,o=0;for(;;){let c=await Sr(t,n,i,s,a);if(!c)return{found:!1,reason:"no-testable-commits"};if(c.found)return{found:!0,hash:c.hash,stepsTaken:o};if(c.onlySkippedLeft)return{found:!1,reason:"all-skipped",candidates:[...s,n]};let f=await $(t,c.hash),l=We(t,f.tree),u=await e.test(c.hash,l);o++;let m;u==="skip"?(m="skip",s.add(c.hash)):u===!0?(m="good",i.push(c.hash)):(m="bad",n=c.hash),e.onStep?.({hash:c.hash,subject:c.subject,verdict:m,remaining:c.remaining,estimatedSteps:c.steps,stepNumber:o})}}async function go(t,e){let n=await Me(t,e.commit),r=await Me(t,e.onto),i=await $(t,n),s=await $(t,r),a=await vr(t,i,n,e.mainline),o=e.message??i.message;return e.recordOrigin&&(o=wo(o,n)),$r(t,{baseTree:a,oursTree:s.tree,theirsTree:i.tree,ontoHash:r,author:i.author,committer:e.committer,message:o,noCommit:e.noCommit,branch:e.branch,mergeDriver:e.mergeDriver})}async function yo(t,e){let n=await Me(t,e.commit),r=await Me(t,e.onto),i=await $(t,n),s=await $(t,r),a=await vr(t,i,n,e.mainline),o=i.message.split(` ++`;return N(t,"blob",se.encode(s))}function B(t,e,n,r=0){let i=typeof n=="string"?parseInt(n,8):n;return{path:t,mode:i,hash:e,stage:r,stat:de()}}function Ut(t,e){let n=t.get(e);return n||(n={path:e,stages:[null,null,null],pathnames:[e,e,e],filemask:0,matchMask:0,merged:{result:null,clean:!1},pathConflict:!1},t.set(e,n)),n}async function wo(t,e,n,r){let i=r?{a:r.ours??"ours",b:r.theirs??"theirs"}:void 0,s=await Mr(t,e,n,i,r?.mergeDriver);return{treeHash:s.resultTree,clean:s.conflicts.length===0,conflicts:s.conflicts,messages:s.messages}}async function Wt(t,e,n,r,i){let s=i?{a:i.ours??"ours",b:i.theirs??"theirs"}:void 0,a=await Me(t,e,n,r,s,i?.mergeDriver);return{treeHash:a.resultTree,clean:a.conflicts.length===0,conflicts:a.conflicts,messages:a.messages}}var zt=class{constructor(e){this.inner=e}read(e){return this.inner.read(e)}write(e,n){throw new Error("cannot write: object store is read-only")}exists(e){return this.inner.exists(e)}ingestPack(e){throw new Error("cannot ingest pack: object store is read-only")}ingestPackStream(e){throw new Error("cannot ingest pack: object store is read-only")}findByPrefix(e){return this.inner.findByPrefix(e)}},Vt=class{constructor(e){this.inner=e}readRef(e){return this.inner.readRef(e)}writeRef(e,n){throw new Error("cannot write ref: ref store is read-only")}deleteRef(e){throw new Error("cannot delete ref: ref store is read-only")}listRefs(e){return this.inner.listRefs(e)}compareAndSwapRef(e,n,r){throw new Error("cannot update ref: ref store is read-only")}};function Ro(t){return{objectStore:new zt(t.objectStore),refStore:new Vt(t.refStore),hooks:t.hooks}}var qt=class{constructor(e){this.inner=e}overlay=new Map;async read(e){let n=this.overlay.get(e);return n?{type:n.type,content:new Uint8Array(n.content)}:this.inner.read(e)}async write(e,n){let r=await Je(yn(e,n));return this.overlay.has(r)||await this.inner.exists(r).catch(()=>!1)||this.overlay.set(r,{type:e,content:new Uint8Array(n)}),r}async exists(e){return this.overlay.has(e)?!0:this.inner.exists(e)}async ingestPack(e){if(e.byteLength<32)return 0;let n=new DataView(e.buffer,e.byteOffset,e.byteLength),r=n.getUint32(0);if(r!==1346454347)throw new Error(`invalid pack signature: 0x${r.toString(16)} (expected 0x5041434b)`);let i=n.getUint32(4);if(i!==2)throw new Error(`unsupported pack version: ${i}`);if(n.getUint32(8)===0)return 0;let a=this.overlay,o=this.inner,c=await pn(e,async f=>{let l=a.get(f);if(l)return{type:l.type,content:new Uint8Array(l.content)};try{return await o.read(f)}catch{return null}});for(let f of c)a.has(f.hash)||a.set(f.hash,{type:f.type,content:f.content});return c.length}async ingestPackStream(e){let n=this.overlay,r=0;for await(let i of e)n.has(i.hash)||n.set(i.hash,{type:i.type,content:i.content}),r++;return r}async findByPrefix(e){let n=await this.inner.findByPrefix(e),r=[];for(let s of this.overlay.keys())s.startsWith(e)&&r.push(s);return[...new Set([...n,...r])]}},Kt=class{constructor(e){this.inner=e}overlay=new Map;deleted=new Set;async readRef(e){if(this.deleted.has(e))return null;let n=this.overlay.get(e);return n||this.inner.readRef(e)}async writeRef(e,n){this.deleted.delete(e),this.overlay.set(e,kn(n))}async deleteRef(e){this.overlay.delete(e),this.deleted.add(e)}async listRefs(e){let n=await this.inner.listRefs(e),r=new Map;for(let i of n)this.deleted.has(i.name)||r.set(i.name,i);for(let[i,s]of this.overlay)if(!(e&&!i.startsWith(e))){if(s.type==="direct")r.set(i,{name:i,hash:s.hash});else if(s.type==="symbolic"){let a=await this.resolveSymbolic(s.target);a&&r.set(i,{name:i,hash:a})}}return[...r.values()]}async compareAndSwapRef(e,n,r){let i=await this.readRef(e),s=null;if(i&&(i.type==="direct"?s=i.hash:i.type==="symbolic"&&(s=await this.resolveSymbolic(i.target))),n===null){if(i!==null)return!1}else if(s!==n)return!1;return r===null?(this.overlay.delete(e),this.deleted.add(e)):(this.deleted.delete(e),this.overlay.set(e,r)),!0}async resolveSymbolic(e,n=0){if(n>10)return null;let r=await this.readRef(e);return r?r.type==="direct"?r.hash:r.type==="symbolic"?this.resolveSymbolic(r.target,n+1):null:null}};function Yt(t){return{objectStore:new qt(t.objectStore),refStore:new Kt(t.refStore),hooks:t.hooks}}async function Xt(t,e){let n=await we(t,e);if(n)return n;throw new Error(`ref or commit '${e}' not found`)}function Dr(t){return Dn(t.map(e=>({path:e.path,mode:parseInt(e.mode,8),hash:e.hash,stage:0,stat:de()})))}async function xo(t,e,n,r="/"){let i=await Xt(t,e),s=await v(t,i),a=await K(t,s.tree),o=await ze(t,a,n,r);return{commitHash:i,treeHash:s.tree,filesWritten:o}}async function Io(t,e,n){let r=n?.workTree??"/",i=n?.gitDir??ae(r,".git"),s=n?.ref??"HEAD";await e.mkdir(i,{recursive:!0});let a=await Xt(t,s),o=await v(t,a),c=await K(t,o.tree),f={...t,fs:e,gitDir:i,commonDir:i,workTree:r},l=await ze(t,c,e,r),u=await Hn(f,Dr(c));return await nt(f,u),{ctx:f,commitHash:a,treeHash:o.tree,filesWritten:l}}async function Eo(t,e){let n=Yt(t),r=e?.workTree??"/",i=e?.gitDir??ae(r,".git"),s=e?.ref??"HEAD",a=await Xt(n,s),o=await v(n,a),c=new Te(n.objectStore,o.tree,r),f="refs/heads/main";await n.refStore.writeRef("HEAD",{type:"symbolic",target:f}),await n.refStore.writeRef(f,{type:"direct",hash:a});let l={...n,fs:c,gitDir:i,commonDir:i,workTree:r},u=await K(n,o.tree);return await nt(l,Dr(u)),{ctx:l,commitHash:a,treeHash:o.tree,filesWritten:0}}async function Hr(t,e,n,r,i){let s=[],a=new Map;for await(let p of ue(t,e,{exclude:n})){let b=i?p.commit.parents.slice(0,1):p.commit.parents;s.push({hash:p.hash,subject:Fn(p.commit.message)}),a.set(p.hash,b)}let o=s.length;if(o===0)return null;if(o===1)return{hash:s[0].hash,subject:s[0].subject,remaining:0,steps:0,found:!0,onlySkippedLeft:!1};let c=new Set(s.map(p=>p.hash)),f=new Map;for(let p of s){let b=new Set,E=[p.hash],C=0;for(;Cp.hash===l),d=ko(o),g=Oo(o);return{hash:h.hash,subject:h.subject,remaining:d,steps:g,found:!1,onlySkippedLeft:m}}function ko(t){return Math.floor((t-1)/2)}function Oo(t){return t<=1?0:Math.ceil(Math.log2(t))}async function Le(t,e){let n=await we(t,e);if(!n)throw new Error(`revision '${e}' not found`);return n}async function Po(t,e){let n=await Le(t,e.bad),r=Array.isArray(e.good)?e.good:[e.good],i=[];for(let c of r)i.push(await Le(t,c));let s=new Set,a=e.firstParent??!1,o=0;for(;;){let c=await Hr(t,n,i,s,a);if(!c)return{found:!1,reason:"no-testable-commits"};if(c.found)return{found:!0,hash:c.hash,stepsTaken:o};if(c.onlySkippedLeft)return{found:!1,reason:"all-skipped",candidates:[...s,n]};let f=await v(t,c.hash),l=Ve(t,f.tree),u=await e.test(c.hash,l);o++;let m;u==="skip"?(m="skip",s.add(c.hash)):u===!0?(m="good",i.push(c.hash)):(m="bad",n=c.hash),e.onStep?.({hash:c.hash,subject:c.subject,verdict:m,remaining:c.remaining,estimatedSteps:c.steps,stepNumber:o})}}async function Co(t,e){let n=await Le(t,e.commit),r=await Le(t,e.onto),i=await v(t,n),s=await v(t,r),a=await Br(t,i,n,e.mainline),o=e.message??i.message;return e.recordOrigin&&(o=vo(o,n)),Nr(t,{baseTree:a,oursTree:s.tree,theirsTree:i.tree,ontoHash:r,author:i.author,committer:e.committer,message:o,noCommit:e.noCommit,branch:e.branch,mergeDriver:e.mergeDriver})}async function To(t,e){let n=await Le(t,e.commit),r=await Le(t,e.onto),i=await v(t,n),s=await v(t,r),a=await Br(t,i,n,e.mainline),o=i.message.split(` + `)[0]??"",c=e.message??`Revert "${o}" + + This reverts commit ${n}. +-`,f=e.author??e.committer;if(!f&&!e.noCommit)throw new Error("revert requires at least one of `author` or `committer`");let l=a??await bo(t);return $r(t,{baseTree:i.tree,oursTree:s.tree,theirsTree:l,ontoHash:r,author:f,committer:e.committer??e.author,message:c,noCommit:e.noCommit,branch:e.branch,mergeDriver:e.mergeDriver})}async function vr(t,e,n,r){if(e.parents.length>1){if(r==null)throw new Error(`commit ${n} is a merge but no mainline option was given`);let s=r-1;if(s<0||s>=e.parents.length)throw new Error(`commit ${n} does not have parent ${r}`);return(await $(t,e.parents[s])).tree}if(r!=null)throw new Error("mainline was specified but commit is not a merge");return e.parents.length===0?null:(await $(t,e.parents[0])).tree}async function bo(t){return N(t,"tree",ge({type:"tree",entries:[]}))}async function $r(t,e){let n=await Nt(t,e.baseTree,e.oursTree,e.theirsTree,{mergeDriver:e.mergeDriver});if(!n.clean)return{clean:!1,treeHash:n.treeHash,conflicts:n.conflicts,messages:n.messages};if(e.noCommit)return{clean:!0,treeHash:n.treeHash};if(!e.author)throw new Error("author is required when creating a commit");return{clean:!0,hash:await jt(t,{tree:n.treeHash,parents:[e.ontoHash],author:e.author,committer:e.committer,message:e.message,branch:e.branch}),treeHash:n.treeHash}}function wo(t,e){let n=`(cherry picked from commit ${e})`,r=t.replace(/\n+$/,""),i=r.lastIndexOf(` ++`,f=e.author??e.committer;if(!f&&!e.noCommit)throw new Error("revert requires at least one of `author` or `committer`");let l=a??await So(t);return Nr(t,{baseTree:i.tree,oursTree:s.tree,theirsTree:l,ontoHash:r,author:f,committer:e.committer??e.author,message:c,noCommit:e.noCommit,branch:e.branch,mergeDriver:e.mergeDriver})}async function Br(t,e,n,r){if(e.parents.length>1){if(r==null)throw new Error(`commit ${n} is a merge but no mainline option was given`);let s=r-1;if(s<0||s>=e.parents.length)throw new Error(`commit ${n} does not have parent ${r}`);return(await v(t,e.parents[s])).tree}if(r!=null)throw new Error("mainline was specified but commit is not a merge");return e.parents.length===0?null:(await v(t,e.parents[0])).tree}async function So(t){return N(t,"tree",be({type:"tree",entries:[]}))}async function Nr(t,e){let n=await Wt(t,e.baseTree,e.oursTree,e.theirsTree,{mergeDriver:e.mergeDriver});if(!n.clean)return{clean:!1,treeHash:n.treeHash,conflicts:n.conflicts,messages:n.messages};if(e.noCommit)return{clean:!0,treeHash:n.treeHash};if(!e.author)throw new Error("author is required when creating a commit");return{clean:!0,hash:await Dt(t,{tree:n.treeHash,parents:[e.ontoHash],author:e.author,committer:e.committer,message:e.message,branch:e.branch}),treeHash:n.treeHash}}function vo(t,e){let n=`(cherry picked from commit ${e})`,r=t.replace(/\n+$/,""),i=r.lastIndexOf(` + `),s=i===-1?r:r.slice(i+1);return/^\(cherry picked from commit [0-9a-f]+\)$/.test(s)?`${r} + ${n} + `:`${r} + + ${n} +-`}export{po as bisect,Ds as blame,xt as branchNameFromRef,hr as buildCommit,go as cherryPick,Vs as commit,Ls as countAheadBehind,zs as createAnnotatedTag,jt as createCommit,uo as createSandboxWorktree,We as createTreeAccessor,lo as createWorktree,Gs as diffCommits,vs as diffTrees,fo as extractTree,As as findMergeBases,Ss as flattenTree,Us as formatDiff,$s as getChangedFiles,js as getNewCommits,Ki as grep,Ms as isAncestor,Bi as listBranches,Ni as listTags,ao as mergeTrees,Nt as mergeTreesFromTreeHashes,Wt as overlayRepo,Fi as readBlob,_i as readBlobText,Ui as readCommit,zi as readFileAtCommit,Gi as readHead,Wi as readTree,co as readonlyRepo,Hi as resolveRef,ye as revParse,yo as revert,wn as tagNameFromRef,pr as updateTree,Fs as walkCommitHistory,Ks as writeBlob,qs as writeTree}; ++`}export{Po as bisect,qs as blame,Et as branchNameFromRef,xr as buildCommit,Co as cherryPick,ro as commit,Vs as countAheadBehind,no as createAnnotatedTag,Dt as createCommit,Eo as createSandboxWorktree,Ve as createTreeAccessor,Io as createWorktree,Zs as diffCommits,Us as diffTrees,xo as extractTree,zs as findMergeBases,Gs as flattenTree,Js as formatDiff,Fs as getChangedFiles,_s as getNewCommits,ss as grep,Ws as isAncestor,Yi as listBranches,Xi as listTags,wo as mergeTrees,Wt as mergeTreesFromTreeHashes,Yt as overlayRepo,Qi as readBlob,es as readBlobText,Ji as readCommit,ns as readFileAtCommit,Zi as readHead,ts as readTree,Ro as readonlyRepo,Ki as resolveRef,we as revParse,To as revert,On as tagNameFromRef,Er as updateTree,Qs as walkCommitHistory,so as writeBlob,io as writeTree}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ab4a7220..aad4cf13 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -12,6 +12,9 @@ patchedDependencies: just-bash@3.6.0: hash: 7767ed5b1605abaf5ae15082347fa925b0dfecc7fe870fbcf2c30726c8cbb6b5 path: patches/just-bash@3.6.0.patch + just-git@1.9.1: + hash: 978c0c3e343a697099e5a9f43b8e74940506cc822e12a129570e425cc589858d + path: patches/just-git@1.9.1.patch importers: @@ -43,7 +46,7 @@ importers: version: 3.6.0(patch_hash=7767ed5b1605abaf5ae15082347fa925b0dfecc7fe870fbcf2c30726c8cbb6b5) just-git: specifier: ^1.9.1 - version: 1.9.1 + version: 1.9.1(patch_hash=978c0c3e343a697099e5a9f43b8e74940506cc822e12a129570e425cc589858d) lru-cache: specifier: ^11.0.0 version: 11.3.5 @@ -3780,7 +3783,7 @@ snapshots: transitivePeerDependencies: - supports-color - just-git@1.9.1: {} + just-git@1.9.1(patch_hash=978c0c3e343a697099e5a9f43b8e74940506cc822e12a129570e425cc589858d): {} knip@6.4.1(@emnapi/core@1.10.0)(@emnapi/runtime@1.10.0): dependencies: diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index cd38c1ea..af019720 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -1,5 +1,6 @@ patchedDependencies: just-bash@3.6.0: patches/just-bash@3.6.0.patch + just-git@1.9.1: patches/just-git@1.9.1.patch overrides: guarded-fetch>undici: 7.29.1 express-rate-limit>ip-address: 10.7.1 diff --git a/src/api/commands/git-command.ts b/src/api/commands/git-command.ts index 48ddf913..20e828b9 100644 --- a/src/api/commands/git-command.ts +++ b/src/api/commands/git-command.ts @@ -13,8 +13,11 @@ * is the path just-git actually resolved. A script may background several clones, so each * invocation gets its own scope via AsyncLocalStorage. * - * just-git's checkout also never sets the executable bit (blindmansion/just-git#10), so every - * file git writes is given the mode its index entry records until upstream fixes that. + * just-git 1.9.1 never sets the executable bit on checkout (blindmansion/just-git#10) and drops a + * one-sided mode change in a merge (blindmansion/just-git#18). `patches/just-git@1.9.1.patch` + * carries the fixes, blindmansion/just-git#15 and blindmansion/just-git#20, so just-git now writes + * every mode itself. The repair below, which gives each file git wrote its index mode, stays as a + * fallback until a just-git release includes both PRs; remove it then. */ import { AsyncLocalStorage } from "node:async_hooks"; @@ -217,8 +220,7 @@ async function indexModes( /** * Give each regular file git wrote its index mode, merging unmerged stages as Git does. * Only those files change, as with real git, so a caller's own uncommitted chmod on any other file - * stays. A branch switch where a file differs only in mode is not covered: just-git neither - * rewrites that file nor updates its index entry, so there is no correct mode to read. + * stays. */ async function applyIndexModes( fs: IFileSystem, diff --git a/src/api/tests/unit/git-command.just-git-patch.test.ts b/src/api/tests/unit/git-command.just-git-patch.test.ts new file mode 100644 index 00000000..1128cbcf --- /dev/null +++ b/src/api/tests/unit/git-command.just-git-patch.test.ts @@ -0,0 +1,118 @@ +/** + * Behaviour carried by `patches/just-git@1.9.1.patch` until upstream releases it. + * + * - blindmansion/just-git#15 (fixes #10): status and diff report a chmod-only change, and a branch + * switch where a file differs only in mode rewrites the mode. + * - blindmansion/just-git#14 (fixes #12): `git ls-tree`. + * - blindmansion/just-git#20 (fixes #18): a merge keeps a mode change made on either side. + * - blindmansion/just-git#21 (fixes #19): `--summary` in `show`, `log` and `diff`. + * + * When a just-git release includes all four PRs, drop the patch and keep these tests. + */ + +import { beforeEach, describe, expect, it } from "vitest"; +import { type BashOverSqlFs, bashOverSqlFs } from "../../../sql-fs/tests/fixtures/bash-over-sqlfs.js"; +import { createGitCommand } from "../../commands/git-command.js"; + +const IDENTITY = { + GIT_AUTHOR_NAME: "a", + GIT_AUTHOR_EMAIL: "a@b.c", + GIT_COMMITTER_NAME: "a", + GIT_COMMITTER_EMAIL: "a@b.c", +}; + +/** `main` has an executable `run.sh`; `plain` records the same content as 100644. */ +const SEED = [ + "mkdir repo && cd repo && git init -q", + "printf 'echo ran\\n' > run.sh && chmod 755 run.sh", + "git add -A && git commit -q -m init", + "git checkout -q -b plain && chmod 644 run.sh && git commit -q -am plain && git checkout -q main", +].join(" && "); + +describe("git wrapper — patched just-git behaviour", () => { + let env: BashOverSqlFs; + + async function sh(script: string): Promise<{ stdout: string; stderr: string; exitCode: number }> { + const r = await env.bash.exec(script); + return { stdout: r.stdout, stderr: r.stderr, exitCode: r.exitCode }; + } + + beforeEach(async () => { + env = await bashOverSqlFs({ env: IDENTITY, customCommands: [createGitCommand({ network: false })] }); + expect((await sh(SEED)).exitCode).toBe(0); + }); + + it("reports a chmod-only change in status and diff", async () => { + const r = await sh("cd repo && chmod 644 run.sh && git status --short && git diff"); + expect(r).toEqual({ + stdout: " M run.sh\ndiff --git a/run.sh b/run.sh\nold mode 100755\nnew mode 100644\n", + stderr: "", + exitCode: 0, + }); + }); + + it("applies the mode when switching to a branch where only the mode differs", async () => { + expect((await sh("cd repo && stat -c %a run.sh")).stdout).toBe("755\n"); + await sh("cd repo && git checkout -q plain"); + expect((await sh("cd repo && stat -c %a run.sh && git status --short")).stdout).toBe("644\n"); + await sh("cd repo && git checkout -q main"); + expect((await sh("cd repo && stat -c %a run.sh && git status --short")).stdout).toBe("755\n"); + }); + + it("refuses to switch over a local chmod-only change", async () => { + const r = await sh("cd repo && chmod 644 run.sh && git checkout plain"); + expect(r.exitCode).toBe(1); + expect(r.stderr).toContain("Your local changes to the following files would be overwritten by checkout:"); + expect((await sh("cd repo && git branch --show-current")).stdout).toBe("main\n"); + }); + + it("lists a tree with git ls-tree", async () => { + expect(await sh("cd repo && git ls-tree --name-only plain && git ls-tree HEAD | cut -d' ' -f1-2")).toEqual({ + stdout: "run.sh\n100755 blob\n", + stderr: "", + exitCode: 0, + }); + }); + + it("recurses, filters by path and resolves : in git ls-tree", async () => { + await sh( + "cd repo && mkdir -p src/lib && echo a > src/a && echo b > src/lib/b && git add src && git commit -q -m src", + ); + const r = await sh( + "cd repo && git ls-tree --name-only HEAD && git ls-tree -r --name-only HEAD && " + + "git ls-tree --name-only HEAD src/lib && git ls-tree -r --name-only HEAD:src", + ); + expect(r).toEqual({ + stdout: "run.sh\nsrc\n" + "run.sh\nsrc/a\nsrc/lib/b\n" + "src/lib\n" + "a\nlib/b\n", + stderr: "", + exitCode: 0, + }); + }); + + it("keeps a mode-only change from the merged branch", async () => { + await sh("cd repo && git checkout -q -b side plain && chmod 755 run.sh && git commit -q -am exec"); + await sh("cd repo && git checkout -q plain && echo n > n && git add n && git commit -q -m n"); + const r = await sh("cd repo && git merge -q -m mg side && git ls-files -s run.sh | cut -c1-6 && stat -c %a run.sh"); + expect(r).toEqual({ stdout: "100755\n755\n", stderr: "", exitCode: 0 }); + }); + + it("gives a conflicted file the merged mode", async () => { + await sh( + "cd repo && git checkout -q -b side plain && echo theirs > run.sh && chmod 755 run.sh && git commit -q -am t", + ); + await sh("cd repo && git checkout -q plain && echo ours > run.sh && git commit -q -am o"); + const r = await sh( + "cd repo && git merge -q side; echo rc=$?; git ls-files -s run.sh | cut -c1-6 && stat -c %a run.sh", + ); + expect(r.stdout.split("\n").slice(-6)).toEqual(["rc=1", "100644", "100644", "100755", "755", ""]); + }); + + it("prints git show --summary", async () => { + await sh("cd repo && git mv run.sh go.sh && echo n > n && git add n && git commit -q -m sum"); + expect(await sh("cd repo && git show --summary --format=%s HEAD")).toEqual({ + stdout: "sum\n\n rename run.sh => go.sh (100%)\n create mode 100644 n\n", + stderr: "", + exitCode: 0, + }); + }); +});