just-git 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -8
- package/dist/index.js +210 -199
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
var br=(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
|
|
2
|
-
`)}function
|
|
3
|
-
`)}function
|
|
4
|
-
`)){let o=r.trim();if(!(!o||o.startsWith("#")||o.startsWith(";"))){if(o.startsWith("[")){let s=o.indexOf("]");if(s===-1)continue;n=o.slice(1,s).trim(),n in t||(t[n]={});continue}if(n!==null){let s=t[n];if(!s)continue;let a=o.indexOf("=");if(a===-1){let i=o.trim().toLowerCase();s[i]="true"}else{let i=o.slice(0,a).trim().toLowerCase(),c=o.slice(a+1).trim();s[i]=c}}}}return t}function
|
|
1
|
+
var br=(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 Is=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})}};function Uo(e){return new Is({_kind:"arg",type:e,required:!0})}function Bo(){return Uo("string")}function Wo(){return Uo("number")}var yr=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})}};var $s=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})}required(){return new e({...this._def,required:!0})}default(t){return new e({...this._def,default:t})}};function qo(e){return new $s({_kind:"option",type:e})}function Ko(){return qo("string")}function zo(){return qo("number")}var te={string:Ko,number:zo};function v(){return new yr}var W={string:Bo,number:Wo};function of(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}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=`Unknown command "${e.path}".`;return e.suggestions.length>0&&(t+=` Did you mean ${e.suggestions.map(n=>`"${n}"`).join(" or ")}?`),t}}}function Ts(e){return e.map(of).join(`
|
|
2
|
+
`)}function af(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 a=1;a<=r;a++){let i=e[s-1]===t[a-1]?0:1;o[s*(r+1)+a]=Math.min(o[(s-1)*(r+1)+a]+1,o[s*(r+1)+(a-1)]+1,o[(s-1)*(r+1)+(a-1)]+i)}return o[n*(r+1)+r]}function Er(e,t,n=3){return t.map(o=>({candidate:o,distance:af(e,o)})).filter(o=>o.distance<=n&&o.distance>0).sort((o,s)=>o.distance-s.distance).slice(0,2).map(o=>o.candidate)}function Vo(e,t,n,r){let o=[],s=new Map,a=new Map;for(let[l,m]of Object.entries(e)){let h=Wn(l);s.set(h,{key:l,def:m}),m.short&&a.set(m.short,{key:l,def:m})}let i={},c=[],f=[],d=0;for(;d<n.length;){let l=n[d];if(l==="--"){for(d++;d<n.length;)f.push(n[d]),d++;break}if(l.startsWith("--")){let m=l.indexOf("="),h,p;m!==-1?(h=l.slice(2,m),p=l.slice(m+1)):h=l.slice(2);let g=s.get(h);if(!g){if(h.startsWith("no-")){let y=s.get(h.slice(3));if(y&&y.def._kind==="flag"){i[y.key]=y.def.counted?0:!1,d++;continue}}let b=[...s.keys()];o.push({type:"unknown_option",name:`--${h}`,suggestions:Er(h,b).map(y=>`--${y}`)}),d++;continue}if(g.def._kind==="flag"){g.def.counted?i[g.key]=(i[g.key]||0)+1:i[g.key]=!0,d++;continue}let w=p??n[++d];if(w===void 0){o.push({type:"missing_value",name:g.key}),d++;continue}let x=Bn(w,g.def.type,g.key,o);x!==void 0&&(i[g.key]=x),d++;continue}if(l.startsWith("-")&&l.length>1){let m=l.slice(1);for(let h=0;h<m.length;h++){let p=m[h],g=a.get(p);if(!g){let y=[];s.has(p)&&y.push(`--${p}`),o.push({type:"unknown_option",name:`-${p}`,suggestions:y});continue}if(g.def._kind==="flag"){g.def.counted?i[g.key]=(i[g.key]||0)+1:i[g.key]=!0;continue}let w=m.slice(h+1),x=w.length>0?w:n[++d];if(x===void 0){o.push({type:"missing_value",name:g.key});break}let b=Bn(x,g.def.type,g.key,o);b!==void 0&&(i[g.key]=b);break}d++;continue}c.push(l),d++}let u=0;for(let l=0;l<t.length;l++){let m=t[l],h=m.name??`arg${l}`;if(m.variadic){let p=c.slice(u);p.length>0?i[h]=p.map(g=>Bn(g,m.type,h,o)):m.required?o.push({type:"missing_required",name:h,kind:"arg"}):m.default!==void 0?i[h]=m.default:i[h]=[],u=c.length}else{let p=c[u];p!==void 0?(i[h]=Bn(p,m.type,h,o),u++):m.required?o.push({type:"missing_required",name:h,kind:"arg"}):m.default!==void 0&&(i[h]=m.default)}}if(u<c.length)for(let l=u;l<c.length;l++)o.push({type:"unexpected_positional",value:c[l],maxPositionals:t.length});for(let[l,m]of Object.entries(e))if(i[l]===void 0){if(m._kind==="flag")i[l]=m.default??(m.counted?0:!1);else if(m._kind==="option"){let h=m;if(h.env&&r?.[h.env]!==void 0){let p=Bn(r[h.env],h.type,l,o);p!==void 0&&(i[l]=p)}i[l]===void 0&&(h.required&&h.default===void 0?o.push({type:"missing_required",name:l,kind:"option"}):h.default!==void 0&&(i[l]=h.default))}}return o.length>0?{ok:!1,errors:o}:{ok:!0,args:i,passthrough:f}}function Bn(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 Wn(e){return e.replace(/[A-Z]/g,t=>`-${t.toLowerCase()}`)}function Hs(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("<command>"),Object.keys(e.options).length>0&&r.push("[options]");let o=e.args;for(let a of o){let i=a.name??"arg",c=a.variadic?`${i}...`:i;r.push(a.required?`<${c}>`:`[${c}]`)}if(t.push("Usage:"),t.push(` ${r.join(" ")}`),t.push(""),n){t.push("Commands:");let a=[];for(let[c,f]of e.children)a.push([c,f.description||""]);let i=Math.max(...a.map(([c])=>c.length));for(let[c,f]of a)if(f){let d=" ".repeat(i-c.length+2);t.push(` ${c}${d}${f}`)}else t.push(` ${c}`);t.push("")}if(o.length>0){t.push("Arguments:");let a=[];for(let c of o){let f=c.name??"arg",d=c.variadic?`${f}...`:f,u=[];c.description&&u.push(c.description),c.required&&u.push("(required)"),c.default!==void 0&&u.push(`(default: ${JSON.stringify(c.default)})`),a.push([d,u.join(" ")])}let i=Math.max(...a.map(([c])=>c.length));for(let[c,f]of a)if(f){let d=" ".repeat(i-c.length+2);t.push(` ${c}${d}${f}`)}else t.push(` ${c}`);t.push("")}let s=cf(e.options);if(s.length>0&&(t.push("Options:"),t.push(...s),t.push("")),e.examples.length>0){t.push("Examples:");for(let a of e.examples)t.push(` ${a}`);t.push("")}return t.join(`
|
|
3
|
+
`)}function cf(e,t){let n=Object.entries(e);if(n.length===0)return[];let r=[];for(let[a,i]of n){let c=Wn(a);if(i._kind==="flag"){let f=i,d=[];f.short&&d.push(`-${f.short},`),d.push(`--${c}`);let u=[];f.description&&u.push(f.description),f.counted&&u.push("(counted)"),f.default!==void 0&&u.push(`(default: ${f.default})`),r.push([d.join(" "),u.join(" ")])}else{let f=i,d=[];f.short&&d.push(`-${f.short},`),d.push(`--${c} <${f.type}>`);let u=[];f.description&&u.push(f.description),f.required&&u.push("(required)"),f.default!==void 0&&u.push(`(default: ${JSON.stringify(f.default)})`),f.env&&u.push(`[env: ${f.env}]`),r.push([d.join(" "),u.join(" ")])}}let o=Math.max(...r.map(([a])=>a.length)),s=[];t&&s.push(t);for(let[a,i]of r)if(i){let c=" ".repeat(o-a.length+2);s.push(` ${a}${c}${i}`)}else s.push(` ${a}`);return s}function Yo(e){if(!e)return{};let t={};for(let[n,r]of Object.entries(e))t[n]=r._def;return t}function Xo(e){return e?e.map(t=>t._def):[]}var xr=class e{name;description;options;args;examples;handler;transformArgs;children=new Map;parent;constructor(t,n,r,o,s,a,i){this.name=t,this.description=n,this.options=r,this.args=o,this.examples=s,this.handler=a,this.transformArgs=i}command(t,n){let r=new e(t,n.description,Yo(n.options),Xo(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,a]of Object.entries(r)){let i=o[s],c=Wn(s);if(a._kind==="flag")if(a.counted&&typeof i=="number"&&i>0)for(let f=0;f<i;f++)n.push(`--${c}`);else i===!0?n.push(`--${c}`):i===!1&&a.default===!0&&n.push(`--no-${c}`);else a._kind==="option"&&i!==void 0&&n.push(`--${c}`,String(i))}for(let s of this.args){let a=s.name??"arg",i=o[a];if(i!==void 0)if(s.variadic&&Array.isArray(i))for(let c of i)n.push(String(c));else n.push(String(i))}return n}async invoke(t,n){if(!this.handler)return{stdout:"",stderr:`Command "${this.fullPath}" has no handler`,exitCode:1};let r={...t},o=this.allOptions;for(let[s,a]of Object.entries(o))if(r[s]===void 0){if(a._kind==="flag")r[s]=a.default??(a.counted?0:!1);else if(a._kind==="option"){if(a.default!==void 0)r[s]=a.default;else if(a.required)return{stdout:"",stderr:`Missing required option "${s}"`,exitCode:1}}}for(let s of this.args){let a=s.name??"arg";if(r[a]===void 0){if(s.default!==void 0)r[a]=s.default;else if(s.required)return{stdout:"",stderr:`Missing required arg "${a}"`,exitCode:1}}}try{return await this.handler(r,n,{passthrough:[]})}catch(s){return{stdout:"",stderr:s instanceof Error?s.message:String(s),exitCode:1}}}async execute(t,n){let r=n?.env?Object.fromEntries(n.env):{},o=t[0];if(o&&!o.startsWith("-")){let s=this.children.get(o);if(s)return s.execute(t.slice(1),n)}if(ff(t))return{stdout:Hs(this),stderr:"",exitCode:0};if(this.handler){let s=this.transformArgs?this.transformArgs([...t]):[...t],a=Vo(this.allOptions,this.args,s,r);if(!a.ok)return{stdout:"",stderr:Ts(a.errors),exitCode:1};try{return await this.handler(a.args,n,{passthrough:a.passthrough})}catch(i){return{stdout:"",stderr:i instanceof Error?i.message:String(i),exitCode:1}}}if(o&&!o.startsWith("-")){let s=Er(o,[...this.children.keys()]);return{stdout:"",stderr:Ts([{type:"unknown_command",path:`${this.fullPath} ${o}`,suggestions:s}]),exitCode:1}}return{stdout:Hs(this),stderr:"",exitCode:0}}};function As(e,t){return new xr(e,t.description,Yo(t.options),Xo(t.args),t.examples??[],t.handler,t.transformArgs)}function ff(e){return e.some(t=>t==="--help"||t==="-h")}function kr(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 a of r)a===""||a==="."||(a===".."?t||o.length>0&&o[o.length-1]!==".."?o.pop():o.push(".."):o.push(a));let s=o.join("/");return t&&(s=`/${s}`),n&&s.length>1&&!s.endsWith("/")&&(s+="/"),s||(t?"/":n?"./":".")}function H(...e){if(e.length===0)return".";let t=e.filter(n=>n!=="").join("/");return t===""?".":kr(t)}function ct(...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 kr(t||".")}function Pt(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 qn(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 Ke(e,t){let n=kr(e),r=kr(t);if(n===r)return"";let o=n==="/"?[""]:n.split("/"),s=r==="/"?[""]:r.split("/"),a=n.charCodeAt(0)===47,i=r.charCodeAt(0)===47,f=a&&i?1:0,d=Math.min(o.length,s.length);for(;f<d&&o[f]===s[f];)f++;let u=o.length-f,l=s.slice(f),m=[];for(let h=0;h<u;h++)m.push("..");for(let h of l)m.push(h);return m.join("/")||"."}function df(e){let t={},n=null;for(let r of e.split(`
|
|
4
|
+
`)){let o=r.trim();if(!(!o||o.startsWith("#")||o.startsWith(";"))){if(o.startsWith("[")){let s=o.indexOf("]");if(s===-1)continue;n=o.slice(1,s).trim(),n in t||(t[n]={});continue}if(n!==null){let s=t[n];if(!s)continue;let a=o.indexOf("=");if(a===-1){let i=o.trim().toLowerCase();s[i]="true"}else{let i=o.slice(0,a).trim().toLowerCase(),c=o.slice(a+1).trim();s[i]=c}}}}return t}function vs(e){let t=[];for(let[n,r]of Object.entries(e)){t.push(`[${n}]`);for(let[o,s]of Object.entries(r))t.push(` ${o} = ${s}`)}return`${t.join(`
|
|
5
5
|
`)}
|
|
6
|
-
`}async function ae(e){let t=
|
|
6
|
+
`}async function ae(e){let t=H(e.gitDir,"config");if(!await e.fs.exists(t))return{};let n=await e.fs.readFile(t);return df(n)}async function Ge(e,t){let n=H(e.gitDir,"config");await e.fs.writeFile(n,vs(t))}async function bt(e,t){let n=await ae(e),{section:r,key:o}=Ds(t);return n[r]?.[o]}async function Ss(e,t,n){let r=await ae(e),{section:o,key:s}=Ds(t);r[o]||(r[o]={}),r[o][s]=n,await Ge(e,r)}async function Zo(e,t){let n=await ae(e),{section:r,key:o}=Ds(t);return n[r]?.[o]?(delete n[r][o],Object.keys(n[r]).length===0&&delete n[r],await Ge(e,n),!0):!1}function Ds(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 lf={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 Cr(e,t){return Qo(e,t,"author")}function Kn(e,t){return Qo(e,t,"committer")}async function Qo(e,t,n){let r=lf[n],o=e.identityOverride;if(o?.locked)return{name:o.name,email:o.email,timestamp:Jo(t.get(r.date)),timezone:"+0000"};let s=t.get(r.name)??await bt(e,"user.name")??o?.name,a=t.get(r.email)??await bt(e,"user.email")??o?.email;if(!s||!a)throw new Error(`${n.charAt(0).toUpperCase()}${n.slice(1)} identity unknown
|
|
7
7
|
|
|
8
8
|
*** Please tell me who you are.
|
|
9
9
|
|
|
@@ -11,96 +11,106 @@ Run
|
|
|
11
11
|
|
|
12
12
|
git config user.email "you@example.com"
|
|
13
13
|
git config user.name "Your Name"
|
|
14
|
-
`);return{name:s,email:a,timestamp:Zo(t.get(r.date)),timezone:"+0000"}}async function Ot(e,t){try{let n=await qn(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 Zo(e){if(e){let t=parseInt(e,10);if(!Number.isNaN(t))return t;let n=Date.parse(e);if(!Number.isNaN(n))return Math.floor(n/1e3)}return Math.floor(Date.now()/1e3)}var Z="0000000000000000000000000000000000000000",Qo=(()=>{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 qt(e){let t="";for(let n=0;n<20;n++)t+=Qo[e[n]];return t}function Pr(e,t){let n="";for(let r=0;r<20;r++)n+=Qo[e[t+r]];return n}function ft(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 lf=new TextEncoder;function Ds(e){return typeof e=="string"?lf.encode(e):e}function uf(){if(typeof globalThis.Bun<"u")return()=>{let e=new Bun.CryptoHasher("sha1"),t={update(n){return e.update(Ds(n)),t},hex:()=>Promise.resolve(e.digest("hex"))};return t};try{let e=br(["node","crypto"].join(":"));if(typeof e.createHash=="function")return()=>{let t=e.createHash("sha1"),n={update(r){return t.update(Ds(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(Ds(n)),t},async hex(){let n=0;for(let a of e)n+=a.byteLength;let r=new Uint8Array(n),o=0;for(let a of e)r.set(a,o),o+=a.byteLength;let s=await crypto.subtle.digest("SHA-1",r);return qt(new Uint8Array(s))}};return t};throw new Error("No SHA-1 implementation available. Requires Bun, Node.js, Deno, or a browser with Web Crypto.")}var ei=uf(),Kt=ei;async function On(e){return ei().update(e).hex()}var ti=1145655875,Ms=2;async function U(e){let t=v(e.gitDir,"index");if(!await e.fs.exists(t))return{version:Ms,entries:[]};let n=await e.fs.readFileBuffer(t);return mf(n)}async function re(e,t){let n=v(e.gitDir,"index"),r=await hf(t);await e.fs.writeFile(n,r)}function Xe(e,t){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(js),{...e,entries:n}}function Ne(e,t){return{...e,entries:e.entries.filter(n=>n.path!==t)}}function Dt(e,t,n=0){return e.entries.find(r=>r.path===t&&r.stage===n)}function dt(e){return e.entries.some(t=>t.stage>0)}function Rt(e){return[...new Set(e.entries.filter(t=>t.stage>0).map(t=>t.path))]}function xe(e){return e.entries.filter(t=>t.stage===0)}function ni(){return{version:Ms,entries:[]}}function Or(e){let t=[...e].sort(js);return{version:Ms,entries:t}}function pe(){return{ctimeSeconds:0,ctimeNanoseconds:0,mtimeSeconds:0,mtimeNanoseconds:0,dev:0,ino:0,uid:0,gid:0,size:0}}function mf(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=0,r=t.getUint32(n);if(n+=4,r!==ti)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 a=[];for(let i=0;i<s;i++){let c=n,f={ctimeSeconds:t.getUint32(n),ctimeNanoseconds:t.getUint32(n+4),mtimeSeconds:t.getUint32(n+8),mtimeNanoseconds:t.getUint32(n+12),dev:t.getUint32(n+16),ino:t.getUint32(n+20),uid:t.getUint32(n+28),gid:t.getUint32(n+32),size:t.getUint32(n+36)},d=t.getUint32(n+24);n+=40;let u=e.subarray(n,n+20),l=qt(u);n+=20;let m=t.getUint16(n);n+=2;let h=m>>12&3,p=m&4095,g;if(p<4095)g=new TextDecoder().decode(e.subarray(n,n+p));else{let b=n;for(;b<e.byteLength&&e[b]!==0;)b++;g=new TextDecoder().decode(e.subarray(n,b))}let w=62+g.length+1,x=Math.ceil(w/8)*8;n=c+x,a.push({path:g,mode:d,hash:l,stage:h,stat:f})}return{version:o,entries:a}}async function hf(e){let t=[...e.entries].sort(js),n=12;for(let d of t){let u=62+d.path.length+1;n+=Math.ceil(u/8)*8}n+=20;let r=new ArrayBuffer(n),o=new Uint8Array(r),s=new DataView(r),a=0;s.setUint32(a,ti),a+=4,s.setUint32(a,e.version),a+=4,s.setUint32(a,t.length),a+=4;for(let d of t){let u=a;s.setUint32(a,d.stat.ctimeSeconds),s.setUint32(a+4,d.stat.ctimeNanoseconds),s.setUint32(a+8,d.stat.mtimeSeconds),s.setUint32(a+12,d.stat.mtimeNanoseconds),s.setUint32(a+16,d.stat.dev),s.setUint32(a+20,d.stat.ino),s.setUint32(a+24,d.mode),s.setUint32(a+28,d.stat.uid),s.setUint32(a+32,d.stat.gid),s.setUint32(a+36,d.stat.size),a+=40;let l=ft(d.hash);o.set(l,a),a+=20;let m=Math.min(d.path.length,4095),h=(d.stage&3)<<12|m;s.setUint16(a,h),a+=2;let p=new TextEncoder().encode(d.path);o.set(p,a),a+=p.byteLength,o[a]=0,a+=1;let g=62+p.byteLength+1,w=Math.ceil(g/8)*8;a=u+w}let i=o.subarray(0,a),c=await On(i),f=ft(c);return o.set(f,a),o}function js(e,t){return e.path<t.path?-1:e.path>t.path?1:e.stage-t.stage}var ri=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;ri[e]=t}function Ls(e){let t=4294967295;for(let n=0;n<e.byteLength;n++)t=ri[(t^e[n])&255]^t>>>8;return(t^4294967295)>>>0}function pf(){try{let e=br(["node","zlib"].join(":"));if(typeof e.deflateSync=="function"&&typeof e.inflateSync=="function")return{deflate:t=>Promise.resolve(new Uint8Array(e.deflateSync(t))),inflate:t=>Promise.resolve(new Uint8Array(e.inflateSync(t)))}}catch{}if(typeof globalThis.CompressionStream=="function"&&typeof globalThis.DecompressionStream=="function")return{async deflate(e){let t=new CompressionStream("deflate"),n=t.writable.getWriter();return n.write(e),n.close(),new Uint8Array(await new Response(t.readable).arrayBuffer())},async inflate(e){let t=new DecompressionStream("deflate"),n=t.writable.getWriter();return n.write(e),n.close(),new Uint8Array(await new Response(t.readable).arrayBuffer())}};throw new Error("No zlib implementation available. Requires Bun, Node.js, Deno, or a browser with CompressionStream.")}var si=pf(),Rn=si.deflate,Mt=si.inflate;var Rr=1346454347,Ns=2,ai=1,ci=2,fi=3,di=4,Kn=6,_s=7,gf={[ai]:"commit",[ci]:"tree",[fi]:"blob",[di]:"tag"},li={commit:ai,tree:ci,blob:fi,tag:di};async function ui(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=t.getUint32(0);if(n!==Rr)throw new Error(`Invalid pack signature: 0x${n.toString(16)} (expected 0x${Rr.toString(16)})`);let r=t.getUint32(4);if(r!==Ns)throw new Error(`Unsupported pack version: ${r}`);let o=t.getUint32(8),s=[],a=12;for(let c=0;c<o;c++){let f=await wf(e,a);s.push(f),a=f.nextOffset}return(await bf(s)).map((c,f)=>({...c,offset:s[f].headerOffset,nextOffset:s[f].nextOffset}))}async function wf(e,t){let n=t,r=e[t++],o=r>>4&7,s=r&15,a=4;for(;r&128;)r=e[t++],s|=(r&127)<<a,a+=7;let i,c;if(o===Kn){let u=e[t++];for(i=u&127;u&128;)i+=1,u=e[t++],i=(i<<7)+(u&127);i=n-i}else o===_s&&(c=Pr(e,t),t+=20);let{result:f,bytesConsumed:d}=await xf(e,t,s);return{headerOffset:n,typeNum:o,inflated:f,baseOffset:i,baseHash:c,nextOffset:t+d}}async function bf(e){let t=new Map;for(let o=0;o<e.length;o++)t.set(e[o].headerOffset,o);let n=new Array(e.length).fill(null);async function r(o){let s=n[o];if(s)return s;let a=e[o];if(a.typeNum!==Kn&&a.typeNum!==_s){let u=gf[a.typeNum];if(!u)throw new Error(`Unknown object type: ${a.typeNum}`);let l={type:u,content:a.inflated,hash:await ii(u,a.inflated)};return n[o]=l,l}let i;if(a.typeNum===Kn){if(i=t.get(a.baseOffset),i===void 0)throw new Error(`OFS_DELTA base not found at offset ${a.baseOffset}`)}else if(i=await yf(e,n,a.baseHash,r),i===void 0)throw new Error(`REF_DELTA base not found for hash ${a.baseHash}`);let c=await r(i),f=Ir(c.content,a.inflated),d={type:c.type,content:f,hash:await ii(c.type,f)};return n[o]=d,d}for(let o=0;o<e.length;o++)await r(o);return n}async function yf(e,t,n,r){for(let o=0;o<t.length;o++)if(t[o]?.hash===n)return o;for(let o=0;o<e.length;o++){let s=e[o];if(s.typeNum!==Kn&&s.typeNum!==_s&&(await r(o)).hash===n)return o}}function Ir(e,t){let n=0,{value:r,newPos:o}=oi(t,n);if(n=o,r!==e.byteLength)throw new Error(`Delta base size mismatch: expected ${r}, got ${e.byteLength}`);let{value:s,newPos:a}=oi(t,n);n=a;let i=new Uint8Array(s),c=0;for(;n<t.byteLength;){let f=t[n++];if(f&128){let d=0,u=0;f&1&&(d=t[n++]),f&2&&(d|=t[n++]<<8),f&4&&(d|=t[n++]<<16),f&8&&(d|=t[n++]<<24),f&16&&(u=t[n++]),f&32&&(u|=t[n++]<<8),f&64&&(u|=t[n++]<<16),u===0&&(u=65536),i.set(e.subarray(d,d+u),c),c+=u}else if(f>0)i.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 i}async function $r(e){let t=[],n=new Uint8Array(12),r=new DataView(n.buffer);r.setUint32(0,Rr),r.setUint32(4,Ns),r.setUint32(8,e.length),t.push(n);for(let d of e){let u=li[d.type],l=await Rn(d.content),m=Gs(u,d.content.byteLength);t.push(m),t.push(l)}let o=0;for(let d of t)o+=d.byteLength;o+=20;let s=new Uint8Array(o),a=0;for(let d of t)s.set(d,a),a+=d.byteLength;let i=Kt();i.update(s.subarray(0,a));let c=await i.hex(),f=ft(c);return s.set(f,a),s}async function mi(e){let t=[],n=new Map,r=new Uint8Array(12),o=new DataView(r.buffer);o.setUint32(0,Rr),o.setUint32(4,Ns),o.setUint32(8,e.length),t.push(r);let s=12,a=[];for(let l of e){let m=s;n.set(l.hash,s);let h=l.delta&&l.deltaBaseHash?n.get(l.deltaBaseHash):void 0;if(l.delta&&h!==void 0){let p=Gs(Kn,l.delta.byteLength),g=Ef(s-h),w=await Rn(l.delta);t.push(p,g,w),s+=p.byteLength+g.byteLength+w.byteLength}else{let p=li[l.type],g=Gs(p,l.content.byteLength),w=await Rn(l.content);t.push(g,w),s+=g.byteLength+w.byteLength}a.push({hash:l.hash,offset:m,nextOffset:s})}let i=0;for(let l of t)i+=l.byteLength;i+=20;let c=new Uint8Array(i),f=0;for(let l of t)c.set(l,f),f+=l.byteLength;let d=Kt();d.update(c.subarray(0,f));let u=await d.hex();return c.set(ft(u),f),{data:c,entries:a}}function Ef(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 Gs(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 oi(e,t){let n=0,r=0,o;do o=e[t++],n|=(o&127)<<r,r+=7;while(o&128);return{value:n,newPos:t}}async function xf(e,t,n){let r=e.subarray(t),o=await Mt(r);if(o.byteLength!==n)throw new Error(`Inflate size mismatch: got ${o.byteLength}, expected ${n}`);let s=2,a=r.byteLength;for(;s<a;){let i=s+a>>>1;try{(await Mt(r.subarray(0,i))).byteLength===n?a=i:s=i+1}catch{s=i+1}}return{result:o,bytesConsumed:s}}var kf=new TextEncoder;async function ii(e,t){let n=kf.encode(`${e} ${t.byteLength}\0`),r=Kt();return r.update(n),r.update(t),r.hex()}var hi=4285812579,pi=2,un=class{fanout;hashes;offsets;largeOffsets;count;constructor(t){let n=new DataView(t.buffer,t.byteOffset,t.byteLength);if(n.getUint32(0)!==hi)throw new Error("Invalid pack index: bad magic");if(n.getUint32(4)!==pi)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<this.count;s++)this.offsets[s]=n.getUint32(r),r+=4;let o=!1;for(let s=0;s<this.count;s++)if(this.offsets[s]&2147483648){o=!0;break}this.largeOffsets=o?new DataView(t.buffer,t.byteOffset+r):null}lookup(t){let n=ft(t),r=n[0],o=r===0?0:this.fanout[r-1],s=this.fanout[r],a=o,i=s;for(;a<i;){let c=a+i>>>1,f=this.compareAt(c,n);if(f<0)a=c+1;else if(f>0)i=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<this.count;n++){let r="",o=n*20;for(let s=0;s<20;s++){let a=this.hashes[o+s];r+=(a>>4).toString(16)+(a&15).toString(16)}t.push(r)}return t}compareAt(t,n){let r=t*20;for(let o=0;o<20;o++){let s=this.hashes[r+o],a=n[o];if(s<a)return-1;if(s>a)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}};async function gi(e,t){let n=[...e].sort((m,h)=>m.hash<h.hash?-1:m.hash>h.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,a=new Uint8Array(s),i=new DataView(a.buffer),c=0;i.setUint32(c,hi),c+=4,i.setUint32(c,pi),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++)i.setUint32(c,f[m]),c+=4;for(let m of n)a.set(ft(m.hash),c),c+=20;for(let m of n)i.setUint32(c,m.crc),c+=4;let d=0;for(let m of n)m.offset>=2147483648?i.setUint32(c,2147483648|d++):i.setUint32(c,m.offset),c+=4;for(let m of o)i.setBigUint64(c,m),c+=8;a.set(t,c),c+=20;let u=Kt();u.update(a.subarray(0,c));let l=await u.hex();return a.set(ft(l),c),a}async function wi(e){let n=(await ui(e)).map(o=>({hash:o.hash,offset:o.offset,crc:Ls(e.subarray(o.offset,o.nextOffset))})),r=e.subarray(e.byteLength-20);return gi(n,r)}async function bi(e,t){let n=t.map(o=>({hash:o.hash,offset:o.offset,crc:Ls(e.subarray(o.offset,o.nextOffset))})),r=e.subarray(e.byteLength-20);return gi(n,r)}var Cf=6,Pf=7,Of={1:"commit",2:"tree",3:"blob",4:"tag"},zn=class{constructor(t,n){this.data=t;this.index=new un(n)}index;hasObject(t){return this.index.has(t)}async readObject(t){let n=this.index.lookup(t);return n===null?null:this.readAt(n)}get objectCount(){return this.index.objectCount}async readAt(t){let n=this.data,r=t,o=n[r++],s=o>>4&7,a=o&15,i=4;for(;o&128;)o=n[r++],a|=(o&127)<<i,i+=7;if(s===Cf){let d=n[r++],u=d&127;for(;d&128;)u+=1,d=n[r++],u=(u<<7)+(d&127);let l=await Mt(n.subarray(r)),m=await this.readAt(t-u);return{type:m.type,content:Ir(m.content,l)}}if(s===Pf){let d=Pr(n,r);r+=20;let u=await Mt(n.subarray(r)),l=this.index.lookup(d);if(l===null)throw new Error(`REF_DELTA base ${d} not found in pack`);let m=await this.readAt(l);return{type:m.type,content:Ir(m.content,u)}}let c=Of[s];if(!c)throw new Error(`Unknown pack object type: ${s}`);let f=await Mt(n.subarray(r));if(f.byteLength!==a)throw new Error(`Pack inflate size mismatch at offset ${t}: got ${f.byteLength}, expected ${a}`);return{type:c,content:f}}};var Rf=new TextEncoder,If=new TextDecoder;function Us(e,t){let n=Rf.encode(`${e} ${t.byteLength}\0`),r=new Uint8Array(n.byteLength+t.byteLength);return r.set(n),r.set(t,n.byteLength),r}function $f(e,t){let n=t.indexOf(0);if(n===-1)throw new Error(`Corrupt object ${e}: no null byte in header`);let r=If.decode(t.subarray(0,n)),o=r.indexOf(" ");if(o===-1)throw new Error(`Corrupt object ${e}: malformed header "${r}"`);let s=r.slice(0,o),a=parseInt(r.slice(o+1),10),i=t.subarray(n+1);if(i.byteLength!==a)throw new Error(`Corrupt object ${e}: expected ${a} bytes, got ${i.byteLength}`);return{type:s,content:i}}function Fs(e,t){return v(e,"objects",t.slice(0,2),t.slice(2))}var Tr=class{constructor(t,n,r){this.fs=t;this.gitDir=n;this.hooks=r}packs=[];loadedPackNames=new Set;discoverPromise=null;async write(t,n){let r=Us(t,n),o=await On(r),s=Fs(this.gitDir,o);if(await this.fs.exists(s))return o;let a=v(this.gitDir,"objects",o.slice(0,2));return await this.fs.mkdir(a,{recursive:!0}),await this.fs.writeFile(s,await Rn(r)),this.hooks?.emit("object:write",{type:t,hash:o}),o}async read(t){let n=Fs(this.gitDir,t);if(await this.fs.exists(n)){let r=await this.fs.readFileBuffer(n),o=await Mt(r);return $f(t,o)}await this.discover();for(let r of this.packs){let o=await r.readObject(t);if(o)return o}throw new Error(`object ${t} not found`)}async exists(t){if(await this.fs.exists(Fs(this.gitDir,t)))return!0;await this.discover();for(let n of this.packs)if(n.hasObject(t))return!0;return!1}async ingestPack(t){if(t.byteLength<32)return 0;let r=new DataView(t.buffer,t.byteOffset,t.byteLength).getUint32(8);if(r===0)return 0;let o=t.subarray(t.byteLength-20),s=qt(o),a=v(this.gitDir,"objects","pack");await this.fs.mkdir(a,{recursive:!0});let i=`pack-${s}`,c=v(a,`${i}.pack`);await this.fs.writeFile(c,t);let f=await wi(t),d=v(a,`${i}.idx`);return await this.fs.writeFile(d,f),this.loadedPackNames.add(i),this.packs.push(new zn(t,f)),r}discover(){return this.discoverPromise||(this.discoverPromise=this.doDiscover()),this.discoverPromise}async doDiscover(){let t=v(this.gitDir,"objects","pack");if(!await this.fs.exists(t))return;let n=await this.fs.readdir(t);for(let r of n){if(!r.endsWith(".idx"))continue;let o=r.slice(0,-4);if(this.loadedPackNames.has(o))continue;let s=v(t,`${o}.pack`);if(!await this.fs.exists(s))continue;let[a,i]=await Promise.all([this.fs.readFileBuffer(v(t,r)),this.fs.readFileBuffer(s)]);this.loadedPackNames.add(o),this.packs.push(new zn(i,a))}}};function Vn(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),[a="0",i="+0000"]=s.split(" "),c=parseInt(a,10);return{name:r,email:o,timestamp:c,timezone:i}}function Yn(e){return`${e.name} <${e.email}> ${e.timestamp} ${e.timezone}`}var Tf=new TextEncoder,Hf=new TextDecoder;function It(e){let t=Hf.decode(e),n=t.indexOf(`
|
|
14
|
+
`);return{name:s,email:a,timestamp:Jo(t.get(r.date)),timezone:"+0000"}}async function Ot(e,t){try{let n=await Kn(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 Jo(e){if(e){let t=parseInt(e,10);if(!Number.isNaN(t))return t;let n=Date.parse(e);if(!Number.isNaN(n))return Math.floor(n/1e3)}return Math.floor(Date.now()/1e3)}var Z="0000000000000000000000000000000000000000",ei=(()=>{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 qt(e){let t="";for(let n=0;n<20;n++)t+=ei[e[n]];return t}function Pr(e,t){let n="";for(let r=0;r<20;r++)n+=ei[e[t+r]];return n}function ft(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 uf=new TextEncoder;function Ms(e){return typeof e=="string"?uf.encode(e):e}function mf(){if(typeof globalThis.Bun<"u")return()=>{let e=new Bun.CryptoHasher("sha1"),t={update(n){return e.update(Ms(n)),t},hex:()=>Promise.resolve(e.digest("hex"))};return t};try{let e=br(["node","crypto"].join(":"));if(typeof e.createHash=="function")return()=>{let t=e.createHash("sha1"),n={update(r){return t.update(Ms(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(Ms(n)),t},async hex(){let n=0;for(let a of e)n+=a.byteLength;let r=new Uint8Array(n),o=0;for(let a of e)r.set(a,o),o+=a.byteLength;let s=await crypto.subtle.digest("SHA-1",r);return qt(new Uint8Array(s))}};return t};throw new Error("No SHA-1 implementation available. Requires Bun, Node.js, Deno, or a browser with Web Crypto.")}var ti=mf(),Kt=ti;async function On(e){return ti().update(e).hex()}var ni=1145655875,js=2;async function U(e){let t=H(e.gitDir,"index");if(!await e.fs.exists(t))return{version:js,entries:[]};let n=await e.fs.readFileBuffer(t);return hf(n)}async function re(e,t){let n=H(e.gitDir,"index"),r=await pf(t);await e.fs.writeFile(n,r)}function Xe(e,t){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(Ls),{...e,entries:n}}function Ne(e,t){return{...e,entries:e.entries.filter(n=>n.path!==t)}}function Dt(e,t,n=0){return e.entries.find(r=>r.path===t&&r.stage===n)}function dt(e){return e.entries.some(t=>t.stage>0)}function Rt(e){return[...new Set(e.entries.filter(t=>t.stage>0).map(t=>t.path))]}function xe(e){return e.entries.filter(t=>t.stage===0)}function ri(){return{version:js,entries:[]}}function Or(e){let t=[...e].sort(Ls);return{version:js,entries:t}}function pe(){return{ctimeSeconds:0,ctimeNanoseconds:0,mtimeSeconds:0,mtimeNanoseconds:0,dev:0,ino:0,uid:0,gid:0,size:0}}function hf(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=0,r=t.getUint32(n);if(n+=4,r!==ni)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 a=[];for(let i=0;i<s;i++){let c=n,f={ctimeSeconds:t.getUint32(n),ctimeNanoseconds:t.getUint32(n+4),mtimeSeconds:t.getUint32(n+8),mtimeNanoseconds:t.getUint32(n+12),dev:t.getUint32(n+16),ino:t.getUint32(n+20),uid:t.getUint32(n+28),gid:t.getUint32(n+32),size:t.getUint32(n+36)},d=t.getUint32(n+24);n+=40;let u=e.subarray(n,n+20),l=qt(u);n+=20;let m=t.getUint16(n);n+=2;let h=m>>12&3,p=m&4095,g;if(p<4095)g=new TextDecoder().decode(e.subarray(n,n+p));else{let b=n;for(;b<e.byteLength&&e[b]!==0;)b++;g=new TextDecoder().decode(e.subarray(n,b))}let w=62+g.length+1,x=Math.ceil(w/8)*8;n=c+x,a.push({path:g,mode:d,hash:l,stage:h,stat:f})}return{version:o,entries:a}}async function pf(e){let t=[...e.entries].sort(Ls),n=12;for(let d of t){let u=62+d.path.length+1;n+=Math.ceil(u/8)*8}n+=20;let r=new ArrayBuffer(n),o=new Uint8Array(r),s=new DataView(r),a=0;s.setUint32(a,ni),a+=4,s.setUint32(a,e.version),a+=4,s.setUint32(a,t.length),a+=4;for(let d of t){let u=a;s.setUint32(a,d.stat.ctimeSeconds),s.setUint32(a+4,d.stat.ctimeNanoseconds),s.setUint32(a+8,d.stat.mtimeSeconds),s.setUint32(a+12,d.stat.mtimeNanoseconds),s.setUint32(a+16,d.stat.dev),s.setUint32(a+20,d.stat.ino),s.setUint32(a+24,d.mode),s.setUint32(a+28,d.stat.uid),s.setUint32(a+32,d.stat.gid),s.setUint32(a+36,d.stat.size),a+=40;let l=ft(d.hash);o.set(l,a),a+=20;let m=Math.min(d.path.length,4095),h=(d.stage&3)<<12|m;s.setUint16(a,h),a+=2;let p=new TextEncoder().encode(d.path);o.set(p,a),a+=p.byteLength,o[a]=0,a+=1;let g=62+p.byteLength+1,w=Math.ceil(g/8)*8;a=u+w}let i=o.subarray(0,a),c=await On(i),f=ft(c);return o.set(f,a),o}function Ls(e,t){return e.path<t.path?-1:e.path>t.path?1:e.stage-t.stage}var si=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;si[e]=t}function Gs(e){let t=4294967295;for(let n=0;n<e.byteLength;n++)t=si[(t^e[n])&255]^t>>>8;return(t^4294967295)>>>0}function gf(){try{let e=br(["node","zlib"].join(":"));if(typeof e.deflateSync=="function"&&typeof e.inflateSync=="function")return{deflate:t=>Promise.resolve(new Uint8Array(e.deflateSync(t))),inflate:t=>Promise.resolve(new Uint8Array(e.inflateSync(t)))}}catch{}if(typeof globalThis.CompressionStream=="function"&&typeof globalThis.DecompressionStream=="function")return{async deflate(e){let t=new CompressionStream("deflate"),n=t.writable.getWriter();return n.write(e),n.close(),new Uint8Array(await new Response(t.readable).arrayBuffer())},async inflate(e){let t=new DecompressionStream("deflate"),n=t.writable.getWriter();return n.write(e),n.close(),new Uint8Array(await new Response(t.readable).arrayBuffer())}};throw new Error("No zlib implementation available. Requires Bun, Node.js, Deno, or a browser with CompressionStream.")}var oi=gf(),Rn=oi.deflate,Mt=oi.inflate;var Rr=1346454347,_s=2,ci=1,fi=2,di=3,li=4,zn=6,Fs=7,wf={[ci]:"commit",[fi]:"tree",[di]:"blob",[li]:"tag"},ui={commit:ci,tree:fi,blob:di,tag:li};async function mi(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=t.getUint32(0);if(n!==Rr)throw new Error(`Invalid pack signature: 0x${n.toString(16)} (expected 0x${Rr.toString(16)})`);let r=t.getUint32(4);if(r!==_s)throw new Error(`Unsupported pack version: ${r}`);let o=t.getUint32(8),s=[],a=12;for(let c=0;c<o;c++){let f=await bf(e,a);s.push(f),a=f.nextOffset}return(await yf(s)).map((c,f)=>({...c,offset:s[f].headerOffset,nextOffset:s[f].nextOffset}))}async function bf(e,t){let n=t,r=e[t++],o=r>>4&7,s=r&15,a=4;for(;r&128;)r=e[t++],s|=(r&127)<<a,a+=7;let i,c;if(o===zn){let u=e[t++];for(i=u&127;u&128;)i+=1,u=e[t++],i=(i<<7)+(u&127);i=n-i}else o===Fs&&(c=Pr(e,t),t+=20);let{result:f,bytesConsumed:d}=await kf(e,t,s);return{headerOffset:n,typeNum:o,inflated:f,baseOffset:i,baseHash:c,nextOffset:t+d}}async function yf(e){let t=new Map;for(let o=0;o<e.length;o++)t.set(e[o].headerOffset,o);let n=new Array(e.length).fill(null);async function r(o){let s=n[o];if(s)return s;let a=e[o];if(a.typeNum!==zn&&a.typeNum!==Fs){let u=wf[a.typeNum];if(!u)throw new Error(`Unknown object type: ${a.typeNum}`);let l={type:u,content:a.inflated,hash:await ai(u,a.inflated)};return n[o]=l,l}let i;if(a.typeNum===zn){if(i=t.get(a.baseOffset),i===void 0)throw new Error(`OFS_DELTA base not found at offset ${a.baseOffset}`)}else if(i=await Ef(e,n,a.baseHash,r),i===void 0)throw new Error(`REF_DELTA base not found for hash ${a.baseHash}`);let c=await r(i),f=Ir(c.content,a.inflated),d={type:c.type,content:f,hash:await ai(c.type,f)};return n[o]=d,d}for(let o=0;o<e.length;o++)await r(o);return n}async function Ef(e,t,n,r){for(let o=0;o<t.length;o++)if(t[o]?.hash===n)return o;for(let o=0;o<e.length;o++){let s=e[o];if(s.typeNum!==zn&&s.typeNum!==Fs&&(await r(o)).hash===n)return o}}function Ir(e,t){let n=0,{value:r,newPos:o}=ii(t,n);if(n=o,r!==e.byteLength)throw new Error(`Delta base size mismatch: expected ${r}, got ${e.byteLength}`);let{value:s,newPos:a}=ii(t,n);n=a;let i=new Uint8Array(s),c=0;for(;n<t.byteLength;){let f=t[n++];if(f&128){let d=0,u=0;f&1&&(d=t[n++]),f&2&&(d|=t[n++]<<8),f&4&&(d|=t[n++]<<16),f&8&&(d|=t[n++]<<24),f&16&&(u=t[n++]),f&32&&(u|=t[n++]<<8),f&64&&(u|=t[n++]<<16),u===0&&(u=65536),i.set(e.subarray(d,d+u),c),c+=u}else if(f>0)i.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 i}async function $r(e){let t=[],n=new Uint8Array(12),r=new DataView(n.buffer);r.setUint32(0,Rr),r.setUint32(4,_s),r.setUint32(8,e.length),t.push(n);for(let d of e){let u=ui[d.type],l=await Rn(d.content),m=Ns(u,d.content.byteLength);t.push(m),t.push(l)}let o=0;for(let d of t)o+=d.byteLength;o+=20;let s=new Uint8Array(o),a=0;for(let d of t)s.set(d,a),a+=d.byteLength;let i=Kt();i.update(s.subarray(0,a));let c=await i.hex(),f=ft(c);return s.set(f,a),s}async function hi(e){let t=[],n=new Map,r=new Uint8Array(12),o=new DataView(r.buffer);o.setUint32(0,Rr),o.setUint32(4,_s),o.setUint32(8,e.length),t.push(r);let s=12,a=[];for(let l of e){let m=s;n.set(l.hash,s);let h=l.delta&&l.deltaBaseHash?n.get(l.deltaBaseHash):void 0;if(l.delta&&h!==void 0){let p=Ns(zn,l.delta.byteLength),g=xf(s-h),w=await Rn(l.delta);t.push(p,g,w),s+=p.byteLength+g.byteLength+w.byteLength}else{let p=ui[l.type],g=Ns(p,l.content.byteLength),w=await Rn(l.content);t.push(g,w),s+=g.byteLength+w.byteLength}a.push({hash:l.hash,offset:m,nextOffset:s})}let i=0;for(let l of t)i+=l.byteLength;i+=20;let c=new Uint8Array(i),f=0;for(let l of t)c.set(l,f),f+=l.byteLength;let d=Kt();d.update(c.subarray(0,f));let u=await d.hex();return c.set(ft(u),f),{data:c,entries:a}}function xf(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 Ns(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 ii(e,t){let n=0,r=0,o;do o=e[t++],n|=(o&127)<<r,r+=7;while(o&128);return{value:n,newPos:t}}async function kf(e,t,n){let r=e.subarray(t),o=await Mt(r);if(o.byteLength!==n)throw new Error(`Inflate size mismatch: got ${o.byteLength}, expected ${n}`);let s=2,a=r.byteLength;for(;s<a;){let i=s+a>>>1;try{(await Mt(r.subarray(0,i))).byteLength===n?a=i:s=i+1}catch{s=i+1}}return{result:o,bytesConsumed:s}}var Cf=new TextEncoder;async function ai(e,t){let n=Cf.encode(`${e} ${t.byteLength}\0`),r=Kt();return r.update(n),r.update(t),r.hex()}var pi=4285812579,gi=2,un=class{fanout;hashes;offsets;largeOffsets;count;constructor(t){let n=new DataView(t.buffer,t.byteOffset,t.byteLength);if(n.getUint32(0)!==pi)throw new Error("Invalid pack index: bad magic");if(n.getUint32(4)!==gi)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<this.count;s++)this.offsets[s]=n.getUint32(r),r+=4;let o=!1;for(let s=0;s<this.count;s++)if(this.offsets[s]&2147483648){o=!0;break}this.largeOffsets=o?new DataView(t.buffer,t.byteOffset+r):null}lookup(t){let n=ft(t),r=n[0],o=r===0?0:this.fanout[r-1],s=this.fanout[r],a=o,i=s;for(;a<i;){let c=a+i>>>1,f=this.compareAt(c,n);if(f<0)a=c+1;else if(f>0)i=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<this.count;n++){let r="",o=n*20;for(let s=0;s<20;s++){let a=this.hashes[o+s];r+=(a>>4).toString(16)+(a&15).toString(16)}t.push(r)}return t}compareAt(t,n){let r=t*20;for(let o=0;o<20;o++){let s=this.hashes[r+o],a=n[o];if(s<a)return-1;if(s>a)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}};async function wi(e,t){let n=[...e].sort((m,h)=>m.hash<h.hash?-1:m.hash>h.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,a=new Uint8Array(s),i=new DataView(a.buffer),c=0;i.setUint32(c,pi),c+=4,i.setUint32(c,gi),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++)i.setUint32(c,f[m]),c+=4;for(let m of n)a.set(ft(m.hash),c),c+=20;for(let m of n)i.setUint32(c,m.crc),c+=4;let d=0;for(let m of n)m.offset>=2147483648?i.setUint32(c,2147483648|d++):i.setUint32(c,m.offset),c+=4;for(let m of o)i.setBigUint64(c,m),c+=8;a.set(t,c),c+=20;let u=Kt();u.update(a.subarray(0,c));let l=await u.hex();return a.set(ft(l),c),a}async function bi(e){let n=(await mi(e)).map(o=>({hash:o.hash,offset:o.offset,crc:Gs(e.subarray(o.offset,o.nextOffset))})),r=e.subarray(e.byteLength-20);return wi(n,r)}async function yi(e,t){let n=t.map(o=>({hash:o.hash,offset:o.offset,crc:Gs(e.subarray(o.offset,o.nextOffset))})),r=e.subarray(e.byteLength-20);return wi(n,r)}var Pf=6,Of=7,Rf={1:"commit",2:"tree",3:"blob",4:"tag"},Vn=class{constructor(t,n){this.data=t;this.index=new un(n)}index;hasObject(t){return this.index.has(t)}async readObject(t){let n=this.index.lookup(t);return n===null?null:this.readAt(n)}get objectCount(){return this.index.objectCount}async readAt(t){let n=this.data,r=t,o=n[r++],s=o>>4&7,a=o&15,i=4;for(;o&128;)o=n[r++],a|=(o&127)<<i,i+=7;if(s===Pf){let d=n[r++],u=d&127;for(;d&128;)u+=1,d=n[r++],u=(u<<7)+(d&127);let l=await Mt(n.subarray(r)),m=await this.readAt(t-u);return{type:m.type,content:Ir(m.content,l)}}if(s===Of){let d=Pr(n,r);r+=20;let u=await Mt(n.subarray(r)),l=this.index.lookup(d);if(l===null)throw new Error(`REF_DELTA base ${d} not found in pack`);let m=await this.readAt(l);return{type:m.type,content:Ir(m.content,u)}}let c=Rf[s];if(!c)throw new Error(`Unknown pack object type: ${s}`);let f=await Mt(n.subarray(r));if(f.byteLength!==a)throw new Error(`Pack inflate size mismatch at offset ${t}: got ${f.byteLength}, expected ${a}`);return{type:c,content:f}}};var If=new TextEncoder,$f=new TextDecoder;function Bs(e,t){let n=If.encode(`${e} ${t.byteLength}\0`),r=new Uint8Array(n.byteLength+t.byteLength);return r.set(n),r.set(t,n.byteLength),r}function Tf(e,t){let n=t.indexOf(0);if(n===-1)throw new Error(`Corrupt object ${e}: no null byte in header`);let r=$f.decode(t.subarray(0,n)),o=r.indexOf(" ");if(o===-1)throw new Error(`Corrupt object ${e}: malformed header "${r}"`);let s=r.slice(0,o),a=parseInt(r.slice(o+1),10),i=t.subarray(n+1);if(i.byteLength!==a)throw new Error(`Corrupt object ${e}: expected ${a} bytes, got ${i.byteLength}`);return{type:s,content:i}}function Us(e,t){return H(e,"objects",t.slice(0,2),t.slice(2))}var Tr=class{constructor(t,n,r){this.fs=t;this.gitDir=n;this.hooks=r}packs=[];loadedPackNames=new Set;discoverPromise=null;async write(t,n){let r=Bs(t,n),o=await On(r),s=Us(this.gitDir,o);if(await this.fs.exists(s))return o;let a=H(this.gitDir,"objects",o.slice(0,2));return await this.fs.mkdir(a,{recursive:!0}),await this.fs.writeFile(s,await Rn(r)),this.hooks?.emit("object:write",{type:t,hash:o}),o}async read(t){let n=Us(this.gitDir,t);if(await this.fs.exists(n)){let r=await this.fs.readFileBuffer(n),o=await Mt(r);return Tf(t,o)}await this.discover();for(let r of this.packs){let o=await r.readObject(t);if(o)return o}throw new Error(`object ${t} not found`)}async exists(t){if(await this.fs.exists(Us(this.gitDir,t)))return!0;await this.discover();for(let n of this.packs)if(n.hasObject(t))return!0;return!1}async ingestPack(t){if(t.byteLength<32)return 0;let r=new DataView(t.buffer,t.byteOffset,t.byteLength).getUint32(8);if(r===0)return 0;let o=t.subarray(t.byteLength-20),s=qt(o),a=H(this.gitDir,"objects","pack");await this.fs.mkdir(a,{recursive:!0});let i=`pack-${s}`,c=H(a,`${i}.pack`);await this.fs.writeFile(c,t);let f=await bi(t),d=H(a,`${i}.idx`);return await this.fs.writeFile(d,f),this.loadedPackNames.add(i),this.packs.push(new Vn(t,f)),r}discover(){return this.discoverPromise||(this.discoverPromise=this.doDiscover()),this.discoverPromise}async doDiscover(){let t=H(this.gitDir,"objects","pack");if(!await this.fs.exists(t))return;let n=await this.fs.readdir(t);for(let r of n){if(!r.endsWith(".idx"))continue;let o=r.slice(0,-4);if(this.loadedPackNames.has(o))continue;let s=H(t,`${o}.pack`);if(!await this.fs.exists(s))continue;let[a,i]=await Promise.all([this.fs.readFileBuffer(H(t,r)),this.fs.readFileBuffer(s)]);this.loadedPackNames.add(o),this.packs.push(new Vn(i,a))}}};function Yn(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),[a="0",i="+0000"]=s.split(" "),c=parseInt(a,10);return{name:r,email:o,timestamp:c,timezone:i}}function Xn(e){return`${e.name} <${e.email}> ${e.timestamp} ${e.timezone}`}var Hf=new TextEncoder,Af=new TextDecoder;function It(e){let t=Af.decode(e),n=t.indexOf(`
|
|
15
15
|
|
|
16
16
|
`),r=n===-1?t:t.slice(0,n),o=n===-1?"":t.slice(n+2),s="",a=[],i,c;for(let f of r.split(`
|
|
17
|
-
`)){let d=f.indexOf(" ");if(d===-1)continue;let u=f.slice(0,d),l=f.slice(d+1);switch(u){case"tree":s=l;break;case"parent":a.push(l);break;case"author":i=
|
|
18
|
-
`))}var
|
|
17
|
+
`)){let d=f.indexOf(" ");if(d===-1)continue;let u=f.slice(0,d),l=f.slice(d+1);switch(u){case"tree":s=l;break;case"parent":a.push(l);break;case"author":i=Yn(l);break;case"committer":c=Yn(l);break}}if(!s)throw new Error("Commit missing tree field");if(!i)throw new Error("Commit missing author field");if(!c)throw new Error("Commit missing committer field");return{type:"commit",tree:s,parents:a,author:i,committer:c,message:o}}function $t(e){let t=[];t.push(`tree ${e.tree}`);for(let n of e.parents)t.push(`parent ${n}`);return t.push(`author ${Xn(e.author)}`),t.push(`committer ${Xn(e.committer)}`),t.push(""),t.push(e.message),Hf.encode(t.join(`
|
|
18
|
+
`))}var vf=new TextEncoder,Sf=new TextDecoder;function jt(e){let t=Sf.decode(e),n=t.indexOf(`
|
|
19
19
|
|
|
20
20
|
`),r=n===-1?t:t.slice(0,n),o=n===-1?"":t.slice(n+2),s="",a="commit",i="",c;for(let f of r.split(`
|
|
21
|
-
`)){let d=f.indexOf(" ");if(d===-1)continue;let u=f.slice(0,d),l=f.slice(d+1);switch(u){case"object":s=l;break;case"type":a=l;break;case"tag":i=l;break;case"tagger":c=
|
|
22
|
-
`))}function Hr(e){if(e.objectStore)return e.objectStore;let t=new Tr(e.fs,e.gitDir,e.hooks);return e.objectStore=t,t}async function st(e,t){return On(
|
|
23
|
-
`),e.hooks?.emit("ref:update",{ref:t,oldHash:r,newHash:n})}async function $e(e,t,n){let r=
|
|
24
|
-
`)}async function ie(e,t){let n=e.hooks?await F(e,t):null,r=
|
|
21
|
+
`)){let d=f.indexOf(" ");if(d===-1)continue;let u=f.slice(0,d),l=f.slice(d+1);switch(u){case"object":s=l;break;case"type":a=l;break;case"tag":i=l;break;case"tagger":c=Yn(l);break}}if(!s)throw new Error("Tag missing object field");if(!i)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:i,tagger:c,message:o}}function Ei(e){let t=[];return t.push(`object ${e.object}`),t.push(`type ${e.objectType}`),t.push(`tag ${e.name}`),t.push(`tagger ${Xn(e.tagger)}`),t.push(""),t.push(e.message),vf.encode(t.join(`
|
|
22
|
+
`))}function Hr(e){if(e.objectStore)return e.objectStore;let t=new Tr(e.fs,e.gitDir,e.hooks);return e.objectStore=t,t}async function st(e,t){return On(Bs(e,t))}async function we(e,t,n){return Hr(e).write(t,n)}async function ce(e,t){return Hr(e).read(t)}async function zt(e,t){return Hr(e).exists(t)}async function Ar(e,t){return Hr(e).ingestPack(t)}function Pe(e){let t=Math.min(e.length,8e3);for(let n=0;n<t;n++)if(e.charCodeAt(n)===0)return!0;return!1}function Vt(e){let t=Math.min(e.byteLength,8e3);for(let n=0;n<t;n++)if(e[n]===0)return!0;return!1}var Df=new TextDecoder;async function fe(e,t){let n=await ce(e,t);if(n.type!=="blob")throw new Error(`Expected blob for ${t}, got ${n.type}`);return Df.decode(n.content)}async function ot(e,t){let n=await ce(e,t);if(n.type!=="blob")throw new Error(`Expected blob for ${t}, got ${n.type}`);return n.content}async function M(e,t){let n=await ce(e,t);if(n.type!=="commit")throw new Error(`Expected commit object for ${t}, got ${n.type}`);return It(n.content)}async function xi(e,t){let n=await ce(e,t);if(n.type!=="tag")throw new Error(`Expected tag object for ${t}, got ${n.type}`);return jt(n.content)}async function Re(e,t){let n=t;for(let r=0;r<100;r++){let o=await ce(e,n);if(o.type==="commit")return n;if(o.type==="tag"){n=jt(o.content).object;continue}throw new Error(`Cannot peel ${o.type} object ${t} to commit`)}throw new Error(`Tag chain too deep for ${t}`)}var Ws="ref: ",Mf=10;async function ki(e,t){let n=Zn(e,t);if(await e.fs.exists(n)){let s=(await e.fs.readFile(n)).trim();return s.startsWith(Ws)?{type:"symbolic",target:s.slice(Ws.length)}:{type:"direct",hash:s}}let o=(await Oi(e)).get(t);return o?{type:"direct",hash:o}:null}async function F(e,t){let n=t;for(let r=0;r<Mf;r++){let o=await ki(e,n);if(!o)return null;if(o.type==="direct")return o.hash;n=o.target}throw new Error(`Symbolic ref loop detected resolving "${t}"`)}async function J(e){return ki(e,"HEAD")}async function X(e){return F(e,"HEAD")}async function Y(e,t,n){let r=e.hooks?await F(e,t):null,o=Zn(e,t);await In(e.fs,o),await e.fs.writeFile(o,`${n}
|
|
23
|
+
`),e.hooks?.emit("ref:update",{ref:t,oldHash:r,newHash:n})}async function $e(e,t,n){let r=Zn(e,t);await In(e.fs,r),await e.fs.writeFile(r,`${Ws}${n}
|
|
24
|
+
`)}async function ie(e,t){let n=e.hooks?await F(e,t):null,r=Zn(e,t);await e.fs.exists(r)&&await e.fs.rm(r),await jf(e,t),await Jn(e,t),e.hooks&&n&&e.hooks.emit("ref:delete",{ref:t,oldHash:n})}async function le(e,t="refs"){let n=[],r=H(e.gitDir,t);await e.fs.exists(r)&&await Ri(e,r,t,n);let o=await Oi(e);if(o.size>0){let s=new Set(n.map(i=>i.name)),a=`${t}/`;for(let[i,c]of o)i.startsWith(a)&&!s.has(i)&&n.push({name:i,hash:c})}return n.sort((s,a)=>s.name<a.name?-1:s.name>a.name?1:0)}function de(e){return e.replace("refs/heads/","")}async function Yt(e,t){let n=await J(e);n&&n.type==="symbolic"?await Y(e,n.target,t):await Y(e,"HEAD",t)}async function jf(e,t){let n=H(e.gitDir,"packed-refs");if(!await e.fs.exists(n))return;let o=(await e.fs.readFile(n)).split(`
|
|
25
25
|
`),s=[],a=!1;for(let c of o){if(a&&c.startsWith("^")){a=!1;continue}if(a=!1,!c||c.startsWith("#")){s.push(c);continue}let f=c.indexOf(" ");if(f!==-1&&c.slice(f+1).trim()===t){a=!0;continue}s.push(c)}s.some(c=>c&&!c.startsWith("#")&&!c.startsWith("^"))?await e.fs.writeFile(n,s.join(`
|
|
26
|
-
`)):await e.fs.rm(n)}async function
|
|
26
|
+
`)):await e.fs.rm(n)}async function Ci(e){let t=await le(e,"refs");if(t.length===0)return;let n=["# pack-refs with: peeled fully-peeled sorted"];for(let o of t)if(n.push(`${o.hash} ${o.name}`),o.name.startsWith("refs/tags/"))try{let s=await ce(e,o.hash);if(s.type==="tag"){let a=jt(s.content).object;for(let i=0;i<100;i++){let c=await ce(e,a);if(c.type!=="tag")break;a=jt(c.content).object}n.push(`^${a}`)}}catch{}await e.fs.writeFile(H(e.gitDir,"packed-refs"),`${n.join(`
|
|
27
27
|
`)}
|
|
28
|
-
`);for(let
|
|
29
|
-
`)){if(!o||o.startsWith("#")||o.startsWith("^"))continue;let s=o.indexOf(" ");if(s===-1)continue;let a=o.slice(0,s),i=o.slice(s+1).trim();a.length===40&&i&&r.set(i,a)}return r}function
|
|
30
|
-
`)){if(!s)continue;let a=
|
|
28
|
+
`);for(let o of t){let s=Zn(e,o.name);await e.fs.exists(s)&&await e.fs.rm(s)}await Pi(e,H(e.gitDir,"refs"));let r=H(e.gitDir,"refs");await e.fs.mkdir(r,{recursive:!0}),await e.fs.mkdir(H(r,"heads"),{recursive:!0}),await e.fs.mkdir(H(r,"tags"),{recursive:!0})}async function Pi(e,t){if(!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 Pi(e,H(t,s));(await e.fs.readdir(t)).length===0&&await e.fs.rm(t,{recursive:!0})}async function Oi(e){let t=H(e.gitDir,"packed-refs");if(!await e.fs.exists(t))return new Map;let n=await e.fs.readFile(t),r=new Map;for(let o of n.split(`
|
|
29
|
+
`)){if(!o||o.startsWith("#")||o.startsWith("^"))continue;let s=o.indexOf(" ");if(s===-1)continue;let a=o.slice(0,s),i=o.slice(s+1).trim();a.length===40&&i&&r.set(i,a)}return r}function Zn(e,t){return H(e.gitDir,t)}async function Ri(e,t,n,r){let o=await e.fs.readdir(t);for(let s of o){let a=H(t,s),i=`${n}/${s}`,c=await e.fs.stat(a);if(c.isDirectory)await Ri(e,a,i,r);else if(c.isFile){let f=await F(e,i);f&&r.push({name:i,hash:f})}}}async function $n(e,t){let n=t;for(;;){let r=H(n,".git");if(await e.exists(r)&&(await e.stat(r)).isDirectory)return{fs:e,gitDir:r,workTree:n};let o=Lf(n);if(o===n)return null;n=o}}async function vr(e,t,n={}){let{bare:r=!1,initialBranch:o="main"}=n,s=r?t:H(t,".git"),a=r?null:t,i=H(s,"HEAD"),c=await e.exists(i);await e.mkdir(H(s,"objects"),{recursive:!0}),await e.mkdir(H(s,"refs","heads"),{recursive:!0}),await e.mkdir(H(s,"refs","tags"),{recursive:!0});let f={fs:e,gitDir:s,workTree:a};if(!c){await $e(f,"HEAD",`refs/heads/${o}`);let d={core:{repositoryformatversion:"0",filemode:"true",bare:r?"true":"false",...r?{}:{logallrefupdates:"true"}}};await e.writeFile(H(s,"config"),vs(d))}return{ctx:f,reinit:c}}async function In(e,t){let n=t.lastIndexOf("/");if(n>0){let r=t.slice(0,n);await e.mkdir(r,{recursive:!0})}}function Lf(e){let t=e.lastIndexOf("/");return t<=0?"/":e.slice(0,t)}function Sr(e,t){return H(e.gitDir,"logs",t)}function Gf(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],a=o[1];if(!s||!a)return null;let i=n.indexOf("<"),c=n.indexOf(">",i);if(i<0||c<0)return null;let f=n.slice(s.length+1+a.length+1,i).trim(),d=n.slice(i+1,c),u=n.slice(c+2),l=u.indexOf(" ");if(l<0)return null;let m=parseInt(u.slice(0,l),10),h=u.slice(l+1);return{oldHash:s,newHash:a,name:f,email:d,timestamp:m,tz:h,message:r}}async function Me(e,t){let n=Sr(e,t);if(!await e.fs.exists(n))return[];let r=await e.fs.readFile(n);if(!r.trim())return[];let o=[];for(let s of r.split(`
|
|
30
|
+
`)){if(!s)continue;let a=Gf(s);a&&o.push(a)}return o}function Ii(e){return`${e.oldHash} ${e.newHash} ${e.name} <${e.email}> ${e.timestamp} ${e.tz} ${e.message}`}async function Xt(e,t,n){let r=Sr(e,t);if(await In(e.fs,r),n.length===0){await e.fs.writeFile(r,"");return}let o=`${n.map(Ii).join(`
|
|
31
31
|
`)}
|
|
32
|
-
`;await e.fs.writeFile(r,o)}async function Te(e,t,n){let r=Sr(e,t);await In(e.fs,r);let o=`${
|
|
33
|
-
`;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
|
|
34
|
-
`)){let s=nd(o,t);s&&r.push(s)}return{patterns:r,src:n}}function rd(e,t){let{pattern:n,patternLen:r,nowildcardLen:o,flags:s}=t;if(o===r)return e===n;if(s&Mi){let a=n.slice(1);return e.length>=a.length&&e.endsWith(a)}return mn(n,e,2)===0}function sd(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 a=n.length;if(a>0&&(e.length<a+1||e[a]!=="/"||!e.startsWith(n)))return!1;let i=a>0?e.slice(a+1):e,c=i.length;if(s>0){if(s>c||i.slice(0,s)!==r.slice(0,s))return!1;if(o===s&&c===s)return!0}return mn(r,i,2)===0}function Ys(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&ji&&!t)){if(s.flags&Di){if(s.base&&!e.startsWith(`${s.base}/`))continue;if(rd(r,s))return s;continue}if(sd(e,s))return s}}return null}function Tt(e,t,n){for(let r=e.dirPatterns.length-1;r>=0;r--){let o=e.dirPatterns[r],s=Ys(t,n,o);if(s)return s.flags&Dr?"not-ignored":"ignored"}if(e.excludeFile){let r=Ys(t,n,e.excludeFile);if(r)return r.flags&Dr?"not-ignored":"ignored"}if(e.globalExclude){let r=Ys(t,n,e.globalExclude);if(r)return r.flags&Dr?"not-ignored":"ignored"}return"undecided"}async function Hn(e){let t={dirPatterns:[],excludeFile:null,globalExclude:null},n=v(e.gitDir,"info","exclude");try{let r=await e.fs.readFile(n);t.excludeFile=tr(r,"",n)}catch{}try{let r=await bt(e,"core.excludesFile");if(r)try{let o=await e.fs.readFile(r);t.globalExclude=tr(o,"",r)}catch{}}catch{}return t}function hn(e,t,n,r){let s=tr(t,n===""?"":n,r);return{...e,dirPatterns:[...e.dirPatterns,s]}}var od=new TextEncoder,id=new TextDecoder;async function lt(e,t){if(!e.workTree)throw new Error("Cannot diff working tree in a bare repository");let n=[];for(let s of t.entries){if(s.stage!==0)continue;let a=v(e.workTree,s.path),i;try{i=await ze(e.fs,a)}catch{i=null}if(!i){n.push({path:s.path,status:"deleted",indexHash:s.hash});continue}if(!i.isFile&&!i.isSymbolicLink)continue;await Zt(e.fs,a)!==s.hash&&n.push({path:s.path,status:"modified",indexHash:s.hash})}let r=new Set(t.entries.map(s=>s.path)),o=await _e(e,e.workTree,"");for(let s of o)r.has(s)||n.push({path:s,status:"untracked"});return n.sort((s,a)=>he(s.path,a.path))}async function ve(e,t){if(!e.workTree)throw new Error("Cannot checkout in a bare repository");let n=await ce(e,t.hash);if(n.type!=="blob")throw new Error(`Expected blob for ${t.path}, got ${n.type}`);let r=v(e.workTree,t.path),o=r.lastIndexOf("/");if(o>0&&await e.fs.mkdir(r.slice(0,o),{recursive:!0}),t.mode!=null&&Lt(t.mode)&&e.fs.symlink){await ze(e.fs,r).then(()=>!0).catch(()=>!1)&&await e.fs.rm(r,{force:!0});let a=id.decode(n.content);await e.fs.symlink(a,r)}else{if(e.fs.lstat)try{(await e.fs.lstat(r)).isSymbolicLink&&await e.fs.rm(r,{force:!0})}catch{}await e.fs.writeFile(r,n.content)}}async function Gi(e,t){let n=await He(e,t);for(let r of n)await ve(e,r)}async function Gt(e,t,n){if(!e.workTree)throw new Error("Cannot stage in a bare repository");let r=v(e.workTree,n);if(!await e.fs.exists(r))throw new Error(`Path does not exist: ${n}`);let o=await ze(e.fs,r);if(o.isSymbolicLink&&e.fs.readlink){let f=await e.fs.readlink(r),d=od.encode(f),u=await we(e,"blob",d),l={path:n,mode:40960,hash:u,stage:0,stat:{...pe(),size:d.byteLength}};return{index:Xe(t,l),hash:u}}let s=await e.fs.readFileBuffer(r),a=await we(e,"blob",s),i=o.mode!=null?ad(o.mode):33188,c={path:n,mode:i,hash:a,stage:0,stat:{...pe(),size:s.byteLength}};return{index:Xe(t,c),hash:a}}async function _e(e,t,n,r){let o=r?.skipIgnore??!1,s=null;if(!o){s=r?._ignore??await Hn(e);let c=v(t,".gitignore");try{let f=await e.fs.readFile(c);s=hn(s,f,n,c)}catch{}}let a=[],i=await e.fs.readdir(t);for(let c of i){if(n===""&&c===".git")continue;let f=v(t,c),d=n?`${n}/${c}`:c,u=await ze(e.fs,f);if(u.isSymbolicLink){if(s&&Tt(s,d,!1)==="ignored")continue;a.push(d)}else if(u.isDirectory){if(s&&Tt(s,d,!0)==="ignored")continue;let l=await _e(e,f,d,{skipIgnore:o,_ignore:s??void 0});a.push(...l)}else if(u.isFile){if(s&&Tt(s,d,!1)==="ignored")continue;a.push(d)}}return a}function ad(e){return e>511?e:e&73?33261:33188}async function pn(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),await pn(e,Pt(t),n))}function Xs(e){return e.existsOnDisk&&e.indexHash===null}async function cd(e,t,n){let r=await Promise.all(t.map(h=>se(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 a=e.workTree?new Set(await _e(e,e.workTree,"",{skipIgnore:!0})):new Set,i=null,c=async()=>(i===null&&(i=e.workTree?new Set(await _e(e,e.workTree,"")):new Set),i),f=new Set;for(let h of r)for(let p of h.keys())f.add(p);let d=new Set;for(let h of n.entries)f.has(h.path)||d.add(h.path);for(let h of a)f.has(h)||d.add(h);let u=Array.from(f).sort().concat(Array.from(d).sort()),l=(h,p)=>r[h]?.get(p),m=[];for(let h of u){let p=null,g=null,w=null,x=null,b=null;if(r.length===1){let _=l(0,h);w=_?.hash??null,b=_?.mode??null}else if(r.length===2){let _=l(0,h),G=l(1,h);g=_?.hash??null,x=_?.mode??null,w=G?.hash??null,b=G?.mode??null}else if(r.length>=3){let _=l(0,h),G=l(1,h),z=l(2,h);p=_?.hash??null,g=G?.hash??null,x=G?.mode??null,w=z?.hash??null,b=z?.mode??null}let k=o.get(h)?.hash??null,C=s.has(h)?1:0,P=a.has(h),O,E=async()=>O!==void 0?O:P?(O=!(await c()).has(h),O):(O=!1,!1),I,H=async()=>{if(I!==void 0)return I;if(!P||!e.workTree)return I=null,null;let _=v(e.workTree,h);try{I=await Zt(e.fs,_)}catch{I=null}return I};m.push({path:h,baseHash:p,headHash:g,remoteHash:w,indexHash:k,indexStage:C,existsOnDisk:P,isIgnoredOnDisk:E,getWorktreeHash:H,headMode:x,remoteMode:b})}return m}function jr(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 Lr(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 fd(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 dd(e,t,n){let r=[];if(n.reset)return r;for(let[o,s]of e){if(s.requirements.length===0)continue;let a=t.get(o);if(!a)continue;let i=fd(s,a);for(let c of s.requirements){if(n.allowStagedChanges&&c==="INDEX_MUST_MATCH_HEAD")continue;let f=await ld(c,a,i);if(f){r.push({path:o,error:f});break}}if(n.stopAtFirstError&&r.length>0)break}return r}async function ld(e,t,n,r){switch(e){case"INDEX_MUST_NOT_EXIST":return t.indexHash!==null?"WOULD_OVERWRITE":Xs(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 Xs(t)?await t.isIgnoredOnDisk()?null:"WOULD_LOSE_UNTRACKED_OVERWRITTEN":null;case"NO_UNTRACKED_REMOVED":return Xs(t)?await t.isIgnoredOnDisk()?null:"WOULD_LOSE_UNTRACKED_REMOVED":null}}function ud(e,t,n,r){let o=[],s=[],a=new Set(e.keys()),i=new Map;for(let c of n.entries)a.has(c.path)||o.push(c),c.stage===0&&i.set(c.path,c);for(let[c,f]of e){let d=t.get(c);if(d)switch(f.action){case"KEEP":{let u=i.get(c);u&&(o.push(u),r.reset&&r.updateWorktree&&s.push({path:c,type:"checkout",hash:u.hash,mode:u.mode}));break}case"TAKE":{let u=f.takeFrom==="head"?d.headHash:d.remoteHash,l=f.takeFrom==="head"?d.headMode:d.remoteMode,m=l?Number.parseInt(l,8):33188;o.push({path:c,mode:m,hash:u,stage:0,stat:pe()}),r.updateWorktree&&s.push({path:c,type:"checkout",hash:u,mode:m});break}case"DELETE":{r.updateWorktree&&d.existsOnDisk&&s.push({path:c,type:"delete"});break}case"SKIP":break}}return o.sort((c,f)=>he(c.path,f.path)||c.stage-f.stage),{newEntries:o,worktreeOps:s}}var md=[{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 Gr(e,t){let n=t.actionHint??t.operationName,r=[];for(let{error:s,msg:a,fix:i}of md){let c=e.filter(f=>f.error===s).map(f=>f.path).sort();if(c.length>0){let f=c.map(d=>` ${d}`).join(`
|
|
32
|
+
`;await e.fs.writeFile(r,o)}async function Te(e,t,n){let r=Sr(e,t);await In(e.fs,r);let o=`${Ii(n)}
|
|
33
|
+
`;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 Jn(e,t){let n=Sr(e,t);await e.fs.exists(n)&&await e.fs.rm(n)}async function ee(e,t,n,r,o,s,a=!1){let i=await Ot(e,t),c={oldHash:r??Z,newHash:o,...i,message:s};await Te(e,n,c),a&&n!=="HEAD"&&await Te(e,"HEAD",c)}function Nf(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 i=s[2]===""?1:parseInt(s[2],10);t.unshift({type:"tilde",n:i}),n=s[1].length;continue}let a=e.slice(0,n).match(/^(.+?)\^(\d*)$/);if(a&&a[1]!==void 0&&a[2]!==void 0){let i=a[2]===""?1:parseInt(a[2],10);t.unshift({type:"caret",n:i}),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}}var $i=["HEAD","FETCH_HEAD","ORIG_HEAD","MERGE_HEAD","CHERRY_PICK_HEAD","REBASE_HEAD"];async function _f(e,t){let n=t.slice(0,2),r=t.slice(2),o=H(e.gitDir,"objects",n);if(!await e.fs.exists(o))return null;let a=(await e.fs.readdir(o)).filter(i=>i.startsWith(r));if(a.length===0)return null;if(a.length>1)throw new qs(t);return`${n}${a[0]}`}var qs=class extends Error{constructor(n){super(`short object ID ${n} is ambiguous`);this.prefix=n}};async function Ff(e,t){if(t==="HEAD"||t==="@")return F(e,"HEAD");if($i.includes(t))return F(e,t);if(/^[0-9a-f]{40}$/.test(t))return await zt(e,t)?t:null;if(/^[0-9a-f]{4,39}$/.test(t)){let s=await _f(e,t);if(s)return s}if(t.startsWith("refs/")){let s=await F(e,t);if(s)return s}let n=await F(e,`refs/heads/${t}`);if(n)return n;let r=await F(e,`refs/tags/${t}`);if(r)return r;let o=await F(e,`refs/remotes/${t}`);return o||null}function Uf(e){if(e==="HEAD"||e==="@")return"HEAD";for(let t of $i)if(e===t)return t;return e.startsWith("refs/")?e:`refs/heads/${e}`}async function Bf(e,t,n){let r=Uf(t),o=await Me(e,r);if(o.length===0)return null;let s=o.length-1-n;if(s<0||s>=o.length)return null;let a=o[s];return a?a.newHash:null}async function je(e,t){let{base:n,reflogIndex:r,suffixes:o}=Nf(t),s;if(r!==void 0?s=await Bf(e,n,r):s=await Ff(e,n),!s)return null;o.length>0&&(s=await Re(e,s));for(let a of o)if(a.type==="tilde")for(let i=0;i<a.n;i++){if(!s)return null;let c=await M(e,s);if(c.parents.length===0||(s=c.parents[0]??null,!s))return null}else{if(a.n===0)continue;if(!s)return null;let i=await M(e,s);if(a.n>i.parents.length||(s=i.parents[a.n-1]??null,!s))return null}return s}function Ti(e){let t=e.indexOf(":");return t<0?null:{rev:e.slice(0,t)||"HEAD",path:e.slice(t+1)}}var Wf=new TextEncoder;function ze(e,t){return e.lstat?e.lstat(t):e.stat(t)}function Lt(e){return typeof e=="string"?e==="120000":e===40960}async function Qn(e,t){if((await ze(e,t)).isSymbolicLink&&e.readlink){let r=await e.readlink(t);return Wf.encode(r)}return e.readFileBuffer(t)}async function Zt(e,t){let n=await Qn(e,t);return st("blob",n)}var qf=new TextEncoder,Hi=new TextDecoder;function Jt(e){let t=[],n=0;for(;n<e.byteLength;){let r=e.indexOf(32,n);if(r===-1)break;let o=Hi.decode(e.subarray(n,r)),s=e.indexOf(0,r+1);if(s===-1)break;let a=Hi.decode(e.subarray(r+1,s)),i=e.subarray(s+1,s+21),c=qt(i),f=o.padStart(6,"0");t.push({mode:f,name:a,hash:c}),n=s+21}return{type:"tree",entries:t}}function Ai(e){let t=[];for(let s of e.entries){let a=s.mode.replace(/^0+/,""),i=qf.encode(`${a} ${s.name}\0`),c=ft(s.hash);t.push(i),t.push(c)}let n=t.reduce((s,a)=>s+a.byteLength,0),r=new Uint8Array(n),o=0;for(let s of t)r.set(s,o),o+=s.byteLength;return r}var er={REGULAR:"100644",EXECUTABLE:"100755",SYMLINK:"120000",DIRECTORY:"040000",SUBMODULE:"160000"};async function ke(e,t){return vi(e,t,"")}async function vi(e,t,n){let r=[],o=new Map;for(let a of t){let i=n?a.path.slice(n.length+1):a.path,c=i.indexOf("/");if(c===-1)r.push({mode:Kf(a.mode),name:i,hash:a.hash});else{let f=i.slice(0,c),d=o.get(f);d||(d=[],o.set(f,d)),d.push(a)}}for(let[a,i]of o){let c=n?`${n}/${a}`:a,f=await vi(e,i,c);r.push({mode:er.DIRECTORY,name:a,hash:f})}r.sort((a,i)=>{let c=a.mode===er.DIRECTORY?`${a.name}/`:a.name,f=i.mode===er.DIRECTORY?`${i.name}/`:i.name;return c<f?-1:c>f?1:0});let s=Ai({type:"tree",entries:r});return we(e,"tree",s)}async function He(e,t,n=""){let r=await ce(e,t);if(r.type!=="tree")throw new Error(`Expected tree object, got ${r.type}`);let o=Jt(r.content),s=[];for(let a of o.entries){let i=n?`${n}/${a.name}`:a.name;if(a.mode===er.DIRECTORY){let c=await He(e,a.hash,i);s.push(...c)}else s.push({path:i,mode:a.mode,hash:a.hash})}return s}async function se(e,t){if(!t)return new Map;let n=await He(e,t);return new Map(n.map(r=>[r.path,r]))}async function Ae(e,t,n){let r=await se(e,t),o=await se(e,n),s=[];for(let[a,i]of r){let c=o.get(a);c?(i.hash!==c.hash||i.mode!==c.mode)&&s.push({path:a,status:"modified",oldHash:i.hash,newHash:c.hash,oldMode:i.mode,newMode:c.mode}):s.push({path:a,status:"deleted",oldHash:i.hash,oldMode:i.mode})}for(let[a,i]of o)r.has(a)||s.push({path:a,status:"added",newHash:i.hash,newMode:i.mode});return s.sort((a,i)=>he(a.path,i.path))}function Kf(e){return e.toString(8).padStart(6,"0")}function Si(e){return/^[a-zA-Z0-9]$/.test(e)}function zf(e){return/^[a-zA-Z]$/.test(e)}function Vf(e){return e>="0"&&e<="9"}function Ks(e){return e>="A"&&e<="Z"}function zs(e){return e>="a"&&e<="z"}function Di(e){return/^\s$/.test(e)}function Yf(e){return e===" "||e===" "}function Ys(e){let t=e.charCodeAt(0);return t>=32&&t<=126}function Xf(e){return Ys(e)&&!Di(e)}function Zf(e){return Ys(e)&&!Si(e)&&e!==" "}function Jf(e){let t=e.charCodeAt(0);return t<32||t===127}function Qf(e){return/^[0-9a-fA-F]$/.test(e)}function tr(e,t,n){return n?e.toLowerCase()===t.toLowerCase():e===t}function Vs(e,t,n,r,o){let s=(o&1)!==0,a=(o&2)!==0;for(;t<e.length;){let i=e[t];if(r>=n.length&&i!=="*")return-1;let c=r<n.length?n[r]:"";switch(i){case"\\":{if(t++,t>=e.length)return-1;if(!tr(n[r],e[t],s))return 1;r++,t++;break}case"?":{if(a&&c==="/")return 1;r++,t++;break}case"*":{let f;if(t++,t<e.length&&e[t]==="*"){let d=t;for(;t<e.length&&e[t]==="*";)t++;if(!a)f=!0;else if((d-1<1||e[d-2]==="/")&&(t>=e.length||e[t]==="/"||e[t]==="\\"&&t+1<e.length&&e[t+1]==="/")){if(t<e.length&&e[t]==="/"&&Vs(e,t+1,n,r,o)===0)return 0;f=!0}else f=!1}else f=!a;if(t>=e.length)return!f&&n.indexOf("/",r)!==-1?-2:0;if(!f&&e[t]==="/"){let d=n.indexOf("/",r);if(d===-1)return-1;r=d+1,t++;break}for(;!(r>=n.length);){if(!ed(e[t])){let u=s?e[t].toLowerCase():e[t];for(;r<n.length&&(f||n[r]!=="/")&&(s?n[r].toLowerCase():n[r])!==u;)r++;if(r>=n.length||!f&&n[r]==="/")return r<n.length&&!f&&n[r]==="/"?-2:f?-1:-2}let d=Vs(e,t,n,r,o);if(d!==1){if(!f||d!==-2)return d}else if(!f&&n[r]==="/")return-2;r++}return-1}case"[":{if(a&&c==="/")return 1;if(t++,t>=e.length)return-1;let f=!1;(e[t]==="!"||e[t]==="^")&&(f=!0,t++);let d=!1,u="",l=!0;for(;t<e.length&&(l||e[t]!=="]");){l=!1;let m=e[t];if(m==="\\"){if(t++,t>=e.length)return-1;m=e[t],tr(c,m,s)&&(d=!0)}else if(m==="-"&&u&&t+1<e.length&&e[t+1]!=="]"){if(t++,m=e[t],m==="\\"){if(t++,t>=e.length)return-1;m=e[t]}let h=u,p=m;if(c>=h&&c<=p&&(d=!0),s){if(zs(c)){let g=c.toUpperCase();g>=h&&g<=p&&(d=!0)}else if(Ks(c)){let g=c.toLowerCase();g>=h&&g<=p&&(d=!0)}}m=""}else if(m==="["&&t+1<e.length&&e[t+1]===":"){t+=2;let h=t;for(;t<e.length&&e[t]!=="]";)t++;if(t>=e.length)return-1;let p=t-h-1;if(p<0||e[t-1]!==":")t=h-2,m="[",tr(c,m,s)&&(d=!0);else{let g=e.slice(h,h+p);td(g,c,s)&&(d=!0),m=""}}else tr(c,m,s)&&(d=!0);u=m,t++}if(t>=e.length)return-1;if(t++,d===f)return 1;r++;break}default:{if(!tr(c,i,s))return 1;r++,t++;break}}}return r>=n.length?0:1}function ed(e){return e==="*"||e==="?"||e==="["||e==="\\"}function td(e,t,n){switch(e){case"alnum":return Si(t);case"alpha":return zf(t);case"blank":return Yf(t);case"cntrl":return Jf(t);case"digit":return Vf(t);case"graph":return Xf(t);case"lower":return zs(t)||n&&Ks(t);case"print":return Ys(t);case"punct":return Zf(t);case"space":return Di(t);case"upper":return Ks(t)||n&&zs(t);case"xdigit":return Qf(t);default:return!1}}function mn(e,t,n=0){return Vs(e,0,t,0,n)===0?0:1}var Mi=1,ji=4,Li=8,Dr=16;function Gi(e){for(let t=0;t<e.length;t++){let n=e[t];if(n==="\\"){t++;continue}if(n==="*"||n==="?"||n==="[")return t}return e.length}function nd(e){return Gi(e)===e.length}function rd(e,t){let n=e;for(;n.length>0;){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|=Dr,o=o.slice(1)),o.length===0)return null;let s=o.length;o[s-1]==="/"&&(s--,o=o.slice(0,s),r|=Li);let a=!1;for(let c=0;c<s;c++)if(o[c]==="/"){a=!0;break}a||(r|=Mi);let i=Math.min(Gi(o),s);return o[0]==="*"&&nd(o.slice(1))&&(r|=ji),{pattern:o,patternLen:s,nowildcardLen:i,flags:r,base:t}}function nr(e,t,n){let r=[];for(let o of e.split(`
|
|
34
|
+
`)){let s=rd(o,t);s&&r.push(s)}return{patterns:r,src:n}}function sd(e,t){let{pattern:n,patternLen:r,nowildcardLen:o,flags:s}=t;if(o===r)return e===n;if(s&ji){let a=n.slice(1);return e.length>=a.length&&e.endsWith(a)}return mn(n,e,2)===0}function od(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 a=n.length;if(a>0&&(e.length<a+1||e[a]!=="/"||!e.startsWith(n)))return!1;let i=a>0?e.slice(a+1):e,c=i.length;if(s>0){if(s>c||i.slice(0,s)!==r.slice(0,s))return!1;if(o===s&&c===s)return!0}return mn(r,i,2)===0}function Xs(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&Li&&!t)){if(s.flags&Mi){if(s.base&&!e.startsWith(`${s.base}/`))continue;if(sd(r,s))return s;continue}if(od(e,s))return s}}return null}function Tt(e,t,n){for(let r=e.dirPatterns.length-1;r>=0;r--){let o=e.dirPatterns[r],s=Xs(t,n,o);if(s)return s.flags&Dr?"not-ignored":"ignored"}if(e.excludeFile){let r=Xs(t,n,e.excludeFile);if(r)return r.flags&Dr?"not-ignored":"ignored"}if(e.globalExclude){let r=Xs(t,n,e.globalExclude);if(r)return r.flags&Dr?"not-ignored":"ignored"}return"undecided"}async function Hn(e){let t={dirPatterns:[],excludeFile:null,globalExclude:null},n=H(e.gitDir,"info","exclude");try{let r=await e.fs.readFile(n);t.excludeFile=nr(r,"",n)}catch{}try{let r=await bt(e,"core.excludesFile");if(r)try{let o=await e.fs.readFile(r);t.globalExclude=nr(o,"",r)}catch{}}catch{}return t}function hn(e,t,n,r){let s=nr(t,n===""?"":n,r);return{...e,dirPatterns:[...e.dirPatterns,s]}}var id=new TextEncoder,ad=new TextDecoder;async function lt(e,t){if(!e.workTree)throw new Error("Cannot diff working tree in a bare repository");let n=[];for(let s of t.entries){if(s.stage!==0)continue;let a=H(e.workTree,s.path),i;try{i=await ze(e.fs,a)}catch{i=null}if(!i){n.push({path:s.path,status:"deleted",indexHash:s.hash});continue}if(!i.isFile&&!i.isSymbolicLink)continue;await Zt(e.fs,a)!==s.hash&&n.push({path:s.path,status:"modified",indexHash:s.hash})}let r=new Set(t.entries.map(s=>s.path)),o=await _e(e,e.workTree,"");for(let s of o)r.has(s)||n.push({path:s,status:"untracked"});return n.sort((s,a)=>he(s.path,a.path))}async function ve(e,t){if(!e.workTree)throw new Error("Cannot checkout in a bare repository");let n=await ce(e,t.hash);if(n.type!=="blob")throw new Error(`Expected blob for ${t.path}, got ${n.type}`);let r=H(e.workTree,t.path),o=r.lastIndexOf("/");if(o>0&&await e.fs.mkdir(r.slice(0,o),{recursive:!0}),t.mode!=null&&Lt(t.mode)&&e.fs.symlink){await ze(e.fs,r).then(()=>!0).catch(()=>!1)&&await e.fs.rm(r,{force:!0});let a=ad.decode(n.content);await e.fs.symlink(a,r)}else{if(e.fs.lstat)try{(await e.fs.lstat(r)).isSymbolicLink&&await e.fs.rm(r,{force:!0})}catch{}await e.fs.writeFile(r,n.content)}}async function Ni(e,t){let n=await He(e,t);for(let r of n)await ve(e,r)}async function Gt(e,t,n){if(!e.workTree)throw new Error("Cannot stage in a bare repository");let r=H(e.workTree,n);if(!await e.fs.exists(r))throw new Error(`Path does not exist: ${n}`);let o=await ze(e.fs,r);if(o.isSymbolicLink&&e.fs.readlink){let f=await e.fs.readlink(r),d=id.encode(f),u=await we(e,"blob",d),l={path:n,mode:40960,hash:u,stage:0,stat:{...pe(),size:d.byteLength}};return{index:Xe(t,l),hash:u}}let s=await e.fs.readFileBuffer(r),a=await we(e,"blob",s),i=o.mode!=null?cd(o.mode):33188,c={path:n,mode:i,hash:a,stage:0,stat:{...pe(),size:s.byteLength}};return{index:Xe(t,c),hash:a}}async function _e(e,t,n,r){let o=r?.skipIgnore??!1,s=null;if(!o){s=r?._ignore??await Hn(e);let c=H(t,".gitignore");try{let f=await e.fs.readFile(c);s=hn(s,f,n,c)}catch{}}let a=[],i=await e.fs.readdir(t);for(let c of i){if(n===""&&c===".git")continue;let f=H(t,c),d=n?`${n}/${c}`:c,u=await ze(e.fs,f);if(u.isSymbolicLink){if(s&&Tt(s,d,!1)==="ignored")continue;a.push(d)}else if(u.isDirectory){if(s&&Tt(s,d,!0)==="ignored")continue;let l=await _e(e,f,d,{skipIgnore:o,_ignore:s??void 0});a.push(...l)}else if(u.isFile){if(s&&Tt(s,d,!1)==="ignored")continue;a.push(d)}}return a}function cd(e){return e>511?e:e&73?33261:33188}async function pn(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),await pn(e,Pt(t),n))}function Zs(e){return e.existsOnDisk&&e.indexHash===null}async function fd(e,t,n){let r=await Promise.all(t.map(h=>se(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 a=e.workTree?new Set(await _e(e,e.workTree,"",{skipIgnore:!0})):new Set,i=null,c=async()=>(i===null&&(i=e.workTree?new Set(await _e(e,e.workTree,"")):new Set),i),f=new Set;for(let h of r)for(let p of h.keys())f.add(p);let d=new Set;for(let h of n.entries)f.has(h.path)||d.add(h.path);for(let h of a)f.has(h)||d.add(h);let u=Array.from(f).sort().concat(Array.from(d).sort()),l=(h,p)=>r[h]?.get(p),m=[];for(let h of u){let p=null,g=null,w=null,x=null,b=null;if(r.length===1){let _=l(0,h);w=_?.hash??null,b=_?.mode??null}else if(r.length===2){let _=l(0,h),G=l(1,h);g=_?.hash??null,x=_?.mode??null,w=G?.hash??null,b=G?.mode??null}else if(r.length>=3){let _=l(0,h),G=l(1,h),z=l(2,h);p=_?.hash??null,g=G?.hash??null,x=G?.mode??null,w=z?.hash??null,b=z?.mode??null}let k=o.get(h)?.hash??null,C=s.has(h)?1:0,P=a.has(h),O,E=async()=>O!==void 0?O:P?(O=!(await c()).has(h),O):(O=!1,!1),I,A=async()=>{if(I!==void 0)return I;if(!P||!e.workTree)return I=null,null;let _=H(e.workTree,h);try{I=await Zt(e.fs,_)}catch{I=null}return I};m.push({path:h,baseHash:p,headHash:g,remoteHash:w,indexHash:k,indexStage:C,existsOnDisk:P,isIgnoredOnDisk:E,getWorktreeHash:A,headMode:x,remoteMode:b})}return m}function jr(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 Lr(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 dd(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 ld(e,t,n){let r=[];if(n.reset)return r;for(let[o,s]of e){if(s.requirements.length===0)continue;let a=t.get(o);if(!a)continue;let i=dd(s,a);for(let c of s.requirements){if(n.allowStagedChanges&&c==="INDEX_MUST_MATCH_HEAD")continue;let f=await ud(c,a,i);if(f){r.push({path:o,error:f});break}}if(n.stopAtFirstError&&r.length>0)break}return r}async function ud(e,t,n,r){switch(e){case"INDEX_MUST_NOT_EXIST":return t.indexHash!==null?"WOULD_OVERWRITE":Zs(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 Zs(t)?await t.isIgnoredOnDisk()?null:"WOULD_LOSE_UNTRACKED_OVERWRITTEN":null;case"NO_UNTRACKED_REMOVED":return Zs(t)?await t.isIgnoredOnDisk()?null:"WOULD_LOSE_UNTRACKED_REMOVED":null}}function md(e,t,n,r){let o=[],s=[],a=new Set(e.keys()),i=new Map;for(let c of n.entries)a.has(c.path)||o.push(c),c.stage===0&&i.set(c.path,c);for(let[c,f]of e){let d=t.get(c);if(d)switch(f.action){case"KEEP":{let u=i.get(c);u&&(o.push(u),r.reset&&r.updateWorktree&&s.push({path:c,type:"checkout",hash:u.hash,mode:u.mode}));break}case"TAKE":{let u=f.takeFrom==="head"?d.headHash:d.remoteHash,l=f.takeFrom==="head"?d.headMode:d.remoteMode,m=l?Number.parseInt(l,8):33188;o.push({path:c,mode:m,hash:u,stage:0,stat:pe()}),r.updateWorktree&&s.push({path:c,type:"checkout",hash:u,mode:m});break}case"DELETE":{r.updateWorktree&&d.existsOnDisk&&s.push({path:c,type:"delete"});break}case"SKIP":break}}return o.sort((c,f)=>he(c.path,f.path)||c.stage-f.stage),{newEntries:o,worktreeOps:s}}var hd=[{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 Gr(e,t){let n=t.actionHint??t.operationName,r=[];for(let{error:s,msg:a,fix:i}of hd){let c=e.filter(f=>f.error===s).map(f=>f.path).sort();if(c.length>0){let f=c.map(d=>` ${d}`).join(`
|
|
35
35
|
`);r.push(`${a(t.operationName)}
|
|
36
36
|
${f}
|
|
37
37
|
${i(n)}
|
|
38
38
|
`)}}return{stdout:"",stderr:r.length>0?`${r.join("")}Aborting
|
|
39
|
-
`:"",exitCode:t.errorExitCode}}async function gn(e,t,n,r){let o=await
|
|
39
|
+
`:"",exitCode:t.errorExitCode}}async function gn(e,t,n,r){let o=await fd(e,t,n),s=new Map(o.map(d=>[d.path,d])),a=new Map;for(let d of o){let u=r.mergeFn(d,r);a.set(d.path,u)}let i=await ld(a,s,r);if(i.length>0)return{success:!1,newEntries:[],worktreeOps:[],errors:i,errorOutput:Gr(i,r)};let{newEntries:c,worktreeOps:f}=md(a,s,n,r);return{success:!0,newEntries:c,worktreeOps:f,errors:[],errorOutput:null}}async function be(e,t){if(!e.workTree)return;let n=e.workTree,r=[];for(let o of t){let s=H(n,o.path);o.type==="delete"?await ze(e.fs,s).then(()=>!0).catch(()=>!1)&&(await e.fs.rm(s),r.push(s)):o.type==="checkout"&&o.hash&&await ve(e,{path:o.path,hash:o.hash,mode:o.mode})}for(let o of r)await pn(e.fs,Pt(o),n)}async function Qt(e,t,n,r){return gn(e,[{label:"current",treeHash:t},{label:"target",treeHash:n}],r,{mergeFn:Lr,updateWorktree:!0,reset:!1,errorExitCode:1,operationName:"checkout",actionHint:"switch branches"})}async function _i(e,t,n,r){return gn(e,[{label:"HEAD",treeHash:t},{label:"target",treeHash:n}],r,{mergeFn:Lr,updateWorktree:!0,reset:!1,errorExitCode:1,operationName:"merge"})}async function yt(e,t,n){return gn(e,[{label:"target",treeHash:t}],n,{mergeFn:jr,updateWorktree:!0,reset:!0,errorExitCode:128,operationName:"reset"})}async function Fi(e,t,n,r){let o=new Set;for(let i of n.entries)i.stage>0&&o.add(i.path);let s={version:n.version,entries:xe(n)},a=await gn(e,[{label:"ORIG_HEAD",treeHash:t}],s,{mergeFn:jr,updateWorktree:!0,reset:!1,errorExitCode:128,operationName:"merge",stopAtFirstError:!0,strippedConflictPaths:o});if(!a.success){let i=r??"HEAD",c=[];for(let f of a.errors)f.error==="NOT_UPTODATE_FILE"?c.push(`error: Entry '${f.path}' not uptodate. Cannot merge.
|
|
40
40
|
`):f.error==="WOULD_LOSE_UNTRACKED_OVERWRITTEN"&&c.push(`error: Untracked working tree file '${f.path}' would be overwritten by merge.
|
|
41
41
|
`);return c.length>0&&(a.errorOutput=j(c.join("")+`fatal: Could not reset index file to revision '${i}'.
|
|
42
42
|
`,128)),a}if(e.workTree&&o.size>0){let i=await se(e,t),c=new Set(a.newEntries.map(f=>f.path));for(let f of o)!i.has(f)&&!c.has(f)&&a.worktreeOps.push({path:f,type:"delete"})}return a}function T(e){return{stdout:"",stderr:`fatal: ${e}
|
|
43
|
-
`,exitCode:128}}function j(e,t=1){return{stdout:"",stderr:e,exitCode:t}}var
|
|
43
|
+
`,exitCode:128}}function j(e,t=1){return{stdout:"",stderr:e,exitCode:t}}var pd=T("not a git repository (or any of the parent directories): .git"),gd=T("this operation must be run in a work tree");async function B(e,t,n){let r=await $n(e,t);return r?n?{...r,...n}:r:pd}function S(e){return typeof e=="object"&&e!==null&&"exitCode"in e}function Fe(e){return e.workTree?null:gd}async function Se(e){let t=await X(e);return t||T("your current branch does not have any commits yet")}function Nt(e,t,n=`fatal: Exiting because of an unresolved conflict.
|
|
44
44
|
`){return dt(e)?j(`error: ${t} is not possible because you have unmerged files.
|
|
45
45
|
hint: Fix them up in the work tree, and then use 'git add/rm <file>'
|
|
46
46
|
hint: as appropriate to mark resolution and make a commit.
|
|
47
|
-
`+n,128):null}async function An(e,t,n){let r=await je(e,t);return r||T(n??`bad revision '${t}'`)}async function ye(e,t,n){let r=await je(e,t);if(!r)return T(n??`bad revision '${t}'`);try{let o=await Re(e,r),s=await M(e,o);return{hash:o,commit:s}}catch{return T(n??`bad revision '${t}'`)}}async function Le(e,t){try{return await
|
|
47
|
+
`+n,128):null}async function An(e,t,n){let r=await je(e,t);return r||T(n??`bad revision '${t}'`)}async function ye(e,t,n){let r=await je(e,t);if(!r)return T(n??`bad revision '${t}'`);try{let o=await Re(e,r),s=await M(e,o);return{hash:o,commit:s}}catch{return T(n??`bad revision '${t}'`)}}async function Le(e,t){try{return await Kn(e,t)}catch(n){return T(n.message)}}async function Ht(e,t){try{return await Cr(e,t)}catch(n){return T(n.message)}}function vn(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}function he(e,t){return e<t?-1:e>t?1:0}function Ze(e,t){return e.workTree?Ke(e.workTree,t):""}function K(e){return e.slice(0,7)}function ue(e){let t=e.indexOf(`
|
|
48
48
|
`);return t===-1?e:e.slice(0,t)}function Et(e){return T(`ambiguous argument '${e}': unknown revision or path not in the working tree.
|
|
49
49
|
Use '--' to separate paths from revisions, like this:
|
|
50
|
-
'git <command> [<revision>...] -- [<file>...]'`)}function ut(e,t,n,r=!1){return`[${e}${r?" (root-commit)":""} ${K(t)}] ${ue(n)}`}async function en(e,t,n){if(!await F(e,n.operationRef))return n.noOpError;let o=await F(e,"ORIG_HEAD");if(!o)return T(`There is no ${n.operationName} to abort (ORIG_HEAD missing).`);let s=await X(e),a=await M(e,o),i=await U(e),c=await
|
|
50
|
+
'git <command> [<revision>...] -- [<file>...]'`)}function ut(e,t,n,r=!1){return`[${e}${r?" (root-commit)":""} ${K(t)}] ${ue(n)}`}async function en(e,t,n){if(!await F(e,n.operationRef))return n.noOpError;let o=await F(e,"ORIG_HEAD")??await X(e);if(!o)return T(`There is no ${n.operationName} to abort (ORIG_HEAD missing).`);let s=await X(e),a=await M(e,o),i=await U(e),c=await Fi(e,a.tree,i,n.origHeadAsTargetRev?o:void 0);if(!c.success)return c.errorOutput;if(await Yt(e,o),await re(e,{version:2,entries:c.newEntries}),await be(e,c.worktreeOps),s&&((await J(e))?.type==="symbolic"||s!==o)){let u=n.origHeadAsTargetRev?o:"HEAD";await ee(e,t,"HEAD",s,o,`reset: moving to ${u}`)}return await n.clearState(e),{stdout:"",stderr:"",exitCode:0}}async function Je(e,t,n,r,o,s){let a=$t({type:"commit",tree:t,parents:n,author:r,committer:o,message:s}),i=await we(e,"commit",a);return await Yt(e,i),i}function rr(e){return e.split(`
|
|
51
51
|
`).filter(t=>!t.startsWith("#")).join(`
|
|
52
52
|
`).replace(/\n+$/,`
|
|
53
53
|
`)}function mt(e){return e.endsWith(`
|
|
54
54
|
`)?e:`${e}
|
|
55
|
-
`}var _r=1,
|
|
56
|
-
Maybe you wanted to say 'git add .'?`,exitCode:0};let d=await U(s),u=[],l=[];for(let p of f)Ve(p)?l.push(p):u.push(p);let m=[];for(let p of u){let g=ct(r.cwd,p),w=Ke(i,g);if((w==="."||w==="")&&(w=""),w.startsWith(".."))return T(`'${p}' is outside repository at '${i}'`);if(await r.fs.exists(g)){if(!n.force&&w!==""){let y=d.entries.some(C=>C.path===w||C.path.startsWith(`${w}/`)),k=await
|
|
55
|
+
`}var _r=1,Js=2,Nr=4,Qs=8,sr=16,Ui=new Set(["*","?","[","\\"]),bd={glob:_r,literal:Js,icase:Nr,top:Qs,exclude:sr};function Ve(e){for(let t=0;t<e.length;t++)if(Ui.has(e[t]))return!0;return!1}function yd(e){for(let t=0;t<e.length;t++)if(Ui.has(e[t]))return t;return e.length}function Ed(e){let t=e.split("/"),n=[];for(let r of t)if(!(r===""||r===".")){if(r===".."){n.length>0&&n[n.length-1]!==".."&&n.pop();continue}n.push(r)}return n.join("/")}function Oe(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 d of f.split(",")){let u=bd[d.trim()];u!==void 0&&(n|=u)}}}else r.startsWith(":/")?(n|=Qs,r=r.slice(2)):(r.startsWith(":!")||r.startsWith(":^"))&&(n|=sr,r=r.slice(2));n&Js&&n&_r&&(n&=~_r);let o;n&Qs||t===""?o=r:o=Ed(`${t}/${r}`);let s=!!(n&Js),a=s?!1:Ve(o),i=s?o.length:yd(o);return{original:e,pattern:o,magic:n,hasWildcard:a,nowildcardLen:i}}function Fr(e,t){let{pattern:n,hasWildcard:r,magic:o,nowildcardLen:s}=e;if(n==="")return!0;if(!r){let i=!!(o&Nr),c=i?n.toLowerCase():n,f=i?t.toLowerCase():t;return!!(c===f||f.startsWith(c)&&f[c.length]==="/"||c.endsWith("/")&&f.startsWith(c))}if(s>0){let i=n.slice(0,s),c=t.slice(0,s);if(o&Nr){if(i.toLowerCase()!==c.toLowerCase())return!1}else if(i!==c)return!1}let a=0;return o&_r&&(a|=2),o&Nr&&(a|=1),mn(n,t,a)===0}function me(e,t){let n=!1,r=!1;for(let o of e)o.magic&sr?Fr(o,t)&&(r=!0):Fr(o,t)&&(n=!0);return n&&!r}function Wi(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:v().alias("A").describe("Add changes from all tracked and untracked files"),force:v().alias("f").describe("Allow adding otherwise ignored files"),update:v().alias("u").describe("Update tracked files"),"dry-run":v().alias("n").describe("Don't actually add the file(s)")},handler:async(n,r)=>{let o=await B(r.fs,r.cwd,t);if(S(o))return o;let s=o,a=Fe(s);if(a)return a;let i=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 U(s);return p=await Bi(s,p,i,"",c),n["dry-run"]||await re(s,p),{stdout:c.actions?c.actions.join(""):"",stderr:"",exitCode:0}}if(f.length===0)return{stdout:"",stderr:`Nothing specified, nothing added.
|
|
56
|
+
Maybe you wanted to say 'git add .'?`,exitCode:0};let d=await U(s),u=[],l=[];for(let p of f)Ve(p)?l.push(p):u.push(p);let m=[];for(let p of u){let g=ct(r.cwd,p),w=Ke(i,g);if((w==="."||w==="")&&(w=""),w.startsWith(".."))return T(`'${p}' is outside repository at '${i}'`);if(await r.fs.exists(g)){if(!n.force&&w!==""){let y=d.entries.some(C=>C.path===w||C.path.startsWith(`${w}/`)),k=await kd(s,i,w,y);if(k){m.push(k);continue}}if((await r.fs.stat(g)).isDirectory)d=await Bi(s,d,g,w,c);else{let y=d.entries.find(C=>C.path===w&&C.stage===0)?.hash,k=await Gt(s,d,w);d=k.index,c.actions&&k.hash!==y&&c.actions.push(`add '${w}'
|
|
57
57
|
`)}}else if(d.entries.some(y=>y.path===w||y.path.startsWith(`${w}/`))){if(c.actions)for(let y of d.entries)(y.path===w||y.path.startsWith(`${w}/`))&&c.actions.push(`remove '${y.path}'
|
|
58
58
|
`);d={...d,entries:d.entries.filter(y=>y.path!==w&&!y.path.startsWith(`${w}/`))}}else return T(`pathspec '${p}' did not match any files`)}if(m.length>0)return j(`The following paths are ignored by one of your .gitignore files:
|
|
59
59
|
${m.join(`
|
|
60
60
|
`)}
|
|
61
61
|
hint: Use -f if you really want to add them.
|
|
62
62
|
hint: Disable this message with "git config set advice.addIgnoredFile false"
|
|
63
|
-
`);if(l.length>0){let p=await
|
|
63
|
+
`);if(l.length>0){let p=await xd(s,r.cwd,d,l,c);if(p.error)return p.error;d=p.index}return n["dry-run"]||await re(s,d),{stdout:c.actions?c.actions.join(""):"",stderr:"",exitCode:0}}})}async function xd(e,t,n,r,o){let s=e.workTree,a=Ze(e,t),i=r.map(u=>Oe(u,a)),c=new Array(i.length).fill(!1),f=u=>{for(let l=0;l<i.length;l++)i[l].hasWildcard&&Fr(i[l],u)&&(c[l]=!0)},d=[];for(let u of n.entries){if(u.stage>0||!me(i,u.path))continue;f(u.path);let l=H(s,u.path);if(await e.fs.exists(l)){let m=await Gt(e,n,u.path);n=m.index,o?.actions&&m.hash!==u.hash&&o.actions.push(`add '${u.path}'
|
|
64
64
|
`)}else o?.actions&&o.actions.push(`remove '${u.path}'
|
|
65
65
|
`),d.push(u.path)}for(let u of d)n=Ne(n,u);if(!o?.updateOnly){let u=new Set(n.entries.map(m=>m.path)),l=await _e(e,s,"",{skipIgnore:o?.skipIgnore});for(let m of l){if(u.has(m)||!me(i,m))continue;f(m),o?.actions&&o.actions.push(`add '${m}'
|
|
66
|
-
`),n=(await Gt(e,n,m)).index}}for(let u=0;u<i.length;u++){let l=i[u];if(!c[u]&&!(l.magic&
|
|
66
|
+
`),n=(await Gt(e,n,m)).index}}for(let u=0;u<i.length;u++){let l=i[u];if(!c[u]&&!(l.magic&sr))return{index:n,error:T(`pathspec '${l.original}' did not match any files`)}}return{index:n}}async function Bi(e,t,n,r,o){let s=r===""?"":`${r}/`,a=e.workTree,i=[],c=new Set;for(let f of t.entries){if(!(s===""||f.path.startsWith(s))||c.has(f.path))continue;c.add(f.path);let d=H(a,f.path);if(await e.fs.exists(d)){let u=f.stage>0,l=await Gt(e,t,f.path);t=l.index,o?.actions&&(u||l.hash!==f.hash)&&o.actions.push(`add '${f.path}'
|
|
67
67
|
`)}else o?.actions&&o.actions.push(`remove '${f.path}'
|
|
68
68
|
`),i.push(f.path)}for(let f of i)t=Ne(t,f);if(!o?.updateOnly){let f=new Set(t.entries.map(u=>u.path)),d=await _e(e,n,r===""?"":r,{skipIgnore:o?.skipIgnore});for(let u of d){if(f.has(u))continue;o?.actions&&o.actions.push(`add '${u}'
|
|
69
|
-
`),t=(await Gt(e,t,u)).index}}return t}async function
|
|
69
|
+
`),t=(await Gt(e,t,u)).index}}return t}async function kd(e,t,n,r){let o=await Hn(e);try{let a=await e.fs.readFile(H(t,".gitignore"));o=hn(o,a,"",H(t,".gitignore"))}catch{}let s=n.split("/");for(let a=0;a<s.length-1;a++){let i=s.slice(0,a+1).join("/"),c=H(t,i);if(Tt(o,i,!0)==="ignored")return i;try{let f=await e.fs.readFile(H(c,".gitignore"));o=hn(o,f,i,H(c,".gitignore"))}catch{}}if(!r){let a=await e.fs.stat(H(t,n)).then(i=>i.isDirectory).catch(()=>!1);if(Tt(o,n,a)==="ignored")return n}return null}function nn(e){if(e.length===0)return[];let t=e.split(`
|
|
70
70
|
`);return t[t.length-1]===""&&t.pop(),t}function rn(e){if(e.length===0)return[];let t=[],n=0;for(let r=0;r<e.length;r++)e[r]===`
|
|
71
|
-
`&&(t.push(e.slice(n,r+1)),n=r+1);return n<e.length&&t.push(e.slice(n)),t}var
|
|
71
|
+
`&&(t.push(e.slice(n,r+1)),n=r+1);return n<e.length&&t.push(e.slice(n)),t}var Cd=4,qi=1024,Ur=100,qr=0,Br=1,Sn=2;function to(e){let t=1;for(;t*t<e;)t++;return t}function Pd(e,t){let n=new Map,r=[],o=new Array(e.length),s=new Array(t.length);for(let a=0;a<e.length;a++){let i=e[a],c=n.get(i);c===void 0&&(c=r.length,n.set(i,c),r.push({len1:0,len2:0})),r[c].len1++,o[a]=c}for(let a=0;a<t.length;a++){let i=t[a],c=n.get(i);c===void 0&&(c=r.length,n.set(i,c),r.push({len1:0,len2:0})),r[c].len2++,s[a]=c}return{classes1:o,classes2:s,classInfo:r}}function Od(e,t,n,r){let o=0,s=Math.min(t,r);for(;o<s&&e[o]===n[o];)o++;let a=o,i=0,c=s-a;for(;i<c&&e[t-1-i]===n[r-1-i];)i++;return{dstart:a,dend1:t-i-1,dend2:r-i-1}}function Ki(e,t,n,r){t-n>Ur&&(n=t-Ur),r-t>Ur&&(r=t+Ur);let o=0,s=1;for(let c=1;t-c>=n;c++){let f=e[t-c];if(f===qr)o++;else if(f===Sn)s++;else break}if(o===0)return!1;let a=0,i=1;for(let c=1;t+c<=r;c++){let f=e[t+c];if(f===qr)a++;else if(f===Sn)i++;else break}return a===0?!1:(a+=o,i+=s,i*Cd<i+a)}function Rd(e,t,n,r,o,s,a,i,c,f){let d=new Uint8Array(t),u=new Uint8Array(r),l=Math.min(to(t),qi);for(let g=s;g<=a;g++){let w=o[e[g]].len2;w===0?d[g]=qr:w>=l?d[g]=Sn:d[g]=Br}let m=Math.min(to(r),qi);for(let g=s;g<=i;g++){let w=o[n[g]].len1;w===0?u[g]=qr:w>=m?u[g]=Sn:u[g]=Br}let h=[];for(let g=s;g<=a;g++)d[g]===Br||d[g]===Sn&&!Ki(d,g,s,a)?h.push(g):c[g]=1;let p=[];for(let g=s;g<=i;g++)u[g]===Br||u[g]===Sn&&!Ki(u,g,s,i)?p.push(g):f[g]=1;return{refIndex1:h,nreff1:h.length,refIndex2:p,nreff2:p.length}}var tn=20,zi=4,Id=256,$d=256,Wr=2147483647;function Qe(e,t){return e[t]??0}function Td(e,t,n,r,o,s,a,i,c,f){let d=t-s,u=n-o,l=t-o,m=n-s,h=l-m&1,p=l,g=l,w=m,x=m;a[l]=t,i[m]=n;for(let b=1;;b++){let y=!1;p>d?a[--p-1]=-1:++p,g<u?a[++g+1]=-1:--g;for(let k=g;k>=p;k-=2){let C;Qe(a,k-1)>=Qe(a,k+1)?C=Qe(a,k-1)+1:C=Qe(a,k+1);let P=C,O=C-k;for(;C<n&&O<s&&e[C]===r[O];)C++,O++;if(C-P>tn&&(y=!0),a[k]=C,h&&w<=k&&k<=x&&Qe(i,k)<=C)return{i1:C,i2:O,minLo:!0,minHi:!0}}w>d?i[--w-1]=Wr:++w,x<u?i[++x+1]=Wr:--x;for(let k=x;k>=w;k-=2){let C;Qe(i,k-1)<Qe(i,k+1)?C=Qe(i,k-1):C=Qe(i,k+1)-1;let P=C,O=C-k;for(;C>t&&O>o&&e[C-1]===r[O-1];)C--,O--;if(P-C>tn&&(y=!0),i[k]=C,!h&&p<=k&&k<=g&&C<=Qe(a,k))return{i1:C,i2:O,minLo:!0,minHi:!0}}if(!c){if(y&&b>Id){let k=0,C=null;for(let P=g;P>=p;P-=2){let O=P>l?P-l:l-P,E=Qe(a,P),I=E-P,A=E-t+(I-o)-O;if(A>zi*b&&A>k&&t+tn<=E&&E<n&&o+tn<=I&&I<s){let _=!0;for(let G=1;G<=tn;G++)if(e[E-G]!==r[I-G]){_=!1;break}_&&(k=A,C={i1:E,i2:I,minLo:!0,minHi:!1})}}if(C)return C;k=0,C=null;for(let P=x;P>=w;P-=2){let O=P>m?P-m:m-P,E=Qe(i,P),I=E-P,A=n-E+(s-I)-O;if(A>zi*b&&A>k&&t<E&&E<=n-tn&&o<I&&I<=s-tn){let _=!0;for(let G=0;G<tn;G++)if(e[E+G]!==r[I+G]){_=!1;break}_&&(k=A,C={i1:E,i2:I,minLo:!1,minHi:!0})}}if(C)return C}if(b>=f){let k=-1,C=-1;for(let E=g;E>=p;E-=2){let I=Math.min(Qe(a,E),n),A=I-E;s<A&&(I=s+E,A=s),k<I+A&&(k=I+A,C=I)}let P=Wr,O=Wr;for(let E=x;E>=w;E-=2){let I=Math.max(t,Qe(i,E)),A=I-E;A<o&&(I=o+E,A=o),I+A<P&&(P=I+A,O=I)}return n+s-P<k-(t+o)?{i1:C,i2:k-C,minLo:!0,minHi:!1}:{i1:O,i2:P-O,minLo:!1,minHi:!0}}}}}function no(e,t,n,r,o,s,a,i,c,f,d,u,l,m){for(;t<n&&o<s&&e[t]===r[o];)t++,o++;for(;t<n&&o<s&&e[n-1]===r[s-1];)n--,s--;if(t===n)for(let h=o;h<s;h++)i[f[h]]=1;else if(o===s)for(let h=t;h<n;h++)a[c[h]]=1;else{let h=Td(e,t,n,r,o,s,d,u,l,m);no(e,t,h.i1,r,o,h.i2,a,i,c,f,d,u,h.minLo,m),no(e,h.i1,n,r,h.i2,s,a,i,c,f,d,u,h.minHi,m)}}function Hd(e,t,n,r){let o=[],s=0,a=0,i=1,c=1;for(;s<e.length||a<t.length;){if(s<e.length&&a<t.length&&!n[s]&&!r[a]){o.push({type:"keep",line:e[s]??"",oldLineNo:i++,newLineNo:c++}),s++,a++;continue}for(;s<e.length&&n[s];)o.push({type:"delete",line:e[s]??"",oldLineNo:i++,newLineNo:0}),s++;for(;a<t.length&&r[a];)o.push({type:"insert",line:t[a]??"",oldLineNo:0,newLineNo:c++}),a++}return o}var Vi=200,Yi=20,Xi=100,Ad=1,vd=21,Sd=-30,Dd=6,Md=-4,jd=10,Ld=24,Gd=17,Nd=23,_d=17,Fd=60;function eo(e){let t=0;for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);if(r===32)t+=1;else if(r===9)t+=8-t%8;else if(!(r===10||r===13||r===11||r===12))return t;if(t>=Vi)return Vi}return-1}function Zi(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=eo(e[n]));for(let o=n-1;o>=0&&(r.preIndent=eo(e[o]),r.preIndent===-1);o--)if(r.preBlank+=1,r.preBlank===Yi){r.preIndent=0;break}for(let o=n+1;o<t&&(r.postIndent=eo(e[o]),r.postIndent===-1);o++)if(r.postBlank+=1,r.postBlank===Yi){r.postIndent=0;break}return r}function Ji(e,t){e.preIndent===-1&&e.preBlank===0&&(t.penalty+=Ad),e.endOfFile&&(t.penalty+=vd);let n=e.indent===-1?1+e.postBlank:0,r=e.preBlank+n;t.penalty+=Sd*r,t.penalty+=Dd*n;let o=e.indent!==-1?e.indent:e.postIndent,s=r!==0;t.effectiveIndent+=o,o===-1||e.preIndent===-1||(o>e.preIndent?t.penalty+=s?jd:Md:o===e.preIndent||(e.postIndent!==-1&&e.postIndent>o?t.penalty+=s?Gd:Ld:t.penalty+=s?_d:Nd))}function Ud(e,t){let n=(e.effectiveIndent>t.effectiveIndent?1:0)-(e.effectiveIndent<t.effectiveIndent?1:0);return Fd*n+(e.penalty-t.penalty)}function Qi(e,t,n,r,o,s){let a=0,i=0;for(;e[i];)i++;let c=0,f=0;for(;o[f];)f++;let d=(u,l)=>t[u]===t[l];for(;;){if(i!==a){let u,l,m;do{for(u=i-a,l=-1;a>0&&d(a-1,i-1);){for(e[--a]=1,e[--i]=0;e[a-1];)a--;if(c===0)break;for(f=c-1,c=f;o[c-1];c--);}for(m=i,f>c&&(l=i);!(i>=r||!d(a,i));){for(e[a++]=0,e[i++]=1;e[i];)i++;if(f>=s)break;for(c=f+1,f=c;o[f];f++);f>c&&(l=i)}}while(u!==i-a);if(i!==m)if(l!==-1)for(;f===c;){for(e[--i]=0,e[--a]=1;e[a-1];)a--;for(f=c-1,c=f;o[c-1];c--);}else{let h=-1,p={effectiveIndent:0,penalty:0},g=m;for(i-u-1>g&&(g=i-u-1),i-Xi>g&&(g=i-Xi);g<=i;g++){let w={effectiveIndent:0,penalty:0},x=Zi(n,r,g);Ji(x,w);let b=Zi(n,r,g-u);Ji(b,w),(h===-1||Ud(w,p)<=0)&&(p={effectiveIndent:w.effectiveIndent,penalty:w.penalty},h=g)}for(;i>h;){for(e[--i]=0,e[--a]=1;e[a-1];)a--;for(f=c-1,c=f;o[c-1];c--);}}}if(i>=r)break;for(a=i+1,i=a;e[i];i++);if(f>=s)break;for(c=f+1,f=c;o[f];f++);}}function ro(e,t){let n=e.length,r=t.length,o=new Uint8Array(n),s=new Uint8Array(r);if(n>0&&r>0){let{classes1:a,classes2:i,classInfo:c}=Pd(e,t),{dstart:f,dend1:d,dend2:u}=Od(a,n,i,r);if(f>d)for(let l=f;l<r-(n-1-d);l++)s[l]=1;else if(f>u)for(let l=f;l<n-(r-1-u);l++)o[l]=1;else{let{refIndex1:l,nreff1:m,refIndex2:h,nreff2:p}=Rd(a,n,i,r,c,f,d,u,o,s);if(m>0&&p>0){let g=new Array(m);for(let C=0;C<m;C++)g[C]=a[l[C]];let w=new Array(p);for(let C=0;C<p;C++)w[C]=i[h[C]];let x={},b={},y=m+p+3,k=Math.max($d,to(y));no(g,0,m,w,0,p,o,s,l,h,x,b,!1,k)}else if(m===0)for(let g=0;g<p;g++)s[h[g]]=1;else for(let g=0;g<m;g++)o[l[g]]=1;Qi(o,a,e,n,s,r),Qi(s,i,t,r,o,n)}}else n===0?s.fill(1):o.fill(1);return{changedOld:o,changedNew:s}}function xt(e,t){let n=e.length,r=t.length;if(n===0&&r===0)return[];if(n===0)return t.map((a,i)=>({type:"insert",line:a,oldLineNo:0,newLineNo:i+1}));if(r===0)return e.map((a,i)=>({type:"delete",line:a,oldLineNo:i+1,newLineNo:0}));let{changedOld:o,changedNew:s}=ro(e,t);return Hd(e,t,o,s)}var Bd=3;function Wd(e,t=Bd){if(e.length===0)return[];let n=[];for(let i=0;i<e.length;i++){let c=e[i];c&&c.type!=="keep"&&n.push(i)}if(n.length===0)return[];let r=n[0]??0,o=[],s=Math.max(0,r-t),a=Math.min(e.length-1,r+t);for(let i=1;i<n.length;i++){let c=n[i]??0,f=Math.max(0,c-t),d=Math.min(e.length-1,c+t);f<=a+1||(o.push({start:s,end:a}),s=f),a=d}return o.push({start:s,end:a}),o.map(i=>qd(e,i.start,i.end))}function qd(e,t,n){let r=0,o=0,s=0,a=0,i=[],c=!1,f=!1;for(let d=t;d<=n;d++){let u=e[d];if(u)switch(u.type){case"keep":c||(r=u.oldLineNo,c=!0),f||(s=u.newLineNo,f=!0),o++,a++,i.push({type:"context",content:u.line});break;case"delete":c||(r=u.oldLineNo,c=!0),o++,i.push({type:"delete",content:u.line});break;case"insert":f||(s=u.newLineNo,f=!0),a++,i.push({type:"insert",content:u.line});break}}if(c||(r=s>0?s:1),f||(s=r>0?r:1),o===0)for(let d=t;d<=n;d++){let u=e[d];if(u&&u.type==="insert"){r=u.newLineNo>1?u.newLineNo-1:0;break}}if(a===0)for(let d=t;d<=n;d++){let u=e[d];if(u&&u.type==="delete"){s=u.oldLineNo>1?u.oldLineNo-1:0;break}}return{oldStart:r,oldCount:o,newStart:s,newCount:a,lines:i}}function Kr(e){return e?e.length<40?e:K(e):"0000000"}function ea(e,t,n,r,o,s){let{path:a,oldMode:i,newMode:c}=t;e.push(`diff --git a/${a} b/${n}`),s?(e.push(`similarity index ${t.similarity??100}%`),e.push(`rename from ${a}`),e.push(`rename to ${n}`)):r?e.push(`new file mode ${c||"100644"}`):o?e.push(`deleted file mode ${i||"100644"}`):i&&c&&i!==c&&(e.push(`old mode ${i}`),e.push(`new mode ${c}`))}function Kd(e,t,n){let{path:r,oldContent:o,newContent:s,oldMode:a,oldHash:i,newHash:c}=e,f=e.renameTo!==void 0,d=e.renameTo??r,u=e.isNew??o==="",l=e.isDeleted??s==="";if(o===s&&!f)return"";let m=[];if(ea(m,e,d,u,l,f),o!==s){if(i||c){let h=Kr(i),p=Kr(c);u||l||f?m.push(`index ${h}..${p}`):m.push(`index ${h}..${p} ${a||"100644"}`)}t&&n?m.push(`Binary files a/${r} and b/${d} differ`):u?m.push(`Binary files /dev/null and b/${d} differ`):l?m.push(`Binary files a/${r} and /dev/null differ`):m.push(`Binary files a/${r} and b/${d} differ`)}return`${m.join(`
|
|
72
72
|
`)}
|
|
73
|
-
`}function At(e){let{path:t,oldContent:n,newContent:r,oldMode:o,newMode:s,oldHash:a,newHash:i}=e,c=e.renameTo!==void 0,f=e.renameTo??t,d=Pe(n),u=Pe(r);if(d||u)return
|
|
73
|
+
`}function At(e){let{path:t,oldContent:n,newContent:r,oldMode:o,newMode:s,oldHash:a,newHash:i}=e,c=e.renameTo!==void 0,f=e.renameTo??t,d=Pe(n),u=Pe(r);if(d||u)return Kd(e,d,u);let l=nn(n),m=nn(r),h=n.length>0&&n.endsWith(`
|
|
74
74
|
`),p=r.length>0&&r.endsWith(`
|
|
75
|
-
`),g="\0NOEOL",w=l;!h&&l.length>0&&(w=l.slice(),w[w.length-1]+=g);let x=m;!p&&m.length>0&&(x=m.slice(),x[x.length-1]+=g);let b=xt(w,x);if(!h||!p)for(let
|
|
75
|
+
`),g="\0NOEOL",w=l;!h&&l.length>0&&(w=l.slice(),w[w.length-1]+=g);let x=m;!p&&m.length>0&&(x=m.slice(),x[x.length-1]+=g);let b=xt(w,x);if(!h||!p)for(let A of b)A.line.includes(g)&&(A.line=A.line.replace(g,""));let y=Wd(b);if(y.length===0&&!c)return"";let k=e.isNew??n==="",C=e.isDeleted??r==="",P=[];if(ea(P,e,f,k,C,c),y.length===0)return`${P.join(`
|
|
76
76
|
`)}
|
|
77
|
-
`;if(a||i){let
|
|
77
|
+
`;if(a||i){let A=Kr(a),_=Kr(i);k||C?P.push(`index ${A}..${_}`):c?P.push(`index ${A}..${_} ${o||"100644"}`):o&&s&&o!==s?P.push(`index ${A}..${_}`):P.push(`index ${A}..${_} ${o||"100644"}`)}let O=A=>A.includes(" ")?" ":"";k?(P.push("--- /dev/null"),P.push(`+++ b/${f}${O(f)}`)):C?(P.push(`--- a/${t}${O(t)}`),P.push("+++ /dev/null")):(P.push(`--- a/${t}${O(t)}`),P.push(`+++ b/${f}${O(f)}`));let E=l.length,I=m.length;for(let A of y){let _=A.oldCount===1?`${A.oldStart}`:`${A.oldStart},${A.oldCount}`,G=A.newCount===1?`${A.newStart}`:`${A.newStart},${A.newCount}`,z="";for(let R=A.oldStart-2;R>=0;R--){let N=l[R];if(N&&/^[a-zA-Z$_]/.test(N)){z=` ${N.trimEnd().slice(0,79)}`;break}}P.push(`@@ -${_} +${G} @@${z}`);let D=A.oldStart,$=A.newStart;for(let R of A.lines)switch(R.type){case"context":P.push(` ${R.content}`),(!h&&D===E||!p&&$===I)&&P.push("\"),D++,$++;break;case"delete":P.push(`-${R.content}`),!h&&D===E&&P.push("\"),D++;break;case"insert":P.push(`+${R.content}`),!p&&$===I&&P.push("\"),$++;break}}return`${P.join(`
|
|
78
78
|
`)}
|
|
79
|
-
`}function Dn(e){let t=e.lastIndexOf("/");return t>=0?e.slice(t+1):e}function
|
|
80
|
-
`)[0],boundary:a,previous:i}}function
|
|
79
|
+
`}function Dn(e){let t=e.lastIndexOf("/");return t>=0?e.slice(t+1):e}function zd(e,t){if(e.length===0)return;if(e.length===1)return e.shift();let n=Dn(t),r=0;for(let o=0;o<e.length;o++){let s=e[o];if(s&&Dn(s.path)===n){r=o;break}}return e.splice(r,1)[0]}var Vd=50;async function Ye(e,t,n=Vd){let r=new Map,o=[],s=[],a=[];for(let d of t)if(d.status==="deleted"&&d.oldHash){let u=r.get(d.oldHash)??[];u.push(d),r.set(d.oldHash,u),o.push(d)}else d.status==="added"&&d.newHash?s.push(d):a.push(d);let i=[],c=[];for(let d of s){let u=d.newHash;if(!u){c.push(d);continue}let l=r.get(u);if(l&&l.length>0){let m=zd(l,d.path);m&&i.push({oldPath:m.path,newPath:d.path,oldHash:m.oldHash??u,newHash:u,similarity:100,oldMode:m.oldMode,newMode:d.newMode})}else c.push(d)}let f=[...r.values()].flat();if(f.length>0&&c.length>0){let d=await Yd(e,f,c,n);if(d.length>0){let u=new Set(d.map(m=>m.oldPath)),l=new Set(d.map(m=>m.newPath));f=f.filter(m=>!u.has(m.path)),c=c.filter(m=>!l.has(m.path)),i.push(...d)}}if(f.length>0&&c.length>0){let d=await Jd(e,f,c,n);if(d.length>0){let u=new Set(d.map(m=>m.oldPath)),l=new Set(d.map(m=>m.newPath));f=f.filter(m=>!u.has(m.path)),c=c.filter(m=>!l.has(m.path)),i.push(...d)}}return{remaining:[...a,...f,...c],renames:i}}async function Yd(e,t,n,r){let o=new Map;for(let i=0;i<t.length;i++){let c=t[i];if(!c)continue;let f=Dn(c.path);o.has(f)?o.set(f,-1):o.set(f,i)}let s=new Map;for(let i=0;i<n.length;i++){let c=n[i];if(!c)continue;let f=Dn(c.path);s.has(f)?s.set(f,-1):s.set(f,i)}let a=[];for(let[i,c]of o){if(c===-1)continue;let f=s.get(i);if(f===void 0||f===-1)continue;let d=t[c],u=n[f];if(!d?.oldHash||!u?.newHash||d.oldHash===u.newHash)continue;let l=await ot(e,d.oldHash),m=await ot(e,u.newHash),h=Zd(l,m);h<r||a.push({oldPath:d.path,newPath:u.path,oldHash:d.oldHash,newHash:u.newHash,similarity:h,oldMode:d.oldMode,newMode:u.newMode})}return a}var ta=107927;function zr(e){let t=new Map,n=0,r=0,o=0;for(let a=0;a<e.length;a++){let i=e[a],c=r;if(r=(r<<7^o>>>25)>>>0,o=(o<<7^c>>>25)>>>0,r=r+i>>>0,n++,n<64&&i!==10)continue;let f=(r+Math.imul(o,97))%ta;t.set(f,(t.get(f)??0)+n),n=0,r=0,o=0}if(n>0){let a=(r+Math.imul(o,97))%ta;t.set(a,(t.get(a)??0)+n)}let s=[];for(let[a,i]of t)s.push({hash:a,count:i});return s.sort((a,i)=>a.hash-i.hash),s}function Xd(e,t){let n=0,r=0,o=0,s=0;for(;o<e.length;){let a=e[o];if(!a)break;for(;s<t.length;){let f=t[s];if(!f||f.hash>=a.hash)break;r+=f.count,s++}let i=a.count,c=0;if(s<t.length){let f=t[s];f&&f.hash===a.hash&&(c=f.count,s++)}i<c?(r+=c-i,n+=i):n+=c,o++}for(;s<t.length;){let a=t[s];a&&(r+=a.count),s++}return{srcCopied:n,literalAdded:r}}function Zd(e,t){return e.length===0&&t.length===0?100:e.length===0||t.length===0?0:na(e.length,zr(e),t.length,zr(t))}function na(e,t,n,r){let o=Math.max(e,n),s=Math.min(e,n);if(s<o-s)return 0;let{srcCopied:a}=Xd(t,r);return Math.floor(a*100/o)}async function Jd(e,t,n,r){let o=[];for(let d of t)if(d.oldHash){let u=await ot(e,d.oldHash);o.push({size:u.length,chunks:zr(u)})}else o.push(null);let s=[];for(let d of n)if(d.newHash){let u=await ot(e,d.newHash);s.push({size:u.length,chunks:zr(u)})}else s.push(null);let a=[];for(let d=0;d<t.length;d++){let u=t[d],l=o[d];if(!(!u||!l))for(let m=0;m<n.length;m++){let h=n[m],p=s[m];if(!h||!p)continue;let g=na(l.size,l.chunks,p.size,p.chunks);if(g>=r){let w=Dn(u.path)===Dn(h.path)?1:0;a.push({similarity:g,nameScore:w,delIdx:d,addIdx:m})}}}a.sort((d,u)=>u.similarity-d.similarity||u.nameScore-d.nameScore);let i=new Set,c=new Set,f=[];for(let{similarity:d,delIdx:u,addIdx:l}of a){if(i.has(u)||c.has(l))continue;i.add(u),c.add(l);let m=t[u],h=n[l];!m||!h||f.push({oldPath:m.path,newPath:h.path,oldHash:m.oldHash??"",newHash:h.newHash??"",similarity:d,oldMode:m.oldMode,newMode:h.newMode})}return f}function Mn(e,t){let n=e.length,r=t.length,o=0,s=0;for(;s<n&&s<r&&e[s]===t[s];)e[s]==="/"&&(o=s+1),s++;let a=o>0?1:0,i=0,c=n,f=r;for(;o-a<=c&&o-a<=f&&c>=0&&f>=0;){if(c===n&&f===r){c--,f--;continue}if(e[c]!==t[f])break;e[c]==="/"&&(i=n-c),c--,f--}let d=Math.max(0,n-o-i),u=Math.max(0,r-o-i),l=e.slice(0,o),m=e.slice(n-i),h=e.slice(o,o+d),p=t.slice(o,o+u);return o+i>0?`${l}{${h} => ${p}}${m}`:`${e} => ${t}`}async function Vr(e,t,n){return(await se(e,t)).get(n)?.hash??null}async function Qd(e,t,n,r){let o=await Ae(e,t,n);if(!o.find(c=>c.status==="added"&&c.path===r))return null;let{renames:a}=await Ye(e,o);return a.find(c=>c.newPath===r)?.oldPath??null}async function ra(e,t,n,r){let o=await M(e,t),s=await Vr(e,o.tree,n);if(!s)throw new Error(`no such path '${n}' in ${t.slice(0,7)}`);let a=await fe(e,s),i=nn(a),c=r?.startLine??1,f=r?.endLine??i.length,d=i.slice(c-1,f),u=new Array(d.length),l=d.map((g,w)=>({finalIdx:w,currentLine:c+w})),m=t,h=n,p=i;for(;l.length>0;){let g=await M(e,m);if(g.parents.length===0){for(let A of l)u[A.finalIdx]=so(m,h,A.currentLine,c+A.finalIdx,d[A.finalIdx],g,!0,void 0);break}let w=g.parents[0],x=await M(e,w),b=h,y=await Vr(e,x.tree,b);if(!y){let A=await Qd(e,x.tree,g.tree,h);A&&(b=A,y=await Vr(e,x.tree,b))}if(!y){for(let A of l)u[A.finalIdx]=so(m,h,A.currentLine,c+A.finalIdx,d[A.finalIdx],g,!1,void 0);break}let k=await fe(e,y),C=nn(k);if(await Vr(e,g.tree,h)===y){m=w,h=b,p=C;continue}let O=xt(C,p),E=new Map;for(let A of O)A.type==="keep"&&E.set(A.newLineNo,A.oldLineNo);let I=[];for(let A of l){let _=E.get(A.currentLine);_!==void 0?I.push({finalIdx:A.finalIdx,currentLine:_}):u[A.finalIdx]=so(m,h,A.currentLine,c+A.finalIdx,d[A.finalIdx],g,!1,{hash:w,path:b})}l=I,m=w,h=b,p=C}return u}function so(e,t,n,r,o,s,a,i){return{hash:e,origPath:t,origLine:n,finalLine:r,content:o,author:s.author,committer:s.committer,summary:s.message.split(`
|
|
80
|
+
`)[0],boundary:a,previous:i}}function el(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 tl(e,t){let n=el(t),r=new Date((e+n*60)*1e3),o=r.getUTCFullYear(),s=(r.getUTCMonth()+1).toString().padStart(2,"0"),a=r.getUTCDate().toString().padStart(2,"0"),i=r.getUTCHours().toString().padStart(2,"0"),c=r.getUTCMinutes().toString().padStart(2,"0"),f=r.getUTCSeconds().toString().padStart(2,"0");return`${o}-${s}-${a} ${i}:${c}:${f} ${t}`}function nl(e,t,n,r,o){if(e.length===0)return"";let s=Math.max(...e.map(d=>d.finalLine)),a=String(s).length,i=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=[];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 l=i&&d.origPath!==t?` ${d.origPath}`:"";if(o)f.push(`${u}${l} ${String(d.finalLine).padStart(a)}) ${d.content}`);else{let m=r?`<${d.author.email}>`:d.author.name,h=tl(d.author.timestamp,d.author.timezone);f.push(`${u}${l} (${m.padEnd(c)} ${h} ${String(d.finalLine).padStart(a)}) ${d.content}`)}}return`${f.join(`
|
|
81
81
|
`)}
|
|
82
|
-
`}function
|
|
82
|
+
`}function rl(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(`
|
|
83
83
|
`)}
|
|
84
|
-
`}function
|
|
84
|
+
`}function sl(e,t,n){if(e.startsWith("/"))return Ke(n,e);let r=Ke(n,t);return r===""||r==="."?e:`${r}/${e}`}function sa(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:te.string().alias("L").describe("Annotate only the given line range (<start>,<end>)"),long:v().alias("l").describe("Show long revision"),showEmail:v().alias("e").describe("Show author email instead of name"),suppress:v().alias("s").describe("Suppress author name and date"),porcelain:v().alias("p").describe("Show in machine-readable format"),linePorcelain:v().describe("Show porcelain format with full headers for each line")},handler:async(n,r,o)=>{let s=await B(r.fs,r.cwd,t);if(S(s))return s;let a=s;if(!a.workTree)return T("this operation must be run in a work tree");let i=await Se(a);if(S(i))return i;let c=n.args??[],f=o.passthrough??[],d=null,u=null;if(f.length>0?(u=f[f.length-1],c.length>0&&(d=c[0])):c.length===2?(d=c[0],u=c[1]):c.length===1&&(u=c[0]),!u)return T("no file specified");let l=sl(u,r.cwd,a.workTree),m;if(d){let C=await An(a,d);if(S(C))return C;m=await Re(a,C)}else m=i;let h=await M(a,m),p=await se(a,h.tree);if(!p.has(l))return T(`no such path ${l} in ${d??"HEAD"}`);let g=p.get(l).hash,w=await fe(a,g);if(Pe(w))return T(`cannot blame binary file '${l}'`);let x,b;if(n.lineRange){let C=n.lineRange,P=C.match(/^(\d+),(\d+)$/);if(P)x=parseInt(P[1],10),b=parseInt(P[2],10);else return T(`invalid -L range: '${C}'`)}let y;try{y=await ra(a,m,l,{startLine:x,endLine:b})}catch(C){let P=C instanceof Error?C.message:String(C);return T(P)}let k;return n.porcelain||n.linePorcelain?k=rl(y,!!n.linePorcelain):k=nl(y,l,!!n.long,!!n.showEmail,!!n.suppress),{stdout:k,stderr:"",exitCode:0}}})}var ol=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],il=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function vt(e,t){let n=al(t),r=new Date((e+n*60)*1e3),o=ol[r.getUTCDay()],s=il[r.getUTCMonth()],a=r.getUTCDate(),i=r.getUTCHours().toString().padStart(2,"0"),c=r.getUTCMinutes().toString().padStart(2,"0"),f=r.getUTCSeconds().toString().padStart(2,"0"),d=r.getUTCFullYear();return`${o} ${s} ${a} ${i}:${c}:${f} ${d} ${t}`}function oo(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 al(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)}var Yr=new TextDecoder;function oa(e){if(e.length===0)return 0;let t=0;for(let n=0;n<e.length;n++)e[n]===`
|
|
85
85
|
`&&t++;return e[e.length-1]!==`
|
|
86
|
-
`&&t++,t}function Zr(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
|
|
86
|
+
`&&t++,t}function Zr(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 ia(e,t,n){let r=[],o=[],s=[];for(let i of t)if(i.status==="added"&&i.newHash&&i.newMode){let c=await ot(e,i.newHash);Vt(c)?r.push({path:i.path,sortKey:i.path,insertions:0,deletions:0,isBinary:!0,oldSize:0,newSize:c.byteLength}):r.push({path:i.path,sortKey:i.path,insertions:oa(Yr.decode(c)),deletions:0}),o.push({path:i.path,mode:i.newMode})}else if(i.status==="deleted"&&i.oldHash&&i.oldMode){let c=await ot(e,i.oldHash);Vt(c)?r.push({path:i.path,sortKey:i.path,insertions:0,deletions:0,isBinary:!0,oldSize:c.byteLength,newSize:0}):r.push({path:i.path,sortKey:i.path,insertions:0,deletions:oa(Yr.decode(c))}),s.push({path:i.path,mode:i.oldMode})}else if(i.status==="modified"&&i.oldHash&&i.newHash){let c=await ot(e,i.oldHash),f=await ot(e,i.newHash);if(Vt(c)||Vt(f))r.push({path:i.path,sortKey:i.path,insertions:0,deletions:0,isBinary:!0,oldSize:c.byteLength,newSize:f.byteLength});else{let d=rn(Yr.decode(c)),u=rn(Yr.decode(f)),l=xt(d,u),m=0,h=0;for(let p of l)p.type==="insert"?m++:p.type==="delete"&&h++;r.push({path:i.path,sortKey:i.path,insertions:m,deletions:h})}i.oldMode&&i.newMode&&i.oldMode!==i.newMode&&(s.push({path:i.path,mode:i.oldMode}),o.push({path:i.path,mode:i.newMode}))}for(let i of n){let c=Mn(i.oldPath,i.newPath),f=0,d=0;if(i.similarity<100&&i.oldHash&&i.newHash){let u=await fe(e,i.oldHash),l=await fe(e,i.newHash);if(!Pe(u)&&!Pe(l)){let m=rn(u),h=rn(l),p=xt(m,h);for(let g of p)g.type==="insert"?f++:g.type==="delete"&&d++}}r.push({path:c,sortKey:i.newPath,insertions:f,deletions:d})}let a=[];for(let{path:i,mode:c}of o)a.push({sortKey:i,text:` create mode ${c} ${i}`});for(let{path:i,mode:c}of s)a.push({sortKey:i,text:` delete mode ${c} ${i}`});for(let i of n){let c=Mn(i.oldPath,i.newPath);a.push({sortKey:i.newPath,text:` rename ${c} (${i.similarity}%)`})}return a.sort((i,c)=>i.sortKey<c.sortKey?-1:i.sortKey>c.sortKey?1:0),{fileStats:r,modeLines:a.map(i=>i.text)}}async function St(e,t,n,r,o,s=!1,a=!1){let i=[];if((r.name!==o.name||r.email!==o.email)&&i.push(` Author: ${r.name} <${r.email}>`),s&&i.push(` Date: ${vt(r.timestamp,r.timezone)}`),a)return i.join(`
|
|
87
87
|
`)+(i.length>0?`
|
|
88
|
-
`:"");let c=await Ae(e,t,n),{remaining:f,renames:d}=await Ye(e,c),{fileStats:u,modeLines:l}=await
|
|
88
|
+
`:"");let c=await Ae(e,t,n),{remaining:f,renames:d}=await Ye(e,c),{fileStats:u,modeLines:l}=await ia(e,f,d),m=0,h=0;for(let g of u)m+=g.insertions,h+=g.deletions;let p=Zr(u.length,m,h);p&&i.push(p);for(let g of l)i.push(g);return i.join(`
|
|
89
89
|
`)+(i.length>0?`
|
|
90
|
-
`:"")}var Xr=80;function
|
|
90
|
+
`:"")}var Xr=80;function cl(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 io(e){if(e.length===0)return"";let t=e.filter(h=>!h.isUnmerged),n=t.length>0?Math.max(...t.map(h=>h.insertions+h.deletions)):0,r=e.some(h=>h.isBinary),o=n>0?String(n).length:1;r&&o<3&&(o=3);let s=Math.max(...e.map(h=>h.path.length)),a=n,i=s;if(i+o+6+a>Xr){let h=Math.floor(Xr*3/8)-o-6;a>h&&(a=Math.max(h,6));let p=Xr-o-6-a;i>p?i=p:a=Xr-o-6-i}for(let h of e)h.path=cl(h.path,i);let c=i,f=[],d=0,u=0,l=0;for(let h of e){let p=h.path.padEnd(c);if(h.isUnmerged){f.push(` ${p} | Unmerged`);continue}if(l++,d+=h.insertions,u+=h.deletions,h.isBinary){let P=`${"Bin".padStart(o)} ${h.oldSize??0} -> ${h.newSize??0} bytes`;f.push(` ${p} | ${P}`);continue}let g=h.insertions+h.deletions,w=String(g).padStart(o),x,b;if(n<=a)x=h.insertions,b=h.deletions;else{let C=E=>E===0?0:1+Math.floor(E*(a-1)/n),P=C(g),O=P<2&&h.insertions>0&&h.deletions>0?2:P;h.insertions<h.deletions?(x=C(h.insertions),b=O-x):(b=C(h.deletions),x=O-b)}let y="+".repeat(x)+"-".repeat(b),k=y?` ${y}`:"";f.push(` ${p} | ${w}${k}`)}let m=Zr(l,d,u);return m?f.push(m):e.some(h=>h.isUnmerged)&&f.push(" 0 files changed"),`${f.join(`
|
|
91
91
|
`)}
|
|
92
|
-
`}async function sn(e,t,n){let r=await Ae(e,t,n),{remaining:o,renames:s}=await Ye(e,r);if(o.length===0&&s.length===0)return"";let{fileStats:a,modeLines:i}=await
|
|
93
|
-
`;return c}async function
|
|
92
|
+
`}async function sn(e,t,n){let r=await Ae(e,t,n),{remaining:o,renames:s}=await Ye(e,r);if(o.length===0&&s.length===0)return"";let{fileStats:a,modeLines:i}=await ia(e,o,s);a.sort((f,d)=>f.sortKey<d.sortKey?-1:f.sortKey>d.sortKey?1:0);let c=io(a);for(let f of i)c+=`${f}
|
|
93
|
+
`;return c}async function fl(e,t){let n=new Set,r=[t],o=0;for(;o<r.length;){let s=r[o++];if(n.has(s))continue;n.add(s);let a=await M(e,s);for(let i of a.parents)n.has(i)||r.push(i)}return n}async function _t(e,t,n){if(t===n)return!0;let r=new Set,o=[n],s=0;for(;s<o.length;){let a=o[s++];if(a===t)return!0;if(r.has(a))continue;r.add(a);let i=await M(e,a);for(let c of i.parents)r.has(c)||o.push(c)}return!1}async function ht(e,t,n){if(t===n)return[t];let r=await fl(e,t),o=[],s=new Set,a=[n],i=0;for(;i<a.length;){let f=a[i++];if(s.has(f))continue;if(s.add(f),r.has(f)){o.push(f);continue}let d=await M(e,f);for(let u of d.parents)s.has(u)||a.push(u)}if(o.length<=1)return o;let c=[];for(let f of o){let d=!1;for(let u of o)if(u!==f&&await _t(e,f,u)){d=!0;break}d||c.push(f)}return c.length<=1?c:dl(e,t,n,c)}async function dl(e,t,n,r){let o=new Set(r),s=new Set,a=[],i=new Map,c=new Map,f=0,d=[{hash:t,mask:1,seq:f++},{hash:n,mask:2,seq:f++}];async function u(l){let m=c.get(l);if(m!==void 0)return m;let h=(await M(e,l)).committer.timestamp;return c.set(l,h),h}for(;d.length>0;){let l=0,m=await u(d[0].hash);for(let x=1;x<d.length;x++){let b=d[x],y=await u(b.hash),k=d[l];(y>m||y===m&&b.seq<k.seq)&&(l=x,m=y)}let h=d.splice(l,1)[0],p=i.get(h.hash)??0,g=p|h.mask;if(g===p)continue;if(i.set(h.hash,g),g===3&&o.has(h.hash)&&!s.has(h.hash)&&(a.push(h.hash),s.add(h.hash),s.size===o.size))break;let w=await M(e,h.hash);for(let x of w.parents)d.push({hash:x,mask:g,seq:f++})}for(let l of r)s.has(l)||a.push(l);return a}async function Ft(e,t,n){let r=await bt(e,"init.defaultBranch")??"main";return n===r?`Merge branch '${t}'
|
|
94
94
|
`:`Merge branch '${t}' into ${n}
|
|
95
95
|
`}async function Jr(e,t,n){let r=await M(e,t),o=await M(e,n),s=K(t),a=K(n),i=`Updating ${s}..${a}
|
|
96
|
-
`;if(e.workTree){let f=await U(e),d=await
|
|
97
|
-
${c}`,stderr:"",exitCode:0}}async function qe(e,t){let n=
|
|
98
|
-
`)
|
|
99
|
-
`)}
|
|
100
|
-
`
|
|
101
|
-
`)
|
|
102
|
-
`)}
|
|
103
|
-
`
|
|
96
|
+
`;if(e.workTree){let f=await U(e),d=await _i(e,r.tree,o.tree,f);if(!d.success){let u=d.errorOutput;return{stdout:i+u.stdout,stderr:u.stderr,exitCode:u.exitCode}}await re(e,{version:2,entries:d.newEntries}),await be(e,d.worktreeOps)}await Yt(e,n);let c=await sn(e,r.tree,o.tree);return{stdout:`${i}Fast-forward
|
|
97
|
+
${c}`,stderr:"",exitCode:0}}async function qe(e,t){let n=H(e.gitDir,t);return await e.fs.exists(n)?e.fs.readFile(n):null}async function Ue(e,t,n){await e.fs.writeFile(H(e.gitDir,t),n)}async function et(e,t){let n=H(e.gitDir,t);await e.fs.exists(n)&&await e.fs.rm(n)}async function or(e){await ie(e,"MERGE_HEAD"),await ie(e,"ORIG_HEAD"),await et(e,"MERGE_MSG"),await et(e,"MERGE_MODE")}async function kt(e){await ie(e,"CHERRY_PICK_HEAD"),await ie(e,"ORIG_HEAD"),await et(e,"MERGE_MSG")}async function pt(e){await ie(e,"REVERT_HEAD"),await ie(e,"ORIG_HEAD"),await et(e,"MERGE_MSG")}async function wn(e){for(let t of["CHERRY_PICK_HEAD","REVERT_HEAD","MERGE_HEAD","ORIG_HEAD"])await ie(e,t);await et(e,"MERGE_MSG"),await et(e,"MERGE_MODE")}var ao="DETACH_POINT";async function aa(e,t){await e.fs.writeFile(H(e.gitDir,ao),t)}async function tt(e){let t=H(e.gitDir,ao);await e.fs.exists(t)&&await e.fs.rm(t)}async function ir(e){let t=H(e.gitDir,ao);return await e.fs.exists(t)?(await e.fs.readFile(t))?.trim()??null:null}function jn(e){return H(e.gitDir,"rebase-merge")}async function gt(e){return e.fs.exists(jn(e))}async function nt(e){let t=jn(e);if(!await e.fs.exists(t))return null;let n=await e.fs.readFile(H(t,"head-name")),r=await e.fs.readFile(H(t,"orig-head")),o=await e.fs.readFile(H(t,"onto")),s=Number.parseInt(await e.fs.readFile(H(t,"msgnum")),10),a=Number.parseInt(await e.fs.readFile(H(t,"end")),10),i=await e.fs.exists(H(t,"git-rebase-todo"))?H(t,"git-rebase-todo"):H(t,"todo"),c=ca(await e.fs.readFile(i)),f=await e.fs.exists(H(t,"done"))?await e.fs.readFile(H(t,"done")):"",d=ca(f);return{headName:n.trim(),origHead:r.trim(),onto:o.trim(),todo:c,done:d,msgnum:s,end:a}}async function co(e,t){let n=jn(e);await e.fs.mkdir(n,{recursive:!0}),await e.fs.writeFile(H(n,"head-name"),`${t.headName}
|
|
98
|
+
`),await e.fs.writeFile(H(n,"orig-head"),`${t.origHead}
|
|
99
|
+
`),await e.fs.writeFile(H(n,"onto"),`${t.onto}
|
|
100
|
+
`),await e.fs.writeFile(H(n,"msgnum"),`${String(t.msgnum)}
|
|
101
|
+
`),await e.fs.writeFile(H(n,"end"),`${String(t.end)}
|
|
102
|
+
`),await e.fs.writeFile(H(n,"git-rebase-todo"),es(t.todo)),await e.fs.writeFile(H(n,"done"),es(t.done)),await e.fs.writeFile(H(n,"interactive"),"")}async function la(e){let t=jn(e),n=await nt(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(H(t,"msgnum"),`${String(n.msgnum)}
|
|
103
|
+
`),await e.fs.writeFile(H(t,"git-rebase-todo"),es(n.todo)),await e.fs.writeFile(H(t,"done"),es(n.done))}async function fo(e){let t=jn(e);await e.fs.exists(t)&&await e.fs.rm(t,{recursive:!0})}async function ts(e,t,n){let r=jn(e),o=`@${n.timestamp} ${n.timezone}`;await e.fs.writeFile(H(r,"author-script"),`GIT_AUTHOR_NAME='${n.name}'
|
|
104
|
+
GIT_AUTHOR_EMAIL='${n.email}'
|
|
105
|
+
GIT_AUTHOR_DATE='${o}'
|
|
106
|
+
`),await e.fs.writeFile(H(r,"stopped-sha"),`${t}
|
|
107
|
+
`)}function ca(e){let t=[];for(let n of e.split(`
|
|
108
|
+
`)){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].startsWith("# ")?o[2].slice(2):o[2];t.push({hash:o[1],subject:s})}}return t}function es(e){return e.length===0?"":`${e.map(t=>`pick ${t.hash} # ${t.subject}`).join(`
|
|
109
|
+
`)}
|
|
110
|
+
`}async function ua(e,t,n){let r=new Map,[o,s]=await Promise.all([fa(e,t,r),fa(e,n,r)]),a=new Set;for(let c of s)o.has(c)||a.add(c);let i=new Set;for(let c of o)s.has(c)||i.add(c);return{right:await da(e,r,n,a),left:await da(e,r,t,i)}}async function fa(e,t,n){let r=new Set,o=[t],s=0;for(;s<o.length;){let a=o[s++];if(r.has(a))continue;r.add(a);let i=await Qr(e,a,n);for(let c of i.commit.parents)r.has(c)||o.push(c)}return r}async function da(e,t,n,r){if(r.size===0)return[];let o=new Map;for(let f of r)o.set(f,0);for(let f of r){let d=await Qr(e,f,t);for(let u of d.commit.parents)r.has(u)&&o.set(u,(o.get(u)??0)+1)}let s=[];for(let f of r)o.get(f)===0&&s.push(await Qr(e,f,t));s.sort((f,d)=>f.commit.committer.timestamp-d.commit.committer.timestamp);let a=s.map(f=>f.hash),i=[],c=new Set;for(;a.length>0;){let f=a.pop();if(!f||c.has(f))continue;c.add(f);let d=await Qr(e,f,t);d.commit.parents.length<=1&&i.push(d);for(let u of d.commit.parents)if(r.has(u)&&!c.has(u)){let l=(o.get(u)??0)-1;o.set(u,l),l<=0&&a.push(u)}}return i.reverse(),i}async function Qr(e,t,n){let r=n.get(t);if(r)return r;let o=await ce(e,t);if(o.type!=="commit")throw new Error(`Expected commit object, got ${o.type}`);let s={hash:t,commit:It(o.content)};return n.set(t,s),s}var Ln=class{heap=[];get size(){return this.heap.length}push(t){this.heap.push(t),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}siftUp(t){let{heap:n}=this;for(;t>0;){let r=t-1>>1;if(n[r].commit.committer.timestamp>=n[t].commit.committer.timestamp)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,a=2*t+2;if(s<r&&n[s].commit.committer.timestamp>n[o].commit.committer.timestamp&&(o=s),a<r&&n[a].commit.committer.timestamp>n[o].commit.committer.timestamp&&(o=a),o===t)break;[n[t],n[o]]=[n[o],n[t]],t=o}}};async function*bn(e,t,n){let r=await ll(e,n?.exclude),o=new Set(r),s=new Ln,a=Array.isArray(t)?t:[t];for(let i of a)o.has(i)||s.push(await ns(e,i));for(;s.size>0;){let i=s.pop();if(!o.has(i.hash)){o.add(i.hash),yield i;for(let c of i.commit.parents)o.has(c)||s.push(await ns(e,c))}}}async function ma(e,t,n){if(t===n)return{ahead:0,behind:0};let r=new Set;for await(let i of bn(e,t))r.add(i.hash);let o=new Set;for await(let i of bn(e,n))o.add(i.hash);let s=0;for(let i of r)o.has(i)||s++;let a=0;for(let i of o)r.has(i)||a++;return{ahead:s,behind:a}}async function ha(e,t,n){let r=n?.maxCount??25,o=await le(e,"refs"),s=[];for(let d of o)try{s.push(await Re(e,d.hash))}catch{}n?.targetHash&&s.push(n.targetHash);let a=new Set;if(s.length>0)for await(let d of bn(e,s))a.add(d.hash);if(a.has(t))return[];let i=[],c=new Set,f=new Ln;for(f.push(await ns(e,t));f.size>0&&i.length<r;){let d=f.pop();if(!c.has(d.hash)&&(c.add(d.hash),!a.has(d.hash))){i.push({hash:d.hash,subject:ue(d.commit.message)});for(let u of d.commit.parents)c.has(u)||f.push(await ns(e,u))}}return i}async function ll(e,t){if(!t||t.length===0)return new Set;let n=new Set;for await(let r of bn(e,t))n.add(r.hash);return n}async function ns(e,t){return{hash:t,commit:await M(e,t)}}async function Be(e,t){let n=await J(e),r=await X(e),o,s=!1;n&&n.type==="symbolic"?o=de(n.target):(s=!0,o="HEAD detached");let a=t?.index??await U(e),i=uo(a),c=t?.compareHash!==void 0?t.compareHash:r,f=t?.compareHash!==void 0?!t.compareHash:!r,d=await lo(e,c,a,i),u=await lt(e,a),l=[],m=[];for(let g of u)g.status==="untracked"?m.push(g.path):l.push({path:g.path,status:g.status});l.sort((g,w)=>he(g.path,w.path));let h=new Set(a.entries.map(g=>g.path)),p=mo(m,h);return ul(e,r,s,o,a,d,l,i,p,{fromCommit:t?.fromCommit,noWarn:t?.noWarn,isInitial:f})}function pa(e,t){if(t.done.length>0){let n=t.done.length;e.push(`Last command${n===1?"":"s"} done (${n} command${n===1?"":"s"} done):`);for(let r of t.done.slice(-2))e.push(` pick ${K(r.hash)} # ${r.subject}`);n>2&&e.push(" (see more in file .git/rebase-merge/done)")}if(t.todo.length>0){let n=t.todo.length;e.push(`Next command${n===1?"":"s"} to do (${n} remaining command${n===1?"":"s"}):`);for(let r of t.todo.slice(0,2))e.push(` pick ${K(r.hash)} # ${r.subject}`);e.push(' (use "git rebase --edit-todo" to view and edit)')}else e.push("No commands remaining.")}async function ul(e,t,n,r,o,s,a,i,c,f){let d=[],u=!1,l=await F(e,"CHERRY_PICK_HEAD"),m=await F(e,"REVERT_HEAD"),h=await F(e,"MERGE_HEAD"),p=!l&&!h,w=await gt(e)?await nt(e):null;if(n&&w){let O=K(w.onto);d.push(`interactive rebase in progress; onto ${O}`)}else if(n){let O=await ir(e);if(O){let E=t===O?"at":"from";d.push(`HEAD detached ${E} ${K(O)}`)}else d.push("Not currently on any branch.")}else d.push(`On branch ${r}`);if(!n&&!w){let O=await ae(e),E=await Ut(e,O,r);if(E){let I=yn(E,{abbreviated:f?.fromCommit});for(let A of I.trimEnd().split(`
|
|
111
|
+
`))d.push(A);u=!0}}if(u&&(w||l||m||h)&&d.push(""),w&&h)pa(d,w),d.push(""),i.length>0?(d.push("You have unmerged paths."),d.push(' (fix conflicts and run "git commit")'),d.push(' (use "git merge --abort" to abort the merge)')):(d.push("All conflicts fixed but you are still merging."),d.push(' (use "git commit" to conclude merge)')),u=!0;else if(w){let O=dt(o),E=await e.fs.exists(H(e.gitDir,"MERGE_MSG"));pa(d,w);let A=w.headName==="detached HEAD"?null:de(w.headName),_=K(w.onto),G=A?` branch '${A}' on '${_}'`:"";if(O)d.push(`You are currently rebasing${G}.`),d.push(' (fix conflicts and then run "git rebase --continue")'),d.push(' (use "git rebase --skip" to skip this patch)'),d.push(' (use "git rebase --abort" to check out the original branch)');else if(E)d.push(`You are currently rebasing${G}.`),d.push(' (all conflicts fixed: run "git rebase --continue")');else{let z=G?`You are currently editing a commit while rebasing${G}.`:"You are currently editing a commit during a rebase.";d.push(z),d.push(' (use "git commit --amend" to amend the current commit)'),d.push(' (use "git rebase --continue" once you are satisfied with your changes)')}u=!0}else l?(d.push(`You are currently cherry-picking commit ${K(l)}.`),i.length>0?d.push(' (fix conflicts and run "git cherry-pick --continue")'):d.push(' (all conflicts fixed: run "git cherry-pick --continue")'),d.push(' (use "git cherry-pick --skip" to skip this patch)'),d.push(' (use "git cherry-pick --abort" to cancel the cherry-pick operation)'),u=!0):m?(d.push(`You are currently reverting commit ${K(m)}.`),i.length>0?d.push(' (fix conflicts and run "git revert --continue")'):d.push(' (all conflicts fixed: run "git revert --continue")'),d.push(' (use "git revert --skip" to skip this patch)'),d.push(' (use "git revert --abort" to cancel the revert operation)'),u=!0):h&&(i.length>0?(d.push("You have unmerged paths."),d.push(' (fix conflicts and run "git commit")'),d.push(' (use "git merge --abort" to abort the merge)')):(d.push("All conflicts fixed but you are still merging."),d.push(' (use "git commit" to conclude merge)')),u=!0);let x=f?.isInitial??!t;x&&(d.push(""),d.push(f?.fromCommit?"Initial commit":"No commits yet"),u=!0);let b=null;p&&(b=t?' (use "git restore --staged <file>..." to unstage)':' (use "git rm --cached <file>..." to unstage)');let k=a.some(O=>O.status==="deleted")?' (use "git add/rm <file>..." to update what will be committed)':' (use "git add <file>..." to update what will be committed)',C=!1;if(s.length>0){u&&d.push(""),d.push("Changes to be committed:"),b&&d.push(b);for(let O of s)d.push(` ${ga(O.status,O.path,O.displayPath)}`);d.push(""),C=!0}if(i.length>0){!C&&u&&d.push(""),d.push("Unmerged paths:"),p&&(t?d.push(' (use "git restore --staged <file>..." to unstage)'):d.push(' (use "git rm --cached <file>..." to unstage)')),i.some(E=>E.status==="deleted by us"||E.status==="deleted by them"||E.status==="both deleted")?d.push(' (use "git add/rm <file>..." as appropriate to mark resolution)'):d.push(' (use "git add <file>..." to mark resolution)');for(let E of i)d.push(` ${ml(E.status,E.path)}`);d.push(""),C=!0}if(a.length>0){!C&&u&&d.push(""),d.push("Changes not staged for commit:"),d.push(k),d.push(' (use "git restore <file>..." to discard changes in working directory)');for(let O of a)d.push(` ${ga(O.status,O.path)}`);d.push(""),C=!0}if(c.length>0){!C&&u&&d.push(""),d.push("Untracked files:"),d.push(' (use "git add <file>..." to include in what will be committed)');for(let O of c)d.push(` ${O}`);d.push(""),C=!0}let P=s.length>0||!!h&&i.length===0;return!C&&u&&(f?.noWarn||P)&&d.push(""),!P&&!f?.noWarn&&(!C&&u&&a.length===0&&i.length===0&&c.length===0&&d.push(""),a.length>0||i.length>0?d.push('no changes added to commit (use "git add" and/or "git commit -a")'):c.length>0?d.push('nothing added to commit but untracked files present (use "git add" to track)'):x?d.push('nothing to commit (create/copy files and use "git add" to track)'):d.push("nothing to commit, working tree clean")),`${d.join(`
|
|
112
|
+
`)}
|
|
113
|
+
`}async function lo(e,t,n,r){let o=new Set(r?.map(m=>m.path)),s=null;t&&(s=(await M(e,t)).tree);let a=await se(e,s),i=new Map(xe(n).map(m=>[m.path,m])),c=[];for(let[m,h]of i){if(o.has(m))continue;let p=a.get(m);p?p.hash!==h.hash&&c.push({path:m,status:"modified",oldHash:p.hash,newHash:h.hash,oldMode:p.mode,newMode:h.mode.toString(8).padStart(6,"0")}):c.push({path:m,status:"added",newHash:h.hash,newMode:h.mode.toString(8).padStart(6,"0")})}for(let[m,h]of a)o.has(m)||i.has(m)||c.push({path:m,status:"deleted",oldHash:h.hash,oldMode:h.mode});let{remaining:f,renames:d}=await Ye(e,c),u={added:"new file",deleted:"deleted",modified:"modified"},l=[];for(let m of f){let h=u[m.status];h&&l.push({path:m.path,status:h})}for(let m of d)l.push({path:m.newPath,status:"renamed",displayPath:`${m.oldPath} -> ${m.newPath}`});return l.sort((m,h)=>he(m.path,h.path))}function uo(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,a=o.has(1),i=o.has(2),c=o.has(3);i&&c?s=a?"both modified":"both added":a&&!i&&!c?s="both deleted":a&&c?s="deleted by us":a&&i?s="deleted by them":i&&!a&&!c?s="added by us":c&&!a&&!i?s="added by them":s="unmerged",n.push({path:r,status:s})}return n.sort((r,o)=>he(r.path,o.path))}function mo(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 a=!1;for(let i=1;i<s.length;i++){let c=`${s.slice(0,i).join("/")}/`;if(!n.has(c)){r.add(c),a=!0;break}}a||r.add(o)}return[...r].sort()}function ga(e,t,n){return`${e}:`.padEnd(12)+(n??t)}function ml(e,t){return`${e}:`.padEnd(17)+t}async function Ut(e,t,n){let r=t[`branch "${n}"`];if(!r?.remote||!r?.merge)return null;let o=r.remote,s=r.merge,a=s.replace(/^refs\/heads\//,`refs/remotes/${o}/`),i=`${o}/${s.replace(/^refs\/heads\//,"")}`,c=await F(e,a);if(!c)return{upstream:i,ahead:0,behind:0,gone:!0};let f=await F(e,`refs/heads/${n}`);if(!f)return null;if(f===c)return{upstream:i,ahead:0,behind:0,gone:!1};let{ahead:d,behind:u}=await ma(e,f,c);return{upstream:i,ahead:d,behind:u,gone:!1}}function wa(e,t){if(t){if(e.gone)return`[${e.upstream}: gone]`;if(e.ahead===0&&e.behind===0)return`[${e.upstream}]`;let r=[];return e.ahead>0&&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 yn(e,t){if(e.gone)return`Your branch is based on '${e.upstream}', but the upstream is gone.
|
|
104
114
|
(use "git branch --unset-upstream" to fixup)
|
|
105
115
|
`;if(e.ahead===0&&e.behind===0)return`Your branch is up to date with '${e.upstream}'.
|
|
106
116
|
`;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}.
|
|
@@ -110,9 +120,9 @@ ${c}`,stderr:"",exitCode:0}}async function qe(e,t){let n=v(e.gitDir,t);return aw
|
|
|
110
120
|
`}let n=`Your branch and '${e.upstream}' have diverged,
|
|
111
121
|
and have ${e.ahead} and ${e.behind} different commits each, respectively.
|
|
112
122
|
`;return t?.abbreviated?n:n+` (use "git pull" if you want to integrate the remote branch with yours)
|
|
113
|
-
`}function
|
|
123
|
+
`}function ba(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:v().alias("d").describe("Delete a branch"),forceDelete:v().alias("D").describe("Force delete a branch"),move:v().alias("m").describe("Rename a branch"),forceMove:v().alias("M").describe("Force rename a branch"),remotes:v().alias("r").describe("List remote-tracking branches"),all:v().alias("a").describe("List all branches"),setUpstreamTo:te.string().alias("u").describe("Set upstream tracking branch"),verbose:v().alias("v").count().describe("Show hash and subject")},handler:async(n,r)=>{let o=await B(r.fs,r.cwd,t);if(S(o))return o;let s=o,a=await J(s),i=a?.type==="symbolic"?de(a.target):null,c=!!n.forceMove;if(n.move||c){let w,x;if(n.newName)w=n.name,x=n.newName;else if(n.name){if(!i)return T("not on any branch");w=i,x=n.name}else return T("branch name required");let b=`refs/heads/${w}`,y=`refs/heads/${x}`,k=await F(s,b);if(!k)return T(`no branch named '${w}'`);if(await gt(s)&&(await nt(s))?.headName===b)return T(`branch ${b} is being rebased at ${s.workTree}`);let C=await F(s,y);if(C&&!c)return T(`a branch named '${x}' already exists`);C&&await ie(s,y);let P=await Me(s,b);await Y(s,y,k),await ie(s,b),w===i&&await $e(s,"HEAD",y),P.length>0&&await Xt(s,y,P);let O=`Branch: renamed ${b} to ${y}`;if(await ee(s,r.env,y,k,k,O),w===i){let A=await Ot(s,r.env);await Te(s,"HEAD",{oldHash:k,newHash:Z,...A,message:O}),await Te(s,"HEAD",{oldHash:Z,newHash:k,...A,message:O})}let E=await ae(s),I=`branch "${w}"`;return E[I]&&(E[`branch "${x}"`]=E[I],delete E[I],await Ge(s,E)),{stdout:"",stderr:"",exitCode:0}}let f=n.forceDelete;if(n.delete||f){if(!n.name)return T("branch name required");let w=n.name===i;if(!w&&!i&&await gt(s)&&(await nt(s))?.headName===`refs/heads/${n.name}`&&(w=!0),w)return j(`error: cannot delete branch '${n.name}' used by worktree at '${s.workTree}'
|
|
114
124
|
`);let x=`refs/heads/${n.name}`,b=await F(s,x);if(!b)return j(`error: branch '${n.name}' not found
|
|
115
|
-
`);let y="";if(!f){let k=await X(s),P=(await ae(s))[`branch "${n.name}"`],O=P?.remote,E=P?.merge,I=null,
|
|
125
|
+
`);let y="";if(!f){let k=await X(s),P=(await ae(s))[`branch "${n.name}"`],O=P?.remote,E=P?.merge,I=null,A=null;if(O&&E&&(I=E.replace(/^refs\/heads\//,`refs/remotes/${O}/`),A=await F(s,I)),A&&I){if(!(b===A||await _t(s,b,A))){let D=k!=null&&(b===k||await _t(s,b,k))?`warning: not deleting branch '${n.name}' that is not yet merged to
|
|
116
126
|
'${I}', even though it is merged to HEAD
|
|
117
127
|
`:"";return j(`${D}error: the branch '${n.name}' is not fully merged
|
|
118
128
|
hint: If you are sure you want to delete it, run 'git branch -D ${n.name}'
|
|
@@ -124,26 +134,26 @@ hint: If you are sure you want to delete it, run 'git branch -D ${n.name}'
|
|
|
124
134
|
hint: Disable this message with "git config set advice.forceDeleteBranch false"
|
|
125
135
|
`)}return await ie(s,x),{stdout:`Deleted branch ${n.name} (was ${K(b)}).
|
|
126
136
|
`,stderr:y,exitCode:0}}if(n.setUpstreamTo){let w=n.setUpstreamTo,x=n.name||i;if(!x)return T("could not set upstream of HEAD when it does not point to any branch.");if(!await F(s,`refs/heads/${x}`))return T(`branch '${x}' does not exist`);let y=w.indexOf("/");if(y<0)return T(`the requested upstream branch '${w}' does not exist`);let k=w.slice(0,y),C=w.slice(y+1);if(!await F(s,`refs/remotes/${w}`))return T(`the requested upstream branch '${w}' does not exist`);let O=await ae(s),E=`branch "${x}"`;return O[E]||(O[E]={}),O[E].remote=k,O[E].merge=`refs/heads/${C}`,await Ge(s,O),{stdout:"",stderr:`branch '${x}' set up to track '${w}'.
|
|
127
|
-
`,exitCode:0}}if(n.name&&!n.remotes&&!n.all){let w=n.newName,x;if(w){let C=await ye(s,w,`not a valid object name: '${w}'`);if(S(C))return C;x=C.hash}else if(x=await X(s),!x)return T("Not a valid object name: 'HEAD'.");let b=`refs/heads/${n.name}`;if(await F(s,b))return T(`a branch named '${n.name}' already exists`);await Y(s,b,x);let k=w??"HEAD";return await ee(s,r.env,b,null,x,`branch: Created from ${k}`),{stdout:"",stderr:"",exitCode:0}}let d=n.verbose||0,u=!n.remotes||n.all,l=n.remotes||n.all,m=[];if(u&&!i){let w=await X(s);if(w){let x=await gt(s),b;if(x){let y=await nt(s);if(y?.headName){let k=de(y.headName);if(k==="detached HEAD"){let C=await
|
|
137
|
+
`,exitCode:0}}if(n.name&&!n.remotes&&!n.all){let w=n.newName,x;if(w){let C=await ye(s,w,`not a valid object name: '${w}'`);if(S(C))return C;x=C.hash}else if(x=await X(s),!x)return T("Not a valid object name: 'HEAD'.");let b=`refs/heads/${n.name}`;if(await F(s,b))return T(`a branch named '${n.name}' already exists`);await Y(s,b,x);let k=w??"HEAD";return await ee(s,r.env,b,null,x,`branch: Created from ${k}`),{stdout:"",stderr:"",exitCode:0}}let d=n.verbose||0,u=!n.remotes||n.all,l=n.remotes||n.all,m=[];if(u&&!i){let w=await X(s);if(w){let x=await gt(s),b;if(x){let y=await nt(s);if(y?.headName){let k=de(y.headName);if(k==="detached HEAD"){let C=await ir(s);b=`(no branch, rebasing detached HEAD ${C?K(C):"(null)"})`}else b=`(no branch, rebasing ${k})`}else b="(no branch)"}else{let y=await ir(s);y?b=`(HEAD detached ${w===y?"at":"from"} ${K(y)})`:b="(no branch)"}m.push({displayName:b,hash:w,isCurrent:!0,branchName:null})}}if(u){let w=await le(s,"refs/heads");for(let x of w){let b=de(x.name);m.push({displayName:b,hash:x.hash,isCurrent:b===i,branchName:b})}}if(l){let w=await le(s,"refs/remotes");for(let x of w){let b=x.name.replace("refs/remotes/","");m.push({displayName:n.all?`remotes/${b}`:b,hash:x.hash,isCurrent:!1,branchName:null})}}if(m.length===0)return{stdout:"",stderr:"",exitCode:0};if(d===0)return{stdout:`${m.map(x=>x.isCurrent?`* ${x.displayName}`:` ${x.displayName}`).join(`
|
|
128
138
|
`)}
|
|
129
|
-
`,stderr:"",exitCode:0};let h=d>=1?await ae(s):null,p=Math.max(...m.map(w=>w.displayName.length)),g=[];for(let w of m){let x=w.isCurrent?"* ":" ",b=w.displayName.padEnd(p),y=K(w.hash),k="";try{let P=await M(s,w.hash);k=ue(P.message)}catch{}let C="";if(h&&w.branchName){let P=await Ut(s,h,w.branchName);if(P){let O=
|
|
139
|
+
`,stderr:"",exitCode:0};let h=d>=1?await ae(s):null,p=Math.max(...m.map(w=>w.displayName.length)),g=[];for(let w of m){let x=w.isCurrent?"* ":" ",b=w.displayName.padEnd(p),y=K(w.hash),k="";try{let P=await M(s,w.hash);k=ue(P.message)}catch{}let C="";if(h&&w.branchName){let P=await Ut(s,h,w.branchName);if(P){let O=wa(P,d>=2);O&&(C=` ${O}`)}}g.push(`${x}${b} ${y}${C} ${k}`)}return{stdout:`${g.join(`
|
|
130
140
|
`)}
|
|
131
|
-
`,stderr:"",exitCode:0}}})}async function
|
|
141
|
+
`,stderr:"",exitCode:0}}})}async function rs(e){let t=await Me(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]){let s=o[1],a=`refs/heads/${s}`,i=await F(e,a);if(i)return{name:s,refName:a,hash:i}}}return null}async function Bt(e){let t="";return await F(e,"CHERRY_PICK_HEAD")&&(t=`warning: cancelling a cherry picking in progress
|
|
132
142
|
`),await F(e,"REVERT_HEAD")&&(t+=`warning: cancelling a revert in progress
|
|
133
|
-
`),await wn(e),t}function
|
|
143
|
+
`),await wn(e),t}function hl(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(`
|
|
134
144
|
`)}
|
|
135
|
-
`:""}function on(e){return e.entries.some(t=>t.stage>0)?{stdout:
|
|
136
|
-
`,exitCode:1}:null}async function
|
|
145
|
+
`:""}function on(e){return e.entries.some(t=>t.stage>0)?{stdout:hl(e),stderr:`error: you need to resolve your current index first
|
|
146
|
+
`,exitCode:1}:null}async function ss(e,t,n,r){if(!e.workTree)return T("this operation must be run in a work tree");if(r)return pl(e,t,n,r);let o=await U(e);if(t.some(Ve)){let a=t.map(c=>Oe(c,n)),i=o.entries.filter(c=>c.stage===0&&me(a,c.path));if(i.length===0)return j(`error: pathspec '${t[0]}' did not match any file(s) known to git
|
|
137
147
|
`);for(let c of i)await ve(e,{path:c.path,hash:c.hash,mode:c.mode})}else for(let a of t){let i=Dt(o,a);if(!i)return o.entries.some(f=>f.path===a&&f.stage>0)?j(`error: path '${a}' is unmerged
|
|
138
148
|
`):j(`error: pathspec '${a}' did not match any file(s) known to git
|
|
139
|
-
`);await ve(e,{path:i.path,hash:i.hash,mode:i.mode})}return{stdout:"",stderr:"",exitCode:0}}async function
|
|
149
|
+
`);await ve(e,{path:i.path,hash:i.hash,mode:i.mode})}return{stdout:"",stderr:"",exitCode:0}}async function pl(e,t,n,r){let o=await se(e,r),s=await U(e),a=t.some(Ve),i=[];if(a){let c=t.map(f=>Oe(f,n));for(let[f]of o)me(c,f)&&i.push(f);if(i.length===0)return j(`error: pathspec '${t[0]}' did not match any file(s) known to git
|
|
140
150
|
`)}else for(let c of t){if(!o.get(c))return j(`error: pathspec '${c}' did not match any file(s) known to git
|
|
141
|
-
`);i.push(c)}for(let c of i){let f=o.get(c);f&&(await ve(e,{path:f.path,hash:f.hash,mode:f.mode}),s=Xe(s,{path:f.path,hash:f.hash,mode:parseInt(f.mode,8),stage:0,stat:pe()}))}return await re(e,s),{stdout:"",stderr:"",exitCode:0}}async function
|
|
142
|
-
`);for(let d of f){let u=a.entries.find(h=>h.path===d&&h.stage===r),l=!u&&a.entries.find(h=>h.path===d&&h.stage===0),m=u||l;if(m)await ve(e,{path:m.path,hash:m.hash,mode:m.mode});else if(s){let h=
|
|
151
|
+
`);i.push(c)}for(let c of i){let f=o.get(c);f&&(await ve(e,{path:f.path,hash:f.hash,mode:f.mode}),s=Xe(s,{path:f.path,hash:f.hash,mode:parseInt(f.mode,8),stage:0,stat:pe()}))}return await re(e,s),{stdout:"",stderr:"",exitCode:0}}async function os(e,t,n,r,o){if(!e.workTree)return T("this operation must be run in a work tree");let s=o?.deleteOnMissing??!1,a=await U(e);if(t.some(Ve)){let c=t.map(d=>Oe(d,n)),f=new Set;for(let d of a.entries)me(c,d.path)&&f.add(d.path);if(f.size===0)return j(`error: pathspec '${t[0]}' did not match any file(s) known to git
|
|
152
|
+
`);for(let d of f){let u=a.entries.find(h=>h.path===d&&h.stage===r),l=!u&&a.entries.find(h=>h.path===d&&h.stage===0),m=u||l;if(m)await ve(e,{path:m.path,hash:m.hash,mode:m.mode});else if(s){let h=H(e.workTree,d);await e.fs.exists(h)&&await e.fs.rm(h)}}}else for(let c of t)if(a.entries.some(d=>d.path===c&&d.stage>0)){let d=a.entries.find(u=>u.path===c&&u.stage===r);if(d)await ve(e,{path:d.path,hash:d.hash,mode:d.mode});else if(s){let u=H(e.workTree,c);await e.fs.exists(u)&&await e.fs.rm(u)}else return j(`error: path '${c}' does not have ${r===2?"our":"their"} version
|
|
143
153
|
`)}else{let d=Dt(a,c);if(!d)return j(`error: pathspec '${c}' did not match any file(s) known to git
|
|
144
|
-
`);await ve(e,{path:d.path,hash:d.hash,mode:d.mode})}return{stdout:"",stderr:"",exitCode:0}}async function En(e,t,n){if(!e.workTree)return"";let r=await He(e,t),o=new Map;for(let c of r)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 a=new Map;for(let[c]of s){let f=
|
|
154
|
+
`);await ve(e,{path:d.path,hash:d.hash,mode:d.mode})}return{stdout:"",stderr:"",exitCode:0}}async function En(e,t,n){if(!e.workTree)return"";let r=await He(e,t),o=new Map;for(let c of r)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 a=new Map;for(let[c]of s){let f=H(e.workTree,c);if(await e.fs.exists(f)){if((await e.fs.stat(f)).isFile){let u=await e.fs.readFileBuffer(f);a.set(c,await st("blob",u))}}else a.set(c,null)}let i=[];for(let[c,f]of o){let d=s.get(c);if(d===void 0){i.push(`D ${c}`);continue}let u=a.get(c);u===null?i.push(`D ${c}`):(d!==f||u!==void 0&&u!==f)&&i.push(`M ${c}`)}for(let[c]of s)o.has(c)||a.get(c)!=null&&i.push(`A ${c}`);return i.length===0?"":(i.sort((c,f)=>{let d=c.slice(2),u=f.slice(2);return d<u?-1:d>u?1:0}),`${i.join(`
|
|
145
155
|
`)}
|
|
146
|
-
`)}var
|
|
156
|
+
`)}var ya=5;function gl(e){let t=e.length,n=t===1?"commit":"commits",r=t===1?"it":"them",o=t>ya?ya-1:t,a=e.slice(0,o).map(c=>` ${K(c.hash)} ${c.subject}`),i=t-o;return i>0&&a.push(` ... and ${i} more.`),`Warning: you are leaving ${t} ${n} behind, not connected to
|
|
147
157
|
any of your branches:
|
|
148
158
|
|
|
149
159
|
${a.join(`
|
|
@@ -154,10 +164,10 @@ to do so with:
|
|
|
154
164
|
|
|
155
165
|
git branch <new-branch-name> ${K(e[0].hash)}
|
|
156
166
|
|
|
157
|
-
`}async function
|
|
158
|
-
`}async function
|
|
159
|
-
`,exitCode:0};let i=await U(e),c=on(i);if(c)return c;let f=await X(e),u=(await M(e,r)).tree,l=null;if(f&&(l=(await M(e,f)).tree),l!==u){let b=await Qt(e,l,u,i);if(!b.success)return b.errorOutput??j("error: checkout would overwrite local changes");i={version:2,entries:b.newEntries},await re(e,i),await be(e,b.worktreeOps)}let m="";a?.type==="direct"&&f&&(m=await
|
|
160
|
-
${p}`,exitCode:0}}async function
|
|
167
|
+
`}async function ho(e,t){let n=await M(e,t);return`Previous HEAD position was ${K(t)} ${ue(n.message)}
|
|
168
|
+
`}async function is(e,t,n){let r=await ha(e,t,{targetHash:n});return r.length>0?gl(r):t!==n?ho(e,t):""}async function as(e,t,n,r,o,s){let a=await J(e);if(a?.type==="symbolic"&&a.target===n)return{stdout:"",stderr:`Already on '${t}'
|
|
169
|
+
`,exitCode:0};let i=await U(e),c=on(i);if(c)return c;let f=await X(e),u=(await M(e,r)).tree,l=null;if(f&&(l=(await M(e,f)).tree),l!==u){let b=await Qt(e,l,u,i);if(!b.success)return b.errorOutput??j("error: checkout would overwrite local changes");i={version:2,entries:b.newEntries},await re(e,i),await be(e,b.worktreeOps)}let m="";a?.type==="direct"&&f&&(m=await is(e,f,r));let h=a?.type==="symbolic"?a.target.replace(/^refs\/heads\//,""):f??Z;await $e(e,"HEAD",n),await tt(e);let p=await Bt(e);await ee(e,o,"HEAD",f,r,`checkout: moving from ${h} to ${t}`),await s?.hooks?.emitPost("post-checkout",{prevHead:f,newHead:r,isBranchCheckout:!0});let g=await En(e,u,i),w=await ae(e),x=await Ut(e,w,t);return x&&(g+=yn(x)),{stdout:g,stderr:`${m}Switched to branch '${t}'
|
|
170
|
+
${p}`,exitCode:0}}async function cs(e,t,n,r,o){let s=await U(e),a=on(s);if(a)return a;let i=await X(e),c=await M(e,t),f=c.tree,d=null;if(i&&(d=(await M(e,i)).tree),d!==f){let b=await Qt(e,d,f,s);if(!b.success)return b.errorOutput??j("error: checkout would overwrite local changes");s={version:2,entries:b.newEntries},await re(e,s),await be(e,b.worktreeOps)}let u=await J(e),l=u?.type==="direct"&&i===t;if(await Y(e,"HEAD",t),!l){await aa(e,t);let b=u?.type==="symbolic"?u.target.replace(/^refs\/heads\//,""):i??Z;await ee(e,n,"HEAD",i,t,`checkout: moving from ${b} to ${t}`)}let m=await Bt(e);await r?.hooks?.emitPost("post-checkout",{prevHead:i,newHead:t,isBranchCheckout:!1});let h=K(t),p=ue(c.message),g=u?.type==="direct",w="";return g&&i&&i!==t&&(w+=await is(e,i,t)),g||!o?.detachAdviceTarget?w+=`HEAD is now at ${h} ${p}
|
|
161
171
|
`:w=`Note: switching to '${o.detachAdviceTarget}'.
|
|
162
172
|
|
|
163
173
|
You are in 'detached HEAD' state. You can look around, make experimental
|
|
@@ -176,18 +186,18 @@ Or undo this operation with:
|
|
|
176
186
|
Turn off this advice by setting config variable advice.detachedHead to false
|
|
177
187
|
|
|
178
188
|
HEAD is now at ${h} ${p}
|
|
179
|
-
`,w+=m,{stdout:await En(e,f,s),stderr:w,exitCode:0}}function
|
|
180
|
-
`)}})}async function
|
|
181
|
-
${d}`,exitCode:0}}async function
|
|
189
|
+
`,w+=m,{stdout:await En(e,f,s),stderr:w,exitCode:0}}function Ea(e,t){e.command("checkout",{description:"Switch branches or restore working tree files",args:[W.string().name("target").describe("Branch name or path to checkout").optional()],options:{branch:v().alias("b").describe("Create and switch to a new branch"),forceBranch:v().alias("B").describe("Create/reset and switch to a new branch"),orphan:v().describe("Create a new orphan branch"),ours:v().describe("Checkout our version for unmerged files"),theirs:v().describe("Checkout their version for unmerged files")},handler:async(n,r,o)=>{let s=await B(r.fs,r.cwd,t);if(S(s))return s;let a=s,i=n.target;if(n.ours&&n.theirs)return T("--ours and --theirs are incompatible");if(o.passthrough.length>0){let u=Ze(a,r.cwd),l=o.passthrough,m=null;if(i){if(n.ours||n.theirs)return T("cannot specify both a revision and --ours/--theirs");let h=await ye(a,i,`invalid reference: ${i}`);if(S(h))return h;m=h.commit.tree}return n.ours||n.theirs?os(a,l,u,n.theirs?3:2):ss(a,l,u,m)}if(n.orphan)return n.branch?T("--orphan and -b are incompatible"):n.ours||n.theirs?T("--orphan and --ours/--theirs are incompatible"):i?bl(a,i,r.env,t):T("you must specify a branch to checkout");if(!i)return T("you must specify a branch to checkout");if(n.branch||n.forceBranch)return yl(a,i,r.env,t,!!n.forceBranch);if(i==="-")return wl(a,r.env,t);let c=`refs/heads/${i}`,f=await F(a,c);if(f)return xa(a,i,c,f,r.env,t);let d=await je(a,i);if(d){let u=await Re(a,d);return El(a,i,u,r.env,t)}if(a.workTree){let u=await U(a),l=Dt(u,i);if(l)return await ve(a,{path:l.path,hash:l.hash,mode:l.mode}),{stdout:"",stderr:"",exitCode:0}}return j(`error: pathspec '${i}' did not match any file(s) known to git
|
|
190
|
+
`)}})}async function wl(e,t,n){let r=await rs(e);return r?xa(e,r.name,r.refName,r.hash,t,n):T("no previous branch")}async function bl(e,t,n,r){let o=`refs/heads/${t}`;if(await F(e,o))return T(`a branch named '${t}' already exists`);let a=await U(e),i=on(a);if(i)return i;let c=await X(e),f=null;c&&(f=(await M(e,c)).tree),await $e(e,"HEAD",o),await tt(e);let d=await Bt(e);await r?.hooks?.emitPost("post-checkout",{prevHead:c,newHead:Z,isBranchCheckout:!0});let u="";return f&&(u=await En(e,f,a)),{stdout:u,stderr:`Switched to a new branch '${t}'
|
|
191
|
+
${d}`,exitCode:0}}async function yl(e,t,n,r,o=!1){if(r?.hooks){let p=await r.hooks.emitPre("pre-checkout",{target:t,mode:"create-branch"});if(p)return{stdout:"",stderr:p.message??"",exitCode:1}}let s=await J(e),a=await X(e),i=`refs/heads/${t}`,c=await F(e,i);if(c&&!o)return T(`a branch named '${t}' already exists`);if(o){let p=await U(e),g=on(p);if(g)return g}a&&await Y(e,i,a),await $e(e,"HEAD",i),await tt(e);let f=await Bt(e),d=s?.type==="symbolic"?s.target.replace(/^refs\/heads\//,""):a??Z;a&&await ee(e,n,i,c,a,c?"branch: Reset to HEAD":"branch: Created from HEAD"),await ee(e,n,"HEAD",a,a??Z,`checkout: moving from ${d} to ${t}`),await r?.hooks?.emitPost("post-checkout",{prevHead:a,newHead:a??Z,isBranchCheckout:!0});let u="";if(o&&a){let p=await U(e),g=await M(e,a);u=await En(e,g.tree,p)}let l=await ae(e),m=await Ut(e,l,t);m&&(u+=yn(m));let h=c?`Switched to and reset branch '${t}'
|
|
182
192
|
`:`Switched to a new branch '${t}'
|
|
183
|
-
`;return{stdout:u,stderr:`${h}${f}`,exitCode:0}}async function
|
|
193
|
+
`;return{stdout:u,stderr:`${h}${f}`,exitCode:0}}async function xa(e,t,n,r,o,s){if(s?.hooks){let a=await s.hooks.emitPre("pre-checkout",{target:t,mode:"switch"});if(a)return{stdout:"",stderr:a.message??"",exitCode:1}}return as(e,t,n,r,o,s)}async function El(e,t,n,r,o){if(o?.hooks){let s=await o.hooks.emitPre("pre-checkout",{target:t,mode:"detach"});if(s)return{stdout:"",stderr:s.message??"",exitCode:1}}return cs(e,n,r,o,{detachAdviceTarget:t})}function po(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}=ro(e,t);return ka(o,e,s,t),ka(s,t,o,e),xl(o,n,s,r)}function xl(e,t,n,r){let o=[],s=0,a=0;for(;s<t||a<r;){for(;s<t&&a<r&&!e[s]&&!n[a];)s++,a++;if(s>=t&&a>=r)break;let i=s,c=a;for(;s<t&&e[s];)s++;for(;a<r&&n[a];)a++;(s>i||a>c)&&o.push({buffer1:[i,s-i],buffer2:[c,a-c]})}return o}function ka(e,t,n,r){let o=t.length,s=r.length,a=0,i=0;for(;i<o&&e[i];)i++;let c=0,f=0;for(;f<s&&n[f];)f++;for(;;){if(i===a){if(i>=o)break;for(a=i+1,i=a;i<o&&e[i];)i++;if(f>=s)break;for(c=f+1,f=c;f<s&&n[f];)f++;continue}let d,u,l;do{for(d=i-a,l=-1;a>0&&i>0&&t[a-1]===t[i-1];){for(e[--a]=1,e[--i]=0;a>0&&e[a-1];)a--;if(c===0)break;for(f=c-1,c=f;c>0&&n[c-1];)c--}for(u=i,f>c&&(l=i);i<o&&t[a]===t[i];){for(e[a++]=0,e[i++]=1;i<o&&e[i];)i++;if(f>=s)break;for(c=f+1,f=c;f<s&&n[f];)f++;f>c&&(l=i)}}while(d!==i-a);if(i!==u&&l!==-1)for(;f===c&&!(a<=0||t[a-1]!==t[i-1]);){for(e[--a]=1,e[--i]=0;a>0&&e[a-1];)a--;if(c===0)break;for(f=c-1,c=f;c>0&&n[c-1];)c--}if(i>=o)break;for(a=i+1,i=a;i<o&&e[i];)i++;if(f>=s)break;for(c=f+1,f=c;f<s&&n[f];)f++}}function kl(e,t,n){let r=[];for(let c of po(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 po(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 a(c){c>s&&(o.push({stable:!0,buffer:"o",bufferStart:s,bufferLength:c-s,content:t.slice(s,c)}),s=c)}let i=0;for(;i<r.length;){let c=r[i++],f=c.oStart,d=c.oStart+c.oLength,u=[c];for(a(f);i<r.length;){let l=r[i];if(l.oStart>d)break;d=Math.max(d,l.oStart+l.oLength),u.push(l),i++}if(u.length===1){if(c.abLength>0){let l=c.ab==="a"?e:n;o.push({stable:!0,buffer:c.ab,bufferStart:c.abStart,bufferLength:c.abLength,content:l.slice(c.abStart,c.abStart+c.abLength)})}}else{let l={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 u){let x=w.oStart,b=x+w.oLength,y=w.abStart,k=y+w.abLength,C=l[w.ab];C.abMin=Math.min(y,C.abMin),C.abMax=Math.max(k,C.abMax),C.oMin=Math.min(x,C.oMin),C.oMax=Math.max(b,C.oMax)}let m=l.a.abMin+(f-l.a.oMin),h=l.a.abMax+(d-l.a.oMax),p=l.b.abMin+(f-l.b.oMin),g=l.b.abMax+(d-l.b.oMax);o.push({stable:!1,a:e.slice(m,h),o:t.slice(f,d),b:n.slice(p,g)})}s=d}return a(t.length),o}function Cl(e,t,n,r){let o=r?.excludeFalseConflicts??!0,s=kl(e,t,n),a=[],i=[];function c(){i.length&&(a.push({type:"ok",lines:i}),i=[])}for(let f of s)f.stable?i.push(...f.content):o&&Ca(f.a,f.b)?i.push(...f.a):(c(),a.push({type:"conflict",a:f.a,o:f.o,b:f.b}));return c(),Rl(Pl(a))}function ar(e,t,n,r){let o=r?.markerSize??7,s=`${"<".repeat(o)}${r?.a?` ${r.a}`:""}`,a="=".repeat(o),i=`${">".repeat(o)}${r?.b?` ${r.b}`:""}`,c=Cl(e,t,n),f=!1,d=[];for(let u of c)u.type==="ok"?d.push(...u.lines):(f=!0,d.push(s,...u.a,a,...u.b,i));return{conflict:f,result:d}}function Pl(e){let t=[];for(let n of e)n.type==="ok"?t.push(n):t.push(...Ol(n));return t}function Ol(e){let{a:t,b:n}=e;if(t.length===0||n.length===0)return[e];if(Ca(t,n))return[e];let r=po(t,n);if(r.length===0)return[{type:"ok",lines:t}];let o=[],s=0;for(let i of r){let c=i.buffer1[0];c-s>0&&o.push({type:"ok",lines:t.slice(s,c)});let d=c+i.buffer1[1],u=i.buffer2[0]+i.buffer2[1];o.push({type:"conflict",a:t.slice(c,d),o:[],b:n.slice(i.buffer2[0],u)}),s=d}return t.length-s>0&&o.push({type:"ok",lines:t.slice(s)}),o.length===1&&o[0].type==="conflict"?[e]:o}function Rl(e){if(e.length<3)return e;let t=[e[0]];for(let n=1;n<e.length;n++){let r=t[t.length-1],o=e[n];if(r.type==="conflict"&&o.type==="ok"&&o.lines.length<=3&&n+1<e.length&&e[n+1].type==="conflict"){let s=e[n+1],a=r;a.a=[...r.a,...o.lines,...s.a],a.b=[...r.b,...o.lines,...s.b],a.o=[...r.o,...o.lines,...s.o],n++}else t.push(o)}return t}function xn(e,t,n,r){let o=ar(it(e),it(t),it(n),{a:r.a,b:r.b,markerSize:r.markerSize}),a=(o.result[o.result.length-1]??"").endsWith("\0"),i=o.result.map(go);return(i[i.length-1]??"").startsWith(">>>>>>>")||!a?`${i.join(`
|
|
184
194
|
`)}
|
|
185
195
|
`:i.join(`
|
|
186
196
|
`)}function it(e){if(e==="")return[];let t=e.split(`
|
|
187
|
-
`);if(t[t.length-1]==="")t.pop();else{let n=t[t.length-1]??"";t[t.length-1]=`${n}\0`}return t}function po(e){return e.endsWith("\0")?e.slice(0,-1):e}function ka(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}var Ln=new TextDecoder,an=new TextEncoder,Ca={name:"virtual",email:"virtual@merge",timestamp:0,timezone:"+0000"};async function wt(e,t,n,r,o){let{paths:s,baseMap:a,oursMap:i,theirsMap:c}=await Il(e,t,n,r),f=await Tl(e,s,a,i,c,o);return Hl(e,s,o,f)}async function fr(e,t,n,r){let o=await ht(e,t,n),s=await M(e,t),a=await M(e,n);if(o.length===0)return{...await wt(e,null,s.tree,a.tree,r),baseTree:null};if(o.length===1){let f=await M(e,o[0]);return{...await wt(e,f.tree,s.tree,a.tree,r),baseTree:f.tree}}let i=await va(e,t,n,o,1);return{...await wt(e,i,s.tree,a.tree,r),baseTree:i}}async function Il(e,t,n,r){let o=await se(e,t),s=await se(e,n),a=await se(e,r),i=new Set;for(let f of o.keys())i.add(f);for(let f of s.keys())i.add(f);for(let f of a.keys())i.add(f);let c=new Map;for(let f of i){let d=o.get(f)??null,u=s.get(f)??null,l=a.get(f)??null,m=d?{hash:d.hash,mode:d.mode}:null,h=u?{hash:u.hash,mode:u.mode}:null,p=l?{hash:l.hash,mode:l.mode}:null,g=(d?1:0)|(u?2:0)|(l?4:0),w=d?.hash??null,x=u?.hash??null,b=l?.hash??null,y=0;w!==null&&w===x&&(y|=3),w!==null&&w===b&&(y|=5),x!==null&&x===b&&(y|=6);let k={path:f,stages:[m,h,p],pathnames:[f,f,f],filemask:g,matchMask:y,merged:{result:null,clean:!1},pathConflict:!1};if($l(k)){c.set(f,k);continue}c.set(f,k)}return{paths:c,baseMap:o,oursMap:s,theirsMap:a}}function $l(e){let[t,n,r]=e.stages,o=t?.hash??null,s=n?.hash??null,a=r?.hash??null;return s===o&&a===o?(n?e.merged={result:{hash:s,mode:n.mode},clean:!0}:e.merged={result:null,clean:!0},!0):s===a&&s!==null?(e.merged={result:{hash:s,mode:n.mode},clean:!0},!0):s===null&&a===null?(e.merged={result:null,clean:!0},!0):a===o&&s!==o?(n?e.merged={result:{hash:s,mode:n.mode},clean:!0}:e.merged={result:null,clean:!0},!0):s===o&&a!==o?(r?e.merged={result:{hash:a,mode:r.mode},clean:!0}:e.merged={result:null,clean:!0},!0):!1}async function Tl(e,t,n,r,o,s){let a={entries:[],conflicts:[],msgBuf:[],worktreeBlobs:new Map},i=[],c=[];for(let[D,$]of n)r.has(D)||i.push({path:D,status:"deleted",oldHash:$.hash,oldMode:$.mode}),o.has(D)||c.push({path:D,status:"deleted",oldHash:$.hash,oldMode:$.mode});for(let[D,$]of r)n.has(D)||i.push({path:D,status:"added",newHash:$.hash,newMode:$.mode});for(let[D,$]of o)n.has(D)||c.push({path:D,status:"added",newHash:$.hash,newMode:$.mode});let f=await Ye(e,i),d=await Ye(e,c);if(f.renames.length===0&&d.renames.length===0)return a;let u=new Map,l=new Map;for(let D of f.renames)u.set(D.oldPath,D);for(let D of d.renames)l.set(D.oldPath,D);let m=new Set;for(let[D]of r)!n.has(D)&&o.has(D)&&m.add(D);let h=new Set,p=s?.a??"HEAD",g=s?.b??"theirs";function w(D,$,R=0){a.msgBuf.push({sortKey:D,subOrder:R,text:$})}for(let D of[...n.keys()].sort()){let $=u.get(D),R=l.get(D);if(!$&&!R)continue;let N=n.get(D);if(h.add(D),$&&R)if(h.add($.newPath),h.add(R.newPath),$.newPath===R.newPath){let q=r.get($.newPath),L=o.get(R.newPath);if(q.hash===L.hash)a.entries.push(rt($.newPath,q));else{let V=go(t,$.newPath);V.stages=[{hash:N.hash,mode:N.mode},{hash:q.hash,mode:q.mode},{hash:L.hash,mode:L.mode}],V.pathnames=[D,$.newPath,R.newPath],V.filemask=7,V.merged={result:null,clean:!1}}}else{let q=r.get($.newPath),L=o.get(R.newPath),V=await Aa(e,N,q,L,s);V.conflict&&w(D,`Auto-merging ${D}`,-1),a.conflicts.push({path:D,reason:"rename-rename",oursPath:$.newPath,theirsPath:R.newPath}),w(D,`CONFLICT (rename/rename): ${D} renamed to ${$.newPath} in ${p} and to ${R.newPath} in ${g}.`),a.entries.push(rt(D,N,1)),a.entries.push(We($.newPath,q.mode,V.hash,2)),a.entries.push(We(R.newPath,L.mode,V.hash,3)),a.worktreeBlobs.set($.newPath,{hash:V.hash,mode:q.mode}),a.worktreeBlobs.set(R.newPath,{hash:V.hash,mode:L.mode})}else if($){h.add($.newPath);let q=o.get(D),L=r.get($.newPath),V=m.has($.newPath);if(q)if(V)await Ta(e,a,$.newPath,D,N,L,q,r,o,!1,s);else if(q.hash===N.hash&&L.hash===N.hash)a.entries.push(rt($.newPath,L));else if(q.hash===N.hash)a.entries.push(rt($.newPath,L));else if(L.hash===N.hash)a.entries.push(We($.newPath,L.mode,q.hash));else{let oe=go(t,$.newPath);oe.stages=[{hash:N.hash,mode:N.mode},{hash:L.hash,mode:L.mode},{hash:q.hash,mode:q.mode}],oe.pathnames=[D,$.newPath,D],oe.filemask=7,oe.merged={result:null,clean:!1}}else{let oe=o.get($.newPath);if(a.conflicts.push({path:$.newPath,reason:"rename-delete",deletedBy:"theirs",oldPath:D}),w($.newPath,`CONFLICT (rename/delete): ${D} renamed to ${$.newPath} in ${p}, but deleted in ${g}.`),oe){a.conflicts.push({path:$.newPath,reason:"add-add"}),w($.newPath,`Auto-merging ${$.newPath}`,0),w($.newPath,`CONFLICT (add/add): Merge conflict in ${$.newPath}`,1),a.entries.push(rt($.newPath,L,2)),a.entries.push(rt($.newPath,oe,3));let Q=await cs(e,L.hash,oe.hash,L.mode,s);a.worktreeBlobs.set($.newPath,{hash:Q,mode:L.mode})}else a.entries.push(We($.newPath,N.mode,N.hash,1)),a.entries.push(rt($.newPath,L,2)),a.worktreeBlobs.set($.newPath,{hash:L.hash,mode:L.mode}),L.hash!==N.hash&&w($.newPath,`CONFLICT (modify/delete): ${$.newPath} deleted in ${g} and modified in ${p}. Version ${p} of ${$.newPath} left in tree.`,1)}}else if(R){h.add(R.newPath);let q=r.get(D),L=o.get(R.newPath),V=m.has(R.newPath);if(q)if(V)await Ta(e,a,R.newPath,D,N,q,L,r,o,!0,s);else if(q.hash===N.hash&&L.hash===N.hash)a.entries.push(rt(R.newPath,L));else if(q.hash===N.hash)a.entries.push(rt(R.newPath,L));else if(L.hash===N.hash)a.entries.push(We(R.newPath,L.mode,q.hash));else{let oe=go(t,R.newPath);oe.stages=[{hash:N.hash,mode:N.mode},{hash:q.hash,mode:q.mode},{hash:L.hash,mode:L.mode}],oe.pathnames=[D,D,R.newPath],oe.filemask=7,oe.merged={result:null,clean:!1}}else{let oe=r.get(R.newPath);if(a.conflicts.push({path:R.newPath,reason:"rename-delete",deletedBy:"ours",oldPath:D}),w(R.newPath,`CONFLICT (rename/delete): ${D} renamed to ${R.newPath} in ${g}, but deleted in ${p}.`),oe){a.conflicts.push({path:R.newPath,reason:"add-add"}),w(R.newPath,`Auto-merging ${R.newPath}`,0),w(R.newPath,`CONFLICT (add/add): Merge conflict in ${R.newPath}`,1),a.entries.push(rt(R.newPath,oe,2)),a.entries.push(rt(R.newPath,L,3));let Q=await cs(e,oe.hash,L.hash,oe.mode,s);a.worktreeBlobs.set(R.newPath,{hash:Q,mode:oe.mode})}else a.entries.push(We(R.newPath,N.mode,N.hash,1)),a.entries.push(rt(R.newPath,L,3)),a.worktreeBlobs.set(R.newPath,{hash:L.hash,mode:L.mode}),L.hash!==N.hash&&w(R.newPath,`CONFLICT (modify/delete): ${R.newPath} deleted in ${p} and modified in ${g}. Version ${g} of ${R.newPath} left in tree.`,1)}}}let x=new Set(f.renames.map(D=>D.newPath)),b=new Set(d.renames.map(D=>D.newPath)),y=Pa(n,r),k=Pa(n,o),C=Oa(y,o,n),P=Oa(k,r,n),O=Ra(f.renames,C),E=Ra(d.renames,P),I=Ia(O),H=Ia(E);for(let D of[...I.keys()])H.has(D)&&(I.delete(D),H.delete(D));let _=new Set(I.keys()),G=new Set(H.keys());if(H.size>0)for(let D of i){if(D.status!=="added"||x.has(D.path))continue;let $=$a(D.path,H,_);if(!$)continue;if(t.has($)||n.has($)||r.has($)||o.has($)){if(r.has($)){w($,`CONFLICT (implicit dir rename): Existing file/dir at ${$} in the way of implicit directory rename(s) putting the following path(s) there: ${D.path}.`,1);continue}let q=r.get(D.path),L=o.get($)??n.get($);a.entries.push(We($,q.mode,q.hash,2)),L&&a.entries.push(We($,L.mode,L.hash,3)),a.worktreeBlobs.set($,{hash:q.hash,mode:q.mode}),a.conflicts.push({path:$,reason:"add-add"}),w($,`CONFLICT (file location): ${D.path} added in ${p} inside a directory that was renamed in ${g}, suggesting it should perhaps be moved to ${$}.`,1);let V=t.get(D.path);V&&(V.merged={result:null,clean:!0}),h.add(D.path);continue}let R=r.get(D.path);a.entries.push(We($,R.mode,R.hash,2)),a.worktreeBlobs.set($,{hash:R.hash,mode:R.mode}),a.conflicts.push({path:$,reason:"directory-rename"}),w($,`CONFLICT (file location): ${D.path} added in ${p} inside a directory that was renamed in ${g}, suggesting it should perhaps be moved to ${$}.`,1);let N=t.get(D.path);N&&(N.merged={result:null,clean:!0}),h.add(D.path)}if(I.size>0)for(let D of c){if(D.status!=="added"||b.has(D.path))continue;let $=$a(D.path,I,G);if(!$)continue;if(t.has($)||n.has($)||r.has($)||o.has($)){if(o.has($)){w($,`CONFLICT (implicit dir rename): Existing file/dir at ${$} in the way of implicit directory rename(s) putting the following path(s) there: ${D.path}.`,1);continue}let q=o.get(D.path),L=r.get($)??n.get($);L&&a.entries.push(We($,L.mode,L.hash,2)),a.entries.push(We($,q.mode,q.hash,3)),a.worktreeBlobs.set($,{hash:q.hash,mode:q.mode}),a.conflicts.push({path:$,reason:"add-add"}),w($,`CONFLICT (file location): ${D.path} added in ${g} inside a directory that was renamed in ${p}, suggesting it should perhaps be moved to ${$}.`,1);let V=t.get(D.path);V&&(V.merged={result:null,clean:!0}),h.add(D.path);continue}let R=o.get(D.path);a.entries.push(We($,R.mode,R.hash,3)),a.worktreeBlobs.set($,{hash:R.hash,mode:R.mode}),a.conflicts.push({path:$,reason:"directory-rename"}),w($,`CONFLICT (file location): ${D.path} added in ${g} inside a directory that was renamed in ${p}, suggesting it should perhaps be moved to ${$}.`,1);let N=t.get(D.path);N&&(N.merged={result:null,clean:!0}),h.add(D.path)}let z=new Set(a.entries.map(D=>D.path));for(let D of z){let $=t.get(D);$&&($.merged={result:null,clean:!0})}for(let D of h){if(z.has(D))continue;let $=t.get(D);if(!$||$.merged.clean)continue;$.filemask===7&&!$.pathConflict||($.merged={result:null,clean:!0})}return a}function Pa(e,t){let n=new Set;for(let s of e.keys()){let a=at(s);for(;a;)n.add(a),a=at(a)}let r=new Set;for(let s of t.keys()){let a=at(s);for(;a;)r.add(a),a=at(a)}let o=new Set;for(let s of n)r.has(s)||o.add(s);return o}function Oa(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=at(o)??"";e.has(s)&&r.add(s)}for(let o of[...r]){let s=at(o);for(;s;)e.has(s)&&!r.has(s)&&r.add(s),s=at(s)}return r}function Ra(e,t){let n=new Map;for(let r of e){let o=at(r.oldPath),s=at(r.newPath),a=!0;for(;;){if(!a){let i=o.length+(o?1:0),c=s.length+(s?1:0),f=r.oldPath.slice(i,r.oldPath.indexOf("/",i)),d=r.newPath.slice(c,r.newPath.indexOf("/",c));if(f!==d)break}if(t.has(o)){let i=n.get(o);i||(i=new Map,n.set(o,i)),i.set(s,(i.get(s)??0)+1)}if(a=!1,!o||!s)break;o=at(o),s=at(s)}}return n}function Ia(e){let t=new Map;for(let[n,r]of e){let o=0,s=0,a=null;for(let[i,c]of r)c===o?s=o:c>o&&(o=c,a=i);o>0&&s!==o&&a!==null&&t.set(n,a)}return t}function $a(e,t,n){let r=at(e);for(;r;){let s=t.get(r);if(s!==void 0){if(n.has(s))return null;let a=e.slice(r.length+1);return s?`${s}/${a}`:a}r=at(r)}let o=t.get("");return o!==void 0&&!n.has(o)?`${o}/${e}`:null}function at(e){let t=e.lastIndexOf("/");return t===-1?"":e.slice(0,t)}async function Ta(e,t,n,r,o,s,a,i,c,f=!1,d){let u=f?i.get(n):c.get(n),l=f?a:s;if(u.hash===l.hash){t.entries.push(We(n,u.mode,u.hash)),t.msgBuf.push({sortKey:r,subOrder:0,text:`Auto-merging ${r}`});return}let h=await Aa(e,o,s,a,d,f?{oursPath:r,theirsPath:n}:{oursPath:n,theirsPath:r},8);if(u.hash===h.hash)t.entries.push(We(n,u.mode,h.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(rt(n,u,2)),t.entries.push(We(n,a.mode,h.hash,3));let p=await cs(e,u.hash,h.hash,u.mode,d);t.worktreeBlobs.set(n,{hash:p,mode:u.mode})}else{t.entries.push(We(n,s.mode,h.hash,2)),t.entries.push(rt(n,u,3));let p=await cs(e,h.hash,u.hash,s.mode,d);t.worktreeBlobs.set(n,{hash:p,mode:s.mode})}}async function Aa(e,t,n,r,o,s,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(Lt(t.mode)||Lt(n.mode)||Lt(r.mode))return{hash:n.hash,conflict:!0};let i=await fe(e,t.hash),c=await fe(e,n.hash),f=await fe(e,r.hash);if(Pe(c)||Pe(f)||Pe(i))return{hash:n.hash,conflict:!0};let d=it(i),u=it(c),l=it(f),m=ar(u,d,l);if(!m.conflict)return{hash:await bo(e,m.result),conflict:!1};let h=o?.a??"HEAD",p=o?.b??"theirs",g=s?.oursPath?`${h}:${s.oursPath}`:h,w=s?.theirsPath?`${p}:${s.theirsPath}`:p,x=xn(c,i,f,{a:g,b:w,markerSize:a??7});return{hash:await we(e,"blob",an.encode(x)),conflict:!0}}async function cs(e,t,n,r,o){let s=await fe(e,t),a=await fe(e,n),i=xn(s,"",a,{a:o?.a??"HEAD",b:o?.b??"theirs"});return we(e,"blob",an.encode(i))}function rt(e,t,n=0){return We(e,t.mode,t.hash,n)}function We(e,t,n,r=0){return{path:e,mode:parseInt(t,8),hash:n,stage:r,stat:pe()}}async function Hl(e,t,n,r){let o=[...r.entries],s=[...r.conflicts],a=[...r.msgBuf],i=new Map(r.worktreeBlobs);function c(m,h,p=0){a.push({sortKey:m,subOrder:p,text:h})}for(let m of[...t.keys()].sort()){let h=t.get(m);if(h.merged.clean){h.merged.result?.hash&&o.push(Ee(m,h.merged.result.hash,h.merged.result.mode));continue}await Al(e,h,n,o,s,c,i)}a.sort((m,h)=>(m.sortKey<h.sortKey?-1:m.sortKey>h.sortKey?1:0)||m.subOrder-h.subOrder);let f=a.map(m=>m.text),d=[],u=new Set;for(let m of o)m.stage===0&&(d.push(m),u.add(m.path));for(let[m,h]of i)u.has(m)||d.push(Ee(m,h.hash,h.mode));d.sort((m,h)=>he(m.path,h.path));let l=await ke(e,d);return{entries:o,conflicts:s,messages:f,resultTree:l}}async function Al(e,t,n,r,o,s,a){let i=t.path,[c,f,d]=t.stages,u=c?.hash??null,l=f?.hash??null,m=d?.hash??null;if(l===null&&m!==null&&u!==null){o.push({path:i,reason:"delete-modify",deletedBy:"ours"});let h=n?.a??"HEAD",p=n?.b??"theirs";s(i,`CONFLICT (modify/delete): ${i} deleted in ${h} and modified in ${p}. Version ${p} of ${i} left in tree.`),c&&r.push(Ee(i,u,c.mode,1)),r.push(Ee(i,m,d.mode,3)),a.set(i,{hash:m,mode:d.mode});return}if(m===null&&l!==null&&u!==null){o.push({path:i,reason:"delete-modify",deletedBy:"theirs"});let h=n?.b??"theirs",p=n?.a??"HEAD";s(i,`CONFLICT (modify/delete): ${i} deleted in ${h} and modified in ${p}. Version ${p} of ${i} left in tree.`),c&&r.push(Ee(i,u,c.mode,1)),r.push(Ee(i,l,f.mode,2)),a.set(i,{hash:l,mode:f.mode});return}if(u===null&&l!==null&&m!==null){if(l===m){r.push(Ee(i,l,f.mode));return}s(i,`Auto-merging ${i}`,0);let h=await fe(e,l),p=await fe(e,m);if(Pe(h)||Pe(p)){o.push({path:i,reason:"add-add"}),s(i,`warning: Cannot merge binary files: ${i} (${n?.a??"HEAD"} vs. ${n?.b??"theirs"})`,-1),s(i,`CONFLICT (add/add): Merge conflict in ${i}`,1),r.push(Ee(i,l,f.mode,2)),r.push(Ee(i,m,d.mode,3)),a.set(i,{hash:l,mode:f.mode});return}let g=it(""),w=it(h),x=it(p),b=ar(w,g,x,n);if(!b.conflict){let C=await bo(e,b.result);r.push(Ee(i,C,f.mode));return}o.push({path:i,reason:"add-add"}),s(i,`CONFLICT (add/add): Merge conflict in ${i}`,1),r.push(Ee(i,l,f.mode,2)),r.push(Ee(i,m,d.mode,3));let y=xn(h,"",p,{a:n?.a??"HEAD",b:n?.b??"theirs"}),k=await we(e,"blob",an.encode(y));a.set(i,{hash:k,mode:f.mode});return}if(u!==null&&l!==null&&m!==null){if(l===u){r.push(Ee(i,m,d.mode));return}if(m===u){r.push(Ee(i,l,f.mode));return}if(l===m){r.push(Ee(i,l,f.mode));return}if(s(i,`Auto-merging ${i}`,0),Lt(c.mode)||Lt(f.mode)||Lt(d.mode)){o.push({path:i,reason:"content"}),s(i,`CONFLICT (content): Merge conflict in ${i}`,1),r.push(Ee(i,u,c.mode,1)),r.push(Ee(i,l,f.mode,2)),r.push(Ee(i,m,d.mode,3)),a.set(i,{hash:l,mode:f.mode});return}let h=await fe(e,u),p=await fe(e,l),g=await fe(e,m);if(Pe(p)||Pe(g)||Pe(h)){o.push({path:i,reason:"content"}),s(i,`warning: Cannot merge binary files: ${i} (${n?.a??"HEAD"} vs. ${n?.b??"theirs"})`,-1),s(i,`CONFLICT (content): Merge conflict in ${i}`,1),r.push(Ee(i,u,c.mode,1)),r.push(Ee(i,l,f.mode,2)),r.push(Ee(i,m,d.mode,3)),a.set(i,{hash:l,mode:f.mode});return}let w=it(h),x=it(p),b=it(g),y=ar(x,w,b,n);if(y.conflict){let k=t.pathnames[1],C=t.pathnames[2],P=k!==i||C!==i,O={path:i,reason:"content"};P&&(k!==i&&(O.oursOrigPath=k),C!==i&&(O.theirsOrigPath=C)),o.push(O),s(i,`CONFLICT (content): Merge conflict in ${i}`,1),r.push(Ee(i,u,c.mode,1)),r.push(Ee(i,l,f.mode,2)),r.push(Ee(i,m,d.mode,3));let E=P?`${n?.a??"HEAD"}:${k}`:n?.a??"HEAD",I=P?`${n?.b??"theirs"}:${C}`:n?.b??"theirs",H=xn(p,h,g,{a:E,b:I}),_=await we(e,"blob",an.encode(H));a.set(i,{hash:_,mode:f.mode})}else{let k=await bo(e,y.result);r.push(Ee(i,k,f.mode))}return}}var vl=200;async function va(e,t,n,r,o){let s=await Promise.all(r.map(async d=>({hash:d,timestamp:(await M(e,d)).committer.timestamp})));s.sort((d,u)=>d.timestamp-u.timestamp);let a=s.map(d=>d.hash),i=a[0],c=i,f=(await M(e,i)).tree;for(let d=1;d<a.length;d++){let u=a[d],l=(await M(e,u)).tree,m=null;if(o>=vl)m=f;else{let g=await ht(e,c,u);g.length===0?m=null:g.length===1?m=(await M(e,g[0])).tree:m=await va(e,c,u,g,o+1)}let h=await wt(e,m,f,l);f=await Sl(e,h,o);let p=$t({type:"commit",tree:f,parents:[c,u],author:Ca,committer:Ca,message:"merged common ancestors"});c=await we(e,"commit",p)}return f}async function Sl(e,t,n){let r=t.entries.filter(i=>i.stage===0),o=new Map;for(let i of t.entries)i.stage>0&&o.set(`${i.path}\0${i.stage}`,i);let s=(i,c)=>o.get(`${i}\0${c}`),a={a:"Temporary merge branch 1",b:"Temporary merge branch 2",markerSize:7+n*2};for(let i of t.conflicts){if(i.reason==="delete-modify"||i.reason==="rename-delete"){let d=s(i.path,1);if(d){r.push({...d,stage:0});continue}}if(i.reason==="rename-rename"){let d=i.oursPath??i.path,u=i.theirsPath??i.path,l=s(i.path,1),m=s(d,2),h=s(u,3);if(m&&h){let p=Ln.decode((await ce(e,m.hash)).content),g=Ln.decode((await ce(e,h.hash)).content),w=l?Ln.decode((await ce(e,l.hash)).content):"",x=8+n*2,b=a.a??"Temporary merge branch 1",y=a.b??"Temporary merge branch 2",k=xn(p,w,g,{a:`${b}:${d}`,o:a.o,b:`${y}:${u}`,markerSize:x}),C=await we(e,"blob",an.encode(k));r.push({path:d,mode:m.mode,hash:C,stage:0,stat:pe()}),r.push({path:u,mode:h.mode,hash:C,stage:0,stat:pe()});continue}else if(m){r.push({...m,stage:0});continue}}let c=s(i.path,2),f=s(i.path,3);if(c&&f&&(i.reason==="content"||i.reason==="add-add")){let d=Ln.decode((await ce(e,c.hash)).content),u=Ln.decode((await ce(e,f.hash)).content),l=i.reason==="content"?s(i.path,1):null,m=l?Ln.decode((await ce(e,l.hash)).content):"",h=i.oursOrigPath||i.theirsOrigPath,p=a.a??"Temporary merge branch 1",g=a.b??"Temporary merge branch 2",w=h?`${p}:${i.oursOrigPath??i.path}`:p,x=h?`${g}:${i.theirsOrigPath??i.path}`:g,b=xn(d,m,u,{a:w,o:a.o,b:x,markerSize:a.markerSize}),y=await we(e,"blob",an.encode(b));r.push({path:i.path,mode:c.mode,hash:y,stage:0,stat:pe()})}else c?r.push({...c,stage:0}):f&&r.push({...f,stage:0})}return r.sort((i,c)=>he(i.path,c.path)),ke(e,r)}async function bo(e,t){let n=t.map(po);if(n.length===0)return we(e,"blob",an.encode(""));let s=(t[t.length-1]??"").endsWith("\0")?n.join(`
|
|
197
|
+
`);if(t[t.length-1]==="")t.pop();else{let n=t[t.length-1]??"";t[t.length-1]=`${n}\0`}return t}function go(e){return e.endsWith("\0")?e.slice(0,-1):e}function Ca(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}var Gn=new TextDecoder,an=new TextEncoder,Pa={name:"virtual",email:"virtual@merge",timestamp:0,timezone:"+0000"};async function wt(e,t,n,r,o){let{paths:s,baseMap:a,oursMap:i,theirsMap:c}=await $l(e,t,n,r),f=await Hl(e,s,a,i,c,o);return Al(e,s,o,f)}async function fr(e,t,n,r){let o=await ht(e,t,n),s=await M(e,t),a=await M(e,n);if(o.length===0)return{...await wt(e,null,s.tree,a.tree,r),baseTree:null};if(o.length===1){let f=await M(e,o[0]);return{...await wt(e,f.tree,s.tree,a.tree,r),baseTree:f.tree}}let i=await Sa(e,t,n,o,1);return{...await wt(e,i,s.tree,a.tree,r),baseTree:i}}async function $l(e,t,n,r){let o=await se(e,t),s=await se(e,n),a=await se(e,r),i=new Set;for(let f of o.keys())i.add(f);for(let f of s.keys())i.add(f);for(let f of a.keys())i.add(f);let c=new Map;for(let f of i){let d=o.get(f)??null,u=s.get(f)??null,l=a.get(f)??null,m=d?{hash:d.hash,mode:d.mode}:null,h=u?{hash:u.hash,mode:u.mode}:null,p=l?{hash:l.hash,mode:l.mode}:null,g=(d?1:0)|(u?2:0)|(l?4:0),w=d?.hash??null,x=u?.hash??null,b=l?.hash??null,y=0;w!==null&&w===x&&(y|=3),w!==null&&w===b&&(y|=5),x!==null&&x===b&&(y|=6);let k={path:f,stages:[m,h,p],pathnames:[f,f,f],filemask:g,matchMask:y,merged:{result:null,clean:!1},pathConflict:!1};if(Tl(k)){c.set(f,k);continue}c.set(f,k)}return{paths:c,baseMap:o,oursMap:s,theirsMap:a}}function Tl(e){let[t,n,r]=e.stages,o=t?.hash??null,s=n?.hash??null,a=r?.hash??null;return s===o&&a===o?(n?e.merged={result:{hash:s,mode:n.mode},clean:!0}:e.merged={result:null,clean:!0},!0):s===a&&s!==null?(e.merged={result:{hash:s,mode:n.mode},clean:!0},!0):s===null&&a===null?(e.merged={result:null,clean:!0},!0):a===o&&s!==o?(n?e.merged={result:{hash:s,mode:n.mode},clean:!0}:e.merged={result:null,clean:!0},!0):s===o&&a!==o?(r?e.merged={result:{hash:a,mode:r.mode},clean:!0}:e.merged={result:null,clean:!0},!0):!1}async function Hl(e,t,n,r,o,s){let a={entries:[],conflicts:[],msgBuf:[],worktreeBlobs:new Map},i=[],c=[];for(let[D,$]of n)r.has(D)||i.push({path:D,status:"deleted",oldHash:$.hash,oldMode:$.mode}),o.has(D)||c.push({path:D,status:"deleted",oldHash:$.hash,oldMode:$.mode});for(let[D,$]of r)n.has(D)||i.push({path:D,status:"added",newHash:$.hash,newMode:$.mode});for(let[D,$]of o)n.has(D)||c.push({path:D,status:"added",newHash:$.hash,newMode:$.mode});let f=await Ye(e,i),d=await Ye(e,c);if(f.renames.length===0&&d.renames.length===0)return a;let u=new Map,l=new Map;for(let D of f.renames)u.set(D.oldPath,D);for(let D of d.renames)l.set(D.oldPath,D);let m=new Set;for(let[D]of r)!n.has(D)&&o.has(D)&&m.add(D);let h=new Set,p=s?.a??"HEAD",g=s?.b??"theirs";function w(D,$,R=0){a.msgBuf.push({sortKey:D,subOrder:R,text:$})}for(let D of[...n.keys()].sort()){let $=u.get(D),R=l.get(D);if(!$&&!R)continue;let N=n.get(D);if(h.add(D),$&&R)if(h.add($.newPath),h.add(R.newPath),$.newPath===R.newPath){let q=r.get($.newPath),L=o.get(R.newPath);if(q.hash===L.hash)a.entries.push(rt($.newPath,q));else{let V=wo(t,$.newPath);V.stages=[{hash:N.hash,mode:N.mode},{hash:q.hash,mode:q.mode},{hash:L.hash,mode:L.mode}],V.pathnames=[D,$.newPath,R.newPath],V.filemask=7,V.merged={result:null,clean:!1}}}else{let q=r.get($.newPath),L=o.get(R.newPath),V=await va(e,N,q,L,s);V.conflict&&w(D,`Auto-merging ${D}`,-1),a.conflicts.push({path:D,reason:"rename-rename",oursPath:$.newPath,theirsPath:R.newPath}),w(D,`CONFLICT (rename/rename): ${D} renamed to ${$.newPath} in ${p} and to ${R.newPath} in ${g}.`),a.entries.push(rt(D,N,1)),a.entries.push(We($.newPath,q.mode,V.hash,2)),a.entries.push(We(R.newPath,L.mode,V.hash,3)),a.worktreeBlobs.set($.newPath,{hash:V.hash,mode:q.mode}),a.worktreeBlobs.set(R.newPath,{hash:V.hash,mode:L.mode})}else if($){h.add($.newPath);let q=o.get(D),L=r.get($.newPath),V=m.has($.newPath);if(q)if(V)await Ha(e,a,$.newPath,D,N,L,q,r,o,!1,s);else if(q.hash===N.hash&&L.hash===N.hash)a.entries.push(rt($.newPath,L));else if(q.hash===N.hash)a.entries.push(rt($.newPath,L));else if(L.hash===N.hash)a.entries.push(We($.newPath,L.mode,q.hash));else{let oe=wo(t,$.newPath);oe.stages=[{hash:N.hash,mode:N.mode},{hash:L.hash,mode:L.mode},{hash:q.hash,mode:q.mode}],oe.pathnames=[D,$.newPath,D],oe.filemask=7,oe.merged={result:null,clean:!1}}else{let oe=o.get($.newPath);if(a.conflicts.push({path:$.newPath,reason:"rename-delete",deletedBy:"theirs",oldPath:D}),w($.newPath,`CONFLICT (rename/delete): ${D} renamed to ${$.newPath} in ${p}, but deleted in ${g}.`),oe){a.conflicts.push({path:$.newPath,reason:"add-add"}),w($.newPath,`Auto-merging ${$.newPath}`,0),w($.newPath,`CONFLICT (add/add): Merge conflict in ${$.newPath}`,1),a.entries.push(rt($.newPath,L,2)),a.entries.push(rt($.newPath,oe,3));let Q=await fs(e,L.hash,oe.hash,L.mode,s);a.worktreeBlobs.set($.newPath,{hash:Q,mode:L.mode})}else a.entries.push(We($.newPath,N.mode,N.hash,1)),a.entries.push(rt($.newPath,L,2)),a.worktreeBlobs.set($.newPath,{hash:L.hash,mode:L.mode}),L.hash!==N.hash&&w($.newPath,`CONFLICT (modify/delete): ${$.newPath} deleted in ${g} and modified in ${p}. Version ${p} of ${$.newPath} left in tree.`,1)}}else if(R){h.add(R.newPath);let q=r.get(D),L=o.get(R.newPath),V=m.has(R.newPath);if(q)if(V)await Ha(e,a,R.newPath,D,N,q,L,r,o,!0,s);else if(q.hash===N.hash&&L.hash===N.hash)a.entries.push(rt(R.newPath,L));else if(q.hash===N.hash)a.entries.push(rt(R.newPath,L));else if(L.hash===N.hash)a.entries.push(We(R.newPath,L.mode,q.hash));else{let oe=wo(t,R.newPath);oe.stages=[{hash:N.hash,mode:N.mode},{hash:q.hash,mode:q.mode},{hash:L.hash,mode:L.mode}],oe.pathnames=[D,D,R.newPath],oe.filemask=7,oe.merged={result:null,clean:!1}}else{let oe=r.get(R.newPath);if(a.conflicts.push({path:R.newPath,reason:"rename-delete",deletedBy:"ours",oldPath:D}),w(R.newPath,`CONFLICT (rename/delete): ${D} renamed to ${R.newPath} in ${g}, but deleted in ${p}.`),oe){a.conflicts.push({path:R.newPath,reason:"add-add"}),w(R.newPath,`Auto-merging ${R.newPath}`,0),w(R.newPath,`CONFLICT (add/add): Merge conflict in ${R.newPath}`,1),a.entries.push(rt(R.newPath,oe,2)),a.entries.push(rt(R.newPath,L,3));let Q=await fs(e,oe.hash,L.hash,oe.mode,s);a.worktreeBlobs.set(R.newPath,{hash:Q,mode:oe.mode})}else a.entries.push(We(R.newPath,N.mode,N.hash,1)),a.entries.push(rt(R.newPath,L,3)),a.worktreeBlobs.set(R.newPath,{hash:L.hash,mode:L.mode}),L.hash!==N.hash&&w(R.newPath,`CONFLICT (modify/delete): ${R.newPath} deleted in ${p} and modified in ${g}. Version ${g} of ${R.newPath} left in tree.`,1)}}}let x=new Set(f.renames.map(D=>D.newPath)),b=new Set(d.renames.map(D=>D.newPath)),y=Oa(n,r),k=Oa(n,o),C=Ra(y,o,n),P=Ra(k,r,n),O=Ia(f.renames,C),E=Ia(d.renames,P),I=$a(O),A=$a(E);for(let D of[...I.keys()])A.has(D)&&(I.delete(D),A.delete(D));let _=new Set(I.keys()),G=new Set(A.keys());if(A.size>0)for(let D of i){if(D.status!=="added"||x.has(D.path))continue;let $=Ta(D.path,A,_);if(!$)continue;if(t.has($)||n.has($)||r.has($)||o.has($)){if(r.has($)){w($,`CONFLICT (implicit dir rename): Existing file/dir at ${$} in the way of implicit directory rename(s) putting the following path(s) there: ${D.path}.`,1);continue}let q=r.get(D.path),L=o.get($)??n.get($);a.entries.push(We($,q.mode,q.hash,2)),L&&a.entries.push(We($,L.mode,L.hash,3)),a.worktreeBlobs.set($,{hash:q.hash,mode:q.mode}),a.conflicts.push({path:$,reason:"add-add"}),w($,`CONFLICT (file location): ${D.path} added in ${p} inside a directory that was renamed in ${g}, suggesting it should perhaps be moved to ${$}.`,1);let V=t.get(D.path);V&&(V.merged={result:null,clean:!0}),h.add(D.path);continue}let R=r.get(D.path);a.entries.push(We($,R.mode,R.hash,2)),a.worktreeBlobs.set($,{hash:R.hash,mode:R.mode}),a.conflicts.push({path:$,reason:"directory-rename"}),w($,`CONFLICT (file location): ${D.path} added in ${p} inside a directory that was renamed in ${g}, suggesting it should perhaps be moved to ${$}.`,1);let N=t.get(D.path);N&&(N.merged={result:null,clean:!0}),h.add(D.path)}if(I.size>0)for(let D of c){if(D.status!=="added"||b.has(D.path))continue;let $=Ta(D.path,I,G);if(!$)continue;if(t.has($)||n.has($)||r.has($)||o.has($)){if(o.has($)){w($,`CONFLICT (implicit dir rename): Existing file/dir at ${$} in the way of implicit directory rename(s) putting the following path(s) there: ${D.path}.`,1);continue}let q=o.get(D.path),L=r.get($)??n.get($);L&&a.entries.push(We($,L.mode,L.hash,2)),a.entries.push(We($,q.mode,q.hash,3)),a.worktreeBlobs.set($,{hash:q.hash,mode:q.mode}),a.conflicts.push({path:$,reason:"add-add"}),w($,`CONFLICT (file location): ${D.path} added in ${g} inside a directory that was renamed in ${p}, suggesting it should perhaps be moved to ${$}.`,1);let V=t.get(D.path);V&&(V.merged={result:null,clean:!0}),h.add(D.path);continue}let R=o.get(D.path);a.entries.push(We($,R.mode,R.hash,3)),a.worktreeBlobs.set($,{hash:R.hash,mode:R.mode}),a.conflicts.push({path:$,reason:"directory-rename"}),w($,`CONFLICT (file location): ${D.path} added in ${g} inside a directory that was renamed in ${p}, suggesting it should perhaps be moved to ${$}.`,1);let N=t.get(D.path);N&&(N.merged={result:null,clean:!0}),h.add(D.path)}let z=new Set(a.entries.map(D=>D.path));for(let D of z){let $=t.get(D);$&&($.merged={result:null,clean:!0})}for(let D of h){if(z.has(D))continue;let $=t.get(D);if(!$||$.merged.clean)continue;$.filemask===7&&!$.pathConflict||($.merged={result:null,clean:!0})}return a}function Oa(e,t){let n=new Set;for(let s of e.keys()){let a=at(s);for(;a;)n.add(a),a=at(a)}let r=new Set;for(let s of t.keys()){let a=at(s);for(;a;)r.add(a),a=at(a)}let o=new Set;for(let s of n)r.has(s)||o.add(s);return o}function Ra(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=at(o)??"";e.has(s)&&r.add(s)}for(let o of[...r]){let s=at(o);for(;s;)e.has(s)&&!r.has(s)&&r.add(s),s=at(s)}return r}function Ia(e,t){let n=new Map;for(let r of e){let o=at(r.oldPath),s=at(r.newPath),a=!0;for(;;){if(!a){let i=o.length+(o?1:0),c=s.length+(s?1:0),f=r.oldPath.slice(i,r.oldPath.indexOf("/",i)),d=r.newPath.slice(c,r.newPath.indexOf("/",c));if(f!==d)break}if(t.has(o)){let i=n.get(o);i||(i=new Map,n.set(o,i)),i.set(s,(i.get(s)??0)+1)}if(a=!1,!o||!s)break;o=at(o),s=at(s)}}return n}function $a(e){let t=new Map;for(let[n,r]of e){let o=0,s=0,a=null;for(let[i,c]of r)c===o?s=o:c>o&&(o=c,a=i);o>0&&s!==o&&a!==null&&t.set(n,a)}return t}function Ta(e,t,n){let r=at(e);for(;r;){let s=t.get(r);if(s!==void 0){if(n.has(s))return null;let a=e.slice(r.length+1);return s?`${s}/${a}`:a}r=at(r)}let o=t.get("");return o!==void 0&&!n.has(o)?`${o}/${e}`:null}function at(e){let t=e.lastIndexOf("/");return t===-1?"":e.slice(0,t)}async function Ha(e,t,n,r,o,s,a,i,c,f=!1,d){let u=f?i.get(n):c.get(n),l=f?a:s;if(u.hash===l.hash){t.entries.push(We(n,u.mode,u.hash)),t.msgBuf.push({sortKey:r,subOrder:0,text:`Auto-merging ${r}`});return}let h=await va(e,o,s,a,d,f?{oursPath:r,theirsPath:n}:{oursPath:n,theirsPath:r},8);if(u.hash===h.hash)t.entries.push(We(n,u.mode,h.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(rt(n,u,2)),t.entries.push(We(n,a.mode,h.hash,3));let p=await fs(e,u.hash,h.hash,u.mode,d);t.worktreeBlobs.set(n,{hash:p,mode:u.mode})}else{t.entries.push(We(n,s.mode,h.hash,2)),t.entries.push(rt(n,u,3));let p=await fs(e,h.hash,u.hash,s.mode,d);t.worktreeBlobs.set(n,{hash:p,mode:s.mode})}}async function va(e,t,n,r,o,s,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(Lt(t.mode)||Lt(n.mode)||Lt(r.mode))return{hash:n.hash,conflict:!0};let i=await fe(e,t.hash),c=await fe(e,n.hash),f=await fe(e,r.hash);if(Pe(c)||Pe(f)||Pe(i))return{hash:n.hash,conflict:!0};let d=it(i),u=it(c),l=it(f),m=ar(u,d,l);if(!m.conflict)return{hash:await yo(e,m.result),conflict:!1};let h=o?.a??"HEAD",p=o?.b??"theirs",g=s?.oursPath?`${h}:${s.oursPath}`:h,w=s?.theirsPath?`${p}:${s.theirsPath}`:p,x=xn(c,i,f,{a:g,b:w,markerSize:a??7});return{hash:await we(e,"blob",an.encode(x)),conflict:!0}}async function fs(e,t,n,r,o){let s=await fe(e,t),a=await fe(e,n),i=xn(s,"",a,{a:o?.a??"HEAD",b:o?.b??"theirs"});return we(e,"blob",an.encode(i))}function rt(e,t,n=0){return We(e,t.mode,t.hash,n)}function We(e,t,n,r=0){return{path:e,mode:parseInt(t,8),hash:n,stage:r,stat:pe()}}async function Al(e,t,n,r){let o=[...r.entries],s=[...r.conflicts],a=[...r.msgBuf],i=new Map(r.worktreeBlobs);function c(m,h,p=0){a.push({sortKey:m,subOrder:p,text:h})}for(let m of[...t.keys()].sort()){let h=t.get(m);if(h.merged.clean){h.merged.result?.hash&&o.push(Ee(m,h.merged.result.hash,h.merged.result.mode));continue}await vl(e,h,n,o,s,c,i)}a.sort((m,h)=>(m.sortKey<h.sortKey?-1:m.sortKey>h.sortKey?1:0)||m.subOrder-h.subOrder);let f=a.map(m=>m.text),d=[],u=new Set;for(let m of o)m.stage===0&&(d.push(m),u.add(m.path));for(let[m,h]of i)u.has(m)||d.push(Ee(m,h.hash,h.mode));d.sort((m,h)=>he(m.path,h.path));let l=await ke(e,d);return{entries:o,conflicts:s,messages:f,resultTree:l}}async function vl(e,t,n,r,o,s,a){let i=t.path,[c,f,d]=t.stages,u=c?.hash??null,l=f?.hash??null,m=d?.hash??null;if(l===null&&m!==null&&u!==null){o.push({path:i,reason:"delete-modify",deletedBy:"ours"});let h=n?.a??"HEAD",p=n?.b??"theirs";s(i,`CONFLICT (modify/delete): ${i} deleted in ${h} and modified in ${p}. Version ${p} of ${i} left in tree.`),c&&r.push(Ee(i,u,c.mode,1)),r.push(Ee(i,m,d.mode,3)),a.set(i,{hash:m,mode:d.mode});return}if(m===null&&l!==null&&u!==null){o.push({path:i,reason:"delete-modify",deletedBy:"theirs"});let h=n?.b??"theirs",p=n?.a??"HEAD";s(i,`CONFLICT (modify/delete): ${i} deleted in ${h} and modified in ${p}. Version ${p} of ${i} left in tree.`),c&&r.push(Ee(i,u,c.mode,1)),r.push(Ee(i,l,f.mode,2)),a.set(i,{hash:l,mode:f.mode});return}if(u===null&&l!==null&&m!==null){if(l===m){r.push(Ee(i,l,f.mode));return}s(i,`Auto-merging ${i}`,0);let h=await fe(e,l),p=await fe(e,m);if(Pe(h)||Pe(p)){o.push({path:i,reason:"add-add"}),s(i,`warning: Cannot merge binary files: ${i} (${n?.a??"HEAD"} vs. ${n?.b??"theirs"})`,-1),s(i,`CONFLICT (add/add): Merge conflict in ${i}`,1),r.push(Ee(i,l,f.mode,2)),r.push(Ee(i,m,d.mode,3)),a.set(i,{hash:l,mode:f.mode});return}let g=it(""),w=it(h),x=it(p),b=ar(w,g,x,n);if(!b.conflict){let C=await yo(e,b.result);r.push(Ee(i,C,f.mode));return}o.push({path:i,reason:"add-add"}),s(i,`CONFLICT (add/add): Merge conflict in ${i}`,1),r.push(Ee(i,l,f.mode,2)),r.push(Ee(i,m,d.mode,3));let y=xn(h,"",p,{a:n?.a??"HEAD",b:n?.b??"theirs"}),k=await we(e,"blob",an.encode(y));a.set(i,{hash:k,mode:f.mode});return}if(u!==null&&l!==null&&m!==null){if(l===u){r.push(Ee(i,m,d.mode));return}if(m===u){r.push(Ee(i,l,f.mode));return}if(l===m){r.push(Ee(i,l,f.mode));return}if(s(i,`Auto-merging ${i}`,0),Lt(c.mode)||Lt(f.mode)||Lt(d.mode)){o.push({path:i,reason:"content"}),s(i,`CONFLICT (content): Merge conflict in ${i}`,1),r.push(Ee(i,u,c.mode,1)),r.push(Ee(i,l,f.mode,2)),r.push(Ee(i,m,d.mode,3)),a.set(i,{hash:l,mode:f.mode});return}let h=await fe(e,u),p=await fe(e,l),g=await fe(e,m);if(Pe(p)||Pe(g)||Pe(h)){o.push({path:i,reason:"content"}),s(i,`warning: Cannot merge binary files: ${i} (${n?.a??"HEAD"} vs. ${n?.b??"theirs"})`,-1),s(i,`CONFLICT (content): Merge conflict in ${i}`,1),r.push(Ee(i,u,c.mode,1)),r.push(Ee(i,l,f.mode,2)),r.push(Ee(i,m,d.mode,3)),a.set(i,{hash:l,mode:f.mode});return}let w=it(h),x=it(p),b=it(g),y=ar(x,w,b,n);if(y.conflict){let k=t.pathnames[1],C=t.pathnames[2],P=k!==i||C!==i,O={path:i,reason:"content"};P&&(k!==i&&(O.oursOrigPath=k),C!==i&&(O.theirsOrigPath=C)),o.push(O),s(i,`CONFLICT (content): Merge conflict in ${i}`,1),r.push(Ee(i,u,c.mode,1)),r.push(Ee(i,l,f.mode,2)),r.push(Ee(i,m,d.mode,3));let E=P?`${n?.a??"HEAD"}:${k}`:n?.a??"HEAD",I=P?`${n?.b??"theirs"}:${C}`:n?.b??"theirs",A=xn(p,h,g,{a:E,b:I}),_=await we(e,"blob",an.encode(A));a.set(i,{hash:_,mode:f.mode})}else{let k=await yo(e,y.result);r.push(Ee(i,k,f.mode))}return}}var Sl=200;async function Sa(e,t,n,r,o){let s=await Promise.all(r.map(async d=>({hash:d,timestamp:(await M(e,d)).committer.timestamp})));s.sort((d,u)=>d.timestamp-u.timestamp);let a=s.map(d=>d.hash),i=a[0],c=i,f=(await M(e,i)).tree;for(let d=1;d<a.length;d++){let u=a[d],l=(await M(e,u)).tree,m=null;if(o>=Sl)m=f;else{let g=await ht(e,c,u);g.length===0?m=null:g.length===1?m=(await M(e,g[0])).tree:m=await Sa(e,c,u,g,o+1)}let h=await wt(e,m,f,l);f=await Dl(e,h,o);let p=$t({type:"commit",tree:f,parents:[c,u],author:Pa,committer:Pa,message:"merged common ancestors"});c=await we(e,"commit",p)}return f}async function Dl(e,t,n){let r=t.entries.filter(i=>i.stage===0),o=new Map;for(let i of t.entries)i.stage>0&&o.set(`${i.path}\0${i.stage}`,i);let s=(i,c)=>o.get(`${i}\0${c}`),a={a:"Temporary merge branch 1",b:"Temporary merge branch 2",markerSize:7+n*2};for(let i of t.conflicts){if(i.reason==="delete-modify"||i.reason==="rename-delete"){let d=s(i.path,1);if(d){r.push({...d,stage:0});continue}}if(i.reason==="rename-rename"){let d=i.oursPath??i.path,u=i.theirsPath??i.path,l=s(i.path,1),m=s(d,2),h=s(u,3);if(m&&h){let p=Gn.decode((await ce(e,m.hash)).content),g=Gn.decode((await ce(e,h.hash)).content),w=l?Gn.decode((await ce(e,l.hash)).content):"",x=8+n*2,b=a.a??"Temporary merge branch 1",y=a.b??"Temporary merge branch 2",k=xn(p,w,g,{a:`${b}:${d}`,o:a.o,b:`${y}:${u}`,markerSize:x}),C=await we(e,"blob",an.encode(k));r.push({path:d,mode:m.mode,hash:C,stage:0,stat:pe()}),r.push({path:u,mode:h.mode,hash:C,stage:0,stat:pe()});continue}else if(m){r.push({...m,stage:0});continue}}let c=s(i.path,2),f=s(i.path,3);if(c&&f&&(i.reason==="content"||i.reason==="add-add")){let d=Gn.decode((await ce(e,c.hash)).content),u=Gn.decode((await ce(e,f.hash)).content),l=i.reason==="content"?s(i.path,1):null,m=l?Gn.decode((await ce(e,l.hash)).content):"",h=i.oursOrigPath||i.theirsOrigPath,p=a.a??"Temporary merge branch 1",g=a.b??"Temporary merge branch 2",w=h?`${p}:${i.oursOrigPath??i.path}`:p,x=h?`${g}:${i.theirsOrigPath??i.path}`:g,b=xn(d,m,u,{a:w,o:a.o,b:x,markerSize:a.markerSize}),y=await we(e,"blob",an.encode(b));r.push({path:i.path,mode:c.mode,hash:y,stage:0,stat:pe()})}else c?r.push({...c,stage:0}):f&&r.push({...f,stage:0})}return r.sort((i,c)=>he(i.path,c.path)),ke(e,r)}async function yo(e,t){let n=t.map(go);if(n.length===0)return we(e,"blob",an.encode(""));let s=(t[t.length-1]??"").endsWith("\0")?n.join(`
|
|
188
198
|
`):`${n.join(`
|
|
189
199
|
`)}
|
|
190
|
-
`;return we(e,"blob",an.encode(s))}function Ee(e,t,n,r=0){let o=typeof n=="string"?parseInt(n,8):n;return{path:e,mode:o,hash:t,stage:r,stat:pe()}}function
|
|
200
|
+
`;return we(e,"blob",an.encode(s))}function Ee(e,t,n,r=0){let o=typeof n=="string"?parseInt(n,8):n;return{path:e,mode:o,hash:t,stage:r,stat:pe()}}function wo(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 cr(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}
|
|
191
201
|
${e.join(" ")}
|
|
192
202
|
Merge with strategy ort failed.
|
|
193
203
|
`;let c=e.map(d=>` ${d}`).join(`
|
|
@@ -202,7 +212,7 @@ ${a}
|
|
|
202
212
|
${i}
|
|
203
213
|
Aborting
|
|
204
214
|
fatal: ${n} failed
|
|
205
|
-
`}function
|
|
215
|
+
`}function Aa(e,t,n,r){let o=[];if(e.length>0){let a=e.map(i=>` ${i}`).join(`
|
|
206
216
|
`);o.push(`error: Your local changes to the following files would be overwritten by ${n}:
|
|
207
217
|
${a}
|
|
208
218
|
Please commit your changes or stash them before you ${n}.
|
|
@@ -212,13 +222,13 @@ ${a}
|
|
|
212
222
|
Please move or remove them before you ${n}.
|
|
213
223
|
`)}let s=r==="merge"?"Merge with strategy ort failed.":`fatal: ${r} failed`;return`${o.join("")}Aborting
|
|
214
224
|
${s}
|
|
215
|
-
`}async function Wt(e,t,n,r){let o=await U(e),s=await se(e,n);if(!r.skipStagedChangeCheck&&e.workTree){let h=new Map(xe(o).map(g=>[g.path,g])),p=[];for(let[g,w]of h){let x=s.get(g);(!x||x.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();await
|
|
225
|
+
`}async function Wt(e,t,n,r){let o=await U(e),s=await se(e,n);if(!r.skipStagedChangeCheck&&e.workTree){let h=new Map(xe(o).map(g=>[g.path,g])),p=[];for(let[g,w]of h){let x=s.get(g);(!x||x.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();await bo(e,o,s);let w=r.operationName??"merge",x=r.callerCommand??"merge";return{ok:!1,stdout:"",stderr:cr(g,w,x,"local","staged"),exitCode:r.errorExitCode??2,failureKind:"staged"}}}if(e.workTree&&r.preflightOnewayCheck){let h=await gn(e,[{label:"target",treeHash:t.resultTree}],o,{mergeFn:jr,updateWorktree:!1,reset:!1,errorExitCode:r.errorExitCode??2,operationName:r.operationName??"merge"});if(!h.success){await bo(e,o,s);let p=r.operationName??"merge",g=r.callerCommand??"merge",w=h.errors.filter(y=>y.error==="WOULD_OVERWRITE"||y.error==="NOT_UPTODATE_FILE").map(y=>y.path).sort(),x=h.errors.filter(y=>y.error==="WOULD_LOSE_UNTRACKED_OVERWRITTEN"||y.error==="WOULD_LOSE_UNTRACKED_REMOVED").map(y=>y.path).sort(),b;return w.length>0&&x.length>0?b=Aa(w,x,p,g):x.length>0?b=cr(x,p,g,"untracked","worktree"):b=cr(w,p,g,"local","worktree"),{ok:!1,stdout:"",stderr:b,exitCode:r.errorExitCode??2,failureKind:"worktree"}}}if(e.workTree){let h=await gn(e,[{label:"current",treeHash:n},{label:"target",treeHash:t.resultTree}],o,{mergeFn:Lr,updateWorktree:!0,reset:!1,errorExitCode:r.errorExitCode??2,operationName:r.operationName??"merge",allowStagedChanges:!!r.preflightOnewayCheck});if(!h.success){await bo(e,o,s);let p=r.operationName??"merge",g=r.callerCommand??"merge",w=h.errors.filter(k=>k.error==="WOULD_OVERWRITE"||k.error==="NOT_UPTODATE_FILE").map(k=>k.path).sort(),x=h.errors.filter(k=>k.error==="WOULD_LOSE_UNTRACKED_OVERWRITTEN"||k.error==="WOULD_LOSE_UNTRACKED_REMOVED").map(k=>k.path).sort(),b=[];w.length>0&&b.push(cr(w,p,g,"local","worktree")),x.length>0&&b.push(cr(x,p,g,"untracked","worktree"));let y;return b.length>1?y=Aa(w,x,p,g):y=b[0]??"",{ok:!1,stdout:"",stderr:y,exitCode:r.errorExitCode??2,failureKind:"worktree"}}await be(e,h.worktreeOps)}let a=new Set,i=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){a.add(p.path);continue}}h.push(p)}i=h}let c=new Set(i.map(h=>h.path));for(let h of s.keys())a.has(h)||c.add(h);let f=o.entries.filter(h=>!c.has(h.path)),d=[...i,...f];d.sort((h,p)=>he(h.path,p.path)||h.stage-p.stage);let u={version:2,entries:d};await re(e,u);let l=d.filter(h=>h.stage===0),m=await ke(e,l);return{ok:!0,finalIndex:u,mergedTreeHash:m}}async function bo(e,t,n){if(e.workTree)for(let r of t.entries){if(r.stage!==0||n.has(r.path))continue;let o=H(e.workTree,r.path);await e.fs.exists(o)||await ve(e,{path:r.path,hash:r.hash,mode:r.mode})}}function Da(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:v().describe("Abort the current cherry-pick operation"),continue:v().describe("Continue the cherry-pick after conflict resolution"),skip:v().describe("Skip the current cherry-pick and continue with the rest"),"record-origin":v().alias("x").describe('Append "(cherry picked from commit ...)" to the commit message'),mainline:te.number().alias("m").describe("Select parent number for merge commit (1-based)"),noCommit:v().alias("n").describe("Apply changes without creating a commit")},handler:async(n,r)=>{let o=await B(r.fs,r.cwd,t);if(S(o))return o;let s=o;if(n.abort){if(t?.hooks){let R=await t.hooks.emitPre("pre-cherry-pick",{mode:"abort",commit:null});if(R)return{stdout:"",stderr:R.message??"",exitCode:1}}let $=await jl(s,r.env);return $.exitCode===0&&await t?.hooks?.emitPost("post-cherry-pick",{mode:"abort",commitHash:null,hadConflicts:!1}),$}if(n.continue){if(t?.hooks){let R=await t.hooks.emitPre("pre-cherry-pick",{mode:"continue",commit:null});if(R)return{stdout:"",stderr:R.message??"",exitCode:1}}let $=await Ll(s,r.env);return $.exitCode===0&&await t?.hooks?.emitPost("post-cherry-pick",{mode:"continue",commitHash:null,hadConflicts:!1}),$}if(n.skip)return Ml(s,r.env);let a=n.commit;if(!a)return T("you must specify a commit to cherry-pick");if(t?.hooks){let $=await t.hooks.emitPre("pre-cherry-pick",{mode:"pick",commit:a});if($)return{stdout:"",stderr:$.message??"",exitCode:1}}let i=await ye(s,a);if(S(i))return i;let c=i.hash,f=i.commit,d=await Se(s);if(S(d))return d;let u=await U(s);if(n.noCommit){let $=u.entries.filter(R=>R.stage>0);if($.length>0){let q=$.slice(0,10).map(V=>`${V.path}: unmerged (${V.hash})`).join(`
|
|
216
226
|
`),L=$.length>10?`
|
|
217
227
|
...`:"";return j(`${q}${L}
|
|
218
228
|
error: your index file is unmerged.
|
|
219
229
|
fatal: cherry-pick failed
|
|
220
230
|
`,128)}}else{let $=Nt(u,"Cherry-picking",`fatal: cherry-pick failed
|
|
221
|
-
`);if($)return $}let l=await M(s,d),h=!!n["record-origin"]?
|
|
231
|
+
`);if($)return $}let l=await M(s,d),h=!!n["record-origin"]?Gl(f.message,c):f.message;if(s.workTree&&!n.noCommit){let $=await se(s,l.tree);if(vn(u,$))return j(`error: your local changes would be overwritten by cherry-pick.
|
|
222
232
|
hint: commit your changes or stash them to proceed.
|
|
223
233
|
fatal: cherry-pick failed
|
|
224
234
|
`,128)}if(f.parents.length>1){if(!n.mainline)return j(`error: commit ${c} is a merge but no -m option was given.
|
|
@@ -251,48 +261,48 @@ hint: To abort and get back to the state before "git cherry-pick",
|
|
|
251
261
|
hint: run "git cherry-pick --abort".
|
|
252
262
|
hint: Disable this message with "git config set advice.mergeConflict false"
|
|
253
263
|
`,exitCode:1})}let k=y.mergedTreeHash;if(n.noCommit)return{stdout:"",stderr:"",exitCode:0};let C=await Le(s,r.env);if(S(C))return C;let P=await Je(s,k,[d],f.author,C,h);await kt(s),await pt(s);let O=await J(s),E=h.split(`
|
|
254
|
-
`)[0]??"",I=O?.type==="symbolic"?O.target:"HEAD";await ee(s,r.env,I,d,P,`cherry-pick: ${E}`,O?.type==="symbolic");let
|
|
264
|
+
`)[0]??"",I=O?.type==="symbolic"?O.target:"HEAD";await ee(s,r.env,I,d,P,`cherry-pick: ${E}`,O?.type==="symbolic");let A=O?.type==="symbolic"?de(O.target):"detached HEAD",_=l.tree,G=await St(s,_,k,f.author,C,!0),z=ut(A,P,h),D=b.messages.length>0?`${b.messages.join(`
|
|
255
265
|
`)}
|
|
256
266
|
`:"";return await t?.hooks?.emitPost("post-cherry-pick",{mode:"pick",commitHash:P,hadConflicts:!1}),{stdout:`${D}${z}
|
|
257
|
-
${G}`,stderr:"",exitCode:0}}})}async function
|
|
267
|
+
${G}`,stderr:"",exitCode:0}}})}async function Ml(e,t){if(!await F(e,"CHERRY_PICK_HEAD"))return j(`error: no cherry-pick in progress
|
|
258
268
|
fatal: cherry-pick failed
|
|
259
|
-
`,128);let r=await X(e);if(!r)return T("unable to resolve HEAD");let o=await M(e,r),s=await U(e),a=await yt(e,o.tree,s);return a.success?(await re(e,{version:2,entries:a.newEntries}),await be(e,a.worktreeOps),await ee(e,t,"HEAD",r,r,`reset: moving to ${r}`),await kt(e),{stdout:"",stderr:"",exitCode:0}):a.errorOutput}async function
|
|
269
|
+
`,128);let r=await X(e);if(!r)return T("unable to resolve HEAD");let o=await M(e,r),s=await U(e),a=await yt(e,o.tree,s);return a.success?(await re(e,{version:2,entries:a.newEntries}),await be(e,a.worktreeOps),await ee(e,t,"HEAD",r,r,`reset: moving to ${r}`),await kt(e),{stdout:"",stderr:"",exitCode:0}):a.errorOutput}async function jl(e,t){return await F(e,"CHERRY_PICK_HEAD")?en(e,t,{operationRef:"CHERRY_PICK_HEAD",noOpError:j(`error: no cherry-pick or revert in progress
|
|
260
270
|
fatal: cherry-pick failed
|
|
261
271
|
`,128),operationName:"cherry-pick",clearState:kt,origHeadAsTargetRev:!0}):await F(e,"REVERT_HEAD")?en(e,t,{operationRef:"REVERT_HEAD",noOpError:j(`error: no cherry-pick or revert in progress
|
|
262
272
|
fatal: cherry-pick failed
|
|
263
273
|
`,128),operationName:"cherry-pick",clearState:pt,origHeadAsTargetRev:!0}):j(`error: no cherry-pick or revert in progress
|
|
264
274
|
fatal: cherry-pick failed
|
|
265
|
-
`,128)}async function
|
|
275
|
+
`,128)}async function Ll(e,t){let n=await F(e,"CHERRY_PICK_HEAD");if(!n)return j(`error: no cherry-pick or revert in progress
|
|
266
276
|
fatal: cherry-pick failed
|
|
267
277
|
`,128);let r=await U(e),o=Nt(r,"Committing");if(o)return o;let s=await M(e,n),a=await qe(e,"MERGE_MSG");a||(a=s.message);let i=xe(r),c=await ke(e,i),f=await Se(e);if(S(f))return f;let u=(await M(e,f)).tree,l=await Le(e,t);if(S(l))return l;let m=mt(a),h=await Je(e,c,[f],s.author,l,m);await kt(e),await pt(e);let p=await J(e),g=ue(m),w=p?.type==="symbolic"?p.target:"HEAD";await ee(e,t,w,f,h,`commit (cherry-pick): ${g}`,p?.type==="symbolic");let x=p?.type==="symbolic"?de(p.target):"detached HEAD",b=await St(e,u,c,s.author,l,!0);return{stdout:`${ut(x,h,a)}
|
|
268
|
-
${b}`,stderr:"",exitCode:0}}function
|
|
278
|
+
${b}`,stderr:"",exitCode:0}}function Gl(e,t){let n=`(cherry picked from commit ${t})`,r=e.replace(/\n+$/,""),o=r.lastIndexOf(`
|
|
269
279
|
`),s=o===-1?r:r.slice(o+1);return/^\(cherry picked from commit [0-9a-f]+\)$/.test(s)?`${r}
|
|
270
280
|
${n}
|
|
271
281
|
`:`${r}
|
|
272
282
|
|
|
273
283
|
${n}
|
|
274
|
-
`}function
|
|
284
|
+
`}function Ma(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:v().alias("f").describe("Required to actually remove files"),"dry-run":v().alias("n").describe("Don't actually remove anything, just show what would be done"),directories:v().alias("d").describe("Also remove untracked directories"),removeIgnored:v().alias("x").describe("Remove ignored files as well"),onlyIgnored:v().alias("X").describe("Remove only ignored files"),exclude:te.string().alias("e").describe("Additional exclude pattern")},handler:async(n,r)=>{let o=await B(r.fs,r.cwd,t);if(S(o))return o;let s=o,a=Fe(s);if(a)return a;let i=s.workTree,c=n["dry-run"],f=n.force,d=n.directories,u=n.removeIgnored,l=n.onlyIgnored;if(t?.hooks){let P=await t.hooks.emitPre("pre-clean",{dryRun:c,force:f,removeDirs:d,removeIgnored:u,onlyIgnored:l});if(P)return{stdout:"",stderr:P.message??"",exitCode:1}}if(!f&&!c&&await bt(s,"clean.requireForce")!=="false")return T("clean.requireForce defaults to true and neither -i, -n, nor -f given; refusing to clean");let m=await U(s),h=new Set(m.entries.map(P=>P.path)),p=Ze(s,r.cwd),g=n.pathspec,w=g.length>0?g.map(P=>Oe(P,p)):null,x=n.exclude?[n.exclude]:[],b=await ja(s,i,"",{trackedPaths:h,removeDirs:d,removeIgnored:u,onlyIgnored:l,extraExcludes:x}),y;w?y=b.filter(P=>me(w,P.path)):y=b,y.sort((P,O)=>P.path<O.path?-1:P.path>O.path?1:0);let k=[];if(c)for(let P of y){let O=P.isDir?`Would remove ${P.path}/`:`Would remove ${P.path}`;k.push(O)}else for(let P of y){let O=H(i,P.path);P.isDir?(await r.fs.rm(O,{recursive:!0}),k.push(`Removing ${P.path}/`)):(await r.fs.rm(O),k.push(`Removing ${P.path}`))}let C=k.length>0?`${k.join(`
|
|
275
285
|
`)}
|
|
276
|
-
`:"";return await t?.hooks?.emitPost("post-clean",{removed:y.map(P=>P.path),dryRun:c}),{stdout:C,stderr:"",exitCode:0}}})}async function
|
|
277
|
-
`),d=
|
|
278
|
-
`)?t.slice(0,-1):t}var
|
|
286
|
+
`:"";return await t?.hooks?.emitPost("post-clean",{removed:y.map(P=>P.path),dryRun:c}),{stdout:C,stderr:"",exitCode:0}}})}async function ja(e,t,n,r){let o=[],s=!r.removeIgnored,a=null;if(s||r.onlyIgnored){a=r._ignore??await Hn(e);let c=H(t,".gitignore");try{let f=await e.fs.readFile(c);a=hn(a,f,n,c)}catch{}if(!r._ignore&&r.extraExcludes.length>0){let f=r.extraExcludes.join(`
|
|
287
|
+
`),d=nr(f,"","<cli>");a={...a,dirPatterns:[d,...a.dirPatterns]}}}let i=await e.fs.readdir(t);for(let c of i){if(n===""&&c===".git")continue;let f=H(t,c),d=n?`${n}/${c}`:c,u=await e.fs.stat(f);if(u.isDirectory){let l=a&&Tt(a,d,!0)==="ignored",m=Nl(r.trackedPaths,d),h=()=>ja(e,f,d,{...r,_ignore:a??void 0});if(r.onlyIgnored){if(l&&!m){r.removeDirs&&o.push({path:d,isDir:!0});continue}let p=await h();!m&&r.removeDirs?p.length>0&&o.push({path:d,isDir:!0}):o.push(...p)}else if(m){let p=await h();o.push(...p)}else if(!(l&&s)){if(r.removeDirs)if(r.removeIgnored)o.push({path:d,isDir:!0});else{let p=await h(),g=await e.fs.readdir(f);(p.length>0||g.length===0)&&o.push({path:d,isDir:!0})}}}else if(u.isFile){if(r.trackedPaths.has(d))continue;let l=a&&Tt(a,d,!1)==="ignored";r.onlyIgnored?l&&o.push({path:d,isDir:!1}):l&&s||o.push({path:d,isDir:!1})}}return o}function Nl(e,t){let n=`${t}/`;for(let r of e)if(r.startsWith(n))return!0;return!1}async function ds(e,t,n){return La(e,t,n,!1)}async function ls(e,t,n){return La(e,t,n,!0)}async function La(e,t,n,r){let o=new Set;for(let i of n)await dr(e,i,o);let s=[],a=new Set;for(let i of t)await lr(e,i,o,a,s,r);return s}async function dr(e,t,n){if(n.has(t)||(n.add(t),!await zt(e,t)))return;let r=await ce(e,t);switch(r.type){case"commit":{let o=It(r.content);await dr(e,o.tree,n);for(let s of o.parents)await dr(e,s,n);break}case"tree":{let o=Jt(r.content);for(let s of o.entries)await dr(e,s.hash,n);break}case"tag":{let o=jt(r.content);await dr(e,o.object,n);break}case"blob":break}}async function lr(e,t,n,r,o,s){if(r.has(t)||n.has(t))return;r.add(t);let a=await ce(e,t);switch(o.push(s?{hash:t,type:a.type,content:a.content}:{hash:t,type:a.type}),a.type){case"commit":{let i=It(a.content);await lr(e,i.tree,n,r,o,s);for(let c of i.parents)await lr(e,c,n,r,o,s);break}case"tree":{let i=Jt(a.content);for(let c of i.entries)await lr(e,c.hash,n,r,o,s);break}case"tag":{let i=jt(a.content);await lr(e,i.object,n,r,o,s);break}case"blob":break}}var _l=new TextEncoder,us=new TextDecoder,Ga=65520,Fl=new Uint8Array([48,48,48,48]);function kn(e){let t=typeof e=="string"?_l.encode(e):e,n=4+t.byteLength;if(n>Ga)throw new Error(`pkt-line too long: ${n} bytes (max ${Ga})`);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 Eo(){return Fl.slice()}function ms(...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 Nn(e){let t=[],n=0;for(;n<e.byteLength;){if(n+4>e.byteLength)throw new Error("Truncated pkt-line header");let r=us.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<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 hs(e){if(e.type==="flush")return"";let t=us.decode(e.data);return t.endsWith(`
|
|
288
|
+
`)?t.slice(0,-1):t}var Ul=1,Bl=2,Wl=3;function xo(e){let t=[],n=[],r=[],o=0;for(let i of e){if(i.type==="flush"||i.data.byteLength===0)continue;let c=i.data[0];if(c===void 0)continue;let f=i.data.subarray(1);switch(c){case Ul:t.push(f),o+=f.byteLength;break;case Bl:n.push(us.decode(f));break;case Wl:r.push(us.decode(f));break;default:break}}let s=new Uint8Array(o),a=0;for(let i of t)s.set(i,a),a+=i.byteLength;return{packData:s,progress:n,errors:r}}function ko(e){return e?e.type==="bearer"?{Authorization:`Bearer ${e.token}`}:{Authorization:`Basic ${btoa(`${e.username}:${e.password}`)}`}:{}}async function Co(e,t,n,r=globalThis.fetch){let o=e.replace(/\/+$/,""),s=await r(`${o}/info/refs?service=${t}`,{headers:{...ko(n),"User-Agent":"just-git/1.0"}});if(!s.ok)throw new Error(`HTTP ${s.status} discovering refs at ${o}`);let a=s.headers.get("content-type")??"",i=`application/x-${t}-advertisement`,c=new Uint8Array(await s.arrayBuffer());if(!a.startsWith(i)){let d=new TextDecoder().decode(c.subarray(0,5));if(!/^[0-9a-f]{4}#/.test(d))throw new Error(`Server does not support smart HTTP (Content-Type: ${a})`)}let f=Nn(c);return ql(f,t)}function ql(e,t){let n=0,r=e[n];r?.type==="data"&&hs(r)===`# service=${t}`&&n++,e[n]?.type==="flush"&&n++;let o=[],s=[],a=new Map;for(;n<e.length;n++){let i=e[n];if(!i||i.type==="flush")break;let c=i.data,f=c.indexOf(0),d;if(f!==-1){d=new TextDecoder().decode(c.subarray(0,f)),s=new TextDecoder().decode(c.subarray(f+1)).replace(/\n$/,"").split(" ").filter(Boolean);for(let p of s)if(p.startsWith("symref=")){let g=p.slice(7),w=g.indexOf(":");w!==-1&&a.set(g.slice(0,w),g.slice(w+1))}}else d=new TextDecoder().decode(c).replace(/\n$/,"");let u=d.indexOf(" ");if(u===-1)continue;let l=d.slice(0,u),m=d.slice(u+1);if(!(l===Z&&m==="capabilities^{}")){if(m.endsWith("^{}")){let h=m.slice(0,-3),p=o.find(g=>g.name===h);p&&(p.peeledHash=l);continue}o.push({name:m,hash:l})}}return{refs:o,capabilities:s,symrefs:a}}var Kl=["multi_ack_detailed","no-done","side-band-64k","ofs-delta","thin-pack","include-tag"];async function Na(e,t,n,r,o,s=globalThis.fetch){if(t.length===0)throw new Error("fetchPack requires at least one want");let a=Fa(r,Kl),i=[];i.push(kn(`want ${t[0]} ${a.join(" ")}
|
|
279
289
|
`));for(let l=1;l<t.length;l++)i.push(kn(`want ${t[l]}
|
|
280
|
-
`));i.push(
|
|
290
|
+
`));i.push(Eo());for(let l of n)i.push(kn(`have ${l}
|
|
281
291
|
`));i.push(kn(`done
|
|
282
|
-
`));let c=
|
|
292
|
+
`));let c=ms(...i),f=e.replace(/\/+$/,""),d=await s(`${f}/git-upload-pack`,{method:"POST",headers:{"Content-Type":"application/x-git-upload-pack-request",...ko(o),"User-Agent":"just-git/1.0"},body:c});if(!d.ok)throw new Error(`HTTP ${d.status} fetching pack from ${f}`);let u=new Uint8Array(await d.arrayBuffer());return zl(u,a.includes("side-band-64k"))}function zl(e,t){let n=Nn(e),r=[],o=0;for(let f=0;f<n.length;f++){let d=n[f];if(!d||d.type==="flush"){o=f+1;continue}if(d.type!=="data")continue;let u=hs(d);if(u.startsWith("ACK ")||u==="NAK")r.push(u),o=f+1;else{o=f;break}}let s=n.slice(o);if(t){let{packData:f,progress:d,errors:u}=xo(s);if(u.length>0)throw new Error(`Remote error: ${u.join("")}`);return{packData:f,acks:r,progress:d}}let a=0;for(let f of s)f.type==="data"&&(a+=f.data.byteLength);let i=new Uint8Array(a),c=0;for(let f of s)f.type==="data"&&(i.set(f.data,c),c+=f.data.byteLength);return{packData:i,acks:r,progress:[]}}var Vl=["report-status","side-band-64k","ofs-delta","delete-refs"];async function _a(e,t,n,r,o,s=globalThis.fetch){if(t.length===0)throw new Error("pushPack requires at least one command");let a=Fa(r,Vl),i=[],[c,...f]=t;if(!c)throw new Error("pushPack requires at least one command");i.push(kn(`${c.oldHash} ${c.newHash} ${c.refName}\0${a.join(" ")}
|
|
283
293
|
`));for(let h of f)i.push(kn(`${h.oldHash} ${h.newHash} ${h.refName}
|
|
284
|
-
`));i.push(
|
|
294
|
+
`));i.push(Eo());let d;if(n&&n.byteLength>0){let h=ms(...i);d=new Uint8Array(h.byteLength+n.byteLength),d.set(h,0),d.set(n,h.byteLength)}else d=ms(...i);let u=e.replace(/\/+$/,""),l=await s(`${u}/git-receive-pack`,{method:"POST",headers:{"Content-Type":"application/x-git-receive-pack-request",...ko(o),"User-Agent":"just-git/1.0"},body:d});if(!l.ok)throw new Error(`HTTP ${l.status} pushing to ${u}`);let m=new Uint8Array(await l.arrayBuffer());return a.includes("report-status")?Yl(m,a.includes("side-band-64k")):{unpackOk:!0,refResults:[],progress:[]}}function Yl(e,t){let n,r=[];if(t){let i=Nn(e),{packData:c,progress:f,errors:d}=xo(i);if(d.length>0)throw new Error(`Remote error: ${d.join("")}`);r=f,n=Nn(c)}else n=Nn(e);let o=!1,s,a=[];for(let i of n){if(i.type==="flush")break;let c=hs(i);if(c.startsWith("unpack "))o=c==="unpack ok",o||(s=c.slice(7));else if(c.startsWith("ok "))a.push({name:c.slice(3),ok:!0});else if(c.startsWith("ng ")){let f=c.slice(3),d=f.indexOf(" ");d!==-1?a.push({name:f.slice(0,d),ok:!1,error:f.slice(d+1)}):a.push({name:f,ok:!1})}}return{unpackOk:o,unpackError:s,refResults:a,progress:r}}function Fa(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 ur=class{constructor(t,n){this.local=t;this.remote=n}headTarget;async advertiseRefs(){let t=await le(this.remote),n=[];for(let s of t)n.push({name:s.name,hash:s.hash});let r=await F(this.remote,"HEAD");r&&n.push({name:"HEAD",hash:r});let o=await J(this.remote);return o?.type==="symbolic"&&(this.headTarget=o.target),n}async fetch(t,n){let r=await this.advertiseRefs();if(t.length===0)return{remoteRefs:r,objectCount:0};let o=await ds(this.remote,t,n);if(o.length===0)return{remoteRefs:r,objectCount:0};let s=[];for(let c of o){let f=await ce(this.remote,c.hash);s.push({type:f.type,content:f.content})}let a=await $r(s),i=await Ar(this.local,a);return{remoteRefs:r,objectCount:i}}async push(t){let n=[],r=[];for(let s of t)s.newHash!==Z&&n.push(s.newHash),s.oldHash&&r.push(s.oldHash);if(n.length>0){let s=await ds(this.local,n,r);if(s.length>0){let a=[];for(let c of s){let f=await ce(this.local,c.hash);a.push({type:f.type,content:f.content})}let i=await $r(a);await Ar(this.remote,i)}}let o=[];for(let s of t)try{if(s.newHash===Z){await ie(this.remote,s.name),o.push({...s,ok:!0});continue}let a=await F(this.remote,s.name);if(a&&!s.ok&&!await _t(this.remote,a,s.newHash)){o.push({...s,ok:!1,error:`non-fast-forward update rejected for ${s.name}`});continue}await Y(this.remote,s.name,s.newHash),o.push({...s,ok:!0})}catch(a){o.push({...s,ok:!1,error:a instanceof Error?a.message:String(a)})}return{updates:o}}},mr=class{constructor(t,n,r,o){this.local=t;this.url=n;this.auth=r;this.fetchFn=o}headTarget;cachedFetchCaps=null;cachedPushCaps=null;cachedFetchRefs=null;async advertiseRefs(){let t=await Co(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 Co(this.url,"git-receive-pack",this.auth,this.fetchFn);this.cachedPushCaps=t.capabilities}return this.cachedPushCaps}async fetch(t,n){let{caps:r,refs:o}=await this.ensureFetchDiscovery();if(t.length===0)return{remoteRefs:o,objectCount:0};let s=await Na(this.url,t,n,r,this.auth,this.fetchFn);if(s.packData.byteLength===0)return{remoteRefs:o,objectCount:0};let a=await Ar(this.local,s.packData);return{remoteRefs:o,objectCount:a}}async push(t){for(let d of t)if(d.oldHash&&d.oldHash!==Z&&d.newHash!==Z&&!d.ok&&!await _t(this.local,d.oldHash,d.newHash))return{updates:t.map(l=>l===d?{...l,ok:!1,error:"non-fast-forward"}:{...l,ok:!1,error:"atomic push failed"})};let n=await this.ensurePushDiscovery(),r=t.map(d=>({oldHash:d.oldHash??Z,newHash:d.newHash,refName:d.name})),o=[],s=[],a=!1;for(let d of t)d.newHash!==Z&&(o.push(d.newHash),a=!0),d.oldHash&&d.oldHash!==Z&&s.push(d.oldHash);let i=null;if(a){let d=await ds(this.local,o,s),u=[];for(let l of d){let m=await ce(this.local,l.hash);u.push({type:m.type,content:m.content})}i=await $r(u)}let c=await _a(this.url,r,i,n,this.auth,this.fetchFn);return{updates:t.map(d=>{let u=c.refResults.find(h=>h.name===d.name),l=u?.ok??c.unpackOk,m=u?.error??(!l&&c.unpackError?`unpack failed: ${c.unpackError}`:void 0);return{...d,ok:l,error:m}})}}};async function Xl(e,t){let r=(await ae(e))[`remote "${t}"`];return r?.url?{name:t,url:r.url,fetchRefspec:r.fetch??"+refs/heads/*:refs/remotes/origin/*"}:null}function Po(e){return e.startsWith("http://")||e.startsWith("https://")}function Ua(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(Po(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 Zl(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 Ba(e,t,n){if(e.credentialProvider){let r=await e.credentialProvider(t);if(r)return r}return Zl(n)}async function Wa(e,t,n,r){if(Po(t)){let o=Ua(t,e.networkPolicy);if(o)throw new Error(o);let s=await Ba(e,t,n);return new mr(e,t,s,e.fetchFn)}if(!r)throw new Error(`'${t}' does not appear to be a git repository`);return new ur(e,r)}async function _n(e,t,n){let r=await Xl(e,t);if(!r)return null;if(Po(r.url)){let s=Ua(r.url,e.networkPolicy);if(s)throw new Error(s);let a=n?await Ba(e,r.url,n):void 0;return{transport:new mr(e,r.url,a,e.fetchFn),config:r}}let o=await $n(e.fs,r.url);return o?{transport:new ur(e,o),config:r}:null}function qa(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:v().describe("Create a bare clone"),branch:te.string().alias("b").describe("Checkout this branch instead of HEAD")},handler:async(n,r)=>{let o=n.repository;if(!o)return T("You must specify a repository to clone.");let s=o.startsWith("http://")||o.startsWith("https://"),a=s?o:ct(r.cwd,o),i=n.branch,c=n.directory;if(!c){let E=s?o.split("/").pop()??o:qn(a);E.endsWith(".git")&&(E=E.slice(0,-4)),c=E}let f=ct(r.cwd,c);if(t?.hooks){let E=await t.hooks.emitPre("pre-clone",{repository:o,targetPath:f,bare:n.bare,branch:i??null});if(E)return{stdout:"",stderr:E.message??"",exitCode:1}}if(await r.fs.exists(f))try{if((await r.fs.readdir(f)).length>0)return T(`destination path '${c}' already exists and is not an empty directory.`)}catch{return T(`destination path '${c}' already exists and is not an empty directory.`)}let d=null;if(!s&&(d=await $n(r.fs,a),!d))return T(`repository '${o}' does not exist`);await r.fs.mkdir(f,{recursive:!0});let{ctx:u}=await vr(r.fs,f,{bare:n.bare}),l=t?{...u,hooks:t.hooks,credentialProvider:t.credentialProvider,identityOverride:t.identityOverride,fetchFn:t.fetchFn,networkPolicy:t.networkPolicy}:u,m=await ae(l);m['remote "origin"']={url:a,fetch:"+refs/heads/*:refs/remotes/origin/*"},await Ge(l,m);let h;try{h=await Wa(l,a,r.env,d??void 0)}catch(E){let I=E instanceof Error?E.message:"";return I.startsWith("network")?T(I):T(`repository '${o}' does not exist`)}let p=await h.advertiseRefs();if(p.length===0)return await t?.hooks?.emitPost("post-clone",{repository:o,targetPath:f,bare:n.bare,branch:i??null}),{stdout:"",stderr:`Cloning into '${c}'...
|
|
285
295
|
warning: You appear to have cloned an empty repository.
|
|
286
|
-
`,exitCode:0};let g=[],w=new Set;for(let E of p)E.name!=="HEAD"&&(w.has(E.hash)||(w.add(E.hash),g.push(E.hash)));g.length>0&&await h.fetch(g,[]);let x=p.find(E=>E.name==="HEAD"),b=null,y=null,k=await Ot(l,r.env),C=`clone: from ${a}`,P=h.headTarget;P?.startsWith("refs/heads/")&&p.some(E=>E.name===P)&&(b=P.slice(11),y=p.find(E=>E.name===P)?.hash??null);for(let E of p)if(E.name!=="HEAD"){if(E.name.startsWith("refs/heads/")){let I=E.name.slice(11),
|
|
287
|
-
`,exitCode:0};if(b&&await $e(l,"refs/remotes/origin/HEAD",`refs/remotes/origin/${b}`),b&&y){await Y(l,`refs/heads/${b}`,y),await $e(l,"HEAD",`refs/heads/${b}`);let E={oldHash:Z,newHash:y,name:k.name,email:k.email,timestamp:k.timestamp,tz:k.tz,message:C};await Te(l,`refs/heads/${b}`,E),await Te(l,"HEAD",E);let I=await ae(l);I[`branch "${b}"`]={remote:"origin",merge:`refs/heads/${b}`},await Ge(l,I);let
|
|
288
|
-
`,exitCode:0};return await t?.hooks?.emitPost("post-clone",{repository:o,targetPath:f,bare:n.bare,branch:b}),O}})}function
|
|
296
|
+
`,exitCode:0};let g=[],w=new Set;for(let E of p)E.name!=="HEAD"&&(w.has(E.hash)||(w.add(E.hash),g.push(E.hash)));g.length>0&&await h.fetch(g,[]);let x=p.find(E=>E.name==="HEAD"),b=null,y=null,k=await Ot(l,r.env),C=`clone: from ${a}`,P=h.headTarget;P?.startsWith("refs/heads/")&&p.some(E=>E.name===P)&&(b=P.slice(11),y=p.find(E=>E.name===P)?.hash??null);for(let E of p)if(E.name!=="HEAD"){if(E.name.startsWith("refs/heads/")){let I=E.name.slice(11),A=`refs/remotes/origin/${I}`;await Y(l,A,E.hash),await Te(l,A,{oldHash:Z,newHash:E.hash,name:k.name,email:k.email,timestamp:k.timestamp,tz:k.tz,message:C}),!b&&x&&E.hash===x.hash&&(b=I,y=E.hash)}E.name.startsWith("refs/tags/")&&await Y(l,E.name,E.hash)}if(i){let E=p.find(I=>I.name===`refs/heads/${i}`);if(!E)return T(`Remote branch '${i}' not found in upstream origin`);b=i,y=E.hash}if(!b){let E=p.find(I=>I.name.startsWith("refs/heads/"));E&&(b=E.name.slice(11),y=E.hash)}if(n.bare)return b&&await $e(l,"HEAD",`refs/heads/${b}`),await t?.hooks?.emitPost("post-clone",{repository:o,targetPath:f,bare:n.bare,branch:b}),{stdout:"",stderr:`Cloning into bare repository '${c}'...
|
|
297
|
+
`,exitCode:0};if(b&&await $e(l,"refs/remotes/origin/HEAD",`refs/remotes/origin/${b}`),b&&y){await Y(l,`refs/heads/${b}`,y),await $e(l,"HEAD",`refs/heads/${b}`);let E={oldHash:Z,newHash:y,name:k.name,email:k.email,timestamp:k.timestamp,tz:k.tz,message:C};await Te(l,`refs/heads/${b}`,E),await Te(l,"HEAD",E);let I=await ae(l);I[`branch "${b}"`]={remote:"origin",merge:`refs/heads/${b}`},await Ge(l,I);let A=await M(l,y);await Ni(l,A.tree);let _=await He(l,A.tree),G=Or(_.map(z=>({path:z.path,mode:parseInt(z.mode,8),hash:z.hash,stage:0,stat:pe()})));await re(l,G)}let O={stdout:"",stderr:`Cloning into '${c}'...
|
|
298
|
+
`,exitCode:0};return await t?.hooks?.emitPost("post-clone",{repository:o,targetPath:f,bare:n.bare,branch:b}),O}})}function Ka(e,t){e.command("commit",{description:"Record changes to the repository",options:{message:te.string().alias("m").describe("Commit message"),file:te.string().alias("F").describe("Read commit message from file ('-' for stdin)"),allowEmpty:v().describe("Allow creating an empty commit"),amend:v().describe("Amend the previous commit"),noEdit:v().describe("Use the previous commit message without editing"),all:v().alias("a").describe("Auto-stage modified and deleted tracked files")},handler:async(n,r)=>{if(n.message!==void 0&&n.file!==void 0)return T("options '-m' and '-F' cannot be used together");let o=await B(r.fs,r.cwd,t);if(S(o))return o;let s=o,a=await U(s);if(n.all){let Q=Fe(s);if(Q)return Q;let ge=await lt(s,a);for(let Ie of ge)Ie.status==="modified"?a=(await Gt(s,a,Ie.path)).index:Ie.status==="deleted"&&(a=Ne(a,Ie.path));let De=new Set(xe(a).map(Ie=>Ie.path)),dn=new Set(a.entries.filter(Ie=>Ie.stage>0&&!De.has(Ie.path)).map(Ie=>Ie.path));for(let Ie of dn){let wr=H(s.workTree,Ie);await r.fs.exists(wr)?a=(await Gt(s,a,Ie)).index:a=Ne(a,Ie)}}let i=await F(s,"MERGE_HEAD"),c=await F(s,"CHERRY_PICK_HEAD"),f=await F(s,"REVERT_HEAD"),u=await gt(s)?await F(s,"REBASE_HEAD"):null,l=n.amend,m=await X(s);if(l){if(!m)return T("You have nothing yet to amend.");if(i)return T("You are in the middle of a merge -- cannot amend.");if(c)return T("You are in the middle of a cherry-pick -- cannot amend.")}if(dt(a)){let Q=new Set,ge=[];for(let De of a.entries)De.stage>0&&!Q.has(De.path)&&(Q.add(De.path),ge.push(`U ${De.path}`));return ge.sort(),{stdout:ge.length>0?`${ge.join(`
|
|
289
299
|
`)}
|
|
290
300
|
`:"",stderr:`error: Committing is not possible because you have unmerged files.
|
|
291
301
|
hint: Fix them up in the work tree, and then use 'git add/rm <file>'
|
|
292
302
|
hint: as appropriate to mark resolution and make a commit.
|
|
293
303
|
fatal: Exiting because of an unresolved conflict.
|
|
294
|
-
`,exitCode:128}}let h=l&&m?await M(s,m):null,p=n.message;if(!p&&n.file!==void 0){if(n.file==="-")p=r.stdin;else{let Q=n.file.startsWith("/")?n.file:
|
|
295
|
-
`,stderr:"",exitCode:1}}if(!p&&l&&h&&(p=h.message),!p&&(i||c||f||u)){let Q=await qe(s,"MERGE_MSG");Q!==null&&(p=
|
|
304
|
+
`,exitCode:128}}let h=l&&m?await M(s,m):null,p=n.message;if(!p&&n.file!==void 0){if(n.file==="-")p=r.stdin;else{let Q=n.file.startsWith("/")?n.file:H(r.cwd,n.file);if(!await r.fs.exists(Q))return T(`could not read log file '${n.file}': No such file or directory`);let ge=await r.fs.readFile(Q);p=typeof ge=="string"?ge:new TextDecoder().decode(ge)}if(p=rr(p),!p)return{stdout:`Aborting commit due to empty commit message.
|
|
305
|
+
`,stderr:"",exitCode:1}}if(!p&&l&&h&&(p=h.message),!p&&(i||c||f||u)){let Q=await qe(s,"MERGE_MSG");Q!==null&&(p=rr(Q))}if(!p)return j("error: must provide a commit message with -m or -F");let g=xe(a),w=await ke(s,g);if(t?.hooks){let Q=await t.hooks.emitPre("pre-commit",{index:a,treeHash:w});if(Q)return j(Q.message??"")}let x=n.allowEmpty,b=null;if(l&&h){let Q=h.parents[0];Q?b=(await M(s,Q)).tree:b=await st("tree",new Uint8Array(0))}else m&&(b=(await M(s,m)).tree);let y=l&&h&&h.parents.length>1;if(!x&&!i&&!y){if(!m&&!l&&g.length===0)return{stdout:await Be(s,{fromCommit:!0,index:a}),stderr:"",exitCode:1};if(b!==null&&b===w){if(l){let Q=h?.parents[0]??null;return{stdout:`${await Be(s,{fromCommit:!0,compareHash:Q,noWarn:!0,index:a})}No changes
|
|
296
306
|
`,stderr:`You asked to amend the most recent commit, but doing so would make
|
|
297
307
|
it empty. You can repeat your command with --allow-empty, or you can
|
|
298
308
|
remove the commit entirely with "git reset HEAD^".
|
|
@@ -302,55 +312,56 @@ If you wish to commit it anyway, use:
|
|
|
302
312
|
git commit --allow-empty
|
|
303
313
|
|
|
304
314
|
Otherwise, please use 'git cherry-pick --skip'
|
|
305
|
-
`,exitCode:1}:{stdout:await Be(s,{fromCommit:!0,index:a}),stderr:"",exitCode:1}}}let k=await Ht(s,r.env);if(S(k))return k;let C=await Le(s,r.env);if(S(C))return C;l&&h&&(k.name=h.author.name,k.email=h.author.email,k.timestamp=h.author.timestamp,k.timezone=h.author.timezone),c&&(k=(await M(s,c)).author);let P=mt(p);if(t?.hooks){let Q={message:P},ge=await t.hooks.emitPre("commit-msg",Q);if(ge)return j(ge.message??"");P=Q.message}let O;l&&h?O=[...h.parents]:(O=m?[m]:[],i&&O.push(i));let E=$t({type:"commit",tree:w,parents:O,author:k,committer:C,message:P}),I=await we(s,"commit",E);await re(s,a);let
|
|
306
|
-
${V}`,stderr:"",exitCode:0}}})}function hr(e){let t=e.split(".");return t.length===2||t.length===3}function
|
|
307
|
-
`,stderr:"",exitCode:0}}async function
|
|
315
|
+
`,exitCode:1}:{stdout:await Be(s,{fromCommit:!0,index:a}),stderr:"",exitCode:1}}}let k=await Ht(s,r.env);if(S(k))return k;let C=await Le(s,r.env);if(S(C))return C;l&&h&&(k.name=h.author.name,k.email=h.author.email,k.timestamp=h.author.timestamp,k.timezone=h.author.timezone),c&&(k=(await M(s,c)).author);let P=mt(p);if(t?.hooks){let Q={message:P},ge=await t.hooks.emitPre("commit-msg",Q);if(ge)return j(ge.message??"");P=Q.message}let O;l&&h?O=[...h.parents]:(O=m?[m]:[],i&&O.push(i));let E=$t({type:"commit",tree:w,parents:O,author:k,committer:C,message:P}),I=await we(s,"commit",E);await re(s,a);let A=await J(s);A&&A.type==="symbolic"?await Y(s,A.target,I):await Y(s,"HEAD",I);let _=ue(P),G;l?G="commit (amend)":i?G="commit (merge)":c?G="commit (cherry-pick)":m?G="commit":G="commit (initial)";let z=`${G}: ${_}`,D=A?.type==="symbolic"?A.target:"HEAD";await ee(s,r.env,D,m,I,z,A?.type==="symbolic"),i&&await or(s),c&&await kt(s),f&&await pt(s),u&&await et(s,"MERGE_MSG"),await t?.hooks?.emitPost("post-commit",{hash:I,message:P,branch:A?.type==="symbolic"?de(A.target):null,parents:O,author:k});let $=A?.type==="symbolic"?A.target:null,R=$?de($):"detached HEAD",N;if(l&&h){let Q=h.parents[0];N=Q?(await M(s,Q)).tree:null}else N=m?(await M(s,m)).tree:null;let q=k.timestamp!==C.timestamp||k.timezone!==C.timezone,L=O.length>1,V=await St(s,N,w,k,C,q,L);return{stdout:`${ut(R,I,p,O.length===0&&!l)}
|
|
316
|
+
${V}`,stderr:"",exitCode:0}}})}function hr(e){let t=e.split(".");return t.length===2||t.length===3}function Jl(e){let t=[];for(let[n,r]of Object.entries(e)){let o=n.match(/^(\S+)\s+"(.+)"$/);for(let[s,a]of Object.entries(r)){let i=o?`${o[1]}.${o[2]}.${s}`:`${n}.${s}`;t.push(`${i}=${a}`)}}return t}function Xa(e,t){e.command("config",{description:"Get and set repository options",args:[W.string().name("positionals").variadic().optional()],options:{list:v().alias("l").describe("List all config entries"),unset:v().describe("Remove a config key")},handler:async(n,r)=>{let o=await B(r.fs,r.cwd,t);if(S(o))return o;let s=o,a=n.positionals,i=a[0];if(n.list)return Ya(await ae(s));if(n.unset){let f=i;return f?hr(f)?Va(s,f):j(`error: invalid key: ${f}`,2):j("error: missing key",2)}if(i==="list")return Ya(await ae(s));if(i==="get"){let f=a[1];return f?hr(f)?za(s,f):j(`error: invalid key: ${f}`,2):j("error: missing key",2)}if(i==="set"){let f=a[1],d=a[2];return!f||d===void 0?j("error: missing key and/or value",2):hr(f)?(await Ss(s,f,d),{stdout:"",stderr:"",exitCode:0}):j(`error: invalid key: ${f}`,2)}if(i==="unset"){let f=a[1];return f?hr(f)?Va(s,f):j(`error: invalid key: ${f}`,2):j("error: missing key",2)}if(!i)return j("usage: git config [get|set|unset|list] [<key>] [<value>]",2);if(!hr(i))return j(`error: invalid key: ${i}`,2);let c=a[1];return c!==void 0?(await Ss(s,i,c),{stdout:"",stderr:"",exitCode:0}):za(s,i)}})}async function za(e,t){let n=await bt(e,t);return n===void 0?j(""):{stdout:`${n}
|
|
317
|
+
`,stderr:"",exitCode:0}}async function Va(e,t){return await Zo(e,t)?{stdout:"",stderr:"",exitCode:0}:j("",5)}function Ya(e){let t=Jl(e);return{stdout:t.length>0?`${t.join(`
|
|
308
318
|
`)}
|
|
309
|
-
`:"",stderr:"",exitCode:0}}function
|
|
319
|
+
`:"",stderr:"",exitCode:0}}function ps(e){let{path:t,parentHashes:n,parentModes:r,resultHash:o,resultMode:s}=e,a=[];a.push(`diff --cc ${t}`);let i=n.map(x=>x?K(x):"0000000"),c=o?K(o):"0000000";a.push(`index ${i.join(",")}..${c}`);let f=e.resultContent.length>0,d=n.every(x=>x===null),u=!f&&n.some(x=>x!==null);if(d&&s)a.push(`new file mode ${s}`);else if(u){let x=r.map(b=>b||"000000").join(",");a.push(`deleted file mode ${x}`)}else{let x=r.map(k=>k||"000000"),b=s||"000000";x.some(k=>k!==b)&&a.push(`mode ${x.join(",")}..${b}`)}let l=n.some(x=>x!==null);if(a.push(l?`--- a/${t}`:"--- /dev/null"),a.push(f?`+++ b/${t}`:"+++ /dev/null"),u||d)return`${a.join(`
|
|
310
320
|
`)}
|
|
311
|
-
`;let m=e.parentContents.map(x=>x.length>0?nn(x):[]),h=e.resultContent.length>0?nn(e.resultContent):[],p=m.map(x=>xt(x,h)),g=
|
|
321
|
+
`;let m=e.parentContents.map(x=>x.length>0?nn(x):[]),h=e.resultContent.length>0?nn(e.resultContent):[],p=m.map(x=>xt(x,h)),g=Ql(m,h,p),w=tu(g,m.length,h);if(w.length===0)return"";for(let x of w)a.push(x);return`${a.join(`
|
|
312
322
|
`)}
|
|
313
|
-
`}function
|
|
314
|
-
`);let c=a[0],f=await M(e,c),d=await Ae(e,f.tree,s.commit.tree),u=await
|
|
323
|
+
`}function Ql(e,t,n){let r=e.length,o=n.map(a=>{let i=[],c=new Map,f=0;for(let d of a)if(d.type==="keep")i[d.newLineNo-1]="keep",f=d.newLineNo;else if(d.type==="insert")i[d.newLineNo-1]="insert",f=d.newLineNo;else if(d.type==="delete"){let u=c.get(f)??[];u.push({text:d.line,parentLineNo:d.oldLineNo}),c.set(f,u)}return{resultStatus:i,deletions:c}}),s=[];for(let a=0;a<=t.length;a++){let i=[];for(let f=0;f<r;f++){let d=o[f];i.push(d?.deletions.get(a)??[])}let c=eu(i,r);for(let f of c)s.push(f);if(a<t.length){let f=[],d=Array(r).fill(0);for(let u=0;u<r;u++){let m=o[u]?.resultStatus[a];if(f.push(m==="insert"?"+":" "),m==="keep"){let h=n[u];if(h){for(let p of h)if(p.type==="keep"&&p.newLineNo===a+1){d[u]=p.oldLineNo;break}}}}s.push({columns:f,text:t[a]??"",resultLineNo:a+1,parentLineNos:d})}}return s}function eu(e,t){if(!e.some(o=>o.length>0))return[];if(t===2){let o=e[0]??[],s=e[1]??[];if(o.length===0)return s.map(d=>({columns:[" ","-"],text:d.text,resultLineNo:0,parentLineNos:[0,d.parentLineNo]}));if(s.length===0)return o.map(d=>({columns:["-"," "],text:d.text,resultLineNo:0,parentLineNos:[d.parentLineNo,0]}));let a=o.map(d=>d.text),i=s.map(d=>d.text),c=xt(a,i),f=[];for(let d of c)if(d.type==="keep"){let u=o.find(m=>m.text===d.line&&m.parentLineNo===d.oldLineNo),l=s.find(m=>m.text===d.line&&m.parentLineNo===d.newLineNo);f.push({columns:["-","-"],text:d.line,resultLineNo:0,parentLineNos:[u?.parentLineNo??0,l?.parentLineNo??0]})}else if(d.type==="delete"){let u=o.find(l=>l.parentLineNo===d.oldLineNo);f.push({columns:["-"," "],text:d.line,resultLineNo:0,parentLineNos:[u?.parentLineNo??0,0]})}else if(d.type==="insert"){let u=s.find(l=>l.parentLineNo===d.newLineNo);f.push({columns:[" ","-"],text:d.line,resultLineNo:0,parentLineNos:[0,u?.parentLineNo??0]})}return f}let r=[];for(let o=0;o<t;o++){let s=e[o]??[];for(let a of s){let i=Array(t).fill(" ");i[o]="-";let c=Array(t).fill(0);c[o]=a.parentLineNo,r.push({columns:i,text:a.text,resultLineNo:0,parentLineNos:c})}}return r}function tu(e,t,n){let o=[];for(let d=0;d<e.length;d++)e[d]?.columns.some(l=>l!==" ")&&o.push(d);if(o.length===0)return[];let s=[],a=o[0]??0,i=Math.max(0,a-3),c=Math.min(e.length-1,a+3);for(let d=1;d<o.length;d++){let u=o[d]??0,l=Math.max(0,u-3),m=Math.min(e.length-1,u+3);l<=c+1||(s.push({start:i,end:c}),i=l),c=m}s.push({start:i,end:c});let f=[];for(let d of s){let u=e.slice(d.start,d.end+1),l=[];for(let y=0;y<t;y++){let k=u.filter(C=>(C.parentLineNos[y]??0)>0||C.columns[y]==="-");if(k.length===0)l.push({start:1,count:0});else{let P=k.find(O=>(O.parentLineNos[y]??0)>0)?.parentLineNos[y]??1;l.push({start:P,count:k.length})}}let m=u.filter(y=>y.resultLineNo>0),h=m[0],p=h?h.resultLineNo:1,g=m.length,w="";for(let y=p-2;y>=0;y--){let k=n[y];if(k&&/^[a-zA-Z$_]/.test(k)){w=` ${k.trimEnd().slice(0,79)}`;break}}let x=l.map(y=>`-${y.start},${y.count}`),b=`${"@".repeat(t+1)} ${x.join(" ")} +${p},${g} ${"@".repeat(t+1)}${w}`;f.push(b);for(let y of u)f.push(`${y.columns.join("")}${y.text}`)}return f}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}var Oo=new TextDecoder;function ec(e){return"exitCode"in e}function Fn(e){return e.toString(8).padStart(6,"0")}function tc(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 nc(e,t){e.command("diff",{description:"Show changes between commits, commit and working tree, etc.",args:[W.string().name("commits").variadic().optional()],options:{cached:v().describe("Show staged changes (index vs HEAD)"),staged:v().describe("Synonym for --cached"),stat:v().describe("Show diffstat summary"),nameOnly:v().describe("Show only names of changed files"),nameStatus:v().describe("Show names and status of changed files"),shortstat:v().describe("Show only the shortstat summary line"),numstat:v().describe("Machine-readable insertions/deletions per file")},handler:async(n,r,o)=>{let s=await B(r.fs,r.cwd,t);if(S(s))return s;let a=s,i=n.cached||n.staged,c=n.commits,f=Ze(a,r.cwd),d=o.passthrough.length>0?o.passthrough.map(p=>Oe(p,f)):null,u=n.stat?"stat":n.nameOnly?"name-only":n.nameStatus?"name-status":n.shortstat?"shortstat":n.numstat?"numstat":"unified",l,m=c.length===1?gs(c[0]):null;if(m){if(i)return T("too many arguments");m.type==="three-dot"?l=await ou(a,m.left,m.right,d):l=await Qa(a,m.left,m.right,d)}else if(c.length===2)l=await Qa(a,c[0],c[1],d);else{if(c.length>2)return T("too many arguments");i?l=await su(a,c.length===1?c[0]:null,d):c.length===1?l=await iu(a,c[0],d):l=await nu(a,d)}if(ec(l))return l;let h=await au(a,l.items,u);return l.stderr&&(h.stderr=l.stderr),h}})}async function nu(e,t){let n=Fe(e);if(n)return n;let r=await U(e),o=new Set,s=new Map,a=new Map,i=new Map;for(let d of r.entries)d.stage===0?s.set(d.path,d):(o.add(d.path),d.stage===2?a.set(d.path,d):d.stage===3&&i.set(d.path,d));let c=await lt(e,r);c.sort((d,u)=>he(d.path,u.path));let f=[];for(let d of c){if(d.status==="untracked"||t&&!me(t,d.path)||o.has(d.path))continue;let u=s.get(d.path);if(!u)continue;let l=Fn(u.mode),m;if(d.status==="modified"&&e.workTree){let h=H(e.workTree,d.path),p=await e.fs.readFileBuffer(h);m=await st("blob",p)}f.push({path:d.path,status:d.status==="deleted"?"D":"M",oldHash:u.hash,newHash:m,oldMode:l,newMode:l,newFromWorkTree:d.status==="modified"})}for(let d of o){if(t&&!me(t,d))continue;let u=a.get(d),l=i.get(d);await ru(f,e,d,u,l)}return f.sort((d,u)=>{let l=he(d.path,u.path);return l!==0?l:d.status==="U"&&u.status!=="U"?-1:d.status!=="U"&&u.status==="U"?1:0}),{items:f}}async function ru(e,t,n,r,o){let s=t.workTree;if(s&&r&&o){let a=Fn(r.mode),i=Fn(o.mode),{exists:c,hash:f}=await Za(t.fs,s,n);e.push({path:n,status:"U",newHash:f,newMode:a,newFromWorkTree:c,combinedParentHashes:[r.hash,o.hash],combinedParentModes:[a,i]}),Ja(e,n,r.hash,a,c,f);return}if(e.push({path:n,status:"U"}),s&&r){let a=Fn(r.mode),{exists:i,hash:c}=await Za(t.fs,s,n);Ja(e,n,r.hash,a,i,c)}}async function Za(e,t,n){let r=H(t,n);if(!await e.exists(r))return{exists:!1};let o=await Qn(e,r);return{exists:!0,hash:await st("blob",o)}}function Ja(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 su(e,t,n){let r=null;if(t){let l=await ye(e,t);if(S(l))return l;r=l.commit.tree}else{let l=await X(e);l&&(r=(await M(e,l)).tree)}let o=await se(e,r),s=await U(e),a=new Set;for(let l of s.entries)l.stage>0&&a.add(l.path);let i=new Map(xe(s).map(l=>[l.path,l])),c=[];for(let[l,m]of i){if(a.has(l))continue;let h=o.get(l);h?h.hash!==m.hash&&c.push({path:l,status:"modified",oldHash:h.hash,newHash:m.hash,oldMode:h.mode,newMode:Fn(m.mode)}):c.push({path:l,status:"added",newHash:m.hash,newMode:Fn(m.mode)})}for(let[l,m]of o)a.has(l)||i.has(l)||c.push({path:l,status:"deleted",oldHash:m.hash,oldMode:m.mode});let{remaining:f,renames:d}=await Ye(e,c),u=tc(f,d);for(let l of a)u.push({path:l,status:"U"});return u.sort((l,m)=>he(l.path,m.path)),n?{items:u.filter(l=>me(n,l.path))}:{items:u}}async function Qa(e,t,n,r){let o=await ye(e,t);if(S(o))return o;let s=await ye(e,n);if(S(s))return s;let a=await Ae(e,o.commit.tree,s.commit.tree);return rc(e,a,r)}async function ou(e,t,n,r){let o=await ye(e,t);if(S(o))return o;let s=await ye(e,n);if(S(s))return s;let a=await ht(e,o.hash,s.hash);if(a.length===0)return T(`${t}...${n}: no merge base`);let i;a.length>1&&(i=`warning: ${t}...${n}: multiple merge bases, using ${a[0]}
|
|
324
|
+
`);let c=a[0],f=await M(e,c),d=await Ae(e,f.tree,s.commit.tree),u=await rc(e,d,r);return ec(u)||i&&(u.stderr=i),u}async function rc(e,t,n){let{remaining:r,renames:o}=await Ye(e,t),s=tc(r,o);return s.sort((a,i)=>he(a.path,i.path)),n?{items:s.filter(a=>me(n,a.path))}:{items:s}}async function iu(e,t,n){let r=Fe(e);if(r)return r;let o=await ye(e,t);if(S(o))return o;let s=e.workTree,a=await se(e,o.commit.tree),i=[];for(let[c,f]of a){if(n&&!me(n,c))continue;let d=H(s,c);if(!await e.fs.exists(d)){i.push({path:c,status:"D",oldHash:f.hash,oldMode:f.mode});continue}let u=await e.fs.readFileBuffer(d),l=await st("blob",u);l!==f.hash&&i.push({path:c,status:"M",oldHash:f.hash,newHash:l,oldMode:f.mode,newMode:f.mode,newFromWorkTree:!0})}return i.sort((c,f)=>he(c.path,f.path)),{items:i}}async function au(e,t,n){let r;switch(n){case"stat":r=await mu(e,t);break;case"shortstat":r=await hu(e,t);break;case"numstat":r=await uu(e,t);break;case"name-only":r=du(t);break;case"name-status":r=lu(t);break;default:r=await cu(e,t);break}return{stdout:r,stderr:"",exitCode:0}}async function cu(e,t){let n="",r=new Set,o=await fu(e,t);for(let s of t)if(s.status==="U")if(s.combinedParentHashes){let a=await Promise.all(s.combinedParentHashes.map(async f=>f?await fe(e,f):"")),i=await Ro(e,s);if(a.some(f=>Pe(f))||Pe(i)){let f=s.combinedParentHashes.map(d=>d?K(d):"0000000");n+=`diff --cc ${s.path}
|
|
315
325
|
index ${f.join(",")}..0000000
|
|
316
326
|
Binary files differ
|
|
317
|
-
`,r.add(s.path)}else{let f=
|
|
327
|
+
`,r.add(s.path)}else{let f=ps({path:s.path,parentHashes:s.combinedParentHashes,parentModes:s.combinedParentModes??[],parentContents:a,resultHash:null,resultMode:s.newMode??null,resultContent:i});f?(n+=f,r.add(s.path)):n+=`* Unmerged path ${s.path}
|
|
318
328
|
`}}else n+=`* Unmerged path ${s.path}
|
|
319
|
-
`;for(let s of t){if(s.status==="U"||r.has(s.path))continue;let a=s.oldHash?await fe(e,s.oldHash):"",i=await
|
|
320
|
-
`;return t}function
|
|
329
|
+
`;for(let s of t){if(s.status==="U"||r.has(s.path))continue;let a=s.oldHash?await fe(e,s.oldHash):"",i=await Ro(e,s);s.status==="R"&&s.oldPath?n+=At({path:s.oldPath,oldContent:a,newContent:i,oldMode:s.oldMode,newMode:s.newMode,oldHash:ws(s.oldHash,o),newHash:ws(s.newHash,o),renameTo:s.path,similarity:s.similarity}):n+=At({path:s.path,oldContent:a,newContent:i,oldMode:s.oldMode,newMode:s.newMode,oldHash:ws(s.oldHash,o),newHash:ws(s.newHash,o),isNew:s.status==="A",isDeleted:s.status==="D"})}return n}async function fu(e,t){let n=new Set;for(let i of t)i.oldHash&&i.oldHash.length===40&&n.add(i.oldHash),i.newHash&&i.newHash.length===40&&n.add(i.newHash);let r=new Map,o=async i=>{let c=r.get(i);if(c)return c;let f=H(e.gitDir,"objects",i),d=await e.fs.exists(f)?await e.fs.readdir(f):[];return r.set(i,d),d},s=async(i,c)=>{let f=i.slice(0,2),d=i.slice(2,c),u=await o(f),l=0;for(let m of u)if(m.startsWith(d)&&(l++,l>1))return!1;return l===1},a=new Map;for(let i of n){let c=7;for(;c<40&&!await s(i,c);)c++;a.set(i,i.slice(0,c))}return a}function ws(e,t){if(e)return e.length!==40?e:t.get(e)??K(e)}function du(e){let t="";for(let n of e)t+=`${n.path}
|
|
330
|
+
`;return t}function lu(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}
|
|
321
331
|
`}else t+=`${n.status} ${n.path}
|
|
322
|
-
`;return t}async function
|
|
323
|
-
`;continue}let o=r.oldHash?await fe(e,r.oldHash):"",s=await
|
|
332
|
+
`;return t}async function uu(e,t){let n="";for(let r of t){if(r.status==="U"){n+=`0 0 ${r.path}
|
|
333
|
+
`;continue}let o=r.oldHash?await fe(e,r.oldHash):"",s=await Ro(e,r),a=Pe(o)||Pe(s),i,c;if(a)i="-",c="-";else{let{ins:f,del:d}=sc(o,s);i=String(f),c=String(d)}if(r.status==="R"&&r.oldPath){let f=Mn(r.oldPath,r.path);n+=`${i} ${c} ${f}
|
|
324
334
|
`}else n+=`${i} ${c} ${r.path}
|
|
325
|
-
`}return n}async function
|
|
335
|
+
`}return n}async function mu(e,t){let n=await oc(e,t);return io(n)}async function hu(e,t){let n=await oc(e,t);if(n.length===0)return"";let r=0,o=0,s=0;for(let i of n)i.isUnmerged||(s++,r+=i.insertions,o+=i.deletions);let a=Zr(s,r,o);return a?`${a}
|
|
326
336
|
`:n.some(i=>i.isUnmerged)?` 0 files changed
|
|
327
|
-
`:""}async function
|
|
328
|
-
`);for(let E of x){let I=await F(s,E.localRef);await Y(s,E.localRef,E.remote.hash),await Te(s,E.localRef,{oldHash:I??Z,newHash:E.remote.hash,name:k.name,email:k.email,timestamp:k.timestamp,tz:k.tz,message:I?"fetch":"fetch: storing head"});let
|
|
329
|
-
`)}}else{let z=E.remote.name.startsWith("refs/tags/")?" * [new tag]":" * [new branch]";C.push(`${z} ${
|
|
330
|
-
`)}}if(!n.tags)for(let E of l){if(!E.name.startsWith("refs/tags/")||w.has(E.hash))continue;let I=await F(s,E.name),
|
|
331
|
-
`))}if(n.prune){let E=`refs/remotes/${a}`,I=await le(s,E),
|
|
332
|
-
`))}}let P=l.find(E=>E.name==="HEAD");if(P){let E=
|
|
333
|
-
`)}let O={stdout:"",stderr:C.join(""),exitCode:0};return await t?.hooks?.emitPost("post-fetch",{remote:a,url:f.url,refsUpdated:x.length}),O}})}function bs(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 ic(e){let t=new Set,n=await X(e);n&&t.add(n);let r=await le(e,"refs");for(let i of r)t.add(i.hash);let o=v(e.gitDir,"logs");await e.fs.exists(o)&&await ac(e,o,o,t);let s=await U(e);for(let i of s.entries)t.add(i.hash);for(let i of["MERGE_HEAD","CHERRY_PICK_HEAD","ORIG_HEAD"]){let c=await F(e,i);c&&t.add(c)}let a=[];for(let i of t)await zt(e,i)&&a.push(i);return a}async function ac(e,t,n,r){let o=await e.fs.readdir(t);for(let s of o){let a=v(t,s),i=await e.fs.stat(a);if(i.isDirectory)await ac(e,a,n,r);else if(i.isFile){let c=a.slice(n.length+1),f=await Me(e,c);for(let d of f)d.newHash!==Z&&r.add(d.newHash)}}}var Es=new Uint32Array([0,2874782929,1454598562,4260027763,104818581,2909197124,1351355959,4225088230,209637162,2804382715,1523426952,4053013081,172075199,2702711918,1559413021,4155209164,419274324,3013880453,1313798134,3843506983,516094401,3046853904,1215402083,3811058866,344150398,3218793903,1110456540,3916008461,314324715,3118826042,1141858121,4015451032,838548648,2594343033,1732793610,3423723995,935615293,2627596268,1635201695,3392046670,1032188802,2531018579,1798740512,3228511985,1002083351,2430804166,1829371317,3327150436,688300796,2187269677,2142620510,3572268943,792315241,2220913080,2039131339,3537049626,628649430,2384582919,1942684788,3633492133,591858243,2283716242,1978950625,3735934768,1677097296,3366964609,893718770,2652677155,1707679429,3465587220,863663975,2552480694,1871230586,3302032043,960225240,2455923465,1773654511,3270403390,1057273933,2489126044,2064377604,3495056341,767069862,2262907511,2100592785,3597481024,730327347,2162056674,2004166702,3693911295,566641036,2325738845,1900695483,3658742634,670639641,2359333576,1376601592,4183093545,79572058,2951190667,1412571757,4285241020,42027983,2849570590,1584630482,4113186307,146858864,2744735649,1481436487,4078262678,251626725,2779131956,1257298860,3785977725,474198542,3071936223,1288682553,3885369576,444388763,2972016970,1183716486,3990331479,272465188,3143944693,1085371155,3957901250,369236657,3176902240,1823819377,3354194592,973483987,2438961922,1787437540,3251868981,1010387014,2539715735,1623951707,3415358858,913891577,2636207144,1727327950,3450690079,809994092,2602447805,1950930981,3742461172,586920327,2309096790,1920450480,3643673441,616879634,2409456323,2016810767,3547309022,780500653,2245839484,2114547866,3578840139,683284792,2212736489,1565424345,4128755208,201134971,2695145386,1534139724,4029196701,230847726,2795225151,1362146803,4201185570,126082129,2899994752,1460654694,4233520823,29146052,2867138325,1169417357,4008333404,318803247,3092855294,1133282072,3906287561,356510394,3194379883,1238182823,3801390966,528368133,3022517972,1341279282,3836475619,423699856,2987954497,256065313,2753203184,1508923011,4071219794,159144116,2720394341,1607414038,4103505351,54390795,2825143514,1435408809,4275514744,84055966,2925208399,1404173884,4175973101,398369141,3169260964,1091422423,3931405318,293717728,3134747185,1194504002,3966442387,465595999,2962872974,1299384317,3861558060,503253450,3064380699,1263296616,3759527097,1052246921,2514597720,1745578539,3276988154,948397084,2480853197,1848905150,3312302447,851889315,2577365106,1685431553,3475771856,888777526,2678071271,1649066644,3373495877,642096605,2367432972,1895232639,3685695662,544930376,2334346905,1992922090,3717211963,708530935,2170742310,2089302869,3620835204,738473314,2271052211,2058837184,3522095121]),gu=new Uint32Array([0,2125799437,1446245579,679924934,121527623,2039184714,1359849868,800622977,243055246,1892260483,1481592389,653946440,155379657,2012727236,1601245954,566506255,486110492,1649169681,1254785495,880779738,466036827,1701972054,1307892880,859962525,310759314,1815146399,1152793433,973282132,364614357,1796125400,1133012510,1027425811,972220984,1195887157,1874927347,292830974,1053603711,1081710450,1761559476,373973945,932073654,1228632251,1639818365,520651888,816844273,1308962300,1719925050,406247735,621518628,1539227433,1933077487,227363810,573948515,1551950446,1946564264,179508901,729228714,1438778791,2101662049,66187628,743012589,1392269536,2054851622,80718891,1944441968,223409277,634790075,1533214902,1960544567,175024442,585661948,1549622769,2107207422,53235443,732600885,1428142648,2057778105,68293556,747947890,1377953663,1864147308,296321377,959403431,1201305002,1747123243,379051046,1041303776,1084500205,1633688546,534068207,928247593,1239863076,1717454501,418080424,812495470,1322816099,1243037256,883039813,472173187,1653729934,1294557967,865878786,454727620,1706014665,1147897030,987669707,307785741,1827491840,1129699713,1038154124,359017802,1808993607,1458457428,677079897,14532511,2120785810,1372591635,795162142,132375256,2035729109,1486025178,640143831,245433617,1880368412,1605151901,555322512,161437782,1999272027,1284643889,841432124,446818554,1679083767,1269580150,890855803,497006013,1663735216,1122936511,1012631218,350048884,1785229945,1171323896,996531189,333647667,1834364734,1349216557,786319648,106470886,2028846571,1465201770,702551143,23511201,2144592044,1578619811,547550126,136587112,1989216101,1495895780,664579817,253393455,1907317282,1969288713,198563332,592642754,1575363279,1918806862,216763203,611147653,1524137864,2065452167,94989450,758102092,1402640449,2082607552,43463117,705815819,1420084486,1771668245,388801304,1068136414,1092573139,1856495186,269680223,949234329,1176570516,1743075739,424679830,836160848,1331948893,1624990940,510543057,921210903,1214099482,1064814657,1103292492,1766079626,401677447,944346374,1190966539,1853514189,282018240,822833871,1337873090,1731757572,428713481,909455240,1216352133,1611062083,515111758,596557149,1564187984,1975339414,185100699,615571482,1510326295,1921193169,204879068,770836435,1397172190,2076308248,91542293,718035604,1417247385,2097131103,38440530,109388409,2016412276,1354159794,772011711,29065022,2131648307,1468566517,691907576,150575351,1984739578,1590324284,545213489,264750512,1903355325,1509175675,658575734,444356453,1690924904,1280287662,855278499,490867234,1677142575,1265762025,902094564,335605227,1790299622,1110645024,1015429421,322875564,1837863073,1158497383,1001940074]),ys=64,wu=4,Ro=4096,cc=65536,bu=127;function yu(e){let t=e.byteLength;if(t===0)return null;let n=(t-1)/16|0;if(n===0)return null;let r=n>>>2;r<16&&(r=16),r=xu(r);let o=r-1,s=new Uint32Array(r),a=[],i=-1>>>0;for(let l=n*16-16;l>=0;l-=16){let m=0;for(let h=1;h<=16;h++)m=(m<<8|e[l+h])^Es[m>>>23];if(m=m>>>0,m===i)a[a.length-1].ptr=l+16;else{i=m;let h=m&o;a.push({ptr:l+16,val:m}),s[h]++}}let c=new Map;for(let l of a){let m=l.val&o,h=c.get(m);h||(h=[],c.set(m,h)),h.push(l)}for(let[l,m]of c){if(m.length<=ys)continue;let h=[],p=m.length/ys;for(let g=0;g<ys;g++)h.push(m[Math.floor(g*p)]);c.set(l,h),s[l]=ys}let f=new Uint32Array(r+1),d=[],u=0;for(let l=0;l<r;l++){f[l]=u;let m=c.get(l);if(m){for(let h of m)d.push(h);u+=m.length}}return f[r]=u,{src:e,hashMask:o,buckets:f,entries:d}}function Eu(e,t,n){if(!e||t.byteLength===0)return null;let r=e.src.byteLength,o=t.byteLength,s=e.src,a=new Uint8Array(Math.max(o,1024)),i=0;function c(p){for(;i+p>a.length;){let g=new Uint8Array(a.length*2);g.set(a),a=g}}i=dc(a,i,r),i=dc(a,i,o),c(18),i++;let f=0,d=0,u=Math.min(16,o);for(let p=0;p<u;p++)a[i++]=t[p],f=(f<<8|t[p])^Es[f>>>23],d++;f=f>>>0;let l=u,m=0,h=0;for(;l<o;){if(h<Ro){f^=gu[t[l-16]],f=((f<<8|t[l])^Es[f>>>23])>>>0;let p=f&e.hashMask,g=e.buckets[p],w=e.buckets[p+1];for(let x=g;x<w;x++){let b=e.entries[x];if(b.val!==f)continue;let y=b.ptr,k=s.byteLength-y,C=o-l;if(k>C&&(k=C),k<=h)break;let P=0;for(;P<k&&s[y+P]===t[l+P];)P++;if(P>h&&(h=P,m=y,h>=Ro))break}}if(h<wu)c(2),d===0&&i++,a[i++]=t[l++],d++,d===bu&&(a[i-d-1]=d,d=0),h=0;else{if(d>0){for(;m>0&&s[m-1]===t[l-1];)if(h++,m--,l--,i--,!(--d>0)){i--,d=-1;break}d>0&&(a[i-d-1]=d),d=0}let p=h>cc?h-cc:0;h-=p,c(8);let g=i++,w=128;if(m&255&&(a[i++]=m&255,w|=1),m&65280&&(a[i++]=m>>>8&255,w|=2),m&16711680&&(a[i++]=m>>>16&255,w|=4),m&4278190080&&(a[i++]=m>>>24&255,w|=8),h&255&&(a[i++]=h&255,w|=16),h&65280&&(a[i++]=h>>>8&255,w|=32),a[g]=w,l+=h,m+=h,h=p,m>4294967295&&(h=0),h<Ro){f=0;for(let x=-16;x<0;x++)f=(f<<8|t[l+x])^Es[f>>>23];f=f>>>0}}if(n&&i>n)return null}return d>0&&(a[i-d-1]=d),n&&i>n?null:a.subarray(0,i)}var fc={blob:0,tree:1,commit:2,tag:3};function lc(e,t){let n=t?.window??10,r=t?.depth??50,o=e.slice().sort((f,d)=>{let u=fc[f.type]??99,l=fc[d.type]??99;return u!==l?u-l:d.content.byteLength-f.content.byteLength}),s=new Map,a=[],i=[],c=[];for(let f=0;f<o.length;f++){let d=o[f],u={hash:d.hash,type:d.type,content:d.content,depth:0},l=null,m=null,h=Math.max(0,f-n);for(let p=f-1;p>=h;p--){let g=o[p];if(g.type!==d.type||(s.get(g.hash)?.depth??0)>=r||d.content.byteLength<g.content.byteLength>>>5)continue;let b=i[p-h]??null;if(!b)continue;let y=l?l.byteLength:d.content.byteLength/2|0;if(y<16)continue;let k=Eu(b,d.content,y);k&&(!l||k.byteLength<l.byteLength)&&(l=k,m=g.hash)}if(l&&m){u.delta=l,u.deltaBase=m;let p=s.get(m);u.depth=(p?.depth??0)+1}s.set(d.hash,u),a.push(u),i.length>=n&&(i.shift(),c.shift()),i.push(yu(d.content)),c.push(d.hash)}return a}function xu(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 dc(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}async function ku(e,t){let n=new Set,r=v(e.gitDir,"objects","pack");try{let s=await e.fs.readdir(r);for(let a of s){if(!a.endsWith(".idx"))continue;let i=await e.fs.readFileBuffer(v(r,a)),c=new un(i);for(let f of c.allHashes())n.add(f)}}catch{}return n.size===0?ds(e,t,[]):(await ds(e,t,[])).filter(s=>!n.has(s.hash))}async function Io(e){let{gitCtx:t,fs:n,tips:r,cleanup:o}=e,s=e.window??10,a=e.depth??50;if(r.length===0)return null;let i=e.all?await ds(t,r,[]):await ku(t,r);if(i.length===0)return null;let c=i.length,f=lc(i,{window:s,depth:a}),d=f.filter(C=>C.delta).length,u=f.map(C=>({hash:C.hash,type:C.type,content:C.content,delta:C.delta,deltaBaseHash:C.deltaBase})),{data:l,entries:m}=await mi(u),h=await bi(l,m),p=l.subarray(l.byteLength-20),g="";for(let C=0;C<20;C++){let P=p[C];g+=(P>>4).toString(16)+(P&15).toString(16)}let w=v(t.gitDir,"objects","pack");await n.mkdir(w,{recursive:!0});let x=`pack-${g}`,b=v(w,`${x}.pack`),y=v(w,`${x}.idx`);await n.writeFile(b,l),await n.writeFile(y,h);let k=new Set(f.map(C=>C.hash));if(o){let C=await n.readdir(w);for(let E of C){if(!E.endsWith(".idx"))continue;let I=E.slice(0,-4);if(I===x)continue;let H=v(w,`${I}.idx`),_=!0;try{let G=await n.readFileBuffer(H),z=new un(G);for(let D of z.allHashes())if(!k.has(D)){_=!1;break}}catch{_=!1}if(_){try{await n.rm(v(w,`${I}.pack`))}catch{}try{await n.rm(H)}catch{}}}let P=v(t.gitDir,"objects"),O;try{O=await n.readdir(P)}catch{O=[]}for(let E of O){if(E==="pack"||E==="info"||E.length!==2)continue;let I=v(P,E),H;try{H=await n.readdir(I)}catch{continue}for(let _ of H){let G=`${E}${_}`;k.has(G)&&await n.rm(v(I,_))}try{(await n.readdir(I)).length===0&&await n.rm(I,{recursive:!0})}catch{}}}return{totalCount:c,deltaCount:d,packHash:g}}function $o(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(`
|
|
334
|
-
`)}function
|
|
337
|
+
`:""}async function Ro(e,t){if(!t.newHash)return"";if(t.newFromWorkTree&&e.workTree){let n=H(e.workTree,t.path),r=await Qn(e.fs,n);return Oo.decode(r)}return fe(e,t.newHash)}async function pu(e,t){if(!t.newHash)return new Uint8Array(0);if(t.newFromWorkTree&&e.workTree){let n=H(e.workTree,t.path);return Qn(e.fs,n)}return ot(e,t.newHash)}function sc(e,t){let n=rn(e),r=rn(t),o=xt(n,r),s=0,a=0;for(let i of o)i.type==="insert"?s++:i.type==="delete"&&a++;return{ins:s,del:a}}async function oc(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?Mn(r.oldPath,r.path):r.path,s=r.oldHash?await ot(e,r.oldHash):new Uint8Array(0),a=await pu(e,r);if(Vt(s)||Vt(a))n.push({path:o,sortKey:r.path,insertions:0,deletions:0,isBinary:!0,oldSize:s.byteLength,newSize:a.byteLength});else{let i=Oo.decode(s),c=Oo.decode(a),{ins:f,del:d}=sc(i,c);n.push({path:o,sortKey:r.path,insertions:f,deletions:d})}}return n}function Cn(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 gu(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 bs(e,t){if(!gu(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),a=s.length>0?t.length-s.length:t.length,i=t.slice(o.length,a);return r===-1?e.dst:e.dst.slice(0,r)+i+e.dst.slice(r+1)}function ic(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:v().describe("Fetch from all remotes"),prune:v().alias("p").describe("Remove stale remote-tracking refs"),tags:v().describe("Also fetch tags")},handler:async(n,r)=>{let o=await B(r.fs,r.cwd,t);if(S(o))return o;let s=o,a=n.remote||"origin",i;try{i=await _n(s,a,r.env)}catch(E){let I=E instanceof Error?E.message:"";if(I.startsWith("network"))return T(I);throw E}if(!i)return T(`'${a}' does not appear to be a git repository`);let{transport:c,config:f}=i,d=n.refspec,u;if(d&&d.length>0?u=d.map(Cn):u=[Cn(f.fetchRefspec)],t?.hooks){let E=await t.hooks.emitPre("pre-fetch",{remote:a,url:f.url,refspecs:u.map(I=>`${I.src}:${I.dst}`),prune:n.prune,tags:n.tags});if(E)return{stdout:"",stderr:E.message??"",exitCode:1}}let l=await c.advertiseRefs();if(l.length===0)return{stdout:"",stderr:"",exitCode:0};let h=(await le(s)).map(E=>E.hash),p=await F(s,"HEAD");p&&h.push(p);let g=[],w=new Set,x=[];for(let E of l)if(E.name!=="HEAD")for(let I of u){let A=bs(I,E.name);if(A!==null){x.push({remote:E,localRef:A,force:I.force}),w.has(E.hash)||(w.add(E.hash),g.push(E.hash));break}}if(n.tags)for(let E of l)E.name.startsWith("refs/tags/")&&(x.push({remote:E,localRef:E.name,force:!1}),w.has(E.hash)||(w.add(E.hash),g.push(E.hash)));let b=new Set(h),y=g.filter(E=>!b.has(E));y.length>0&&await c.fetch(y,h);let k=await Ot(s,r.env),C=[];C.push(`From ${f.url}
|
|
338
|
+
`);for(let E of x){let I=await F(s,E.localRef);await Y(s,E.localRef,E.remote.hash),await Te(s,E.localRef,{oldHash:I??Z,newHash:E.remote.hash,name:k.name,email:k.email,timestamp:k.timestamp,tz:k.tz,message:I?"fetch":"fetch: storing head"});let A=ys(E.remote.name),_=ys(E.localRef);if(I){if(I!==E.remote.hash){let G=K(I),z=K(E.remote.hash);C.push(` ${G}..${z} ${A} -> ${_}
|
|
339
|
+
`)}}else{let z=E.remote.name.startsWith("refs/tags/")?" * [new tag]":" * [new branch]";C.push(`${z} ${A} -> ${_}
|
|
340
|
+
`)}}if(!n.tags)for(let E of l){if(!E.name.startsWith("refs/tags/")||w.has(E.hash))continue;let I=await F(s,E.name),A=E.peeledHash??E.hash;!I&&b.has(A)&&(await Y(s,E.name,E.hash),await Te(s,E.name,{oldHash:Z,newHash:E.hash,name:k.name,email:k.email,timestamp:k.timestamp,tz:k.tz,message:"fetch: storing head"}),C.push(` * [new tag] ${ys(E.name)} -> ${ys(E.name)}
|
|
341
|
+
`))}if(n.prune){let E=`refs/remotes/${a}`,I=await le(s,E),A=new Set(l.filter(_=>_.name.startsWith("refs/heads/")).map(_=>_.name.slice(11)));for(let _ of I){let G=_.name.slice(E.length+1);A.has(G)||(await ie(s,_.name),C.push(` - [deleted] (none) -> ${a}/${G}
|
|
342
|
+
`))}}let P=l.find(E=>E.name==="HEAD");if(P){let E=H(s.gitDir,"FETCH_HEAD"),I=l.find(_=>_.name.startsWith("refs/heads/")&&_.hash===P.hash),A=I?`branch '${I.name.slice(11)}' of`:"of";await r.fs.writeFile(E,`${P.hash} ${A} ${f.url}
|
|
343
|
+
`)}let O={stdout:"",stderr:C.join(""),exitCode:0};return await t?.hooks?.emitPost("post-fetch",{remote:a,url:f.url,refsUpdated:x.length}),O}})}function ys(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 ac(e){let t=new Set,n=await X(e);n&&t.add(n);let r=await le(e,"refs");for(let i of r)t.add(i.hash);let o=H(e.gitDir,"logs");await e.fs.exists(o)&&await cc(e,o,o,t);let s=await U(e);for(let i of s.entries)t.add(i.hash);for(let i of["MERGE_HEAD","CHERRY_PICK_HEAD","ORIG_HEAD"]){let c=await F(e,i);c&&t.add(c)}let a=[];for(let i of t)await zt(e,i)&&a.push(i);return a}async function cc(e,t,n,r){let o=await e.fs.readdir(t);for(let s of o){let a=H(t,s),i=await e.fs.stat(a);if(i.isDirectory)await cc(e,a,n,r);else if(i.isFile){let c=a.slice(n.length+1),f=await Me(e,c);for(let d of f)d.newHash!==Z&&r.add(d.newHash)}}}var xs=new Uint32Array([0,2874782929,1454598562,4260027763,104818581,2909197124,1351355959,4225088230,209637162,2804382715,1523426952,4053013081,172075199,2702711918,1559413021,4155209164,419274324,3013880453,1313798134,3843506983,516094401,3046853904,1215402083,3811058866,344150398,3218793903,1110456540,3916008461,314324715,3118826042,1141858121,4015451032,838548648,2594343033,1732793610,3423723995,935615293,2627596268,1635201695,3392046670,1032188802,2531018579,1798740512,3228511985,1002083351,2430804166,1829371317,3327150436,688300796,2187269677,2142620510,3572268943,792315241,2220913080,2039131339,3537049626,628649430,2384582919,1942684788,3633492133,591858243,2283716242,1978950625,3735934768,1677097296,3366964609,893718770,2652677155,1707679429,3465587220,863663975,2552480694,1871230586,3302032043,960225240,2455923465,1773654511,3270403390,1057273933,2489126044,2064377604,3495056341,767069862,2262907511,2100592785,3597481024,730327347,2162056674,2004166702,3693911295,566641036,2325738845,1900695483,3658742634,670639641,2359333576,1376601592,4183093545,79572058,2951190667,1412571757,4285241020,42027983,2849570590,1584630482,4113186307,146858864,2744735649,1481436487,4078262678,251626725,2779131956,1257298860,3785977725,474198542,3071936223,1288682553,3885369576,444388763,2972016970,1183716486,3990331479,272465188,3143944693,1085371155,3957901250,369236657,3176902240,1823819377,3354194592,973483987,2438961922,1787437540,3251868981,1010387014,2539715735,1623951707,3415358858,913891577,2636207144,1727327950,3450690079,809994092,2602447805,1950930981,3742461172,586920327,2309096790,1920450480,3643673441,616879634,2409456323,2016810767,3547309022,780500653,2245839484,2114547866,3578840139,683284792,2212736489,1565424345,4128755208,201134971,2695145386,1534139724,4029196701,230847726,2795225151,1362146803,4201185570,126082129,2899994752,1460654694,4233520823,29146052,2867138325,1169417357,4008333404,318803247,3092855294,1133282072,3906287561,356510394,3194379883,1238182823,3801390966,528368133,3022517972,1341279282,3836475619,423699856,2987954497,256065313,2753203184,1508923011,4071219794,159144116,2720394341,1607414038,4103505351,54390795,2825143514,1435408809,4275514744,84055966,2925208399,1404173884,4175973101,398369141,3169260964,1091422423,3931405318,293717728,3134747185,1194504002,3966442387,465595999,2962872974,1299384317,3861558060,503253450,3064380699,1263296616,3759527097,1052246921,2514597720,1745578539,3276988154,948397084,2480853197,1848905150,3312302447,851889315,2577365106,1685431553,3475771856,888777526,2678071271,1649066644,3373495877,642096605,2367432972,1895232639,3685695662,544930376,2334346905,1992922090,3717211963,708530935,2170742310,2089302869,3620835204,738473314,2271052211,2058837184,3522095121]),wu=new Uint32Array([0,2125799437,1446245579,679924934,121527623,2039184714,1359849868,800622977,243055246,1892260483,1481592389,653946440,155379657,2012727236,1601245954,566506255,486110492,1649169681,1254785495,880779738,466036827,1701972054,1307892880,859962525,310759314,1815146399,1152793433,973282132,364614357,1796125400,1133012510,1027425811,972220984,1195887157,1874927347,292830974,1053603711,1081710450,1761559476,373973945,932073654,1228632251,1639818365,520651888,816844273,1308962300,1719925050,406247735,621518628,1539227433,1933077487,227363810,573948515,1551950446,1946564264,179508901,729228714,1438778791,2101662049,66187628,743012589,1392269536,2054851622,80718891,1944441968,223409277,634790075,1533214902,1960544567,175024442,585661948,1549622769,2107207422,53235443,732600885,1428142648,2057778105,68293556,747947890,1377953663,1864147308,296321377,959403431,1201305002,1747123243,379051046,1041303776,1084500205,1633688546,534068207,928247593,1239863076,1717454501,418080424,812495470,1322816099,1243037256,883039813,472173187,1653729934,1294557967,865878786,454727620,1706014665,1147897030,987669707,307785741,1827491840,1129699713,1038154124,359017802,1808993607,1458457428,677079897,14532511,2120785810,1372591635,795162142,132375256,2035729109,1486025178,640143831,245433617,1880368412,1605151901,555322512,161437782,1999272027,1284643889,841432124,446818554,1679083767,1269580150,890855803,497006013,1663735216,1122936511,1012631218,350048884,1785229945,1171323896,996531189,333647667,1834364734,1349216557,786319648,106470886,2028846571,1465201770,702551143,23511201,2144592044,1578619811,547550126,136587112,1989216101,1495895780,664579817,253393455,1907317282,1969288713,198563332,592642754,1575363279,1918806862,216763203,611147653,1524137864,2065452167,94989450,758102092,1402640449,2082607552,43463117,705815819,1420084486,1771668245,388801304,1068136414,1092573139,1856495186,269680223,949234329,1176570516,1743075739,424679830,836160848,1331948893,1624990940,510543057,921210903,1214099482,1064814657,1103292492,1766079626,401677447,944346374,1190966539,1853514189,282018240,822833871,1337873090,1731757572,428713481,909455240,1216352133,1611062083,515111758,596557149,1564187984,1975339414,185100699,615571482,1510326295,1921193169,204879068,770836435,1397172190,2076308248,91542293,718035604,1417247385,2097131103,38440530,109388409,2016412276,1354159794,772011711,29065022,2131648307,1468566517,691907576,150575351,1984739578,1590324284,545213489,264750512,1903355325,1509175675,658575734,444356453,1690924904,1280287662,855278499,490867234,1677142575,1265762025,902094564,335605227,1790299622,1110645024,1015429421,322875564,1837863073,1158497383,1001940074]),Es=64,bu=4,Io=4096,fc=65536,yu=127;function Eu(e){let t=e.byteLength;if(t===0)return null;let n=(t-1)/16|0;if(n===0)return null;let r=n>>>2;r<16&&(r=16),r=ku(r);let o=r-1,s=new Uint32Array(r),a=[],i=-1>>>0;for(let l=n*16-16;l>=0;l-=16){let m=0;for(let h=1;h<=16;h++)m=(m<<8|e[l+h])^xs[m>>>23];if(m=m>>>0,m===i)a[a.length-1].ptr=l+16;else{i=m;let h=m&o;a.push({ptr:l+16,val:m}),s[h]++}}let c=new Map;for(let l of a){let m=l.val&o,h=c.get(m);h||(h=[],c.set(m,h)),h.push(l)}for(let[l,m]of c){if(m.length<=Es)continue;let h=[],p=m.length/Es;for(let g=0;g<Es;g++)h.push(m[Math.floor(g*p)]);c.set(l,h),s[l]=Es}let f=new Uint32Array(r+1),d=[],u=0;for(let l=0;l<r;l++){f[l]=u;let m=c.get(l);if(m){for(let h of m)d.push(h);u+=m.length}}return f[r]=u,{src:e,hashMask:o,buckets:f,entries:d}}function xu(e,t,n){if(!e||t.byteLength===0)return null;let r=e.src.byteLength,o=t.byteLength,s=e.src,a=new Uint8Array(Math.max(o,1024)),i=0;function c(p){for(;i+p>a.length;){let g=new Uint8Array(a.length*2);g.set(a),a=g}}i=lc(a,i,r),i=lc(a,i,o),c(18),i++;let f=0,d=0,u=Math.min(16,o);for(let p=0;p<u;p++)a[i++]=t[p],f=(f<<8|t[p])^xs[f>>>23],d++;f=f>>>0;let l=u,m=0,h=0;for(;l<o;){if(h<Io){f^=wu[t[l-16]],f=((f<<8|t[l])^xs[f>>>23])>>>0;let p=f&e.hashMask,g=e.buckets[p],w=e.buckets[p+1];for(let x=g;x<w;x++){let b=e.entries[x];if(b.val!==f)continue;let y=b.ptr,k=s.byteLength-y,C=o-l;if(k>C&&(k=C),k<=h)break;let P=0;for(;P<k&&s[y+P]===t[l+P];)P++;if(P>h&&(h=P,m=y,h>=Io))break}}if(h<bu)c(2),d===0&&i++,a[i++]=t[l++],d++,d===yu&&(a[i-d-1]=d,d=0),h=0;else{if(d>0){for(;m>0&&s[m-1]===t[l-1];)if(h++,m--,l--,i--,!(--d>0)){i--,d=-1;break}d>0&&(a[i-d-1]=d),d=0}let p=h>fc?h-fc:0;h-=p,c(8);let g=i++,w=128;if(m&255&&(a[i++]=m&255,w|=1),m&65280&&(a[i++]=m>>>8&255,w|=2),m&16711680&&(a[i++]=m>>>16&255,w|=4),m&4278190080&&(a[i++]=m>>>24&255,w|=8),h&255&&(a[i++]=h&255,w|=16),h&65280&&(a[i++]=h>>>8&255,w|=32),a[g]=w,l+=h,m+=h,h=p,m>4294967295&&(h=0),h<Io){f=0;for(let x=-16;x<0;x++)f=(f<<8|t[l+x])^xs[f>>>23];f=f>>>0}}if(n&&i>n)return null}return d>0&&(a[i-d-1]=d),n&&i>n?null:a.subarray(0,i)}var dc={blob:0,tree:1,commit:2,tag:3};function uc(e,t){let n=t?.window??10,r=t?.depth??50,o=e.slice().sort((f,d)=>{let u=dc[f.type]??99,l=dc[d.type]??99;return u!==l?u-l:d.content.byteLength-f.content.byteLength}),s=new Map,a=[],i=[],c=[];for(let f=0;f<o.length;f++){let d=o[f],u={hash:d.hash,type:d.type,content:d.content,depth:0},l=null,m=null,h=Math.max(0,f-n);for(let p=f-1;p>=h;p--){let g=o[p];if(g.type!==d.type||(s.get(g.hash)?.depth??0)>=r||d.content.byteLength<g.content.byteLength>>>5)continue;let b=i[p-h]??null;if(!b)continue;let y=l?l.byteLength:d.content.byteLength/2|0;if(y<16)continue;let k=xu(b,d.content,y);k&&(!l||k.byteLength<l.byteLength)&&(l=k,m=g.hash)}if(l&&m){u.delta=l,u.deltaBase=m;let p=s.get(m);u.depth=(p?.depth??0)+1}s.set(d.hash,u),a.push(u),i.length>=n&&(i.shift(),c.shift()),i.push(Eu(d.content)),c.push(d.hash)}return a}function ku(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 lc(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}async function Cu(e,t){let n=new Set,r=H(e.gitDir,"objects","pack");try{let s=await e.fs.readdir(r);for(let a of s){if(!a.endsWith(".idx"))continue;let i=await e.fs.readFileBuffer(H(r,a)),c=new un(i);for(let f of c.allHashes())n.add(f)}}catch{}return n.size===0?ls(e,t,[]):(await ls(e,t,[])).filter(s=>!n.has(s.hash))}async function $o(e){let{gitCtx:t,fs:n,tips:r,cleanup:o}=e,s=e.window??10,a=e.depth??50;if(r.length===0)return null;let i=e.all?await ls(t,r,[]):await Cu(t,r);if(i.length===0)return null;let c=i.length,f=uc(i,{window:s,depth:a}),d=f.filter(C=>C.delta).length,u=f.map(C=>({hash:C.hash,type:C.type,content:C.content,delta:C.delta,deltaBaseHash:C.deltaBase})),{data:l,entries:m}=await hi(u),h=await yi(l,m),p=l.subarray(l.byteLength-20),g="";for(let C=0;C<20;C++){let P=p[C];g+=(P>>4).toString(16)+(P&15).toString(16)}let w=H(t.gitDir,"objects","pack");await n.mkdir(w,{recursive:!0});let x=`pack-${g}`,b=H(w,`${x}.pack`),y=H(w,`${x}.idx`);await n.writeFile(b,l),await n.writeFile(y,h);let k=new Set(f.map(C=>C.hash));if(o){let C=await n.readdir(w);for(let E of C){if(!E.endsWith(".idx"))continue;let I=E.slice(0,-4);if(I===x)continue;let A=H(w,`${I}.idx`),_=!0;try{let G=await n.readFileBuffer(A),z=new un(G);for(let D of z.allHashes())if(!k.has(D)){_=!1;break}}catch{_=!1}if(_){try{await n.rm(H(w,`${I}.pack`))}catch{}try{await n.rm(A)}catch{}}}let P=H(t.gitDir,"objects"),O;try{O=await n.readdir(P)}catch{O=[]}for(let E of O){if(E==="pack"||E==="info"||E.length!==2)continue;let I=H(P,E),A;try{A=await n.readdir(I)}catch{continue}for(let _ of A){let G=`${E}${_}`;k.has(G)&&await n.rm(H(I,_))}try{(await n.readdir(I)).length===0&&await n.rm(I,{recursive:!0})}catch{}}}return{totalCount:c,deltaCount:d,packHash:g}}function To(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(`
|
|
344
|
+
`)}function mc(e,t){e.command("repack",{description:"Pack unpacked objects in a repository",options:{all:v().alias("a").describe("Pack all objects, including already-packed"),delete:v().alias("d").describe("After packing, remove redundant packs and loose objects")},handler:async(n,r)=>{let o=await B(r.fs,r.cwd,t);if(S(o))return o;let s=o,a=await ac(s),i=await $o({gitCtx:s,fs:r.fs,tips:a,cleanup:n.delete,all:n.all});return i?{stdout:"",stderr:`${To(i.totalCount,i.deltaCount)}
|
|
335
345
|
`,exitCode:0}:{stdout:`Nothing new to pack.
|
|
336
|
-
`,stderr:"",exitCode:0}}})}function
|
|
337
|
-
`,exitCode:0}}return{stdout:"",stderr:"",exitCode:0}}})}var
|
|
338
|
-
|
|
339
|
-
`,s+=2;continue;case"
|
|
346
|
+
`,stderr:"",exitCode:0}}})}function hc(e,t){e.command("gc",{description:"Cleanup unnecessary files and optimize the local repository",options:{aggressive:v().describe("More aggressively optimize the repository")},handler:async(n,r)=>{let o=await B(r.fs,r.cwd,t);if(S(o))return o;let s=o;await Ci(s),await tt(s);let a=await Ou(s);if(a.length>0){let i=n.aggressive?250:10,c=n.aggressive?250:50,f=await $o({gitCtx:s,fs:r.fs,tips:a,window:i,depth:c,cleanup:!0,all:!0});if(await Ru(s.gitDir,r.fs),f)return{stdout:"",stderr:`${To(f.totalCount,f.deltaCount,!0)}
|
|
347
|
+
`,exitCode:0}}return{stdout:"",stderr:"",exitCode:0}}})}var Pu=2160*60*60;async function Ou(e){let t=new Set,n=await X(e);n&&t.add(n);let r=await le(e,"refs");for(let f of r)t.add(f.hash);let s=Math.floor(Date.now()/1e3)-Pu,a=H(e.gitDir,"logs");await e.fs.exists(a)&&await pc(e,a,a,s,t);let i=await U(e);for(let f of i.entries)t.add(f.hash);for(let f of["MERGE_HEAD","CHERRY_PICK_HEAD","ORIG_HEAD"]){let d=await F(e,f);d&&t.add(d)}let c=[];for(let f of t)await zt(e,f)&&c.push(f);return c}async function pc(e,t,n,r,o){let s=await e.fs.readdir(t);for(let a of s){let i=H(t,a),c=await e.fs.stat(i);if(c.isDirectory){await pc(e,i,n,r,o);try{(await e.fs.readdir(i)).length===0&&await e.fs.rm(i,{recursive:!0})}catch{}}else if(c.isFile){let f=i.slice(n.length+1),d=await Me(e,f);if(f==="refs/stash"){for(let l of d)l.newHash!==Z&&o.add(l.newHash);continue}let u=d.filter(l=>l.timestamp>=r);await Xt(e,f,u);for(let l of u)l.newHash!==Z&&o.add(l.newHash)}}}async function Ru(e,t){let n=H(e,"objects"),r;try{r=await t.readdir(n)}catch{return}for(let o of r)if(!(o==="pack"||o==="info"||o.length!==2))try{await t.rm(H(n,o),{recursive:!0})}catch{}}function gc(e){e.command("init",{description:"Initialize a new repository",args:[W.string().name("directory").describe("The directory to initialize").optional()],options:{bare:v().describe("Create a bare repository"),initialBranch:te.string().alias("b").describe("Name for the initial branch")},examples:["git init","git init --bare","git init my-project"],handler:async(t,n)=>{let r=t.initialBranch,o=t.directory?ct(n.cwd,t.directory):n.cwd;t.directory&&await n.fs.mkdir(o,{recursive:!0});let{ctx:s,reinit:a}=await vr(n.fs,o,{bare:t.bare,...r?{initialBranch:r}:{}}),i="";a&&r&&(i=`warning: re-init: ignored --initial-branch=${r}
|
|
348
|
+
`);let c=t.bare?"bare ":"";return{stdout:`${a?"Reinitialized existing":"Initialized empty"} ${c}Git repository in ${s.gitDir}/
|
|
349
|
+
`,stderr:i,exitCode:0}}})}function wc(e,t){let{hash:n,commit:r}=t,o="",s=0;for(;s<e.length;){if(e[s]==="%"){let a=e[s+1];if(a===void 0){o+="%",s++;continue}if((a==="a"||a==="c")&&s+2<e.length){let i=e[s+2],c=a==="a"?r.author:r.committer;switch(i){case"n":o+=c.name,s+=3;continue;case"e":case"E":o+=c.email,s+=3;continue;case"t":o+=c.timestamp.toString(),s+=3;continue;case"I":o+=Su(c.timestamp,c.timezone),s+=3;continue;case"i":o+=Du(c.timestamp,c.timezone),s+=3;continue;case"d":o+=vt(c.timestamp,c.timezone),s+=3;continue;case"D":o+=Mu(c.timestamp,c.timezone),s+=3;continue}}switch(a){case"H":o+=n,s+=2;continue;case"h":o+=K(n),s+=2;continue;case"T":o+=r.tree,s+=2;continue;case"t":o+=K(r.tree),s+=2;continue;case"P":o+=r.parents.join(" "),s+=2;continue;case"p":o+=r.parents.map(K).join(" "),s+=2;continue;case"s":o+=Ho(r.message),s+=2;continue;case"b":o+=Iu(r.message),s+=2;continue;case"B":o+=r.message.replace(/\n$/,""),s+=2;continue;case"d":if(t.decorations){let i=t.decorations(n);o+=i?` ${i}`:""}s+=2;continue;case"D":t.decorationsRaw&&(o+=t.decorationsRaw(n)),s+=2;continue;case"n":o+=`
|
|
350
|
+
`,s+=2;continue;case"%":o+="%",s+=2;continue;default:o+=`%${a}`,s+=2;continue}}o+=e[s],s++}return o}var Ho=ue;function Iu(e){let t=e.indexOf(`
|
|
340
351
|
|
|
341
|
-
`);return t===-1?"":e.slice(t+2).replace(/\n$/,"")}function
|
|
352
|
+
`);return t===-1?"":e.slice(t+2).replace(/\n$/,"")}function bc(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"].includes(e)?{formatStr:null,preset:e}:{formatStr:e,preset:null}}function yc(e,t,n,r=!1){let{hash:o,commit:s}=t,a=t.decorations?t.decorations(o):"";switch(e){case"oneline":{let i=r?K(o):o,c=Ho(s.message);return a?`${i} ${a} ${c}`:`${i} ${c}`}case"short":{let i=[];return n||i.push(""),i.push(a?`commit ${o} ${a}`:`commit ${o}`),s.parents.length>=2&&i.push(`Merge: ${s.parents.map(K).join(" ")}`),i.push(`Author: ${s.author.name} <${s.author.email}>`),i.push(""),i.push(` ${Ho(s.message)}`),i.join(`
|
|
342
353
|
`)}case"full":{let i=[];n||i.push(""),i.push(a?`commit ${o} ${a}`:`commit ${o}`),s.parents.length>=2&&i.push(`Merge: ${s.parents.map(K).join(" ")}`),i.push(`Author: ${s.author.name} <${s.author.email}>`),i.push(`Commit: ${s.committer.name} <${s.committer.email}>`),i.push("");let c=s.message.replace(/\n$/,"");for(let f of c.split(`
|
|
343
354
|
`))i.push(` ${f}`);return i.join(`
|
|
344
355
|
`)}case"fuller":{let i=[];n||i.push(""),i.push(a?`commit ${o} ${a}`:`commit ${o}`),s.parents.length>=2&&i.push(`Merge: ${s.parents.map(K).join(" ")}`),i.push(`Author: ${s.author.name} <${s.author.email}>`),i.push(`AuthorDate: ${vt(s.author.timestamp,s.author.timezone)}`),i.push(`Commit: ${s.committer.name} <${s.committer.email}>`),i.push(`CommitDate: ${vt(s.committer.timestamp,s.committer.timezone)}`),i.push("");let c=s.message.replace(/\n$/,"");for(let f of c.split(`
|
|
345
356
|
`))i.push(` ${f}`);return i.join(`
|
|
346
|
-
`)}default:return
|
|
357
|
+
`)}default:return $u(t,n)}}function $u(e,t){let{hash:n,commit:r}=e,o=e.decorations?e.decorations(n):"",s=[];t||s.push(""),s.push(o?`commit ${n} ${o}`:`commit ${n}`),r.parents.length>=2&&s.push(`Merge: ${r.parents.map(K).join(" ")}`),s.push(`Author: ${r.author.name} <${r.author.email}>`),s.push(`Date: ${vt(r.author.timestamp,r.author.timezone)}`),s.push("");let a=r.message.replace(/\n$/,"");for(let i of a.split(`
|
|
347
358
|
`))s.push(` ${i}`);return s.join(`
|
|
348
|
-
`)}var
|
|
359
|
+
`)}var Tu=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],Hu=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function Au(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 Ao(e,t){let n=Au(t);return new Date((e+n*60)*1e3)}function vu(e){return`${e.slice(0,3)}:${e.slice(3)}`}function Su(e,t){let n=Ao(e,t),r=n.getUTCFullYear(),o=String(n.getUTCMonth()+1).padStart(2,"0"),s=String(n.getUTCDate()).padStart(2,"0"),a=String(n.getUTCHours()).padStart(2,"0"),i=String(n.getUTCMinutes()).padStart(2,"0"),c=String(n.getUTCSeconds()).padStart(2,"0");return`${r}-${o}-${s}T${a}:${i}:${c}${vu(t)}`}function Du(e,t){let n=Ao(e,t),r=n.getUTCFullYear(),o=String(n.getUTCMonth()+1).padStart(2,"0"),s=String(n.getUTCDate()).padStart(2,"0"),a=String(n.getUTCHours()).padStart(2,"0"),i=String(n.getUTCMinutes()).padStart(2,"0"),c=String(n.getUTCSeconds()).padStart(2,"0");return`${r}-${o}-${s} ${a}:${i}:${c} ${t}`}function Mu(e,t){let n=Ao(e,t),r=Tu[n.getUTCDay()]?.slice(0,3),o=Hu[n.getUTCMonth()],s=n.getUTCDate(),a=String(n.getUTCHours()).padStart(2,"0"),i=String(n.getUTCMinutes()).padStart(2,"0"),c=String(n.getUTCSeconds()).padStart(2,"0"),f=n.getUTCFullYear();return`${r}, ${s} ${o} ${f} ${a}:${i}:${c} ${t}`}function kc(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:te.number().alias("n").describe("Limit the number of commits to output"),oneline:v().describe("Condense each commit to a single line"),all:v().describe("Walk all refs, not just HEAD"),author:te.string().describe("Filter by author (regex or substring)"),grep:te.string().describe("Filter by commit message (regex or substring)"),since:te.string().describe("Show commits after date"),after:te.string().describe("Synonym for --since"),until:te.string().describe("Show commits before date"),before:te.string().describe("Synonym for --until"),decorate:v().describe("Show ref names next to commit hashes"),reverse:v().describe("Output commits in reverse order"),format:te.string().describe("Pretty-print format string"),pretty:te.string().describe("Pretty-print format or preset name")},handler:async(n,r,o)=>{let s=await B(r.fs,r.cwd,t);if(S(s))return s;let a=s,i,c,f=n.revisions,d=f&&f.length===1?gs(f[0]):null;if(d){let R=async oe=>{let Q=await je(a,oe);if(!Q)return Et(oe);try{return await Re(a,Q)}catch{return Et(oe)}},N=await R(d.left);if(typeof N=="object"&&"exitCode"in N)return N;let q=await R(d.right);if(typeof q=="object"&&"exitCode"in q)return q;let L=N,V=q;if(d.type==="two-dot")i=[V],c=[L];else{i=[L,V];let oe=await ht(a,L,V);c=oe.length>0?oe:void 0}if(n.all){let oe=await le(a);for(let ge of oe)try{let De=await Re(a,ge.hash);i.includes(De)||i.push(De)}catch{}let Q=await X(a);Q&&!i.includes(Q)&&i.push(Q)}}else if(n.all){let R=await le(a),N=new Set;for(let L of R)try{N.add(await Re(a,L.hash))}catch{}let q=await X(a);q&&N.add(q),i=[...N]}else if(f&&f.length>0){let R=[];for(let N of f){let q=await je(a,N);if(!q)return Et(N);try{R.push(await Re(a,q))}catch{return Et(N)}}i=R}else{let R=await Se(a);if(S(R))return R;i=[R]}if(i.length===0)return T("your current branch does not have any commits yet");let u=o.passthrough.length>0?o.passthrough.map(R=>Oe(R,"")):null,l=n.author?Ec(n.author):null,m=n.grep?Ec(n.grep):null,h=n.since??n.after,p=n.until??n.before,g=h?oo(h):null,w=p?oo(p):null,x=n.format??n.pretty,b=null,y=null,k=!1;if(n.oneline)y="oneline",k=!0;else if(x!==void 0){let R=bc(x);b=R.formatStr,y=R.preset}let P=n.decorate||b!=null&&(b.includes("%d")||b.includes("%D"))?await Gu(a):null,O=P?R=>xc(P,R):void 0,E=P?R=>{let N=xc(P,R);return N.startsWith("(")&&N.endsWith(")")?N.slice(1,-1):N}:void 0,I=n.maxCount,A=n.reverse,_=u?Lu(a,i,u,c?await ju(a,c):void 0):bn(a,i,{exclude:c}),G=[];for await(let R of _){if(I!==void 0&&G.length>=I)break;let{commit:N}=R;if(!(w!==null&&N.committer.timestamp>w)&&!(g!==null&&N.committer.timestamp<=g)){if(l){let q=`${N.author.name} <${N.author.email}>`;if(!l(q))continue}m&&!m(N.message)||G.push(R)}}let z=A?G.reverse():G;if(b!==null){let R=[];for(let N of z){let q={hash:N.hash,commit:N.commit,decorations:O,decorationsRaw:E};R.push(wc(b,q))}return{stdout:R.length>0?`${R.join(`
|
|
349
360
|
`)}
|
|
350
|
-
`:"",stderr:"",exitCode:0}}let D=y??"medium",$=[];for(let R=0;R<z.length;R++){let N=z[R],q={hash:N.hash,commit:N.commit,decorations:O,decorationsRaw:E};$.push(
|
|
361
|
+
`:"",stderr:"",exitCode:0}}let D=y??"medium",$=[];for(let R=0;R<z.length;R++){let N=z[R],q={hash:N.hash,commit:N.commit,decorations:O,decorationsRaw:E};$.push(yc(D,q,R===0,k))}return{stdout:$.length>0?`${$.join(`
|
|
351
362
|
`)}
|
|
352
|
-
`:"",stderr:"",exitCode:0}}})}async function
|
|
353
|
-
`,k=o.passthrough.length>0?o.passthrough.map(O=>{let E=r.cwd!==c?
|
|
363
|
+
`:"",stderr:"",exitCode:0}}})}async function ju(e,t){let n=new Set;for await(let r of bn(e,t))n.add(r.hash);return n}function Ec(e){try{let t=new RegExp(e);return n=>t.test(n)}catch{return t=>t.includes(e)}}async function*Lu(e,t,n,r){let o=new Set(r),s=new Ln,a=async i=>{if(!o.has(i)){let c=await M(e,i);s.push({hash:i,commit:c})}};for(let i of t)await a(i);for(;s.size>0;){let i=s.pop();if(o.has(i.hash))continue;o.add(i.hash);let{commit:c}=i,f=c.parents;if(f.length===0){(await Ae(e,null,c.tree)).some(l=>me(n,l.path))&&(yield i);continue}if(f.length===1){let u=f[0];if(u){let l=await M(e,u);(await Ae(e,l.tree,c.tree)).some(h=>me(n,h.path))&&(yield i),await a(u)}continue}let d=[];for(let u of f){let l=await M(e,u);(await Ae(e,l.tree,c.tree)).some(h=>me(n,h.path))||d.push(u)}if(d.length>0&&d[0])await a(d[0]);else{yield i;for(let u of f)await a(u)}}}async function Gu(e){let t=await J(e),n=t?.type==="symbolic"?de(t.target):null,r=await X(e),o=new Map,s=(f,d,u)=>{let l=o.get(f);l||(l=[],o.set(f,l)),l.push({label:d,fullRef:u})},a=await le(e,"refs/heads");for(let f of a)s(f.hash,de(f.name),f.name);let i=await le(e,"refs/remotes");for(let f of i)s(f.hash,f.name.replace("refs/remotes/",""),f.name);let c=await le(e,"refs/tags");for(let f of c){let d=f.hash;try{d=await Re(e,f.hash)}catch{}s(d,`tag: ${f.name.replace("refs/tags/","")}`,f.name)}return{headTarget:n,headHash:r,byHash:o}}function xc(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(i=>i.label===e.headTarget):null;s?o.push(`HEAD -> ${s.label}`):r&&o.push("HEAD");let a=n?n.filter(i=>i!==s):[];a.sort((i,c)=>i.fullRef>c.fullRef?-1:i.fullRef<c.fullRef?1:0);for(let i of a)o.push(i.label);return o.length>0?`(${o.join(", ")})`:""}function Pc(e,t){e.command("ls-files",{description:"Show information about files in the index and the working tree",options:{cached:v().alias("c").describe("Show cached files (default)"),modified:v().alias("m").describe("Show modified files"),deleted:v().alias("d").describe("Show deleted files"),others:v().alias("o").describe("Show other (untracked) files"),unmerged:v().alias("u").describe("Show unmerged files"),stage:v().alias("s").describe("Show staged contents' mode, hash, and stage number"),"exclude-standard":v().describe("Add standard git exclusions (.gitignore, info/exclude, core.excludesFile)"),"nul-terminate":v().alias("z").describe("Use \\0 as line terminator instead of \\n"),"show-tags":v().alias("t").describe("Show status tags")},handler:async(n,r,o)=>{let s=await B(r.fs,r.cwd,t);if(S(s))return s;let a=s,i=Fe(a);if(i)return i;let c=a.workTree,f=n.cached,d=n.modified,u=n.deleted,l=n.others,m=n.unmerged,h=n.stage,p=n["exclude-standard"],g=n["nul-terminate"],w=n["show-tags"];f||d||u||l||m||(f=!0);let b=await U(a),y=g?"\0":`
|
|
364
|
+
`,k=o.passthrough.length>0?o.passthrough.map(O=>{let E=r.cwd!==c?Nu(c,r.cwd):"";return Oe(O,E)}):null,C=[];if(f)for(let O of b.entries){if(k&&!me(k,O.path))continue;let E=w?O.stage>0?"M":"H":null;C.push(Cc(O,h,E))}if(m&&!f)for(let O of b.entries)O.stage!==0&&(k&&!me(k,O.path)||C.push(Cc(O,!0,w?"M":null)));if(d||u){let O=await _u(a,c,b);for(let{path:E,status:I}of O){if(I==="modified"&&!d||I==="deleted"&&!u||k&&!me(k,E))continue;let A=w?I==="deleted"?"R":"C":null;C.push(A?`${A} ${E}`:E)}}if(l){let O=await Fu(a,c,b,p);for(let E of O)k&&!me(k,E)||C.push(w?`? ${E}`:E)}return{stdout:C.length>0?C.join(y)+y:"",stderr:"",exitCode:0}}})}function Cc(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 Nu(e,t){return t===e?"":t.startsWith(`${e}/`)?t.slice(e.length+1):""}async function _u(e,t,n){let r=[];for(let o of n.entries){if(o.stage!==0)continue;let s=H(t,o.path);if(!await e.fs.exists(s)){r.push({path:o.path,status:"deleted"});continue}let i=await ze(e.fs,s);if(!i.isFile&&!i.isSymbolicLink)continue;await Zt(e.fs,s)!==o.hash&&r.push({path:o.path,status:"modified"})}return r}async function Fu(e,t,n,r){let o=new Set(n.entries.map(a=>a.path));return(await _e(e,t,"",{skipIgnore:!r})).filter(a=>!o.has(a))}function Oc(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:v().describe("Abort the current in-progress merge"),continue:v().describe("Continue the merge after conflict resolution"),noFf:v().describe("Create a merge commit even when fast-forward is possible"),ffOnly:v().describe("Refuse to merge unless fast-forward is possible"),squash:v().describe("Apply merge result to worktree/index without creating a merge commit"),edit:v().describe("Edit the merge message (no-op, accepted for compatibility)"),message:te.string().alias("m").describe("Merge commit message")},transformArgs:n=>n.filter(r=>r!=="--ff"),handler:async(n,r)=>{let o=await B(r.fs,r.cwd,t);if(S(o))return o;let s=o;if(n.abort)return qu(s,r.env);if(n.continue)return Wu(s,r.env,t);let a=n.branch;if(!a)return T("you must specify a branch to merge");let i=await Se(s);if(S(i))return i;let c=await U(s),f=Nt(c,"Merging");if(f)return f;if(await F(s,"MERGE_HEAD"))return T(`You have not concluded your merge (MERGE_HEAD exists).
|
|
354
365
|
Please, commit your changes before you merge.`);if(await F(s,"CHERRY_PICK_HEAD"))return T(`You have not concluded your cherry-pick (CHERRY_PICK_HEAD exists).
|
|
355
366
|
Please, commit your changes before you merge.`);let l=await je(s,a);if(!l)return j(`merge: ${a} - not something we can merge
|
|
356
367
|
`);let m=await Re(s,l),h=await ht(s,i,m),p=h[0]??null;if(h.length===0)return T("refusing to merge unrelated histories");if(p===m)return{stdout:`Already up to date.${n.squash?" (nothing to squash)":""}
|
|
@@ -366,7 +377,7 @@ hint: Disable this message with "git config set advice.diverging false"
|
|
|
366
377
|
fatal: Not possible to fast-forward, aborting.
|
|
367
378
|
`,128);if(await F(s,"REVERT_HEAD")&&await pt(s),g&&!n.squash){let b=await J(s),y=await Jr(s,i,m);if(y.exitCode===0&&n.message&&(y.stdout=y.stdout.replace(/^Fast-forward$/m,"Fast-forward (no commit created; -m option ignored)")),y.exitCode===0){let k=b?.type==="symbolic"?b.target:"HEAD";await ee(s,r.env,k,i,m,`merge ${a}: Fast-forward${n.message?" (no commit created; -m option ignored)":""}`,b?.type==="symbolic"),await t?.hooks?.emitPost("post-merge",{headHash:i,theirsHash:m,strategy:"fast-forward",commitHash:null})}return y}let w=n.message,x=w?w.endsWith(`
|
|
368
379
|
`)?w:`${w}
|
|
369
|
-
`:void 0;return n.squash?
|
|
380
|
+
`:void 0;return n.squash?Bu(s,i,m,a,r.env,t,x):Uu(s,i,m,a,r.env,n.noFf,t,x)}})}async function Uu(e,t,n,r,o,s=!1,a,i){let c=await M(e,t),f=await J(e),d=f?.type==="symbolic"?de(f.target):"HEAD",u={a:"HEAD",b:r},l=await fr(e,t,n,u),m=await Wt(e,l,c.tree,{labels:u,errorExitCode:2,operationName:"merge"});if(!m.ok)return m.failureKind==="staged"&&f?.type==="symbolic"&&await ee(e,o,"HEAD",t,t,`merge ${r}: updating HEAD`),m;if(l.conflicts.length>0){await Y(e,"MERGE_HEAD",n),await Y(e,"ORIG_HEAD",t);let C=i??await Ft(e,r,d);if(a?.hooks){let E={message:C,treeHash:m.mergedTreeHash,headHash:t,theirsHash:n},I=await a.hooks.emitPre("merge-msg",E);if(I)return{stdout:"",stderr:I.message??"",exitCode:1};C=E.message}let P=Rt({version:2,entries:l.entries}).sort();return C+=`
|
|
370
381
|
# Conflicts:
|
|
371
382
|
${P.map(E=>`# ${E}`).join(`
|
|
372
383
|
`)}
|
|
@@ -375,7 +386,7 @@ ${P.map(E=>`# ${E}`).join(`
|
|
|
375
386
|
`,stderr:"",exitCode:1}}let h=m.mergedTreeHash,p=await Ht(e,o);if(S(p))return p;let g=await Le(e,o);if(S(g))return g;let w=i??await Ft(e,r,d);if(a?.hooks){let C={message:w,treeHash:h,headHash:t,theirsHash:n},P=await a.hooks.emitPre("merge-msg",C);if(P)return{stdout:"",stderr:P.message??"",exitCode:1};w=C.message}if(a?.hooks){let C=await a.hooks.emitPre("pre-merge-commit",{mergeMessage:w,treeHash:h,headHash:t,theirsHash:n});if(C)return{stdout:"",stderr:C.message??"",exitCode:1}}let x=await Je(e,h,[t,n],p,g,w),b=f?.type==="symbolic"?f.target:"HEAD";await ee(e,o,b,t,x,`merge ${r}: Merge made by the 'ort' strategy.`,f?.type==="symbolic"),await a?.hooks?.emitPost("post-merge",{headHash:t,theirsHash:n,strategy:"three-way",commitHash:x});let y=await sn(e,c.tree,h);return{stdout:`${l.messages.length>0?`${l.messages.join(`
|
|
376
387
|
`)}
|
|
377
388
|
`:""}Merge made by the 'ort' strategy.
|
|
378
|
-
${y}`,stderr:"",exitCode:0}}async function
|
|
389
|
+
${y}`,stderr:"",exitCode:0}}async function Bu(e,t,n,r,o,s,a){let i=await M(e,t),c=await J(e),f=c?.type==="symbolic"?de(c.target):"HEAD",d={a:"HEAD",b:r},u=await ht(e,t,n),l=u.length>0&&u[0]===t,m=l?`Updating ${K(t)}..${K(n)}
|
|
379
390
|
`:"",h=await fr(e,t,n,d),p=await Wt(e,h,i.tree,{labels:d,errorExitCode:l?1:2,operationName:"merge"});if(!p.ok){!l&&p.failureKind==="staged"&&c?.type==="symbolic"&&await ee(e,o,"HEAD",t,t,`merge ${r}: updating HEAD`);let k=p;return m&&(k.stdout=m+k.stdout),k}if(h.conflicts.length>0){await Y(e,"ORIG_HEAD",t);let k=a??await Ft(e,r,f);return k=`Squashed commit of the following:
|
|
380
391
|
|
|
381
392
|
${k}`,await Ue(e,"MERGE_MSG",k),await Ue(e,"MERGE_MODE",""),{stdout:`${[...h.messages,"Squash commit -- not updating HEAD","Automatic merge failed; fix conflicts and then commit the result."].join(`
|
|
@@ -387,12 +398,12 @@ ${k}`,await Ue(e,"MERGE_MSG",k),await Ue(e,"MERGE_MODE",""),{stdout:`${[...h.mes
|
|
|
387
398
|
${b}`,await Ue(e,"MERGE_MSG",b),{stdout:`${l?`${m}Fast-forward
|
|
388
399
|
`:""}${x}Squash commit -- not updating HEAD
|
|
389
400
|
${l?w:""}`,stderr:l?"":`Automatic merge went well; stopped before committing as requested
|
|
390
|
-
`,exitCode:0}}async function
|
|
391
|
-
${x}`,stderr:"",exitCode:0}}async function
|
|
392
|
-
`);let f=c[c.length-1],d=c.slice(0,-1),u=ct(r.cwd,f),l=Ke(i,u);if(l.startsWith(".."))return T(`'${f}' is outside repository at '${i}'`);let m=await U(s),h=await r.fs.exists(u),p=h&&(await r.fs.stat(u)).isDirectory;if(d.length>1&&!p)return T(h?`destination '${f}' is not a directory`:`destination directory '${f}' does not exist`);let g=[];for(let w of d){let x=ct(r.cwd,w),b=Ke(i,x);if(b.startsWith("..")){if(n.skip)continue;return T(`'${w}' is outside repository at '${i}'`)}if(!await r.fs.exists(x)){if(n.skip)continue;return T(`bad source, source=${b}, destination=${l}`)}let C=(await r.fs.stat(x)).isDirectory;if(!(C?m.entries.some(_=>_.path===b||_.path.startsWith(`${b}/`)):m.entries.some(_=>_.path===b&&_.stage===0))){let _=!C&&m.entries.some(G=>G.path===b&&G.stage>0);if(n.skip)continue;return T(_?`conflicted, source=${b}, destination=${l}`:`not under version control, source=${b}, destination=${l}`)}let O,E;if(p){let _=
|
|
393
|
-
`,128);let c=n.remote,f=n.branch;if(!c){let ne=await J(s);if(ne?.type==="symbolic"){let Ce=ne.target.startsWith("refs/heads/")?ne.target.slice(11):ne.target,Pn=(await ae(s))[`branch "${Ce}"`];Pn&&(c=Pn.remote||"origin",!f&&Pn.merge&&(f=Pn.merge.startsWith("refs/heads/")?Pn.merge.slice(11):Pn.merge))}}c=c||"origin";let d;try{d=await
|
|
401
|
+
`,exitCode:0}}async function Wu(e,t,n){let r=await F(e,"MERGE_HEAD");if(!r)return T("There is no merge in progress (MERGE_HEAD missing).");let o=await U(e),s=Nt(o,"Committing");if(s)return s;let a=await Se(e);if(S(a))return a;let i=await M(e,a),c=await qe(e,"MERGE_MSG");if(c)c=rr(c);else{let k=await J(e),C=k?.type==="symbolic"?de(k.target):"HEAD";c=await Ft(e,"unknown",C)}let f=xe(o),d=await ke(e,f),u=await Ht(e,t);if(S(u))return u;let l=await Le(e,t);if(S(l))return l;let m=mt(c);if(n?.hooks){let k={message:m,treeHash:d,headHash:a,theirsHash:r},C=await n.hooks.emitPre("merge-msg",k);if(C)return{stdout:"",stderr:C.message??"",exitCode:1};m=k.message}if(n?.hooks){let k=await n.hooks.emitPre("pre-merge-commit",{mergeMessage:m,treeHash:d,headHash:a,theirsHash:r});if(k)return{stdout:"",stderr:k.message??"",exitCode:1}}let h=await Je(e,d,[a,r],u,l,m);await or(e);let p=await J(e),g=ue(m),w=p?.type==="symbolic"?p.target:"HEAD";await ee(e,t,w,a,h,`commit (merge): ${g}`,p?.type==="symbolic"),await n?.hooks?.emitPost("post-merge",{headHash:a,theirsHash:r,strategy:"three-way",commitHash:h});let x=await sn(e,i.tree,d),b=p?.type==="symbolic"?de(p.target):"detached HEAD";return{stdout:`${ut(b,h,c)}
|
|
402
|
+
${x}`,stderr:"",exitCode:0}}async function qu(e,t){return en(e,t,{operationRef:"MERGE_HEAD",noOpError:T("There is no merge to abort (MERGE_HEAD missing)."),operationName:"merge",clearState:or})}function Rc(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:v().alias("f").describe("Force renaming even if target exists"),"dry-run":v().alias("n").describe("Do nothing; only show what would happen"),skip:v().alias("k").describe("Skip move/rename actions that would lead to errors")},handler:async(n,r)=>{let o=await B(r.fs,r.cwd,t);if(S(o))return o;let s=o,a=Fe(s);if(a)return a;let i=s.workTree,c=n.sources;if(c.length<2)return j(`usage: git mv [<options>] <source>... <destination>
|
|
403
|
+
`);let f=c[c.length-1],d=c.slice(0,-1),u=ct(r.cwd,f),l=Ke(i,u);if(l.startsWith(".."))return T(`'${f}' is outside repository at '${i}'`);let m=await U(s),h=await r.fs.exists(u),p=h&&(await r.fs.stat(u)).isDirectory;if(d.length>1&&!p)return T(h?`destination '${f}' is not a directory`:`destination directory '${f}' does not exist`);let g=[];for(let w of d){let x=ct(r.cwd,w),b=Ke(i,x);if(b.startsWith("..")){if(n.skip)continue;return T(`'${w}' is outside repository at '${i}'`)}if(!await r.fs.exists(x)){if(n.skip)continue;return T(`bad source, source=${b}, destination=${l}`)}let C=(await r.fs.stat(x)).isDirectory;if(!(C?m.entries.some(_=>_.path===b||_.path.startsWith(`${b}/`)):m.entries.some(_=>_.path===b&&_.stage===0))){let _=!C&&m.entries.some(G=>G.path===b&&G.stage>0);if(n.skip)continue;return T(_?`conflicted, source=${b}, destination=${l}`:`not under version control, source=${b}, destination=${l}`)}let O,E;if(p){let _=qn(b);O=l===""||l==="."?_:`${l}/${_}`,E=H(u,_)}else O=l,E=u;if(await r.fs.exists(E)&&!n.force)if((await r.fs.stat(E)).isDirectory){let G=qn(b);O=`${O}/${G}`,E=H(E,G)}else{if(n.skip)continue;return T(`destination exists, source=${b}, destination=${O}`)}if(b===O){if(n.skip)continue;return T(`can not move directory into itself, source=${b}, destination=${O}`)}let A=Pt(E);if(!await r.fs.exists(A)){if(n.skip)continue;return T(`renaming '${b}' failed: No such file or directory`)}if(C){let _=`${b}/`,G=m.entries.filter(z=>z.path.startsWith(_)&&z.stage===0);for(let z of G){let D=z.path.slice(b.length),$=O+D,R=E+D;g.push({srcRel:z.path,dstRel:$,srcAbs:H(i,z.path),dstAbs:R})}}else g.push({srcRel:b,dstRel:O,srcAbs:x,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 x=Pt(w.dstAbs);await r.fs.exists(x)||await r.fs.mkdir(x,{recursive:!0});let b=await r.fs.readFileBuffer(w.srcAbs);await r.fs.writeFile(w.dstAbs,b),await r.fs.rm(w.srcAbs);let y=Dt(m,w.srcRel,0);if(y){m=Ne(m,w.srcRel);let k={...y,path:w.dstRel};m=Xe(m,k)}}for(let w of g)await pn(r.fs,Pt(w.srcAbs),i);return await re(s,m),{stdout:"",stderr:"",exitCode:0}}})}function Ic(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:v().alias("r").describe("Rebase instead of merge"),noRebase:v().describe("Merge instead of rebase"),ffOnly:v().describe("Only fast-forward"),noFf:v().describe("Create a merge commit even for fast-forwards")},handler:async(n,r)=>{let o=await B(r.fs,r.cwd,t);if(S(o))return o;let s=o,a=await Se(s);if(S(a))return a;let i=await U(s);if(dt(i))return j(`error: Pulling is not possible because you have unmerged files.
|
|
404
|
+
`,128);let c=n.remote,f=n.branch;if(!c){let ne=await J(s);if(ne?.type==="symbolic"){let Ce=ne.target.startsWith("refs/heads/")?ne.target.slice(11):ne.target,Pn=(await ae(s))[`branch "${Ce}"`];Pn&&(c=Pn.remote||"origin",!f&&Pn.merge&&(f=Pn.merge.startsWith("refs/heads/")?Pn.merge.slice(11):Pn.merge))}}c=c||"origin";let d;try{d=await _n(s,c,r.env)}catch(ne){let Ce=ne instanceof Error?ne.message:"";if(Ce.startsWith("network"))return T(Ce);throw ne}if(!d)return T(`'${c}' does not appear to be a git repository`);let{transport:u,config:l}=d,m=f??null;if(t?.hooks){let ne=await t.hooks.emitPre("pre-pull",{remote:c,branch:m});if(ne)return{stdout:"",stderr:ne.message??"",exitCode:1}}let h=Cn(l.fetchRefspec),p=await u.advertiseRefs();if(p.length===0)return T("Couldn't find remote ref HEAD");let w=(await le(s)).map(ne=>ne.hash),x=await F(s,"HEAD");x&&w.push(x);let b=[],y=new Set,k=[];for(let ne of p){if(ne.name==="HEAD")continue;let Ce=bs(h,ne.name);Ce!==null&&(k.push({remote:ne,localRef:Ce}),y.has(ne.hash)||(y.add(ne.hash),b.push(ne.hash)))}let C=new Set(w),P=b.filter(ne=>!C.has(ne));P.length>0&&await u.fetch(P,w);let O=await Ot(s,r.env);for(let ne of k){let Ce=await F(s,ne.localRef);await Y(s,ne.localRef,ne.remote.hash),await Te(s,ne.localRef,{oldHash:Ce??Z,newHash:ne.remote.hash,name:O.name,email:O.email,timestamp:O.timestamp,tz:O.tz,message:Ce?"pull":"pull: storing head"})}let E=null;if(f){let ne=p.find(Ce=>Ce.name===`refs/heads/${f}`);if(ne)E=ne.hash;else return T(`Couldn't find remote ref refs/heads/${f}`)}else{let ne=p.find(Ce=>Ce.name==="HEAD");ne&&(E=ne.hash)}if(E&&await r.fs.writeFile(H(s.gitDir,"FETCH_HEAD"),`${E} ${l.url}
|
|
394
405
|
`),!E)return T("Could not determine remote HEAD");let I=E;if(a===I)return await t?.hooks?.emitPost("post-pull",{remote:c,branch:m,strategy:"up-to-date",commitHash:null}),{stdout:`Already up to date.
|
|
395
|
-
`,stderr:"",exitCode:0};let
|
|
406
|
+
`,stderr:"",exitCode:0};let A=await ht(s,a,I),_=A[0]??null;if(A.length===0)return T("refusing to merge unrelated histories");if(_===I)return await t?.hooks?.emitPost("post-pull",{remote:c,branch:m,strategy:"up-to-date",commitHash:null}),{stdout:`Already up to date.
|
|
396
407
|
`,stderr:"",exitCode:0};let G=_===a;if(n.ffOnly&&!G)return T("Not possible to fast-forward, aborting.");if(G&&!n.noFf){let ne=await Jr(s,a,I),Ce=await J(s),ln=Ce?.type==="symbolic"?Ce.target:"HEAD";return await Te(s,ln,{oldHash:a,newHash:I,name:O.name,email:O.email,timestamp:O.timestamp,tz:O.tz,message:"pull: Fast-forward"}),Ce?.type==="symbolic"&&await Te(s,"HEAD",{oldHash:a,newHash:I,name:O.name,email:O.email,timestamp:O.timestamp,tz:O.tz,message:"pull: Fast-forward"}),ne.exitCode===0&&(await t?.hooks?.emitPost("post-merge",{headHash:a,theirsHash:I,strategy:"fast-forward",commitHash:null}),await t?.hooks?.emitPost("post-pull",{remote:c,branch:m,strategy:"fast-forward",commitHash:null})),ne}let z=await J(s),D=z?.type==="symbolic"?de(z.target):"HEAD",$=f||c||"FETCH_HEAD",R={a:"HEAD",b:$},N=await fr(s,a,I,R),q=await M(s,a),L=await Wt(s,N,q.tree,{labels:R,errorExitCode:2,operationName:"merge"});if(!L.ok)return L;if(N.conflicts.length>0){await Y(s,"MERGE_HEAD",I),await Y(s,"ORIG_HEAD",a);let ne=await Ft(s,$,D),Ce=Rt({version:2,entries:N.entries}).sort();return ne+=`
|
|
397
408
|
# Conflicts:
|
|
398
409
|
${Ce.map(ln=>`# ${ln}`).join(`
|
|
@@ -402,8 +413,8 @@ ${Ce.map(ln=>`# ${ln}`).join(`
|
|
|
402
413
|
`,stderr:"",exitCode:1}}let V=L.mergedTreeHash,oe=await Ht(s,r.env);if(S(oe))return oe;let Q=await Le(s,r.env);if(S(Q))return Q;let ge=await Ft(s,$,D);if(t?.hooks){let ne={message:ge,treeHash:V,headHash:a,theirsHash:I},Ce=await t.hooks.emitPre("merge-msg",ne);if(Ce)return{stdout:"",stderr:Ce.message??"",exitCode:1};ge=ne.message;let ln=await t.hooks.emitPre("pre-merge-commit",{mergeMessage:ge,treeHash:V,headHash:a,theirsHash:I});if(ln)return{stdout:"",stderr:ln.message??"",exitCode:1}}let De=await Je(s,V,[a,I],oe,Q,ge);await t?.hooks?.emitPost("post-merge",{headHash:a,theirsHash:I,strategy:"three-way",commitHash:De}),await t?.hooks?.emitPost("post-pull",{remote:c,branch:m,strategy:"three-way",commitHash:De});let dn=z?.type==="symbolic"?z.target:"HEAD",Ie="pull: Merge made by the 'ort' strategy.";await Te(s,dn,{oldHash:a,newHash:De,name:O.name,email:O.email,timestamp:O.timestamp,tz:O.tz,message:Ie}),z?.type==="symbolic"&&await Te(s,"HEAD",{oldHash:a,newHash:De,name:O.name,email:O.email,timestamp:O.timestamp,tz:O.tz,message:Ie});let wr=await sn(s,q.tree,V);return{stdout:`${N.messages.length>0?`${N.messages.join(`
|
|
403
414
|
`)}
|
|
404
415
|
`:""}Merge made by the 'ort' strategy.
|
|
405
|
-
${wr}`,stderr:"",exitCode:0}}})}function
|
|
406
|
-
`);m.push({name:k,oldHash:C,newHash:Z,ok:d})}}else if(n.all){let b=await le(s,"refs/heads");for(let y of b){let k=y.name,C=l.get(k)??null;m.push({name:k,oldHash:C,newHash:y.hash,ok:d})}}else if(n.tags){let b=await le(s,"refs/tags");for(let y of b){let k=l.get(y.name)??null;k!==y.hash&&m.push({name:y.name,oldHash:k,newHash:y.hash,ok:d})}}else if(h&&h.length>0)for(let b of h){let y=Cn(b),k=await
|
|
416
|
+
${wr}`,stderr:"",exitCode:0}}})}function $c(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:v().alias("f").describe("Force push"),"set-upstream":v().alias("u").describe("Set upstream tracking reference"),all:v().describe("Push all branches"),delete:v().alias("d").describe("Delete remote refs"),tags:v().describe("Push all tags")},handler:async(n,r)=>{let o=await B(r.fs,r.cwd,t);if(S(o))return o;let s=o,a=n.remote||"origin",i;try{i=await _n(s,a,r.env)}catch(b){let y=b instanceof Error?b.message:"";if(y.startsWith("network"))return T(y);throw b}if(!i)return T(`'${a}' does not appear to be a git repository`);let{transport:c,config:f}=i,d=n.force,u=await c.advertiseRefs(),l=new Map;for(let b of u)l.set(b.name,b.hash);let m=[],h=n.refspec;if(n.delete){let b=h&&h.length>0?h:[];if(b.length===0)return T("--delete requires a ref argument");for(let y of b){let k=y.startsWith("refs/")?y:`refs/heads/${y}`,C=l.get(k)??null;if(!C)return j(`error: unable to delete '${y}': remote ref does not exist
|
|
417
|
+
`);m.push({name:k,oldHash:C,newHash:Z,ok:d})}}else if(n.all){let b=await le(s,"refs/heads");for(let y of b){let k=y.name,C=l.get(k)??null;m.push({name:k,oldHash:C,newHash:y.hash,ok:d})}}else if(n.tags){let b=await le(s,"refs/tags");for(let y of b){let k=l.get(y.name)??null;k!==y.hash&&m.push({name:y.name,oldHash:k,newHash:y.hash,ok:d})}}else if(h&&h.length>0)for(let b of h){let y=Cn(b),k=await Ku(s,y.src);if(!k)return j(`error: src refspec '${y.src}' does not match any
|
|
407
418
|
`);let C=y.dst.startsWith("refs/")?y.dst:`refs/heads/${y.dst}`,P=l.get(C)??null;m.push({name:C,oldHash:P,newHash:k,ok:d||y.force})}else{let b=await J(s);if(!b||b.type!=="symbolic")return T("You are not currently on a branch.");let y=b.target,k=await X(s);if(!k)return j(`error: src refspec does not match any
|
|
408
419
|
`);let C=l.get(y)??null;m.push({name:y,oldHash:C,newHash:k,ok:d})}if(m.length===0)return{stdout:`Everything up-to-date
|
|
409
420
|
`,stderr:"",exitCode:0};if(t?.hooks){let b=await t.hooks.emitPre("pre-push",{remote:a,url:f.url,refs:m.map(y=>({srcRef:y.newHash===Z?null:y.name,srcHash:y.newHash===Z?null:y.newHash,dstRef:y.name,dstHash:y.oldHash,force:!!y.ok,delete:y.newHash===Z}))});if(b)return j(b.message??"")}let p=await c.push(m),g=[];g.push(`To ${f.url}
|
|
@@ -412,13 +423,13 @@ ${wr}`,stderr:"",exitCode:0}}})}function Ic(e,t){e.command("push",{description:"
|
|
|
412
423
|
`);else if(b.newHash===Z)g.push(` - [deleted] ${y}
|
|
413
424
|
`);else{let k=K(b.oldHash),C=K(b.newHash);g.push(` ${k}..${C} ${y} -> ${y}
|
|
414
425
|
`)}}if(n["set-upstream"]&&!w){let b=await J(s);if(b?.type==="symbolic"){let y=b.target.startsWith("refs/heads/")?b.target.slice(11):b.target,k=await ae(s);k[`branch "${y}"`]={remote:a,merge:`refs/heads/${y}`},await Ge(s,k),g.push(`branch '${y}' set up to track '${a}/${y}'.
|
|
415
|
-
`)}}let x={stdout:"",stderr:g.join(""),exitCode:w?1:0};return w||await t?.hooks?.emitPost("post-push",{remote:a,url:f.url,refs:m.map(b=>({srcRef:b.newHash===Z?null:b.name,srcHash:b.newHash===Z?null:b.newHash,dstRef:b.name,dstHash:b.oldHash,force:!!b.ok,delete:b.newHash===Z}))}),x}})}async function
|
|
426
|
+
`)}}let x={stdout:"",stderr:g.join(""),exitCode:w?1:0};return w||await t?.hooks?.emitPost("post-push",{remote:a,url:f.url,refs:m.map(b=>({srcRef:b.newHash===Z?null:b.name,srcHash:b.newHash===Z?null:b.newHash,dstRef:b.name,dstHash:b.oldHash,force:!!b.ok,delete:b.newHash===Z}))}),x}})}async function Ku(e,t){if(t.startsWith("refs/"))return F(e,t);let n=await F(e,`refs/heads/${t}`);if(n)return n;let r=await F(e,`refs/tags/${t}`);return r||(t==="HEAD"?X(e):null)}async function vo(e,t){let n=await ce(e,t);if(n.type!=="commit")return null;let r=It(n.content),o=null;if(r.parents.length>0&&r.parents[0]){let f=await ce(e,r.parents[0]);f.type==="commit"&&(o=It(f.content).tree)}let s=await Ae(e,o,r.tree);if(s.length===0)return null;let a=Kt(),i=!1,c=[...s].sort((f,d)=>he(f.path,d.path));for(let f of c){let d="",u="";if(f.oldHash)try{let m=await ce(e,f.oldHash);d=new TextDecoder().decode(m.content)}catch{}if(f.newHash)try{let m=await ce(e,f.newHash);u=new TextDecoder().decode(m.content)}catch{}let l=At({path:f.path,oldContent:d,newContent:u,oldMode:f.oldMode,newMode:f.newMode});if(l)for(let m of l.split(`
|
|
416
427
|
`)){if(!m||m.startsWith("index "))continue;let p=(m.startsWith("@@")?m.replace(/^@@ [^@]* @@/,"@@ @@"):m).replace(/[ \t\r]/g,"");p&&(a.update(p),a.update(`
|
|
417
|
-
`),i=!0)}}return i?a.hex():null}async function
|
|
428
|
+
`),i=!0)}}return i?a.hex():null}async function zu(e){let t=await J(e);return t?.type==="symbolic"?de(t.target):"detached HEAD"}function Tc(e){return e==="HEAD"?`HEAD is up to date.
|
|
418
429
|
`:`Current branch ${e} is up to date.
|
|
419
|
-
`}async function
|
|
420
|
-
`)}return null}async function
|
|
421
|
-
`,exitCode:128}:null}async function
|
|
430
|
+
`}async function Vu(e,t,n){if(!e.workTree)return null;let r=await se(e,t),o=new Map(xe(n).map(i=>[i.path,i])),s=new Set(await _e(e,e.workTree,"")),a=[];for(let[i]of r)o.has(i)||s.has(i)&&a.push({path:i,error:"WOULD_LOSE_UNTRACKED_OVERWRITTEN"});if(a.length>0){let i=Gr(a,{errorExitCode:1,operationName:"checkout",actionHint:"switch branches"});return j(`${i.stderr}error: could not detach HEAD
|
|
431
|
+
`)}return null}async function Yu(e,t,n,r){if(!e.workTree)return null;let o=await se(e,t),s=new Set(n.entries.map(c=>c.path)),a=new Set(await _e(e,e.workTree,"")),i=[];for(let[c]of o)!s.has(c)&&a.has(c)&&i.push({path:c,error:"WOULD_LOSE_UNTRACKED_OVERWRITTEN"});return i.length>0?{stdout:"",stderr:`${Gr(i,{errorExitCode:128,operationName:"reset",actionHint:"reset"}).stderr}fatal: could not move back to ${r}
|
|
432
|
+
`,exitCode:128}:null}async function Hc(e,t,n){if(!e.workTree)return null;let r=new Map(xe(t).map(a=>[a.path,a])),o=new Set(await _e(e,e.workTree,"")),s=[];for(let[a]of n)!r.has(a)&&o.has(a)&&s.push(a);return s.length>0?s:null}function Ac(e,t){return`error: The following untracked working tree files would be overwritten by merge:
|
|
422
433
|
${e.map(r=>` ${r}`).join(`
|
|
423
434
|
`)}
|
|
424
435
|
Please move or remove them before you merge.
|
|
@@ -432,7 +443,7 @@ hint: edit the todo list first:
|
|
|
432
443
|
hint:
|
|
433
444
|
hint: git rebase --edit-todo
|
|
434
445
|
hint: git rebase --continue
|
|
435
|
-
`}async function
|
|
446
|
+
`}async function So(e,t,n,r,o,s){await ee(e,t,"HEAD",n,r,`rebase (start): checkout ${s}`),o!=="detached HEAD"&&(await ee(e,t,o,n,r,`rebase (finish): ${o} onto ${r}`),await ee(e,t,"HEAD",r,r,`rebase (finish): returning to ${o}`))}async function ks(e,t,n,r){let o=await M(e,t),s=await Vu(e,o.tree,n);if(s)return s;let a=await yt(e,o.tree,n);return a.success&&(await re(e,{version:2,entries:a.newEntries}),await be(e,a.worktreeOps)),r!=="detached HEAD"?await Y(e,r,t):await Y(e,"HEAD",t),null}function vc(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:te.string().describe("Starting point at which to create new commits"),abort:v().describe("Abort the current rebase operation"),continue:v().describe("Continue the rebase after conflict resolution"),skip:v().describe("Skip the current patch and continue")},handler:async(n,r)=>{let o=await B(r.fs,r.cwd,t);if(S(o))return o;let s=o;if(n.abort)return Ju(s,r.env);if(n.continue)return Qu(s,r.env);if(n.skip)return em(s,r.env);let a=n.upstream;if(!a)return T("no upstream configured and no upstream argument given");if(await gt(s))return T(`It seems that there is already a rebase-merge directory, and
|
|
436
447
|
I wonder if you are in the middle of another rebase. If that is the
|
|
437
448
|
case, please try
|
|
438
449
|
git rebase (--continue | --abort | --skip)
|
|
@@ -446,16 +457,16 @@ error: additionally, your index contains uncommitted changes.
|
|
|
446
457
|
error: Please commit or stash them.
|
|
447
458
|
`,exitCode:1};let w=await M(s,i),x=await se(s,w.tree);if(s.workTree){let R=vn(p,x),q=(await lt(s,p)).some(L=>L.status==="modified"||L.status==="deleted");if(R||q){let L=[];return q&&L.push("error: cannot rebase: You have unstaged changes."),R&&(q?L.push("error: additionally, your index contains uncommitted changes."):L.push("error: cannot rebase: Your index contains uncommitted changes.")),L.push("error: Please commit or stash them."),j(`${L.join(`
|
|
448
459
|
`)}
|
|
449
|
-
`)}}if(t?.hooks){let R=await t.hooks.emitPre("pre-rebase",{upstream:a,branch:c?.type==="symbolic"?de(c.target):null});if(R)return{stdout:"",stderr:R.message??"",exitCode:1}}let b=await
|
|
450
|
-
`,exitCode:0})}return{stdout
|
|
460
|
+
`)}}if(t?.hooks){let R=await t.hooks.emitPre("pre-rebase",{upstream:a,branch:c?.type==="symbolic"?de(c.target):null});if(R)return{stdout:"",stderr:R.message??"",exitCode:1}}let b=await ua(s,l,i),y=b.right;if(y.length===0){if(m!==i){let R=await ks(s,m,p,f);return R||(await So(s,r.env,i,m,f,a),{stdout:"",stderr:`Successfully rebased and updated ${f}.
|
|
461
|
+
`,exitCode:0})}return{stdout:Tc(d),stderr:"",exitCode:0}}let k=[],C=b.left,P=new Set;for(let R of C){let N=await vo(s,R.hash);N&&P.add(N)}let O=[];if(P.size>0)for(let R of y){let N=await vo(s,R.hash);N&&P.has(N)?k.push(`warning: skipped previously applied commit ${K(R.hash)}`):O.push(R)}else O.push(...y);let E="";if(k.length>0&&(E=`${k.join(`
|
|
451
462
|
`)}
|
|
452
463
|
hint: use --reapply-cherry-picks to include skipped commits
|
|
453
464
|
hint: Disable this message with "git config set advice.skippedCherryPicks false"
|
|
454
|
-
`),O.length===0){if(m!==i){let R=await
|
|
455
|
-
`,exitCode:0}}let I=O.map(R=>({hash:R.hash,subject:ue(R.commit.message)})),
|
|
456
|
-
`,exitCode:0})}let z=await
|
|
465
|
+
`),O.length===0){if(m!==i){let R=await ks(s,m,p,f);if(R)return R.stderr=E+R.stderr,R;await So(s,r.env,i,m,f,a)}return{stdout:"",stderr:`${E}Successfully rebased and updated ${f}.
|
|
466
|
+
`,exitCode:0}}let I=O.map(R=>({hash:R.hash,subject:ue(R.commit.message)})),A=m,_=0;for(let R of I){let N=await M(s,R.hash);if(N.parents.length>1||N.parents.length===0||N.parents[0]!==A)break;A=R.hash,_++}let G=I.splice(0,_);if(I.length===0){if(A===i)return{stdout:Tc(d),stderr:E,exitCode:0};let R=await ks(s,A,p,f);return R?(R.stderr=E+R.stderr,R):(await So(s,r.env,i,A,f,a),{stdout:"",stderr:`${E}Successfully rebased and updated ${f}.
|
|
467
|
+
`,exitCode:0})}let z=await ks(s,A,p,"detached HEAD");if(z)return z.stderr=E+z.stderr,z;await ee(s,r.env,"HEAD",i,A,`rebase (start): checkout ${a}`);let D={headName:f,origHead:i,onto:m,todo:I,done:G,msgnum:_,end:_+I.length};await co(s,D),await Y(s,"ORIG_HEAD",i);let $=await Do(s,r.env);return E&&($.stderr=E+$.stderr),$}})}async function Do(e,t){let n=[],r=[];for(;;){let o=await nt(e);if(!o||o.todo.length===0)break;let s=o.todo[0];if(!s)break;n.push(`Rebasing (${o.msgnum+1}/${o.end})\r`),await la(e);let a=await Xu(e,s,t);if(a.conflict){if(a.rescheduleCurrent){let i=await nt(e);i&&(i.todo=[s,...i.todo],await co(e,i))}return a.stdout&&r.push(a.stdout),n.push(a.stderr),{stdout:r.join(""),stderr:n.join(""),exitCode:1}}a.stdout&&r.push(a.stdout),a.stderr&&n.push(a.stderr)}return Zu(e,n,t)}async function Xu(e,t,n){let r=t.hash,o=await M(e,r),s=o.parents.length>0?o.parents[0]:null,a=s?await M(e,s):null,i=await X(e);if(!i)return{conflict:!0,stdout:"",stderr:`fatal: no HEAD commit during rebase
|
|
457
468
|
`};if(s&&s===i){let G=await U(e);if(!a)return{conflict:!0,stdout:"",stderr:`fatal: missing parent commit during rebase
|
|
458
|
-
`};let z=await He(e,a.tree),D=await He(e,o.tree),$=new Map(z.map(L=>[L.path,L.hash])),R=new Map;for(let L of D){let V=$.get(L.path);(!V||V!==L.hash)&&R.set(L.path,L.hash)}let N=await
|
|
469
|
+
`};let z=await He(e,a.tree),D=await He(e,o.tree),$=new Map(z.map(L=>[L.path,L.hash])),R=new Map;for(let L of D){let V=$.get(L.path);(!V||V!==L.hash)&&R.set(L.path,L.hash)}let N=await Hc(e,G,R);if(N)return await Y(e,"REBASE_HEAD",r),await ts(e,r,o.author),{conflict:!0,stdout:"",stderr:Ac(N,t),rescheduleCurrent:!0};let q=await yt(e,o.tree,G);return q.success&&(await re(e,{version:2,entries:q.newEntries}),await be(e,q.worktreeOps)),await Yt(e,r),await ee(e,n,"HEAD",i,r,`rebase (pick): ${t.subject}`),{conflict:!1,stdout:"",stderr:""}}let c=await M(e,i),f=a?a.tree:null,d=K(r),u=ue(o.message),l={a:"HEAD",b:u?`${d} (${u})`:d},m=await wt(e,f,c.tree,o.tree,l),h=await U(e),[p,g,w]=await Promise.all([He(e,c.tree),f?He(e,f):Promise.resolve([]),He(e,o.tree)]),x=new Set;for(let G of g)x.add(G.path);for(let G of p)x.add(G.path);for(let G of w)x.add(G.path);let b=h.entries.filter(G=>!x.has(G.path)),y=[...m.entries,...b];y.sort((G,z)=>he(G.path,z.path)||G.stage-z.stage);let k={version:2,entries:y},C=y.filter(G=>G.stage===0),P=await ke(e,C),O=new Map(p.map(G=>[G.path,G])),E=new Map;for(let G of C){let z=O.get(G.path);(!z||z.hash!==G.hash)&&E.set(G.path,G.hash)}for(let G of m.conflicts){if(G.reason==="content"||G.reason==="add-add"){E.set(G.path,null);continue}if(G.reason==="delete-modify"){let z=m.entries.filter(R=>R.path===G.path&&R.stage>0),D=z.find(R=>R.stage===2),$=z.find(R=>R.stage===3);$&&!D&&E.set(G.path,$.hash)}}let I=await Hc(e,h,E);if(I)return await Y(e,"REBASE_HEAD",r),await ts(e,r,o.author),{conflict:!0,stdout:"",stderr:Ac(I,t),rescheduleCurrent:!0};if(await re(e,k),e.workTree){let G=await Qt(e,c.tree,m.resultTree,h);G.success&&await be(e,G.worktreeOps)}if(m.conflicts.length>0){await Y(e,"REBASE_HEAD",r),await ts(e,r,o.author),await Ue(e,"MERGE_MSG",o.message),await Ue(e,"rebase-merge/message",o.message);let G=m.messages.join(`
|
|
459
470
|
`);return{conflict:!0,stdout:G?`${G}
|
|
460
471
|
`:"",stderr:`error: could not apply ${d}... ${t.subject}
|
|
461
472
|
hint: Resolve all conflicts manually, mark them as resolved with
|
|
@@ -465,8 +476,8 @@ hint: To abort and get back to the state before "git rebase", run "git rebase --
|
|
|
465
476
|
hint: Disable this message with "git config set advice.mergeConflict false"
|
|
466
477
|
Could not apply ${d}... # ${t.subject}
|
|
467
478
|
`}}if(P===c.tree)return{conflict:!1,stdout:"",stderr:`dropping ${r} ${t.subject} -- patch contents already upstream
|
|
468
|
-
`};let
|
|
469
|
-
`;return await ie(e,"REBASE_HEAD"),await wn(e),await
|
|
479
|
+
`};let A=await Le(e,n);if(S(A))return{conflict:!0,stdout:"",stderr:A.stderr};let _=await Je(e,P,[i],o.author,A,o.message);return await ee(e,n,"HEAD",i,_,`rebase (pick): ${t.subject}`),{conflict:!1,stdout:"",stderr:""}}async function Zu(e,t,n){let r=await nt(e);if(!r)return T("no rebase in progress");let o=await X(e);if(!o)return T("no HEAD during rebase finish");r.headName!=="detached HEAD"&&(await Y(e,r.headName,o),await $e(e,"HEAD",r.headName),await tt(e),await ee(e,n,r.headName,r.origHead,o,`rebase (finish): ${r.headName} onto ${r.onto}`),await ee(e,n,"HEAD",o,o,`rebase (finish): returning to ${r.headName}`));let a=`Successfully rebased and updated ${r.headName}.
|
|
480
|
+
`;return await ie(e,"REBASE_HEAD"),await wn(e),await fo(e),{stdout:"",stderr:t.join("")+a,exitCode:0}}async function Ju(e,t){let n=await nt(e);if(!n)return T("no rebase in progress");let r=await X(e),o=n.origHead,s=await M(e,o),a=await U(e),i=await Yu(e,s.tree,a,o);if(i)return i;let c=await yt(e,s.tree,a);c.success&&(await re(e,{version:2,entries:c.newEntries}),await be(e,c.worktreeOps)),n.headName!=="detached HEAD"?(await Y(e,n.headName,o),await $e(e,"HEAD",n.headName),await tt(e)):await Yt(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 ie(e,"REBASE_HEAD"),await wn(e),await fo(e),{stdout:"",stderr:"",exitCode:0}}async function Qu(e,t){let n="";if(!await nt(e))return T("no rebase in progress");let o=await U(e);if(dt(o))return j(`error: Committing is not possible because you have unmerged files.
|
|
470
481
|
hint: Fix them up in the work tree, and then use 'git add <file>'
|
|
471
482
|
hint: as appropriate to mark resolution and make a commit.
|
|
472
483
|
fatal: Exiting because of an unresolved conflict.
|
|
@@ -483,40 +494,40 @@ In both cases, once you're done, continue with:
|
|
|
483
494
|
|
|
484
495
|
git rebase --continue
|
|
485
496
|
|
|
486
|
-
`);if(u){let m=await M(e,s),h;h=await qe(e,"rebase-merge/message")??await qe(e,"MERGE_MSG")??void 0,h||(h=m.message);let p=await Le(e,t);if(S(p))return p;let g=mt(h),w=[i],x=await F(e,"MERGE_HEAD");x&&w.push(x);let b=await Je(e,d,w,m.author,p,g);x&&(await ie(e,"MERGE_HEAD"),await et(e,"MERGE_MODE"));let y=ue(g);await ee(e,t,"HEAD",i,b,`rebase (continue): ${y}`);let k=await
|
|
487
|
-
${C}`}await ie(e,"REBASE_HEAD"),await ie(e,"CHERRY_PICK_HEAD"),await ie(e,"REVERT_HEAD"),await et(e,"MERGE_MSG"),await et(e,"rebase-merge/message")}let a=await
|
|
497
|
+
`);if(u){let m=await M(e,s),h;h=await qe(e,"rebase-merge/message")??await qe(e,"MERGE_MSG")??void 0,h||(h=m.message);let p=await Le(e,t);if(S(p))return p;let g=mt(h),w=[i],x=await F(e,"MERGE_HEAD");x&&w.push(x);let b=await Je(e,d,w,m.author,p,g);x&&(await ie(e,"MERGE_HEAD"),await et(e,"MERGE_MODE"));let y=ue(g);await ee(e,t,"HEAD",i,b,`rebase (continue): ${y}`);let k=await zu(e),C=await St(e,c.tree,d,m.author,p,!1);n=`${ut(k,b,g)}
|
|
498
|
+
${C}`}await ie(e,"REBASE_HEAD"),await ie(e,"CHERRY_PICK_HEAD"),await ie(e,"REVERT_HEAD"),await et(e,"MERGE_MSG"),await et(e,"rebase-merge/message")}let a=await Do(e,t);return n&&(a.stdout=n+a.stdout),a}async function em(e,t){if(!await nt(e))return T("no rebase in progress");let r=await X(e);if(!r)return{stdout:"",stderr:`error: could not determine HEAD revision
|
|
488
499
|
fatal: could not discard worktree changes
|
|
489
|
-
`,exitCode:128};let o=await M(e,r),s=await U(e),a=await yt(e,o.tree,s);return a.success&&(await re(e,{version:2,entries:a.newEntries}),await be(e,a.worktreeOps)),await ie(e,"REBASE_HEAD"),await ie(e,"CHERRY_PICK_HEAD"),await ie(e,"REVERT_HEAD"),await et(e,"MERGE_MSG"),await et(e,"rebase-merge/message"),
|
|
500
|
+
`,exitCode:128};let o=await M(e,r),s=await U(e),a=await yt(e,o.tree,s);return a.success&&(await re(e,{version:2,entries:a.newEntries}),await be(e,a.worktreeOps)),await ie(e,"REBASE_HEAD"),await ie(e,"CHERRY_PICK_HEAD"),await ie(e,"REVERT_HEAD"),await et(e,"MERGE_MSG"),await et(e,"rebase-merge/message"),Do(e,t)}function tm(e,t,n,r){return`${K(n)} ${e}@{${t}}: ${r}`}async function Cs(e,t,n){let r=t==="HEAD"?"HEAD":`refs/heads/${t}`;if(!await F(e,r))return{stdout:"",stderr:`fatal: ambiguous argument '${t}': unknown revision or path not in the working tree.
|
|
490
501
|
Use '--' to separate paths from revisions, like this:
|
|
491
502
|
'git <command> [<revision>...] -- [<file>...]'
|
|
492
|
-
`,exitCode:128};let s=await Me(e,r),a=[],i=n!==void 0?n:s.length,c=0;for(let d=s.length-1;d>=0&&c<i;d--){let u=s[d];if(!u)continue;let l=s.length-1-d;u.newHash!==Z&&(a.push(
|
|
503
|
+
`,exitCode:128};let s=await Me(e,r),a=[],i=n!==void 0?n:s.length,c=0;for(let d=s.length-1;d>=0&&c<i;d--){let u=s[d];if(!u)continue;let l=s.length-1-d;u.newHash!==Z&&(a.push(tm(t,l,u.newHash,u.message)),c++)}return{stdout:a.length>0?`${a.join(`
|
|
493
504
|
`)}
|
|
494
|
-
`:"",stderr:"",exitCode:0}}function
|
|
495
|
-
`,exitCode:128};let d=
|
|
505
|
+
`:"",stderr:"",exitCode:0}}function Sc(e,t){return e.command("reflog",{description:"Manage reflog information",args:[W.string().name("args").variadic().optional()],options:{maxCount:te.number().alias("n").describe("Limit the number of entries to output")},handler:async(r,o)=>{let s=await B(o.fs,o.cwd,t);if(S(s))return s;let a=s,i=r.args;if(i.length===0)return Cs(a,"HEAD",r.maxCount);let c=i[0];if(!c)return Cs(a,"HEAD",r.maxCount);if(c==="show"){let f=i[1]??"HEAD";return Cs(a,f,r.maxCount)}if(c==="exists"){let f=i[1];if(!f)return{stdout:"",stderr:`fatal: reflog exists requires a ref argument
|
|
506
|
+
`,exitCode:128};let d=H(a.gitDir,"logs",f);return{stdout:"",stderr:"",exitCode:await a.fs.exists(d)?0:1}}return Cs(a,c,r.maxCount)}})}function nm(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 Dc(e,t){let n=e.command("remote",{description:"Manage set of tracked repositories",options:{verbose:v().alias("v").describe("Show remote URLs")},handler:async(s,a)=>{let i=await B(a.fs,a.cwd,t);if(S(i))return i;let c=await ae(i),f=nm(c);if(f.length===0)return{stdout:"",stderr:"",exitCode:0};if(s.verbose){let d=[];for(let u of f){let m=c[`remote "${u}"`]?.url??"";d.push(`${u} ${m} (fetch)`),d.push(`${u} ${m} (push)`)}return{stdout:`${d.join(`
|
|
496
507
|
`)}
|
|
497
508
|
`,stderr:"",exitCode:0}}return{stdout:`${f.join(`
|
|
498
509
|
`)}
|
|
499
510
|
`,stderr:"",exitCode:0}}});n.command("add",{description:"Add a remote named <name> for the repository at <url>",args:[W.string().name("name").describe("Remote name"),W.string().name("url").describe("Remote URL")],handler:async(s,a)=>{let i=await B(a.fs,a.cwd,t);if(S(i))return i;let c=await ae(i),f=`remote "${s.name}"`;return f in c?j(`error: remote ${s.name} already exists.
|
|
500
|
-
`,3):(c[f]={url:s.url,fetch:`+refs/heads/*:refs/remotes/${s.name}/*`},await Ge(i,c),{stdout:"",stderr:"",exitCode:0})}});let r=async(s,a)=>{let i=await B(a.fs,a.cwd,t);if(S(i))return i;let c=await ae(i),f=`remote "${s.name}"`;return f in c?(delete c[f],
|
|
501
|
-
`,2)},o=[W.string().name("name").describe("Remote name")];n.command("remove",{description:"Remove the remote named <name>",args:o,handler:r}),n.command("rm",{description:"Remove the remote named <name>",args:o,handler:r}),n.command("rename",{description:"Rename the remote named <old> to <new>",args:[W.string().name("old").describe("Current remote name"),W.string().name("new").describe("New remote name")],handler:async(s,a)=>{let i=await B(a.fs,a.cwd,t);if(S(i))return i;let c=await ae(i);return
|
|
511
|
+
`,3):(c[f]={url:s.url,fetch:`+refs/heads/*:refs/remotes/${s.name}/*`},await Ge(i,c),{stdout:"",stderr:"",exitCode:0})}});let r=async(s,a)=>{let i=await B(a.fs,a.cwd,t);if(S(i))return i;let c=await ae(i),f=`remote "${s.name}"`;return f in c?(delete c[f],sm(c,s.name),await Ge(i,c),await om(i,s.name),{stdout:"",stderr:"",exitCode:0}):j(`error: No such remote: '${s.name}'
|
|
512
|
+
`,2)},o=[W.string().name("name").describe("Remote name")];n.command("remove",{description:"Remove the remote named <name>",args:o,handler:r}),n.command("rm",{description:"Remove the remote named <name>",args:o,handler:r}),n.command("rename",{description:"Rename the remote named <old> to <new>",args:[W.string().name("old").describe("Current remote name"),W.string().name("new").describe("New remote name")],handler:async(s,a)=>{let i=await B(a.fs,a.cwd,t);if(S(i))return i;let c=await ae(i);return rm(i,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,a)=>{let i=await B(a.fs,a.cwd,t);if(S(i))return i;let c=await ae(i),f=`remote "${s.name}"`;if(!(f in c))return j(`error: No such remote '${s.name}'
|
|
502
513
|
`,2);let d=c[f];return d&&(d.url=s.url),await Ge(i,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,a)=>{let i=await B(a.fs,a.cwd,t);if(S(i))return i;let c=await ae(i),f=`remote "${s.name}"`;return f in c?{stdout:`${c[f]?.url??""}
|
|
503
514
|
`,stderr:"",exitCode:0}:j(`error: No such remote '${s.name}'
|
|
504
|
-
`,2)}})}async function
|
|
505
|
-
`,2);let s=`remote "${r}"`;if(s in t)return T(`remote ${r} already exists.`);let a={...t[o]};a.fetch&&(a.fetch=a.fetch.replace(`refs/remotes/${n}/`,`refs/remotes/${r}/`)),t[s]=a,delete t[o];for(let f of Object.keys(t))f.match(/^branch "(.+)"$/)&&t[f]?.remote===n&&(t[f].remote=r);await Ge(e,t);let i=`refs/remotes/${n}`,c=await le(e,i);for(let f of c){let d=f.name.replace(i,`refs/remotes/${r}`),u=await Me(e,f.name);await Y(e,d,f.hash),await ie(e,f.name),u.length>0&&await Xt(e,d,u)}return{stdout:"",stderr:"",exitCode:0}}function
|
|
515
|
+
`,2)}})}async function rm(e,t,n,r){let o=`remote "${n}"`;if(!(o in t))return j(`error: No such remote: '${n}'
|
|
516
|
+
`,2);let s=`remote "${r}"`;if(s in t)return T(`remote ${r} already exists.`);let a={...t[o]};a.fetch&&(a.fetch=a.fetch.replace(`refs/remotes/${n}/`,`refs/remotes/${r}/`)),t[s]=a,delete t[o];for(let f of Object.keys(t))f.match(/^branch "(.+)"$/)&&t[f]?.remote===n&&(t[f].remote=r);await Ge(e,t);let i=`refs/remotes/${n}`,c=await le(e,i);for(let f of c){let d=f.name.replace(i,`refs/remotes/${r}`),u=await Me(e,f.name);await Y(e,d,f.hash),await ie(e,f.name),u.length>0&&await Xt(e,d,u)}return{stdout:"",stderr:"",exitCode:0}}function sm(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 om(e,t){let n=`refs/remotes/${t}`,r=await le(e,n);for(let o of r)await ie(e,o.name)}function jc(e,t){e.command("reset",{description:"Reset current HEAD to the specified state",args:[W.string().name("args").variadic().optional()],options:{soft:v().describe("Only move HEAD"),mixed:v().describe("Move HEAD and reset index (default)"),hard:v().describe("Move HEAD, reset index, and reset working tree")},handler:async(n,r,o)=>{let s=await B(r.fs,r.cwd,t);if(S(s))return s;let a=s,i=n.args;if([n.soft,n.mixed,n.hard].filter(Boolean).length>1)return T("--soft, --mixed, and --hard are mutually exclusive");let f=n.soft||n.mixed||n.hard,d=Ze(a,r.cwd);if(o.passthrough.length>0){let m=i.length>0?i[0]:void 0;return Mo(a,o.passthrough,d,m,t)}if(!f&&i.length>0){let m=i[0],h=await je(a,m);return i.length===1&&h?Mc(a,m,"mixed",r.env,t):h?Mo(a,i.slice(1),d,m,t):Mo(a,i,d,void 0,t)}let u=n.soft?"soft":n.hard?"hard":"mixed",l=i.length>0?i[0]:"HEAD";return Mc(a,l,u,r.env,t)}})}async function Mo(e,t,n,r,o){if(o?.hooks){let d=await o.hooks.emitPre("pre-reset",{mode:"paths",target:r??null});if(d)return{stdout:"",stderr:d.message??"",exitCode:1}}let s=null;if(r){let d=await je(e,r);if(!d)return Et(r);let u=await Re(e,d);s=(await M(e,u)).tree}else{let d=await X(e);d&&(s=(await M(e,d)).tree)}let a=await se(e,s??null),i=await U(e);if(t.some(Ve)){let d=t.map(l=>Oe(l,n)),u=new Set;for(let[l]of a)u.add(l);for(let l of i.entries)u.add(l.path);for(let l of u){if(!me(d,l))continue;let m=a.get(l);m?i=Xe(i,{path:m.path,mode:parseInt(m.mode,8),hash:m.hash,stage:0,stat:pe()}):i=Ne(i,l)}}else for(let d of t){let u=a.get(d);if(u)i=Xe(i,{path:u.path,mode:parseInt(u.mode,8),hash:u.hash,stage:0,stat:pe()});else if(i.entries.some(m=>m.path===d))i=Ne(i,d);else if(!(e.workTree&&await e.fs.exists(H(e.workTree,d))))return Et(d)}await re(e,i);let f={stdout:await Lc(e,i),stderr:"",exitCode:0};return await o?.hooks?.emitPost("post-reset",{mode:"paths",targetHash:null}),f}async function Lc(e,t){if(!e.workTree)return"";let n=new Set;for(let a of t.entries)a.stage>0&&n.add(a.path);let o=(await lt(e,t)).filter(a=>a.status==="modified"||a.status==="deleted");if(o.length===0&&n.size===0)return"";let s=["Unstaged changes after reset:"];for(let a of o){let i=a.status==="modified"?"M":"D";s.push(`${i} ${a.path}`)}for(let a of[...n].sort())s.push(`U ${a}`);return s.sort((a,i)=>{if(a==="Unstaged changes after reset:")return-1;if(i==="Unstaged changes after reset:")return 1;let c=a.slice(2),f=i.slice(2);return c<f?-1:c>f?1:0}),`${s.join(`
|
|
506
517
|
`)}
|
|
507
|
-
`}async function
|
|
508
|
-
`:"";return await o?.hooks?.emitPost("post-reset",{mode:n,targetHash:a}),{stdout:u,stderr:"",exitCode:0}}function
|
|
518
|
+
`}async function Mc(e,t,n,r,o){if(o?.hooks){let l=await o.hooks.emitPre("pre-reset",{mode:n,target:t});if(l)return{stdout:"",stderr:l.message??"",exitCode:1}}let s=await je(e,t);if(!s)return Et(t);let a=await Re(e,s),i=await M(e,a);if(n==="soft"){let l=await F(e,"MERGE_HEAD"),m=await U(e);if(l||dt(m))return T("Cannot do a soft reset in the middle of a merge.")}let c=await X(e),f=await J(e);f?.type==="symbolic"?await Y(e,f.target,a):await Y(e,"HEAD",a);let d=`reset: moving to ${t}`;if(f?.type==="symbolic"&&c!==a?await ee(e,r,f.target,c,a,d,!0):(f?.type==="symbolic"||c!==a)&&await ee(e,r,"HEAD",c,a,d),await wn(e),n==="mixed"){let l=await He(e,i.tree),m=Or(l.map(p=>({path:p.path,mode:parseInt(p.mode,8),hash:p.hash,stage:0,stat:pe()})));await re(e,m);let h=await Lc(e,m);if(h)return await o?.hooks?.emitPost("post-reset",{mode:n,targetHash:a}),{stdout:h,stderr:"",exitCode:0}}if(n==="hard"){let l=Fe(e);if(l)return l;let m=await U(e),h=await yt(e,i.tree,m);await re(e,{version:2,entries:h.newEntries}),await be(e,h.worktreeOps)}let u=n==="hard"?`HEAD is now at ${K(a)} ${ue(i.message)}
|
|
519
|
+
`:"";return await o?.hooks?.emitPost("post-reset",{mode:n,targetHash:a}),{stdout:u,stderr:"",exitCode:0}}function Gc(e,t){e.command("restore",{description:"Restore working tree files",args:[W.string().name("pathspec").variadic().optional()],options:{source:te.string().alias("s").describe("Restore from tree-ish"),staged:v().alias("S").describe("Restore the index"),worktree:v().alias("W").describe("Restore the working tree (default)"),ours:v().describe("Checkout our version for unmerged files"),theirs:v().describe("Checkout their version for unmerged files")},handler:async(n,r,o)=>{let s=await B(r.fs,r.cwd,t);if(S(s))return s;let a=s,i=[...n.pathspec??[],...o.passthrough];if(i.length===0)return T("you must specify path(s) to restore");if(n.ours&&n.theirs)return T("--ours and --theirs are incompatible");let c=!!n.staged,f=n.worktree!==void 0?!!n.worktree:!c,d=Ze(a,r.cwd);if(n.ours||n.theirs)return n.source?T("cannot specify both --source and --ours/--theirs"):c?T("cannot use --ours/--theirs with --staged"):os(a,i,d,n.theirs?3:2,{deleteOnMissing:!0});let u=null;if(n.source){let l=await ye(a,n.source,`could not resolve '${n.source}'`);if(S(l))return l;u=l.commit.tree}else if(c){let l=await X(a);l&&(u=(await M(a,l)).tree)}return c&&f?cm(a,i,d,u):c?im(a,i,d,u):u?am(a,i,d,u):ss(a,i,d)}})}async function im(e,t,n,r){let o=await se(e,r),s=await U(e);if(t.some(Ve)){let i=t.map(d=>Oe(d,n)),c=new Set;for(let[d]of o)c.add(d);for(let d of s.entries)c.add(d.path);let f=!1;for(let d of c){if(!me(i,d))continue;f=!0;let u=o.get(d);u?s=Xe(s,{path:u.path,mode:parseInt(u.mode,8),hash:u.hash,stage:0,stat:pe()}):s=Ne(s,d)}if(!f)return j(`error: pathspec '${t[0]}' did not match any file(s) known to git
|
|
509
520
|
`)}else for(let i of t){let c=o.get(i),f=s.entries.some(d=>d.path===i&&d.stage>0);if(c)s=Xe(s,{path:c.path,mode:parseInt(c.mode,8),hash:c.hash,stage:0,stat:pe()});else{if(f)return{stdout:"",stderr:`error: path '${i}' is unmerged
|
|
510
521
|
`,exitCode:1};if(s.entries.some(u=>u.path===i))s=Ne(s,i);else return j(`error: pathspec '${i}' did not match any file(s) known to git
|
|
511
|
-
`)}}return await re(e,s),{stdout:"",stderr:"",exitCode:0}}async function
|
|
522
|
+
`)}}return await re(e,s),{stdout:"",stderr:"",exitCode:0}}async function am(e,t,n,r){if(!e.workTree)return T("this operation must be run in a work tree");let o=await se(e,r),s=t.some(Ve),a=[],i=await U(e);if(s){let c=t.map(d=>Oe(d,n)),f=new Set;for(let[d]of o)f.add(d);for(let d of i.entries)f.add(d.path);for(let d of f)me(c,d)&&a.push(d);if(a.length===0)return j(`error: pathspec '${t[0]}' did not match any file(s) known to git
|
|
512
523
|
`)}else for(let c of t){let f=o.has(c);if(!f&&i.entries.some(l=>l.path===c&&l.stage!==0))return{stdout:"",stderr:`error: path '${c}' is unmerged
|
|
513
524
|
`,exitCode:1};let d=Dt(i,c);if(!f&&!d)return j(`error: pathspec '${c}' did not match any file(s) known to git
|
|
514
|
-
`);a.push(c)}for(let c of a){let f=o.get(c);if(f)await ve(e,{path:f.path,hash:f.hash,mode:f.mode});else{let d=`${e.workTree}/${c}`;await e.fs.exists(d)&&await e.fs.rm(d)}}return{stdout:"",stderr:"",exitCode:0}}async function
|
|
525
|
+
`);a.push(c)}for(let c of a){let f=o.get(c);if(f)await ve(e,{path:f.path,hash:f.hash,mode:f.mode});else{let d=`${e.workTree}/${c}`;await e.fs.exists(d)&&await e.fs.rm(d)}}return{stdout:"",stderr:"",exitCode:0}}async function cm(e,t,n,r){if(!e.workTree)return T("this operation must be run in a work tree");let o=await se(e,r),s=await U(e),a=t.some(Ve),i=[];if(a){let c=t.map(d=>Oe(d,n)),f=new Set;for(let[d]of o)f.add(d);for(let d of s.entries)f.add(d.path);for(let d of f)me(c,d)&&i.push(d);if(i.length===0)return j(`error: pathspec '${t[0]}' did not match any file(s) known to git
|
|
515
526
|
`)}else for(let c of t){if(s.entries.some(l=>l.path===c&&l.stage>0))return{stdout:"",stderr:`error: path '${c}' is unmerged
|
|
516
527
|
`,exitCode:1};let d=o.get(c),u=s.entries.some(l=>l.path===c);if(!d&&!u)return j(`error: pathspec '${c}' did not match any file(s) known to git
|
|
517
|
-
`);i.push(c)}for(let c of i){let f=o.get(c);if(f)s=Xe(s,{path:f.path,mode:parseInt(f.mode,8),hash:f.hash,stage:0,stat:pe()}),await ve(e,{path:f.path,hash:f.hash,mode:f.mode});else{s=Ne(s,c);let d=`${e.workTree}/${c}`;await e.fs.exists(d)&&await e.fs.rm(d)}}return await re(e,s),{stdout:"",stderr:"",exitCode:0}}function
|
|
518
|
-
`).join(""),stderr:"",exitCode:0};if(s&&o.length!==1)return T("Needed a single revision");for(let y of o){if(i){let C=await
|
|
519
|
-
`).join(""),stderr:"",exitCode:0}}})}function
|
|
528
|
+
`);i.push(c)}for(let c of i){let f=o.get(c);if(f)s=Xe(s,{path:f.path,mode:parseInt(f.mode,8),hash:f.hash,stage:0,stat:pe()}),await ve(e,{path:f.path,hash:f.hash,mode:f.mode});else{s=Ne(s,c);let d=`${e.workTree}/${c}`;await e.fs.exists(d)&&await e.fs.rm(d)}}return await re(e,s),{stdout:"",stderr:"",exitCode:0}}function Nc(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:v().describe("Verify that exactly one parameter is provided and resolves to an object"),short:v().describe("Abbreviate object name (default 7 chars)"),"abbrev-ref":v().describe("Output abbreviated ref name instead of object hash"),"symbolic-full-name":v().describe("Output the full symbolic ref name"),"show-toplevel":v().describe("Show the absolute path of the top-level directory"),"git-dir":v().describe("Show the path to the .git directory"),"is-inside-work-tree":v().describe("Output whether cwd is inside the work tree"),"is-bare-repository":v().describe("Output whether the repository is bare"),"show-prefix":v().describe("Show path of cwd relative to top-level directory"),"show-cdup":v().describe("Show relative path from cwd up to top-level directory")},handler:async(n,r)=>{let o=n.args.filter(y=>y!==""),s=n.verify,a=n.short,i=n["abbrev-ref"],c=n["symbolic-full-name"],f=n["show-toplevel"],d=n["git-dir"],u=n["is-inside-work-tree"],l=n["is-bare-repository"],m=n["show-prefix"],h=n["show-cdup"],p=f||d||u||l||m||h,g=await B(r.fs,r.cwd,t);if(S(g))return g;let w=g,x=[];if(f){if(!w.workTree)return T("this operation must be run in a work tree");x.push(w.workTree)}if(d&&x.push(w.gitDir),u&&x.push(w.workTree?"true":"false"),l&&x.push(w.workTree?"false":"true"),m){if(!w.workTree)return T("this operation must be run in a work tree");let y=Ke(w.workTree,r.cwd);x.push(y===""?"":`${y}/`)}if(h){if(!w.workTree)return T("this operation must be run in a work tree");let y=Ke(r.cwd,w.workTree);x.push(y===""?"":`${y}/`)}if(p&&o.length===0)return{stdout:x.map(k=>`${k}
|
|
529
|
+
`).join(""),stderr:"",exitCode:0};if(s&&o.length!==1)return T("Needed a single revision");for(let y of o){if(i){let C=await fm(w,y);if(C===null)return jo(y,s);x.push(C);continue}if(c){let C=await dm(w,y);if(C===null)return jo(y,s);x.push(C);continue}let k=await je(w,y);if(!k)return jo(y,s);x.push(a?K(k):k)}return{stdout:x.map(y=>`${y}
|
|
530
|
+
`).join(""),stderr:"",exitCode:0}}})}function jo(e,t){return t?T("Needed a single revision"):Et(e)}async function fm(e,t){if(t==="HEAD"||t==="@"){let r=await J(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 je(e,t)?t:null}async function dm(e,t){if(t==="HEAD"||t==="@"){let r=await J(e);return r?r.type==="symbolic"?r.target:"HEAD":null}if(!await je(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 F(e,o))return o}return t}function _c(e,t){e.command("revert",{description:"Revert some existing commits",args:[W.string().name("commit").describe("The commit to revert").optional()],options:{abort:v().describe("Abort the current revert operation"),continue:v().describe("Continue the revert after conflict resolution"),"no-commit":v().alias("n").describe("Apply changes without creating a commit"),"no-edit":v().describe("Do not edit the commit message"),mainline:te.number().alias("m").describe("Select the parent number for reverting merges")},handler:async(n,r)=>{let o=await B(r.fs,r.cwd,t);if(S(o))return o;let s=o;if(n.abort){if(t?.hooks){let N=await t.hooks.emitPre("pre-revert",{mode:"abort",commit:null});if(N)return{stdout:"",stderr:N.message??"",exitCode:1}}let R=await lm(s,r.env);return R.exitCode===0&&await t?.hooks?.emitPost("post-revert",{mode:"abort",commitHash:null,hadConflicts:!1}),R}if(n.continue){if(t?.hooks){let N=await t.hooks.emitPre("pre-revert",{mode:"continue",commit:null});if(N)return{stdout:"",stderr:N.message??"",exitCode:1}}let R=await um(s,r.env);return R.exitCode===0&&await t?.hooks?.emitPost("post-revert",{mode:"continue",commitHash:null,hadConflicts:!1}),R}let a=n.commit;if(!a)return T("you must specify a commit to revert");if(t?.hooks){let R=await t.hooks.emitPre("pre-revert",{mode:"revert",commit:a});if(R)return{stdout:"",stderr:R.message??"",exitCode:1}}let i=await ye(s,a);if(S(i))return i;let c=i.hash,f=i.commit,d=await Se(s);if(S(d))return d;let u=await U(s),l=Nt(u,"Reverting",`fatal: revert failed
|
|
520
531
|
`);if(l)return l;let m=await M(s,d);if(s.workTree){let R=await se(s,m.tree);if(vn(u,R))return j(`error: your local changes would be overwritten by revert.
|
|
521
532
|
hint: commit your changes or stash them to proceed.
|
|
522
533
|
fatal: revert failed
|
|
@@ -524,7 +535,7 @@ fatal: revert failed
|
|
|
524
535
|
fatal: revert failed
|
|
525
536
|
`,128);if(h<1||h>f.parents.length)return j(`error: commit ${c} does not have parent ${h}
|
|
526
537
|
fatal: revert failed
|
|
527
|
-
`,128);let R=f.parents[h-1];p=(await M(s,R)).tree}else if(f.parents.length===0)p=await ke(s,[]);else{let R=f.parents[0];p=(await M(s,R)).tree}let g=K(c),w=ue(f.message),x=
|
|
538
|
+
`,128);let R=f.parents[h-1];p=(await M(s,R)).tree}else if(f.parents.length===0)p=await ke(s,[]);else{let R=f.parents[0];p=(await M(s,R)).tree}let g=K(c),w=ue(f.message),x=Fc(f,c,h),b={a:"HEAD",b:w?`parent of ${g} (${w})`:`parent of ${g}`},y=await wt(s,f.tree,m.tree,p,b);if(y.conflicts.length===0&&y.resultTree===m.tree){let R=y.messages.length>0?`${y.messages.join(`
|
|
528
539
|
`)}
|
|
529
540
|
`:"",N=await Be(s,{fromCommit:!0}),q=await F(s,"CHERRY_PICK_HEAD");return{stdout:`${R}${N}`,stderr:q?`The previous cherry-pick is now empty, possibly due to conflict resolution.
|
|
530
541
|
If you wish to commit it anyway, use:
|
|
@@ -542,27 +553,27 @@ hint: You can instead skip this commit with "git revert --skip".
|
|
|
542
553
|
hint: To abort and get back to the state before "git revert",
|
|
543
554
|
hint: run "git revert --abort".
|
|
544
555
|
hint: Disable this message with "git config set advice.mergeConflict false"
|
|
545
|
-
`,exitCode:1}}if(n["no-commit"])return await Y(s,"REVERT_HEAD",c),await Ue(s,"MERGE_MSG",x),{stdout:"",stderr:"",exitCode:0};let C=k.mergedTreeHash,P=await Ht(s,r.env);if(S(P))return P;let O=await Le(s,r.env);if(S(O))return O;let E=await Je(s,C,[d],P,O,x);await pt(s),await kt(s);let I=await J(s),
|
|
556
|
+
`,exitCode:1}}if(n["no-commit"])return await Y(s,"REVERT_HEAD",c),await Ue(s,"MERGE_MSG",x),{stdout:"",stderr:"",exitCode:0};let C=k.mergedTreeHash,P=await Ht(s,r.env);if(S(P))return P;let O=await Le(s,r.env);if(S(O))return O;let E=await Je(s,C,[d],P,O,x);await pt(s),await kt(s);let I=await J(s),A=ue(x),_=I?.type==="symbolic"?I.target:"HEAD";await ee(s,r.env,_,d,E,`revert: ${A}`,I?.type==="symbolic");let G=I?.type==="symbolic"?de(I.target):"detached HEAD",z=await St(s,m.tree,C,P,O,P.timestamp!==O.timestamp||P.timezone!==O.timezone),D=ut(G,E,x),$=y.messages.length>0?`${y.messages.join(`
|
|
546
557
|
`)}
|
|
547
558
|
`:"";return await t?.hooks?.emitPost("post-revert",{mode:"revert",commitHash:E,hadConflicts:!1}),{stdout:`${$}${D}
|
|
548
|
-
${z}`,stderr:"",exitCode:0}}})}async function
|
|
559
|
+
${z}`,stderr:"",exitCode:0}}})}async function lm(e,t){return await F(e,"REVERT_HEAD")?en(e,t,{operationRef:"REVERT_HEAD",noOpError:j(`error: no cherry-pick or revert in progress
|
|
549
560
|
fatal: revert failed
|
|
550
561
|
`,128),operationName:"revert",clearState:pt,origHeadAsTargetRev:!0}):await F(e,"CHERRY_PICK_HEAD")?en(e,t,{operationRef:"CHERRY_PICK_HEAD",noOpError:j(`error: no cherry-pick or revert in progress
|
|
551
562
|
fatal: revert failed
|
|
552
563
|
`,128),operationName:"revert",clearState:kt,origHeadAsTargetRev:!0}):j(`error: no cherry-pick or revert in progress
|
|
553
564
|
fatal: revert failed
|
|
554
|
-
`,128)}async function
|
|
565
|
+
`,128)}async function um(e,t){let n=await F(e,"REVERT_HEAD");if(!n)return j(`error: no cherry-pick or revert in progress
|
|
555
566
|
fatal: revert failed
|
|
556
|
-
`,128);let r=await U(e),o=Nt(r,"Committing");if(o)return o;let s=await qe(e,"MERGE_MSG");if(!s){let y=await M(e,n);s=
|
|
557
|
-
${x}`,stderr:"",exitCode:0}}function
|
|
567
|
+
`,128);let r=await U(e),o=Nt(r,"Committing");if(o)return o;let s=await qe(e,"MERGE_MSG");if(!s){let y=await M(e,n);s=Fc(y,n)}let a=xe(r),i=await ke(e,a),c=await Se(e);if(S(c))return c;let f=await M(e,c),d=await Ht(e,t);if(S(d))return d;let u=await Le(e,t);if(S(u))return u;let l=mt(s),m=await Je(e,i,[c],d,u,l);await pt(e),await kt(e);let h=await J(e),p=ue(l),g=h?.type==="symbolic"?h.target:"HEAD";await ee(e,t,g,c,m,`commit: ${p}`,h?.type==="symbolic");let w=h?.type==="symbolic"?de(h.target):"detached HEAD",x=await St(e,f.tree,i,d,u,d.timestamp!==u.timestamp||d.timezone!==u.timezone);return{stdout:`${ut(w,m,s)}
|
|
568
|
+
${x}`,stderr:"",exitCode:0}}function Fc(e,t,n){let r=ue(e.message),o='Revert "',i=`${r.startsWith(o)&&r.endsWith('"')?`Reapply "${r.slice(o.length,-1)}"`:`Revert "${r}"`}
|
|
558
569
|
|
|
559
570
|
This reverts commit ${t}`;if(n!==void 0&&e.parents.length>1&&n>=1){let c=e.parents[n===1?1:0]??e.parents[0];i+=`, reversing
|
|
560
571
|
changes made to ${c}`}return i+=`.
|
|
561
|
-
`,i}function
|
|
572
|
+
`,i}function Uc(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:v().describe("Only remove from the index"),recursive:v().alias("r").describe("Allow recursive removal when a directory name is given"),force:v().alias("f").describe("Override the up-to-date check"),dryRun:v().alias("n").describe("Don't actually remove any file(s)")},handler:async(n,r)=>{let o=await B(r.fs,r.cwd,t);if(S(o))return o;let s=o,a=Fe(s);if(a)return a;let i=s.workTree,c=n.paths;if(c.length===0)return j("usage: git rm [--cached] [-f] [-r] <file>...");let f=n.cached,d=n.recursive,u=n.force;if(t?.hooks){let w=await t.hooks.emitPre("pre-rm",{paths:c,cached:f,recursive:d,force:u});if(w)return{stdout:"",stderr:w.message??"",exitCode:1}}let l=await U(s),m=[],h=Ze(s,r.cwd);for(let w of c){if(Ve(w)){let k=[Oe(w,h)],C=l.entries.filter(P=>me(k,P.path));if(C.length===0)return T(`pathspec '${w}' did not match any files`);for(let P of C)m.push(P.path);continue}let x=ct(r.cwd,w),b=Ke(i,x);if((b==="."||b==="")&&(b=""),b.startsWith(".."))return T(`'${w}' is outside repository at '${i}'`);if(await r.fs.exists(x)&&!(await ze(r.fs,x)).isSymbolicLink&&(await ze(r.fs,x)).isDirectory){if(!d)return T(`not removing '${b}' recursively without -r`);let k=b===""?"":`${b}/`,C=l.entries.filter(P=>k===""||P.path.startsWith(k));if(C.length===0)return T(`pathspec '${w}' did not match any files`);for(let P of C)m.push(P.path)}else{if(!l.entries.some(C=>C.path===b))return T(`pathspec '${w}' did not match any files`);m.push(b)}}if(!u){let w=await mm(s,l,m,f);if(w)return w}if(n.dryRun){let w=m.map(b=>`rm '${b}'`);return{stdout:w.length>0?`${w.join(`
|
|
562
573
|
`)}
|
|
563
|
-
`:"",stderr:"",exitCode:0}}let p=[];for(let w of m){if(l=Ne(l,w),!f){let x=
|
|
574
|
+
`:"",stderr:"",exitCode:0}}let p=[];for(let w of m){if(l=Ne(l,w),!f){let x=H(i,w);await ze(r.fs,x).then(()=>!0).catch(()=>!1)&&await r.fs.rm(x)}p.push(`rm '${w}'`)}await re(s,l);let g=p.length>0?`${p.join(`
|
|
564
575
|
`)}
|
|
565
|
-
`:"";return await t?.hooks?.emitPost("post-rm",{removedPaths:m,cached:f}),{stdout:g,stderr:"",exitCode:0}}})}async function
|
|
576
|
+
`:"";return await t?.hooks?.emitPost("post-rm",{removedPaths:m,cached:f}),{stdout:g,stderr:"",exitCode:0}}})}async function mm(e,t,n,r){let o=await X(e),s=new Map;if(o){let f=await M(e,o),d=await He(e,f.tree);for(let u of d)s.set(u.path,u.hash)}let a=[],i=[],c=[];for(let f of n){let d=t.entries.find(h=>h.path===f&&h.stage===0);if(!d)continue;let l=s.get(f)!==d.hash,m=!1;if(e.workTree){let h=H(e.workTree,f),p=!1;try{await ze(e.fs,h),p=!0}catch{p=!1}p&&(m=await Zt(e.fs,h)!==d.hash)}l&&m?a.push(f):l&&!r?i.push(f):m&&!r&&c.push(f)}if(a.length>0){let f=a.map(u=>` ${u}`).join(`
|
|
566
577
|
`),d=a.length===1?"the following file has":"the following files have";return j(`error: ${d} staged content different from both the
|
|
567
578
|
file and the HEAD:
|
|
568
579
|
${f}
|
|
@@ -575,27 +586,27 @@ ${f}
|
|
|
575
586
|
`),d=c.length===1?"the following file has":"the following files have";return j(`error: ${d} local modifications:
|
|
576
587
|
${f}
|
|
577
588
|
(use --cached to keep the file, or -f to force removal)
|
|
578
|
-
`)}return null}var
|
|
579
|
-
`))r.push(` ${s}`);if(n.parents.length<=1){let s=n.parents.length===1?(await M(e,n.parents[0])).tree:null,a=await Ae(e,s,n.tree),{remaining:i,renames:c}=await Ye(e,a),f=await
|
|
589
|
+
`)}return null}var Lo=new TextDecoder;function Bc(e,t){e.command("show",{description:"Show various types of objects",args:[W.string().name("object").variadic().optional()],handler:async(n,r)=>{let o=await B(r.fs,r.cwd,t);if(S(o))return o;let s=o,i=n.object[0]??"HEAD",c=Ti(i);if(c)return hm(s,c.rev,c.path);if(i==="HEAD"){let u=await Se(s);if(S(u))return u}let f=await An(s,i,`bad object '${i}'`);if(S(f))return f;let d=await ce(s,f);switch(d.type){case"commit":{let u=await M(s,f);return{stdout:await Wc(s,f,u),stderr:"",exitCode:0}}case"tag":{let u=await xi(s,f);return{stdout:await pm(s,u),stderr:"",exitCode:0}}case"tree":{let u=Jt(d.content);return{stdout:qc(u),stderr:"",exitCode:0}}case"blob":return{stdout:Lo.decode(d.content),stderr:"",exitCode:0}}}})}async function hm(e,t,n){let r=await ye(e,t);if(S(r))return r;let o=r.commit.tree,s=n.replace(/^\//,""),i=(await se(e,o)).get(s);if(!i){let f=`path '${s}' does not exist in '${t}'`;if(e.workTree){let d=H(e.workTree,s);await e.fs.exists(d)&&(f=`path '${s}' exists on disk, but not in '${t}'`)}return T(f)}let c=await ce(e,i.hash);if(c.type==="blob")return{stdout:Lo.decode(c.content),stderr:"",exitCode:0};if(c.type==="tree"){let f=Jt(c.content);return{stdout:qc(f),stderr:"",exitCode:0}}return{stdout:Lo.decode(c.content),stderr:"",exitCode:0}}async function Wc(e,t,n){let r=[];if(r.push(`commit ${t}`),n.parents.length>=2){let s=n.parents.map(a=>K(a)).join(" ");r.push(`Merge: ${s}`)}r.push(`Author: ${n.author.name} <${n.author.email}>`),r.push(`Date: ${vt(n.author.timestamp,n.author.timezone)}`),r.push("");let o=n.message.replace(/\n$/,"");for(let s of o.split(`
|
|
590
|
+
`))r.push(` ${s}`);if(n.parents.length<=1){let s=n.parents.length===1?(await M(e,n.parents[0])).tree:null,a=await Ae(e,s,n.tree),{remaining:i,renames:c}=await Ye(e,a),f=await bm(e,i,c);f&&(r.push(""),r.push(f.replace(/\n$/,"")))}else{let s=await ym(e,n);s?(r.push(""),r.push(s.replace(/\n$/,""))):r.push("")}return`${r.join(`
|
|
580
591
|
`)}
|
|
581
|
-
`}async function
|
|
582
|
-
`))n.push(` ${o}`);if(t.objectType==="commit"){let o=await M(e,t.object),s=await
|
|
592
|
+
`}async function pm(e,t){let n=[];n.push(`tag ${t.name}`),n.push(`Tagger: ${t.tagger.name} <${t.tagger.email}>`),n.push(`Date: ${vt(t.tagger.timestamp,t.tagger.timezone)}`),n.push("");let r=t.message.replace(/\n$/,"");for(let o of r.split(`
|
|
593
|
+
`))n.push(` ${o}`);if(t.objectType==="commit"){let o=await M(e,t.object),s=await Wc(e,t.object,o);n.push(""),n.push(s.replace(/\n$/,""))}return`${n.join(`
|
|
583
594
|
`)}
|
|
584
|
-
`}function
|
|
595
|
+
`}function qc(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(`
|
|
585
596
|
`)}
|
|
586
|
-
`:""}async function
|
|
587
|
-
`,C=$t({type:"commit",tree:f,parents:[s],author:p,committer:g,message:k}),P=await we(e,"commit",C),O=await se(e,a.tree),E=[],I=new Set;for(let L of l){let V=u.get(L),oe=O.get(L);if(!V&&!oe)continue;let Q=
|
|
588
|
-
`,Q=$t({type:"commit",tree:V,parents:[],author:p,committer:g,message:oe});_=await we(e,"commit",Q)}let G=n?`On ${x}: ${n}`:`WIP on ${x}: ${b} ${y}`,z=[s,P];_&&z.push(_);let D=$t({type:"commit",tree:
|
|
597
|
+
`:""}async function gm(e,t){let n=t.oldHash?await fe(e,t.oldHash):"",r=t.newHash?await fe(e,t.newHash):"";return At({path:t.path,oldContent:n,newContent:r,oldMode:t.oldMode,newMode:t.newMode,oldHash:t.oldHash,newHash:t.newHash})}async function wm(e,t){let n=t.oldHash?await fe(e,t.oldHash):"",r=t.newHash?await fe(e,t.newHash):"";return At({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 bm(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,a)=>{let i=s.type==="diff"?s.entry.path:s.entry.newPath,c=a.type==="diff"?a.entry.path:a.entry.newPath;return i<c?-1:i>c?1:0});let o="";for(let s of r)s.type==="rename"?o+=await wm(e,s.entry):o+=await gm(e,s.entry);return o}async function ym(e,t){if(t.parents.length<2)return"";let n=await Promise.all(t.parents.map(async i=>{let c=await M(e,i);return se(e,c.tree)})),r=await se(e,t.tree),o=new Set;for(let i of n)for(let c of i.keys())o.add(c);for(let i of r.keys())o.add(i);let s=[];for(let i of o){let f=r.get(i)?.hash??null;n.every(u=>(u.get(i)?.hash??null)!==f)&&s.push(i)}if(s.sort(),s.length===0)return"";let a="";for(let i of s)a+=await Em(e,i,n,r);return a}async function Em(e,t,n,r){let o=r.get(t),s=n.map(l=>l.get(t)??null),a=o?.hash??null,i=o?.mode??null,c=s.map(l=>l?.hash??null),f=s.map(l=>l?.mode??null),d=await Promise.all(c.map(async l=>l?await fe(e,l):"")),u=a?await fe(e,a):"";return ps({path:t,parentHashes:c,parentModes:f,parentContents:d,resultHash:a,resultMode:i,resultContent:u})}var Ct="refs/stash";function No(e,t){return he(e.replaceAll("/","\0"),t.replaceAll("/","\0"))}async function Kc(e){let t=await Me(e,Ct),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 Un(e,t){let n=await Me(e,Ct);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 zc(e,t,n,r){if(!e.workTree)throw new Error("Cannot stash in a bare repository");let o=e.workTree,s=await X(e);if(!s)return null;let a=await M(e,s),i=await U(e),c=xe(i),f=await ke(e,c),d=await Ae(e,a.tree,f),u=new Map(c.map(L=>[L.path,L])),l=await _e(e,o,"",{skipIgnore:!0}),m=!1;for(let L of l){let V=u.get(L);if(!V)continue;let oe=H(o,L),Q=await e.fs.readFileBuffer(oe);if(await st("blob",Q)!==V.hash){m=!0;break}}if(!m)for(let[L]of u){let V=H(o,L);if(!await e.fs.exists(V)){m=!0;break}}let h=[];if(r?.includeUntracked){let L=await _e(e,o,"");for(let V of L)u.has(V)||h.push(V)}if(d.length===0&&!m&&h.length===0)return null;let p=await Cr(e,t),g=await Kn(e,t),w=await J(e),x=w?.type==="symbolic"?de(w.target):"(no branch)",b=K(s),y=ue(a.message),k=`index on ${x}: ${b} ${y}
|
|
598
|
+
`,C=$t({type:"commit",tree:f,parents:[s],author:p,committer:g,message:k}),P=await we(e,"commit",C),O=await se(e,a.tree),E=[],I=new Set;for(let L of l){let V=u.get(L),oe=O.get(L);if(!V&&!oe)continue;let Q=H(o,L),ge=await e.fs.readFileBuffer(Q),De=await we(e,"blob",ge),dn=V?V.mode:parseInt(oe?.mode??"100644",8);E.push({path:L,mode:dn,hash:De,stage:0,stat:pe()}),I.add(L)}for(let[L,V]of u)I.has(L)||O.has(L)||E.push({path:L,mode:V.mode,hash:V.hash,stage:0,stat:pe()});let A=await ke(e,E),_=null;if(r?.includeUntracked){let L=[];for(let ge of h){let De=H(o,ge),dn=await e.fs.readFileBuffer(De),Ie=await we(e,"blob",dn);L.push({path:ge,mode:33188,hash:Ie,stage:0,stat:pe()})}let V=await ke(e,L),oe=`untracked files on ${x}: ${b} ${y}
|
|
599
|
+
`,Q=$t({type:"commit",tree:V,parents:[],author:p,committer:g,message:oe});_=await we(e,"commit",Q)}let G=n?`On ${x}: ${n}`:`WIP on ${x}: ${b} ${y}`,z=[s,P];_&&z.push(_);let D=$t({type:"commit",tree:A,parents:z,author:p,committer:g,message:G}),$=await we(e,"commit",D),R=await Un(e,0)??Z;await Te(e,Ct,{oldHash:R,newHash:$,name:g.name,email:g.email,timestamp:g.timestamp,tz:g.timezone,message:G.trimEnd()}),await Y(e,Ct,$);let N=await yt(e,a.tree,i);await re(e,{version:2,entries:N.newEntries}),await be(e,N.worktreeOps),(await J(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 ie(e,L);for(let L of["MERGE_MSG","MERGE_MODE"]){let V=H(e.gitDir,L);await e.fs.exists(V)&&await e.fs.rm(V)}if(h.length>0)for(let L of h){if(O.has(L))continue;let V=H(o,L);await e.fs.exists(V)&&(await e.fs.rm(V),await pn(e.fs,Pt(V),o))}return $}async function Go(e,t){let n=e.workTree,r=await M(e,t),o=await He(e,r.tree),s=[];for(let a of o){let i=H(n,a.path);await e.fs.exists(i)?s.push(a.path):await ve(e,a)}return s.length>0?(s.sort(No),{ok:!1,stdout:"",stderr:`${s.map(a=>`${a} already exists, no checkout`).join(`
|
|
589
600
|
`)}
|
|
590
601
|
error: could not restore untracked files from stash
|
|
591
|
-
`,exitCode:1}):{ok:!0,hasConflicts:!1,messages:[]}}async function
|
|
592
|
-
`,exitCode:128};let n=await
|
|
602
|
+
`,exitCode:1}):{ok:!0,hasConflicts:!1,messages:[]}}async function _o(e,t=0){if(!e.workTree)return{ok:!1,stdout:"",stderr:`fatal: this operation must be run in a work tree
|
|
603
|
+
`,exitCode:128};let n=await Un(e,t);if(!n)return{ok:!1,stdout:"",stderr:`error: stash@{${t}} is not a valid reference
|
|
593
604
|
`,exitCode:1};if(!await X(e))return{ok:!1,stdout:"",stderr:`error: your current branch does not have any commits yet
|
|
594
605
|
`,exitCode:1};let o=await U(e),s=Rt(o).sort();if(s.length>0)return{ok:!1,stdout:`${s.map(O=>`${O}: needs merge`).join(`
|
|
595
606
|
`)}
|
|
596
607
|
`,stderr:`error: could not write index
|
|
597
608
|
`,exitCode:1};let a=await M(e,n),i=a.parents[0];if(!i)return{ok:!1,stdout:"",stderr:`error: invalid stash commit (no parent)
|
|
598
|
-
`,exitCode:1};let c=await M(e,i),f=a.parents[2],d=xe(o),u=await ke(e,d),l={a:"Updated upstream",b:"Stashed changes"};if(c.tree===a.tree){if(f){let P=await
|
|
609
|
+
`,exitCode:1};let c=await M(e,i),f=a.parents[2],d=xe(o),u=await ke(e,d),l={a:"Updated upstream",b:"Stashed changes"};if(c.tree===a.tree){if(f){let P=await Go(e,f);if(!P.ok)return{...P,messages:["Already up to date."]}}return{ok:!0,hasConflicts:!1,messages:["Already up to date."]}}let m=await wt(e,c.tree,u,a.tree,l),h=await se(e,u),p=await se(e,m.resultTree),g=[];for(let[P,O]of p){let E=h.get(P);(!E||E.hash!==O.hash)&&g.push({path:P,type:"checkout",hash:O.hash,mode:parseInt(O.mode,8)})}for(let[P]of h)p.has(P)||g.push({path:P,type:"delete"});let w=new Map(d.map(P=>[P.path,P])),x=[],b=[];for(let P of g){let O=w.get(P.path),E=H(e.workTree,P.path);if(O){if(!await e.fs.exists(E))continue;let I=await e.fs.readFileBuffer(E);await st("blob",I)!==O.hash&&x.push(P.path)}else P.type==="checkout"&&await e.fs.exists(E)&&b.push(P.path)}if(x.length>0||b.length>0){x.sort(No),b.sort(No);let P="";if(x.length>0&&(P+=`error: Your local changes to the following files would be overwritten by merge:
|
|
599
610
|
${x.map(O=>` ${O}`).join(`
|
|
600
611
|
`)}
|
|
601
612
|
Please commit your changes or stash them before you merge.
|
|
@@ -604,43 +615,43 @@ ${b.map(O=>` ${O}`).join(`
|
|
|
604
615
|
`)}
|
|
605
616
|
Please move or remove them before you merge.
|
|
606
617
|
`),P+=`Aborting
|
|
607
|
-
`,f){let O=await
|
|
618
|
+
`,f){let O=await Go(e,f);O.ok||(P+=O.stderr)}return{ok:!1,stdout:"",stderr:P,exitCode:1}}await be(e,g);let y=new Set(m.conflicts.map(P=>P.path)),k=new Set;for(let P of m.entries)P.stage>0&&k.add(P.path);let C=y.size>0;if(C){let P=[];for(let[O,E]of p){if(y.has(O)||k.has(O))continue;let I=w.get(O);P.push({path:O,mode:parseInt(E.mode,8),hash:E.hash,stage:0,stat:I?.stat??pe()})}for(let O of m.entries)O.stage>0&&P.push(O);P.sort((O,E)=>he(O.path,E.path)||O.stage-E.stage),await re(e,{version:2,entries:P})}else{let P=[...o.entries],O=new Set(P.map(E=>E.path));for(let[E,I]of p)h.has(E)||O.has(E)||P.push({path:E,mode:parseInt(I.mode,8),hash:I.hash,stage:0,stat:pe()});P.sort((E,I)=>he(E.path,I.path)||E.stage-I.stage),await re(e,{version:2,entries:P})}if(f){let P=await Go(e,f);if(!P.ok)return{...P,messages:m.messages}}return{ok:!0,hasConflicts:C,messages:m.messages}}async function Fo(e,t=0){let n=await Me(e,Ct);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 ie(e,Ct),await Jn(e,Ct);else{await Xt(e,Ct,n);let o=n[n.length-1];o&&await Y(e,Ct,o.newHash)}return null}async function Vc(e){await ie(e,Ct),await Jn(e,Ct)}function Ps(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 xm(e,t){let n=t.oldHash?await fe(e,t.oldHash):"",r=t.newHash?await fe(e,t.newHash):"";return At({path:t.path,oldContent:n,newContent:r,oldMode:t.oldMode,newMode:t.newMode})}async function cn(e,t,n){return e?.hooks?e.hooks.emitPre("pre-stash",{action:t,ref:n}):null}async function fn(e,t,n){await e?.hooks?.emitPost("post-stash",{action:t,ok:n})}function Xc(e,t){let n=e.command("stash",{description:"Stash the changes in a dirty working directory away",options:{message:te.string().alias("m").describe("Stash message"),"include-untracked":v().alias("u").describe("Also stash untracked files")},transformArgs:r=>{if(r[0]!=="save")return r;let o=r.slice(1),s=[],a=[];for(let i of o)i.startsWith("-")?s.push(i):a.push(i);return a.length>0?[...s,"-m",a.join(" ")]:s},handler:async(r,o)=>{let s=await B(o.fs,o.cwd,t);if(S(s))return s;let a=await cn(t,"push",null);if(a)return{stdout:"",stderr:a.message??"",exitCode:1};let i=await Yc(s,o.env,r.message,r["include-untracked"]);return await fn(t,"push",i.exitCode===0),i}});n.command("push",{description:"Save your local modifications to a new stash entry",options:{message:te.string().alias("m").describe("Stash message"),"include-untracked":v().alias("u").describe("Also stash untracked files")},handler:async(r,o)=>{let s=await B(o.fs,o.cwd,t);if(S(s))return s;let a=await cn(t,"push",null);if(a)return{stdout:"",stderr:a.message??"",exitCode:1};let i=await Yc(s,o.env,r.message,r["include-untracked"]);return await fn(t,"push",i.exitCode===0),i}}),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()],handler:async(r,o)=>{let s=await B(o.fs,o.cwd,t);if(S(s))return s;let a=await cn(t,"pop",r.stash??null);if(a)return{stdout:"",stderr:a.message??"",exitCode:1};let i=await km(s,r.stash);return await fn(t,"pop",i.exitCode===0),i}}),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()],handler:async(r,o)=>{let s=await B(o.fs,o.cwd,t);if(S(s))return s;let a=await cn(t,"apply",r.stash??null);if(a)return{stdout:"",stderr:a.message??"",exitCode:1};let i=await Cm(s,r.stash);return await fn(t,"apply",i.exitCode===0),i}}),n.command("list",{description:"List the stash entries that you currently have",handler:async(r,o)=>{let s=await B(o.fs,o.cwd,t);if(S(s))return s;let a=await cn(t,"list",null);if(a)return{stdout:"",stderr:a.message??"",exitCode:1};let i=await Pm(s);return await fn(t,"list",i.exitCode===0),i}}),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()],handler:async(r,o)=>{let s=await B(o.fs,o.cwd,t);if(S(s))return s;let a=await cn(t,"drop",r.stash??null);if(a)return{stdout:"",stderr:a.message??"",exitCode:1};let i=await Om(s,r.stash);return await fn(t,"drop",i.exitCode===0),i}}),n.command("show",{description:"Show the changes recorded in a stash entry as a diff",args:[W.string().name("stash").describe("Stash reference (e.g. stash@{0})").optional()],handler:async(r,o)=>{let s=await B(o.fs,o.cwd,t);if(S(s))return s;let a=await cn(t,"show",r.stash??null);if(a)return{stdout:"",stderr:a.message??"",exitCode:1};let i=await Rm(s,r.stash);return await fn(t,"show",i.exitCode===0),i}}),n.command("clear",{description:"Remove all the stash entries",handler:async(r,o)=>{let s=await B(o.fs,o.cwd,t);if(S(s))return s;let a=await cn(t,"clear",null);if(a)return{stdout:"",stderr:a.message??"",exitCode:1};let i=await Im(s);return await fn(t,"clear",i.exitCode===0),i}})}async function Yc(e,t,n,r){if(!await X(e))return j(`You do not have the initial commit yet
|
|
608
619
|
`);let s=await U(e),a=Rt(s).sort();if(a.length>0)return{stdout:`${a.map(d=>`${d}: needs merge`).join(`
|
|
609
620
|
`)}
|
|
610
621
|
`,stderr:`error: could not write index
|
|
611
|
-
`,exitCode:1};let i;try{i=await
|
|
622
|
+
`,exitCode:1};let i;try{i=await zc(e,t,n,{includeUntracked:r})}catch(d){return T(d.message)}return i?{stdout:`Saved working directory and index state ${(await M(e,i)).message.trim()}
|
|
612
623
|
`,stderr:"",exitCode:0}:{stdout:`No local changes to save
|
|
613
|
-
`,stderr:"",exitCode:0}}async function
|
|
624
|
+
`,stderr:"",exitCode:0}}async function km(e,t){let n=Ps(t);if(n<0)return j(`error: '${t}' is not a valid stash reference`);let r=await Un(e,n);if(!r)return j(`error: stash@{${n}} is not a valid reference`);let o=await _o(e,n);if(!o.ok){let f=o.messages?.length?`${o.messages.join(`
|
|
614
625
|
`)}
|
|
615
626
|
`:"";if(o.stdout)return{stdout:`${f}${o.stdout}The stash entry is kept in case you need it again.
|
|
616
627
|
`,stderr:o.stderr,exitCode:o.exitCode};let d=await Be(e);return{stdout:`${f}${d}The stash entry is kept in case you need it again.
|
|
617
628
|
`,stderr:o.stderr,exitCode:o.exitCode}}if(o.hasConflicts){let f=o.messages.length>0?`${o.messages.join(`
|
|
618
629
|
`)}
|
|
619
630
|
`:"",d=await Be(e);return{stdout:`${f}${d}The stash entry is kept in case you need it again.
|
|
620
|
-
`,stderr:"",exitCode:1}}let s=await
|
|
631
|
+
`,stderr:"",exitCode:1}}let s=await Fo(e,n);if(s)return j(s);let a=o.messages.length>0?`${o.messages.join(`
|
|
621
632
|
`)}
|
|
622
633
|
`:"",i=t?`stash@{${n}}`:`refs/stash@{${n}}`,c=await Be(e);return{stdout:`${a}${c}Dropped ${i} (${r})
|
|
623
|
-
`,stderr:"",exitCode:0}}async function
|
|
634
|
+
`,stderr:"",exitCode:0}}async function Cm(e,t){let n=Ps(t);if(n<0)return j(`error: '${t}' is not a valid stash reference`);let r=await _o(e,n);if(!r.ok){let i=r.messages?.length?`${r.messages.join(`
|
|
624
635
|
`)}
|
|
625
636
|
`:"",c=r.stdout;return c||(c=await Be(e)),{stdout:`${i}${c}`,stderr:r.stderr,exitCode:r.exitCode}}let o=r.messages.length>0?`${r.messages.join(`
|
|
626
637
|
`)}
|
|
627
|
-
`:"",s=await Be(e),a=r.hasConflicts?1:0;return{stdout:`${o}${s}`,stderr:"",exitCode:a}}async function
|
|
638
|
+
`:"",s=await Be(e),a=r.hasConflicts?1:0;return{stdout:`${o}${s}`,stderr:"",exitCode:a}}async function Pm(e){let t=await Kc(e);return t.length===0?{stdout:"",stderr:"",exitCode:0}:{stdout:`${t.map(r=>`stash@{${r.index}}: ${r.message}`).join(`
|
|
628
639
|
`)}
|
|
629
|
-
`,stderr:"",exitCode:0}}async function
|
|
630
|
-
`,stderr:"",exitCode:0}}async function
|
|
640
|
+
`,stderr:"",exitCode:0}}async function Om(e,t){let n=Ps(t);if(n<0)return j(`error: '${t}' is not a valid stash reference`);let r=await Un(e,n);if(!r)return j(`error: stash@{${n}} is not a valid reference`);let o=await Fo(e,n);return o?j(o):{stdout:`Dropped ${t?`stash@{${n}}`:`refs/stash@{${n}}`} (${r})
|
|
641
|
+
`,stderr:"",exitCode:0}}async function Rm(e,t){let n=Ps(t);if(n<0)return j(`error: '${t}' is not a valid stash reference`);let r=await Un(e,n);if(!r)return j(`error: stash@{${n}} is not a valid reference`);let o=await M(e,r),s=o.parents[0];if(!s)return j("error: invalid stash commit (no parent)");let a=await M(e,s),i=await Ae(e,a.tree,o.tree),c="";for(let f of i)c+=await xm(e,f);return{stdout:c,stderr:"",exitCode:0}}async function Im(e){return await Vc(e),{stdout:"",stderr:"",exitCode:0}}function Zc(e,t){e.command("status",{description:"Show the working tree status",options:{short:v().alias("s").describe("Give the output in the short-format"),porcelain:v().describe("Give the output in a machine-parseable format"),branch:v().alias("b").describe("Show the branch in short-format output")},handler:async(n,r)=>{let o=await B(r.fs,r.cwd,t);if(S(o))return o;let s=o;if(!n.short&&!n.porcelain)return{stdout:await Be(s),stderr:"",exitCode:0};let a=await J(s),i=await X(s),c;a&&a.type==="symbolic"?c=de(a.target):c="HEAD detached";let f=await U(s),d=uo(f),u=await lo(s,i,f,d),l=await lt(s,f),m=[],h=[];for(let x of l)x.status==="untracked"?h.push(x.path):m.push({path:x.path,status:x.status});m.sort((x,b)=>he(x.path,b.path));let p=new Set(f.entries.map(x=>x.path)),g=mo(h,p);return{stdout:Am(c,u,m,d,g,n.branch),stderr:"",exitCode:0}}})}var $m={"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 Tm(e){switch(e){case"new file":return"A";case"modified":return"M";case"deleted":return"D";case"renamed":return"R";default:return" "}}function Hm(e){switch(e){case"modified":return"M";case"deleted":return"D";default:return" "}}function Am(e,t,n,r,o,s){let a=[];s&&(e==="HEAD detached"?a.push("## HEAD (no branch)"):a.push(`## ${e}`));let i=new Map(r.map(l=>[l.path,l])),c=new Map(t.map(l=>[l.path,l])),f=new Map(n.map(l=>[l.path,l])),d=new Set;for(let l of r)d.add(l.path);for(let l of t)d.add(l.path);for(let l of n)d.add(l.path);let u=[...d].sort();for(let l of u){let m=i.get(l);if(m){let x=$m[m.status]??"UU";a.push(`${x} ${pr(l)}`);continue}let h=c.get(l),p=f.get(l),g=h?Tm(h.status):" ",w=p?Hm(p.status):" ";if(h?.status==="renamed"&&h.displayPath){let x=h.displayPath.indexOf(" -> "),b=h.displayPath.slice(0,x),y=h.displayPath.slice(x+4);a.push(`${g}${w} ${pr(b)} -> ${pr(y)}`)}else a.push(`${g}${w} ${pr(l)}`)}for(let l of o)a.push(`?? ${pr(l)}`);return a.length===0?"":`${a.join(`
|
|
631
642
|
`)}
|
|
632
|
-
`}function pr(e){return!/[ \t"\\]/.test(e)&&!/[^\x20-\x7E]/.test(e)?e:`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\t/g,"\\t").replace(/\n/g,"\\n")}"`}function
|
|
643
|
+
`}function pr(e){return!/[ \t"\\]/.test(e)&&!/[^\x20-\x7E]/.test(e)?e:`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\t/g,"\\t").replace(/\n/g,"\\n")}"`}function vm(e,t){return e?.type==="symbolic"?e.target.replace(/^refs\/heads\//,""):t??Z}function Qc(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:te.string().alias("c").describe("Create and switch to a new branch"),forceCreate:te.string().alias("C").describe("Create/reset and switch to a branch"),detach:v().alias("d").describe("Detach HEAD at named commit"),orphan:te.string().describe("Create a new orphan branch"),guess:v().default(!0).describe("Guess branch from remote tracking")},handler:async(n,r,o)=>{let s=await B(r.fs,r.cwd,t);if(S(s))return s;let a=s,i=n["branch-or-start-point"];if(n.orphan)return n.create||n.forceCreate?T("--orphan and -c/-C are incompatible"):n.detach?T("--orphan and --detach are incompatible"):jm(a,n.orphan,r.env,t);if(n.detach){if(n.create||n.forceCreate)return T("--detach and -c/-C are incompatible");let d=i??"HEAD",u=await ye(a,d,`invalid reference: ${d}`);return S(u)?u:Mm(a,d,u.hash,r.env,t)}if(n.create||n.forceCreate){let d=n.create||n.forceCreate,u=i??(o.passthrough.length>0?o.passthrough[0]:void 0);return Jc(a,d,!!n.forceCreate,u,r.env,t)}if(!i)return T("missing branch or commit argument");if(i==="-")return Sm(a,r.env,t);let c=`refs/heads/${i}`,f=await F(a,c);if(f)return ef(a,i,c,f,r.env,t);if(n.guess!==!1){let d=await Dm(a,i);if(d)return Jc(a,i,!1,d.startPoint,r.env,t,d.trackingRef)}return T(`invalid reference: ${i}`)}})}async function gr(e){return await qe(e,"CHERRY_PICK_HEAD")?T(`cannot switch branch while cherry-picking
|
|
633
644
|
Consider "git cherry-pick --quit" or "git worktree add".`):await qe(e,"MERGE_HEAD")?T(`cannot switch branch while merging
|
|
634
645
|
Consider "git merge --quit" or "git worktree add".`):await qe(e,"REVERT_HEAD")?T(`cannot switch branch while reverting
|
|
635
646
|
Consider "git revert --quit" or "git worktree add".`):await gt(e)?T(`cannot switch branch while rebasing
|
|
636
|
-
Consider "git rebase --quit" or "git worktree add".`):null}async function
|
|
637
|
-
${_}`,exitCode:0}}f=E}let d=await gr(e);if(d)return d;let u=await X(e),l=await U(e);if(r){let E=on(l);if(E)return E}let m=await M(e,f);if(u&&u!==f){let E=await M(e,u);if(E.tree!==m.tree){let I=await Qt(e,E.tree,m.tree,l);if(!I.success)return I.errorOutput??j("error: checkout would overwrite local changes");l={version:2,entries:I.newEntries},await re(e,l),await be(e,I.worktreeOps)}}let h=await J(e),p="";h?.type==="direct"&&u&&(p=await
|
|
647
|
+
Consider "git rebase --quit" or "git worktree add".`):null}async function Sm(e,t,n){let r=await gr(e);if(r)return r;let o=await rs(e);return o?ef(e,o.name,o.refName,o.hash,t,n):T("no previous branch")}async function Dm(e,t){let n=await le(e,"refs/remotes"),r=[];for(let s of n){let a=s.name.replace(/^refs\/remotes\//,"").split("/"),i=a[0];a.length>=2&&i&&a.slice(1).join("/")===t&&r.push({remote:i,ref:s.name})}let o=r.length===1?r[0]:void 0;return o?{startPoint:o.ref,trackingRef:o.ref}:null}async function Jc(e,t,n,r,o,s,a){let i=`refs/heads/${t}`,c=await F(e,i);if(c&&!n)return T(`a branch named '${t}' already exists`);let f;if(r){let E=await ye(e,r,`invalid reference: ${r}`);if(S(E))return E;f=E.hash}else{let E=await X(e);if(!E){let I=await J(e),A=I?.type==="symbolic"?I.target.replace(/^refs\/heads\//,""):"";n&&c&&await ie(e,i),await $e(e,"HEAD",i),await tt(e);let _=await Bt(e);return await ee(e,o,"HEAD",null,Z,`checkout: moving from ${A} to ${t}`),{stdout:"",stderr:`Switched to a new branch '${t}'
|
|
648
|
+
${_}`,exitCode:0}}f=E}let d=await gr(e);if(d)return d;let u=await X(e),l=await U(e);if(r){let E=on(l);if(E)return E}let m=await M(e,f);if(u&&u!==f){let E=await M(e,u);if(E.tree!==m.tree){let I=await Qt(e,E.tree,m.tree,l);if(!I.success)return I.errorOutput??j("error: checkout would overwrite local changes");l={version:2,entries:I.newEntries},await re(e,l),await be(e,I.worktreeOps)}}let h=await J(e),p="";h?.type==="direct"&&u&&(p=await is(e,u,f));let g=vm(h,u);await Y(e,i,f),await $e(e,"HEAD",i),await tt(e);let w=await Bt(e),x=r??"HEAD";n&&c?c!==f&&await ee(e,o,i,c,f,`branch: Reset to ${x}`):await ee(e,o,i,null,f,`branch: Created from ${x}`),await ee(e,o,"HEAD",u,f,`checkout: moving from ${g} to ${t}`);let b=a?.replace(/^refs\/remotes\//,"").split("/");if(b){let E=b[0]??"",I=`refs/heads/${b.slice(1).join("/")}`,A=await ae(e);A[`branch "${t}"`]={...A[`branch "${t}"`],remote:E,merge:I},await Ge(e,A)}await s?.hooks?.emitPost("post-checkout",{prevHead:u,newHead:f,isBranchCheckout:!0});let y=n&&c?`Switched to and reset branch '${t}'
|
|
638
649
|
`:`Switched to a new branch '${t}'
|
|
639
650
|
`,k=p+y+w;if(b){let E=b.slice(1).join("/");k+=`branch '${t}' set up to track '${b[0]}/${E}'.
|
|
640
|
-
`}let C="";r&&(C=await En(e,m.tree,l));let P=await ae(e),O=await Ut(e,P,t);return O&&(C+=yn(O)),{stdout:C,stderr:k,exitCode:0}}async function
|
|
641
|
-
${l}`,exitCode:0}}function
|
|
651
|
+
`}let C="";r&&(C=await En(e,m.tree,l));let P=await ae(e),O=await Ut(e,P,t);return O&&(C+=yn(O)),{stdout:C,stderr:k,exitCode:0}}async function ef(e,t,n,r,o,s){let a=await gr(e);return a||as(e,t,n,r,o,s)}async function Mm(e,t,n,r,o){let s=await gr(e);return s||cs(e,n,r,o)}async function jm(e,t,n,r){let o=await gr(e);if(o)return o;let s=`refs/heads/${t}`;if(await F(e,s))return T(`a branch named '${t}' already exists`);let i=await U(e),c=on(i);if(c)return c;let f=await X(e),d=await J(e),u="";if(d?.type==="direct"&&f&&(u=await ho(e,f)),e.workTree){let m=f?(await M(e,f)).tree:null,h=await ke(e,[]),p=await Qt(e,m,h,i);if(!p.success)return p.errorOutput??j("error: checkout would overwrite local changes");await be(e,p.worktreeOps)}await re(e,ri()),await $e(e,"HEAD",s),await tt(e);let l=await Bt(e);return await r?.hooks?.emitPost("post-checkout",{prevHead:f,newHead:Z,isBranchCheckout:!0}),{stdout:"",stderr:`${u}Switched to a new branch '${t}'
|
|
652
|
+
${l}`,exitCode:0}}function nf(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:v().alias("a").describe("Make an annotated tag object"),message:te.string().alias("m").describe("Tag message"),delete:v().alias("d").describe("Delete a tag"),force:v().alias("f").describe("Replace an existing tag"),list:te.string().alias("l").describe("List tags matching pattern")},handler:async(n,r)=>{let o=await B(r.fs,r.cwd,t);if(S(o))return o;let s=o;if(n.delete){if(!n.name)return T("tag name required");let a=`refs/tags/${n.name}`,i=await F(s,a);return i?(await ie(s,a),{stdout:`Deleted tag '${n.name}' (was ${K(i)})
|
|
642
653
|
`,stderr:"",exitCode:0}):j(`error: tag '${n.name}' not found.
|
|
643
|
-
`)}if(n.list!==void 0)return
|
|
654
|
+
`)}if(n.list!==void 0)return tf(s,n.list||void 0);if(n.name){let a=n.commit,i;if(a){let u=await An(s,a,`Failed to resolve '${a}' as a valid ref.`);if(S(u))return u;i=u}else if(i=await X(s),!i)return T("Failed to resolve 'HEAD' as a valid ref.");let c=`refs/tags/${n.name}`;if(await F(s,c)&&!n.force)return T(`tag '${n.name}' already exists`);if(n.annotate||n.message){if(!n.message)return T("no tag message specified (use -m)");let u=await Le(s,r.env);if(S(u))return u;let l=mt(n.message),m=Ei({type:"tag",object:i,objectType:"commit",name:n.name,tagger:u,message:l}),h=await we(s,"tag",m);await Y(s,c,h)}else await Y(s,c,i);return{stdout:"",stderr:"",exitCode:0}}return tf(s)}})}async function tf(e,t){let n=await le(e,"refs/tags");if(n.length===0)return{stdout:"",stderr:"",exitCode:0};let r=n.map(o=>o.name.replace("refs/tags/",""));return t&&(r=r.filter(o=>mn(t,o,0)===0)),r.length===0?{stdout:"",stderr:"",exitCode:0}:{stdout:`${r.join(`
|
|
644
655
|
`)}
|
|
645
|
-
`,stderr:"",exitCode:0}}var
|
|
646
|
-
`,exitCode:1}:s())}this.inner=
|
|
656
|
+
`,stderr:"",exitCode:0}}var Lm={init:e=>gc(e),clone:(e,t)=>qa(e,t),fetch:(e,t)=>ic(e,t),pull:(e,t)=>Ic(e,t),push:(e,t)=>$c(e,t),add:(e,t)=>Wi(e,t),blame:(e,t)=>sa(e,t),commit:(e,t)=>Ka(e,t),status:(e,t)=>Zc(e,t),log:(e,t)=>kc(e,t),branch:(e,t)=>ba(e,t),tag:(e,t)=>nf(e,t),checkout:(e,t)=>Ea(e,t),diff:(e,t)=>nc(e,t),reset:(e,t)=>jc(e,t),merge:(e,t)=>Oc(e,t),"cherry-pick":(e,t)=>Da(e,t),revert:(e,t)=>_c(e,t),rebase:(e,t)=>vc(e,t),mv:(e,t)=>Rc(e,t),rm:(e,t)=>Uc(e,t),remote:(e,t)=>Dc(e,t),config:(e,t)=>Xa(e,t),show:(e,t)=>Bc(e,t),stash:(e,t)=>Xc(e,t),"rev-parse":(e,t)=>Nc(e,t),"ls-files":(e,t)=>Pc(e,t),clean:(e,t)=>Ma(e,t),switch:(e,t)=>Qc(e,t),restore:(e,t)=>Gc(e,t),reflog:(e,t)=>Sc(e,t),repack:(e,t)=>mc(e,t),gc:(e,t)=>hc(e,t)};function rf(e){let t=As("git",{description:"Git command"});for(let n of Object.values(Lm))n(t,e);return t}var Os=class{listeners=new Map;onError=()=>{};on(t,n){let r=t,o=this.listeners.get(r);o||(o=[],this.listeners.set(r,o));let s=n;return o.push(s),()=>{let a=this.listeners.get(r);if(a){let i=a.indexOf(s);i!==-1&&a.splice(i,1)}}}async emitPre(t,n){let r=this.listeners.get(t);if(!r||r.length===0)return null;for(let o of r){let s=await o(n);if(s&&typeof s=="object"&&"abort"in s)return s}return null}async emitPost(t,n){let r=this.listeners.get(t);if(!(!r||r.length===0))for(let o of r)await o(n)}emit(t,n){let r=this.listeners.get(t);if(!(!r||r.length===0))for(let o of r)try{let s=o(n);s&&typeof s=="object"&&"then"in s&&s.catch(this.onError)}catch(s){this.onError(s)}}};var Rs=class{name="git";hooks;middlewares=[];extensions;inner;constructor(t){this.hooks=new Os;let n=t?.network;if(this.extensions={hooks:this.hooks,credentialProvider:t?.credentials,identityOverride:t?.identity,fetchFn:typeof n=="object"?n.fetch:void 0,networkPolicy:n},t?.disabled?.length){let r=new Set(t.disabled);this.use(async(o,s)=>o.command&&r.has(o.command)?{stdout:"",stderr:`git: '${o.command}' is not available in this environment
|
|
657
|
+
`,exitCode:1}:s())}this.inner=rf(this.extensions).toCommand()}on(t,n){return this.hooks.on(t,n)}use(t){return this.middlewares.push(t),()=>{let n=this.middlewares.indexOf(t);n!==-1&&this.middlewares.splice(n,1)}}execute=async(t,n)=>{let r={command:t[0],rawArgs:t.slice(1),fs:n.fs,cwd:n.cwd,env:n.env,stdin:n.stdin,exec:n.exec,signal:n.signal};return this.runMiddleware(r,()=>this.inner.execute(t,n))};async runMiddleware(t,n){if(this.middlewares.length===0)return n();let r=0,o=async()=>{if(r>=this.middlewares.length)return n();let s=this.middlewares[r++];return s(t,o)};return o()}};function Gm(e){return new Rs(e)}export{Rs as Git,Gm as createGit};
|