@scolladon/tsgit 2.0.1 → 3.1.0
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 +14 -2
- package/dist/cjs/adapters/browser/index.cjs +1 -2
- package/dist/cjs/adapters/memory/index.cjs +1 -2
- package/dist/cjs/adapters/node/index.cjs +1 -2
- package/dist/cjs/chunks/adapter-detect-DW9fsw9d.cjs +1 -0
- package/dist/cjs/chunks/browser-http-transport-DGwW5YL7.cjs +1 -0
- package/dist/cjs/chunks/context-BcoAzPuU.cjs +0 -1
- package/dist/cjs/chunks/error-CfLWDui_.cjs +1 -0
- package/dist/cjs/chunks/index-Cy44GVR6.cjs +1 -0
- package/dist/cjs/chunks/inflate-CmCtM4-w.cjs +1 -0
- package/dist/cjs/chunks/lru-cache-1OU7JhD8.cjs +0 -1
- package/dist/cjs/chunks/memory-http-transport-CGriODcQ.cjs +1 -0
- package/dist/cjs/chunks/node-ssh-transport-PFu3ijfp.cjs +1 -0
- package/dist/cjs/chunks/{progress-CxU62NC1.cjs → progress-D8Dqbftk.cjs} +1 -2
- package/dist/cjs/chunks/readable-stream-MTA6D0Zh.cjs +0 -1
- package/dist/cjs/chunks/repository-Ci-BBxk0.cjs +1 -0
- package/dist/cjs/chunks/write-sparse-checkout-C1dsHCAD.cjs +1 -0
- package/dist/cjs/commands/index.cjs +1 -2
- package/dist/cjs/index.browser.cjs +1 -2
- package/dist/cjs/index.cjs +1 -2
- package/dist/cjs/index.default.cjs +1 -2
- package/dist/cjs/index.node.cjs +1 -2
- package/dist/cjs/operators/index.cjs +0 -1
- package/dist/cjs/primitives/index.cjs +1 -2
- package/dist/cjs/transport/index.cjs +0 -1
- package/dist/esm/adapters/browser/index.js +1 -2
- package/dist/esm/adapters/memory/index.js +1 -2
- package/dist/esm/adapters/node/index.js +1 -2
- package/dist/esm/chunks/adapter-detect-BkCMnjrI.js +1 -0
- package/dist/esm/chunks/browser-http-transport-CSxAte5h.js +1 -0
- package/dist/esm/chunks/context-CumKOV7K.js +0 -1
- package/dist/esm/chunks/error-BotOd-nD.js +1 -0
- package/dist/esm/chunks/index-DsvINN8n.js +1 -0
- package/dist/esm/chunks/inflate-BCIXqeeE.js +1 -0
- package/dist/esm/chunks/lru-cache-Cy7C7Lx2.js +0 -1
- package/dist/esm/chunks/memory-http-transport-caqmMGR1.js +1 -0
- package/dist/esm/chunks/node-ssh-transport-BgSv2IhT.js +1 -0
- package/dist/esm/chunks/{progress-BZobfl7p.js → progress-B_AJnOHx.js} +1 -2
- package/dist/esm/chunks/readable-stream-CGuf8k1J.js +0 -1
- package/dist/esm/chunks/repository-DyxknzvE.js +1 -0
- package/dist/esm/chunks/write-sparse-checkout-BwHbNKNS.js +1 -0
- package/dist/esm/commands/index.js +1 -2
- package/dist/esm/index.browser.js +1 -2
- package/dist/esm/index.default.js +1 -2
- package/dist/esm/index.js +1 -2
- package/dist/esm/index.node.js +1 -2
- package/dist/esm/operators/index.js +0 -1
- package/dist/esm/primitives/index.js +1 -2
- package/dist/esm/transport/index.js +0 -1
- package/dist/types/adapters/browser/index.d.cts +5 -3
- package/dist/types/adapters/browser/index.d.ts +5 -3
- package/dist/types/adapters/memory/index.d.cts +31 -4
- package/dist/types/adapters/memory/index.d.ts +31 -4
- package/dist/types/adapters/node/index.d.cts +146 -40
- package/dist/types/adapters/node/index.d.ts +146 -40
- package/dist/types/chunks/{context-YDw6qicq.d.cts → context-CF1YF2S8.d.cts} +165 -6
- package/dist/types/chunks/{context-CCL0_F8R.d.ts → context-sIhhtk2u.d.ts} +165 -6
- package/dist/types/chunks/{http-transport--_NdQOiw.d.cts → http-transport-DirKfK2S.d.cts} +1 -1
- package/dist/types/chunks/{http-transport--_NdQOiw.d.ts → http-transport-DirKfK2S.d.ts} +1 -1
- package/dist/types/chunks/index-B5Dps3fg.d.ts +2468 -0
- package/dist/types/chunks/index-B_A8VLaf.d.ts +1221 -0
- package/dist/types/chunks/index-Dfh8cvEs.d.cts +2468 -0
- package/dist/types/chunks/index-Dqxddhav.d.cts +1221 -0
- package/dist/types/chunks/progress-BjAKfkam.d.ts +1217 -0
- package/dist/types/chunks/progress-Ldnfb8st.d.cts +1217 -0
- package/dist/types/chunks/reflog-entry-Cqh3QrPH.d.ts +697 -0
- package/dist/types/chunks/reflog-entry-Dy-O27Dd.d.cts +697 -0
- package/dist/types/chunks/{repository-FoS_Laoy.d.ts → repository-D8QBTkEz.d.ts} +58 -20
- package/dist/types/chunks/{repository-BeifCqp0.d.cts → repository-D9YrVhcH.d.cts} +58 -20
- package/dist/types/commands/index.d.cts +4 -1259
- package/dist/types/commands/index.d.ts +4 -1259
- package/dist/types/index.browser.d.cts +7 -8
- package/dist/types/index.browser.d.ts +7 -8
- package/dist/types/index.d.cts +61 -124
- package/dist/types/index.d.ts +61 -124
- package/dist/types/index.default.d.cts +7 -8
- package/dist/types/index.default.d.ts +7 -8
- package/dist/types/index.node.d.cts +7 -8
- package/dist/types/index.node.d.ts +7 -8
- package/dist/types/primitives/index.d.cts +4 -692
- package/dist/types/primitives/index.d.ts +4 -692
- package/dist/types/transport/index.d.cts +1 -1
- package/dist/types/transport/index.d.ts +1 -1
- package/package.json +94 -28
- package/dist/cjs/adapters/browser/index.cjs.map +0 -1
- package/dist/cjs/adapters/memory/index.cjs.map +0 -1
- package/dist/cjs/adapters/node/index.cjs.map +0 -1
- package/dist/cjs/chunks/adapter-detect-CD_LcgaH.cjs +0 -2
- package/dist/cjs/chunks/adapter-detect-CD_LcgaH.cjs.map +0 -1
- package/dist/cjs/chunks/browser-http-transport-CiMRqtDS.cjs +0 -2
- package/dist/cjs/chunks/browser-http-transport-CiMRqtDS.cjs.map +0 -1
- package/dist/cjs/chunks/context-BcoAzPuU.cjs.map +0 -1
- package/dist/cjs/chunks/error-CfjFO3x_.cjs +0 -2
- package/dist/cjs/chunks/error-CfjFO3x_.cjs.map +0 -1
- package/dist/cjs/chunks/index-BWCq_5BJ.cjs +0 -2
- package/dist/cjs/chunks/index-BWCq_5BJ.cjs.map +0 -1
- package/dist/cjs/chunks/lru-cache-1OU7JhD8.cjs.map +0 -1
- package/dist/cjs/chunks/memory-http-transport-BVL6VgB-.cjs +0 -2
- package/dist/cjs/chunks/memory-http-transport-BVL6VgB-.cjs.map +0 -1
- package/dist/cjs/chunks/node-http-transport-BvfVcf02.cjs +0 -2
- package/dist/cjs/chunks/node-http-transport-BvfVcf02.cjs.map +0 -1
- package/dist/cjs/chunks/progress-CxU62NC1.cjs.map +0 -1
- package/dist/cjs/chunks/readable-stream-MTA6D0Zh.cjs.map +0 -1
- package/dist/cjs/chunks/repository-BEg2zNtx.cjs +0 -2
- package/dist/cjs/chunks/repository-BEg2zNtx.cjs.map +0 -1
- package/dist/cjs/chunks/walk-submodules-D2Sp7JEB.cjs +0 -2
- package/dist/cjs/chunks/walk-submodules-D2Sp7JEB.cjs.map +0 -1
- package/dist/cjs/commands/index.cjs.map +0 -1
- package/dist/cjs/index.browser.cjs.map +0 -1
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/cjs/index.default.cjs.map +0 -1
- package/dist/cjs/index.node.cjs.map +0 -1
- package/dist/cjs/operators/index.cjs.map +0 -1
- package/dist/cjs/primitives/index.cjs.map +0 -1
- package/dist/cjs/transport/index.cjs.map +0 -1
- package/dist/esm/adapters/browser/index.js.map +0 -1
- package/dist/esm/adapters/memory/index.js.map +0 -1
- package/dist/esm/adapters/node/index.js.map +0 -1
- package/dist/esm/chunks/adapter-detect-DkZhhUhd.js +0 -2
- package/dist/esm/chunks/adapter-detect-DkZhhUhd.js.map +0 -1
- package/dist/esm/chunks/browser-http-transport-4rJkHcQu.js +0 -2
- package/dist/esm/chunks/browser-http-transport-4rJkHcQu.js.map +0 -1
- package/dist/esm/chunks/context-CumKOV7K.js.map +0 -1
- package/dist/esm/chunks/error-Dc-SRSJK.js +0 -2
- package/dist/esm/chunks/error-Dc-SRSJK.js.map +0 -1
- package/dist/esm/chunks/index-jH0UMhh-.js +0 -2
- package/dist/esm/chunks/index-jH0UMhh-.js.map +0 -1
- package/dist/esm/chunks/lru-cache-Cy7C7Lx2.js.map +0 -1
- package/dist/esm/chunks/memory-http-transport-CA1WxWBp.js +0 -2
- package/dist/esm/chunks/memory-http-transport-CA1WxWBp.js.map +0 -1
- package/dist/esm/chunks/node-http-transport-DPa2lK3T.js +0 -2
- package/dist/esm/chunks/node-http-transport-DPa2lK3T.js.map +0 -1
- package/dist/esm/chunks/progress-BZobfl7p.js.map +0 -1
- package/dist/esm/chunks/readable-stream-CGuf8k1J.js.map +0 -1
- package/dist/esm/chunks/repository-DF6ePd1x.js +0 -2
- package/dist/esm/chunks/repository-DF6ePd1x.js.map +0 -1
- package/dist/esm/chunks/walk-submodules-Dq9oGwP8.js +0 -2
- package/dist/esm/chunks/walk-submodules-Dq9oGwP8.js.map +0 -1
- package/dist/esm/commands/index.js.map +0 -1
- package/dist/esm/index.browser.js.map +0 -1
- package/dist/esm/index.default.js.map +0 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/index.node.js.map +0 -1
- package/dist/esm/operators/index.js.map +0 -1
- package/dist/esm/primitives/index.js.map +0 -1
- package/dist/esm/transport/index.js.map +0 -1
- package/dist/types/chunks/index-entry-DtEbVpOG.d.cts +0 -47
- package/dist/types/chunks/index-entry-UD4dvtKh.d.ts +0 -47
- package/dist/types/chunks/progress-7KKiXXfX.d.ts +0 -405
- package/dist/types/chunks/progress-By8yFaUE.d.cts +0 -405
- package/dist/types/chunks/reflog-entry-BbNnXCTC.d.cts +0 -368
- package/dist/types/chunks/reflog-entry-CSzjnZd4.d.ts +0 -368
- package/dist/types/chunks/write-tree-C3oNxOlX.d.cts +0 -196
- package/dist/types/chunks/write-tree-DRI-LzSr.d.ts +0 -196
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{T as t,O as e,E as a,P as n,Q as r,R as i,u as o,z as s,S as c,U as d,k as u,V as f,M as l,o as h,W as w,X as m,Y as p,Z as g,_ as y,$ as v,a0 as b,a1 as k,a2 as $,a3 as x,a4 as I,a5 as E,a6 as T,a7 as D,a8 as S,a9 as A,aa as M,ab as O,ac as N,ad as P,ae as C,s as H,m as L,j as R,af as U,n as _,ag as W,ah as j,ai as B,aj as F,I as z,ak as q,al as K,am as V,an as G,ao as Y,ap as X,aq as J,ar as Q,as as Z,at as tt,au as et,av as at,aw as nt,ax as rt,ay as it,az as ot,aA as st,aB as ct,aC as dt,aD as ut,aE as ft,aF as lt,aG as ht,aH as wt,aI as mt,aJ as pt,aK as gt,aL as yt,aM as vt,aN as bt,aO as kt,aP as $t,aQ as xt,aR as It,aS as Et,aT as Tt,aU as Dt}from"./error-BotOd-nD.js";import{G as St,H as At,I as Mt,J as Ot,K as Nt,S as Pt,L as Ct,N as Ht,P as Lt,Q as Rt,T as Ut,U as _t,V as Wt,W as jt,X as Bt,Y as Ft,Z as zt,a as qt,O as Kt,M as Vt,_ as Gt,$ as Yt,C as Xt,l as Jt,a0 as Qt,a1 as Zt,a2 as te,a3 as ee,a4 as ae,a5 as ne,R as re,a6 as ie,b as oe,u as se,a7 as ce,r as de,a8 as ue,s as fe,a9 as le,j as he,aa as we,ab as me,w as pe,ac as ge,n as ye,ad as ve,ae as be,af as ke,ag as $e,x as xe,ah as Ie,ai as Ee,aj as Te,ak as De,g as Se,h as Ae,al as Me,am as Oe,an as Ne,ao as Pe,e as Ce,d as He,F as Le,B as Re,ap as Ue,aq as _e,ar as We,as as je,at as Be,au as Fe,av as ze,aw as qe,q as Ke,ax as Ve,ay as Ge,az as Ye,f as Xe,aA as Je,aB as Qe,aC as Ze,y as ta,aD as ea,aE as aa,aF as na,aG as ra,E as ia,aH as oa,aI as sa,aJ as ca,aK as da,aL as ua,aM as fa,aN as la,aO as ha,aP as wa,aQ as ma,aR as pa,aS as ga,t as ya,aT as va,aU as ba,aV as ka,D as $a,aW as xa,aX as Ia,aY as Ea,aZ as Ta,a_ as Da,a$ as Sa,b0 as Aa,v as Ma,b1 as Oa,b2 as Na,m as Pa,b3 as Ca,b4 as Ha,b5 as La,b6 as Ra,b7 as Ua,b8 as _a,b9 as Wa,ba as ja,bb as Ba,bc as Fa,bd as za,be as qa,bf as Ka,bg as Va,bh as Ga,bi as Ya,bj as Xa,bk as Ja,bl as Qa,bm as Za,bn as tn,bo as en,bp as an,bq as nn,br as rn,bs as on,bt as sn,bu as cn,bv as dn,bw as un,bx as fn,by as ln,bz as hn,bA as wn,bB as mn,bC as pn,bD as gn,bE as yn,bF as vn,bG as bn,bH as kn,bI as $n,bJ as xn,bK as In,bL as En,bM as Tn,bN as Dn,bO as Sn,bP as An,bQ as Mn,bR as On,bS as Nn,bT as Pn,bU as Cn,bV as Hn,bW as Ln,bX as Rn,bY as Un,bZ as _n,z as Wn,b_ as jn,b$ as Bn,o as Fn,c0 as zn,c1 as qn,c2 as Kn,c3 as Vn,c4 as Gn,c5 as Yn,c6 as Xn,c7 as Jn,p as Qn,c8 as Zn,c9 as tr,ca as er,cb as ar}from"./write-sparse-checkout-BwHbNKNS.js";import{r as nr}from"./readable-stream-CGuf8k1J.js";import{withRetry as rr,withAuth as ir,withLogging as or}from"../transport/index.js";const sr=t=>{const e=void 0!==t.stage1,a=void 0!==t.stage2,n=void 0!==t.stage3;return e&&a&&n?"both-modified":a&&n?"both-added":e&&a?"deleted-by-them":e&&n?"deleted-by-us":e?"both-deleted":a?"added-by-us":"added-by-them"},cr=e=>new t({code:"INVALID_DIFF_INPUT",reason:e}),dr=/[ \t\v\f\r]+$/,ur=t=>{const e=t.indexOf("\n");return-1===e?t:t.slice(0,e)},fr=t=>{const e=[];for(const a of t.split("\n")){const t=a.replace(dr,"");if(""!==t)e.push(t);else if(e.length>0)break}return e.join(" ")},lr=t=>{const e=[];for(const a of t.split("\n")){const t=a.replace(dr,"");(""!==t||0!==e.length&&""!==e[e.length-1])&&e.push(t)}return""===e[e.length-1]&&e.pop(),0===e.length?"":`${e.join("\n")}\n`};function hr(t,e,a){return void 0!==e&&void 0!==a?function(t,e,a){if(e.id!==a.id||e.mode!==a.mode)return Ot(e.mode,a.mode)?{type:"modify",path:t,oldId:a.id,newId:e.id,oldMode:a.mode,newMode:e.mode}:{type:"type-change",path:t,oldId:a.id,newId:e.id,oldMode:a.mode,newMode:e.mode}}(t,e,a):void 0!==e?{type:"add",newPath:(n=e).path,newId:n.id,newMode:n.mode}:function(t,e){return{type:"delete",oldPath:t,oldId:e.id,oldMode:e.mode}}(t,a);var n}function wr(e,a){!function(e){if(void 0!==e&&e.entries.size>Mt)throw new t({code:"INVALID_TREE_FOR_DIFF",reason:"FlatTree exceeds MAX_FLAT_TREE_ENTRIES"})}(a);const n=function(t){const e=new Map;for(const a of t.entries)0===a.flags.stage&&e.set(a.path,a);return e}(e),r=function(t,e){const a=new Set;for(const e of t.keys())a.add(e);if(void 0!==e)for(const t of e.entries.keys())a.add(t);return a}(n,a),i=[];for(const t of r){const e=hr(t,n.get(t),a?.entries.get(t));void 0!==e&&i.push(e)}return{changes:St(i,Nt)}}function mr(t,e){const a=e.flags.stage;return 1===a?{...t,stage1:e}:2===a?{...t,stage2:e}:{...t,stage3:e}}function pr(t){return"distinct-types"===t.type?function(t){const e=[];return void 0!==t.ourId&&void 0!==t.ourMode&&void 0!==t.ourPath&&e.push({id:t.ourId,mode:t.ourMode,stage:2,path:t.ourPath}),void 0!==t.theirId&&void 0!==t.theirMode&&void 0!==t.theirPath&&e.push({id:t.theirId,mode:t.theirMode,stage:3,path:t.theirPath}),void 0!==t.baseId&&void 0!==t.baseMode&&void 0!==t.basePath&&e.push({id:t.baseId,mode:t.baseMode,stage:1,path:t.basePath}),e}(t):function(t){const e=[];return void 0!==t.baseId&&void 0!==t.baseMode&&e.push({id:t.baseId,mode:t.baseMode,stage:1,path:t.path}),void 0!==t.ourId&&void 0!==t.ourMode&&e.push({id:t.ourId,mode:t.ourMode,stage:2,path:t.path}),void 0!==t.theirId&&void 0!==t.theirMode&&e.push({id:t.theirId,mode:t.theirMode,stage:3,path:t.path}),e}(t)}function gr(t){if("distinct-types"===t.type){const e=[];return void 0!==t.ourPath&&e.push(t.ourPath),void 0!==t.theirPath&&e.push(t.theirPath),e}return[t.path]}function yr(t){return t.flatMap(t=>gr(t)).sort(At)}function vr(t,e){const a=e(t.mode);return{ctimeSeconds:a.ctimeSeconds,ctimeNanoseconds:a.ctimeNanoseconds,mtimeSeconds:a.mtimeSeconds,mtimeNanoseconds:a.mtimeNanoseconds,dev:a.dev,ino:a.ino,mode:t.mode,uid:a.uid,gid:a.gid,fileSize:a.fileSize,id:t.id,flags:{...Pt,stage:t.stage},path:t.path}}function br(t,e){const a=new Set;for(const e of t)for(const t of gr(e)){if(a.has(t))throw cr("duplicate conflict path");a.add(t)}const n=[];for(const a of t)for(const t of pr(a))n.push(vr(t,e));return n.sort((t,e)=>{const a=At(t.path,e.path);return 0!==a?a:t.flags.stage-e.flags.stage}),n}const kr="0000000",$r={old:"a/",new:"b/"},xr="\",Ir=(t,e)=>void 0===e?Lt(t):"binary"===e,Er=new TextDecoder("utf-8",{fatal:!1});function Tr(t,e){for(let a=0;a<e.length;a++){const n=e.charCodeAt(a);if(10===n||13===n||0===n)throw cr(`${t} contains control character (code ${n}) at index ${a}`)}}function Dr(t,e){if(Tr("pathPrefix.old",e.old),Tr("pathPrefix.new",e.new),"rename"===t.type||"copy"===t.type)return Tr("oldPath",t.oldPath),void Tr("newPath",t.newPath);"add"!==t.type?"delete"!==t.type?Tr("path",t.path):Tr("oldPath",t.oldPath):Tr("newPath",t.newPath)}function Sr(t){return void 0===t||0===t.length?{lines:[],hasTrailingNewline:!0}:{lines:Ct(t).map(Ar),hasTrailingNewline:10===t[t.length-1]}}function Ar(t){return Er.decode(t.subarray(0,t.length>0&&10===t[t.length-1]?t.length-1:t.length))}function Mr(t){return t.slice(0,7)}function Or(t,e,a){return`diff --git ${a.old}${t} ${a.new}${e}`}function Nr(t,e,a,n){return`@@ -${1===e?`${t}`:`${t},${e}`} +${1===n?`${a}`:`${a},${n}`} @@`}function Pr(t,e,a){return"common"===t.kind?function(t,e){const a=[];for(let n=t.oursStart;n<t.oursEnd;n++){const r=t.theirsStart+(n-t.oursStart);a.push({kind:"context",oldIndex:n,newIndex:r,text:e[r]})}return a}(t,a):"ours-only"===t.kind?function(t,e){const a=[];for(let n=t.oursStart;n<t.oursEnd;n++)a.push({kind:"delete",oldIndex:n,newIndex:t.theirsStart,text:e[n]});return a}(t,e):function(t,e){const a=[];for(let n=t.theirsStart;n<t.theirsEnd;n++)a.push({kind:"insert",oldIndex:t.oursEnd,newIndex:n,text:e[n]});return a}(t,a)}function Cr(t,e){const a="insert"!==t.kind&&t.oldIndex===e.lastOldIdx&&e.lastOldIdx===e.oldTotal-1,n="delete"!==t.kind&&t.newIndex===e.lastNewIdx&&e.lastNewIdx===e.newTotal-1;return"context"===t.kind?a&&!e.oldHasTrailingNewline||n&&!e.newHasTrailingNewline:"delete"===t.kind?a&&!e.oldHasTrailingNewline:n&&!e.newHasTrailingNewline}function Hr(t){return"context"===t?" ":"delete"===t?"-":"+"}function Lr(t){const e=[];for(const a of t)e.push(`${Hr(a.kind)}${a.text}`),a.trailingNoNewline&&e.push(xr);return e}function Rr(t,e,a){const n=Sr(e),r=[];if(r.push(Or(t.newPath,t.newPath,a)),r.push(`new file mode ${t.newMode}`),r.push(`index ${kr}..${Mr(t.newId)}`),r.push("--- /dev/null"),r.push(`+++ ${a.new}${t.newPath}`),0===n.lines.length)return r;r.push(Nr(0,0,1,n.lines.length));for(const t of n.lines)r.push(`+${t}`);return n.hasTrailingNewline||r.push(xr),r}function Ur(t,e,a){const n=Sr(e),r=[];if(r.push(Or(t.oldPath,t.oldPath,a)),r.push(`deleted file mode ${t.oldMode}`),r.push(`index ${Mr(t.oldId)}..${kr}`),r.push(`--- ${a.old}${t.oldPath}`),r.push("+++ /dev/null"),0===n.lines.length)return r;r.push(Nr(1,n.lines.length,0,0));for(const t of n.lines)r.push(`-${t}`);return n.hasTrailingNewline||r.push(xr),r}function _r(t){return{path:t.path,oldId:t.oldId,newId:t.newId,oldMode:t.oldMode,newMode:t.newMode}}function Wr(t){return t.oldMode===t.newMode?[`index ${Mr(t.oldId)}..${Mr(t.newId)} ${t.newMode}`]:[`old mode ${t.oldMode}`,`new mode ${t.newMode}`,`index ${Mr(t.oldId)}..${Mr(t.newId)}`]}function jr(t,e,a,n){return[`Binary files ${0===a.length?"/dev/null":`${e.old}${t.path}`} and ${0===n.length?"/dev/null":`${e.new}${t.path}`} differ`]}function Br(t,e,a,n){const r=Sr(t),i=Sr(e);return function(t,e,a){if(0===t.length)return[];const n=function(t,e){const a=[];return t.forEach((t,n)=>{if("context"===t.kind)return;const r=a[a.length-1];void 0!==r&&n-r.last<=e?a[a.length-1]={first:r.first,last:n}:a.push({first:n,last:n})}),a}(t,2*e+1);return 0===n.length?[]:n.map(n=>function(t,e,a,n){const r=Math.max(0,t.first-a),i=Math.min(e.length,t.last+a+1),o=e.slice(r,i),s=function(t){let e=0,a=0,n=0,r=0,i=!1,o=!1,s=-1,c=-1;for(const d of t)"insert"!==d.kind&&(i||(e=d.oldIndex+1,i=!0),n++,s=d.oldIndex),"delete"!==d.kind&&(o||(a=d.newIndex+1,o=!0),r++,c=d.newIndex);return 0===n&&(e=t[0].oldIndex),0===r&&(a=t[0].newIndex),{oldStart:e,oldLen:n,newStart:a,newLen:r,lastOldIdx:s,lastNewIdx:c}}(o),c={...n,lastOldIdx:s.lastOldIdx,lastNewIdx:s.lastNewIdx},d=o.map(t=>({kind:t.kind,text:t.text,trailingNoNewline:Cr(t,c)}));return{oldStart:s.oldStart,oldLen:s.oldLen,newStart:s.newStart,newLen:s.newLen,body:d}}(n,t,e,a))}(function(t,e,a,n,r){const i=Ht(a,n,void 0!==r?.lineKey?{lineKey:r.lineKey}:void 0),o=[];for(const a of i.hunks)for(const n of Pr(a,t,e))o.push(n);return!0!==r?.ignoreBlankLines?o:function(t,e,a){return t.filter(t=>{if("context"===t.kind)return!0;const n="delete"===t.kind?e.oursLines[t.oldIndex]:e.theirsLines[t.newIndex];return void 0===n||!_t(n,a)})}(o,i,r.lineKey??Wt)}(r.lines,i.lines,t,e,n),a,{oldTotal:r.lines.length,newTotal:i.lines.length,oldHasTrailingNewline:r.hasTrailingNewline,newHasTrailingNewline:i.hasTrailingNewline})}function Fr(t,e,a,n,r,i){const o=Br(a,n,r,i);if(0===o.length&&!0===i?.ignoreBlankLines)return[];const s=[];s.push(`--- ${e.old}${t.path}`),s.push(`+++ ${e.new}${t.path}`);for(const t of o){s.push(Nr(t.oldStart,t.oldLen,t.newStart,t.newLen));for(const e of Lr(t.body))s.push(e)}return s}function zr(t,e,a,n,r,i){const o=[];if(o.push(Or(t.oldPath,t.newPath,n)),t.oldMode!==t.newMode&&(o.push(`old mode ${t.oldMode}`),o.push(`new mode ${t.newMode}`)),o.push(`similarity index ${Rt(t.similarity.score)}%`),o.push(`${e} from ${t.oldPath}`),o.push(`${e} to ${t.newPath}`),t.similarity.score===Ut)return o;const s=function(t,e,a,n,r,i,o){const s=[];if(s.push(function(t){const e=`index ${Mr(t.oldId)}..${Mr(t.newId)}`;return t.oldMode===t.newMode?`${e} ${t.newMode}`:e}(t)),Ir(e,o)||Ir(a,o))return s.push(`Binary files ${n.old}${t.oldPath} and ${n.new}${t.newPath} differ`),s;const c=Br(e,a,r,i);if(0===c.length&&!0===i?.ignoreBlankLines)return s;s.push(`--- ${n.old}${t.oldPath}`),s.push(`+++ ${n.new}${t.newPath}`);for(const t of c){s.push(Nr(t.oldStart,t.oldLen,t.newStart,t.newLen));for(const e of Lr(t.body))s.push(e)}return s}(t,a.oldContent??new Uint8Array(0),a.newContent??new Uint8Array(0),n,r,i,a.patchBinaryOverride);return[...o,...s]}function qr(t,e){return[Or(t.newPath,t.newPath,e),`new file mode ${t.newMode}`,`index ${kr}..${Mr(t.newId)}`,`Binary files /dev/null and ${e.new}${t.newPath} differ`]}function Kr(t,e){return[Or(t.oldPath,t.oldPath,e),`deleted file mode ${t.oldMode}`,`index ${Mr(t.oldId)}..${kr}`,`Binary files ${e.old}${t.oldPath} and /dev/null differ`]}function Vr(t,e,a,n){const r=t.change,i=t.patchBinaryOverride;if("add"===r.type){const a=t.newContent??new Uint8Array(0);return Ir(a,i)?qr(r,e):Rr(r,t.newContent,e)}if("delete"===r.type){const a=t.oldContent??new Uint8Array(0);return Ir(a,i)?Kr(r,e):Ur(r,t.oldContent,e)}return"rename"===r.type?function(t,e,a,n,r){return zr(t,"rename",e,a,n,r)}(r,t,e,a,n):"copy"===r.type?function(t,e,a,n,r){return zr(t,"copy",e,a,n,r)}(r,t,e,a,n):"type-change"===r.type?function(t,e,a,n,r){const i={oldPath:t.path,oldId:t.oldId,oldMode:t.oldMode},o={newPath:t.path,newId:t.newId,newMode:t.newMode};return[...Ir(e,r)?Kr(i,n):Ur(i,e,n),...Ir(a,r)?qr(o,n):Rr(o,a,n)]}(r,t.oldContent??new Uint8Array(0),t.newContent??new Uint8Array(0),e,i):function(t,e,a,n,r,i,o){return void 0!==t.broken?function(t,e,a,n,r,i,o){const s=t.broken,c=_r(t),d=[];d.push(Or(c.path,c.path,n)),d.push(`dissimilarity index ${Rt(s.score)}%`);const u=`index ${Mr(c.oldId)}..${Mr(c.newId)}`;d.push(c.oldMode===c.newMode?`${u} ${c.newMode}`:u);const f=Ir(e,o)||Ir(a,o)?jr(c,n,e,a):Fr(c,n,e,a,r,i);for(const t of f)d.push(t);return d}(t,e,a,n,r,i,o):function(t,e,a,n,r,i,o){if(t.oldId!==t.newId&&!Ir(a,o)&&!Ir(n,o)){const o=Fr(t,e,a,n,r,i);if(0===o.length)return[];const s=[];s.push(Or(t.path,t.path,e));for(const e of Wr(t))s.push(e);for(const t of o)s.push(t);return s}const s=[];s.push(Or(t.path,t.path,e));for(const e of Wr(t))s.push(e);if(t.oldId===t.newId)return s;for(const r of jr(t,e,a,n))s.push(r);return s}(_r(t),n,e,a,r,i,o)}(r,t.oldContent??new Uint8Array(0),t.newContent??new Uint8Array(0),e,a,n,i)}function Gr(t,e){const a=function(t){if(void 0===t)return 3;if(!Number.isInteger(t)||t<0)throw cr(`contextLines must be a non-negative integer; got ${t}`);return t}(e?.contextLines);if(0===t.length)return"";const n=e?.pathPrefix??$r;for(const e of t)Dr(e.change,n);const r=function(t){if(void 0===t)return;const e=t.lineKey,a=t.ignoreBlankLines;return void 0!==e&&!0===a?{lineKey:e,ignoreBlankLines:!0}:void 0!==e?{lineKey:e}:!0===a?{ignoreBlankLines:!0}:void 0}(e),i=[];for(const e of t){const t=Vr(e,n,a,r);for(const e of t)i.push(e)}return 0===i.length?"":(i.push(""),i.join("\n"))}const Yr=t=>{const e=t.startsWith("!"),a=e?t.slice(1):t;return jt(a)?{pattern:t,body:a,negated:e,isLiteral:!1,compiled:Bt(a,{anchored:a.includes("/")})}:{pattern:t,body:a,negated:e,isLiteral:!0,compiled:Bt(a,{anchored:!0,withDirSuffix:!0})}},Xr=(t,e)=>{let a=!1;for(const n of t)n.compiled.test(e)&&(a=!n.negated);return a},Jr=e=>new t({code:"INVALID_MERGE_TREE",reason:e}),Qr=e=>new t({code:"INVALID_MERGE_INPUT",reason:e}),Zr=268435456,ti=new TextEncoder;function ei(t){let e=0;for(const a of t)e+=a.length;return e}function ai(t){if(0===t.length)return new Uint8Array(0);const e=ei(t),a=t[t.length-1],n=0===a.length||10!==a[a.length-1],r=new Uint8Array(e+(n?1:0));let i=0;for(const e of t)r.set(e,i),i+=e.length;return n&&(r[i]=10),r}function ni(t,e,a={}){if("diff3"===a.conflictStyle)throw Qr("diff3 conflict style requires base lines — not supported in v1");const n=a.labels?.ours??"ours",r=a.labels?.theirs??"theirs";if(ei(t)+ei(e)>Zr)throw Qr("conflict output exceeds MAX_CONFLICT_OUTPUT_BYTES");const i=a.markerSize??7,o=ti.encode(`${"<".repeat(i)} ${n}\n`),s=ti.encode(`${"=".repeat(i)}\n`),c=ti.encode(`${">".repeat(i)} ${r}\n`),d=ai(t),u=ai(e),f=new Uint8Array(o.length+d.length+s.length+u.length+c.length);let l=0;return f.set(o,l),l+=o.length,f.set(d,l),l+=d.length,f.set(s,l),l+=s.length,f.set(u,l),l+=u.length,f.set(c,l),f}const ri="HEAD",ii=t=>t.slice(0,7),oi=(t,e)=>`${ii(t)} (${e})`,si=t=>`parent of ${t}`,ci=(t,e)=>{const a=oi(t,e);return{ours:ri,theirs:a,base:si(a)}},di=(t,e)=>{const a=oi(t,e);return{ours:ri,theirs:si(a),base:a}},ui={ours:"Updated upstream",theirs:"Stashed changes",base:"Stash base"},fi={ours:"ours",theirs:"theirs",base:""};function li(t,e){const a=[];let n;const r=()=>{void 0!==n&&(a.push({baseStart:n.baseStart,baseEnd:n.baseEnd,replacement:n.replacement}),n=void 0)};for(const a of t)if("common"!==a.kind)if(void 0===n&&(n={baseStart:a.oursStart,baseEnd:a.oursStart,replacement:[]}),"ours-only"===a.kind)n.baseEnd=Math.max(n.baseEnd,a.oursEnd);else for(let t=a.theirsStart;t<a.theirsEnd;t++)n.replacement.push(e[t]);else r();return r(),a}function hi(t,e){return t.baseStart===t.baseEnd?e.baseStart===e.baseEnd?t.baseStart===e.baseStart:t.baseStart>=e.baseStart&&t.baseStart<e.baseEnd:e.baseStart===e.baseEnd?e.baseStart>=t.baseStart&&e.baseStart<t.baseEnd:t.baseStart<e.baseEnd&&e.baseStart<t.baseEnd}function wi(t,e,a,n){const r=[];let i=e;for(const e of n){for(let a=i;a<e.baseStart;a++)r.push(t[a]);for(const t of e.replacement)r.push(t);i=e.baseEnd}for(let e=i;e<a;e++)r.push(t[e]);return r}function mi(t,e){const a=Math.min(t.length,e.length);let n=0;for(;n<a&&Ft(t[n],e[n]);)n++;let r=0;for(;r<a-n&&Ft(t[t.length-1-r],e[e.length-1-r]);)r++;return{prefix:t.slice(0,n),oursMid:t.slice(n,t.length-r),theirsMid:e.slice(n,e.length-r),suffix:t.slice(t.length-r)}}function pi(t){if(!(t.ours.length>0))return"clean-theirs";if(!(t.theirs.length>0))return"clean-ours";const[e]=t.ours,[a]=t.theirs;return 1===t.ours.length&&1===t.theirs.length&&e.baseStart===a.baseStart&&e.baseEnd===a.baseEnd&&function(t,e){if(t.length!==e.length)return!1;for(let a=0;a<t.length;a++)if(!Ft(t[a],e[a]))return!1;return!0}(e.replacement,a.replacement)?"clean-twin":"conflict"}function gi(t){return{kind:"clean",start:t.start,end:t.end,replacement:t.ours.length>0?t.ours[0].replacement:t.theirs[0].replacement}}function yi(t){return t.length>0&&10===t[t.length-1]}function vi(t){let e=0;for(let a=0;a<t.length;a++)e+=t[a].length,a<t.length-1&&!yi(t[a])&&(e+=1);const a=new Uint8Array(e);let n=0;for(let e=0;e<t.length;e++){const r=t[e];a.set(r,n),n+=r.length,e<t.length-1&&!yi(r)&&(a[n]=10,n+=1)}return a}function bi(t,e,a,n){const r=Ht(t,e),i=Ht(t,a),o=r.degraded||i.degraded?[{kind:"conflict",ours:Ct(e),theirs:Ct(a)}]:function(t,e,a){const n=function(t){const e=[];let a=0;for(;a<t.length;){const n=t[a];if("conflict"!==n.classification){e.push(gi(n)),a++;continue}let r=n.end;const i=[...n.ours],o=[...n.theirs];let s=a+1;for(;s<t.length;){const e=t[s];if("conflict"!==e.classification||e.start-r>3)break;i.push(...e.ours),o.push(...e.theirs),r=e.end,s++}e.push({kind:"conflict",start:n.start,end:r,ours:i,theirs:o}),a=s}return e}(function(t){const e=[];let a;for(const n of t)void 0!==a&&hi(n,{baseStart:a.start,baseEnd:a.end})?a.end=Math.max(a.end,n.baseEnd):(a={start:n.baseStart,end:n.baseEnd,ours:[],theirs:[]},e.push(a)),("ours"===n.side?a.ours:a.theirs).push(n);return e}(function(t,e){const a=[...t.map(t=>({...t,side:"ours"})),...e.map(t=>({...t,side:"theirs"}))];return a.sort((t,e)=>t.baseStart-e.baseStart),a}(e,a)).map(t=>({...t,classification:pi(t)}))),r=[],i=t=>{t.length>0&&r.push({kind:"clean",lines:t})};let o=0;for(const e of n){if(i(t.slice(o,e.start)),"clean"===e.kind)i(e.replacement);else{const a=mi(wi(t,e.start,e.end,e.ours),wi(t,e.start,e.end,e.theirs));i(a.prefix),r.push({kind:"conflict",ours:a.oursMid,theirs:a.theirsMid}),i(a.suffix)}o=e.end}return i(t.slice(o)),r}(r.oursLines,li(r.hunks,r.theirsLines),li(i.hunks,i.theirsLines));return"union"===n.favor?function(t){const e=[];for(const a of t)"clean"===a.kind?e.push(...a.lines):e.push(...a.ours,...a.theirs);return{status:"clean",bytes:vi(e)}}(o):function(t,e){const a=[];let n=!1;for(const r of t)"clean"===r.kind?a.push(...r.lines):(n=!0,a.push(ni(r.ours,r.theirs,e)));const r=function(t){let e=0;for(const a of t)e+=a.length;const a=new Uint8Array(e);let n=0;for(const e of t)a.set(e,n),n+=e.length;return a}(a);return n?{status:"conflict",conflictType:"content",markedBytes:r}:{status:"clean",bytes:r}}(o,n)}const ki=new Uint8Array(0);function $i(t,e){return t.id===e.id&&t.mode===e.mode}function xi(t){return t===qt.GITLINK}function Ii(t,e){if(void 0!==t&&t.entries.size>Mt)throw Jr(`${e} FlatTree exceeds MAX_FLAT_TREE_ENTRIES`)}function Ei(t){return{status:"conflict",conflict:t}}function Ti(t,e,a,n){return Ei({type:"modify-delete",path:t,baseId:e.id,baseMode:e.mode,...void 0===a?{}:{ourId:a.id,ourMode:a.mode},...void 0===n?{}:{theirId:n.id,theirMode:n.mode}})}function Di(t,e,a,n){return Ei({type:"type-change",path:t,baseId:e.id,ourId:a.id,theirId:n.id,baseMode:e.mode,ourMode:a.mode,theirMode:n.mode})}function Si(t,e,a,n){return void 0===e?{status:"resolved-known",path:t,id:a.id,mode:a.mode}:$i(e,a)?{status:"resolved-deleted",path:t}:"our"===n?Ti(t,e,a,void 0):Ti(t,e,void 0,a)}function Ai(t){return"file"===zt(t)}function Mi(t){return t===qt.SYMLINK}function Oi(t,e,a,n,r,i){const o=Ai(e.mode),s=function(t,e,a){const n=`${e}~${function(t){return t.replace(/\//g,"_")}(a)}`;let r=n,i=0;for(;t.has(r);)r=`${n}_${i}`,i+=1;return t.add(r),r}(r,t,o?n.ours:n.theirs),c=o?s:t,d=o?t:s;if(void 0===i)return Ei({type:"distinct-types",path:t,ourId:e.id,ourMode:e.mode,theirId:a.id,theirMode:a.mode,ourPath:c,theirPath:d});const u=Ai(i.mode)?s:t;return Ei({type:"distinct-types",path:t,baseId:i.id,baseMode:i.mode,basePath:u,ourId:e.id,ourMode:e.mode,theirId:a.id,theirMode:a.mode,ourPath:c,theirPath:d})}function Ni(t,e){if(t.length>Zr)throw Qr(`contentMerger returned oversize ${e}`)}async function Pi(t,e,a,n){const r={path:t,ourId:e.id,theirId:a.id,ourMode:e.mode,theirMode:a.mode},i=await n(r,void 0,ki,ki);return"clean"===i.status?(Ni(i.bytes,"clean bytes"),e.mode===a.mode?void 0!==i.id?{tag:"resolved",outcome:{status:"resolved-known",path:t,id:i.id,mode:e.mode}}:{tag:"resolved",outcome:{status:"resolved-merged",path:t,bytes:i.bytes,mode:e.mode}}:{tag:"clean-split",bytes:i.bytes}):(Ni(i.markedBytes,"marked bytes"),{tag:"conflict",bytes:i.markedBytes,conflictType:i.conflictType})}function Ci(t,e,a,n,r,i,o){return void 0===a&&void 0===n?{status:"resolved-deleted",path:t}:void 0===a?Si(t,e,n,"their"):void 0===n?Si(t,e,a,"our"):void 0===e?async function(t,e,a,n,r,i){if($i(e,a))return{status:"resolved-known",path:t,id:e.id,mode:e.mode};const o=Ai(e.mode),s=Ai(a.mode),c=Mi(e.mode),d=Mi(a.mode);if(o&&d||c&&s)return Oi(t,e,a,r,i);if(!o||!s)return function(t,e,a){return Ei({type:"add-add",path:t,ourId:e.id,theirId:a.id,ourMode:e.mode,theirMode:a.mode})}(t,e,a);const u=await Pi(t,e,a,n);return"resolved"===u.tag?u.outcome:Ei({type:"add-add",path:t,ourId:e.id,theirId:a.id,ourMode:e.mode,theirMode:a.mode,conflictContent:u.bytes,contentVerdict:"clean-split"===u.tag?"clean":u.conflictType})}(t,a,n,r,i,o):async function(t,e,a,n,r,i,o){const s=$i(e,a),c=$i(e,n);return s&&c?{status:"unchanged",path:t,id:e.id,mode:e.mode}:s?{status:"resolved-known",path:t,id:n.id,mode:n.mode}:c||$i(a,n)?{status:"resolved-known",path:t,id:a.id,mode:a.mode}:function(t,e,a,n,r,i,o){if(xi(a.mode)||xi(n.mode))return xi(a.mode)&&xi(n.mode)&&xi(e.mode)?function(t,e,a,n){return Ei({type:"gitlink",path:t,baseId:e.id,ourId:a.id,theirId:n.id,baseMode:e.mode,ourMode:a.mode,theirMode:n.mode})}(t,e,a,n):Di(t,e,a,n);const s=Mi(a.mode),c=Mi(n.mode);if(s&&c)return function(t,e,a,n){return Ei({type:"content",path:t,baseId:e.id,baseMode:e.mode,ourId:a.id,ourMode:a.mode,theirId:n.id,theirMode:n.mode})}(t,e,a,n);if(s||c)return xi(e.mode)?Di(t,e,a,n):Oi(t,a,n,i,o,e);if(!Ot(e.mode,a.mode))return async function(t,e,a,n,r){const i=await Pi(t,a,n,r);return"resolved"===i.tag?i.outcome:Ei("clean-split"===i.tag?{type:"content",path:t,baseId:e.id,baseMode:e.mode,ourId:a.id,ourMode:a.mode,theirId:n.id,theirMode:n.mode,conflictContent:i.bytes,contentVerdict:"clean"}:{type:i.conflictType,path:t,baseId:e.id,baseMode:e.mode,ourId:a.id,ourMode:a.mode,theirId:n.id,theirMode:n.mode,conflictContent:i.bytes})}(t,e,a,n,r);const d=function(t,e,a){return e.mode===a.mode?e.mode:e.mode===t.mode?a.mode:e.mode}(e,a,n);return async function(t,e,a,n,r,i){const o={path:t,baseId:e.id,ourId:a.id,theirId:n.id,baseMode:e.mode,ourMode:a.mode,theirMode:n.mode},s=await i(o,void 0,ki,ki);return"clean"===s.status?(Ni(s.bytes,"clean bytes"),void 0!==s.id?{status:"resolved-known",path:t,id:s.id,mode:r}:{status:"resolved-merged",path:t,bytes:s.bytes,mode:r}):(Ni(s.markedBytes,"marked bytes"),Ei({type:s.conflictType,path:t,baseId:e.id,ourId:a.id,theirId:n.id,baseMode:e.mode,ourMode:a.mode,theirMode:n.mode,conflictContent:s.markedBytes,mergedMode:r}))}(t,e,a,n,d,r)}(t,e,a,n,r,i,o)}(t,e,a,n,r,i,o)}async function Hi(t,e,a,n,r=fi){Ii(t,"base"),Ii(e,"ours"),Ii(a,"theirs");const i=function(t,e,a){const n=new Set;for(const r of[t,e,a])if(void 0!==r)for(const t of r.entries.keys())n.add(t);if(n.size>Mt)throw Jr("union FlatTree exceeds MAX_FLAT_TREE_ENTRIES");return n}(t,e,a),o=St([...i],t=>t),s=new Set(i),c=[];for(const i of o){const o=Ci(i,t?.entries.get(i),e?.entries.get(i),a?.entries.get(i),n,r,s),d=o instanceof Promise?await o:o;c.push(d)}const d=function(t){const e=[];for(const a of t)"conflict"===a.status&&e.push(a.conflict);return e}(c);return{outcomes:c,conflicts:d,cleanMerge:0===d.length}}const Li="agent=tsgit/0.0",Ri=["multi_ack_detailed","side-band-64k","ofs-delta","thin-pack","no-progress","include-tag","filter",Li],Ui=["report-status","side-band-64k","ofs-delta","atomic","delete-refs",Li],_i="push-cert",Wi=t=>{const e=t.indexOf("=");return e<0?t:t.slice(0,e)},ji=(t,e)=>{const a=new Map;for(const e of t)a.set(Wi(e),e);const n=[];for(const t of e){const e=Wi(t),r=a.get(e);void 0!==r&&n.push(r)}return n},Bi=e=>new t({code:"PKT_LENGTH_RESERVED",value:e}),Fi=e=>new t({code:"PKT_TOO_LARGE",value:e}),zi=e=>new t({code:"INVALID_BASE_URL",reason:e}),qi=(e,a)=>new t({code:"MISSING_SERVICE_HEADER",expected:e,actual:a}),Ki=e=>new t({code:"INVALID_REF_LINE",line:e}),Vi=e=>new t({code:"INVALID_SIDEBAND_CHANNEL",channel:e}),Gi=e=>new t({code:"SIDEBAND_FATAL",message:e}),Yi=e=>new t({code:"INVALID_REPORT_STATUS",line:e}),Xi=(e,a)=>new t({code:"REFSPEC_INVALID",raw:e,reason:a}),Ji=(e,a)=>new t({code:"TOO_MANY_ADVERTISED_REFS",count:e,limit:a}),Qi=(e,a)=>new t({code:"INVALID_FILTER_SPEC",spec:e,reason:a}),Zi=()=>new t({code:"REMOTE_FILTER_UNSUPPORTED"}),to=e=>new t({code:"UNEXPECTED_V2_SECTION",section:e}),eo=e=>new t({code:"V2_COMMAND_UNSUPPORTED",command:e}),ao=(e,a,n)=>new t({code:"TOO_MANY_SECTION_ENTRIES",section:e,count:a,limit:n}),no="blob:limit=",ro="tree:",io=/^(\d+)([kmg])?$/i,oo=/^\d+$/,so=t=>{if(""===t)throw Qi(t,"empty");if("blob:none"===t)return{kind:"blob-none"};if(t.startsWith(no))return(t=>{const e=t.slice(11).match(io);if(null===e)throw Qi(t,"bad-blob-limit");const a=Number(e[1])*(t=>{switch(t?.toLowerCase()){case"k":return 1024;case"m":return 1048576;case"g":return 1073741824;default:return 1}})(e[2]);if(!Number.isSafeInteger(a))throw Qi(t,"bad-blob-limit");return{kind:"blob-limit",bytes:a}})(t);if(t.startsWith(ro))return(t=>{const e=t.slice(5);if(!oo.test(e))throw Qi(t,"bad-tree-depth");const a=Number(e);if(!Number.isSafeInteger(a))throw Qi(t,"bad-tree-depth");return{kind:"tree-depth",depth:a}})(t);throw Qi(t,"unknown-kind")},co=t=>{switch(t.kind){case"blob-none":return"blob:none";case"blob-limit":return`${no}${t.bytes}`;case"tree-depth":return`${ro}${t.depth}`}},uo=new TextEncoder,fo=new TextDecoder("utf-8",{fatal:!1}),lo=/^[0-9a-f]{4}$/i,ho=65520,wo=uo.encode("0000"),mo=uo.encode("0001");uo.encode("0002");const po=t=>{const e=(t+65536).toString(16).slice(-4);return uo.encode(e)},go=(t,e)=>{let a=e.byteLength;for(const e of t){if(e.byteLength>65516)throw new RangeError(`pkt-line: payload too large (${e.byteLength} > 65516)`);a+=e.byteLength+4}const n=new Uint8Array(a);let r=0;for(const e of t)n.set(po(e.byteLength+4),r),r+=4,n.set(e,r),r+=e.byteLength;return n.set(e,r),n},yo=t=>go(t,wo),vo=t=>go(t,new Uint8Array(0)),bo=e=>{const a=fo.decode(e.subarray(0,4));if(!lo.test(a))throw new t({code:"INVALID_PKT_LENGTH",value:a});const n=Number.parseInt(a,16);if(n>ho)throw Fi(n);return n},ko=(e,a)=>{const n=a?.v2??!1;return{[Symbol.asyncIterator]:()=>async function*(e,a){const n=new xo;for await(const t of e)n.accept(t),yield*Io(n,a);if(n.used>0)throw new t({code:"PKT_TRUNCATED",remaining:n.used})}(e,n)}},$o=(t,e,a)=>{if(0===t)return{kind:"flush",consume:4};if(1===t){if(!a)throw Bi(1);return{kind:"delim",consume:4}}if(2===t){if(!a)throw Bi(2);return{kind:"response-end",consume:4}}if(t<4)throw Bi(t);return e<t?{kind:"wait"}:{kind:"data",consume:t}};class xo{acc=new Uint8Array(ho);used=0;accept(t){if(this.used+t.byteLength<=ho)return this.acc.set(t,this.used),void(this.used+=t.byteLength);const e=Math.max(0,4-this.used),a=t.subarray(0,e);throw this.acc.set(a,this.used),this.used+=a.byteLength,bo(this.acc),Fi(this.used)}drop(t){this.acc.copyWithin(0,t,this.used),this.used-=t}slice(t,e){return this.acc.slice(t,e)}}function*Io(t,e){for(;t.used>=4;){const a=bo(t.acc),n=$o(a,t.used,e);if("wait"===n.kind)return;if("data"===n.kind){const e=t.slice(4,n.consume);t.drop(n.consume),yield{kind:"data",payload:e};continue}t.drop(n.consume),yield{kind:n.kind}}}const Eo=new TextDecoder("utf-8",{fatal:!1}),To=new TextEncoder,Do=(t,e)=>{const a=0===e.length?"":`\0${e.join(" ")}`;return To.encode(`${t.oldId} ${t.newId} ${t.name}${a}\n`)},So=t=>[To.encode("certificate version 0.1\n"),To.encode(`pusher ${t.pusher}\n`),To.encode(`pushee ${t.pushee}\n`),To.encode(`nonce ${t.nonce}\n`),To.encode("\n"),...t.updates.map(t=>Do(t,[]))],Ao=t=>t.endsWith("\n")?t.slice(0,-1):t,Mo=t=>{if(t.startsWith("ok "))return{name:t.slice(3),accepted:!0};if(t.startsWith("ng ")){const e=t.slice(3),a=e.indexOf(" ");if(a<0)throw Yi(t);return{name:e.slice(0,a),accepted:!1,reason:e.slice(a+1)}}throw Yi(t)},Oo=async t=>{const e=await(async t=>{const e=[];for await(const a of t){if("data"!==a.kind)return e;e.push(Ao(Eo.decode(a.payload)))}return e})(t);if(0===e.length)throw Yi("");const[a,...n]=e,r=(t=>{if("unpack ok"===t)return{ok:!0};if(t.startsWith("unpack "))return{ok:!1,error:t.slice(7)};throw Yi(t)})(a);return r.ok?{unpackOk:!0,refUpdates:n.map(Mo)}:{unpackOk:!1,unpackError:r.error,refUpdates:[]}},No=new TextDecoder("utf-8",{fatal:!1}),Po=(t,e)=>{if(t)try{t(e)}catch{}},Co=(t,e)=>({[Symbol.asyncIterator]:()=>async function*(t,e){for await(const a of t){if("data"!==a.kind)return;if(0===a.payload.byteLength)throw Vi(-1);const t=a.payload[0],n=a.payload.subarray(1);if(1!==t){if(2!==t){if(3===t){const t=No.decode(n);throw Po(e.onError,t),Gi(t)}throw Vi(t)}Po(e.onProgress,No.decode(n))}else yield n}}(t,e)}),Ho=new TextDecoder("utf-8",{fatal:!1}),Lo=new TextEncoder,Ro=/^[0-9a-f]{40}([0-9a-f]{24})?$/i,Uo=/^# service=(?<service>[^\n]+)\n?$/,_o=5e5,Wo=(t,e)=>{let a;try{a=new URL(t)}catch{throw zi("invalid URL")}if(""!==a.hash)throw zi("fragment must not be set");const n=a.pathname.endsWith("/")?a.pathname.slice(0,-1):a.pathname;return`${a.protocol}//${a.host}${n}/info/refs${""===a.search?`?service=${e}`:`${a.search}&service=${e}`}`},jo=t=>t.endsWith("\n")?t.slice(0,-1):t,Bo=t=>{if(!Ro.test(t))throw Ki(t);return Kt.from(t)},Fo=t=>{const e=t.indexOf(" ");if(e<0)throw Ki(t);const a=t.slice(0,e),n=t.slice(e+1);if(0===n.length)throw Ki(t);return{id:a,name:n}},zo=async(t,e,a)=>{const n=((t,e)=>{if(t.done||"data"!==t.value.kind)throw qi(e,"");const a=jo(Ho.decode(t.value.payload)),n=Uo.exec(`${a}\n`),r=n?.groups?.service;if(void 0===r)throw qi(e,a);if(r!==e)throw qi(e,r);return r})(e,a),r=await t.next();if(r.done||"flush"!==r.value.kind)throw qi(a,n)},qo=(e,a,n)=>{if(e.byName.has(a))throw(e=>new t({code:"DUPLICATE_REF",name:e}))(a);e.refs.push({id:n,name:a}),e.byName.set(a,e.refs.length-1)},Ko=(e,a,n)=>{if(void 0===a){const a=(e=>{const a=e.indexOf("\0");if(a<0)throw new t({code:"MISSING_CAPABILITIES"});const n=e.slice(0,a),r=e.slice(a+1),i=n.indexOf(" ");if(i<0)throw Ki(e);const o=n.slice(0,i),s=n.slice(i+1);if(0===s.length)throw Ki(e);return{id:o,name:s,tail:r}})(n);return qo(e,a.name,Bo(a.id)),(t=>{const e=new Map;for(const a of t)e.set(Wi(a),a);return Array.from(e.values())})(a.tail.split(" ").filter(t=>t.length>0))}if(n.endsWith("^{}"))return((t,e)=>{const a=e.slice(0,-3),n=Fo(a),r=Bo(n.id),i=t.byName.get(n.name);if(void 0===i)throw Ki(e);t.refs[i]={...t.refs[i],peeled:r}})(e,n),a;const r=Fo(n);return qo(e,r.name,Bo(r.id)),a},Vo=async(t,e,a)=>{const n=t[Symbol.asyncIterator]();try{(a?.servicePrologue??1)&&await(async(t,e)=>{const a=await t.next();await zo(t,a,e)})(n,e);const{capabilities:t,refs:r}=await(async t=>{const e={refs:[],byName:new Map};let a,n=await t.next();for(;!n.done&&"data"===n.value.kind;){if(e.refs.length>=_o)throw Ji(e.refs.length+1,_o);const r=jo(Ho.decode(n.value.payload));a=Ko(e,a,r),n=await t.next()}return{capabilities:a??[],refs:e.refs}})(n),i=((t,e)=>{const a=e.find(t=>"HEAD"===t.name);if(a)return a;const n=t.find(t=>t.startsWith("symref=HEAD:"));if(!n)return;const r=n.slice(12),i=e.find(t=>t.name===r);return i?{name:"HEAD",id:i.id}:void 0})(t,r);return i?{capabilities:t,refs:r,head:i}:{capabilities:t,refs:r}}finally{await(n.return?.())}},Go=t=>Lo.encode(`have ${t}\n`),Yo=(t=>{if(t.byteLength>65516)throw new RangeError(`pkt-line: payload too large (${t.byteLength} > 65516)`);const e=t.byteLength+4,a=new Uint8Array(e);return a.set(po(e),0),a.set(t,4),a})(Lo.encode("done\n")),Xo=e=>{const a=jo(e).split(" "),n=Kt.from(a[1]),r=a[2];if(void 0===r)return{id:n,status:"ack"};if("continue"===r||"common"===r||"ready"===r)return{id:n,status:r};throw new t({code:"UNKNOWN_ACK_STATUS",value:r})},Jo="shallow ",Qo="unshallow ",Zo=(t,e)=>{const a=jo(t),n=a.slice(e.length);if(!Ro.test(n))throw Ki(a);return Kt.from(n)},ts=(t,e)=>t.startsWith(Jo)?(e.shallow.push(Zo(t,Jo)),!0):!!t.startsWith(Qo)&&(e.unshallow.push(Zo(t,Qo)),!0),es=new WeakMap,as="sha1",ns=new Set(["ls-refs","fetch"]),rs=new TextDecoder,is=async t=>{const e=await t.next();var a;if(!e.done&&"data"===e.value.kind)return(a=rs.decode(e.value.payload)).endsWith("\n")?a.slice(0,-1):a},os=(e,a)=>{const[n,r]=(t=>{const e=t.indexOf("=");return-1===e?[t,void 0]:[t.slice(0,e),t.slice(e+1)]})(a);if("agent"!==n){if("object-format"!==n)((t,e,a)=>{if(ns.has(e)&&(t.commands.add(e),"fetch"===e))for(const e of(t=>void 0===t?[]:t.split(" ").filter(t=>t.length>0))(a))t.fetchFeatures.add(e)})(e,n,r);else if(e.objectFormat=r??"",e.objectFormat!==as)throw new t({code:"UNSUPPORTED_OBJECT_FORMAT",format:e.objectFormat})}else e.agent=r},ss=["acknowledgments","shallow-info","wanted-refs","packfile"],cs=new TextEncoder,ds=new TextDecoder,us=t=>ss.includes(t),fs=t=>t.endsWith("\n")?t.slice(0,-1):t,ls=(t,e,a)=>{const n=vo([cs.encode(`command=${t}\n`),cs.encode(`${Li}\n`),cs.encode("object-format=sha1\n")]),r=vo([...e.map(t=>cs.encode(`${t}\n`)),...a]);return((...t)=>{const e=t.reduce((t,e)=>t+e.byteLength,0),a=new Uint8Array(e);let n=0;for(const e of t)a.set(e,n),n+=e.byteLength;return a})(n,mo,r,wo)};async function*hs(t,e){for(;;){const a=await t.next();if(a.done||"data"!==a.value.kind)return void e(!a.done&&"delim"===a.value.kind);yield a.value}}const ws=new TextEncoder,ms=new TextDecoder,ps=_o;async function*gs(t,e){let a=0;for await(const n of e){if(a+=1,a>ps)throw ao(t,a,ps);yield n}}const ys=t=>ws.encode(`want ${t}\n`),vs=t=>ws.encode(`have ${t}\n`),bs=ws.encode("done\n"),ks=async t=>{const e=[];let a=!1,n=!1;for await(const r of t){const t=ms.decode(r.payload);t.startsWith("ACK ")?e.push(Xo(t)):t.startsWith("NAK")?a=!0:n=!0}return{acks:e,nak:a,ready:n}},$s=async t=>{const e={shallow:[],unshallow:[]};for await(const a of t)ts(ms.decode(a.payload),e);return e},xs=t=>{const e=t.indexOf(" "),a=t.slice(e+1).replace(/\n$/,"");return{id:Kt.from(t.slice(0,e)),name:a}},Is=async t=>{const e=[];for await(const a of t)e.push(xs(ms.decode(a.payload)));return e},Es=new TextEncoder,Ts=new TextDecoder,Ds=/^[0-9a-f]{40}([0-9a-f]{24})?$/i,Ss=t=>Es.encode(`ref-prefix ${t}\n`),As=t=>t.endsWith("\n")?t.slice(0,-1):t,Ms=(t,e)=>{const a=t.find(t=>t.startsWith(e));return void 0===a?void 0:a.slice(e.length)},Os=t=>{const e=t.indexOf(" ");if(e<0)throw Ki(t);const a=t.slice(0,e);if("unborn"!==a&&!Ds.test(a))throw Ki(t);const n=t.slice(e+1),r=n.indexOf(" "),i=-1===r?n:n.slice(0,r);if(0===i.length)throw Ki(t);const o=-1===r?[]:n.slice(r+1).split(" "),s=Ms(o,"symref-target:");if(void 0!==s)return{name:i,oidToken:a,symrefTarget:s};const c=Ms(o,"peeled:");return void 0===c?{name:i,oidToken:a}:{name:i,oidToken:a,peeled:c}},Ns=(t,e)=>{if(!Ds.test(t))throw Ki(e);return Kt.from(t)},Ps=(t,e,a)=>{if(t.length>=_o)throw Ji(t.length+1,_o);const n=Ns(e.oidToken,a);t.push(void 0===e.peeled?{id:n,name:e.name}:{id:n,name:e.name,peeled:Ns(e.peeled,a)})},Cs={second:1,minute:60,hour:3600,day:86400,week:604800,month:2592e3,year:31536e3},Hs=/^(\d{4})-(\d{2})-(\d{2})(?: (\d{2}):(\d{2}):(\d{2}))?$/,Ls=/^(\d+)[ .]([a-z]+?)s?(?:[ .]ago)?$/;function Rs(t,e){const a=t.trim().toLowerCase();return"now"===a?e:"yesterday"===a?e-86400:function(t){const e=Hs.exec(t);if(null===e)return;const[,a,n,r,i,o,s]=e,c=Number(a),d=Number(n),u=Number(r),f=void 0===i?0:Number(i),l=void 0===o?0:Number(o),h=void 0===s?0:Number(s);if(d<1||d>12)return;if(u<1||u>function(t,e){return 2===e&&function(t){return t%4==0&&t%100!=0||t%400==0}(t)?29:Us[e-1]}(c,d))return;if(f>23)return;if(l>59)return;if(h>59)return;const w=new Date(c,d-1,u,f,l,h);return w.setFullYear(c),Math.floor(w.getTime()/1e3)}(a)??function(t,e){const a=Ls.exec(t);if(null===a)return;const[,n,r]=a,i=Cs[r];return void 0===i?void 0:e-Number(n)*i}(a,e)}const Us=[31,28,31,30,31,30,31,31,30,31,30,31],_s=t=>[t,`refs/${t}`,`refs/tags/${t}`,`refs/heads/${t}`,`refs/remotes/${t}`,`refs/remotes/${t}/HEAD`],Ws=t=>`commit (cherry-pick): ${t}`,js=t=>`commit: ${t}`,Bs=t=>`branch: Created from ${t}`,Fs=t=>`reset: moving to ${t}`,zs=t=>`clone: from ${t}`,qs=t=>`fetch ${t}: storing head`,Ks=t=>`revert: ${t}`,Vs=t=>`rebase (start): checkout ${t}`,Gs=t=>`rebase (pick): ${t}`,Ys=t=>`rebase (reword): ${t}`,Xs=t=>`rebase (continue): ${t}`,Js=(t,e)=>`rebase (finish): ${t} onto ${e}`,Qs=t=>`rebase (abort): returning to ${t}`,Zs="merge",tc="rebase",ec="cherry-pick",ac="revert",nc=`${Zs} --abort`,rc=`${ec} --continue`,ic=`${ec} --skip`,oc=`${ec} --abort`,sc=`${ac} --continue`,cc=`${ac} --skip`,dc=`${ac} --abort`,uc=t=>`${t.layout.gitDir}/${Vt}`,fc=t=>`${t.layout.gitDir}/${Gt}`,lc=t=>`${t.layout.gitDir}/${Yt}`,hc=async(t,e)=>{await t.fs.writeUtf8(fc(t),e)},wc=async(t,e)=>{await t.fs.writeUtf8(lc(t),`${e}\n`)},mc=async t=>{const e=uc(t);if(!await t.fs.exists(e))return;const a=(await t.fs.readUtf8(e)).trim();return 0!==a.length?Kt.from(a):void 0},pc=async t=>{const e=fc(t);if(await t.fs.exists(e))return t.fs.readUtf8(e)},gc=async t=>{for(const e of[uc(t),fc(t)])await t.fs.exists(e)&&await t.fs.rm(e)},yc=async t=>{const e=fc(t);await t.fs.exists(e)&&await t.fs.rm(e)},vc=re.from("HEAD"),bc=async e=>{const a=`${e.layout.gitDir}/HEAD`;if(!await e.fs.exists(a))throw new t({code:"NOT_A_REPOSITORY",path:e.layout.workDir});return e.layout.bare?e.layout.gitDir:e.layout.workDir},kc=["excludesfile","attributesfile"],$c=async t=>{const e=await bc(t);return await(async t=>{const[e,i]=await Promise.all([ee(t,"core",void 0,kc),ae(t)]);if(void 0!==e&&(void 0===i||e.line<i.line))throw a(e.key,e.source,e.line);if(void 0!==i){if("numeric"===i.failure.kind)throw n(i.key,i.source,i.failure.value,i.failure.reason);throw r(i.failure.level)}})(t),e},xc=async(e,a)=>{if(await(async t=>{const e=await ne(t);return e.core?.bare??!1})(e))throw(e=>new t({code:"BARE_REPOSITORY",operation:e}))(a)},Ic=async e=>{const a=`${e.layout.gitDir}/HEAD`;let n;try{n=await e.fs.readUtf8(a)}catch(e){if(e instanceof t&&"FILE_NOT_FOUND"===e.data.code)throw Zt(vc);throw e}const r=te(n);return"symbolic"===r.type?{kind:"symbolic",target:r.target}:{kind:"direct",id:r.target}},Ec=t=>"symbolic"===t.kind?t.target:void 0,Tc=[{file:Vt,operation:Zs},{file:Xt,operation:ec},{file:Jt,operation:ac},{file:Qt,operation:tc}],Dc=async(t,a={})=>{const n=a.except,r=t=>Array.isArray(n)?n.includes(t):n===t,i=await Promise.all(Tc.map(e=>t.fs.exists(`${t.layout.gitDir}/${e.file}`)));for(let t=0;t<Tc.length;t+=1){const a=Tc[t];if(void 0!==a&&!r(a.operation)&&!0===i[t])throw e(a.operation)}},Sc=t=>{if("object"!=typeof t)return 7;const e=(t=>{if(!/^[+-]?[0-9]+$/.test(t))return;const e=Number(t);return e>2147483647?void 0:e})(t.set);return void 0!==e&&e>0?e:7},Ac=(t,e)=>{switch(t){case"O":return e.O;case"A":return e.A;case"B":return e.B;case"L":return e.L;case"P":return e.P;case"S":return e.S;case"X":return e.X;case"Y":return e.Y;case"%":return"%";default:return`%${t}`}},Mc=async(t,e)=>{const a=await ie(t),n=await oe(t,e);if("commit"!==n.type)throw se("commit",n.type,e);const r=await ce(t);try{const e=await de(t),i=await ue(t,{targetTree:n.data.tree,currentIndex:e,force:!0,forceRewriteAll:!0,...void 0!==a?{sparse:a}:{}});await r.commit(i.newIndexEntries)}finally{await r.release()}},Oc=async t=>{if(await $c(t),await xc(t,nc),void 0===await mc(t))throw i(Zs);const e=await(async t=>{const e=lc(t);if(!await t.fs.exists(e))return;const a=(await t.fs.readUtf8(e)).trim();return 0!==a.length?Kt.from(a):void 0})(t);if(void 0===e)throw i(Zs);const a=await Ic(t);if("symbolic"!==a.kind)throw o(nc,"cannot abort with detached HEAD");return await Mc(t,e),await fe(t,a.target,e,{reflogMessage:Fs("HEAD")}),await gc(t),{origHead:e,branch:a.target}},Nc=(t,e,a,n)=>({ctimeSeconds:Math.floor(t.ctimeMs/1e3),ctimeNanoseconds:0,mtimeSeconds:Math.floor(t.mtimeMs/1e3),mtimeNanoseconds:0,dev:t.dev,ino:t.ino,mode:e,uid:t.uid,gid:t.gid,fileSize:t.size,id:a,flags:Pt,path:n}),Pc=le,Cc=(t,e)=>he(t.layout.workDir,e),Hc=async(t,e)=>{const a=Pc(e),n=Cc(t,a);let r;try{r=await t.fs.lstat(n)}catch{throw s({localChanges:[a],untracked:[]})}if(!r.isFile&&!r.isSymbolicLink)throw s({localChanges:[a],untracked:[]});await t.fs.rm(n)},Lc=async(t,e,a)=>{const n=Pc(e),r=Pc(a);await Rc(t,Cc(t,n),Cc(t,r))},Rc=async(t,e,a)=>{const n=await t.fs.lstat(e);if(n.isDirectory&&!n.isSymbolicLink){for(const n of await t.fs.readdir(e))await Rc(t,`${e}/${n.name}`,`${a}/${n.name}`);return void await t.fs.rmRecursive(e)}const r=c(a);""!==r&&await t.fs.mkdir(r),await t.fs.rename(e,a)},Uc=new TextEncoder,_c=t=>{for(const e of t){const t=e.startsWith("!")?e.slice(1):e;Pc(t),Wc(e)}const e=(t=>t.map(Yr))(t),a=e.filter(Fc).map(t=>qc(t)),n=e.some(zc);return{matcher:e,literalMustMatch:a,hasGlob:n}},Wc=t=>{if(Uc.encode(t).byteLength>256)throw u("paths","pattern exceeds max length 256 bytes");if(jc(t)>4)throw u("paths","pattern exceeds max **-token count 4")},jc=t=>{let e=0,a=0;for(;a<t.length;)"*"!==t[a]||"*"!==t[a+1]?a+=1:(e+=1,a+=2);return e},Bc=(t,e)=>{if(0===t.length)return;const a=new Set(e);for(const n of t)if(!a.has(n)&&!e.some(t=>t.startsWith(`${n}/`)))throw d(n)},Fc=t=>!t.negated&&t.isLiteral,zc=t=>!t.negated&&!t.isLiteral,qc=t=>t.body,Kc=new Set(["FILE_NOT_FOUND","INVALID_INDEX_HEADER","INVALID_INDEX_ENTRY"]),Vc=async(t,e,a={})=>{await $c(t),await xc(t,"add"),await Dc(t,{except:[Zs,ec,ac,tc]});const n=await we(t);if(!0===a.all){if(0!==e.length)throw u("all","pathspec must be empty when all=true");return Qc(t,void 0,n)}if(0===e.length)throw f();return Gc(t,e,n)},Gc=async(t,e,a)=>{const{matcher:n,literalMustMatch:r,hasGlob:i}=_c(e);return!i&&await Xc(t,r)?Yc(t,r,a):Jc(t,n,r,a)},Yc=async(t,e,a)=>{const n=await ce(t);try{const r=await ad(t),i=new Map(r),o=[],s=[];for(const n of e){const e=await nd(t,n,a);if("missing"===e)throw d(n);const c=r.get(n);i.set(n,e),void 0===c?o.push(n):c.id===e.id&&c.mode===e.mode||s.push(n)}return await n.commit(Array.from(i.values())),{added:o,modified:s,removed:[]}}finally{await n.release()}},Xc=async(t,e)=>{if(0===e.length)return!1;for(const a of e){const e=await t.fs.lstat(he(t.layout.workDir,a)).catch(()=>{});if(void 0===e)return!1;if(e.isDirectory&&!e.isSymbolicLink)return!1}return!0},Jc=async(t,e,a,n)=>{const r=await me(t),i=async(t,a)=>!!await r(t,a)||!a&&!Xr(e,t),o=await ce(t);try{const e=await ad(t),r=new Map(e),s=[],c=[],d=[],u=new Set;for await(const a of pe(t,{ignore:i})){const i=await ed(t,a,e,u,n);void 0!==i&&(s.push(i.path),r.set(i.path,i.entry),"added"===i.kind?c.push(i.path):"modified"===i.kind&&d.push(i.path))}return Bc(a,s),c.sort(),d.sort(),await o.commit(Array.from(r.values())),{added:c,modified:d,removed:[]}}finally{await o.release()}},Qc=async(t,e,a)=>{const n=await me(t),r=await ce(t);try{const e=await ad(t),i=new Map(e),o=new Set,s=[],c=[];for await(const r of pe(t,{ignore:n})){const n=await ed(t,r,e,o,a);void 0!==n&&(i.set(n.path,n.entry),"added"===n.kind?s.push(n.path):"modified"===n.kind&&c.push(n.path))}const d=await Zc(e,o,n);for(const t of d)i.delete(t);return s.sort(),c.sort(),d.sort(),await r.commit(Array.from(i.values())),{added:s,modified:c,removed:d}}finally{await r.release()}},Zc=async(t,e,a)=>{const n=[];for(const[r,i]of t)e.has(r)||i.flags.skipWorktree||await td(r,a)||n.push(r);return n},td=async(t,e)=>{if(await e(t,!1))return!0;const a=t.split("/");for(let t=1;t<a.length;t+=1){const n=a.slice(0,t).join("/");if(await e(n,!0))return!0}return!1},ed=async(t,e,a,n,r)=>{const{path:i,stat:o}=e;if(n.add(i),o.size>ge)throw l(i,o.size,ge);const s=await rd(t,i,o,r),c=a.get(i);return void 0===c?{kind:"added",path:i,entry:s}:c.id!==s.id||c.mode!==s.mode?{kind:"modified",path:i,entry:s}:{kind:"unchanged",path:i,entry:s}},ad=async e=>{try{const t=await de(e),a=new Map;for(const e of t.entries)a.set(e.path,e);return a}catch(e){if(e instanceof t&&Kc.has(e.data.code))return new Map;throw e}},nd=async(t,e,a)=>{const n=await t.fs.lstat(he(t.layout.workDir,e)).catch(()=>{});return void 0===n?"missing":rd(t,e,n,a)},rd=async(t,e,a,n)=>{const r=await t.fs.lstat(he(t.layout.workDir,e));if(r.isSymbolicLink!==a.isSymbolicLink||r.isDirectory!==a.isDirectory||r.isFile!==a.isFile)throw h();if(r.size>ge)throw l(e,r.size,ge);const i=ke(r),o=await od(t,e,r),s=await id(t,e,o,r.isSymbolicLink,n),c=await ye(t,{type:"blob",id:"",content:s});return Nc(r,i,c,e)},id=async(t,e,a,n,r)=>{if(void 0===r||void 0===t.command||n)return a;const i=await ve(t,r,e);if("external"!==i.kind||void 0===i.clean)return a;const o=await be(t,t.command,i.clean,a);if(o.ok)return o.bytes;if(i.required)throw w(e,i.name,o.exitCode);return a},od=async(t,e,a)=>{if(a.isSymbolicLink){const a=(new TextEncoder).encode(await t.fs.readlink(he(t.layout.workDir,e)));if(a.byteLength>ge)throw l(e,a.byteLength,ge);return a}return(async(t,e)=>{const a=Pc(e);return t.fs.read(Cc(t,a))})(t,e)},sd=async(t,e,a)=>{let n=e;for(let e=0;e<5;e+=1){const e=await oe(t,n);if(e.type===a)return n;if("tag"!==e.type){if("tree"===a&&"commit"===e.type)return e.data.tree;throw $e(n)}n=e.data.object}throw $e(n)},cd=async(t,e,a,n)=>{const r=await dd(t,e,a);if(void 0===r)throw m(n,a);return r},dd=async(t,e,a)=>{const n=a.split("/"),r=n.length-1;let i="string"==typeof e?await xe(t,e):e;for(let e=0;e<r;e+=1){const a=ud(i,n[e]);if(void 0===a)return;const r=await oe(t,a.id);if("tree"!==r.type)return;i=r}return ud(i,n[r])},ud=(t,e)=>t.entries.find(t=>t.name===e),fd=/^[0-9a-f]{40}$/,ld=/^[0-9a-f]{4,39}$/,hd=/^[0-9a-f]{38}$/,wd=async(t,e)=>{const a=Ie(Ee(t),e.slice(0,2));if(!await t.fs.exists(a))return[];const n=e.slice(2),r=[];for(const i of await t.fs.readdir(a))i.isFile&&hd.test(i.name)&&i.name.startsWith(n)&&r.push(e.slice(0,2)+i.name);return r},md=async(t,e)=>{const a=await Te(t).all(),n=[];for(const t of a)for(const a of De(t.index,e))n.push(a);return n},pd=async(t,e)=>{if(fd.test(e))return e;if(!ld.test(e))return;const[a,n]=await Promise.all([wd(t,e),md(t,e)]),r=[...new Set([...a,...n])];if(0!==r.length){if(1===r.length)return r[0];throw p(e,r.slice(0,16))}},gd=new Set(["commit","tree","blob","tag"]),yd=/^:(\d):(.+)$/,vd=/^[0-9a-f]{1,3}$/,bd=t=>{throw g(t)},kd=t=>{if(""===t&&bd(t),t.startsWith(":"))return xd(t);const e=$d(t);return-1!==e?{kind:"tree-path",rev:t.slice(0,e),path:t.slice(e+1)}:t.includes("@{")?Td(t):Id(t)},$d=t=>{let e=!1;for(let a=0;a<t.length;a+=1)if(e||"@"!==t[a]||"{"!==t[a+1]){if(e&&"}"===t[a])e=!1;else if(!e&&":"===t[a])return a}else e=!0,a+=1;return-1},xd=t=>{const e=yd.exec(t);null===e&&bd(t);const a=e[2],n=Number(e[1]);return n>3&&bd(t),{kind:"index-stage",stage:n,path:a}},Id=t=>{const e=Dd(t),a=-1===e?t:t.slice(0,e);return""===a&&bd(t),vd.test(a)&&-1===e&&bd(t),{kind:"ref-or-hex",base:a,operations:-1===e?[]:Sd(t,e)}},Ed=/^\d+$/,Td=t=>{const e=t.indexOf("@{"),a=t.indexOf("}",e+2),n=t.slice(0,e),r=t.slice(e+2,a);return""===r&&bd(t),{kind:"ref-or-hex",base:n,reflog:Ed.test(r)?{kind:"index",n:Number(r)}:{kind:"date",raw:r},operations:Sd(t.slice(a+1),0)}},Dd=t=>{for(let e=0;e<t.length;e+=1){const a=t[e];if("~"===a||"^"===a)return e}return-1},Sd=(t,e)=>{const a=[];let n=e;for(;n<t.length;){const e=t[n];if("~"===e){const e=Ad(t,n);a.push(e.op),n=e.next}else if("^"===e){const e=Md(t,n);a.push(e.op),n=e.next}else bd(t)}return a},Ad=(t,e)=>{let a=e+1;for(;a<t.length&&Od(t.charCodeAt(a));)a+=1;return a===e+1&&bd(t),{op:{kind:"ancestor",n:Number(t.slice(e+1,a))},next:a}},Md=(t,e)=>{if("{"===t[e+1]){const a=t.indexOf("}",e+2);-1===a&&bd(t);const n=t.slice(e+2,a);return gd.has(n)||bd(t),{op:{kind:"peel",target:n},next:a+1}}let a=e+1;for(;a<t.length&&Od(t.charCodeAt(a));)a+=1;const n=t.slice(e+1,a);return{op:{kind:"parent",n:""===n?1:Number(n)},next:a}},Od=t=>t>=48&&t<=57,Nd=async(t,e)=>{await $c(t);const a=kd(e);return Pd(t,a,e)},Pd=async(t,e,a)=>{if("index-stage"===e.kind)return zd(t,e);if("tree-path"===e.kind)return qd(t,e.rev,e.path);const n=Math.floor(Date.now()/1e3);let r=void 0!==e.reflog?await Hd(t,e.base,e.reflog,n,a):await Cd(t,e.base);for(const a of e.operations)r=await Bd(t,r,a);return r},Cd=async(t,e)=>{if(/^[0-9a-f]{40}$/.test(e))return Kt.from(e);for(const a of _s(e))try{return await Ae(t,a)}catch{}const a=await pd(t,e);if(void 0!==a)return a;throw $e(e)},Hd=async(t,e,a,n,r)=>{const i=""===e?await Ld(t):await Rd(t,e),o=await Se(t,i);if(0===o.length)throw g(r);return"index"===a.kind?Wd(o,a.n,i):jd(o,a.raw,n,r)},Ld=async t=>{const e=await Me(t).resolveDirect("HEAD");return"symbolic"===e.kind?e.target:"HEAD"},Rd=async(t,e)=>{const a=Ud(e),n=_s(a);for(const e of n)if(await Oe(t,e))return e;for(const e of n)if(await _d(t,e))return e;return a},Ud=t=>{try{return Pe(t)}catch{throw g(t)}},_d=async(t,e)=>{try{return await Ae(t,e),!0}catch{return!1}},Wd=(t,e,a)=>{const n=t[t.length-1-e];if(void 0===n)throw Ne(a,e,t.length);return n.newId},jd=(t,e,a,n)=>{const r=Rs(e,a);if(void 0===r)throw g(n);for(let e=t.length-1;e>=0;e-=1){const a=t[e];if(a.identity.timestamp<=r)return a.newId}return t[0].oldId},Bd=async(t,e,a)=>{if("parent"===a.kind)return Fd(t,e,a.n);if("ancestor"===a.kind){let n=e;for(let e=0;e<a.n;e+=1)n=await Fd(t,n,1);return n}return sd(t,e,a.target)},Fd=async(t,e,a)=>{const n=await oe(t,e);if("commit"!==n.type)throw $e(e);const r=n.data.parents[a-1];if(void 0===r)throw $e(e);return r},zd=async(t,e)=>{const a=await de(t);for(const t of a.entries)if(t.path===e.path&&t.flags.stage===e.stage)return t.id;throw $e(`${e.stage}:${e.path}`)},qd=async(t,e,a)=>{const n=await Pd(t,kd(e),e),r=await sd(t,n,"tree");if(""===a)return r;const i=await xe(t,r);return(await cd(t,i,a,e)).id};async function Kd(t,e){await bc(t);const a=await Nd(t,e.treeish),n=await async function(t,e){const a=await oe(t,e);if("commit"===a.type)return{tree:a.data.tree,commit:e,commitTime:a.data.committer.timestamp};if("tag"===a.type){const a=await sd(t,e,"commit"),n=await oe(t,a);if("commit"!==n.type)throw se("commit",n.type,a);return{tree:n.data.tree,commit:a,commitTime:n.data.committer.timestamp}}if("tree"===a.type)return{tree:e};throw se("tree",a.type,e)}(t,a),{tree:r}=n;if("commit"in n){const{commit:e,commitTime:a}=n;return{tree:r,commit:e,commitTime:a,entries:Vd(t,r)}}return{tree:r,entries:Vd(t,r)}}async function*Vd(t,e){for await(const a of Ce(t,e,{maxEntries:Number.MAX_SAFE_INTEGER,maxDepth:Number.MAX_SAFE_INTEGER})){const{path:e,id:n,mode:r}=a;if(r===qt.DIRECTORY||r===qt.GITLINK)yield{path:e,mode:r,oid:n};else{const a=await He(t,n);yield{path:e,mode:r,oid:n,content:a.content}}}}const Gd=(t,e)=>{const a=Yd(e),n=[],r=[];for(const e of t)Xd(e,a,n,r);return{passed:n,kept:r}},Yd=t=>{const e=new Map;for(const a of t.hunks){if("common"!==a.kind)continue;const t=a.theirsEnd-a.theirsStart;for(let n=0;n<t;n+=1)e.set(a.theirsStart+n,a.oursStart+n)}return e},Xd=(t,e,a,n)=>{const r=t.sourceStart+t.count;let i=t.sourceStart;for(;i<r;){const o=t.finalStart+(i-t.sourceStart),s=e.get(i);if(void 0===s){let t=i+1;for(;t<r&&!e.has(t);)t+=1;n.push({finalStart:o,count:t-i,sourceStart:i}),i=t}else{let t=i+1,n=s+1;for(;t<r&&e.get(t)===n;)t+=1,n+=1;a.push({finalStart:o,count:t-i,sourceStart:s}),i=t}}},Jd=async(t,e)=>{if(/^[0-9a-f]{40}$/.test(e))return e;for(const a of _s(e))try{return await Ae(t,a,{peel:!0})}catch{}const a=await pd(t,e);if(void 0!==a)return a;throw Zt(e)},Qd=async(t,e)=>{const a=await oe(t,e);if("commit"!==a.type)throw se("commit",a.type,e);return a.data},Zd=async(t,e)=>(await Qd(t,e)).tree,tu=async(t,e)=>{const a=await Ic(t);if("symbolic"!==a.kind)throw o(e,"cannot run with detached HEAD");return a.target},eu=new TextEncoder,au="HEAD",nu=async(t,e,a={})=>{await $c(t);const n=Le.from(e),r={ctx:t,queue:new Ue(_e),finalized:[]};if(!0===a.worktree){if(void 0!==a.rev)throw u("worktree","cannot combine with a revision");await ru(r,n)}else{const e=a.rev??au;await cu(r,await Jd(t,e),n,e)}await du(r);const i=[...r.finalized].sort((t,e)=>t.finalLine-e.finalLine);return{path:n,lines:su(i,a.range)}},ru=async(t,e)=>{le(e);const a=await Jd(t.ctx,au),n=await Qd(t.ctx,a),r=await iu(t.ctx,e),i=Ct(r).length;if(0===i)return;const o=[{finalStart:0,count:i,sourceStart:0}],s=await vu(t.ctx,n.tree,e);if(void 0!==s){const{passed:i,kept:c}=Gd(o,Ht(s.content,r));return gu(t,a,e,n.committer.timestamp,s.content,s.id,i),void ou(t,e,r,c,{commit:a,path:e})}if(!(await de(t.ctx)).entries.some(t=>t.path===e))throw m(au,e);ou(t,e,r,o,void 0)},iu=async(t,e)=>{const a=he(t.layout.workDir,e),n=await t.fs.lstat(a).catch(()=>{});if(void 0===n)throw y(e);return n.isSymbolicLink?eu.encode(await t.fs.readlink(a)):t.fs.read(a)},ou=(t,e,a,n,r)=>{const i=Ct(a);for(const a of n)for(const n of wu(a.count))t.finalized.push({committed:!1,...hu(a,n,i,e,r)})},su=(t,e)=>{if(void 0===e)return t;const{start:a,end:n}=e;if(!Number.isInteger(a)||!Number.isInteger(n))throw u("-L","line numbers must be integers");if(a<1)throw u("-L",`invalid line number: ${a}`);if(a>t.length)throw u("-L",`file has only ${t.length} lines`);if(n<a)throw u("-L",`range end ${n} precedes start ${a}`);const r=Math.min(n,t.length);return t.filter(t=>t.finalLine>=a&&t.finalLine<=r)},cu=async(t,e,a,n)=>{const r=await Qd(t.ctx,e),i=await vu(t.ctx,r.tree,a);if(void 0===i)throw m(n,a);const o=Ct(i.content).length;0!==o&&gu(t,e,a,r.committer.timestamp,i.content,i.id,[{finalStart:0,count:o,sourceStart:0}])},du=async t=>{for(;t.queue.size()>0;){const{value:e}=t.queue.pop();await uu(t,e)}},uu=async(t,e)=>{const a=await Qd(t.ctx,e.commit),n=Ct(e.blob);let r,i=e.entries;for(const n of a.parents){const o=await mu(t.ctx,n,a.tree,e.path,e.blobId);if(void 0!==o&&(r??={commit:n,path:o.sourcePath},i=fu(t,e,n,o,i),0===i.length))break}lu(t,e,a,n,i,r)},fu=(t,e,a,n,r)=>{if("treesame"===n.kind)return gu(t,a,n.sourcePath,n.date,e.blob,e.blobId,r),[];const{passed:i,kept:o}=Gd(r,Ht(n.blob,e.blob));return gu(t,a,n.sourcePath,n.date,n.blob,n.blobId,i),o},lu=(t,e,a,n,r,i)=>{const o=0===a.parents.length,s=ur(a.message);for(const c of r)for(const r of wu(c.count))t.finalized.push({committed:!0,commit:e.commit,author:a.author,committer:a.committer,summary:s,boundary:o,...hu(c,r,n,e.path,i)})},hu=(t,e,a,n,r)=>({finalLine:t.finalStart+e+1,sourceLine:t.sourceStart+e+1,sourcePath:n,...void 0!==r?{previous:r}:{},content:a[t.sourceStart+e]}),wu=t=>Array.from({length:t},(t,e)=>e),mu=async(t,e,a,n,r)=>{const i=await Qd(t,e),o=i.committer.timestamp,s=await yu(t,i.tree,n);if(void 0!==s)return s.id===r?{kind:"treesame",sourcePath:n,date:o}:{kind:"changed",blob:(await He(t,s.id)).content,blobId:s.id,sourcePath:n,date:o};const c=await pu(t,i.tree,a,n);return void 0!==c?{kind:"changed",blob:(await He(t,c.blobId)).content,blobId:c.blobId,sourcePath:c.sourcePath,date:o}:void 0},pu=async(t,e,a,n)=>{const r=await Re(t,e,a,{recursive:!0,detectRenames:!0});for(const t of r.changes)if("rename"===t.type&&t.newPath===n)return{sourcePath:t.oldPath,blobId:t.oldId}},gu=(t,e,a,n,r,i,o)=>{0!==o.length&&t.queue.push({oid:e,date:n,value:{commit:e,path:a,blob:r,blobId:i,entries:o}})},yu=async(t,e,a)=>{const n=await dd(t,e,a);if(void 0!==n&&n.mode!==qt.DIRECTORY&&n.mode!==qt.GITLINK)return n},vu=async(t,e,a)=>{const n=await yu(t,e,a);if(void 0!==n)return{id:n.id,content:(await He(t,n.id)).content}},bu="refs/heads/",ku=new TextEncoder,$u=async(t,e,a)=>{const n=Pe(e),r=Pe(a),i=Be(t.layout.gitDir,n),o=ku.encode(We(r));await je(t,n,i,o)},xu=async t=>{await $c(t);const e=`${t.layout.gitDir}/refs/heads`;if(!await t.fs.exists(e))return{branches:[]};const a=await Ic(t),n=Ec(a),r=n?.startsWith(bu)?n:void 0,i=await t.fs.readdir(e),o=[];for(const e of i){if(!e.isFile)continue;const a=`${bu}${e.name}`,n=await Ae(t,a);o.push({name:a,id:n,current:a===r})}return o.sort((t,e)=>Iu(t.name,e.name)),{branches:o}},Iu=(t,e)=>t<e?-1:t>e?1:0,Eu=async(e,a)=>{await $c(e);const n=Pe(`${bu}${a.name}`),r=a.startPoint??"HEAD",i=await Su(e,r),o=Bs(r);try{await fe(e,n,i,!0===a.force?{reflogMessage:o}:{expected:"absent",reflogMessage:o})}catch(e){if(e instanceof t&&"REF_UPDATE_CONFLICT"===e.data.code)throw v(n);throw e}return{name:n,id:i}},Tu=async(t,e)=>{await $c(t);const a=Pe(`${bu}${e.name}`),n=await Ic(t);if("symbolic"===n.kind&&n.target===a)throw b(a);if(!await t.fs.exists(`${t.layout.gitDir}/${a}`))throw k(a);return await fe(t,a,ze,{delete:!0}),{name:a}},Du=async(e,a)=>{await $c(e);const n=Pe(`${bu}${a.from}`),r=Pe(`${bu}${a.to}`),i=await Ae(e,n),o=((t,e)=>`branch: renamed ${t} to ${e}`)(n,r),s=await Se(e,n);try{await fe(e,r,i,!0===a.force?{reflogMessage:o}:{expected:"absent",reflogMessage:o})}catch(e){if(e instanceof t&&"REF_UPDATE_CONFLICT"===e.data.code)throw v(r);throw e}s.length>0&&await Fe(e,r,[...s,...await Se(e,r)]),await fe(e,n,ze,{delete:!0});const c=await Ic(e);return"symbolic"===c.kind&&c.target===n&&await $u(e,"HEAD",r),{from:n,to:r}},Su=async(t,e)=>{if(/^[0-9a-f]{40}$/.test(e))return e;const a="HEAD"===e?["HEAD"]:[`${bu}${e}`,e];for(const e of a)try{return await Ae(t,e)}catch{}throw k(e)},Au="# v2 git bundle",Mu="# v3 git bundle",Ou=/^[0-9a-f]{40}$/,Nu=t=>Ou.test(t),Pu=(t,e)=>{const a=t.slice(1),n=a.indexOf(" "),r=-1===n?a:a.slice(0,n),i=-1===n?"":a.slice(n+1);if(!Nu(r))throw x(e,"malformed-header");return{oid:Kt.from(r),comment:i}},Cu=(t,e)=>{const a=t.indexOf(" ");if(-1===a)throw x(e,"malformed-header");const n=t.slice(0,a),r=t.slice(a+1);if(!Nu(n))throw x(e,"malformed-header");return{oid:Kt.from(n),name:re.from(r)}},Hu=(t,e)=>{const a=(t=>{for(let e=0;e<t.length-1;e++)if(10===t[e]&&10===t[e+1])return e+2;return-1})(t);if(-1===a)return((t,e)=>{const a=t.subarray(0,Math.min(t.length,64)),n=(new TextDecoder).decode(a);if(n.split("\n")[0]===Mu)throw $(e,3);if(!n.startsWith(Au)&&!n.startsWith(Mu))throw x(e,"not-a-bundle");throw x(e,"malformed-header")})(t,e);const{version:n,hashAlgorithm:r,prerequisites:i,refs:o}=((t,e,a)=>{const n=(new TextDecoder).decode(t.subarray(0,e)).split("\n").filter(t=>t.length>0),[r,...i]=n;if(void 0===r)throw x(a,"not-a-bundle");const{version:o,hashAlgorithm:s}=((t,e)=>{if(t===Mu)throw $(e,3);if(t!==Au)throw x(e,"not-a-bundle");return{version:2,hashAlgorithm:"sha1"}})(r,a),c=[],d=[];for(const t of i)if(t.startsWith("-"))c.push(Pu(t,a));else{if(t.startsWith("@"))throw x(a,"malformed-header");d.push(Cu(t,a))}return{version:o,hashAlgorithm:s,prerequisites:c,refs:d}})(t,a,e);return{version:n,hashAlgorithm:r,prerequisites:i,refs:o,packOffset:a}},Lu=t=>`-${t.oid} ${t.comment}\n`,Ru=t=>`${t.oid} ${t.name}\n`,Uu=async(t,e,a,n,r=0)=>{if(n.has(e))return;if(n.add(e),r>1024)throw Ge(r);if(t.signal?.aborted)throw h();a.add(e);const i=await oe(t,e);if("tree"===i.type)for(const e of i.entries)Ye(e.mode)||(Xe(e.mode)?await Uu(t,e.id,a,n,r+1):a.add(e.id))},_u=async(t,e,a,n,r,i=0)=>{if(r.has(e))return;if(r.add(e),i>1024)throw Ge(i);if(t.signal?.aborted)throw h();a.has(e)||Ve(n,e);const o=await oe(t,e);if("tree"===o.type)for(const e of o.entries)Ye(e.mode)||(Xe(e.mode)?await _u(t,e.id,a,n,r,i+1):a.has(e.id)||Ve(n,e.id))},Wu=["refs/","refs/tags/","refs/heads/","refs/remotes/"],ju=(t,e)=>{const a=e;if(a.includes(t))return t;for(const e of Wu){const n=`${e}${t}`;if(a.includes(n))return n}},Bu=async(t,e,a)=>{const n=await Ae(t,e);a.refs.push({name:e,oid:n}),a.wants.push(n)},Fu=(t,e)=>e.filter(e=>e.startsWith(t)).sort(),zu=async(t,e,a,n)=>{const r=await Nd(t,e),i=ju(e,a);void 0!==i&&n.refs.push({name:i,oid:r}),n.wants.push(r)},qu=async(t,e,a)=>{const n=await Nd(t,e);a.haves.push(await sd(t,n,"commit"))},Ku=async(t,e,a,n)=>{const[r,i]=e,o=await Nd(t,r);n.haves.push(await sd(t,o,"commit"));const s=await Nd(t,i),c=ju(i,a);void 0!==c&&n.refs.push({name:c,oid:s}),n.wants.push(s)},Vu=async(t,e,a,n)=>{const[r,i]=e,o=await Nd(t,r),s=ju(r,a);void 0!==s&&n.refs.push({name:s,oid:o}),n.wants.push(o);const c=await Nd(t,i),d=ju(i,a);void 0!==d&&n.refs.push({name:d,oid:c}),n.wants.push(c);const u=await ta(t,[await sd(t,o,"commit"),await sd(t,c,"commit")],{all:!0});n.haves.push(...u)},Gu=async(t,e)=>{await bc(t);const a=await Qe(t),n={refs:[],wants:[],haves:[]};await(async(t,e,a,n)=>{if(!0===e.branches)for(const e of Fu("refs/heads/",a))await Bu(t,e,n);if(!0===e.tags)for(const e of Fu("refs/tags/",a))await Bu(t,e,n);if(!0===e.all){for(const e of Fu("refs/",a))await Bu(t,e,n);await Bu(t,"HEAD",n)}})(t,e,a,n),await(async(t,e,a,n)=>{for(const r of e)"tip"in r?await zu(t,r.tip,a,n):"exclude"in r?await qu(t,r.exclude,n):"range"in r?await Ku(t,r.range,a,n):await Vu(t,r.symmetricRange,a,n)})(t,e.revs??[],a,n);const r=(t=>{const e=new Set;return t.filter(t=>!e.has(t.name)&&(e.add(t.name),!0))})(n.refs);if(n.refs.splice(0,n.refs.length,...r),0===n.refs.length)throw I("no-refs");const i=await(async(t,e)=>{if(0===e.wants.length)return{objects:[],boundary:[]};const a={emitted:new Set,boundary:new Set,cap:e.maxObjects??Je},n=new Set,r=await(async(t,e,a)=>{const n=new Set,r=new Set;if(0===e.length)return{commits:n,objects:r};for await(const i of Ke(t,{from:e,ignoreMissing:!0}))n.add(i.id),r.add(i.id),await Uu(t,i.data.tree,r,a);return{commits:n,objects:r}})(t,e.haves,n),i=[];for(const n of e.wants)i.push(await qe(t,n,t=>{Ve(a,t)}));return await(async(t,e,a,n,r)=>{for await(const i of Ke(t,{from:e,until:[...a.commits],ignoreMissing:!0})){Ve(n,i.id),await _u(t,i.data.tree,a.objects,n,r);for(const t of i.data.parents)a.commits.has(t)&&n.boundary.add(t)}})(t,i,r,a,n),{objects:[...a.emitted],boundary:[...a.boundary]}})(t,{wants:n.wants,haves:n.haves});if(0===i.objects.length)throw I("no-objects");const o=await(async(t,e)=>Promise.all([...e].sort().map(async e=>{const a=((t,e)=>{if("commit"!==t.type)throw E(e,t.type);return t})(await oe(t,e),e);return{oid:e,comment:fr(a.data.message)}})))(t,i.boundary),s=await Ze(t,{oids:i.objects}),c=(t=>{const e=(a=t.prerequisites,[...a].sort((t,e)=>t.oid.localeCompare(e.oid)));var a;const n=["# v2 git bundle\n"];for(const t of e)n.push(Lu(t));for(const e of t.refs)n.push(Ru(e));return n.push("\n"),(new TextEncoder).encode(n.join(""))})({prerequisites:o,refs:n.refs});return{version:2,bytes:((t,e)=>{const a=new Uint8Array(t.length+e.length);return a.set(t,0),a.set(e,t.length),a})(c,s.bytes),refs:n.refs,prerequisites:o,objectCount:s.objectCount,packSha:s.sha}},Yu=async(t,e)=>{const a=await Xu(t,e),n=Hu(a,e);return{header:n,packBytes:a.subarray(n.packOffset)}},Xu=async(e,a)=>{try{return await e.fs.read(a)}catch(n){if(!(n instanceof t))throw n;if("FILE_NOT_FOUND"===n.data.code||"PERMISSION_DENIED"===n.data.code)throw await Ju(e,a);throw n}},Ju=async(t,e)=>{try{if((await t.fs.stat(e)).isDirectory)return x(e,"not-a-bundle")}catch{}return T(e)},Qu=async(t,e)=>{const{header:a}=await Yu(t,e.path),n=Zu(a.refs,e.names);return{version:a.version,refs:n}},Zu=(t,e)=>{if(void 0===e)return t;const a=new Set(e);return t.filter(t=>a.has(t.name))},tf=async(t,e)=>{const{header:a,packBytes:n}=await Yu(t,e.path),r=await nf(t,a.prerequisites);if(r.length>0)return ef(a,r);await ea(n,t);const i=a.prerequisites.length>0?af(t):void 0;return await aa(t,n,i),ef(a,[])},ef=(t,e)=>({version:t.version,hashAlgorithm:t.hashAlgorithm,refs:t.refs,prerequisites:t.prerequisites,missingPrerequisites:e,prerequisitesPresent:0===e.length,recordsCompleteHistory:0===t.prerequisites.length}),af=e=>{const a=new Map;return async n=>{if(a.has(n))return a.get(n);const r=await(async(e,a)=>{try{const t=await oe(e,a),n=na(t,e.hashConfig),{contentOffset:r}=ra(n);return{type:t.type,content:n.subarray(r)}}catch(e){if(e instanceof t&&"OBJECT_NOT_FOUND"===e.data.code)return;throw e}})(e,n);return a.set(n,r),r}},nf=async(t,e)=>{const a=[];for(const n of e)await rf(t,n.oid)&&a.push(n.oid);return a},rf=async(e,a)=>{try{return await oe(e,a),!1}catch(e){if(e instanceof t&&"OBJECT_NOT_FOUND"===e.data.code)return!0;throw e}},of=t=>"string"==typeof t?Kt.from(t):t,sf=async(t,e)=>{await $c(t);const a=e.ids.map(of),n=void 0===e.maxBytes?void 0:{maxBytes:e.maxBytes},r=[];for await(const e of ia(t,a,n))r.push(e);return{kind:"batch",entries:r}},cf="checkout:materialize",df=async(t,e)=>{if("HEAD"===e){const e=await Ae(t,"HEAD");return(await xe(t,e)).id}return(await xe(t,e)).id},uf=async(t,e)=>{await $c(t),await xc(t,"checkout"),await Dc(t);const a=(t=>"rev"in t&&void 0!==t.rev)(e),n=(t=>"paths"in t&&void 0!==t.paths)(e);if(a&&n)throw u("paths","cannot be combined with rev");if(!a&&!n)throw u("rev","either rev or paths must be provided");t.progress.start(cf);try{return n?await(async(t,e)=>{if(0===e.paths.length)throw u("paths","must not be empty");const a=e.source??"index",{matcher:n,literalMustMatch:r}=_c(e.paths),i=(await(async(t,e)=>{if("index"===e)return(await de(t)).entries.map(t=>t.path);const a=await df(t,e),n=[];for await(const e of Ce(t,a))e.mode!==qt.DIRECTORY&&n.push(e.path);return n})(t,a)).filter(t=>Xr(n,t));Bc(r,i);const o=new Set(i);if(0===o.size)return{branch:void 0,id:await Ae(t,"HEAD"),detached:!1,changedPaths:0};const s="index"===a?await(async(t,e)=>{const a=await de(t),n=await ca(t,a.entries);return ue(t,{targetTree:n,currentIndex:a,force:!0,forceRewriteAll:!0,paths:e})})(t,o):await(async(t,e,a)=>{const n=await ce(t);try{const r=await de(t),i=await ue(t,{targetTree:e,currentIndex:r,force:!0,forceRewriteAll:!0,paths:a});return await n.commit(i.newIndexEntries),i}finally{await n.release()}})(t,await df(t,a),o),c=await Ae(t,"HEAD");return await oa(t,"post-checkout",{args:[c,c,"0"]}),{branch:void 0,id:c,detached:!1,changedPaths:s.written+s.deleted}})(t,e):await(async(t,e)=>{const a=!0===e.detach||/^[0-9a-f]{40}$/.test(e.rev),n=await Ic(t),r=await Ae(t,"HEAD");let i,o;if(a)o=await(async(t,e)=>/^[0-9a-f]{40}$/.test(e)?e:Ae(t,e))(t,e.rev);else{if(i=Pe(`${bu}${e.rev}`),!await t.fs.exists(`${t.layout.gitDir}/${i}`))throw k(i);o=await Ae(t,i)}const s=await xe(t,o),c=await ie(t),d=await ce(t);let u;try{const a=await de(t);u=await ue(t,{targetTree:s.id,currentIndex:a,force:e.force??!1,...void 0!==c?{sparse:c}:{}}),await d.commit(u.newIndexEntries)}finally{await d.release()}const f=(t=>{if("symbolic"!==t.kind)return t.id.slice(0,7);if(t.target.startsWith(bu))return t.target.slice(11);const e=t.target.lastIndexOf("/");return-1===e?t.target:t.target.slice(e+1)})(n);return a?(await t.fs.writeUtf8(`${t.layout.gitDir}/HEAD`,`${o}\n`),await sa(t,"HEAD",r,o,`checkout: moving from ${f} to ${o.slice(0,7)}`)):(await $u(t,"HEAD",i),await sa(t,"HEAD",r,o,`checkout: moving from ${f} to ${e.rev}`)),await oa(t,"post-checkout",{args:[r,o,"1"]}),{branch:a?void 0:i,id:o,detached:a,changedPaths:u.written+u.deleted}})(t,e)}finally{t.progress.end(cf)}},ff={kind:"text"},lf={kind:"union"},hf={kind:"binary"},wf=(t,e)=>!1===e?Promise.resolve(hf):!0===e||"unspecified"===e?Promise.resolve(ff):(async(t,e)=>{const a=(await ne(t)).merge?.get(e);return void 0!==a?.driver?void 0===a.name?{kind:"external",command:a.driver}:{kind:"external",command:a.driver,name:a.name}:void 0===a||void 0===a.name&&void 0===a.recursive?"binary"===e?hf:"union"===e?lf:ff:{kind:"missing-command",name:e}})(t,e.set),mf=new Uint8Array(0),pf=(t,e=fi)=>{let n,r;return async i=>{await(r??=ua(t,"merge",["driver","name","recursive"],{requireSubsection:!0}).then(t=>{if(void 0!==t)throw a(t.key,t.source,t.line)}));const[o,s,c]=await Promise.all([He(t,i.ourId,{maxBytes:Zr}),He(t,i.theirId,{maxBytes:Zr}),void 0!==i.baseId?He(t,i.baseId,{maxBytes:Zr}):Promise.resolve(void 0)]),{driver:d,markerSize:u}=await(async(t,e,a)=>{const{sources:n,macros:r}=await e.sourcesForPath(a);return{driver:await wf(t,da(n,a,"merge",r)),markerSize:Sc(da(n,a,"conflict-marker-size",r))}})(t,await(n??=fa(t)),i.path);if("missing-command"===d.kind)throw D(d.name);return"binary"===d.kind?{status:"conflict",conflictType:"binary",markedBytes:o.content}:"external"===d.kind&&void 0!==t.command?(async(t,e,a)=>{const{gitDir:n,workDir:r}=t.layout,i=`${n}/MERGE_DRIVER_O`,o=`${n}/MERGE_DRIVER_A`,s=`${n}/MERGE_DRIVER_B`;await Promise.all([t.fs.write(i,a.base??mf),t.fs.write(o,a.ours),t.fs.write(s,a.theirs)]);try{const c=((t,e)=>{let a="",n=0;for(;n<t.length;){const r=t[n];if("%"!==r){a+=r,n+=1;continue}const i=t[n+1];void 0!==i?(a+=Ac(i,e),n+=2):(a+="%",n+=1)}return a})(a.command,{O:i,A:o,B:s,L:String(a.markerSize),P:a.path,S:a.labels.base,X:a.labels.ours,Y:a.labels.theirs}),{exitCode:d}=await e.run({command:c,cwd:r,env:{GIT_DIR:n},...void 0!==t.signal?{signal:t.signal}:{}}),u=await t.fs.read(o);return 0===d?{status:"clean",bytes:u}:{status:"conflict",conflictType:"content",markedBytes:u}}finally{await Promise.all([t.fs.rm(i),t.fs.rm(o),t.fs.rm(s)])}})(t,t.command,{command:d.command,base:c?.content,ours:o.content,theirs:s.content,path:i.path,markerSize:u,labels:e}):function(t,e,a,n={}){return Lt(e)||Lt(a)||void 0!==t&&Lt(t)?{status:"conflict",conflictType:"binary",markedBytes:e}:void 0===t?Ft(e,a)?{status:"clean",bytes:e}:bi(new Uint8Array(0),e,a,n):Ft(e,t)?{status:"clean",bytes:a}:Ft(a,t)||Ft(e,a)?{status:"clean",bytes:e}:bi(t,e,a,n)}(c?.content,o.content,s.content,{favor:"union"===d.kind?"union":"none",markerSize:u,labels:{ours:e.ours,theirs:e.theirs}})}},gf=(t,e)=>{if("unchanged"===t.status)return!1;if("resolved-known"===t.status){const a=e.get(t.path);return void 0===a||a.id!==t.id||a.mode!==t.mode}return"resolved-merged"===t.status||"resolved-deleted"===t.status&&e.has(t.path)},yf=(t,e,a)=>{const n=new Set;for(const e of t)"conflict"!==e.status&&gf(e,a)&&n.add(e.path);for(const t of e)for(const e of gr(t))n.add(e);return n},vf=async(t,e)=>{try{return await t.fs.lstat(he(t.layout.workDir,e)),!0}catch{return!1}},bf=async(t,e,a)=>{const n=(t=>{const e=new Map;for(const a of t.entries)0===a.flags.stage&&e.set(a.path,a);return e})(a),r=await we(t),i=[],o=[];for(const a of e){const e=n.get(a);void 0!==e?la(await ha(t,e,r))&&i.push(a):await vf(t,a)&&o.push(a)}return{localChanges:[...i].sort(At),untracked:[...o].sort(At)}},kf=t=>({ctimeSeconds:0,ctimeNanoseconds:0,mtimeSeconds:0,mtimeNanoseconds:0,dev:0,ino:0,mode:t,uid:0,gid:0,fileSize:0}),$f=(t,e,a)=>({...kf(a),id:e,flags:Pt,path:t}),xf=async(t,e)=>{const{ourPath:a,theirPath:n,ourId:r,ourMode:i,theirId:o,theirMode:s}=e;if(void 0!==a&&void 0!==r&&void 0!==i){const e=await He(t,r,{maxBytes:Zr});await wa(t,a,e.content,i)}if(void 0!==n&&void 0!==o&&void 0!==s){const e=await He(t,o,{maxBytes:Zr});await wa(t,n,e.content,s)}},If=new Set(["rename-rename","gitlink"]),Ef=async(t,e)=>{const a=[];for(const n of e)if("resolved-deleted"!==n.status&&"conflict"!==n.status){if("resolved-merged"===n.status){const e=await ye(t,{type:"blob",content:n.bytes,id:""});a.push($f(n.path,e,n.mode));continue}a.push($f(n.path,n.id,n.mode))}return ca(t,a)},Tf=async(t,e)=>{const a=e.mergedMode??e.ourMode??e.theirMode;if(void 0===a)return;const n=await(async(t,e)=>{if(void 0!==e.conflictContent)return e.conflictContent;if("modify-delete"===e.type){const a=e.ourId??e.theirId;return void 0!==a?(await He(t,a,{maxBytes:Zr})).content:void 0}return void 0!==e.ourId?(await He(t,e.ourId,{maxBytes:Zr})).content:void 0})(t,e);void 0!==n&&await wa(t,e.path,n,a)},Df=(t,e)=>{const a=[];for(const e of t)"unchanged"!==e.status&&"resolved-known"!==e.status||a.push($f(e.path,e.id,e.mode));const n=[...a,...br(e,kf)];return n.sort((t,e)=>t.path<e.path?-1:t.path>e.path?1:t.flags.stage-e.flags.stage),n},Sf=async(t,e)=>{const[a,n,r]=await Promise.all([void 0!==e.baseTree?ma(t,e.baseTree):Promise.resolve(void 0),ma(t,e.oursTree),ma(t,e.theirsTree)]),i=await Hi(a,n,r,pf(t,e.labels),e.labels);i.cleanMerge||(t=>{for(const e of t)if(If.has(e.type))throw o("apply-merge",`conflict type '${e.type}' not supported (path=${e.path})`)})(i.conflicts);const s=yf(i.outcomes,i.conflicts,n.entries),c=await bf(t,s,e.currentIndex);if(c.localChanges.length>0||c.untracked.length>0)return{kind:"would-overwrite",localChanges:c.localChanges,untracked:c.untracked};if(i.cleanMerge){const a=await Ef(t,i.outcomes);return{kind:"clean",mergedTree:a,result:await ue(t,{targetTree:a,currentIndex:e.currentIndex,force:!0})}}return await(async(t,e,a,n)=>{for(const a of e)if("conflict"!==a.status&&n.has(a.path))if("resolved-deleted"!==a.status)if("resolved-merged"!==a.status){if("resolved-known"===a.status){const e=await ya(t,a.id);await va(t,a.path,e)}}else await ga(t,a.path,a.bytes);else await pa(t,a.path);for(const e of a)"distinct-types"!==e.type?await Tf(t,e):await xf(t,e)})(t,i.outcomes,i.conflicts,s),{kind:"conflict",conflicts:i.conflicts,indexEntries:Df(i.outcomes,i.conflicts)}},Af=/^(pick|revert) (\S+) (.*)$/,Mf=async(t,e)=>{if(!await t.fs.exists(e))return;const a=(await t.fs.readUtf8(e)).trim();return 0!==a.length?Kt.from(a):void 0},Of=t=>`${t.layout.gitDir}/sequencer`,Nf=t=>`${Of(t)}/head`,Pf=t=>`${Of(t)}/todo`,Cf=t=>`${Of(t)}/opts`,Hf=(t,e)=>t.fs.writeUtf8(Nf(t),`${e}\n`),Lf=t=>Mf(t,Nf(t)),Rf=(t,e)=>t.fs.writeUtf8((t=>`${Of(t)}/abort-safety`)(t),`${e}\n`),Uf=(t,e)=>t.fs.writeUtf8(Pf(t),(t=>t.map(t=>`${t.command} ${t.oid} ${t.subject}\n`).join(""))(e)),_f=async t=>{const e=Pf(t);if(!await t.fs.exists(e))return;const a=(t=>{const e=[];for(const a of t.split("\n")){if(""===a||a.startsWith("#"))continue;const t=Af.exec(a);if(null===t)throw S(a);e.push({command:t[1],oid:t[2],subject:t[3]})}return e})(await t.fs.readUtf8(e)),n=[];for(const e of a){const a=await pd(t,e.oid);if(void 0===a)throw S(`cannot resolve commit ${e.oid}`);n.push({command:e.command,oid:a,subject:e.subject})}return n},Wf=async(t,e)=>{(e.noCommit||e.recordOrigin||e.allowEmpty)&&await t.fs.writeUtf8(Cf(t),(t=>{let e="[options]\n";return t.noCommit&&(e+="\tno-commit = true\n"),t.recordOrigin&&(e+="\trecord-origin = true\n"),t.allowEmpty&&(e+="\tallow-empty = true\n"),e})(e))},jf=(t,e)=>t.some(t=>"options"===t.section.toLowerCase()&&t.entries.some(t=>t.key.toLowerCase()===e&&null!==t.value&&"true"===t.value.toLowerCase())),Bf=async t=>{const e=Of(t);await t.fs.exists(e)&&await t.fs.rmRecursive(e)},Ff=async(t,e)=>{await Mc(t,e.target),await fe(t,e.branch,e.target,{reflogMessage:Fs(e.target)}),await e.clearHead(t),await yc(t),await Bf(t)},zf=t=>`${t.layout.gitDir}/CHERRY_PICK_HEAD`,qf=t=>Mf(t,zf(t)),Kf=async t=>{const e=zf(t);await t.fs.exists(e)&&await t.fs.rm(e)},Vf=(t,e)=>`${t.replace(/\s+$/,"")}\n\n# Conflicts:\n${e.map(t=>`#\t${t}\n`).join("")}`,Gf=async(t,e,a)=>{const n=await ma(t,a),r=new Set(e.map(t=>t.path)),i=[];for(const t of e){const e=n.entries.get(t.path);void 0!==e&&e.id===t.id&&e.mode===t.mode||i.push(t.path)}for(const t of n.entries.keys())r.has(t)||i.push(t);return i},Yf=async(t,e)=>{const a=await we(t),n=[];for(const r of e)r.flags.skipWorktree||"unchanged"!==await ha(t,r,a)&&n.push(r.path);return n},Xf=async(t,e)=>{const{stage0:a,unmerged:n}=(t=>{const e=[],a=[];for(const n of t)0===n.flags.stage?e.push(n):a.push(n.path);return{stage0:e,unmerged:a}})((await de(t)).entries),r=new Set([...n,...await Gf(t,a,e),...await Yf(t,a)]);if(r.size>0)throw A({localChanges:[...r].sort(At),untracked:[]})},Jf=t=>{if(void 0!==t.explicit)return t.explicit;if(void 0!==t.configUser)return t.configUser;throw M()},Qf=t=>{if(void 0!==t.explicit)return t.explicit;if(void 0!==t.author)return t.author;if(void 0!==t.configUser)return t.configUser;throw M()},Zf=(t,e)=>{const a=lr(t);if(""===a&&!e.allowEmpty)throw O();return a},tl=t=>t.split("\n").filter(t=>!t.startsWith("#")).join("\n"),el=async t=>{const e=(await ne(t)).user;await ka(t,"user",void 0,["name","email"]);const a=void 0!==e?.name&&void 0!==e?.email?{name:e.name,email:e.email,timestamp:Math.floor(Date.now()/1e3),timezoneOffset:"+0000"}:void 0;return Qf({configUser:a})},al=t=>t.parents.length>=2,nl=t=>t.map(t=>({path:t.path,type:t.type})),rl=/^(.+)\.\.(.+)$/,il=async(t,e,a)=>{const n=new Set;for await(const a of Ke(t,{from:[e]}))n.add(a.id);const r=[];for await(const e of Ke(t,{from:[a],until:[...n]}))r.push(e.id);return r.reverse()},ol=async(t,e,a,n,r)=>{await Hf(t,e.sequenceHead),await Uf(t,await(async(t,e)=>{const a=[];for(const n of e){const e=await Qd(t,n);a.push({command:"pick",oid:n,subject:ur(e.message)})}return a})(t,a)),await Rf(t,n),await Wf(t,{recordOrigin:r.recordOrigin,allowEmpty:r.allowEmpty,noCommit:!1})},sl=async(t,e,a,n,r,i)=>{let o=n;const s=[];for(let n=0;n<e.length;n+=1){const c=e[n],d=await Qd(t,c);if(al(d))throw i.multiPick&&await ol(t,i,e.slice(n),o,r),N(c);const u=await dl(t,c,d,a,o,r);if("committed"===u.kind){s.push({source:c,created:u.id}),o=u.id;continue}await ul(t,c,d,"conflict"===u.kind?u.conflicts:void 0,r),i.multiPick&&await ol(t,i,e.slice(n),o,r);const f=e.length-(n+1);return"conflict"===u.kind?{kind:"conflict",commit:c,conflicts:nl(u.conflicts),remaining:f}:{kind:"empty",commit:c,remaining:f}}return await Bf(t),{kind:"picked",commits:s}},cl=(t,e,a)=>a?((t,e)=>`${t.replace(/\s+$/,"")}\n\n(cherry picked from commit ${e})`)(t,e):t,dl=async(t,e,a,n,r,i)=>{const o=a.parents[0],s=void 0!==o?await Zd(t,o):void 0,c=await Zd(t,r),d=await ce(t);try{const o=await de(t),f=await Sf(t,{baseTree:s,oursTree:c,theirsTree:a.tree,currentIndex:o,labels:ci(e,ur(a.message))});if("would-overwrite"===f.kind)throw A({localChanges:f.localChanges,untracked:f.untracked});if("conflict"===f.kind)return await d.commit(f.indexEntries),{kind:"conflict",conflicts:f.conflicts};if(f.mergedTree===c&&!i.allowEmpty)return{kind:"empty"};await d.commit(f.result.newIndexEntries);const l=await(async(t,e,a,n,r,i)=>{const o=await el(t);return $a(t,{tree:r,parents:[n],author:a.author,committer:o,message:Zf(cl(a.message,e,i.recordOrigin),{allowEmpty:!1}),extraHeaders:[]})})(t,e,a,r,f.mergedTree,i);return await fe(t,n,l,{expected:r,reflogMessage:(u=ur(a.message),`cherry-pick: ${u}`)}),{kind:"committed",id:l}}finally{await d.release()}var u},ul=async(t,e,a,n,r)=>{await(async(t,e)=>{await t.fs.writeUtf8(zf(t),`${e}\n`)})(t,e);const i=cl(a.message,e,r.recordOrigin),o=void 0!==n&&n.length>0?Vf(i,yr(n)):i;await hc(t,o)},fl=async(e,a)=>{await $c(e),await xc(e,ec),await Dc(e);const n=await Ic(e);if("symbolic"!==n.kind)throw o(ec,"cannot cherry-pick with detached HEAD");const r=await(async(e,a)=>{try{return await Ae(e,a)}catch(e){if(e instanceof t&&"REF_NOT_FOUND"===e.data.code)throw P();throw e}})(e,n.target),i=await(async(t,e)=>{const a=[];for(const n of e){if(n.includes("...")||n.includes("^"))throw u("commits",`unsupported revision form '${n}' (use a commit-ish or A..B)`);const e=rl.exec(n);if(null===e){a.push(await Jd(t,n));continue}const r=await Nd(t,e[1]),i=await Nd(t,e[2]);a.push(...await il(t,r,i))}return a})(e,a.commits);return await Xf(e,await Zd(e,r)),!0===a.noCommit?(async(t,e)=>{const a=await ce(t);try{let n=await de(t);for(let r=0;r<e.length;r+=1){const i=e[r],o=await Qd(t,i);if(al(o))throw N(i);const s=o.parents[0],c=void 0!==s?await Zd(t,s):void 0,d=await ca(t,n.entries),u=await Sf(t,{baseTree:c,oursTree:d,theirsTree:o.tree,currentIndex:n,labels:ci(i,ur(o.message))});if("would-overwrite"===u.kind)throw A({localChanges:u.localChanges,untracked:u.untracked});if("conflict"===u.kind)return await a.commit(u.indexEntries),{kind:"conflict",commit:i,conflicts:nl(u.conflicts),remaining:e.length-(r+1)};n={...n,entries:u.result.newIndexEntries}}return await a.commit(n.entries),{kind:"no-commit",sources:e}}finally{await a.release()}})(e,i):sl(e,i,n.target,r,{recordOrigin:a.recordOrigin??!1,allowEmpty:a.allowEmpty??!1},{multiPick:i.length>1,sequenceHead:r})},ll=async(t,e)=>{if(void 0!==await Lf(t)){const e=await(async t=>{const e=Cf(t);if(!await t.fs.exists(e))return{recordOrigin:!1,allowEmpty:!1,noCommit:!1};const a=ba(await t.fs.readUtf8(e),e);return{noCommit:jf(a,"no-commit"),recordOrigin:jf(a,"record-origin"),allowEmpty:jf(a,"allow-empty")}})(t);return{recordOrigin:e.recordOrigin,allowEmpty:e.allowEmpty}}return{recordOrigin:!1,allowEmpty:e.allowEmpty??!1}},hl=async(t,e={})=>{await $c(t),await xc(t,rc);const a=await qf(t),n=await _f(t);if(void 0===a&&(void 0===n||0===n.length))throw i(ec);const r=await Ic(t);if("symbolic"!==r.kind)throw o(rc,"cannot continue with detached HEAD");const s=await ll(t,e);let c=await Ae(t,r.target);const d=[];if(void 0!==a){const e=void 0!==n?n.length-1:0,i=await(async(t,e,a,n,r)=>{const i=await de(t);(t=>{const e=new Set;for(const a of t)0!==a.flags.stage&&e.add(a.path);if(e.size>0)throw C(e.size,[...e])})(i.entries);const o=await ca(t,i.entries);if(o===await Zd(t,n)&&!r.allowEmpty)return{empty:!0};const s=await(async(t,e,a,n,r)=>{const i=await Qd(t,e),o=await el(t),s=Zf(tl(await pc(t)??""),{allowEmpty:!1}),c=await $a(t,{tree:r,parents:[a],author:i.author,committer:o,message:s,extraHeaders:[]});return await fe(t,n,c,{expected:a,reflogMessage:Ws(ur(s))}),c})(t,e,n,a,o);return await Kf(t),await yc(t),{created:s}})(t,a,r.target,c,s);if("empty"in i)return{kind:"empty",commit:a,remaining:e};d.push({source:a,created:i.created}),c=i.created}const u=(n??[]).slice(void 0!==a?1:0).map(t=>t.oid);if(0===u.length)return await Bf(t),{kind:"picked",commits:d};const f=await Lf(t)??c,l=await sl(t,u,r.target,c,s,{multiPick:!0,sequenceHead:f});return"picked"===l.kind?{kind:"picked",commits:[...d,...l.commits]}:l},wl=async(t,e={})=>{await $c(t),await xc(t,ic);const a=await qf(t),n=await _f(t);if(void 0===a&&(void 0===n||0===n.length))throw i(ec);const r=await tu(t,ic),o=await Ae(t,r),s=await ll(t,e);await Mc(t,o),await Kf(t),await yc(t);const c=(n??[]).slice(1).map(t=>t.oid);if(0===c.length)return await Bf(t),{kind:"picked",commits:[]};const d=await Lf(t)??o;return sl(t,c,r,o,s,{multiPick:!0,sequenceHead:d})},ml=async t=>{await $c(t),await xc(t,oc);const e=await qf(t),a=await Lf(t);if(void 0===e&&void 0===a)throw i(ec);const n=await tu(t,oc),r=a??await Ae(t,n);return await Ff(t,{branch:n,target:r,clearHead:Kf}),{head:r,branch:n}},pl=async(t,e)=>{const a=Pe(e.initialBranch),n=t.layout.gitDir;try{await t.fs.mkdir(n),await t.fs.writeUtf8(`${n}/HEAD`,`ref: refs/heads/${a}\n`),await t.fs.writeUtf8(`${n}/config`,(r=e.bare,`[core]\n\trepositoryformatversion = 0\n\tfilemode = true\n\tbare = ${r?"true":"false"}\n`)),await t.fs.mkdir(`${n}/refs/heads`),await t.fs.mkdir(`${n}/refs/tags`),await t.fs.mkdir(`${n}/objects/info`),await t.fs.mkdir(`${n}/objects/pack`),await t.fs.writeUtf8(`${n}/info/exclude`,"# git ls-files --others --exclude-from=.git/info/exclude\n# Lines that start with '#' are comments.\n# For a project mostly in C, the following would be a good set of\n# exclude patterns (uncomment them if you want to use them):\n# *.[oa]\n# *~\n"),await t.fs.writeUtf8(`${n}/description`,"Unnamed repository; edit this file 'description' to name the repository.\n")}catch(e){throw await t.fs.rmRecursive(n).catch(()=>{}),e}var r;return{gitDir:n,initialBranch:a,bare:e.bare}},gl=new TextDecoder,yl=t=>{return!t.done&&"data"===t.value.kind&&"version 2"===((e=gl.decode(t.value.payload)).endsWith("\n")?e.slice(0,-1):e);var e},vl=(t,e)=>{let a=!1;return{[Symbol.asyncIterator]:()=>({next:()=>a?t.next():(a=!0,Promise.resolve(e)),return:async e=>await(t.return?.(e))??{done:!0,value:void 0}})}},bl=async t=>{const e=(await t.advertisement())[Symbol.asyncIterator](),a=await e.next(),n=await(async(t,e,a)=>!a||yl(e)?e:(await zo(t,e,"git-upload-pack"),t.next()))(e,a,t.servicePrologue);if(!yl(n))return{version:1,advertisement:await Vo(vl(e,n),"git-upload-pack",{servicePrologue:!1})};const r=await(async t=>{const e=t[Symbol.asyncIterator]();try{const t=await is(e);if("version 2"!==t)throw eo(t??"");const a={commands:new Set,fetchFeatures:new Set,agent:void 0,objectFormat:as};for(let t=await is(e);void 0!==t;t=await is(e))os(a,t);return void 0===a.agent?{version:2,commands:a.commands,fetchFeatures:a.fetchFeatures,objectFormat:a.objectFormat}:{version:2,agent:a.agent,commands:a.commands,fetchFeatures:a.fetchFeatures,objectFormat:a.objectFormat}}finally{await(e.return?.())}})(vl(e,n));if(!(i=r).commands.has("fetch")||!i.commands.has("ls-refs"))throw eo("fetch");var i;const o=await t.exchange((t=>{const e=[];e.push(Es.encode("symrefs\n")),!0===t.peel&&e.push(Es.encode("peel\n"));for(const a of t.refPrefixes??[])e.push(Ss(a));return ls("ls-refs",[],e)})({})),s=await(async t=>{const e=t[Symbol.asyncIterator]();try{const t=[];let a,n=await e.next();for(;!n.done&&"data"===n.value.kind;){const r=As(Ts.decode(n.value.payload)),i=Os(r);void 0!==i.symrefTarget?"HEAD"===i.name&&(a=i.symrefTarget):Ps(t,i,r),n=await e.next()}const r=((t,e)=>{const a=t.find(t=>"HEAD"===t.name);if(a)return a;if(void 0===e)return;const n=t.find(t=>t.name===e);return void 0===n?void 0:{name:"HEAD",id:n.id}})(t,a),i=void 0===a?[]:[`symref=HEAD:${a}`];return void 0===r?{capabilities:i,refs:t}:{capabilities:i,refs:t,head:r}}finally{await(e.return?.())}})(o);return{version:2,advertisement:(c=s,d=r.fetchFeatures,d.has("filter")?{...c,capabilities:[...c.capabilities,"filter"]}:c)};var c,d},kl=t=>{const e=[];return void 0!==t.depth&&e.push(`deepen ${t.depth}`),void 0!==t.filter&&e.push(`filter ${t.filter}`),e},$l=async(t,e,a)=>{const n=(t=>{const e=[...t.wants.map(ys),...t.haves.map(vs)];return e.push(bs),ls("fetch",t.args??[],e)})({wants:a.wants,haves:a.haves,args:kl(a)}),r=await e.exchange(n),i=await(async(t,e={})=>{let a=[],n=!1,r=!1,i=[],o=[],s=[],c=async function*(){}();for await(const d of async function*(t){const e=t[Symbol.asyncIterator]();let a=await e.next();for(;!a.done&&"data"===a.value.kind;){const t=fs(ds.decode(a.value.payload));if(!us(t))throw to(t);let n=!1;const r=hs(e,t=>{n=t});yield{name:t,lines:r},a=n?await e.next():{done:!0,value:void 0}}}(t)){if("acknowledgments"===d.name){const t=await ks(gs(d.name,d.lines));a=t.acks,n=t.nak,r=t.ready;continue}if("shallow-info"===d.name){const t=await $s(gs(d.name,d.lines));i=t.shallow,o=t.unshallow;continue}"wanted-refs"!==d.name?c=Co(d.lines,e.onProgress?{onProgress:e.onProgress}:{}):s=await Is(gs(d.name,d.lines))}return{acks:a,nak:n,ready:r,packBody:c,shallow:i,unshallow:o,wantedRefs:s}})(r,{onProgress:e=>t.progress.update(a.progressOp,0,void 0,H(e))});return{packBytes:await xa(t,a,i.packBody),shallow:i.shallow,unshallow:i.unshallow}},xl=(e,a,n,r)=>2===n?$l(e,a,r):(async(e,a,n)=>{const r=(e=>{if(0===e.wants.length)throw new t({code:"EMPTY_WANTS"});const a=[];e.wants.forEach((t,n)=>{a.push(((t,e)=>{const a=0===e.length?"":` ${e.join(" ")}`;return Lo.encode(`want ${t}${a}\n`)})(t,0===n?e.capabilities:[]))}),void 0!==e.depth&&a.push(Lo.encode(`deepen ${e.depth}\n`)),void 0!==e.filter&&a.push(Lo.encode(`filter ${e.filter}\n`));const n=yo(a),r=((t,e)=>{if(0===t.length)return new Uint8Array(0);const a=t.map(Go);return!0===e?vo(a):yo(a)})(e.haves,e.done),i=e.done?Yo:new Uint8Array(0),o=new Uint8Array(n.byteLength+r.byteLength+i.byteLength);let s=0;return o.set(n,s),s+=n.byteLength,o.set(r,s),s+=r.byteLength,o.set(i,s),o})({wants:n.wants,haves:n.haves,capabilities:n.capabilities,done:!0,...void 0!==n.depth?{depth:n.depth}:{},...void 0!==n.filter?{filter:n.filter}:{}}),i=await a.exchange(r),o=await(async(t,e)=>{const a=t[Symbol.asyncIterator](),n=!0===e.expectShallow?await(async t=>{const e={shallow:[],unshallow:[]};let a=await t.next();for(;!a.done;){if("data"!==a.value.kind)return{shallow:e.shallow,unshallow:e.unshallow};const n=Ho.decode(a.value.payload);if(!ts(n,e))return es.set(t,a.value),{shallow:e.shallow,unshallow:e.unshallow};a=await t.next()}return{shallow:e.shallow,unshallow:e.unshallow}})(a):{shallow:[],unshallow:[]},r=await(async t=>{const e=[];let a=!1;const n=es.get(t);void 0!==n&&es.delete(t);let r=void 0!==n?{done:!1,value:n}:await t.next();for(;!r.done;){if("data"!==r.value.kind)return{acks:e,nak:a,buffered:[r.value]};const n=Ho.decode(r.value.payload);if(n.startsWith("ACK "))e.push(Xo(n)),r=await t.next();else{if(!n.startsWith("NAK"))return{acks:e,nak:a,buffered:[r.value]};a=!0,r=await t.next()}}return{acks:e,nak:a,buffered:[]}})(a);return{acks:r.acks,nak:r.nak,shallow:n.shallow,unshallow:n.unshallow,packBody:{[Symbol.asyncIterator]:()=>async function*(t,e,a){const n=async function*(t,e){for(const e of t)yield e;let a=await e.next();for(;!a.done;)yield a.value,a=await e.next()}(t,e);if(a.sideBand){const t=a.onProgress?{onProgress:a.onProgress}:{};return void(yield*Co(n,t))}yield*async function*(t){for await(const e of t){if("data"!==e.kind)return;yield e.payload}}(n)}(r.buffered,a,e)}}})(i,{sideBand:Ia(n.capabilities),onProgress:t=>e.progress.update(n.progressOp,0,void 0,H(t)),expectShallow:void 0!==n.depth});return{packBytes:await xa(e,n,o.packBody),shallow:o.shallow,unshallow:o.unshallow}})(e,a,r),Il={attempts:3,backoff:"exponential",baseMs:250,maxDelayMs:5e3},El=t=>"request"===t.kind||"response"===t.kind?{...t,url:Dl(t.url),headers:Tl(t.headers)}:{...t,url:Dl(t.url),errorMessage:Dl(t.errorMessage)},Tl=t=>{const e={};for(const[a,n]of Object.entries(t))e[a]=Dl(n);return e},Dl=t=>{let e="";for(let a=0;a<t.length;a+=1){const n=t.charCodeAt(a);e+=9===n||10===n?t[a]:n<32||n>126?`\\x${n.toString(16).padStart(2,"0").toUpperCase()}`:t[a]}return e},Sl=/[\n\r\0]/,Al=t=>{const e=t.indexOf("@");if(-1===e)return t;const a=t.indexOf("://");if(-1===a)return t.slice(e+1).includes(":")?t.slice(e+1):t;const n=a+3,r=t.indexOf("/",n);return-1!==r&&r<e?t:`${t.slice(0,n)}${t.slice(e+1)}`},Ml=t=>{const e=t.indexOf(":");if(-1===e)return!1;const a=t.indexOf("/");return(-1===a||e<a)&&!t.includes("://")},Ol=t=>{try{return new URL(t)}catch{throw L("not a valid URL")}},Nl=t=>t.startsWith("/~")?t.slice(1):t,Pl=t=>t.startsWith("[")&&t.endsWith("]")?t.slice(1,-1):t,Cl=t=>{const e=t.indexOf(":");return{hostToken:t.slice(0,e),path:t.slice(e+1)}},Hl=t=>{const e=t.indexOf("@");return-1===e?{host:t}:{user:t.slice(0,e),host:t.slice(e+1)}},Ll=(t,e)=>void 0===t?e:`${t}@${e}`,Rl=(t,e,a,n)=>({kind:"ssh",...void 0!==t?{user:t}:{},host:e,...void 0!==a?{port:a}:{},path:n}),Ul=(t,e)=>{_l("hostname",t),_l("pathname",e)},_l=(t,e)=>{if(e.startsWith("-"))throw L(`strange ${t} '${H(e)}' blocked`)},Wl=(t,e)=>`${t} ${Ea(e)}`,jl=t=>void 0!==t&&""!==t,Bl=t=>{const[e,...a]=ql(t);return void 0===e?{program:t,baseArgs:[]}:{program:e,baseArgs:a}},Fl=/'([^']*)'|"((?:[^"\\]|\\.)*)"|((?:[^\s'"\\]|\\.)+)/g,zl=/(?:'[^']*'|"(?:[^"\\]|\\.)*"|(?:[^\s'"\\]|\\.))+/g,ql=t=>Array.from(t.matchAll(zl),t=>Kl(t[0])),Kl=t=>Array.from(t.matchAll(Fl),Vl).join(""),Vl=t=>{const[,e,a,n]=t;return void 0!==e?e:void 0!==a?a.replace(/\\(["\\])/g,"$1"):(n??"").replace(/\\(.)/g,"$1")},Gl={"git-upload-pack":{"content-type":"application/x-git-upload-pack-request",accept:"application/x-git-upload-pack-result"},"git-receive-pack":{"content-type":"application/x-git-receive-pack-request",accept:"application/x-git-receive-pack-result"}},Yl={"git-upload-pack":"application/x-git-upload-pack-advertisement","git-receive-pack":"application/x-git-receive-pack-advertisement"},Xl={"git-protocol":"version=2"},Jl={},Ql=t=>"git-upload-pack"===t?Xl:Jl,Zl=(t,e,a)=>{const n=(t=>{(t=>{if(Sl.test(t))throw L("contains forbidden control character")})(t);const e=(t=>{if(t.startsWith("http://")||t.startsWith("https://"))return"http";if(t.startsWith("ssh://"))return"sshUrl";if(Ml(t))return"scp";throw L("unrecognised remote URL")})(t);return"http"===e?{kind:"http",url:t}:"sshUrl"===e?(t=>{const e=Ol(t),a=""===e.username?void 0:e.username,n=Pl(e.hostname),r=""===e.port?void 0:Number(e.port),i=Nl(e.pathname);return Ul(Ll(a,n),i),Rl(a,n,r,i)})(t):(t=>{const{hostToken:e,path:a}=Cl(t);Ul(e,a);const{user:n,host:r}=Hl(e);return Rl(n,r,void 0,a)})(t)})(e);if("http"===n.kind)return th(t,n.url,a);if(void 0===t.ssh)throw R(t.runtime,"ssh: transport unavailable in this runtime");return new ah(t,t.ssh,n,a)},th=(t,e,a)=>{const n=((t,e={})=>{const a=void 0!==e.logger?(n=e.logger,{log:t=>n.log(El(t))}):void 0;var n;let r=t.transport;return r=rr(e.retry??Il)(r),void 0!==e.auth&&(r=ir(e.auth)(r)),void 0!==a&&(r=or({logger:a})(r)),r})(t,void 0!==t.config?.auth?{auth:t.config.auth}:{}),r=async e=>{const a=await n.request({url:e.url,method:e.method,headers:e.headers,...void 0!==e.body?{body:e.body}:{},...void 0!==t.signal?{signal:t.signal}:{}});if(200!==a.statusCode)throw U(a.statusCode,`${e.reasonLabel} returned ${a.statusCode}`);return ko(nr(a.body),{v2:!0})};return{advertisement:()=>r({url:Wo(e,a),method:"GET",headers:{accept:Yl[a],...Ql(a)},reasonLabel:`${a} discovery`}),exchange:t=>r({url:eh(e,a),method:"POST",headers:{...Gl[a],...Ql(a)},reasonLabel:a,body:t}),close:async()=>{},servicePrologue:!0}},eh=(t,e)=>{let a;try{a=new URL(t)}catch{throw zi("invalid URL")}if(""!==a.hash)throw zi("fragment must not be set");const n=a.pathname.endsWith("/")?a.pathname.slice(0,-1):a.pathname;return`${a.protocol}//${a.host}${n}/${e}${a.search}`};class ah{servicePrologue=!1;ctx;ssh;remote;service;channel;lines;constructor(t,e,a,n){this.ctx=t,this.ssh=e,this.remote=a,this.service=n}advertisement=()=>this.continuation();exchange=async t=>{const e=await this.openChannel();return this.continuation(rh(e.stdin,t))};close=async()=>{if(void 0===this.channel)return;const t=await this.channel;await t.close()};openChannel(){return this.channel??=nh(this.ctx,this.ssh,this.remote,this.service),this.channel}async continuation(t){const e=await this.openChannel(),a=await this.sharedIterator(e),n=this.ctx.signal;return{[Symbol.asyncIterator]:()=>ih({iterator:a,channel:e,signal:n,awaitWrite:t})}}sharedIterator(t){return this.lines??=Promise.resolve(ko(nr(t.stdout))[Symbol.asyncIterator]()),this.lines}}const nh=async(t,e,a,n)=>{const r=await(async t=>{const e=t.env?.get("GIT_SSH_COMMAND");if(jl(e))return Bl(e);const a=await ne(t),n=a.core?.sshCommand;if(jl(n))return Bl(n);const r=t.env?.get("GIT_SSH");return jl(r)?{program:r,baseArgs:[]}:{program:"ssh",baseArgs:[]}})(t),i=[...(s={service:n,parsed:a,baseArgs:r.baseArgs}).baseArgs,...(o=s.parsed.port,void 0===o?[]:["-p",String(o)]),Ll(s.parsed.user,s.parsed.host),Wl(s.service,s.parsed.path)];var o,s;return e.open({command:r.program,args:i,env:{},...void 0!==t.signal?{signal:t.signal}:{}})},rh=(t,e)=>{let a;const n=(async(t,e)=>{const a=t.getWriter();try{await a.write(e)}finally{a.releaseLock()}})(t,e).catch(t=>{a=t});return async()=>{if(await n,void 0!==a)throw a}},ih=({iterator:t,channel:e,signal:a,awaitWrite:n})=>({next:async()=>{const r=await t.next();return r.done&&(await oh(e,a),await(n?.())),r},return:async()=>({done:!0,value:void 0})}),oh=async(t,e)=>{const a=await t.exit;if(0!==a){if(!0===e?.aborted)throw h();throw _(`ssh exited with code ${a}`)}},sh=t=>{const e=Ri.filter(t=>"thin-pack"!==t&&"no-progress"!==t&&t!==Li);return[...ji(t,e),Li]},ch=t=>{const e=new Set,a=[];for(const n of t)e.has(n.id)||(e.add(n.id),a.push(n.id));return a},dh=t=>t.includes("filter"),uh="clone:discover",fh=async(t,e)=>{if(await t.fs.exists(`${t.layout.gitDir}/HEAD`))throw W(t.layout.workDir);if(""===e.url)throw j();const a=void 0!==e.filter?co(so(e.filter)):void 0;t.progress.start(uh);try{const n=await pl(t,{initialBranch:e.initialBranch??"main",bare:e.bare??!1});try{return await lh(t,e,n.gitDir,a)}catch(e){throw await t.fs.rmRecursive(t.layout.gitDir).catch(()=>{}),e}}finally{t.progress.end(uh)}},lh=async(t,e,a,n)=>{const r=Zl(t,e.url,"git-upload-pack");try{return await hh(t,e,a,n,r)}finally{await r.close()}},hh=async(t,e,a,n,r)=>{const i=await bl(r),o=i.advertisement;if(0===o.refs.length)throw j();if(void 0!==n&&!dh(o.capabilities))throw Zi();const s=sh(o.capabilities),c=ch(o.refs),d=await Ta(t,(t,e)=>xl(t,r,i.version,e),{wants:c,haves:[],capabilities:s,progressOp:"clone:write-objects",...void 0!==e.depth?{depth:e.depth}:{},...void 0!==n?{filter:n,promisor:!0}:{}});d.shallow.length>0&&await Da(t,{shallow:d.shallow,unshallow:d.unshallow});const u=Al(e.url),f=await mh(t,o,u),l=await yh(t,o,u);return await wh(t,e.url,gh(o),n),{path:a,head:l,fetchedRefs:f}},wh=async(t,e,a,n)=>{await Aa(t,[{section:"remote",subsection:"origin",key:"url",value:e},{section:"remote",subsection:"origin",key:"fetch",value:"+refs/heads/*:refs/remotes/origin/*"},...void 0!==a?[{section:"branch",subsection:a,key:"remote",value:"origin"},{section:"branch",subsection:a,key:"merge",value:`refs/heads/${a}`}]:[],...void 0!==n?[{section:"core",key:"repositoryformatversion",value:"1"},{section:"remote",subsection:"origin",key:"promisor",value:"true"},{section:"remote",subsection:"origin",key:"partialclonefilter",value:n},{section:"extensions",key:"partialClone",value:"origin"}]:[]])},mh=async(t,e,a)=>{const n=gh(e),r=[];for(const i of e.refs)if("HEAD"!==i.name&&Sa(i.name)){if(i.name.startsWith("refs/heads/")){const e=i.name.slice(11),o=`refs/remotes/origin/${e}`;if(await ph(t,o,i.id,a),r.push({name:o,id:i.id}),void 0!==n&&e===n){const e=i.name;await ph(t,e,i.id,a),r.push({name:e,id:i.id})}continue}if(i.name.startsWith("refs/tags/")){const e=i.name;await ph(t,e,i.id,a),r.push({name:e,id:i.id});continue}t.logger?.debug?.("clone: skipping unsupported ref namespace",{name:i.name})}return r},ph=async(t,e,a,n)=>{const r=`${t.layout.gitDir}/${e}`;await t.fs.writeUtf8(r,`${a}\n`),await sa(t,e,ze,a,zs(n))},gh=t=>{const e=t.capabilities.find(t=>t.startsWith("symref=HEAD:refs/heads/"));if(void 0!==e)return e.slice(23)},yh=async(t,e,a)=>{const n=gh(e),r=e.head?.id;if(void 0!==n){const e=`refs/heads/${n}`;return await t.fs.writeUtf8(`${t.layout.gitDir}/HEAD`,`ref: ${e}\n`),await vh(t,r,a),e}if(void 0!==e.head)return await t.fs.writeUtf8(`${t.layout.gitDir}/HEAD`,`${e.head.id}\n`),void await vh(t,r,a)},vh=async(t,e,a)=>{void 0!==e&&await sa(t,"HEAD",ze,e,zs(a))},bh=t=>`${t.layout.gitDir}/${Jt}`,kh=t=>Mf(t,bh(t)),$h=async t=>{const e=bh(t);await t.fs.exists(e)&&await t.fs.rm(e)},xh=(t,e)=>{return`Revert ${a=ur(t.message),`"${a.replace(/([\\"])/g,"\\$1")}"`}\n\nThis reverts commit ${e}.\n`;var a},Ih=(t,e,a)=>{const n=t.gpg?.format??"openpgp",r="ssh"===n?t.gpg?.ssh?.program:t.gpg?.program;return{format:n,selector:"ssh"===n?a??t.user?.signingKey??"":Na({...void 0!==t.user?.signingKey?{signingKey:t.user.signingKey}:{},...void 0!==a?{keyOverride:a}:{},fallbackIdent:`${e.name} <${e.email}>`}),...void 0!==r?{program:r}:{}}},Eh=async(t,e,a)=>{const n=await Oa(t,e,a);if(!n.ok)throw"off-node"===n.reason?B(n.reason):B(n.reason,a.format);return n.armor},Th=async(t,e)=>{await $c(t),await xc(t,"commit");const a=await Ah(t),{mergeHead:n,cherryPickHead:r,revertHead:i}=a,o=Mh(a);await Dc(t,void 0!==o?{except:o}:{});const s=e.noVerify??!1;await(async(t,e)=>{e||await Ma(t,"pre-commit")})(t,s);const c=void 0!==n||void 0!==r||void 0!==i,d=c?"merge":"message",u=await Nh(t,e,c),f=await ne(t),l=Lh(f.user);void 0===e.author&&void 0===l&&await ka(t,"user",void 0,["name","email"]);const h=Jf(Rh(e.author,l)),w=Qf(Uh(e.committer,h,l)),m=await de(t);Hh(m.entries);const p=await jh(t,m.entries),g=await Ic(t),y="symbolic"===g.kind?await _h(t,g.target):g.id,v=Ch(y,n);if(!e.allowEmpty&&void 0!==y&&void 0===n&&await Wh(t,y)===p)throw F();const b=await(async(t,e,a)=>{if(void 0===t.hooks)return e;const n=`${t.layout.gitDir}/COMMIT_EDITMSG`;await t.fs.writeUtf8(n,e),await Ma(t,"prepare-commit-msg",{args:[n,a.source]}),a.noVerify||await Ma(t,"commit-msg",{args:[n]});const r=await t.fs.readUtf8(n);return Zf(r,{allowEmpty:a.allowEmptyMessage})})(t,u,{noVerify:s,allowEmptyMessage:e.allowEmptyMessage??!1,source:d}),k={tree:p,parents:v,author:h,committer:w,message:b,extraHeaders:[]},$=await Dh(t,f,k,w,e),x=await $a(t,{...k,...void 0!==$?{gpgSignature:$}:{}}),I="symbolic"===g.kind?g.target:void 0,E=Ph(b,y,n,r);return await Sh(t,{branch:I,id:x,parentId:y,reflogMessage:E}),await Oh(t,a),await oa(t,"post-commit"),{id:x,tree:p,branch:I,parents:v}},Dh=async(t,e,a,n,r)=>{if(r.sign??!0===e.commit?.gpgSign)return(async(t,e,a,n,r)=>{const i=Ih(e,n,r),o=Ca({data:a}),s=await Eh(t,o,i);return s.endsWith("\n")?s.slice(0,-1):s})(t,e,a,n,r.signKey)},Sh=async(t,e)=>{const{branch:a,id:n,parentId:r,reflogMessage:i}=e;void 0===a?(await t.fs.writeUtf8(`${t.layout.gitDir}/HEAD`,`${n}\n`),await sa(t,"HEAD",r??ze,n,i)):await fe(t,a,n,void 0!==r?{expected:r,reflogMessage:i}:{reflogMessage:i})},Ah=async t=>({mergeHead:await mc(t),cherryPickHead:await qf(t),revertHead:await kh(t)}),Mh=t=>void 0!==t.mergeHead?Zs:void 0!==t.cherryPickHead?ec:void 0!==t.revertHead?ac:void 0,Oh=async(t,e)=>{if(void 0===e.mergeHead)return void 0!==e.cherryPickHead?(await Kf(t),void await yc(t)):void(void 0!==e.revertHead&&(await $h(t),await yc(t)));await gc(t)},Nh=async(t,e,a)=>{if(e.message.length>0||!a)return Zf(e.message,{allowEmpty:e.allowEmptyMessage??!1});const n=await pc(t);return Zf(tl(n??""),{allowEmpty:e.allowEmptyMessage??!1})},Ph=(t,e,a,n)=>{const r=ur(t);return void 0===e?(t=>`commit (initial): ${t}`)(r):void 0!==a?(t=>`commit (merge): ${t}`)(r):void 0!==n?Ws(r):js(r)},Ch=(t,e)=>{const a=[];return void 0!==t&&a.push(t),void 0!==e&&a.push(e),a},Hh=t=>{const e=new Set;for(const a of t)0!==a.flags.stage&&e.add(a.path);if(e.size>0)throw C(e.size,[...e])},Lh=t=>{if(void 0!==t?.name&&void 0!==t?.email)return{name:t.name,email:t.email,timestamp:Math.floor(Date.now()/1e3),timezoneOffset:"+0000"}},Rh=(t,e)=>{const a={};return void 0!==t&&(a.explicit=t),void 0!==e&&(a.configUser=e),a},Uh=(t,e,a)=>{const n={};return void 0!==t&&(n.explicit=t),void 0!==e&&(n.author=e),void 0!==a&&(n.configUser=a),n},_h=async(t,e)=>{try{return await Ae(t,e)}catch{return}},Wh=async(t,e)=>{const a=await oe(t,e);return"commit"!==a.type?ze:a.data.tree},jh=async(t,e)=>{const a={files:new Map,subdirs:new Map};for(const t of e)Bh(a,t.path.split("/"),t);return Fh(t,a)},Bh=(t,e,a)=>{if(1===e.length)return void t.files.set(e[0],{id:a.id,mode:a.mode});const[n,...r]=e,i=n;let o=t.subdirs.get(i);void 0===o&&(o={files:new Map,subdirs:new Map},t.subdirs.set(i,o)),Bh(o,r,a)},Fh=async(t,e)=>{const a=[];for(const[t,n]of e.files)a.push({mode:n.mode,name:t,id:n.id});const n=await Promise.all(Array.from(e.subdirs).map(async([e,a])=>({name:e,id:await Fh(t,a)})));for(const{name:t,id:e}of n)a.push({mode:"40000",name:t,id:e});return Pa(t,a)},zh=t=>t,qh=async(t,e)=>(await bc(t),void 0===e.scope?await Ha({ctx:t,key:e.key}):await Ha({ctx:t,key:e.key,scope:e.scope})),Kh=async(t,e)=>(await bc(t),void 0===e.scope?await La({ctx:t,key:e.key}):await La({ctx:t,key:e.key,scope:e.scope})),Vh=async(t,e)=>{await bc(t);const a=void 0===e.scope?await Ra({ctx:t}):await Ra({ctx:t,scope:e.scope}),n=[];for(const{scope:t,section:r}of a)for(const a of r.entries){const i=Ua(r,a.key);e.keyPattern.test(i)&&(void 0===e.valuePattern||e.valuePattern.test(a.value??""))&&n.push({key:zh(i),value:a.value,scope:t})}return{entries:n}},Gh=async(t,e)=>{await bc(t);const a=void 0===e?.scope?await Ra({ctx:t}):await Ra({ctx:t,scope:e.scope}),n=[];for(const{scope:t,section:e}of a)for(const a of e.entries){const r=Ua(e,a.key);n.push({key:zh(r),value:a.value,scope:t})}return{entries:n}},Yh=async(t,e)=>{await bc(t);const a=e.scope??"local",n=await La({ctx:t,key:e.key,scope:a});if(n.values.length>1)throw z(e.key,n.values.length,"overwrite",a);return await ja({ctx:t,key:e.key,value:e.value,scope:a}),{key:e.key,value:e.value,scope:a}},Xh=async(t,e)=>{await bc(t);const a=e.scope??"local",n=await La({ctx:t,key:e.key,scope:a});if(0===n.values.length)return{key:e.key,scope:a,removed:!1};if(n.values.length>1)throw z(e.key,n.values.length,"remove",a);const[r]=n.values;return await Ba({ctx:t,key:e.key,scope:a}),{key:e.key,scope:a,removed:!0,previousValue:r.value}},Jh=async(t,e)=>{await bc(t);const a=e.scope??"local",n=await La({ctx:t,key:e.key,scope:a});return 0===n.values.length?{key:e.key,scope:a,removed:0}:(await Fa({ctx:t,key:e.key,scope:a}),{key:e.key,scope:a,removed:n.values.length})},Qh=async(t,e)=>{await bc(t);const a=e.scope??"local";return await Wa({ctx:t,oldName:e.oldName,newName:e.newName,scope:a}),{oldName:e.oldName,newName:e.newName,scope:a}},Zh=async(t,e)=>{await bc(t);const a=e.scope??"local";return await _a({ctx:t,sectionName:e.name,scope:a}),{name:e.name,scope:a}},tw=async(t,e={})=>{if(await $c(t),await xc(t,"merge --continue"),void 0===await mc(t))throw i("merge");return Th(t,ew(e))},ew=t=>({message:t.message??"",...void 0!==t.author&&{author:t.author},...void 0!==t.committer&&{committer:t.committer},...void 0!==t.noVerify&&{noVerify:t.noVerify}}),aw=(t,e)=>t.depth!==e.depth?t.depth-e.depth:t.foundOrder-e.foundOrder,nw=t=>Bt(t,{anchored:!0}),rw=(t,e)=>e?t.startsWith("refs/")?t.slice(5):t:t.startsWith("refs/tags/")?t.slice(10):t,iw=(t,e)=>e.priority>t.priority||2===e.priority&&e.taggerDate>t.taggerDate,ow=async(t,e)=>{let a=await oe(t,e),n=!1,r=0;for(let e=0;"tag"===a.type;e+=1){if(za(e))return;n||(r=a.data.tagger?.timestamp??0),n=!0,a=await oe(t,a.data.object)}if("commit"===a.type)return{commit:a,viaTag:n,taggerDate:r}},sw=["candidates","exactMatch","firstParent","dirty","broken"],cw=t=>void 0===t?[]:"string"==typeof t?[t]:t,dw=t=>{if(void 0!==t.candidates&&(!Number.isInteger(t.candidates)||t.candidates<0))throw u("candidates",`expected a non-negative integer, got ${t.candidates}`);return!0===t.exactMatch?0:t.candidates??10},uw=Number.MIN_SAFE_INTEGER,fw=(t,e)=>t<e,lw=(t,e)=>(t=>{const e=[...t].map(t=>"*"===t?".*":"?"===t?".":t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("");return new RegExp(`^${e}$`)})(t).test(e),hw=t=>({...t,generation:t.generation+1,distance:t.distance+1}),ww=(t,e)=>({...t,steps:[...mw(t),{kind:"parent",number:e}],generation:0,distance:t.distance+65535}),mw=t=>t.generation>0?[...t.steps,{kind:"ancestor",count:t.generation}]:t.steps,pw=t=>void 0===t?[]:"string"==typeof t?[t]:t,gw=async(t,e)=>sd(t,await Nd(t,e),"commit"),yw=async(t,e)=>sd(t,await Nd(t,e),"tree"),vw=async(t,e,a={})=>{await $c(t);const n=await gw(t,e??"HEAD"),r=0===(i=(await oe(t,n)).data.committer.timestamp)?0:i>uw+86400?i-86400:uw;var i;const o=(t=>({qualifies:e=>"HEAD"!==e&&!(t.tags&&!e.startsWith("refs/tags/"))&&(e=>0===t.refs.length||t.refs.some(t=>lw(t,e)))(e)&&!(e=>t.exclude.some(t=>lw(t,e)))(e)}))((t=>({tags:!0===t.tags,refs:pw(t.refs),exclude:pw(t.exclude)}))(a)),s=[...await Qe(t)].filter(t=>o.qualifies(t)).sort(),c=new Map;for(const e of s)await bw(t,e,c,r);const d=c.get(n);return void 0===d?{oid:n,ref:void 0,tagDeref:!1,steps:[]}:{oid:n,ref:d.ref,tagDeref:d.tagDeref,steps:mw(d)}},bw=async(t,e,a,n)=>{const r=await kw(t,e,a,n);if(void 0===r)return;const i=[r];for(;i.length>0;){const e=i.pop(),r=a.get(e.id),o=await $w(t,e,r,a,n);for(let t=o.length-1;t>=0;t-=1)i.push(o[t])}},kw=async(t,e,a,n)=>{const r=await Me(t).resolveDirect(e);if("direct"!==r.kind)return;const i=await ow(t,r.id);if(void 0===i)return;if(fw(i.commit.data.committer.timestamp,n))return;const o={ref:e,tagDeref:i.viaTag,fromTag:e.startsWith("refs/tags/"),taggerDate:i.viaTag?i.taggerDate:i.commit.data.committer.timestamp,generation:0,distance:0,steps:[]};return xw(a,i.commit.id,o)?i.commit:void 0},$w=async(t,e,a,n,r)=>{const i=[],o=e.data.parents;for(let e=0;e<o.length;e+=1){const s=o[e],c=0===e?hw(a):ww(a,e+1);if(!xw(n,s,c))continue;const d=await oe(t,s);"commit"===d.type&&(fw(d.data.committer.timestamp,r)||i.push(d))}return i},xw=(t,e,a)=>{const n=t.get(e);return!(void 0!==n&&!((t,e)=>t.fromTag!==e.fromTag?e.fromTag:t.distance!==e.distance?t.distance>e.distance:t.taggerDate>e.taggerDate)(n,a)||(t.set(e,a),0))},Iw="status:scan",Ew=async t=>{await $c(t);const e=await Ic(t),a=Ec(e),n="direct"===e.kind,r=await de(t),i=function(t){const e=[],a=new Map;for(const n of t.entries)if(0===n.flags.stage)e.push(n);else{const t=a.get(n.path)??{};a.set(n.path,mr(t,n))}return{staged:e,unmerged:a}}(r),o=new Map(i.staged.map(t=>[t.path,t])),s=new Set(i.unmerged.keys());for(const t of o.keys())s.add(t);t.progress.start(Iw);try{const e=((t,e)=>{let a=0,n=0;return{tick:()=>{a+=1;const r=Math.floor(a/100);r>n&&(n=r,t.update(e,a))}}})(t.progress,Iw),c=await we(t),d=await Tw(t,i.staged,e,c),u=await Dw(t,s),f=await qa(t),l=Sw(r,f,i.unmerged),h=Aw(l,d,f,o),w=await Cw(t,i.unmerged);return{branch:a,detached:n,changes:h,untracked:u,unmerged:w,clean:0===h.length&&0===u.length&&0===w.length}}finally{t.progress.end(Iw)}},Tw=async(t,e,a,n)=>{const r=new Map;return await Promise.all(e.map(async e=>{e.flags.skipWorktree||r.set(e.path,await Ka(t,e,n)),a.tick()})),r},Dw=async(t,e)=>{const a=await me(t),n=[];for await(const{path:r}of pe(t,{ignore:a}))e.has(r)||n.push(r);return n.sort(At)},Sw=(t,e,a)=>{const n=new Map;for(const r of wr(t,e).changes){const t=Nt(r);a.has(t)||n.set(t,Ow(r))}return n},Aw=(t,e,a,n)=>{const r=new Set(t.keys());for(const[t,a]of e)void 0!==Nw(a.status)&&r.add(t);return[...r].map(r=>Mw(r,t.get(r),e.get(r),a,n.get(r))).sort((t,e)=>At(t.path,e.path))},Mw=(t,e,a,n,r)=>{const i=n?.entries.get(t),o=void 0===a?void 0:Nw(a.status);return{path:t,...void 0!==e&&{staged:e},...void 0!==o&&{unstaged:o},...void 0!==i&&{head:{id:i.id,mode:i.mode}},...void 0!==r&&{index:{id:r.id,mode:r.mode}},...void 0!==a?.worktreeMode&&{worktree:{mode:a.worktreeMode}}}},Ow=t=>"add"===t.type?"added":"delete"===t.type?"deleted":"type-change"===t.type?"type-changed":"modify"===t.type&&t.oldId===t.newId?"mode-changed":"modified",Nw=t=>"absent"===t?"deleted":"type-changed"===t?"type-changed":"mode-changed"===t?"mode-changed":"modified"===t?"modified":void 0,Pw=t=>({id:t.id,mode:t.mode}),Cw=(t,e)=>Promise.all([...e].map(async([e,a])=>{const n=await Hw(t,e);return{kind:sr(a),path:e,...a.stage1&&{base:Pw(a.stage1)},...a.stage2&&{ours:Pw(a.stage2)},...a.stage3&&{theirs:Pw(a.stage3)},...void 0!==n&&{worktree:{mode:n}}}})),Hw=async(t,e)=>{const a=await t.fs.lstat(he(t.layout.workDir,e)).catch(()=>{});return void 0===a?void 0:ke(a)},Lw="refs/tags/";async function Rw(t,e,a={}){if(await $c(t),!0===a.contains)return Uw(t,e,(t=>{for(const e of sw)if(void 0!==t[e])throw u(e,`option ${e} cannot be combined with contains`);return{all:!0===t.all,include:cw(t.match),exclude:cw(t.exclude),always:!0===t.always}})(a));const n=((t,e)=>{const a=!0===t.dirty,n=!0===t.broken;if((a||n)&&e)throw u("dirty","option dirty and commit-ishes cannot be used together");return{tags:!0===t.tags,all:!0===t.all,maxCandidates:dw(t),always:!0===t.always,firstParent:!0===t.firstParent,include:cw(t.match),exclude:cw(t.exclude),dirty:a,broken:n}})(a,void 0!==e),r=await Jd(t,e??"HEAD"),i=await Bw(t,n),o=await Fw(t,n),s=_w(n),c=o.get(r);if(void 0!==c&&c.priority>=s)return Ww(c.name,0,r,i,n.all);if(0===n.maxCandidates){if(n.always)return jw(r,i);throw q(r)}const{best:d,sawUnannotated:f}=await Gw(t,r,o,n,s);if(void 0!==d)return Ww(d.name,d.depth,r,i,n.all);if(n.always)return jw(r,i);if(0===o.size)throw K(r);throw f?V(r):G(r)}const Uw=async(t,e,a)=>{const n=!a.all,r=t=>n?t.map(t=>`${Lw}${t}`):[],i=await vw(t,e,{tags:n,refs:r(a.include),exclude:r(a.exclude)});if(void 0===i.ref&&!a.always)throw Y(i.oid);return i},_w=t=>t.all?0:t.tags?1:2,Ww=(t,e,a,n,r)=>({tag:re.from(r?`refs/${t}`:`${Lw}${t}`),name:t,distance:e,oid:a,exact:0===e,dirty:n}),jw=(t,e)=>({tag:void 0,name:"",distance:0,oid:t,exact:!1,dirty:e}),Bw=async(t,e)=>{if(!e.dirty&&!e.broken)return!1;try{const e=await Ew(t);return e.changes.length>0||e.unmerged.length>0}catch(t){if(e.broken)return!0;throw t}},Fw=async(t,e)=>{const a=[...await Qe(t)].filter(t=>"HEAD"!==t&&(e.all||t.startsWith(Lw))).sort(),n=((t,e)=>{const a=t.map(nw),n=e.map(nw);return{matches:t=>!(0!==a.length&&!a.some(e=>e.test(t))||n.some(e=>e.test(t)))}})(e.include,e.exclude),r=Me(t),i=new Map;for(const o of a){const a=await r.resolveDirect(o);if("direct"!==a.kind)continue;const s=await ow(t,a.id);if(void 0===s)continue;const c=rw(o,e.all);if(!n.matches(c))continue;const d=zw(o,c,s),u=i.get(s.commit.id);(void 0===u||iw(u,d))&&i.set(s.commit.id,d)}return i},zw=(t,e,a)=>({name:e,priority:t.startsWith(Lw)?a.viaTag?2:1:0,taggerDate:a.taggerDate}),qw=t=>{const{step:e,candidates:a,reach:n,tally:r}=t,i=e.commit.id,o=t.nameMap.get(i);if(void 0!==o){const e=((t,e,a,n,r,i)=>{if(t.priority<e)return{annotated:0,skippedLowPriority:!0};const o=r.length;return r.push({name:t.name,commitOid:a,depth:n,foundOrder:o}),Zw(i,a).add(o),{annotated:2===t.priority?1:0,skippedLowPriority:!1}})(o,t.minPriority,i,t.depth,a,n);r.annotatedCount+=e.annotated,r.sawUnannotated=r.sawUnannotated||e.skippedLowPriority}return Jw(a,n.get(i)),Qw(n,e.commit,t.firstParent),((t,e,a,n)=>t>0&&e.frontierEmpty&&((t,e)=>{if(void 0===e)return!1;const a=Math.min(...t.map(t=>t.depth));return t.every(t=>t.depth!==a||e.has(t.foundOrder))})(a,n))(r.annotatedCount,e,a,n.get(i))},Kw=(t,e,a)=>t.length===e||t.length===a,Vw=(t,e,a,n)=>(Xw(t,a.commit,e,n),((t,e,a,n)=>!0===t.get(n)?.has(e.foundOrder)&&a.frontier().every(a=>!0===t.get(a)?.has(e.foundOrder)))(t,e,a,a.commit.id)),Gw=async(t,e,a,n,r)=>{const i=a.size,o=new Map,s=[];let c=0;const d={annotatedCount:0,sawUnannotated:!1};let u;for await(const f of Va(t,{from:[e],firstParent:n.firstParent})){if(void 0===u&&Kw(s,n.maxCandidates,i)&&(u=Yw(s),void 0===u))break;if(void 0===u){if(c+=1,qw({step:f,depth:c-1,nameMap:a,minPriority:r,candidates:s,reach:o,tally:d,firstParent:n.firstParent}))break}else if(Vw(o,u,f,n.firstParent))break}return{best:u??Yw(s),sawUnannotated:d.sawUnannotated}},Yw=t=>[...t].sort(aw)[0],Xw=(t,e,a,n)=>{Jw([a],t.get(e.id)),Qw(t,e,n)},Jw=(t,e)=>{for(const a of t)void 0!==e&&e.has(a.foundOrder)||(a.depth+=1)},Qw=(t,e,a)=>{const n=t.get(e.id);if(void 0!==n)for(const r of Ga(e,a)){const e=Zw(t,r);for(const t of n)e.add(t)}},Zw=(t,e)=>{let a=t.get(e);return void 0===a&&(a=new Set,t.set(e,a)),a};async function tm(t,e={}){await $c(t);const a=await yw(t,e.from??"HEAD"),n=void 0!==e.to?await yw(t,e.to):void 0,r=function(t,e){const a=t.detectRenames??e?.detectRenames,n=t.ignoreWhitespace??e?.ignoreWhitespace;return{...!0===a?{detectRenames:!0}:{},...void 0!==t.renameOptions?{renameOptions:t.renameOptions}:{},...!0===t.recursive?{recursive:!0}:{},...!0===t.withStat?{withStat:!0}:{},...void 0!==n?{ignoreWhitespace:n}:{},...!0===(t.ignoreCrAtEol??e?.ignoreCrAtEol)?{ignoreCrAtEol:!0}:{},...!0===(t.ignoreBlankLines??e?.ignoreBlankLines)?{ignoreBlankLines:!0}:{}}}(e,t.config);return Re(t,a,n,r)}const em=t=>t.startsWith(bu)?t.slice(11):t,am="origin",nm=t=>void 0!==t.remote&&1===t.remote.size?t.remote.keys().next().value:void 0,rm=(t,e,a)=>e??(void 0!==a?t.branch?.get(a)?.remote:void 0)??nm(t)??am,im=(t,e,a)=>e??(void 0!==a?t.branch?.get(a)?.pushRemote:void 0)??t.remotePushDefault??(void 0!==a?t.branch?.get(a)?.remote:void 0)??nm(t)??am,om=/^[A-Za-z0-9._-]+$/,sm=t=>{if(!om.test(t))throw u("remote",`invalid remote name: ${t}`)},cm="fetch:negotiate",dm=async(t,e={})=>{await $c(t);const a=await Ic(t),n=Ec(a),r=void 0!==n?em(n):void 0,i=await ne(t),o=rm(i,e.remote,r),{url:s,filter:c}=await wm(t,o);t.progress.start(cm);try{return await um(t,e,o,s,c)}finally{t.progress.end(cm)}},um=async(t,e,a,n,r)=>{const i=Zl(t,n,"git-upload-pack");try{return await fm(t,e,a,n,r,i)}finally{await i.close()}},fm=async(t,e,a,n,r,i)=>{const o=await bl(i),s=o.advertisement;if(0===s.refs.length)throw j();if(void 0!==r&&!dh(s.capabilities))throw Zi();const c=sh(s.capabilities),d=ch(s.refs);if(void 0===r&&void 0===e.depth&&await lm(t,d))return hm(t,e,a,n,s,[],[]);const u=await mm(t,a),f=await Ta(t,(t,e)=>xl(t,i,o.version,e),{wants:d,haves:u,capabilities:c,progressOp:"fetch:write-objects",...void 0!==e.depth?{depth:e.depth}:{},...void 0!==r?{filter:r,promisor:!0}:{}});return(f.shallow.length>0||f.unshallow.length>0)&&await Da(t,{shallow:f.shallow,unshallow:f.unshallow}),hm(t,e,a,n,s,f.shallow,f.unshallow)},lm=async(t,e)=>{for(const a of e)if(!await Ya(t,a))return!1;return!0},hm=async(t,e,a,n,r,i,o)=>({remote:a,url:n,updatedRefs:await bm(t,a,r),prunedRefs:!0===e.prune?await xm(t,a,r):[],shallow:i,unshallow:o}),wm=async(t,e)=>{sm(e);const a=await ne(t),n=a.remote?.get(e);if(void 0===n?.url||""===n.url)throw await ka(t,"remote",e,["url"]),X(e);const r=void 0!==n.partialCloneFilter?co(so(n.partialCloneFilter)):void 0;return{url:n.url,filter:r}},mm=async(t,e)=>{const a=await pm(t,e);if(0===a.length)return[];const n=new Set,r=[];for(const t of a)if(!n.has(t)&&(n.add(t),r.push(t),r.length>=Xa))return r;const i=a.slice(0,Ja);for await(const e of Ke(t,{from:i,ignoreMissing:!0,verifyHash:!1}))if(!n.has(e.id)&&(n.add(e.id),r.push(e.id),r.length>=Xa))break;return r},pm=async(t,e)=>{const a=[],n=[`refs/remotes/${e}`,"refs/tags"];for(const e of n){const n=`${t.layout.gitDir}/${e}`;await t.fs.exists(n)&&await gm(t,n,a)}const r=`refs/remotes/${e}/`,i=await Me(t).getPackedRefs();for(const t of i.entries)(t.name.startsWith(r)||t.name.startsWith("refs/tags/"))&&a.push(t.id);return a},gm=async(t,e,a)=>{const n=await t.fs.readdir(e);for(const r of n){const n=`${e}/${r.name}`;if(r.isDirectory){await gm(t,n,a);continue}const i=(await t.fs.readUtf8(n)).trim();vm(i)&&a.push(i)}},ym=/^[0-9a-f]{40}([0-9a-f]{24})?$/i,vm=t=>ym.test(t),bm=async(t,e,a)=>{const n=[];for(const r of a.refs){const a=km(e,r);if(void 0===a)continue;const i=await $m(t,a);i!==r.id?(await fe(t,a,r.id,{reflogMessage:qs(e)}),n.push({name:a,oldId:i,newId:r.id})):n.push({name:a,oldId:i,newId:r.id})}return n},km=(t,e)=>{if("HEAD"!==e.name&&Sa(e.name)){if(e.name.startsWith(bu)){const a=`refs/remotes/${t}/${e.name.slice(11)}`;if(!Sa(a))return;return a}return e.name.startsWith("refs/tags/")?e.name:void 0}},$m=async(t,e)=>{Pe(e);const a=`${t.layout.gitDir}/${e}`;if(!await t.fs.exists(a))return;const n=(await t.fs.readUtf8(a)).trim();return vm(n)?n:void 0},xm=async(t,e,a)=>{const n=new Set(a.refs.filter(t=>t.name.startsWith(bu)).map(t=>t.name.slice(11))),r=`${t.layout.gitDir}/refs/remotes/${e}`;if(!await t.fs.exists(r))return[];const i=[];return await Im(t,r,"",n,e,i),i},Im=async(t,e,a,n,r,i)=>{const o=await t.fs.readdir(e);for(const s of o){const o=`${e}/${s.name}`,c=""===a?s.name:`${a}/${s.name}`;if(s.isDirectory){await Im(t,o,c,n,r,i);continue}if(n.has(c))continue;const d=`refs/remotes/${r}/${c}`;if(!Sa(d)){t.logger?.warn?.("fetch.prune: skipping unsafe ref name",{name:d});continue}const u=d;try{await fe(t,u,ze,{delete:!0})}catch(e){if(Em(e)){t.logger?.warn?.("fetch.prune: skipping packed-only ref",{name:u});continue}throw e}i.push(u)}},Em=e=>e instanceof t&&"UNSUPPORTED_OPERATION"===e.data.code&&"delete-packed-ref"===e.data.operation,Tm=async(t,e,a)=>!!await t.fs.exists(Qa(t.layout.gitDir,a))||void 0!==await e.lookup(a),Dm=async(e,a)=>{await $c(e);const n=await ne(e),r=n.extensions?.partialClone;if(void 0===r)return{kind:"no-promisor"};const i=n.remote?.get(r)?.url;if(void 0===i||""===i)throw X(r);const o=await(async(t,e)=>{const a=Za(t),n=new Set,r=[];for(const i of e)n.has(i)||(n.add(i),await Tm(t,a,i)||r.push(i));return r})(e,a);if(0===o.length)return{kind:"fetched",remote:r,requested:a.length,fetched:0};const s=Zl(e,i,"git-upload-pack");try{const a=await bl(s),n=sh(a.advertisement.capabilities);try{await Ta(e,(t,e)=>xl(t,s,a.version,e),{wants:o,haves:[],capabilities:n,progressOp:"fetch-missing:write-objects",promisor:!0})}catch(e){if(!(e=>e instanceof t&&"FILE_EXISTS"===e.data.code)(e))throw e}}finally{await s.close()}return{kind:"fetched",remote:r,requested:a.length,fetched:o.length}},Sm=async(t,e)=>{const a=await Dm(t,e.oids);if("no-promisor"===a.kind)throw J();return{remote:a.remote,requested:a.requested,fetched:a.fetched}},Am=t=>({fetch:async e=>{const a=await Dm(t,e);return"no-promisor"===a.kind?{attempted:!1,requested:e.length,fetched:0}:{attempted:!0,requested:a.requested,fetched:a.fetched}}}),Mm="badFilemode",Om="badTree",Nm="badTreeSha1",Pm="duplicateEntries",Cm="emptyName",Hm="fullPathname",Lm="hasDot",Rm="hasDotdot",Um="hasDotgit",_m="largePathname",Wm="nullSha1",jm="treeNotSorted",Bm="zeroPaddedFilemode",Fm="gitattributesBlob",zm="gitattributesSymlink",qm="gitignoreSymlink",Km="gitmodulesBlob",Vm="gitmodulesSymlink",Gm="mailmapSymlink",Ym="badDate",Xm="badDateOverflow",Jm="badObjectSha1",Qm="badParentSha1",Zm="badTimezone",tp="missingAuthor",ep="missingCommitter",ap="missingEmail",np="missingNameBeforeEmail",rp="missingSpaceBeforeDate",ip="missingSpaceBeforeEmail",op="missingTree",sp="multipleAuthors",cp="nulInCommit",dp="nulInHeader",up="zeroPaddedDate",fp="badTagName",lp="missingObject",hp="missingTag",wp="missingTagEntry",mp="missingTaggerEntry",pp="missingType",gp="missingTypeEntry",yp="gitmodulesLarge",vp="gitmodulesName",bp="gitmodulesParse",kp="gitmodulesUrl",$p="gitattributesLarge",xp="gitattributesLineLength",Ip=new Map([[Mm,"info"],[Om,"error"],[Nm,"error"],[Pm,"error"],[Cm,"warning"],[Hm,"warning"],[Lm,"warning"],[Rm,"warning"],[Um,"warning"],[_m,"warning"],[Wm,"warning"],[jm,"error"],[Bm,"warning"],[Fm,"error"],[zm,"info"],[qm,"info"],[Km,"error"],[Vm,"error"],[Gm,"info"],[Ym,"error"],[Xm,"error"],["badEmail","error"],["badName","error"],[Jm,"error"],[Qm,"error"],[Zm,"error"],["badType","error"],[tp,"error"],[ep,"error"],[ap,"error"],[np,"error"],[rp,"error"],[ip,"error"],[op,"error"],[sp,"error"],[cp,"warning"],[dp,"error"],["unknownType","error"],["unterminatedHeader","error"],[up,"error"],["badGpgsig","error"],[fp,"info"],[lp,"error"],[hp,"error"],[wp,"error"],[mp,"info"],[pp,"error"],[gp,"error"],[yp,"error"],["gitmodulesMissing","error"],[vp,"error"],[bp,"info"],["gitmodulesPath","error"],["gitmodulesUpdate","error"],[kp,"error"],[$p,"error"],[xp,"error"],["gitattributesMissing","error"]]),Ep=new Set([Cm,Hm,Lm,Rm,Um,_m,cp,Wm,Bm]);function Tp(t,e){const a=Ip.get(t)??"error";return e&&"warning"===a&&Ep.has(t)?"error":a}const Dp=new TextDecoder,Sp=new TextEncoder;function Ap(t,e,a,n){if(""===t||t.startsWith("#")||t.startsWith(";"))return n;if(t.startsWith("[")){const a=t.indexOf("]");if(-1===a)return!0;const r=t.slice(1,a),i='submodule "';return r.startsWith(i)&&r.endsWith('"')&&e.push(r.slice(i.length,-1)),n}const r=t.indexOf("=");if(-1!==r){const e=t.slice(0,r).trim(),n=t.slice(r+1).trim();"url"===e&&a.push(n)}return n}const Mp=t=>t.startsWith("-");function Op(t,e,a){return".gitmodules"===a?function(t,e){const a=[];if(t.length>104857600)return a.push({msgId:yp,severity:Tp(yp,e)}),a;const n=Dp.decode(t),{names:r,urls:i,parseError:o}=function(t){const e=[],a=[];let n=!1;for(const r of t.split("\n"))n=Ap(r.trim(),e,a,n);return{names:e,urls:a,parseError:n}}(n);o&&a.push({msgId:bp,severity:Tp(bp,e)});for(const t of i)Mp(t)&&a.push({msgId:kp,severity:Tp(kp,e)});for(const t of r)tn(t)&&a.push({msgId:vp,severity:Tp(vp,e)});return a}(t,e):".gitattributes"===a?function(t,e){const a=[];if(t.length>104857600)return a.push({msgId:$p,severity:Tp($p,e)}),a;const n=Dp.decode(t);for(const t of n.split("\n"))if(Sp.encode(t).length>2048)return a.push({msgId:xp,severity:Tp(xp,e)}),a;return a}(t,e):[]}const Np=new TextDecoder,Pp=/^[0-9a-f]{40}$/,Cp=/^[0-9a-f]{64}$/,Hp=/^[+-]\d{4}$/;function Lp(t){return Pp.test(t)||Cp.test(t)}function Rp(t,e){const a=[],n=t.indexOf("<");if(-1===n)return a.push({msgId:ap,severity:Tp(ap,e)}),a;const r=t.slice(0,n);r.endsWith(" ")||a.push({msgId:ip,severity:Tp(ip,e)}),""===r.trimEnd()&&a.push({msgId:np,severity:Tp(np,e)});const i=t.indexOf(">",n);if(-1===i)return a.push({msgId:ap,severity:Tp(ap,e)}),a;const o=t.slice(i+1);if(!o.startsWith(" "))return a.push({msgId:rp,severity:Tp(rp,e)}),a;const[s,c=""]=o.trim().split(/\s+/),d=function(t,e){return t.startsWith("0")&&t.length>1?{msgId:up,severity:Tp(up,e)}:/^\d+$/.test(t)?function(t){return t.length>19||!(t.length<19)&&t>"9223372036854775807"}(t)?{msgId:Xm,severity:Tp(Xm,e)}:void 0:{msgId:Ym,severity:Tp(Ym,e)}}(s,e);return void 0!==d?(a.push(d),a):(""===c||function(t){if(!Hp.test(t))return!1;const e=Number.parseInt(t.slice(1,3),10),a=Number.parseInt(t.slice(3,5),10);return e<24&&a<60}(c)||a.push({msgId:Zm,severity:Tp(Zm,e)}),a)}const Up=new TextDecoder,_p=/^[0-9a-f]{40}$/,Wp=/^[0-9a-f]{64}$/,jp=new Set(["blob","tree","commit","tag"]);function Bp(t,e,a){const n=[],r=t[e];if(void 0===r||!r.startsWith("tag "))return n.push({msgId:hp,severity:Tp(hp,a)}),n;const i=r.slice(4);if(""===i)return n.push({msgId:wp,severity:Tp(wp,a)}),n;(i.includes("\0")||i.includes("\n"))&&n.push({msgId:fp,severity:Tp(fp,a)});const o=t[e+1];if(void 0===o||!o.startsWith("tagger "))return n.push({msgId:mp,severity:Tp(mp,a)}),n;for(const t of function(t,e){const a=t.indexOf("<");if(-1===a)return[];if(!t.slice(0,a).endsWith(" "))return[{msgId:ip,severity:Tp(ip,e)}];const n=t.indexOf(">",a);if(-1===n)return[];const r=t.slice(n+1);if(!r.startsWith(" "))return[];const[i=""]=r.trim().split(/\s+/);return/^\d+$/.test(i)&&function(t){return t.length>19||!(t.length<19)&&t>"9223372036854775807"}(i)?[{msgId:Xm,severity:Tp(Xm,e)}]:[]}(o.slice(7),a))n.push(t);return n}const Fp=new TextDecoder,zp=new TextEncoder,qp=new Set(["100644","100755","120000","40000","160000"]);function Kp(t){const e="40000"===t.mode||"040000"===t.mode,a=zp.encode(t.name);if(!e)return a;const n=new Uint8Array(a.length+1);return n.set(a),n[a.length]=47,n}function Vp(t,e,a,n){const r=[],{mode:i,name:o,sha:s}=t;i.startsWith("0")&&r.push({msgId:Bm,severity:Tp(Bm,n)});const c=i.startsWith("0")?i.slice(1):i;qp.has(c)||r.push({msgId:Mm,severity:Tp(Mm,n)}),function(t){for(const e of t)if(0!==e)return!1;return!0}(s)&&r.push({msgId:Wm,severity:Tp(Wm,n)});for(const t of function(t,e){const a=[];return""===t?(a.push({msgId:Cm,severity:Tp(Cm,e)}),a):("."===t&&a.push({msgId:Lm,severity:Tp(Lm,e)}),".."===t&&a.push({msgId:Rm,severity:Tp(Rm,e)}),".git"===t&&a.push({msgId:Um,severity:Tp(Um,e)}),t.includes("/")&&a.push({msgId:Hm,severity:Tp(Hm,e)}),zp.encode(t).length>4096&&a.push({msgId:_m,severity:Tp(_m,e)}),a)}(o,n))r.push(t);a.has(o)&&r.push({msgId:Pm,severity:Tp(Pm,n)}),void 0!==e&&an(Kp(e),Kp(t))>0&&r.push({msgId:jm,severity:Tp(jm,n)});for(const t of function(t,e,a){const n=[],r="120000"===t,i="100644"===t||"100755"===t;return".gitmodules"===e&&(r?n.push({msgId:Vm,severity:Tp(Vm,a)}):i||n.push({msgId:Km,severity:Tp(Km,a)})),".gitattributes"===e&&(r?n.push({msgId:zm,severity:Tp(zm,a)}):i||n.push({msgId:Fm,severity:Tp(Fm,a)})),".gitignore"===e&&r&&n.push({msgId:qm,severity:Tp(qm,a)}),".mailmap"===e&&r&&n.push({msgId:Gm,severity:Tp(Gm,a)}),n}(i,o,n))r.push(t);return r}function Gp(t){const{rawBody:e,kind:a,strict:n,fileName:r}=t;switch(a){case"tree":return function(t,e){const{entries:a,badTree:n}=function(t){const e=[];let a=0;for(;a<t.length;){const n=en(t,32,a);if(-1===n||n===a)return{entries:e,badTree:!0};const r=en(t,0,n+1);if(-1===r)return{entries:e,badTree:!0};const i=r+1+20;if(i>t.length)return{entries:e,badTree:!0};const o=t.subarray(a,n),s=t.subarray(n+1,r),c=t.subarray(r+1,i),d=Fp.decode(o),u=Fp.decode(s);e.push({mode:d,name:u,sha:c,offset:a}),a=i}return{entries:e,badTree:!1}}(t);if(n)return[{msgId:Om,severity:Tp(Om,e)}];const r=[],i=new Set;let o;for(const t of a){for(const a of Vp(t,o,i,e))r.push(a);i.add(t.name),o=t}return r}(e,n);case"commit":return function(t,e){const a=Np.decode(t),{headerText:n,messageBody:r,lines:i}=function(t){const e=t.indexOf("\n\n"),a=-1===e?t:t.slice(0,e);return{headerText:a,messageBody:-1===e?"":t.slice(e+2),lines:a.split("\n")}}(a);if(n.includes("\0"))return[{msgId:dp,severity:Tp(dp,e)}];const{findings:o,nextIdx:s}=function(t,e){const a=[],n=t[0];if(void 0===n||!n.startsWith("tree "))return a.push({msgId:op,severity:Tp(op,e)}),{findings:a,nextIdx:-1};Lp(n.slice(5))||a.push({msgId:Nm,severity:Tp(Nm,e)});let r=1;for(;r<t.length;){const n=t[r];if(void 0===n||!n.startsWith("parent "))break;Lp(n.slice(7))||a.push({msgId:Qm,severity:Tp(Qm,e)}),r++}return{findings:a,nextIdx:r}}(i,e);if(-1===s)return o;const c=[...o];for(const t of function(t,e,a){const n=[];let r=e;const i=t[r];if(void 0===i||!i.startsWith("author "))return n.push({msgId:tp,severity:Tp(tp,a)}),n;for(const t of Rp(i.slice(7),a))n.push(t);for(r++;r<t.length&&t[r]?.startsWith("author ");)n.push({msgId:sp,severity:Tp(sp,a)}),r++;for(;r<t.length&&!t[r]?.startsWith("committer ");)r++;const o=t[r];if(void 0===o||!o.startsWith("committer "))return n.push({msgId:ep,severity:Tp(ep,a)}),n;for(const t of Rp(o.slice(10),a))n.push(t);return n}(i,s,e))c.push(t);return r.includes("\0")&&c.push({msgId:cp,severity:Tp(cp,e)}),c}(e,n);case"tag":return function(t,e){const a=Up.decode(t),n=a.indexOf("\n\n"),r=(-1!==n?a:a.slice(0,n)).split("\n"),{findings:i,nextIdx:o}=function(t,e){const a=[];if(!t[0]?.startsWith("object "))return{findings:[{msgId:lp,severity:Tp(lp,e)}],nextIdx:-1};var n;if(n=t[0].slice(7),_p.test(n)||Wp.test(n)||a.push({msgId:Jm,severity:Tp(Jm,e)}),!t[1]?.startsWith("type "))return a.push({msgId:pp,severity:Tp(pp,e)}),{findings:a,nextIdx:-1};const r=t[1].slice(5);return""!==r&&jp.has(r)?{findings:a,nextIdx:2}:(a.push({msgId:gp,severity:Tp(gp,e)}),{findings:a,nextIdx:-1})}(r,e);return-1===o?i:[...i,...Bp(r,o,e)]}(e,n);case"blob":return Op(e,n,r)}}const Yp=new Set([".gitmodules",".gitattributes"]);async function Xp(e,a,n,r){const i=[];let o=0;const s=await async function(e,a){const n=await nn(e,a);if(void 0!==n){let a;try{a=await e.compressor.inflate(n)}catch{return{ok:!1,msgId:"unterminatedHeader"}}try{const{type:t,contentOffset:e}=ra(a);return{ok:!0,kind:t,rawBody:a.subarray(e),hashBytes:a}}catch(e){return{ok:!1,msgId:(e instanceof t&&"INVALID_OBJECT_HEADER"===e.data.code?e.data.reason:"").startsWith("unknown object type")?"unknownType":"unterminatedHeader"}}}try{const t=await oe(e,a,{verifyHash:!1}),n=na(t,e.hashConfig),{contentOffset:r}=ra(n);return{ok:!0,kind:t.type,rawBody:n.subarray(r),hashBytes:n}}catch{return{ok:!1,msgId:"badType"}}}(e,a);if(!s.ok)return i.push({type:"bad-object",id:a,objectType:"unknown",msgId:s.msgId,severity:"error"}),{findings:i,exitBit:1};const{kind:c,rawBody:d,hashBytes:u}=s,f="blob"===c?r.get(a):void 0,l=Gp(void 0!==f?{rawBody:d,kind:c,strict:n,fileName:f}:{rawBody:d,kind:c,strict:n});for(const{msgId:t,severity:e}of l)i.push({type:"bad-object",id:a,objectType:c,msgId:t,severity:e}),"error"===e&&(o|=1);try{const t=await e.hash.hashHex(u);t!==a&&(i.push({type:"hash-mismatch",id:a,actual:t}),o|=1)}catch{}return{findings:i,exitBit:o}}function Jp(t,e){if("commit"===t.type){e.add(t.data.tree);for(const a of t.data.parents)e.add(a)}else if("tree"===t.type)for(const a of t.entries)a.mode!==qt.GITLINK&&e.add(a.id);else"tag"===t.type&&e.add(t.data.object)}function Qp(t,e){t.reached.has(e)||t.worklist.push(e)}function Zp(t,e,a){t.reached.add(e),"commit"===a.type&&function(t,e,a){const{tree:n,parents:r}=a.data;t.universe.has(n)?Qp(t,n):(t.missingIds.add(n),t.brokenEdges.push({fromId:e,fromType:"commit",toId:n,toType:"tree"}));for(const a of r)t.universe.has(a)?Qp(t,a):(t.missingIds.add(a),t.brokenEdges.push({fromId:e,fromType:"commit",toId:a,toType:"commit"}));0===r.length&&t.rootCommits.push(e)}(t,e,a),"tree"===a.type&&function(t,e,a){for(const n of a.entries){if(n.mode===qt.GITLINK)continue;const a=n.mode===qt.DIRECTORY?"tree":"blob";t.universe.has(n.id)?Qp(t,n.id):(t.missingIds.add(n.id),t.brokenEdges.push({fromId:e,fromType:"tree",toId:n.id,toType:a}))}}(t,e,a),"tag"===a.type&&function(t,e,a){const{object:n,objectType:r,tagName:i}=a.data;t.universe.has(n)?(Qp(t,n),t.tagRefs.push({tagId:e,tagName:i,targetId:n,targetType:r})):(t.missingIds.add(n),t.brokenEdges.push({fromId:e,fromType:"tag",toId:n,toType:r}))}(t,e,a)}function tg(t,e,a,n){for(const r of t){const t=n.get(r);null!=t&&a.push({type:e,id:r,objectType:t.type})}}function eg(t,e){const a=e.get(t);return null!=a?a.type:"unknown"}const ag=/^[0-9a-f]{40}$|^[0-9a-f]{64}$/;function ng(t,e,a,n){const r=e.replace(/[\r\n]+$/,"");if(r.startsWith("ref: "))return{findings:[],exitBit:0};if(!ag.test(r)){const e=[];let a=2;return n&&(e.push({type:"bad-ref",ref:t,msgId:"badRefContent",severity:"error"}),a|=8),e.push({type:"bad-ref",ref:t,msgId:"badRefOid",severity:"error",target:ze}),{findings:e,exitBit:a}}const i=r;return a.has(i)?{findings:[],exitBit:0}:{findings:[{type:"bad-ref",ref:t,msgId:"badRefOid",severity:"error",target:i}],exitBit:2}}async function rg(t,e={}){await bc(t);const a=await on(t,{includePacks:!1!==e.full}),n=new Set(a),r=await async function(t,e){const a=new Map;for(const n of e)try{a.set(n,await oe(t,n,{verifyHash:!1}))}catch{a.set(n,null)}return a}(t,n),i=!0===e.connectivityOnly?new Map:function(t,e){const a=new Map;for(const n of t){const t=e.get(n);if(null!=t&&"tree"===t.type)for(const e of t.entries)Yp.has(e.name)&&a.set(e.id,e.name)}return a}(n,r),o=!0===e.connectivityOnly?{findings:[],exitBit:0}:await async function(t,e,a,n){const r=[];let i=0;for(const o of e){const{findings:e,exitBit:s}=await Xp(t,o,a,n);r.push(...e),i|=s}return{findings:r,exitBit:i}}(t,n,!0===e.strict,i),s=await async function(t,e,a){const n=[];let r=0;const i=Me(t),o=await Qe(t);for(const t of o){const o=await i.readLooseRaw(t);if(void 0!==o){const{findings:i,exitBit:s}=ng(t,o,e,a);n.push(...i),r|=s;continue}const s=await i.getPackedRefs();for(const a of s.entries)if(a.name===t){e.has(a.id)||(n.push({type:"bad-ref",ref:t,msgId:"badRefOid",severity:"error",target:a.id}),r|=2);break}}return{findings:n,exitBit:r}}(t,n,!1!==e.checkReferences),c=await async function(t,e,a){const n=new Set;return await async function(t,e,a){const n=await Qe(t);for(const r of n)try{const n=await Ae(t,r,{peel:!1});a.has(n)&&e.add(n)}catch{}}(t,n,a),!1!==e.reflogRoots&&await async function(t,e){const a=await rn(t);await Promise.all(a.map(async a=>{try{const n=await Se(t,a);for(const t of n)t.oldId!==ze&&e.add(t.oldId),t.newId!==ze&&e.add(t.newId)}catch{}}))}(t,n),!1!==e.indexRoot&&await async function(t,e){try{const a=await de(t);for(const t of a.entries)0===t.flags.stage&&e.add(t.id)}catch{}}(t,n),n}(t,e,n),d=function(t,e){const a=new Set;for(const n of t){const t=e.get(n);null!=t&&Jp(t,a)}return a}(n,r),{reached:u,missingIds:f,brokenEdges:l,rootCommits:h,tagRefs:w}=function(t,e,a){const n={universe:t,reached:new Set,missingIds:new Set,brokenEdges:[],rootCommits:[],tagRefs:[],worklist:[...e]};for(;n.worklist.length>0;){const e=n.worklist.pop();if(void 0===e||n.reached.has(e))continue;if(!t.has(e)){n.missingIds.add(e);continue}const r=a.get(e);null==r?n.reached.add(e):Zp(n,e,r)}return{reached:n.reached,missingIds:n.missingIds,brokenEdges:n.brokenEdges,rootCommits:n.rootCommits,tagRefs:n.tagRefs}}(n,c,r),{unreachable:m,dangling:p}=function(t,e,a){const n=[],r=[];for(const i of t)e.has(i)||(n.push(i),a.has(i)||r.push(i));return{unreachable:n,dangling:r}}(n,u,d),g=[...o.findings,...s.findings],y=new Map;for(const t of l)y.has(t.toId)||y.set(t.toId,t.toType);for(const t of f){const e=y.get(t)??eg(t,r);g.push({type:"missing",id:t,objectType:e})}for(const t of l)g.push({type:"broken-link",...t});tg(m,"unreachable",g,r),tg(p,"dangling",g,r);for(const t of h)g.push({type:"root",id:t});for(const{tagId:t,tagName:e,targetId:a,targetType:n}of w)g.push({type:"tagged",id:a,objectType:n,tagName:e,tag:t});return{findings:g,exitCode:o.exitBit|(f.size>0||l.length>0?2:0)|s.exitBit}}function ig(t){return t>=65&&t<=90||t>=97&&t<=122||t>=48&&t<=57||95===t}function og(t,e){const a=e?.wholeWord??!1,n=e?.invert??!1,r=t.map(t=>{if(t instanceof RegExp){if(t.flags.includes("u"))throw u("pattern","unicode flag unsupported over byte content");const e=t.flags.replace("y","")+(t.flags.includes("g")?"":"g");return{type:"regex",clone:new RegExp(t.source,e)}}return{type:"fixed",needle:(new TextEncoder).encode(t.fixed)}});return{matchLine(t){const e=function(t){return 10===t[t.length-1]?t.subarray(0,t.length-1):t}(t),i=r.map(t=>{const n="regex"===t.type?function(t,e){const a=function(t){let e="";for(const a of t)e+=String.fromCharCode(a);return e}(t),n=[];e.lastIndex=0;let r=e.exec(a);for(;null!==r;)n.push({start:r.index,end:r.index+r[0].length}),0===r[0].length&&e.lastIndex++,r=e.exec(a);return n}(e,t.clone):function(t,e){if(0===e.length)return[];const a=[];let n=0;t:for(;n<=t.length-e.length;){for(let a=0;a<e.length;a++)if(t[n+a]!==e[a]){n++;continue t}a.push({start:n,end:n+e.length}),n+=e.length}return a}(e,t.needle);return a?function(t,e){return t.filter(t=>{const a=e[t.start-1],n=e[t.end],r=0===t.start||void 0===a||!ig(a),i=t.end>=e.length||void 0===n||!ig(n);return r&&i})}(n,e):n}),o=function(t){const e=new Set,a=[];for(const n of t)for(const t of n){const n=`${t.start}:${t.end}`;e.has(n)||(e.add(n),a.push(t))}return a.sort((t,e)=>t.start-e.start||t.end-e.end)}(i);return n?{returned:0===o.length,spans:[]}:{returned:o.length>0,spans:o}}}}const sg=t=>t===qt.REGULAR||t===qt.EXECUTABLE;async function cg(t,e){if(0===e.patterns.length)throw u("patterns","at least one pattern required");const a=og(e.patterns,{...!0===e.wholeWord?{wholeWord:!0}:{},...!0===e.invert?{invert:!0}:{}}),n=og(e.patterns,{...!0===e.wholeWord?{wholeWord:!0}:{}}),r=void 0!==e.paths&&e.paths.length>0?_c(e.paths):void 0,i=await async function(t,e){const{target:a}=e;if(void 0===a)return(async t=>{const e=await de(t),a=[];for(const n of e.entries){if(0!==n.flags.stage)continue;if(!sg(n.mode))continue;const e=he(t.layout.workDir,n.path),r=await t.fs.lstat(e).catch(()=>{});void 0===r||r.isDirectory||r.isSymbolicLink||a.push({path:n.path,load:()=>t.fs.read(e)})}return a})(t);if("index"===a)return(async t=>(await de(t)).entries.filter(t=>0===t.flags.stage&&sg(t.mode)).map(e=>({path:e.path,load:async()=>(await He(t,e.id)).content})))(t);const n=await yw(t,a.treeish),r=[];for await(const{path:e,id:a,mode:i}of Ce(t,n,{recursive:!0})){if(!sg(i))continue;const n=a;r.push({path:e,load:async()=>(await He(t,n)).content})}return r}(t,e),o=void 0!==r?i.filter(({path:t})=>Xr(r.matcher,t)):i,s=await sn(o,cn,async t=>function(t,e,a,n){if(Lt(n)){if(!e.matchLine(n.subarray(0,dn)).returned)return;return{path:a,hits:[],binaryMatch:!0}}const r=Ct(n),i=[];if(r.forEach((e,a)=>{const n=t.matchLine(e);n.returned&&i.push({lineNumber:a+1,line:e,spans:n.spans})}),0!==i.length)return{path:a,hits:i,binaryMatch:!1}}(a,n,t.path,await t.load()));return{paths:s.filter(t=>void 0!==t)}}const dg=async(e,a={})=>{const n=a.initialBranch??"main",r=a.bare??!1;if(await e.fs.exists(`${e.layout.gitDir}/HEAD`))throw new t({code:"ALREADY_INITIALIZED",path:e.layout.gitDir});const i=await pl(e,{initialBranch:n,bare:r});return{path:i.gitDir,initialBranch:i.initialBranch,bare:i.bare}},ug=(t,e)=>Object.freeze({list:()=>(e(),xu(t)),create:a=>(e(),Eu(t,a)),delete:a=>(e(),Tu(t,a)),rename:a=>(e(),Du(t,a))}),fg=(t,e)=>Object.freeze({create:a=>(e(),Gu(t,a)),verify:a=>(e(),tf(t,a)),listHeads:a=>(e(),Qu(t,a))}),lg=(t,e)=>Object.freeze({run:a=>(e(),fl(t,a)),continue:a=>(e(),hl(t,a)),skip:a=>(e(),wl(t,a)),abort:()=>(e(),ml(t))}),hg=(t,e)=>Object.freeze({get:a=>(e(),qh(t,a)),getAll:a=>(e(),Kh(t,a)),getRegexp:a=>(e(),Vh(t,a)),list:a=>(e(),Gh(t,a)),set:a=>(e(),Yh(t,a)),unset:a=>(e(),Xh(t,a)),unsetAll:a=>(e(),Jh(t,a)),renameSection:a=>(e(),Qh(t,a)),removeSection:a=>(e(),Zh(t,a))}),wg=async(t,e,a={})=>{const n=await mg(t,e,a);return"fast-forward"!==n.kind&&"merge"!==n.kind||await oa(t,"post-merge",{args:["0"]}),n},mg=async(t,e,a)=>{await $c(t),await xc(t,"merge"),await Dc(t);const n=await Ic(t);if("symbolic"!==n.kind)throw o("merge","cannot merge with detached HEAD");const r=await Ae(t,n.target),i=await Jd(t,e.rev);if(r===i)return{kind:"up-to-date",id:r};const[s]=await ta(t,[r,i]);if(s===i)return{kind:"up-to-date",id:r};if(s===r&&"never"!==e.fastForward)return vg(t,await _g(t,i),async()=>(await fe(t,n.target,i,{expected:r,reflogMessage:`${a.reflogAction??`merge ${e.rev}`}: Fast-forward`}),{kind:"fast-forward",id:i,branch:n.target}));if("only"===e.fastForward)throw Q(n.target,r,i);return yg(t,e,a,n.target,r,i,s)},pg="merge:write-files",gg=new Set(["rename-rename","gitlink"]),yg=async(t,e,a,n,r,i,o)=>{t.progress.start(pg);try{const s=await kg(t,r,i,o,e.rev);return"conflict"===s.kind?Ig(t,e,s,r,i):bg(t,e,a,n,r,i,s.tree)}finally{t.progress.end(pg)}},vg=async(e,a,n)=>{const r=await ce(e);try{const i=await(async(e,a)=>{const n=await de(e);try{return(await ue(e,{targetTree:a,currentIndex:n,force:!1})).newIndexEntries}catch(e){throw(e=>e instanceof t&&"CHECKOUT_OVERWRITE_DIRTY"===e.data.code?A({localChanges:e.data.localChanges,untracked:e.data.untracked}):e)(e)}})(e,a);return await r.commit(i),await n()}finally{await r.release()}},bg=async(t,e,a,n,r,i,o)=>{const s=await Rg(t,e),c=Ug(e,s),d=Zf(e.message??`Merge ${e.rev}`,{allowEmpty:!1}),u={tree:o,parents:[r,i],author:s,committer:c,message:d,extraHeaders:[]};return vg(t,o,async()=>{const o=await $a(t,u);return await fe(t,n,o,{expected:r,reflogMessage:`${a.reflogAction??`merge ${e.rev}`}: Merge made by the 'tsgit' strategy.`}),{kind:"merge",id:o,branch:n,parents:[r,i]}})},kg=async(t,e,a,n,r)=>{const i=await _g(t,e),o=await _g(t,a),s=void 0!==n?await _g(t,n):void 0,[c,d,u]=await Promise.all([ma(t,i),ma(t,o),void 0!==s?ma(t,s):Promise.resolve(void 0)]),f=((t,e)=>({ours:ri,theirs:t,base:void 0!==e?ii(e):""}))(r,n),l=pf(t,f),h=await Hi(u,c,d,l,f);return h.cleanMerge?{kind:"clean",tree:await $g(t,h.outcomes)}:{kind:"conflict",outcomes:h.outcomes,conflicts:h.conflicts,ours:c.entries}},$g=async(t,e)=>{const a=await(async(t,e)=>{const a=[];for(const n of e)if("resolved-deleted"!==n.status&&"conflict"!==n.status){if("resolved-merged"===n.status){const e=await ye(t,{type:"blob",content:n.bytes,id:""});a.push({path:n.path,id:e,mode:n.mode});continue}a.push({path:n.path,id:n.id,mode:n.mode})}return a})(t,e);return xg(t,a)},xg=async(t,e,a=0)=>{if(a>4096)throw Ge(a);const{files:n,subdirs:r}=(t=>{const e=[],a=new Map;for(const n of t){const t=n.path.indexOf("/");if(-1===t){e.push(n);continue}const r=n.path.slice(0,t),i={path:n.path.slice(t+1),id:n.id,mode:n.mode},o=a.get(r);void 0===o?a.set(r,[i]):o.push(i)}return{files:e,subdirs:a}})(e),i=await Promise.all(Array.from(r,async([e,n])=>({name:e,id:await xg(t,n,a+1),mode:qt.DIRECTORY}))),o=n.map(t=>({name:t.path,id:t.id,mode:t.mode}));return Pa(t,[...o,...i])},Ig=async(t,e,a,n,r)=>{Eg(a.conflicts);const i=await de(t),o=yf(a.outcomes,a.conflicts,a.ours),{localChanges:s,untracked:c}=await bf(t,o,i);if(s.length>0||c.length>0)throw A({localChanges:s,untracked:c});const d=await ie(t),u=await ce(t);try{await Dg(t,a.outcomes,a.conflicts,o,d),await wc(t,n),await(async(t,e)=>{await t.fs.writeUtf8(uc(t),`${e}\n`)})(t,r);const i=Zf(e.message??`Merge ${e.rev}`,{allowEmpty:!1});await hc(t,i);const s=Lg(a.outcomes,a.conflicts,d);await u.commit(s)}finally{await u.release()}return{kind:"conflict",conflicts:a.conflicts.map(t=>({path:t.path,type:t.type})),mergeHead:r,origHead:n}},Eg=t=>{for(const e of t)if(gg.has(e.type))throw o("merge",`conflict type '${e.type}' not supported in v1 (path=${e.path})`)},Tg=(t,e)=>void 0!==t&&!t(e),Dg=async(t,e,a,n,r)=>{const i=e.filter(t=>"conflict"!==t.status&&n.has(t.path));await Sg(i,32,e=>Ag(t,e,r)),await Sg(a,32,e=>Mg(t,e))},Sg=async(t,e,a)=>{await sn(t,e,a)},Ag=async(t,e,a)=>{if("unchanged"===e.status||"resolved-known"===e.status){if(Tg(a,e.path))return;const n=await ya(t,e.id);return void await va(t,e.path,n)}"resolved-merged"!==e.status?"resolved-deleted"===e.status&&await pa(t,e.path):await ga(t,e.path,e.bytes)},Mg=async(t,e)=>{if("distinct-types"===e.type)return void await xf(t,e);const a=e.mergedMode??e.ourMode??e.theirMode;if(void 0===a)return;const n=await Cg(t,e);void 0!==n&&await wa(t,e.path,n,a)},Og={maxBytes:Zr},Ng=(t,e)=>{if(void 0!==e.ourId)return He(t,e.ourId,Og).then(t=>t.content)},Pg=async(t,e)=>void 0!==e.conflictContent?e.conflictContent:Ng(t,e),Cg=async(t,e)=>{if("content"===e.type)return Pg(t,e);if("add-add"===e.type)return Pg(t,e);if("binary"===e.type)return Ng(t,e);if("type-change"===e.type)return Ng(t,e);if("modify-delete"===e.type){const a=e.ourId??e.theirId;if(void 0===a)return;return(await He(t,a,Og)).content}},Hg=t=>({ctimeSeconds:0,ctimeNanoseconds:0,mtimeSeconds:0,mtimeNanoseconds:0,dev:0,ino:0,mode:t,uid:0,gid:0,fileSize:0}),Lg=(t,e,a)=>{const n=[];for(const e of t)"unchanged"!==e.status&&"resolved-known"!==e.status||n.push(Tg(a,e.path)?un({path:e.path,id:e.id,mode:e.mode}):{...Hg(e.mode),id:e.id,flags:Pt,path:e.path});const r=br(e,Hg),i=[...n,...r];return i.sort((t,e)=>t.path<e.path?-1:t.path>e.path?1:t.flags.stage-e.flags.stage),i},Rg=async(t,e)=>{const a=await ne(t),n=void 0!==a.user?.name&&void 0!==a.user?.email?{name:a.user.name,email:a.user.email,timestamp:Math.floor(Date.now()/1e3),timezoneOffset:"+0000"}:void 0,r={};return void 0!==e.author&&(r.explicit=e.author),void 0!==n&&(r.configUser=n),Jf(r)},Ug=(t,e)=>{const a={author:e};return void 0!==t.committer&&(a.explicit=t.committer),Qf(a)},_g=async(t,e)=>{const a=await oe(t,e);if("commit"!==a.type)throw se("commit",a.type,e);return a.data.tree},Wg=(t,e)=>Object.freeze({run:a=>(e(),wg(t,a)),continue:a=>(e(),tw(t,a)),abort:()=>(e(),Oc(t))}),jg=async(t,e,a,n,r=0)=>{const i=fn(e,r),o=t.slots[i];return"subtree"===o.kind?(async(t,e,a,n,r,i,o)=>{if(!n.startsWith(a.prefix)){const i=mn(mn(gn(),a,o+1),{kind:"note",key:n,val:r},o+1);return hn(t,e,wn(i))}const s=hn(t,e,pn(await ln(a,i),a.prefix,o));return jg(s,n,r,i,o)})(t,i,o,e,a,n,r):"internal"===o.kind?hn(t,i,wn(await jg(o.node,e,a,n,r+1))):mn(t,{kind:"note",key:e,val:a},r)},Bg=async(t,e,a,n=0)=>{const r=fn(e,n),i=t.slots[r];if("empty"!==i.kind){if("note"===i.kind)return i.key===e?i.val:void 0;if("internal"===i.kind)return Bg(i.node,e,a,n+1);if(e.startsWith(i.prefix))return Bg(await ln(i,a),e,a,i.prefix.length)}},Fg=async(t,e,a,n=0)=>{const r=fn(e,n),i=t.slots[r];if("empty"===i.kind)return t;if("note"===i.kind)return i.key===e?hn(t,r,yn):t;if("internal"===i.kind)return hn(t,r,(t=>{if(t.preserved.length>0)return wn(t);const e=t.slots.filter(t=>"empty"!==t.kind);if(0===e.length)return yn;const a=e[0];return 1===e.length&&"internal"!==a.kind?a:wn(t)})(await Fg(i.node,e,a,n+1)));if(!e.startsWith(i.prefix))return t;const o=hn(t,r,pn(await ln(i,a),i.prefix,n));return Fg(o,e,a,n)},zg=/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/,qg=/^[0-9a-f]{40}$/,Kg=async(t,e)=>qg.test(e)?e:Ae(t,e),Vg=async(t,e)=>{await $c(t);const a=await Kg(t,e.object),n=await vn(t,e.ref),{trie:r,read:i,notesCommitOid:o}=await bn(t,n);if(void 0!==await Bg(r,a,i)&&!0!==e.force)throw Z(a);const s=await ye(t,{type:"blob",id:"",content:e.content}),c=await jg(r,a,s,i),d=await el(t),u=await kn(t,{trie:c,read:i,prevCommitOid:o,message:"Notes added by 'git notes add'\n",author:d});return await fe(t,n,u,{reflogMessage:"notes: Notes added by 'git notes add'"}),{notesCommit:u,note:s}},Gg=async(t,e)=>{await $c(t);const a=await Kg(t,e.object),n=await vn(t,e.ref),{trie:r,read:i}=await bn(t,n),o=await Bg(r,a,i);return void 0===o?null:{object:a,note:o,content:(await He(t,o)).content}},Yg=async(t,e)=>{await $c(t);const a=await vn(t,e?.ref),{notesTreeOid:n}=await bn(t,a);if(void 0===n)return[];const r=[];for await(const e of Ce(t,n)){if(e.mode!==qt.REGULAR)continue;const t=e.path.split("/").join("");zg.test(t)&&r.push({object:Kt.from(t),note:e.id})}return r.sort((t,e)=>t.object<e.object?-1:1)},Xg=async(t,e)=>{await $c(t);const a=await Kg(t,e.object),n=await vn(t,e.ref),{trie:r,read:i,notesCommitOid:o}=await bn(t,n);if(void 0===o)throw tt(a);if(void 0===await Bg(r,a,i))throw tt(a);const s=await Fg(r,a,i),c=await el(t),d=await kn(t,{trie:s,read:i,prevCommitOid:o,message:"Notes removed by 'git notes remove'\n",author:c});return await fe(t,n,d,{reflogMessage:"notes: Notes removed by 'git notes remove'"}),{notesCommit:d}},Jg=(t,e)=>Object.freeze({add:a=>(e(),Vg(t,a)),read:a=>(e(),Gg(t,a)),list:a=>(e(),Yg(t,a)),remove:a=>(e(),Xg(t,a))}),Qg=t=>`'${t.replaceAll("'","'\\''")}'`,Zg=(t,e)=>{const a=`${e}=`,n=t.find(t=>t.startsWith(a));if(void 0===n)throw $n(e,"missing author-script key");const r=n.slice(a.length);if(r.length<2||!r.startsWith("'")||!r.endsWith("'"))throw $n(n,"author-script value is not single-quoted");return(t=>t.slice(1,-1).replaceAll("'\\''","'"))(r)},ty=t=>t.replace(/\n+$/,""),ey=(t,e)=>{return 0===e?`# This is the 1st commit message:\n\n${ty(t.message)}\n`:!0===t.skip?`\n# The commit message #${e+1} will be skipped:\n\n${a=t.message,ty(a).split("\n").map(t=>""===t?"#":`# ${t}`).join("\n")}\n`:`\n# This is the commit message #${e+1}:\n\n${ty(t.message)}\n`;var a},ay=t=>{const e=t.length;let a=`# This is a combination of ${e} ${1===e?"commit":"commits"}.\n`;for(let n=0;n<e;n+=1)a+=ey(t[n],n);return a},ny=/^(pick|reword|edit|squash|fixup|drop) (\S+) # (.*)$/,ry=t=>t.map(t=>`${t.action} ${t.oid} # ${t.subject}\n`).join(""),iy=t=>{const e=[];for(const a of t.split("\n")){if(""===a||a.startsWith("#"))continue;const t=ny.exec(a);if(null===t)throw S(a);e.push({action:t[1],oid:t[2],subject:t[3]})}return e},oy=new TextEncoder,sy=new Uint8Array,cy=async(t,e)=>{const a=await oe(t,e);if("commit"!==a.type)throw se("commit",a.type,e);return a.data},dy=async(t,e)=>{const a=await cy(t,e),n=a.parents[0],r=void 0!==n?(await cy(t,n)).tree:void 0,i=await Re(t,r,a.tree,{recursive:!0}),o=await xn(t,i.changes),s=Gr(o,{contextLines:3,pathPrefix:{old:"a/",new:"b/"}}),c=o.filter(t=>Lt(t.oldContent??sy)||Lt(t.newContent??sy)).map(t=>{return`${"oldId"in(e=t.change)?e.oldId:""}${"newId"in e&&void 0!==e.newId?e.newId:""}`;var e}).join("");return t.hash.hashHex(oy.encode(s.split("\n").filter(t=>!t.startsWith("@@ ")&&!t.startsWith("index ")).map(t=>t.replace(/\s/g,"")).join("")+c))},uy=t=>`${t.layout.gitDir}/rebase-merge`,fy=(t,e)=>`${uy(t)}/${e}`,ly=t=>`${t.layout.gitDir}/REBASE_HEAD`,hy=t=>t.map(([t,e])=>`${t} ${e}\n`).join(""),wy=async(t,e)=>{const a=[...e.done,...e.remaining],n=(e,a)=>t.fs.writeUtf8(fy(t,e),a);var r;await n("head-name",`${e.headName}\n`),await n("onto",`${e.onto}\n`),await n("orig-head",`${e.origHead}\n`),await n("git-rebase-todo",ry(e.remaining)),void 0!==e.backupHeader&&await n("git-rebase-todo.backup",((t,e)=>{const a=t.length,n=`# Rebase ${e.shortUpstream}..${e.shortOrigHead} onto ${e.shortOnto} (${a} ${1===a?"command":"commands"})\n`;return`${ry(t)}\n${n}#\n# Commands:\n# p, pick <commit> = use commit\n# r, reword <commit> = use commit, but edit the commit message\n# e, edit <commit> = use commit, but stop for amending\n# s, squash <commit> = use commit, but meld into previous commit\n# f, fixup [-C | -c] <commit> = like "squash" but keep only the previous\n# commit's log message, unless -C is used, in which case\n# keep only this commit's message; -c is same as -C but\n# opens the editor\n# x, exec <command> = run command (the rest of the line) using shell\n# b, break = stop here (continue rebase later with 'git rebase --continue')\n# d, drop <commit> = remove commit\n# l, label <label> = label current HEAD with a name\n# t, reset <label> = reset HEAD to a label\n# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]\n# create a merge commit using the original merge commit's\n# message (or the oneline, if no original merge commit was\n# specified); use -c <commit> to reword the commit message\n# u, update-ref <ref> = track a placeholder for the <ref> to be updated\n# to this position in the new commits. The <ref> is\n# updated at the end of the rebase\n#\n# These lines can be re-ordered; they are executed from top to bottom.\n#\n# If you remove a line here THAT COMMIT WILL BE LOST.\n#\n# However, if you remove everything, the rebase will be aborted.\n#\n`})(a,e.backupHeader)),await n("done",ry(e.done)),await n("message",e.message),await n("author-script",(r=e.stoppedAuthor,`GIT_AUTHOR_NAME=${Qg(r.name)}\nGIT_AUTHOR_EMAIL=${Qg(r.email)}\nGIT_AUTHOR_DATE=${Qg(`@${r.timestamp} ${r.timezoneOffset}`)}\n`)),await n("end",`${a.length}\n`),await n("msgnum",`${e.done.length}\n`),await n("interactive",""),await n("rewritten-list",hy(e.rewritten)),await n("patch",e.patch),await n("drop_redundant_commits",""),await n("no-reschedule-failed-exec",""),await n("stopped-sha",`${e.stoppedSha}\n`),void 0!==e.amend&&await n("amend",`${e.amend}\n`),void 0!==e.currentFixups&&await n("current-fixups",e.currentFixups.map(t=>`${t.action} ${t.oid}\n`).join("")),void 0!==e.rewrittenPending&&await n("rewritten-pending",e.rewrittenPending.map(t=>`${t}\n`).join("")),void 0!==e.messageSquash&&await n("message-squash",e.messageSquash),await t.fs.writeUtf8(ly(t),`${e.stoppedSha}\n`)},my=t=>Mf(t,ly(t)),py=async(t,e)=>{const a=[];for(const n of e){const e=await pd(t,n.oid);if(void 0===e)throw S(`cannot resolve commit ${n.oid}`);a.push({action:n.action,oid:e,subject:n.subject})}return a},gy=async t=>{if(!await(t=>t.fs.exists(uy(t)))(t))return;const e=(await t.fs.readUtf8(fy(t,"head-name"))).trimEnd(),a=await Mf(t,fy(t,"onto")),n=await Mf(t,fy(t,"orig-head")),r=await py(t,iy(await t.fs.readUtf8(fy(t,"done")))),i=await py(t,iy(await t.fs.readUtf8(fy(t,"git-rebase-todo")))),o=(t=>{const e=t.split("\n"),a=Zg(e,"GIT_AUTHOR_NAME"),n=Zg(e,"GIT_AUTHOR_EMAIL"),r=Zg(e,"GIT_AUTHOR_DATE");if(!r.startsWith("@"))throw $n(r,"author-script date lacks the `@` prefix");const[i,o]=r.slice(1).split(" "),s=Number(i);if(!Number.isSafeInteger(s))throw $n(r,"invalid author-script timestamp");if(void 0===o||!/^[+-]\d{4}$/.test(o))throw $n(r,"invalid author-script timezone offset");return{name:a,email:n,timestamp:s,timezoneOffset:o}})(await t.fs.readUtf8(fy(t,"author-script"))),s=await t.fs.readUtf8(fy(t,"message")),c=await Mf(t,fy(t,"amend")),d=await yy(t),u=await vy(t);return{headName:e,onto:a,origHead:n,done:r,remaining:i,stoppedSha:await my(t),author:o,message:s,...void 0!==c?{amend:c}:{},...void 0!==d?{currentFixups:d}:{},...void 0!==u?{rewrittenPending:u}:{}}},yy=async t=>{const e=fy(t,"current-fixups");if(!await t.fs.exists(e))return;const a=[];for(const n of(await t.fs.readUtf8(e)).split("\n")){const[t,e]=n.split(" ");"squash"!==t&&"fixup"!==t||void 0===e||a.push({action:t,oid:e})}return a},vy=async t=>{const e=fy(t,"rewritten-pending");if(!await t.fs.exists(e))return;const a=[];for(const n of(await t.fs.readUtf8(e)).split("\n"))""!==n&&a.push(n);return a},by=async t=>{const e=fy(t,"rewritten-list");if(!await t.fs.exists(e))return[];const a=[];for(const n of(await t.fs.readUtf8(e)).split("\n")){const[t,e]=n.split(" ");void 0!==t&&void 0!==e&&a.push([t,e])}return a},ky=async t=>{await t.fs.exists(uy(t))&&await t.fs.rmRecursive(uy(t)),await t.fs.exists(ly(t))&&await t.fs.rm(ly(t))},$y="HEAD",xy=t=>t.slice(0,7),Iy=async(t,e,a)=>{const n=new Set;if(void 0!==e)for await(const a of Ke(t,{from:[e]}))n.add(a.id);const r=[];for await(const e of Ke(t,{from:[a],until:[...n]}))r.push(e.id);return r.reverse()},Ey=async(t,e,a,n)=>{const r=a.parents[0],i=void 0!==r?await Zd(t,r):void 0,o=await Zd(t,n),s=await ce(t);try{const n=await de(t),r=await Sf(t,{baseTree:i,oursTree:o,theirsTree:a.tree,currentIndex:n,labels:ci(e,ur(a.message))});if("would-overwrite"===r.kind)throw A({localChanges:r.localChanges,untracked:r.untracked});return"conflict"===r.kind?(await s.commit(r.indexEntries),{kind:"conflict",conflicts:r.conflicts}):(await s.commit(r.result.newIndexEntries),{kind:"clean",mergedTree:r.mergedTree,oursTree:o})}finally{await s.release()}},Ty=async(t,e,a,n)=>{const r=await Ey(t,e,a,n);if("conflict"===r.kind)return{kind:"conflict",conflicts:r.conflicts};if(r.mergedTree===r.oursTree)return{kind:"empty"};const i=await el(t),o=await $a(t,{tree:r.mergedTree,parents:[n],author:a.author,committer:i,message:a.message,extraHeaders:[]});return await fe(t,$y,o,{expected:n,reflogMessage:Gs(ur(a.message))}),{kind:"committed",id:o}},Dy=async(t,e)=>{const a=e.parents[0],n=void 0!==a?await Zd(t,a):void 0,r=await Re(t,n,e.tree,{recursive:!0});return Gr(await xn(t,r.changes),{contextLines:3,pathPrefix:{old:"a/",new:"b/"}})},Sy=async(t,e,a,n,r,i)=>{const o={headName:e.branch??"detached HEAD",onto:e.onto,origHead:e.origHead,done:[...e.doneBefore,...e.todo.slice(0,a+1)],remaining:e.todo.slice(a+1),stoppedSha:e.todo[a].oid,stoppedAuthor:n.author,message:Vf(n.message,yr(r)),rewritten:i,patch:await Dy(t,n),...void 0!==e.backupHeader?{backupHeader:e.backupHeader}:{}};await wy(t,o)},Ay=async(t,e,a,n,r)=>{void 0!==e&&(await fe(t,e,n,{expected:a,reflogMessage:Js(e,r)}),await $u(t,$y,e),await sa(t,$y,n,n,(t=>`rebase (finish): returning to ${t}`)(e)))},My=(t,e)=>Ma(t,"pre-rebase",{args:[e]}),Oy=async(t,e)=>{0!==e.length&&await oa(t,"post-rewrite",{args:["rebase"],stdin:hy(e)})},Ny=async(t,e,a,n)=>{let r=a;const i=[...n.applied],o=[...n.rewritten];for(let a=0;a<e.todo.length;a+=1){const n=e.todo[a].oid,s=await Qd(t,n),c=await Ty(t,n,s,r);if("committed"!==c.kind){if("empty"!==c.kind)return await Sy(t,e,a,s,c.conflicts,o),{kind:"conflict",commit:n,conflicts:c.conflicts.map(t=>({path:t.path,type:t.type})),remaining:e.todo.length-(a+1)}}else i.push({source:n,created:c.id}),o.push([n,c.id]),r=c.id}return await Ay(t,e.branch,e.origHead,r,e.onto),await Oy(t,o),await ky(t),{kind:"rebased",commits:i}},Py=async(e,a)=>{await $c(e),await xc(e,"rebase"),await Dc(e);const n=await Ic(e),r="symbolic"===n.kind?await(async(e,a)=>{try{return await Ae(e,a)}catch(e){if(e instanceof t&&"REF_NOT_FOUND"===e.data.code)throw P();throw e}})(e,n.target):n.id,i=Ec(n),o=await Jd(e,a.upstream),s=void 0!==a.onto?await Jd(e,a.onto):o,c=a.onto??a.upstream;await Xf(e,await Zd(e,r));const[d]=await ta(e,[o,r]);if(void 0!==a.interactive)return await My(e,a.upstream),Vy(e,{instructions:a.interactive,branch:i,headCommit:r,upstream:o,onto:s,ontoName:c,base:d});if(s===d)return{kind:"up-to-date"};await My(e,a.upstream);const u=await Iy(e,d,r),f=await(async(t,e,a,n)=>{const r=await Iy(t,a,n),i=new Set;for(const e of r)i.add(await dy(t,e));const o=[];for(const a of e)i.has(await dy(t,a))||o.push(a);return o})(e,u,d,o),l=await(async(t,e)=>{const a=[];for(const n of e)a.push({action:"pick",oid:n,subject:ur((await Qd(t,n)).message)});return a})(e,f);await wc(e,r),await(async(t,e,a,n)=>{await Me(t).writeLoose($y,a),await sa(t,$y,e,a,Vs(n)),await Mc(t,a)})(e,r,s,c);const h={branch:i,onto:s,origHead:r,doneBefore:[],todo:l,backupHeader:{shortUpstream:xy(o),shortOrigHead:xy(r),shortOnto:xy(s)}};return Ny(e,h,s,{applied:[],rewritten:[]})},Cy=t=>"detached HEAD"===t?void 0:t,Hy=t=>{const e=new Set;for(const a of t)0!==a.flags.stage&&e.add(a.path);if(e.size>0)throw C(e.size,[...e])},Ly=async t=>{await $c(t),await xc(t,"rebase --continue");const e=await gy(t);if(void 0===e)throw i("rebase");if(Gy(e))return Yy(t,e);const a=await de(t);Hy(a.entries);const n=e.done[e.done.length-1],r=await Ae(t,$y),o=await ca(t,a.entries),s=await el(t),c=Zf(tl(e.message),{allowEmpty:!1}),d=await $a(t,{tree:o,parents:[r],author:e.author,committer:s,message:c,extraHeaders:[]});await fe(t,$y,d,{expected:r,reflogMessage:Xs(ur(c))});const u=[...await by(t),[n.oid,d]],f={branch:Cy(e.headName),onto:e.onto,origHead:e.origHead,doneBefore:e.done,todo:e.remaining};return Ny(t,f,d,{applied:[{source:n.oid,created:d}],rewritten:u})},Ry=async t=>{await $c(t),await xc(t,"rebase --skip");const e=await gy(t);if(void 0===e)throw i("rebase");if(Gy(e))return Xy(t,e);const a=await Ae(t,$y);await Mc(t,a);const n={branch:Cy(e.headName),onto:e.onto,origHead:e.origHead,doneBefore:e.done,todo:e.remaining};return Ny(t,n,a,{applied:[],rewritten:await by(t)})},Uy=async t=>{await $c(t),await xc(t,"rebase --abort");const e=await gy(t);if(void 0===e)throw i("rebase");const a=Cy(e.headName),n=await Ae(t,$y);return await Mc(t,e.origHead),void 0!==a?(await $u(t,$y,a),await sa(t,$y,n,e.origHead,Qs(a))):(await Me(t).writeLoose($y,e.origHead),await sa(t,$y,n,e.origHead,Qs(e.origHead))),await ky(t),{head:e.origHead,headName:e.headName}},_y=async(t,e)=>{const a=await el(t),n=await $a(t,{tree:e.tree,parents:[e.parent],author:e.author,committer:a,message:e.message,extraHeaders:[]});return await fe(t,$y,n,{expected:e.expected,reflogMessage:e.reflog}),n},Wy=async(t,e,a,n,r)=>{if(a.parents[0]===n)return await(async(t,e)=>{const a=await Ae(t,$y);await Me(t).writeLoose($y,e),await sa(t,$y,a,e,"rebase: fast-forward"),await Mc(t,e)})(t,e.oid),{kind:"committed",created:e.oid};const i=await Ey(t,e.oid,a,n);return"conflict"===i.kind?{kind:"conflict",conflicts:i.conflicts}:{kind:"committed",created:await _y(t,{tree:i.mergedTree,parent:n,expected:n,author:a.author,message:a.message,reflog:r})}},jy=(t,e,a,n)=>"reword"===e.action?(async(t,e,a,n)=>{const r=Zf(e.message??a.message,{allowEmpty:!1}),i=await Wy(t,e,a,n,Ys(ur(a.message)));if("conflict"===i.kind)return{kind:"conflict",conflicts:i.conflicts};const o=await Qd(t,i.created);return{kind:"advanced",created:await _y(t,{tree:o.tree,parent:o.parents[0],expected:i.created,author:o.author,message:r,reflog:Ys(ur(r))})}})(t,e,a,n):"edit"===e.action?(async(t,e,a,n)=>{const r=await Wy(t,e,a,n,(i=ur(a.message),`rebase (edit): ${i}`));var i;return"conflict"===r.kind?{kind:"conflict",conflicts:r.conflicts}:{kind:"edit-stop",created:r.created}})(t,e,a,n):(async(t,e,a,n)=>{const r=await Wy(t,e,a,n,Gs(ur(a.message)));return"conflict"===r.kind?{kind:"conflict",conflicts:r.conflicts}:{kind:"advanced",created:r.created}})(t,e,a,n),By=async(t,e,a,n)=>{await wy(t,{headName:e.branch??"detached HEAD",onto:e.onto,origHead:e.origHead,done:[...e.doneBefore,...e.todo.slice(0,a+1)],remaining:e.todo.slice(a+1),stoppedSha:n.stoppedSha,stoppedAuthor:n.author,message:n.message,rewritten:n.rewritten,patch:n.patch,...void 0!==e.backupHeader?{backupHeader:e.backupHeader}:{},...void 0!==n.amend?{amend:n.amend}:{},...void 0!==n.currentFixups?{currentFixups:n.currentFixups}:{},...void 0!==n.rewrittenPending?{rewrittenPending:n.rewrittenPending}:{},...void 0!==n.messageSquash?{messageSquash:n.messageSquash}:{}})},Fy=(t,e)=>{const a=t[e+1];return void 0!==a&&("squash"===a.action||"fixup"===a.action)},zy=(t,e,a)=>({kind:"conflict",commit:t,conflicts:e.map(t=>({path:t.path,type:t.type})),remaining:a}),qy=async(t,e,a,n,r,i)=>{const o=await Qd(t,n),s=await Ey(t,e.oid,a,n);if("conflict"===s.kind)return{kind:"conflict",conflicts:s.conflicts};r.members.push({message:a.message,skip:"fixup"===e.action}),r.fixups.push({action:e.action,oid:e.oid}),r.pending.push(e.oid),"squash"===e.action&&void 0!==e.message&&(r.inline=e.message);const c=ay([{message:r.baseMessage},...r.members]),d=i?Zf(r.inline??tl(c),{allowEmpty:!1}):c;var u,f;return{kind:"committed",created:await _y(t,{tree:s.mergedTree,parent:o.parents[0],expected:n,author:o.author,message:d,reflog:(u=e.action,f=ur(d),`rebase (${u}): ${f}`)}),message:d}},Ky=async(t,e,a,n)=>{let r=a;const i=[...n.applied],o=[...n.rewritten],s={baseMessage:(await Qd(t,a)).message,members:[],fixups:[],pending:[a],inline:void 0};for(let a=0;a<e.todo.length;a+=1){const n=e.todo[a];if("drop"===n.action)continue;const c=await Qd(t,n.oid),d=await Dy(t,c);if("squash"===n.action||"fixup"===n.action){const u=await qy(t,n,c,r,s,!Fy(e.todo,a));if("conflict"===u.kind){const r=ay([{message:s.baseMessage},...s.members,{message:c.message,skip:"fixup"===n.action}]);return await By(t,e,a,{stoppedSha:n.oid,author:c.author,message:Vf(r,yr(u.conflicts)),patch:d,rewritten:o,currentFixups:[...s.fixups,{action:n.action,oid:n.oid}],rewrittenPending:[...s.pending],messageSquash:r}),zy(n.oid,u.conflicts,e.todo.length-(a+1))}i.push({source:n.oid,created:u.created}),o.push([n.oid,u.created]),r=u.created;continue}const u=await jy(t,n,c,r);if("conflict"===u.kind)return await By(t,e,a,{stoppedSha:n.oid,author:c.author,message:Vf(c.message,yr(u.conflicts)),patch:d,rewritten:o}),zy(n.oid,u.conflicts,e.todo.length-(a+1));if("edit-stop"===u.kind)return await By(t,e,a,{stoppedSha:u.created,author:c.author,message:c.message,patch:d,rewritten:o,amend:u.created}),{kind:"stopped",commit:n.oid,remaining:e.todo.length-(a+1)};i.push({source:n.oid,created:u.created}),o.push([n.oid,u.created]),r=u.created,s.baseMessage=(await Qd(t,u.created)).message,s.members=[],s.fixups=[],s.pending=[u.created],s.inline=void 0}return await Ay(t,e.branch,e.origHead,r,e.onto),await Oy(t,o),await ky(t),{kind:"rebased",commits:i}},Vy=async(t,e)=>{const a=await(async(t,e,a,n)=>{if(e.every(t=>"drop"===t.action))throw u("interactive","nothing to do (every instruction drops a commit)");const r=e.find(t=>"drop"!==t.action);if("squash"===r?.action||"fixup"===r?.action)throw u("interactive",`cannot '${r.action}' without a previous commit`);const i=new Set(await Iy(t,a,n)),o=[];for(const a of e){if("reword"===a.action&&void 0===a.message)throw u("interactive","reword requires a message (no editor in a library)");if(("reword"===a.action||"squash"===a.action)&&void 0!==a.message&&""===Zf(a.message,{allowEmpty:!0}))throw u("interactive",`${a.action} message must not be empty`);const e=await Jd(t,a.oid);if(!i.has(e))throw u("interactive",`commit ${e} is not in the list of commits to be rebased`);const n=ur((await Qd(t,e)).message);o.push({action:a.action,oid:e,subject:n,...void 0!==a.message?{message:a.message}:{}})}return o})(t,e.instructions,e.base,e.headCommit),n=await(async(t,e,a)=>{let n=a,r=0;for(;r<e.length&&"pick"===e[r].action&&(await Qd(t,e[r].oid)).parents[0]===n;)n=e[r].oid,r+=1;return r})(t,a,e.onto),r=n>0?a[n-1].oid:e.onto;await wc(t,e.headCommit),await(async(t,e,a,n)=>{await Me(t).writeLoose($y,n),await sa(t,$y,e,n,Vs(a)),await Mc(t,n)})(t,e.headCommit,e.ontoName,r);const i=a.slice(0,n),o={branch:e.branch,onto:e.onto,origHead:e.headCommit,doneBefore:i,todo:a.slice(n),backupHeader:{shortUpstream:xy(e.upstream),shortOrigHead:xy(e.headCommit),shortOnto:xy(e.onto)}},s={applied:i.map(t=>({source:t.oid,created:t.oid})),rewritten:[]};return Ky(t,o,r,s)},Gy=t=>[...t.done,...t.remaining].some(t=>"pick"!==t.action),Yy=async(t,e)=>{const a={branch:Cy(e.headName),onto:e.onto,origHead:e.origHead,doneBefore:e.done,todo:e.remaining},n=[...await by(t)],r=await de(t);Hy(r.entries);const i=await ca(t,r.entries),o=await Ae(t,$y),s=e.done[e.done.length-1].oid;let c;if(void 0!==e.currentFixups){const a=await Qd(t,o),r=Zf(tl(e.message),{allowEmpty:!1});c=await _y(t,{tree:i,parent:a.parents[0],expected:o,author:a.author,message:r,reflog:Xs(ur(r))}),n.push([s,c])}else if(void 0!==e.amend){const a=await Qd(t,e.amend);i===a.tree?c=o:(c=await _y(t,{tree:i,parent:a.parents[0],expected:o,author:e.author,message:a.message,reflog:Xs(ur(a.message))}),n.push([s,c]))}else{const a=Zf(tl(e.message),{allowEmpty:!1});c=await _y(t,{tree:i,parent:o,expected:o,author:e.author,message:a,reflog:Xs(ur(a))}),n.push([s,c])}return Ky(t,a,c,{applied:[],rewritten:n})},Xy=async(t,e)=>{const a=await Ae(t,$y),n=void 0!==e.amend?(await Qd(t,e.amend)).parents[0]:a;await Me(t).writeLoose($y,n),await Mc(t,n);const r={branch:Cy(e.headName),onto:e.onto,origHead:e.origHead,doneBefore:e.done,todo:e.remaining};return Ky(t,r,n,{applied:[],rewritten:await by(t)})},Jy=(t,e)=>Object.freeze({run:a=>(e(),Py(t,a)),continue:()=>(e(),Ly(t)),skip:()=>(e(),Ry(t)),abort:()=>(e(),Uy(t))}),Qy=t=>"HEAD"===t||t.includes("/")?t:`${bu}${t}`,Zy=t=>{if(""===t)throw Xi(t,"refspec must not be empty");let e=t,a="normal";if(e.startsWith("+")&&(a="force",e=e.slice(1)),""===e)throw Xi(t,"refspec must not be empty after force prefix");const n=tv(e,":");if(n>1)throw Xi(t,"refspec must contain at most one colon");if(0===n){const t=Qy(e);return{force:a,src:t,dst:t,isDelete:!1}}const r=e.indexOf(":"),i=e.slice(0,r),o=e.slice(r+1);if(""===o)throw Xi(t,"destination must not be empty");const s=Qy(o);if("HEAD"===s)throw Xi(t,"destination must not be HEAD");return""===i?{force:a,src:"",dst:s,isDelete:!0}:{force:a,src:Qy(i),dst:s,isDelete:!1}},tv=(t,e)=>{let a=0;for(let n=0;n<t.length;n+=1)t[n]===e&&(a+=1);return a},ev=/[\n\r\t\0"\\\]/]/,av=t=>{if(""===t)throw et(t,"name must not be empty");if(ev.test(t))throw et(t,"name must not contain a newline, tab, NUL, slash, bracket, quote, or backslash");return t},nv=(t,e)=>{if(void 0===t.branch)return[];const a=[];for(const[n,r]of t.branch)r.remote===e&&a.push({branch:n,ref:`refs/heads/${n}`,merge:r.merge});return a},rv=/[\n\r\0]/,iv=t=>{if(rv.test(t))throw u("remote.url","url must not contain a newline or NUL")},ov=(t,e)=>({name:t,url:e?.url??"",pushUrl:e?.pushUrl,fetchRefspecs:e?.fetch??[]}),sv=async t=>{await bc(t);const e=await ne(t);if(void 0===e.remote)return{remotes:[]};const a=[];for(const[t,n]of e.remote)a.push(ov(t,n));return a.sort((t,e)=>t.name<e.name?-1:1),{remotes:a}},cv=async(t,e)=>{await bc(t),av(e.name),iv(e.url);const a=await ne(t);if(!0===a.remote?.has(e.name))throw at(e.name);const n=e.fetch??`+refs/heads/*:refs/remotes/${e.name}/*`;Zy(n);const r=[{kind:"set",section:"remote",subsection:e.name,key:"url",value:e.url},{kind:"set",section:"remote",subsection:e.name,key:"fetch",value:n}];return await In(t,r),{remote:{name:e.name,url:e.url,pushUrl:void 0,fetchRefspecs:[n]}}},dv=async(t,e)=>{const a=`refs/remotes/${e}/`;return(await Qe(t)).filter(t=>t.startsWith(a))},uv=async(t,e)=>{await bc(t),av(e.name);const a=await ne(t);if(!0!==a.remote?.has(e.name))throw X(e.name);const n=await dv(t,e.name),r=nv(a,e.name);for(const e of n)await fe(t,e,ze,{delete:!0});const i=[{kind:"removeSection",section:"remote",subsection:e.name}];for(const t of r)i.push({kind:"removeEntry",section:"branch",subsection:t.branch,key:"remote"},{kind:"removeEntry",section:"branch",subsection:t.branch,key:"merge"});return await In(t,i),{name:e.name,removedTrackingRefs:n,clearedBranches:r.map(t=>t.ref)}},fv=async(t,e,a,n)=>{const r=Me(t),i=await r.resolveDirect(e);if("direct"===i.kind){if(!await r.isLoose(e))throw o("rename-packed-tracking-ref",`cannot rename packed-only ref ${e} — run \`git pack-refs --unpack\` and retry`);await fe(t,a,i.id,{expected:"absent",reflogMessage:n}),await fe(t,e,ze,{delete:!0})}},lv=async(t,e)=>{if(await bc(t),av(e.from),av(e.to),e.from===e.to)throw u("remote.rename","from and to must differ");const a=await ne(t),n=a.remote?.get(e.from);if(void 0===n)throw X(e.from);if(!0===a.remote?.has(e.to))throw at(e.to);const r=await dv(t,e.from),i=nv(a,e.from),o=`remote: renamed ${e.from} to ${e.to}`,s=[];for(const a of r){const n=a.slice(`refs/remotes/${e.from}/`.length),r=`refs/remotes/${e.to}/${n}`;await fv(t,a,r,o),s.push(r)}const c=((t,e,a)=>{const n=`+refs/heads/*:refs/remotes/${e}/*`,r=`+refs/heads/*:refs/remotes/${a}/*`;return t.map(t=>t===n?r:t)})(n.fetch??[],e.from,e.to),d=[{kind:"renameSection",section:"remote",from:e.from,to:e.to}];if(c.length>0){d.push({kind:"removeEntry",section:"remote",subsection:e.to,key:"fetch"});for(const t of c)d.push({kind:"appendEntry",section:"remote",subsection:e.to,key:"fetch",value:t})}for(const t of i)d.push({kind:"set",section:"branch",subsection:t.branch,key:"remote",value:e.to});return await In(t,d),{from:e.from,to:e.to,movedTrackingRefs:s,rewrittenBranches:i.map(t=>t.ref)}},hv=async(t,e)=>{await bc(t),av(e.name),iv(e.url);const a=await ne(t);if(!0!==a.remote?.has(e.name))throw X(e.name);const n=!0===e.push?"pushurl":"url";await In(t,[{kind:"set",section:"remote",subsection:e.name,key:n,value:e.url}]);const r=(await ne(t)).remote?.get(e.name);return{remote:ov(e.name,r)}},wv=async(t,e)=>{await bc(t),av(e.name);const a=await ne(t),n=a.remote?.get(e.name);if(void 0===n)throw X(e.name);const r=await dv(t,e.name),i=Me(t),o=new Map;for(const t of r){const e=await i.resolveDirect(t);"direct"===e.kind&&o.set(t,e.id)}const s=nv(a,e.name);return{remote:{...ov(e.name,n),trackingRefs:o,trackedBy:s.map(t=>({branch:t.ref,merge:t.merge}))}}},mv=(t,e)=>Object.freeze({list:()=>(e(),sv(t)),add:a=>(e(),cv(t,a)),remove:a=>(e(),uv(t,a)),rename:a=>(e(),lv(t,a)),setUrl:a=>(e(),hv(t,a)),show:a=>(e(),wv(t,a))}),pv=t=>t.parents.length>=2,gv=t=>t.map(t=>({path:t.path,type:t.type})),yv=t=>Pa(t,[]),vv=async(t,e,a,n,r)=>{const i=a.parents[0],o=void 0!==i?await Zd(t,i):await yv(t),s=await Zd(t,r),c=await ce(t);try{const i=await de(t),d=await Sf(t,{baseTree:a.tree,oursTree:s,theirsTree:o,currentIndex:i,labels:di(e,ur(a.message))});if("would-overwrite"===d.kind)throw A({localChanges:d.localChanges,untracked:d.untracked});if("conflict"===d.kind)return await c.commit(d.indexEntries),{kind:"conflict",conflicts:d.conflicts};if(d.mergedTree===s)return{kind:"empty"};await c.commit(d.result.newIndexEntries);const{id:u,subject:f}=await(async(t,e,a,n,r)=>{const i=await el(t),o=Zf(xh(a,e),{allowEmpty:!1});return{id:await $a(t,{tree:r,parents:[n],author:i,committer:i,message:o,extraHeaders:[]}),subject:ur(o)}})(t,e,a,r,d.mergedTree);return await fe(t,n,u,{expected:r,reflogMessage:Ks(f)}),{kind:"committed",id:u}}finally{await c.release()}},bv=async(t,e,a,n)=>{await Hf(t,e.sequenceHead),await Uf(t,await(async(t,e)=>{const a=[];for(const n of e){const e=await Qd(t,n);a.push({command:"revert",oid:n,subject:ur(e.message)})}return a})(t,a)),await Rf(t,n),await Wf(t,{recordOrigin:!1,allowEmpty:!1,noCommit:!1})},kv=async(t,e,a)=>{"conflict"===e.kind&&await(async(t,e,a,n)=>{await(async(t,e)=>{await t.fs.writeUtf8(bh(t),`${e}\n`)})(t,e),await hc(t,Vf(xh(a,e),yr(n)))})(t,a.source,a.cData,e.conflicts),a.seq.multiPick&&await bv(t,a.seq,a.remaining,a.currentHead);const n=a.remaining.length-1;return"conflict"===e.kind?{kind:"conflict",commit:a.source,conflicts:gv(e.conflicts),remaining:n}:{kind:"empty",commit:a.source,remaining:n}},$v=async(t,e,a,n,r)=>{let i=n;const o=[];for(let n=0;n<e.length;n+=1){const s=e[n],c=await Qd(t,s);if(pv(c))throw r.multiPick&&await bv(t,r,e.slice(n),i),nt(s);const d=await vv(t,s,c,a,i);if("committed"!==d.kind){if("empty"!==d.kind||"drop"!==r.onEmpty||0!==n)return kv(t,d,{seq:r,source:s,cData:c,remaining:e.slice(n),currentHead:i})}else o.push({source:s,created:d.id}),i=d.id}return await Bf(t),{kind:"reverted",commits:o}},xv=/^(.+)\.\.(.+)$/,Iv=async(t,e,a)=>{const n=new Set;for await(const a of Ke(t,{from:[e]}))n.add(a.id);const r=[];for await(const e of Ke(t,{from:[a],until:[...n]}))r.push(e.id);return r},Ev=async(e,a)=>{await $c(e),await xc(e,ac),await Dc(e);const n=await Ic(e);if("symbolic"!==n.kind)throw o(ac,"cannot revert with detached HEAD");const r=await(async(e,a)=>{try{return await Ae(e,a)}catch(e){if(e instanceof t&&"REF_NOT_FOUND"===e.data.code)throw P();throw e}})(e,n.target),i=await(async(t,e)=>{const a=[];for(const n of e){if(n.includes("...")||n.includes("^"))throw u("commits",`unsupported revision form '${n}' (use a commit-ish or A..B)`);const e=xv.exec(n);if(null===e){a.push(await Jd(t,n));continue}const r=await Nd(t,e[1]),i=await Nd(t,e[2]);a.push(...await Iv(t,r,i))}return a})(e,a.commits);return await Xf(e,await Zd(e,r)),!0===a.noCommit?(async(t,e)=>{const a=await ce(t);try{let n=await de(t);for(let r=0;r<e.length;r+=1){const i=e[r],o=await Qd(t,i);if(pv(o))throw nt(i);const s=o.parents[0],c=void 0!==s?await Zd(t,s):await yv(t),d=await ca(t,n.entries),u=await Sf(t,{baseTree:o.tree,oursTree:d,theirsTree:c,currentIndex:n,labels:di(i,ur(o.message))});if("would-overwrite"===u.kind)throw A({localChanges:u.localChanges,untracked:u.untracked});if("conflict"===u.kind)return await a.commit(u.indexEntries),{kind:"conflict",commit:i,conflicts:gv(u.conflicts),remaining:e.length-(r+1)};n={...n,entries:u.result.newIndexEntries}}return await a.commit(n.entries),{kind:"no-commit",sources:e}}finally{await a.release()}})(e,i):$v(e,i,n.target,r,{multiPick:i.length>1,sequenceHead:r,onEmpty:"stop"})},Tv=async t=>{await $c(t),await xc(t,sc);const e=await kh(t),a=await _f(t);if(void 0===e&&(void 0===a||0===a.length))throw i(ac);const n=await Ic(t);if("symbolic"!==n.kind)throw o(sc,"cannot continue with detached HEAD");let r=await Ae(t,n.target);const s=[];if(void 0!==e){const i=void 0!==a?a.length-1:0,o=await(async(t,e,a)=>{const n=await de(t);(t=>{const e=new Set;for(const a of t)0!==a.flags.stage&&e.add(a.path);if(e.size>0)throw C(e.size,[...e])})(n.entries);const r=await ca(t,n.entries);if(r===await Zd(t,a))return{empty:!0};const i=await(async(t,e,a,n)=>{const r=await el(t),i=Zf(tl(await pc(t)??""),{allowEmpty:!1}),o=await $a(t,{tree:n,parents:[e],author:r,committer:r,message:i,extraHeaders:[]});return await fe(t,a,o,{expected:e,reflogMessage:js(ur(i))}),o})(t,a,e,r);return await $h(t),await yc(t),{created:i}})(t,n.target,r);if("empty"in o)return{kind:"empty",commit:e,remaining:i};s.push({source:e,created:o.created}),r=o.created}const c=(a??[]).slice(void 0!==e?1:0).map(t=>t.oid),d=await Lf(t)??r,u=void 0===e?"drop":"stop",f=await $v(t,c,n.target,r,{multiPick:!0,sequenceHead:d,onEmpty:u});return"reverted"===f.kind?{kind:"reverted",commits:[...s,...f.commits]}:f},Dv=async t=>{await $c(t),await xc(t,cc);const e=await kh(t),a=await _f(t);if(void 0===e&&(void 0===a||0===a.length))throw i(ac);const n=await tu(t,cc),r=await Ae(t,n);await Mc(t,r),await $h(t),await yc(t);const o=(a??[]).slice(1).map(t=>t.oid),s=await Lf(t)??r;return $v(t,o,n,r,{multiPick:!0,sequenceHead:s,onEmpty:"stop"})},Sv=async t=>{await $c(t),await xc(t,dc);const e=await kh(t),a=await Lf(t);if(void 0===e&&void 0===a)throw i(ac);const n=await tu(t,dc),r=a??await Ae(t,n);return await Ff(t,{branch:n,target:r,clearHead:$h}),{head:r,branch:n}},Av=(t,e)=>Object.freeze({run:a=>(e(),Ev(t,a)),continue:()=>(e(),Tv(t)),skip:()=>(e(),Dv(t)),abort:()=>(e(),Sv(t))}),Mv=(t,e)=>void 0===t||t(e),Ov=t=>({kind:"delete",path:t.path,mode:t.mode,id:void 0,previousId:t.id,previousMode:t.mode}),Nv=t=>({kind:"add",path:t.path,mode:t.mode,id:t.id,previousId:void 0,previousMode:void 0}),Pv=t=>({kind:"noop",path:t.path,mode:t.mode,id:t.id,previousId:t.id,previousMode:t.mode}),Cv={ctimeSeconds:0,ctimeNanoseconds:0,mtimeSeconds:0,mtimeNanoseconds:0,dev:0,ino:0,uid:0,gid:0,fileSize:0},Hv=t=>({...Cv,mode:t.mode,id:t.id,flags:{...Pt,skipWorktree:!0},path:t.path}),Lv=t=>t.flags.skipWorktree?{...t,flags:{...t.flags,skipWorktree:!1}}:t,Rv=async(t,e)=>{const a=t.layout.workDir,n=await ce(t);try{const r=(await de(t)).entries.filter(t=>0===t.flags.stage),i=await(async(t,e,a,n)=>{const r=[],i=[],o=[];for(const s of a){if(Mv(n.matcher,s.path)){r.push(s);continue}const a=he(e,s.path),c=await t.fs.exists(a);c&&await Tn(t,a,s.id)&&!0!==n.force?o.push(s):i.push({entry:s,present:c})}return{included:r,removable:i,retained:o}})(t,a,r,e),o=await(async(t,e,a)=>{const n=[];for(const{entry:t,present:e}of a.removable)n.push(e?Ov(t):Pv(t));for(const r of a.included){const a=await t.fs.exists(he(e,r.path));n.push(a?Pv(r):Nv(r))}const r={add:0,update:0,delete:0,noop:0};for(const t of n)r[t.kind]+=1;return{entries:n,stats:r}})(t,a,i),s=await En(t,{changeset:o,force:!0,workdir:a}),c=((t,e)=>{const a=new Map;for(const t of e)a.set(t.path,t);const n=[];for(const e of t.included)n.push(a.get(e.path)??Lv(e));for(const{entry:e}of t.removable)n.push(Hv(e));for(const e of t.retained)n.push(Lv(e));return n})(i,s.writtenEntries);return await n.commit(c),{materialized:s.written,removed:s.deleted,retained:i.retained.map(t=>t.path)}}finally{await n.release()}},Uv=async t=>{await $c(t),await xc(t,"sparse-checkout"),await Dc(t)},_v=async t=>{await Uv(t);const e=await ne(t);if(!0!==e.core?.sparseCheckout)return{cone:!1,patterns:[]};const a=!0===e.core.sparseCheckoutCone,n=await Dn(t)??"";return"cone"===(r=An(n,a).spec).mode?{cone:!0,patterns:[...r.recursive].sort()}:{cone:!1,patterns:r.rules.map(t=>t.source)};var r},Wv=(t,e)=>void 0===e?{matcher:t}:{matcher:t,force:e},jv=async(t,e,a,n)=>{const r=await Rv(t,Wv(Pn(e),n));return await Nn(t,a),await Sn(t,{sparseCheckout:"true",sparseCheckoutCone:"cone"===e.mode?"true":"false"}),Gv("cone"===e.mode,r)},Bv=async(t,e)=>{if(await Uv(t),0===e.patterns.length)throw u("patterns","set requires at least one pattern");const a=await ne(t),n=e.cone??a.core?.sparseCheckoutCone??!0,{spec:r,text:i}=Kv(n,e.patterns);return jv(t,r,i,e.force)},Fv=async(t,e)=>{if(await Uv(t),0===e.patterns.length)throw u("patterns","add requires at least one pattern");const a=await ne(t);if(!0!==a.core?.sparseCheckout)throw u("action","add requires sparse checkout to be enabled");const n=!0===a.core.sparseCheckoutCone,r=await Dn(t)??"",{spec:i,text:o}=Vv(n,r,e.patterns);return jv(t,i,o,e.force)},zv=async(t,e)=>{await Uv(t);const a=await ie(t);if(void 0===a)throw u("action","reapply requires sparse checkout to be enabled");const n=await ne(t),r=await Rv(t,Wv(a,e?.force));return Gv(!0===n.core?.sparseCheckoutCone,r)},qv=async(t,e)=>{await Uv(t);const a=await Rv(t,Wv(void 0,e?.force));return await Sn(t,{sparseCheckout:"false"}),Gv(!1,a)},Kv=(t,e)=>{if(t){const t=Mn(e);return{spec:t,text:On(t)}}const a=e.join("\n");return{spec:An(a,!1).spec,text:a}},Vv=(t,e,a)=>{if(t){const t=An(e,!0).spec,n="cone"===t.mode?[...t.recursive,...a]:a,r=Mn(n);return{spec:r,text:On(r)}}const n=(""===e?a:[e,...a]).join("\n");return{spec:An(n,!1).spec,text:n}},Gv=(t,e)=>({cone:t,materialized:e.materialized,removed:e.removed,retained:e.retained}),Yv=(t,e)=>Object.freeze({list:()=>(e(),_v(t)),set:a=>(e(),Bv(t,a)),add:a=>(e(),Fv(t,a)),reapply:a=>(e(),zv(t,a)),disable:a=>(e(),qv(t,a))}),Xv="refs/stash",Jv=new TextEncoder,Qv=(t,e)=>je(t,Xv,Be(t.layout.gitDir,Xv),Jv.encode(`${e}\n`)),Zv=async t=>{const e=await Se(t,Xv),a=e.length-1;return e.map((t,n)=>{const r=e[a-n];return{index:n,selector:`stash@{${n}}`,stash:r.newId,message:r.message}})},tb=async(t,e)=>{const a=await oe(t,e);if("commit"!==a.type)throw se("commit",a.type,e);return a.data.tree},eb=async(t,e,a)=>{const n=he(t.layout.workDir,e),r=a.isSymbolicLink?(new TextEncoder).encode(await t.fs.readlink(n)):await t.fs.read(n);return{id:await Wn(t,r,{write:!0}),mode:ke(a)}},ab=async(e,a={})=>{await $c(e),await xc(e,"stash"),await Dc(e);const n=await Ic(e),r=await(async(e,a)=>{const n=await(async(e,a)=>{if("direct"===a.kind)return a.id;try{return await Ae(e,a.target)}catch(e){if(e instanceof t&&"REF_NOT_FOUND"===e.data.code)throw P();throw e}})(e,a),r=await oe(e,n);if("commit"!==r.type)throw se("commit",r.type,n);return{b:n,bTree:r.data.tree,branchRef:"symbolic"===a.kind?a.target:void 0,subject:ur(r.data.message)}})(e,n),i=await ce(e);try{const t=await de(e),n=await ca(e,t.entries),o=await(async(t,e)=>{const a=[];let n=!1;const r=await we(t);for(const i of e.entries){if(0!==i.flags.stage)continue;if(i.flags.skipWorktree){a.push(i);continue}const e=await ha(t,i,r);if("absent"===e){n=!0;continue}if("unchanged"===e){a.push(i);continue}n=!0;const o=await t.fs.lstat(he(t.layout.workDir,i.path)),{id:s,mode:c}=await eb(t,i.path,o);a.push($f(i.path,s,c))}return{entries:a,dirty:n}})(e,t),s=a.includeUntracked?await(async(t,e)=>{const a=new Set(e.entries.map(t=>t.path)),n=await me(t),r=[],i=[];for await(const{path:e,stat:o}of pe(t,{ignore:n})){if(a.has(e))continue;const{id:n,mode:s}=await eb(t,e,o);i.push($f(e,n,s)),r.push(e)}return{paths:r,entries:i}})(e,t):{paths:[],entries:[]};if(!(n!==r.bTree||o.dirty||s.paths.length>0))return{kind:"no-local-changes"};const c=await nb(e,{base:r,iTree:n,working:o,untracked:s,opts:a});return await(async(t,e,a)=>{const n=await(async t=>{const e=await Me(t).resolveDirect(Xv);return"direct"===e.kind?e.id:ze})(t);await Qv(t,e);const r=await Hn(t);await Ln(t,Xv,{oldId:n,newId:e,identity:r,message:Rn(a)})})(e,c.stash,c.message),await ob(e,i,{base:r,iTree:n,untracked:s,opts:a}),{kind:"saved",stash:c.stash,message:c.message}}finally{await i.release()}},nb=async(t,e)=>{const{base:a,iTree:n,working:r,untracked:i,opts:o}=e,s=await Hn(t),c=(d=a.branchRef,d?.startsWith(bu)?d.slice(11):"(no branch)");var d;const u=ii(a.b),f=a.subject,l=void 0!==o.message?((t,e)=>`On ${t}: ${e}`)(c,o.message):((t,e,a)=>`WIP on ${t}: ${e} ${a}`)(c,u,f),h=(e,a,n)=>$a(t,{tree:e,parents:a,author:s,committer:s,message:n,extraHeaders:[]}),w=await h(n,[a.b],((t,e,a)=>`index on ${t}: ${e} ${a}`)(c,u,f)),m=await ca(t,r.entries);if(0===i.paths.length)return{stash:await h(m,[a.b,w],l),message:l};const p=await ca(t,i.entries),g=await h(p,[],((t,e,a)=>`untracked files on ${t}: ${e} ${a}`)(c,u,f));return{stash:await h(m,[a.b,w,g],l),message:l}},rb=async t=>(await $c(t),{entries:await Zv(t)}),ib=async(t,e={})=>(await $c(t),await xc(t,"stash drop"),(async(t,e)=>{const a=await Se(t,Xv),n=a.length-1-e,r=a[n];if(void 0===r)throw rt(e,a.length);const i=a[n+1],o=a.filter((t,e)=>e!==n).map(t=>t===i?{...t,oldId:r.oldId}:t);if(0===o.length)return await Me(t).removeLoose(Xv),await Cn(t,Xv),{dropped:r.newId,remaining:0};const s=o[o.length-1];return await Qv(t,s.newId),await Fe(t,Xv,o),{dropped:r.newId,remaining:o.length}})(t,e.index??0)),ob=async(t,e,a)=>{const{base:n,iTree:r,untracked:i,opts:o}=a,s=await de(t),c=!0===o.keepIndex?r:n.bTree,d=await ue(t,{targetTree:c,currentIndex:s,force:!0,forceRewriteAll:!0});if(await e.commit(d.newIndexEntries),!0===o.includeUntracked)for(const e of i.paths)await pa(t,e)},sb=async(t,e={})=>{await $c(t),await xc(t,"stash apply"),await Dc(t);const a=await(async(t,e)=>{const a=await Se(t,Xv),n=a[a.length-1-e];if(void 0===n)throw rt(e,a.length);return n.newId})(t,e.index??0),n=await(async(t,e)=>{const a=await oe(t,e);if("commit"!==a.type)throw se("commit",a.type,e);const[n,r,i]=a.data.parents;if(void 0===n||void 0===r)throw Un("ref does not point at a stash commit");return{base:n,indexParent:r,untrackedParent:i,wTree:a.data.tree}})(t,a),r=await tb(t,n.base),i=void 0!==n.untrackedParent?await tb(t,n.untrackedParent):void 0,o=await ce(t);try{const s=await de(t),c=await ca(t,s.entries);if(void 0!==i){const e=await(async(t,e)=>{const a=await ma(t,e),n=[];for(const e of a.entries.keys())await t.fs.exists(he(t.layout.workDir,e))&&n.push(e);return n})(t,i);if(e.length>0)throw it(e)}const d=await Sf(t,{baseTree:r,oursTree:c,theirsTree:n.wTree,currentIndex:s,labels:ui});if("would-overwrite"===d.kind)throw it([...d.localChanges,...d.untracked]);return"conflict"===d.kind?(await o.commit(d.indexEntries),{kind:"conflict",conflicts:d.conflicts.map(t=>({path:t.path,type:t.type}))}):(!0===e.restoreIndex&&await(async(t,e,a)=>{const n=await tb(t,a.indexParent),r=await(async(t,e)=>{const[a,n,r]=await Promise.all([void 0!==e.baseTree?ma(t,e.baseTree):Promise.resolve(void 0),ma(t,e.oursTree),ma(t,e.theirsTree)]),i=await Hi(a,n,r,pf(t,e.labels),e.labels);return i.cleanMerge?{kind:"clean",mergedTree:await Ef(t,i.outcomes)}:{kind:"conflict",conflicts:i.conflicts}})(t,{baseTree:a.bTree,oursTree:a.cTree,theirsTree:n,labels:ui});if("clean"!==r.kind)return;const i=await _n(t,{targetTree:r.mergedTree,currentIndex:a.currentIndex});await e.commit(i)})(t,o,{bTree:r,cTree:c,indexParent:n.indexParent,currentIndex:s}),void 0!==i&&await(async(t,e)=>{const a=await ma(t,e);for(const[e,n]of a.entries){const a=await ya(t,n.id);await va(t,e,a)}})(t,i),{kind:"applied",stash:a})}finally{await o.release()}},cb=async(t,e={})=>{const a=await sb(t,e);if("conflict"===a.kind)return a;const n=await ib(t,{index:e.index??0});return{kind:"applied",stash:a.stash,dropped:n.dropped}},db=(t,e)=>Object.freeze({push:a=>(e(),ab(t,a)),list:()=>(e(),rb(t)),apply:a=>(e(),sb(t,a)),pop:a=>(e(),cb(t,a)),drop:a=>(e(),ib(t,a))}),ub=t=>t.split("/").length,fb=(t,e)=>`${"../".repeat(2+ub(t))}${e}`,lb="./",hb="../",wb=t=>t.startsWith("/"),mb=t=>{const e=t.indexOf(":"),a=t.indexOf("/");return e<0||a>=0&&a<e},pb=(e,a)=>{const n=e.lastIndexOf("/");if(n>=0)return{base:e.slice(0,n),colonSep:!1};const r=e.lastIndexOf(":");if(r>=0)return{base:e.slice(0,r),colonSep:!0};if(a||"."===e)throw new t({code:"RELATIVE_URL_UNRESOLVABLE",url:e});return{base:".",colonSep:!1}},gb=(t,e)=>e.startsWith(lb)||e.startsWith(hb)?((t,e)=>{if(!mb(e)||wb(e))return e;let a=t.endsWith("/")?t.slice(0,-1):t;const n=mb(a)&&!wb(a);n&&(a=(t=>t.startsWith(lb)||t.startsWith(hb)?t:`${lb}${t}`)(a));let r=e,i=!1;for(;r.length>0;)if(r.startsWith(hb)){r=r.slice(3);const t=pb(a,n);a=t.base,i=i||t.colonSep}else{if(!r.startsWith(lb))break;r=r.slice(2)}const o=`${a}${i?":":"/"}${r}`,s=r.endsWith("/")?o.slice(0,-1):o;return s.startsWith(lb)?s.slice(2):s})(t,e):e,yb=new Set(["checkout","rebase","merge","none"]),vb=t=>yb.has(t)?t:void 0,bb=".gitmodules",kb="HEAD",$b=t=>void 0!==t.path&&!tn(t.path),xb=async t=>{const e=he(t.layout.workDir,bb);if(!await t.fs.exists(e))return[];const a=await t.fs.stat(e);if(a.size>qn)throw l(e,a.size,qn);return Kn(await t.fs.readUtf8(e))},Ib=t=>{const e=new Map;for(const a of t){if(void 0===a.update)continue;const t=vb(a.update);if(void 0===t)throw u(`submodule.${a.name}.update`,`invalid value '${a.update}'`);e.set(a.name,t)}return e},Eb=(t,e)=>{const a=t.filter($b);if(void 0===e)return a;const n=a.filter(t=>e.includes(t.path)),r=new Set(n.map(t=>t.path));for(const t of e)if(!r.has(t))throw d(t);return n},Tb=async(t,e)=>{const a=await(async t=>Ec(await Ic(t)))(t),n=a?.startsWith(bu)?em(a):void 0,r=(void 0!==n?e.branch?.get(n)?.remote:void 0)??am;return e.remote?.get(r)?.url??t.layout.workDir},Db=(t,e,a)=>{const n=(e,a)=>({kind:"set",section:"submodule",subsection:t,key:e,value:a}),r=[n("active","true"),n("url",e)];return void 0!==a&&r.push(n("update",a)),r},Sb=async(t,e={})=>{await $c(t);const a=await xb(t),n=Ib(a),r=Eb(a,e.paths),i=await ne(t),o=await Tb(t,i),s=[],c=[];for(const t of r){if(void 0===t.url)continue;const e=t.path,a=n.get(t.name),r=i.submodule?.get(t.name)?.url;if(void 0!==r){s.push({name:t.name,path:e,url:r,registered:!1,...void 0!==a?{update:a}:{}});continue}const d=gb(o,t.url);c.push(...Db(t.name,d,a)),s.push({name:t.name,path:e,url:d,registered:!0,...void 0!==a?{update:a}:{}})}return c.length>0&&await In(t,c),{entries:s}},Ab=async(t,e,a,n)=>{const r=await Vn(t,e,a);return void 0!==r&&(await In(r,[{kind:"set",section:"remote",subsection:"origin",key:"url",value:n}]),!0)},Mb=async(t,e,a,n)=>{await $c(t);const r=Eb(await xb(t),e.paths),i=await ne(t),o=await Tb(t,i),s=[],c=[];for(const e of r){if(void 0===e.url)continue;if(void 0===i.submodule?.get(e.name)?.url)continue;const a=e.path,n=gb(o,e.url);c.push({kind:"set",section:"submodule",subsection:e.name,key:"url",value:n});const r=await Ab(t,e.name,a,n);s.push({name:e.name,path:a,url:n,syncedRemote:r})}if(c.length>0&&await In(t,c),!0===e.recursive&&a<Yn)for(const i of r){const r=`${t.layout.gitDir}/modules/${i.name}`,o=await Vn(t,i.name,i.path,n);void 0!==o&&await Mb(o,e,a+1,new Set([...n,r]))}return{entries:s}},Ob=(t,e={})=>Mb(t,e,0,new Set),Nb=async(e,a,n)=>{const r=await Vn(e,a,n);if(void 0!==r&&!(await Ew(r)).clean)throw(e=>new t({code:"SUBMODULE_HAS_MODIFICATIONS",path:e}))(n)},Pb=async(t,e)=>{const a=he(t.layout.workDir,e);return!!await t.fs.exists(a)&&0!==(await t.fs.readdir(a)).length&&(await t.fs.rmRecursive(a),await t.fs.mkdir(a),!0)},Cb=async(t,e={})=>{await $c(t);const a=void 0!==e.paths&&e.paths.length>0;if(!0===e.all&&a)throw u("submodule.deinit","pathspec and --all are incompatible");if(!0!==e.all&&!a)throw u("submodule.deinit","use 'all: true' to deinitialise every submodule");const n=await xb(t),r=!0===e.all?n.filter($b):Eb(n,e.paths),i=await ne(t),o=[];for(const a of r){const n=a.path;!0!==e.force&&await Nb(t,a.name,n);const r=await Pb(t,n);!0===i.submodule?.has(a.name)&&await In(t,[{kind:"removeSection",section:"submodule",subsection:a.name}]),o.push({name:a.name,path:n,url:a.url??"",cleared:r})}return{entries:o}},Hb=async(t,e={})=>{await $c(t);const a=(t=>Gn(t)?Kt.from(t):Pe(t))(e.ref??"HEAD"),n=!0===e.recursive,r=[];for await(const i of Fn(t,{ref:a,recursive:n,...void 0!==e.maxDepth?{maxDepth:e.maxDepth}:{}}))r.push(i);return{entries:r}},Lb=(t,e,a)=>({kind:"set",section:"submodule",subsection:t,key:e,value:a}),Rb=async(t,e,a,n,r)=>{await fh(e,{url:a}),await In(e,[{kind:"set",section:"core",key:"worktree",value:fb(n,r)}]),await t.fs.writeUtf8(he(t.layout.workDir,`${r}/.git`),`${((t,e)=>`gitdir: ${"../".repeat(ub(e))}.git/modules/${t}`)(n,r)}\n`)},Ub=async(e,a)=>{await $c(e),await xc(e,"submodule add");const n=a.name??a.path;((t,e,a)=>{if(""===a)throw u("submodule.add","url must not be empty");if(""===e)throw u("submodule.add","path must not be empty");if(tn(t))throw u("submodule.add.name",`unsafe name '${t}'`);if(tn(e))throw u("submodule.add.path",`unsafe path '${e}'`)})(n,a.path,a.url),void 0!==a.branch&&Pe(`${bu}${a.branch}`),await(async(e,a)=>{if((await de(e)).entries.some(t=>t.path===a))throw(e=>new t({code:"SUBMODULE_PATH_EXISTS",path:e}))(a)})(e,a.path);const r=await ne(e),i=await Tb(e,r),o=gb(i,a.url),s=jn(e,n,a.path);await Rb(e,s,o,n,a.path),void 0!==a.branch?await(async(t,e)=>{const a=await Ae(t,`refs/remotes/origin/${e}`),n=`${bu}${e}`;await t.fs.writeUtf8(`${t.layout.gitDir}/${n}`,`${a}\n`),await sa(t,n,ze,a,Bs(`origin/${e}`)),await In(t,[{kind:"set",section:"branch",subsection:e,key:"remote",value:"origin"},{kind:"set",section:"branch",subsection:e,key:"merge",value:n}]),await uf(t,{rev:e})})(s,a.branch):await Bn(s);const c="symbolic"===(l=await Me(s).resolveDirect(kb)).kind&&!0===l.target?.startsWith(bu)?l.target.slice(11):"",d=await Ae(s,kb),f=await(async(t,e,a,n,r)=>{const i=he(t.layout.workDir,bb),o=await t.fs.exists(i)?await t.fs.readUtf8(i):"",s=[Lb(e,"path",a),Lb(e,"url",n)];void 0!==r&&s.push(Lb(e,"branch",r));let c=o;for(const t of s)c=zn(c,t);return await t.fs.writeUtf8(i,c),(new TextEncoder).encode(c)})(e,n,a.path,a.url,a.branch);var l;return await(async(t,e,a,n)=>{const r=await ye(t,{type:"blob",id:"",content:n}),i=await ce(t);try{const n=await de(t),o=new Map(n.entries.map(t=>[t.path,t])),s=await t.fs.lstat(he(t.layout.workDir,e));o.set(e,Nc(s,qt.GITLINK,a,e));const c=await t.fs.lstat(he(t.layout.workDir,bb));o.set(bb,Nc(c,qt.REGULAR,r,bb)),await i.commit([...o.values()])}finally{await i.release()}})(e,a.path,d,f),await In(e,[Lb(n,"url",o),Lb(n,"active","true")]),{name:n,path:a.path,url:o,id:d,branch:c}},_b=(t,e)=>t.entries.find(t=>t.path===e&&t.mode===qt.GITLINK)?.id,Wb=(t,e,a,n)=>{if(void 0!==t.mode)return t.mode;const r=e.submodule?.get(n)?.update,i=void 0===r?void 0:vb(r);if(void 0!==r&&void 0===i)throw u(`submodule.${n}.update`,`invalid value '${r}'`);return i??a??"checkout"},jb=async(t,e,a)=>{if("checkout"===a){const a=await Me(t).resolveDirect(kb);return("direct"!==a.kind||a.id!==e)&&(await uf(t,{rev:e,detach:!0}),!0)}const n=await Ae(t,kb);return"rebase"===a?await Py(t,{upstream:e}):await wg(t,{rev:e}),await Ae(t,kb)!==n},Bb=async(t,e={})=>{await $c(t),await xc(t,"submodule update");const a=await xb(t),n=Eb(a,e.paths),r=Ib(a),i=await de(t);let o=await ne(t);const s=[];for(const a of n){const n=_b(i,a.path);if(void 0===n)continue;if(await ka(t,"submodule",a.name,["update"]),void 0===o.submodule?.get(a.name)?.url){if(await ka(t,"submodule",a.name,["url"]),!0!==e.init)continue;await Sb(t,{paths:[a.path]}),o=await ne(t)}const c=Wb(e,o,r.get(a.name),a.name);if("none"===c){s.push({name:a.name,path:a.path,id:n,mode:c,cloned:!1,changed:!1});continue}const d=o.submodule?.get(a.name)?.url??a.url??"",u=jn(t,a.name,a.path),f=!await t.fs.exists(`${u.layout.gitDir}/HEAD`);f&&(await Rb(t,u,d,a.name,a.path),await Bn(u)),await oe(u,n);const l=await jb(u,n,c);s.push({name:a.name,path:a.path,id:n,mode:c,cloned:f,changed:l})}return{entries:s}},Fb=(t,e)=>Object.freeze({list:a=>(e(),Hb(t,a)),add:a=>(e(),Ub(t,a)),init:a=>(e(),Sb(t,a)),update:a=>(e(),Bb(t,a)),sync:a=>(e(),Ob(t,a)),deinit:a=>(e(),Cb(t,a))}),zb="refs/tags/",qb=async t=>{await $c(t);const e=`${t.layout.gitDir}/refs/tags`;if(!await t.fs.exists(e))return{tags:[]};const a=await t.fs.readdir(e),n=[];for(const e of a){if(!e.isFile)continue;const a=`${zb}${e.name}`,r=await Ae(t,a);n.push({name:a,id:r})}return n.sort((t,e)=>t.name<e.name?-1:1),{tags:n}},Kb=async(t,e)=>{await $c(t);const a=Pe(`${zb}${e.name}`),n=void 0!==e.target?e.target:await tk(t),r=/^[0-9a-f]{40}$/.test(n)?n:await Ae(t,n),i=Vb(e)?await Gb(t,e,r):r;return await Qb(t,a,i,!0===e.force,`tag: ${e.name}`),{name:a,id:i}},Vb=t=>!0===t.annotate||void 0!==t.message||!0===t.sign,Gb=async(t,e,a)=>{const n=await Jb(t,a),r=await el(t),i=lr(e.message??""),o=await Yb(t,e,a,n,r,i);return Xn(t,{object:a,objectType:n,tagName:e.name,tagger:r,message:i,...void 0!==o?{gpgSignature:o}:{}})},Yb=async(t,e,a,n,r,i)=>{const o=await ne(t);if(e.sign??!0===o.tag?.gpgSign)return Xb(t,o,{object:a,objectType:n,tagName:e.name,tagger:r,message:i,extraHeaders:[]},r,e.signKey)},Xb=async(t,e,a,n,r)=>{const i=Ih(e,n,r),o=Jn({data:a});return Eh(t,o,i)},Jb=async(t,e)=>(await oe(t,e)).type,Qb=async(e,a,n,r,i)=>{try{await fe(e,a,n,r?{reflogMessage:i}:{expected:"absent",reflogMessage:i})}catch(e){if(e instanceof t&&"REF_UPDATE_CONFLICT"===e.data.code)throw st(a);throw e}},Zb=async(t,e)=>{await $c(t);const a=Pe(`${zb}${e.name}`);if(!await t.fs.exists(`${t.layout.gitDir}/${a}`))throw ot(a);return await fe(t,a,ze,{delete:!0}),{name:a}},tk=async t=>{const e=await Ic(t);return"direct"===e.kind?e.id:Ae(t,e.target)},ek=(t,e)=>Object.freeze({list:()=>(e(),qb(t)),create:a=>(e(),Kb(t,a)),delete:a=>(e(),Zb(t,a))}),ak=t=>`${t}/.git`,nk=e=>new t({code:"WORKTREE_PATH_EXISTS",path:e}),rk=t=>{const e=t.split("/").filter(t=>""!==t);return e[e.length-1]??""},ik=(t,e)=>{const a=e.startsWith("/")?e:`${t}/${e}`,n=[];for(const t of a.split("/"))""!==t&&"."!==t&&(".."!==t?n.push(t):n.pop());return`/${n.join("/")}`},ok=(t,e)=>t.worktreeFs?.(e)??t.fs,sk=(t,e,a)=>{const n=Ee(t),r=`${n}/worktrees/${e}`,{promisor:i,hooks:o,command:s,...c}=t;return Object.freeze({...c,fs:ok(t,a),layout:Object.freeze({workDir:a,gitDir:r,commonDir:n,bare:!1,...void 0!==t.layout.homeDir?{homeDir:t.layout.homeDir}:{}}),cwd:a})},ck=async(t,e)=>{const a=te(e);if("direct"===a.type)return{head:a.target,detached:!0};const n=await Me(t).resolveDirect(a.target);return{branch:a.target,detached:!1,..."direct"===n.kind?{head:n.id}:{}}},dk=async(t,e,a)=>{const n=(await t.fs.readUtf8(`${a}/gitdir`)).trim(),r=n.endsWith("/.git")?n.slice(0,-5):n,i=await ck(t,await t.fs.readUtf8(`${a}/HEAD`)),o=await(async(t,e)=>{if(await t.fs.exists(`${e}/locked`))return{reason:(await t.fs.readUtf8(`${e}/locked`)).trim()}})(t,a),s=ok(t,r),c=await s.exists(n)?void 0:{reason:"gitdir file points to non-existent location"};return{id:e,path:r,bare:!1,main:!1,...i,...void 0!==o?{locked:o}:{},...void 0!==c?{prunable:c}:{}}},uk=(t,e)=>t.path<e.path?-1:t.path>e.path?1:0,fk=async t=>{const e=await(async t=>{const e=t.layout.workDir;if(t.layout.bare)return{path:e,detached:!1,bare:!0,main:!0};const a=await t.fs.readUtf8(`${Ee(t)}/HEAD`);return{path:e,bare:!1,main:!0,...await ck(t,a)}})(t),a=`${Ee(t)}/worktrees`;if(!await t.fs.exists(a))return[e];const n=[];for(const e of await t.fs.readdir(a))e.isDirectory&&n.push(await dk(t,e.name,`${a}/${e.name}`));return n.sort(uk),[e,...n]},lk="HEAD",hk=async t=>(await $c(t),{entries:await fk(t)}),wk=async(t,e)=>{const a=ok(t,e);if(await a.exists(e)&&(await a.readdir(e)).length>0)throw nk(e)},mk=async(e,a)=>{if(await $c(e),""===a.path)throw nk("");const n=ik(e.cwd,a.path);if(""===(r=rk(n))||"."===r||".."===r||r.includes("/")||r.includes("\\")||(t=>{for(const e of t)if(e.charCodeAt(0)<=31)return!0;return!1})(r))throw u("worktree add",`invalid worktree path '${a.path}'`);var r;await wk(e,n);const i=await gw(e,a.commitish??"HEAD"),o=await xe(e,i),s=await(async(t,e,a)=>{if(void 0!==e.branch)return{kind:"create",branchRef:`${bu}${e.branch}`,name:e.branch};if(!0===e.detach)return{kind:"detached"};if(void 0!==e.commitish){const a=`${bu}${e.commitish}`;return"direct"===(await Me(t).resolveDirect(a)).kind?{kind:"checkout",branchRef:a}:{kind:"detached"}}const n=rk(a);return{kind:"create",branchRef:`${bu}${n}`,name:n}})(e,a,n);"checkout"===s.kind&&await(async(e,a,n)=>{if(n)return;const r=(await fk(e)).find(t=>t.branch===a);if(void 0!==r)throw new t({code:"BRANCH_CHECKED_OUT",branch:a,path:r.path})})(e,s.branchRef,!0===a.force),"create"===s.kind&&await Eu(e,{name:s.name,startPoint:a.commitish??"HEAD",force:!0===a.force});const c="detached"===s.kind?{kind:"detached",oid:i}:{kind:"branch",ref:s.branchRef},d=await(async(t,e)=>{const a=`${Ee(t)}/worktrees`,n=await t.fs.exists(a)?(await t.fs.readdir(a)).filter(t=>t.isDirectory).map(t=>t.name):[];return((t,e)=>{let a=t,n=0;for(;e.has(a);)n+=1,a=`${t}${n}`;return a})(rk(e),new Set(n))})(e,n);await(async(t,e,a,n,r)=>{const i=`${Ee(t)}/worktrees/${e}`;var o;return await t.fs.writeUtf8(`${i}/commondir`,"../..\n"),await t.fs.writeUtf8(`${i}/gitdir`,`${ak(a)}\n`),await t.fs.writeUtf8(`${i}/HEAD`,`${(t=>"branch"===t.kind?`ref: ${t.ref}`:t.oid)(n)}\n`),await t.fs.writeUtf8(`${i}/${Yt}`,`${r}\n`),await ok(t,a).writeUtf8(`${a}/.git`,(o=i,`gitdir: ${o}\n`)),i})(e,d,n,c,i);const f=sk(e,d,n);return await(async(t,e)=>{const a=await ce(t);try{const n=await de(t),r=await ue(t,{targetTree:e,currentIndex:n});await a.commit(r.newIndexEntries)}finally{await a.release()}})(f,o.id),await(async(t,e,a)=>{await sa(t,lk,ze,a,""),"detached"!==e.kind&&await sa(t,lk,a,a,Fs("HEAD"))})(f,s,i),{path:n,id:d,head:i,detached:"detached"===s.kind,..."detached"!==s.kind?{branch:s.branchRef}:{}}},pk=async(e,a,n)=>{const r=(await fk(e)).find(t=>t.path===a);if(void 0===r)throw new t({code:"NOT_A_WORKTREE",path:a});if(r.main||void 0===r.id)throw u(`worktree ${n}`,"cannot operate on the main working tree");return r},gk=(e,a)=>{if(void 0!==e.locked&&!a)throw new t({code:"WORKTREE_LOCKED",path:e.path,reason:e.locked.reason})},yk=async(t,e,a,n={})=>{await $c(t);const r=ik(t.cwd,e),i=ik(t.cwd,a),o=await pk(t,r,"move");gk(o,!0===n.force),await wk(t,i),await ok(t,[r,i]).rename(r,i);const s=`${Ee(t)}/worktrees/${o.id}`;return await t.fs.writeUtf8(`${s}/gitdir`,`${ak(i)}\n`),{from:r,to:i,id:o.id}},vk=async(e,a,n={})=>{await $c(e);const r=ik(e.cwd,a),i=await pk(e,r,"remove");if(gk(i,!0===n.force),!0!==n.force){const a=sk(e,i.id,r);if(!(await Ew(a)).clean)throw(e=>new t({code:"WORKTREE_DIRTY",path:e}))(r)}return await ok(e,r).rmRecursive(r),await e.fs.rmRecursive(`${Ee(e)}/worktrees/${i.id}`),{path:r,id:i.id}},bk=(t,e)=>Object.freeze({list:()=>(e(),hk(t)),add:a=>(e(),mk(t,a)),move:(a,n,r)=>(e(),yk(t,a,n,r)),remove:(a,n)=>(e(),vk(t,a,n))}),kk=(t,e)=>!(void 0!==e.minParents&&t<e.minParents||void 0!==e.maxParents&&t>e.maxParents),$k=async(t,e={})=>{await $c(t);const a=await gw(t,e.rev??"HEAD"),n=await Promise.all((e.excluding??[]).map(e=>gw(t,e))),r=e.before,i="first-parent"===e.order?Ke(t,{from:[a],until:n,order:"first-parent"}):Qn(t,{from:[a],until:n}),o=[];let s=0;for await(const t of i)if(!(void 0!==r&&t.data.committer.timestamp>=r.getTime()/1e3)&&kk(t.data.parents.length,e)&&(o.push({id:t.id,tree:t.data.tree,parents:t.data.parents,author:t.data.author,committer:t.data.committer,message:t.data.message}),s+=1,void 0!==e.limit&&s>=e.limit))break;return o},xk=async(t,e,a,n={})=>{await $c(t),await xc(t,"mv"),await Dc(t);const r=e.map(t=>Pc(t)),[i]=r;if(void 0===i)throw f();Ok(r);const o=Pc(Rk(a)),s=await ce(t);try{const e=await Ik(t),c=await Ek(t,i,a,o);if("rename"===c.kind&&r.length>1)throw ct(i,c.target);const{planned:d,skipped:u}=await Tk(t,e,r,c,n);Nk(d);const f=Pk(d);if(!0===n.dryRun)return{moved:f,skipped:u};Ck(e,d);for(const e of d)await Lc(t,e.source,e.target);return await s.commit(Array.from(e.values())),{moved:f,skipped:u}}finally{await s.release()}},Ik=async e=>{const a=await de(e).catch(e=>{if(e instanceof t&&("FILE_NOT_FOUND"===(a=e.data.code)||"INVALID_INDEX_HEADER"===a||"INVALID_INDEX_ENTRY"===a))return{entries:[]};var a;throw e}),n=new Map;for(const t of a.entries)n.set(t.path,t);return n},Ek=async(t,e,a,n)=>{const r=await Uk(t,n);if(!0===r?.isDirectory&&!0!==r.isSymbolicLink)return{kind:"into-dir",destDir:n};if(a.endsWith("/"))throw ut(e,a);return{kind:"rename",target:n}},Tk=async(t,e,a,n,r)=>{const i=[],o=[];for(const s of a){const a="rename"===n.kind?n.target:Zn(n.destDir,ft(s)),c=await Dk(t,e,s,a,r);if("skip"in c){if(!0===r.skipErrors){o.push({source:s,reason:c.skip});continue}throw Lk(c.skip,s,a)}i.push({source:s,target:a,entries:c.entries})}return{planned:i,skipped:o}},Dk=async(t,e,a,n,r)=>{const i=Sk(e,a);if("untracked"===i.kind)return{skip:"source-not-tracked"};if(!await Ak(t,a,i.kind))return{skip:"bad-source"};if(n===a||n.startsWith(`${a}/`))return{skip:"into-self"};const o=c(n);if(""!==o&&!await _k(t,o))throw ut(a,n);return await Mk(t,e,n,i.kind,!0===r.force)?{kind:i.kind,entries:i.entries}:{skip:"destination-exists"}},Sk=(t,e)=>{const a=t.get(e);if(void 0!==a)return{kind:"file",entries:[a]};const n=`${e}/`,r=Array.from(t.values()).filter(t=>t.path.startsWith(n));return r.length>0?{kind:"directory",entries:r}:{kind:"untracked"}},Ak=async(t,e,a)=>{const n=await Uk(t,e);return void 0!==n&&("directory"===a?n.isDirectory&&!n.isSymbolicLink:n.isFile||n.isSymbolicLink)},Mk=async(t,e,a,n,r)=>!(e.has(a)||void 0!==await Uk(t,a))||"file"===n&&r,Ok=t=>{for(const e of t)for(const a of t)if(a!==e&&a.startsWith(`${e}/`))throw dt(a,e)},Nk=t=>{const e=new Set;for(const a of t){if(e.has(a.target))throw lt(a.source,a.target);e.add(a.target)}},Pk=t=>{const e=[];for(const a of t)for(const t of a.entries)e.push({from:t.path,to:Hk(t,a.source,a.target)});return e.sort((t,e)=>t.from<e.from?-1:t.from>e.from?1:0)},Ck=(t,e)=>{for(const a of e)for(const e of a.entries){const n=Hk(e,a.source,a.target);t.delete(e.path),t.set(n,{...e,path:n})}},Hk=(t,e,a)=>`${a}${t.path.slice(e.length)}`,Lk=(t,e,a)=>{switch(t){case"source-not-tracked":return pt(e,a);case"bad-source":return mt(e,a);case"destination-exists":return wt(e,a);case"into-self":return ht(e,a)}},Rk=t=>t.endsWith("/")?t.slice(0,-1):t,Uk=async(t,e)=>t.fs.lstat(((t,e)=>he(t.layout.workDir,e))(t,e)).catch(()=>{}),_k=async(t,e)=>{const a=await Uk(t,e);return!0===a?.isDirectory&&!0!==a.isSymbolicLink},Wk=async(t,e={})=>{await $c(t),await xc(t,"pull"),await Dc(t);const a=await Ic(t),n=Ec(a),r=void 0!==n?em(n):void 0,i=n??re.from("HEAD"),{remote:o,branch:s}=await(async(t,e,a,n)=>{const r=await ne(t);void 0!==e&&await ka(t,"branch",e,["remote","merge"]);const i=void 0!==e?r.branch?.get(e):void 0,o=rm(r,a.remote,e),s=a.ref??(c=i?.merge,void 0===c?void 0:em(c));var c;if(void 0===s)throw gt(n);return{remote:o,branch:s}})(t,r,e,i),c=await dm(t,{remote:o,...void 0!==e.prune?{prune:e.prune}:{},...void 0!==e.depth?{depth:e.depth}:{}}),d=await Ae(t,`refs/remotes/${o}/${s}`);return{fetch:c,merge:await wg(t,{rev:d,message:e.message??`Merge branch '${s}' of ${c.url}`,...void 0!==e.fastForward?{fastForward:e.fastForward}:{},...void 0!==e.author?{author:e.author}:{},...void 0!==e.committer?{committer:e.committer}:{}},{reflogAction:"pull"})}},jk=(t,e,a)=>{const n=em(a),r=rm(t,void 0,n),i=im(t,e.remote,n);return{branchFull:a,fetchRemote:r,pushRemote:i,triangular:i!==r,merge:t.branch?.get(n)?.merge}},Bk="push:enumerate-objects",Fk="push:upload",zk=Kt.from("0".repeat(40)),qk=new Set(["side-band-64k","side-band"]),Kk=async(t,e={})=>{await $c(t),await(async t=>{const e=await tr(t);if(void 0!==e)throw $t(e.value,e.source,e.line)})(t),t.progress.start(Bk);try{return await Vk(t,e)}finally{t.progress.end(Bk)}},Vk=async(t,e)=>{const a=await Ic(t),n=Ec(a),r=void 0!==n?em(n):void 0,i=await ne(t),o=im(i,e.remote,r),s=await Jk(t,o),c=await(async(t,e,a)=>{if(void 0!==e.refspecs&&e.refspecs.length>0)return{kind:"explicit",refspecs:e.refspecs.map(Zy)};if("current"===t.push?.default)return(t=>{const e=Ec(t);if(void 0===e)throw vt();return{kind:"fixed",refspecs:[Zy(`${e}:${e}`)]}})(a);if("nothing"===t.push?.default)throw yt();return"upstream"===t.push?.default?((t,e,a)=>{const n=Ec(a);if(void 0===n)throw vt();const{branchFull:r,pushRemote:i,triangular:o,merge:s}=jk(t,e,n);if(o)throw bt(i,r);if(void 0===s)throw gt(r);return{kind:"fixed",refspecs:[Zy(`${r}:${s}`)]}})(t,e,a):"matching"===t.push?.default?{kind:"matching"}:((t,e,a)=>{const n=Ec(a);if(void 0===n)throw vt();const{branchFull:r,triangular:i,merge:o}=jk(t,e,n);if(i)return{kind:"fixed",refspecs:[Zy(`${r}:${r}`)]};if(void 0===o)throw gt(r);const s=re.from(o);if(em(s)!==em(r))throw kt(r,s);return{kind:"fixed",refspecs:[Zy(`${r}:${s}`)]}})(t,e,a)})(i,e,a),d=Zl(t,s,"git-receive-pack");try{return await Gk(t,e,o,s,c,d)}finally{await d.close()}},Gk=async(t,e,a,n,r,i)=>{const o=await(async t=>(async t=>{const e=await t.advertisement();return Vo(e,"git-receive-pack",{servicePrologue:t.servicePrologue})})(t))(i),s=((t,e,a)=>{if("matching"!==t.kind)return t.refspecs;const n=new Set(e.refs.filter(t=>t.name.startsWith(bu)).map(t=>t.name));return a.filter(t=>n.has(t)).map(t=>Zy(`${t}:${t}`))})(r,o,"matching"===r.kind?(await Qe(t)).filter(t=>t.startsWith(bu)):[]),c=(await Qk(t,s,o,a,e)).filter(t=>t.localOid!==t.remoteOid);return 0===c.length?{remote:a,url:n,pushedRefs:[]}:(await Yk(t,e.noVerify??!1,a,n,c),{remote:a,url:n,pushedRefs:await i$(t,i,o,c,a,e,n)})},Yk=async(t,e,a,n,r)=>{if(e)return;const i=r.map(Xk).join("");await Ma(t,"pre-push",{args:[a,n],stdin:i})},Xk=t=>`${t.parsed.isDelete?"(delete)":t.parsed.src} ${t.localOid} ${t.parsed.dst} ${t.remoteOid}\n`,Jk=async(t,e)=>{sm(e);const a=await ne(t);await ka(t,"remote",e,["pushurl","url"]);const n=a.remote?.get(e),r=n?.pushUrl??n?.url;if(void 0===r)throw X(e);return r},Qk=async(t,e,a,n,r)=>{const i=Zk(a.refs),o=[];for(const a of e)o.push(await t$(t,a,i,n,r));return o},Zk=t=>{const e=new Map;for(const a of t)e.set(a.name,a.id);return e},t$=async(t,e,a,n,r)=>{const i=a.get(e.dst)??zk;if(e.isDelete){if(i===zk)throw u("refspecs",`delete target ${e.dst} is not advertised`);return{parsed:e,localOid:zk,remoteOid:i}}const o=await Ae(t,e.src);return await e$(t,e,o,i,n,r),{parsed:e,localOid:o,remoteOid:i}},e$=async(t,e,a,n,r,i)=>{const o=await a$(t,e,r,i);if(void 0===o){if("force"!==e.force&&!0!==i.force&&n!==zk&&!await n$(t,n,a))throw Q(e.dst,a,n)}else if(o!==n)throw xt(e.dst,"lease-mismatch",r$())},a$=async(t,e,a,n)=>{if(void 0===n.forceWithLease)return;if("auto"!==n.forceWithLease)return n.forceWithLease;if(!e.dst.startsWith(bu))throw u("forceWithLease","lease-on-non-branch");const r=e.dst.slice(11);return Ae(t,`refs/remotes/${a}/${r}`)},n$=async(t,e,a)=>{for await(const n of Ke(t,{from:[a],ignoreMissing:!0}))if(n.id===e)return!0;return!1},r$=()=>({unpackOk:!0,refUpdates:[]}),i$=async(e,a,n,r,i,o,s)=>{const c=await o$(e,o),d=s$(n.capabilities),u=c$(c,d,i),f=r.filter(t=>!t.parsed.isDelete).map(t=>t.localOid),l=n.refs.map(t=>t.id),h=await u$(e,f,l),w=await Ze(e,{oids:h}),m=((t,e=!1)=>{const a=Ui.filter(t=>t!==Li),n=e?[...a,_i]:a;return[...ji(t,n),Li]})(n.capabilities,u.signing),p=u.signing?await d$(e,m,r,w.bytes,s,u.nonce):(e=>{if(0===e.updates.length)throw new t({code:"EMPTY_RECEIVE_UPDATES"});const a=e.updates.map((t,a)=>Do(t,0===a?e.capabilities:[])),n=yo(a),r=new Uint8Array(n.byteLength+e.packfile.byteLength);return r.set(n,0),r.set(e.packfile,n.byteLength),r})({updates:r.map(f$),capabilities:m,packfile:w.bytes}),g=await l$(e,a,p),y=await h$(e,g,m);if(!y.unpackOk)throw xt(r[0]?.parsed.dst,y.unpackError??"unpack failed",y);return await m$(e,r,y.refUpdates,i)},o$=async(t,e)=>{if(void 0!==e.signed)return e.signed;const a=await ne(t),n=a.push?.gpgSign;return"if-asked"===n?"if-asked":"true"===n?"yes":"no"},s$=t=>t.find(t=>t.startsWith(`${_i}=`))?.slice(10),c$=(t,e,a)=>{if("yes"===t&&void 0===e)throw It(a);return void 0===e||"no"===t?{signing:!1}:{signing:!0,nonce:e}},d$=async(t,e,a,n,r,i)=>{const o=await ne(t),s=await el(t),c=`${Na({...void 0!==o.user?.signingKey?{signingKey:o.user.signingKey}:{},fallbackIdent:`${s.name} <${s.email}>`})} ${s.timestamp} ${s.timezoneOffset}`,d=Al(r),u=a.map(f$),f=(t=>{const e=t.reduce((t,e)=>t+e.byteLength,0),a=new Uint8Array(e);let n=0;for(const e of t)a.set(e,n),n+=e.byteLength;return a})(So({pusher:c,pushee:d,nonce:i,updates:u})),l=await Eh(t,f,Ih(o,s,void 0));return(t=>{const e=To.encode(`push-cert\0 ${t.capabilities.join(" ")}`),a=(n=t.armor,(n.endsWith("\n")?n.slice(0,-1):n).split("\n").map(t=>`${t}\n`)).map(t=>To.encode(t));var n;const r=To.encode("push-cert-end\n"),i=yo([e,...So(t),...a,r]),o=new Uint8Array(i.byteLength+t.packfile.byteLength);return o.set(i,0),o.set(t.packfile,i.byteLength),o})({updates:u,capabilities:e.filter(t=>t!==_i&&!t.startsWith(`${_i}=`)),armor:l,pusher:c,pushee:d,nonce:i,packfile:n})},u$=async(t,e,a)=>{if(0===e.length)return[];const n=[];for await(const r of er(t,{wants:e,haves:a}))n.push(r);return n},f$=t=>({name:t.parsed.dst,oldId:t.remoteOid,newId:t.localOid}),l$=async(t,e,a)=>{t.progress.start(Fk);try{return await e.exchange(a)}finally{t.progress.end(Fk)}},h$=async(t,e,a)=>{if(w$(a)){const a=Co(e,{onProgress:e=>t.progress.update(Fk,0,void 0,H(e))});return Oo(ko(a))}return Oo(e)},w$=t=>t.some(t=>qk.has(t)),m$=async(t,e,a,n)=>{const r=new Map;for(const t of a)r.set(t.name,t);const i=[];for(const a of e){const e=r.get(a.parsed.dst),o=!0===e?.accepted;o&&await p$(t,a,n),i.push({name:a.parsed.dst,oldId:a.remoteOid,newId:a.localOid,status:o?"ok":"rejected",...void 0!==e?.reason?{reason:e.reason}:{}})}return i},p$=async(t,e,a)=>{if(!e.parsed.dst.startsWith(bu))return;if(e.parsed.isDelete)return;const n=`refs/remotes/${a}/${e.parsed.dst.slice(11)}`;Sa(n)&&await fe(t,n,e.localOid,{reflogMessage:"update by push"})},g$=new TextEncoder,y$=65536,v$=t=>0|t,b$=(t,e,a)=>t.cost[e+t.columnCount*a],k$=(t,e,a)=>{const n=0===a?1:0;let r=v$(b$(t,n,e)-t.v[n]);for(let n=1;n<t.columnCount;n++){const i=v$(b$(t,n,e)-t.v[n]);n!==a&&r>i&&(r=i)}t.v[a]=v$(t.v[a]-r)},$$=(t,e,a,n,r)=>{const i=((t,e)=>{let a=0,n=v$(b$(t,a,e)-t.v[a]),r=-1,i=y$;for(let o=1;o<t.columnCount;o++){const s=v$(b$(t,o,e)-t.v[o]);i>s&&(n<s?(i=s,r=o):(i=n,n=s,r=a,a=o))}return r<0&&(r=a,i=n),{j1:a,u1:n,j2:r,u2:i}})(t,a);let o=i.j1,s=t.columnToRow[o],c=n,d=r;return i.u1<i.u2?t.v[o]=v$(t.v[o]-(i.u2-i.u1)):s>=0&&(o=i.j2,s=t.columnToRow[o]),s>=0&&(i.u1<i.u2?e[--c]=s:e[d++]=s),t.rowToColumn[a]=o,t.columnToRow[o]=a,{k:c,freeCount:d}},x$=(t,e,a,n)=>{let r=e[a[n.up++]],i=-1;for(let o=n.up;o<t.columnCount;o++){const t=a[o];i=t;const s=e[t];s<=r&&(s<r&&(n.up=n.low,r=s),a[o]=a[n.up],a[n.up++]=t)}return{min:r,lastJ:i}},I$=(t,e,a)=>{for(let n=a.low;n<a.up;n++)if(-1===t.columnToRow[e[n]])return!0;return!1},E$=(t,e,a,n,r,i)=>{do{const o=n[r.low++],s=t.columnToRow[o],c=v$(b$(t,o,s)-t.v[o]-i);for(let o=r.up;o<t.columnCount;o++){const d=n[o],u=v$(b$(t,d,s)-t.v[d]-c);if(u<e[d]&&(e[d]=u,a[d]=s,u===i)){if(-1===t.columnToRow[d])return d;n[o]=n[r.up],n[r.up++]=d}}}while(r.low!==r.up);return-1},T$=(t,e)=>{const a=new Array(t.columnCount),n=new Array(t.columnCount),r=new Array(t.columnCount);for(let i=0;i<t.columnCount;i++)a[i]=v$(b$(t,i,e)-t.v[i]),n[i]=e,r[i]=i;const i=((t,e,a,n)=>{const r={low:0,up:0};for(;;){const i=r.low,{min:o,lastJ:s}=x$(t,e,n,r);if(I$(t,n,r))return{j:s,last:i,min:o};const c=E$(t,e,a,n,r,o);if(c>=0)return{j:c,last:i,min:o}}})(t,a,n,r);for(let e=0;e<i.last;e++){const n=r[e];t.v[n]=v$(t.v[n]+(a[n]-i.min))}let o,s=i.j;do{o=n[s],t.columnToRow[s]=o;const e=t.rowToColumn[o];t.rowToColumn[o]=s,s=e}while(e!==o)},D$=(t,e,a)=>t<0?Math.trunc(e*a/100):y$,S$=(t,e,a,n,r)=>{return a===r?0:a<0&&n<0?(i=e.diff,Br(g$.encode(t.diff),g$.encode(i),3).reduce((t,e)=>t+1+e.body.length,0)):y$;var i},A$=(t,e,a)=>{const n=t.length,r=e.length,i=new Array(n).fill(-1),o=new Array(r).fill(-1),{exactOld:s,exactNew:c}=((t,e)=>{const a=new Array(t.length).fill(-1),n=new Array(e.length).fill(-1),r=new Map;return t.forEach((t,e)=>{const a=r.get(t.diff);a?a.push(e):r.set(t.diff,[e])}),e.forEach((t,e)=>{const i=r.get(t.diff),o=i?.pop();void 0!==o&&(a[o]=e,n[e]=o)}),{exactOld:a,exactNew:n}})(t,e),d=n+r,u=((t,e,a,n,r)=>{const i=t.length,o=e.length,s=i+o,c=new Array(s*s).fill(0);for(let d=0;d<i;d++){for(let r=0;r<o;r++)c[d+s*r]=S$(t[d],e[r],a[d],n[r],r);const i=D$(a[d],t[d].diffsize,r);for(let t=o;t<s;t++)c[d+s*t]=i}for(let t=0;t<o;t++){const a=D$(n[t],e[t].diffsize,r);for(let e=i;e<s;e++)c[e+s*t]=a}return c})(t,e,s,c,a),{columnToRow:f}=((t,e)=>{const a=new Array(t),n=new Array(t);if(t<2)return a.fill(0),n.fill(0),{columnToRow:a,rowToColumn:n};a.fill(-1),n.fill(-1);const r={columnCount:t,rowCount:t,cost:e,v:new Array(t).fill(0),columnToRow:a,rowToColumn:n};(t=>{for(let e=t.columnCount-1;e>=0;e--){let a=0;for(let n=1;n<t.rowCount;n++)b$(t,e,a)>b$(t,e,n)&&(a=n);t.v[e]=b$(t,e,a),-1===t.rowToColumn[a]?(t.rowToColumn[a]=e,t.columnToRow[e]=a):(t.rowToColumn[a]>=0&&(t.rowToColumn[a]=-2-t.rowToColumn[a]),t.columnToRow[e]=-1)}})(r);const i=new Array(t);let o=((t,e)=>{let a=0;for(let n=0;n<t.rowCount;n++){const r=t.rowToColumn[n];-1===r?e[a++]=n:r<-1?t.rowToColumn[n]=-2-r:k$(t,n,r)}return a})(r,i);if(0===o)return{columnToRow:a,rowToColumn:n};o=((t,e,a)=>{let n=a;for(let a=0;a<2;a++){let a=0;const r=n;for(n=0;a<r;){const r=e[a++],i=$$(t,e,r,a,n);a=i.k,n=i.freeCount}}return n})(r,i,o);for(let t=0;t<o;t++)T$(r,i[t]);return{columnToRow:a,rowToColumn:n}})(d,u);for(let t=0;t<n;t++){const e=f[t];e>=0&&e<r&&(i[t]=e,o[e]=t)}return{old:t.map((t,e)=>({patch:t,matching:i[e]})),new:e.map((t,e)=>({patch:t,matching:o[e]}))}},M$=new TextEncoder,O$=(t,e)=>({position:e+1,id:t.id}),N$=(t,e)=>({status:"only-old",old:O$(t.patch,e),subject:t.patch.subject}),P$=(t,e)=>({status:"only-new",new:O$(t.patch,e),subject:t.patch.subject}),C$=(t,e,a,n)=>{const r=t.patch.patch!==e.patch.patch;return{status:r?"changed":"unchanged",old:O$(t.patch,a),new:O$(e.patch,n),subject:t.patch.subject,...r?{diffOfDiffs:Ht(M$.encode(t.patch.patch),M$.encode(e.patch.patch))}:{}}},H$=new TextDecoder("utf-8",{fatal:!1}),L$=t=>32===t||t>=9&&t<=13,R$=t=>{if(0===t.length||!((e=t[0])>=65&&e<=90||e>=97&&e<=122||95===e||36===e))return;var e;let a=Math.min(t.length,80);for(;a>0&&L$(t[a-1]);)a--;return H$.decode(t.subarray(0,a))},U$=(t,e,a)=>{const n=e>a?-1:1;for(let r=e;r!==a&&r>=0&&r<t.length;r+=n){const e=R$(t[r]);if(void 0!==e)return{index:r,heading:e}}},_$=new Uint8Array,W$=t=>"add"===t.type?`${t.newPath} (new)`:"delete"===t.type?`${t.oldPath} (deleted)`:"rename"===t.type||"copy"===t.type?`${t.oldPath} => ${t.newPath}`:t.oldMode===t.newMode?t.path:`${t.path} (mode change ${t.oldMode} => ${t.newMode})`,j$=t=>"delete"===t.type?t.oldPath:"add"===t.type||"rename"===t.type||"copy"===t.type?t.newPath:t.path,B$=t=>{const e=`${a=t.kind,"context"===a?" ":"delete"===a?"-":"+"}${t.text}`;var a;return t.trailingNoNewline?[e," \"]:[e]},F$=t=>t.oldLen>0?t.oldStart-1:t.oldStart,z$=t=>{const e=t.oldContent??_$,a=t.newContent??_$;return Lt(e)||Lt(a)?{lines:[q$(t,e,a)],count:1}:((t,e,a)=>{const n=Ct(t),r=[];let i=-1,o="";for(const t of e){const e=F$(t),s=U$(n,e-1,i);i=e-1,void 0!==s&&(o=s.heading),r.push(""===o?"@@":`@@ ${a}: ${o}`);for(const e of t.body)for(const t of B$(e))r.push(t)}return{lines:r,count:r.length}})(e,Br(e,a,3),j$(t.change))},q$=(t,e,a)=>` Binary files ${0===e.length?"/dev/null":j$(t.change)} and ${0===a.length?"/dev/null":j$(t.change)} differ`,K$=t=>{const e=(t=>{var e;return` ## Metadata ##\nAuthor: ${t.authorName} <${t.authorEmail}>\n\n ## Commit message ##\n`+(e=t.message,""===e?[]:(e.endsWith("\n")?e.slice(0,-1):e).split("\n").map(t=>` ${t}`.replace(/[\t\n\v\f\r ]+$/u,""))).map(t=>`${t}\n`).join("")})(t);let a=e,n=0;for(const e of t.files){const t=` ## ${W$(e.change)} ##`,{lines:r,count:i}=z$(e);a+=`\n${t}\n${r.map(t=>`${t}\n`).join("")}`,n+=1+i}return{id:t.id,subject:t.subject,patch:a,diff:a.slice(t.files.length>0?e.length+1:0),diffsize:n}},V$=async(t,e)=>{const a=e.data.parents[0],n=void 0!==a?await(async(t,e)=>{const a=await oe(t,e);if("commit"!==a.type)throw se("commit",a.type,e);return a.data.tree})(t,a):void 0,r=await Re(t,n,e.data.tree,{recursive:!0,detectRenames:!0}),i=await xn(t,r.changes);return{id:e.id,authorName:e.data.author.name,authorEmail:e.data.author.email,subject:fr(e.data.message),message:e.data.message,files:i}},G$=async(t,e)=>{const a=await gw(t,e.base),n=await gw(t,e.tip),r=[];for await(const e of Qn(t,{from:[n],until:[a]}))e.data.parents.length<=1&&r.push(e);return r.reverse(),(async(t,e)=>{const a=new Array(e.length);let n=0;const r=Math.min(16,e.length);return await Promise.all(Array.from({length:r},()=>(async()=>{for(;n<e.length;){const r=n++;a[r]=await V$(t,e[r])}})())),a})(t,r)},Y$=async(t,e)=>{await $c(t);const a=(t=>{if(void 0===t)return 60;if(!Number.isInteger(t)||t<0)throw u("creationFactor",`must be a non-negative integer; got ${t}`);return t})(e.creationFactor);return((t,e,a)=>{const n=t.map(K$),r=e.map(K$),{old:i,new:o}=A$(n,r,a);return((t,e)=>{const a=[],n=new Array(t.length).fill(!1);let r=0,i=0;for(;r<t.length||i<e.length;){for(;r<t.length&&n[r];)r++;if(r<t.length&&t[r].matching<0)a.push(N$(t[r],r)),r++;else{for(;i<e.length&&e[i].matching<0;)a.push(P$(e[i],i)),i++;if(i<e.length){const r=e[i].matching;a.push(C$(t[r],e[i],r,i)),n[r]=!0,i++}}}return a})(i,o)})(await G$(t,e.old),await G$(t,e.new),a)},X$=async(t,e,a,n)=>{await $c(t);const r=await Nd(t,e),i=await xe(t,r),o=await cd(t,i,a,e),s=await He(t,o.id,n);return{id:o.id,mode:o.mode,content:s.content}},J$=t=>Pe(t),Q$=async(t,e={})=>(await $c(t),"exists"===e.action?tx(t,e.ref):"delete"===e.action?ex(t,e):"expire"===e.action?nx(t,e):Z$(t,e.ref??"HEAD")),Z$=async(t,e)=>{const a=J$(e),n=await Se(t,a),r=n.length-1,i=n.map((t,e)=>({index:e,selector:`${a}@{${e}}`,entry:n[r-e]}));return{kind:"show",ref:a,entries:i}},tx=async(t,e)=>({kind:"exists",exists:await Oe(t,J$(e))}),ex=async(t,e)=>{const a=J$(e.ref);if(!await Oe(t,a))throw ar(a);const n=await Se(t,a);if(!Number.isInteger(e.index)||e.index<0)throw Ne(a,e.index,n.length);const r=n.length-1-e.index;if(r<0)throw Ne(a,e.index,n.length);const i=n[r],o=ax(n,r,!0===e.rewrite);return await Fe(t,a,o),{kind:"delete",removed:i}},ax=(t,e,a)=>{const n=t[e],r=t[e+1];return t.filter((t,a)=>a!==e).map(t=>a&&t===r?{...t,oldId:n.oldId}:t)},nx=async(t,e)=>{const a=Math.floor(Date.now()/1e3),n=rx(e.expire??"90.days.ago",a),r=rx(e.expireUnreachable??"30.days.ago",a),i=await ox(t),o=!0===e.all?await rn(t):[J$(e.ref??"HEAD")];let s=0,c=0;for(const e of o){const a=await Se(t,e),o=a.filter(t=>ix(t,i,n,r));s+=a.length-o.length,c+=o.length,o.length!==a.length&&await Fe(t,e,o)}return{kind:"expire",removed:s,kept:c}},rx=(t,e)=>{const a=Rs(t,e);if(void 0===a)throw g(t);return a},ix=(t,e,a,n)=>{const r=e.has(t.newId)?a:n;return t.identity.timestamp>=r},ox=async t=>{const e=await sx(t),a=new Set;if(0===e.length)return a;for await(const n of Ke(t,{from:e,ignoreMissing:!0}))a.add(n.id);return a},sx=async t=>{const e=new Set;for(const a of await Qe(t)){const n=await cx(t,a);void 0!==n&&e.add(n)}return[...e]},cx=async(e,a)=>{try{return await Ae(e,a)}catch(e){if(e instanceof t)return;throw e}},dx=async(t,e)=>{await $c(t),"hard"===e.mode&&await xc(t,"reset --hard"),await Dc(t);const a=await lx(t,e.rev);"mixed"===e.mode?await ux(t,a):"hard"===e.mode&&await fx(t,a);const n=await Ic(t),r="symbolic"===n.kind?n.target:void 0;return await fe(t,r??"HEAD",a,{reflogMessage:Fs(e.rev)}),{mode:e.mode,id:a,branch:r}},ux=async(t,e)=>{const a=await oe(t,e);if("commit"!==a.type)throw se("commit",a.type,e);const n=await ie(t),r=await ce(t);try{const e=await de(t),i=await _n(t,{targetTree:a.data.tree,currentIndex:e,...void 0!==n?{sparse:n}:{}});await r.commit(i)}finally{await r.release()}},fx=async(t,e)=>{const a=await oe(t,e);if("commit"!==a.type)throw se("commit",a.type,e);const n=await ie(t),r=await ce(t);try{const e=await de(t),i=await ue(t,{targetTree:a.data.tree,currentIndex:e,force:!0,forceRewriteAll:!0,...void 0!==n?{sparse:n}:{}});(i.written>0||i.deleted>0||void 0!==n)&&await r.commit(i.newIndexEntries)}finally{await r.release()}},lx=async(t,e)=>{if(/^[0-9a-f]{40}$/.test(e))return e;const a="HEAD"===e?["HEAD"]:[e,`refs/heads/${e}`,`refs/tags/${e}`];for(const e of a)try{return await Ae(t,e)}catch{}throw g(e)},hx=async(e,a,n={})=>{if(await $c(e),await xc(e,"rm"),await Dc(e),0===a.length)throw f();const{matcher:r,literalMustMatch:i}=_c(a),o=await ce(e);try{const a=await de(e).catch(e=>{if(e instanceof t&&("FILE_NOT_FOUND"===(a=e.data.code)||"INVALID_INDEX_HEADER"===a||"INVALID_INDEX_ENTRY"===a))return{entries:[]};var a;throw e}),s=new Map;for(const t of a.entries)s.set(t.path,t);const c=[],d=[];for(const[t,e]of s)Xr(r,t)&&(c.push(t),d.push(e));Bc(i,c),!0!==n.force&&await wx(e,d,!0===n.cached);for(const t of c)s.delete(t);if(!n.cached)for(const a of c)await Hc(e,a).catch(e=>{if(!(e instanceof t&&"FILE_NOT_FOUND"===e.data.code))throw e});return await o.commit(Array.from(s.values())),{removed:c}}finally{await o.release()}},wx=async(t,e,a)=>{const n=await px(t),{both:r,stagedOnly:i,localOnly:o}=await(async(t,e,a,n)=>{const r=await we(t),i=[],o=[],s=[];for(const c of e){const e=await ha(t,c,r);if("absent"===e)continue;const d=la(e),u=mx(a,c);u&&d?i.push(c.path):u&&!n?o.push(c.path):d&&!n&&s.push(c.path)}return{both:i,stagedOnly:o,localOnly:s}})(t,e,n,a);if(r.length>0)throw Et(r);if(i.length>0)throw Tt(i);if(o.length>0)throw Dt(o)},mx=(t,e)=>{const a=t.get(e.path);return void 0===a||a.id!==e.id||a.mode!==e.mode},px=async t=>(await qa(t))?.entries??new Map,gx=/^[ \t\n\v\f\r]+/,yx=t=>{const e=fr(t).replace(gx,"");return(e.startsWith("[PATCH")?vx(e):e).replace(gx,"")},vx=t=>t.slice(t.indexOf("]")+1),bx=new TextEncoder,kx=async(t,e={})=>{await $c(t);const a=await gw(t,e.rev??"HEAD"),n=await Promise.all((e.excluding??[]).map(e=>gw(t,e))),r="committer"===e.by,i=[];for await(const e of Qn(t,{from:[a],until:n})){const t=r?e.data.committer:e.data.author;i.push({name:t.name,email:t.email,id:e.id,subject:yx(e.data.message)})}return(t=>{const e=new Map;for(const{name:a,email:n,id:r,subject:i}of t){const t={id:r,email:n,subject:i},o=e.get(a);void 0===o?e.set(a,[t]):o.push(t)}return[...e.entries()].map(([t,e])=>({name:t,commits:[...e].reverse()})).sort((t,e)=>an(bx.encode(t.name),bx.encode(e.name)))})(i)},$x=async(t,e,a,n=!1)=>{const r=void 0!==e?await Zd(t,e):void 0;return Re(t,r,a,{recursive:!0,detectRenames:!0,...n?{withStat:!0}:{}})};async function xx(t,e="HEAD",a={}){await $c(t);const n=!0===a.withStat;if("string"==typeof e)return Ix(t,e,n);const r=[];for(const a of e)r.push(await Ix(t,a,n));return r}const Ix=async(t,e,a)=>Ex(t,await oe(t,await Nd(t,e)),a);async function Ex(t,e,a){switch(e.type){case"blob":return{kind:"blob",id:e.id,content:e.content};case"tree":return function(t){const e=t.entries.map(t=>({name:t.name,mode:t.mode,id:t.id}));return{kind:"tree",id:t.id,entries:e}}(e);case"commit":return async function(t,e,a){const{parents:n,tree:r}=e.data;if(n.length>=2){const i=[];for(const e of n)i.push(await $x(t,e,r,a));return{kind:"commit",id:e.id,commit:e.data,perParent:i}}const i=await $x(t,n[0],r,a);return{kind:"commit",id:e.id,commit:e.data,patch:i}}(t,e,a);case"tag":return async function(t,e,a){const n=await Ex(t,await oe(t,e.data.object),a);return{kind:"tag",id:e.id,tag:e.data,target:n}}(t,e,a)}}const Tx=async(t,e={})=>{await $c(t);const a=await gw(t,e.rev??"HEAD"),n=await Promise.all((e.excluding??[]).map(e=>gw(t,e))),r=e.before,i="first-parent"===e.order?Ke(t,{from:[a],until:n,order:"first-parent"}):Qn(t,{from:[a],until:n}),o=[];let s=0;for await(const a of i){if(a.data.parents.length>=2)continue;if(void 0!==r&&a.data.committer.timestamp>=r.getTime()/1e3)continue;const n=await $x(t,a.data.parents[0],a.data.tree);if(o.push({id:a.id,tree:a.data.tree,parents:a.data.parents,author:a.data.author,committer:a.data.committer,message:a.data.message,changes:n}),s+=1,void 0!==e.limit&&s>=e.limit)break}return o};export{xk as $,ml as A,hl as B,fl as C,wl as D,fh as E,Th as F,qh as G,Kh as H,Vh as I,Gh as J,Zh as K,Qh as L,Yh as M,Xh as N,Jh as O,Am as P,Rw as Q,tm as R,dm as S,Sm as T,rg as U,cg as V,dg as W,$k as X,Oc as Y,tw as Z,wg as _,Vc as a,vw as a0,Vg as a1,Yg as a2,Gg as a3,Xg as a4,Wk as a5,Kk as a6,Y$ as a7,X$ as a8,Uy as a9,rb as aA,cb as aB,ab as aC,Ew as aD,Ub as aE,Cb as aF,Sb as aG,Hb as aH,Ob as aI,Bb as aJ,Kb as aK,Zb as aL,qb as aM,Tx as aN,mk as aO,hk as aP,yk as aQ,vk as aR,Xr as aS,Ly as aa,Py as ab,Ry as ac,Q$ as ad,cv as ae,sv as af,uv as ag,lv as ah,hv as ai,wv as aj,dx as ak,Nd as al,Sv as am,Tv as an,Ev as ao,Dv as ap,hx as aq,kx as ar,xx as as,Fv as at,qv as au,_v as av,zv as aw,Bv as ax,sb as ay,ib as az,Kd as b,ug as c,fg as d,lg as e,hg as f,Wg as g,Jg as h,Jy as i,mv as j,Av as k,Yv as l,db as m,Fb as n,ek as o,bk as p,nu as q,Eu as r,Tu as s,xu as t,Du as u,Gu as v,Qu as w,tf as x,sf as y,uf as z};
|