@scolladon/tsgit 3.0.0 → 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.
Files changed (143) hide show
  1. package/README.md +12 -0
  2. package/dist/cjs/adapters/browser/index.cjs +1 -2
  3. package/dist/cjs/adapters/memory/index.cjs +1 -2
  4. package/dist/cjs/adapters/node/index.cjs +1 -2
  5. package/dist/cjs/chunks/{adapter-detect-D7DFJtuk.cjs → adapter-detect-DW9fsw9d.cjs} +1 -2
  6. package/dist/cjs/chunks/browser-http-transport-DGwW5YL7.cjs +1 -0
  7. package/dist/cjs/chunks/context-BcoAzPuU.cjs +0 -1
  8. package/dist/cjs/chunks/error-CfLWDui_.cjs +1 -0
  9. package/dist/cjs/chunks/index-Cy44GVR6.cjs +1 -0
  10. package/dist/cjs/chunks/inflate-CmCtM4-w.cjs +1 -0
  11. package/dist/cjs/chunks/lru-cache-1OU7JhD8.cjs +0 -1
  12. package/dist/cjs/chunks/memory-http-transport-CGriODcQ.cjs +1 -0
  13. package/dist/cjs/chunks/node-ssh-transport-PFu3ijfp.cjs +1 -0
  14. package/dist/cjs/chunks/{progress-CjhUeyxd.cjs → progress-D8Dqbftk.cjs} +1 -2
  15. package/dist/cjs/chunks/readable-stream-MTA6D0Zh.cjs +0 -1
  16. package/dist/cjs/chunks/{repository-DJNNrfQr.cjs → repository-Ci-BBxk0.cjs} +1 -2
  17. package/dist/cjs/chunks/write-sparse-checkout-C1dsHCAD.cjs +1 -0
  18. package/dist/cjs/commands/index.cjs +1 -2
  19. package/dist/cjs/index.browser.cjs +1 -2
  20. package/dist/cjs/index.cjs +1 -2
  21. package/dist/cjs/index.default.cjs +1 -2
  22. package/dist/cjs/index.node.cjs +1 -2
  23. package/dist/cjs/operators/index.cjs +0 -1
  24. package/dist/cjs/primitives/index.cjs +1 -2
  25. package/dist/cjs/transport/index.cjs +0 -1
  26. package/dist/esm/adapters/browser/index.js +1 -2
  27. package/dist/esm/adapters/memory/index.js +1 -2
  28. package/dist/esm/adapters/node/index.js +1 -2
  29. package/dist/esm/chunks/{adapter-detect-CTTG6hpk.js → adapter-detect-BkCMnjrI.js} +1 -2
  30. package/dist/esm/chunks/browser-http-transport-CSxAte5h.js +1 -0
  31. package/dist/esm/chunks/context-CumKOV7K.js +0 -1
  32. package/dist/esm/chunks/error-BotOd-nD.js +1 -0
  33. package/dist/esm/chunks/index-DsvINN8n.js +1 -0
  34. package/dist/esm/chunks/inflate-BCIXqeeE.js +1 -0
  35. package/dist/esm/chunks/lru-cache-Cy7C7Lx2.js +0 -1
  36. package/dist/esm/chunks/memory-http-transport-caqmMGR1.js +1 -0
  37. package/dist/esm/chunks/node-ssh-transport-BgSv2IhT.js +1 -0
  38. package/dist/esm/chunks/{progress-CLPpgZJ6.js → progress-B_AJnOHx.js} +1 -2
  39. package/dist/esm/chunks/readable-stream-CGuf8k1J.js +0 -1
  40. package/dist/esm/chunks/repository-DyxknzvE.js +1 -0
  41. package/dist/esm/chunks/write-sparse-checkout-BwHbNKNS.js +1 -0
  42. package/dist/esm/commands/index.js +1 -2
  43. package/dist/esm/index.browser.js +1 -2
  44. package/dist/esm/index.default.js +1 -2
  45. package/dist/esm/index.js +1 -2
  46. package/dist/esm/index.node.js +1 -2
  47. package/dist/esm/operators/index.js +0 -1
  48. package/dist/esm/primitives/index.js +1 -2
  49. package/dist/esm/transport/index.js +0 -1
  50. package/dist/types/adapters/browser/index.d.cts +1 -1
  51. package/dist/types/adapters/browser/index.d.ts +1 -1
  52. package/dist/types/adapters/memory/index.d.cts +1 -1
  53. package/dist/types/adapters/memory/index.d.ts +1 -1
  54. package/dist/types/adapters/node/index.d.cts +94 -36
  55. package/dist/types/adapters/node/index.d.ts +94 -36
  56. package/dist/types/chunks/{context-D_A7-uau.d.cts → context-CF1YF2S8.d.cts} +48 -2
  57. package/dist/types/chunks/{context-CNtbFlwI.d.ts → context-sIhhtk2u.d.ts} +48 -2
  58. package/dist/types/chunks/{index-E_KapqW9.d.ts → index-B5Dps3fg.d.ts} +32 -3
  59. package/dist/types/chunks/{index-BJDekgCP.d.ts → index-B_A8VLaf.d.ts} +111 -12
  60. package/dist/types/chunks/{index-wwZiot4c.d.cts → index-Dfh8cvEs.d.cts} +32 -3
  61. package/dist/types/chunks/{index-CMLLVz9B.d.cts → index-Dqxddhav.d.cts} +111 -12
  62. package/dist/types/chunks/{progress-hcn9r2H3.d.ts → progress-BjAKfkam.d.ts} +51 -5
  63. package/dist/types/chunks/{progress-Cp-huK45.d.cts → progress-Ldnfb8st.d.cts} +51 -5
  64. package/dist/types/chunks/{reflog-entry-BGJr9VfU.d.cts → reflog-entry-Cqh3QrPH.d.ts} +12 -3
  65. package/dist/types/chunks/{reflog-entry-DecZqJna.d.ts → reflog-entry-Dy-O27Dd.d.cts} +12 -3
  66. package/dist/types/chunks/{repository-Dxhwpzd6.d.ts → repository-D8QBTkEz.d.ts} +5 -5
  67. package/dist/types/chunks/{repository-DASBgOb9.d.cts → repository-D9YrVhcH.d.cts} +5 -5
  68. package/dist/types/commands/index.d.cts +3 -3
  69. package/dist/types/commands/index.d.ts +3 -3
  70. package/dist/types/index.browser.d.cts +6 -6
  71. package/dist/types/index.browser.d.ts +6 -6
  72. package/dist/types/index.d.cts +8 -8
  73. package/dist/types/index.d.ts +8 -8
  74. package/dist/types/index.default.d.cts +6 -6
  75. package/dist/types/index.default.d.ts +6 -6
  76. package/dist/types/index.node.d.cts +6 -6
  77. package/dist/types/index.node.d.ts +6 -6
  78. package/dist/types/primitives/index.d.cts +3 -3
  79. package/dist/types/primitives/index.d.ts +3 -3
  80. package/package.json +90 -24
  81. package/dist/cjs/adapters/browser/index.cjs.map +0 -1
  82. package/dist/cjs/adapters/memory/index.cjs.map +0 -1
  83. package/dist/cjs/adapters/node/index.cjs.map +0 -1
  84. package/dist/cjs/chunks/adapter-detect-D7DFJtuk.cjs.map +0 -1
  85. package/dist/cjs/chunks/adler32-CrRRuL2P.cjs +0 -2
  86. package/dist/cjs/chunks/adler32-CrRRuL2P.cjs.map +0 -1
  87. package/dist/cjs/chunks/browser-http-transport-nGm6alox.cjs +0 -2
  88. package/dist/cjs/chunks/browser-http-transport-nGm6alox.cjs.map +0 -1
  89. package/dist/cjs/chunks/context-BcoAzPuU.cjs.map +0 -1
  90. package/dist/cjs/chunks/error-CA80UqXF.cjs +0 -2
  91. package/dist/cjs/chunks/error-CA80UqXF.cjs.map +0 -1
  92. package/dist/cjs/chunks/index-01WCH0eg.cjs +0 -2
  93. package/dist/cjs/chunks/index-01WCH0eg.cjs.map +0 -1
  94. package/dist/cjs/chunks/lru-cache-1OU7JhD8.cjs.map +0 -1
  95. package/dist/cjs/chunks/memory-http-transport-7hpDW8o3.cjs +0 -2
  96. package/dist/cjs/chunks/memory-http-transport-7hpDW8o3.cjs.map +0 -1
  97. package/dist/cjs/chunks/node-http-transport-CoqnAvIL.cjs +0 -2
  98. package/dist/cjs/chunks/node-http-transport-CoqnAvIL.cjs.map +0 -1
  99. package/dist/cjs/chunks/progress-CjhUeyxd.cjs.map +0 -1
  100. package/dist/cjs/chunks/readable-stream-MTA6D0Zh.cjs.map +0 -1
  101. package/dist/cjs/chunks/repository-DJNNrfQr.cjs.map +0 -1
  102. package/dist/cjs/chunks/write-sparse-checkout-DzVubBcI.cjs +0 -2
  103. package/dist/cjs/chunks/write-sparse-checkout-DzVubBcI.cjs.map +0 -1
  104. package/dist/cjs/commands/index.cjs.map +0 -1
  105. package/dist/cjs/index.browser.cjs.map +0 -1
  106. package/dist/cjs/index.cjs.map +0 -1
  107. package/dist/cjs/index.default.cjs.map +0 -1
  108. package/dist/cjs/index.node.cjs.map +0 -1
  109. package/dist/cjs/operators/index.cjs.map +0 -1
  110. package/dist/cjs/primitives/index.cjs.map +0 -1
  111. package/dist/cjs/transport/index.cjs.map +0 -1
  112. package/dist/esm/adapters/browser/index.js.map +0 -1
  113. package/dist/esm/adapters/memory/index.js.map +0 -1
  114. package/dist/esm/adapters/node/index.js.map +0 -1
  115. package/dist/esm/chunks/adapter-detect-CTTG6hpk.js.map +0 -1
  116. package/dist/esm/chunks/adler32-BfvKJOAO.js +0 -2
  117. package/dist/esm/chunks/adler32-BfvKJOAO.js.map +0 -1
  118. package/dist/esm/chunks/browser-http-transport-DD0YKmIW.js +0 -2
  119. package/dist/esm/chunks/browser-http-transport-DD0YKmIW.js.map +0 -1
  120. package/dist/esm/chunks/context-CumKOV7K.js.map +0 -1
  121. package/dist/esm/chunks/error-BD0nFV6t.js +0 -2
  122. package/dist/esm/chunks/error-BD0nFV6t.js.map +0 -1
  123. package/dist/esm/chunks/index-BEI7XKaV.js +0 -2
  124. package/dist/esm/chunks/index-BEI7XKaV.js.map +0 -1
  125. package/dist/esm/chunks/lru-cache-Cy7C7Lx2.js.map +0 -1
  126. package/dist/esm/chunks/memory-http-transport-D13LBPvu.js +0 -2
  127. package/dist/esm/chunks/memory-http-transport-D13LBPvu.js.map +0 -1
  128. package/dist/esm/chunks/node-http-transport-doU9Y8WN.js +0 -2
  129. package/dist/esm/chunks/node-http-transport-doU9Y8WN.js.map +0 -1
  130. package/dist/esm/chunks/progress-CLPpgZJ6.js.map +0 -1
  131. package/dist/esm/chunks/readable-stream-CGuf8k1J.js.map +0 -1
  132. package/dist/esm/chunks/repository-dCH3DdLQ.js +0 -2
  133. package/dist/esm/chunks/repository-dCH3DdLQ.js.map +0 -1
  134. package/dist/esm/chunks/write-sparse-checkout-D4tNUXOp.js +0 -2
  135. package/dist/esm/chunks/write-sparse-checkout-D4tNUXOp.js.map +0 -1
  136. package/dist/esm/commands/index.js.map +0 -1
  137. package/dist/esm/index.browser.js.map +0 -1
  138. package/dist/esm/index.default.js.map +0 -1
  139. package/dist/esm/index.js.map +0 -1
  140. package/dist/esm/index.node.js.map +0 -1
  141. package/dist/esm/operators/index.js.map +0 -1
  142. package/dist/esm/primitives/index.js.map +0 -1
  143. package/dist/esm/transport/index.js.map +0 -1
@@ -1,2 +0,0 @@
1
- import{T as t,P as e,F as a,Q as n,R as r,S as i,u as o,z as s,U as c,V as d,k as u,W as f,N as l,o as h,X as w,Y as m,Z as p,_ as g,$ as y,a0 as v,a1 as b,a2 as k,a3 as $,a4 as x,a5 as I,a6 as E,a7 as T,a8 as D,a9 as M,aa as S,ab as A,ac as O,ad as H,ae as C,E as N,af as P,ag as R,ah as U,J as L,ai as _,aj as j,ak as W,al as B,am as z,an as F,ao as q,ap as G,aq as V,ar as K,as as Y,at as X,au as J,av as Z,aw as Q,ax as tt,ay as et,az as at,aA as nt,aB as rt,aC as it,aD as ot,aE as st,aF as ct,aG as dt,aH as ut,aI as ft,aJ as lt,s as ht,aK as wt,aL as mt,aM as pt}from"./error-BD0nFV6t.js";import{C as gt,D as yt,M as vt,E as bt,G as kt,S as $t,H as xt,I as It,J as Et,K as Tt,L as Dt,N as Mt,P as St,Q as At,T as Ot,U as Ht,V as Ct,a as Nt,W as Pt,X as Rt,Y as Ut,Z as Lt,O as _t,_ as jt,$ as Wt,a0 as Bt,a1 as zt,a2 as Ft,R as qt,a3 as Gt,b as Vt,u as Kt,a4 as Yt,r as Xt,a5 as Jt,p as Zt,a6 as Qt,j as te,a7 as ee,a8 as ae,w as ne,a9 as re,l as ie,aa as oe,ab as se,ac as ce,ad as de,ae as ue,af as fe,ag as le,ah as he,t as we,g as me,h as pe,ai as ge,aj as ye,ak as ve,al as be,e as ke,d as $e,F as xe,am as Ie,an as Ee,z as Te,ao as De,ap as Me,aq as Se,ar as Ae,as as Oe,at as He,o as Ce,au as Ne,av as Pe,aw as Re,f as Ue,ax as Le,ay as _e,az as je,v as We,aA as Be,aB as ze,aC as Fe,aD as qe,B as Ge,aE as Ve,aF as Ke,aG as Ye,aH as Xe,aI as Je,aJ as Ze,aK as Qe,aL as ta,aM as ea,aN as aa,aO as na,s as ra,aP as ia,aQ as oa,aR as sa,A as ca,aS as da,aT as ua,aU as fa,aV as la,aW as ha,aX as wa,aY as ma,aZ as pa,a_ as ga,a$ as ya,q as va,k as ba,b0 as ka,b1 as $a,b2 as xa,b3 as Ia,b4 as Ea,b5 as Ta,b6 as Da,b7 as Ma,b8 as Sa,b9 as Aa,ba as Oa,bb as Ha,bc as Ca,bd as Na,be as Pa,bf as Ra,bg as Ua,bh as La,bi as _a,bj as ja,bk as Wa,bl as Ba,bm as za,bn as Fa,bo as qa,bp as Ga,bq as Va,br as Ka,bs as Ya,bt as Xa,bu as Ja,bv as Za,bw as Qa,bx as tn,by as en,bz as an,bA as nn,bB as rn,bC as on,bD as sn,bE as cn,bF as dn,bG as un,bH as fn,bI as ln,bJ as hn,bK as wn,bL as mn,bM as pn,bN as gn,bO as yn,bP as vn,bQ as bn,bR as kn,bS as $n,bT as xn,bU as In,bV as En,x as Tn,bW as Dn,bX as Mn,m as Sn,bY as An,bZ as On,b_ as Hn,b$ as Cn,c0 as Nn,c1 as Pn,n as Rn,c2 as Un,c3 as Ln,c4 as _n,c5 as jn,c6 as Wn,c7 as Bn}from"./write-sparse-checkout-D4tNUXOp.js";import{withRetry as zn,withAuth as Fn,withLogging as qn}from"../transport/index.js";import{r as Gn}from"./readable-stream-CGuf8k1J.js";const Vn=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"},Kn=e=>new t({code:"INVALID_DIFF_INPUT",reason:e}),Yn=/[ \t\v\f\r]+$/,Xn=t=>{const e=t.indexOf("\n");return-1===e?t:t.slice(0,e)},Jn=t=>{const e=[];for(const a of t.split("\n")){const t=a.replace(Yn,"");if(""!==t)e.push(t);else if(e.length>0)break}return e.join(" ")};function Zn(t,e,a){return void 0!==e&&void 0!==a?function(t,e,a){if(e.id!==a.id||e.mode!==a.mode)return bt(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 Qn(e,a){!function(e){if(void 0!==e&&e.entries.size>vt)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=Zn(t,n.get(t),a?.entries.get(t));void 0!==e&&i.push(e)}return{changes:gt(i,kt)}}function tr(t,e){const a=e.flags.stage;return 1===a?{...t,stage1:e}:2===a?{...t,stage2:e}:{...t,stage3:e}}function er(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 ar(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 nr(t){return t.flatMap(t=>ar(t)).sort(yt)}function rr(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:{...$t,stage:t.stage},path:t.path}}function ir(t,e){const a=new Set;for(const e of t)for(const t of ar(e)){if(a.has(t))throw Kn("duplicate conflict path");a.add(t)}const n=[];for(const a of t)for(const t of er(a))n.push(rr(t,e));return n.sort((t,e)=>{const a=yt(t.path,e.path);return 0!==a?a:t.flags.stage-e.flags.stage}),n}const or="0000000",sr={old:"a/",new:"b/"},cr="\",dr=(t,e)=>void 0===e?Et(t):"binary"===e,ur=new TextDecoder("utf-8",{fatal:!1});function fr(t,e){for(let a=0;a<e.length;a++){const n=e.charCodeAt(a);if(10===n||13===n||0===n)throw Kn(`${t} contains control character (code ${n}) at index ${a}`)}}function lr(t,e){if(fr("pathPrefix.old",e.old),fr("pathPrefix.new",e.new),"rename"===t.type||"copy"===t.type)return fr("oldPath",t.oldPath),void fr("newPath",t.newPath);"add"!==t.type?"delete"!==t.type?fr("path",t.path):fr("oldPath",t.oldPath):fr("newPath",t.newPath)}function hr(t){return void 0===t||0===t.length?{lines:[],hasTrailingNewline:!0}:{lines:xt(t).map(wr),hasTrailingNewline:10===t[t.length-1]}}function wr(t){return ur.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 pr(t,e,a){return`diff --git ${a.old}${t} ${a.new}${e}`}function gr(t,e,a,n){return`@@ -${1===e?`${t}`:`${t},${e}`} +${1===n?`${a}`:`${a},${n}`} @@`}function yr(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 vr(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 br(t){return"context"===t?" ":"delete"===t?"-":"+"}function kr(t){const e=[];for(const a of t)e.push(`${br(a.kind)}${a.text}`),a.trailingNoNewline&&e.push(cr);return e}function $r(t,e,a){const n=hr(e),r=[];if(r.push(pr(t.newPath,t.newPath,a)),r.push(`new file mode ${t.newMode}`),r.push(`index ${or}..${mr(t.newId)}`),r.push("--- /dev/null"),r.push(`+++ ${a.new}${t.newPath}`),0===n.lines.length)return r;r.push(gr(0,0,1,n.lines.length));for(const t of n.lines)r.push(`+${t}`);return n.hasTrailingNewline||r.push(cr),r}function xr(t,e,a){const n=hr(e),r=[];if(r.push(pr(t.oldPath,t.oldPath,a)),r.push(`deleted file mode ${t.oldMode}`),r.push(`index ${mr(t.oldId)}..${or}`),r.push(`--- ${a.old}${t.oldPath}`),r.push("+++ /dev/null"),0===n.lines.length)return r;r.push(gr(1,n.lines.length,0,0));for(const t of n.lines)r.push(`-${t}`);return n.hasTrailingNewline||r.push(cr),r}function Ir(t){return{path:t.path,oldId:t.oldId,newId:t.newId,oldMode:t.oldMode,newMode:t.newMode}}function Er(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 Tr(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 Dr(t,e,a,n){const r=hr(t),i=hr(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:vr(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=It(a,n,void 0!==r?.lineKey?{lineKey:r.lineKey}:void 0),o=[];for(const a of i.hunks)for(const n of yr(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||!Mt(n,a)})}(o,i,r.lineKey??St)}(r.lines,i.lines,t,e,n),a,{oldTotal:r.lines.length,newTotal:i.lines.length,oldHasTrailingNewline:r.hasTrailingNewline,newHasTrailingNewline:i.hasTrailingNewline})}function Mr(t,e,a,n,r,i){const o=Dr(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(gr(t.oldStart,t.oldLen,t.newStart,t.newLen));for(const e of kr(t.body))s.push(e)}return s}function Sr(t,e,a,n,r,i){const o=[];if(o.push(pr(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 ${Tt(t.similarity.score)}%`),o.push(`${e} from ${t.oldPath}`),o.push(`${e} to ${t.newPath}`),t.similarity.score===Dt)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)),dr(e,o)||dr(a,o))return s.push(`Binary files ${n.old}${t.oldPath} and ${n.new}${t.newPath} differ`),s;const c=Dr(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(gr(t.oldStart,t.oldLen,t.newStart,t.newLen));for(const e of kr(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 Ar(t,e){return[pr(t.newPath,t.newPath,e),`new file mode ${t.newMode}`,`index ${or}..${mr(t.newId)}`,`Binary files /dev/null and ${e.new}${t.newPath} differ`]}function Or(t,e){return[pr(t.oldPath,t.oldPath,e),`deleted file mode ${t.oldMode}`,`index ${mr(t.oldId)}..${or}`,`Binary files ${e.old}${t.oldPath} and /dev/null differ`]}function Hr(t,e,a,n){const r=t.change,i=t.patchBinaryOverride;if("add"===r.type){const a=t.newContent??new Uint8Array(0);return dr(a,i)?Ar(r,e):$r(r,t.newContent,e)}if("delete"===r.type){const a=t.oldContent??new Uint8Array(0);return dr(a,i)?Or(r,e):xr(r,t.oldContent,e)}return"rename"===r.type?function(t,e,a,n,r){return Sr(t,"rename",e,a,n,r)}(r,t,e,a,n):"copy"===r.type?function(t,e,a,n,r){return Sr(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[...dr(e,r)?Or(i,n):xr(i,e,n),...dr(a,r)?Ar(o,n):$r(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=Ir(t),d=[];d.push(pr(c.path,c.path,n)),d.push(`dissimilarity index ${Tt(s.score)}%`);const u=`index ${mr(c.oldId)}..${mr(c.newId)}`;d.push(c.oldMode===c.newMode?`${u} ${c.newMode}`:u);const f=dr(e,o)||dr(a,o)?Tr(c,n,e,a):Mr(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&&!dr(a,o)&&!dr(n,o)){const o=Mr(t,e,a,n,r,i);if(0===o.length)return[];const s=[];s.push(pr(t.path,t.path,e));for(const e of Er(t))s.push(e);for(const t of o)s.push(t);return s}const s=[];s.push(pr(t.path,t.path,e));for(const e of Er(t))s.push(e);if(t.oldId===t.newId)return s;for(const r of Tr(t,e,a,n))s.push(r);return s}(Ir(t),n,e,a,r,i,o)}(r,t.oldContent??new Uint8Array(0),t.newContent??new Uint8Array(0),e,a,n,i)}function Cr(t,e){const a=function(t){if(void 0===t)return 3;if(!Number.isInteger(t)||t<0)throw Kn(`contextLines must be a non-negative integer; got ${t}`);return t}(e?.contextLines);if(0===t.length)return"";const n=e?.pathPrefix??sr;for(const e of t)lr(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=Hr(e,n,a,r);for(const e of t)i.push(e)}return 0===i.length?"":(i.push(""),i.join("\n"))}const Nr=t=>{const e=t.startsWith("!"),a=e?t.slice(1):t;return At(a)?{pattern:t,body:a,negated:e,isLiteral:!1,compiled:Ot(a,{anchored:a.includes("/")})}:{pattern:t,body:a,negated:e,isLiteral:!0,compiled:Ot(a,{anchored:!0,withDirSuffix:!0})}},Pr=(t,e)=>{let a=!1;for(const n of t)n.compiled.test(e)&&(a=!n.negated);return a},Rr=e=>new t({code:"INVALID_MERGE_TREE",reason:e}),Ur=e=>new t({code:"INVALID_MERGE_INPUT",reason:e}),Lr=268435456,_r=new TextEncoder;function jr(t){let e=0;for(const a of t)e+=a.length;return e}function Wr(t){if(0===t.length)return new Uint8Array(0);const e=jr(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 Br(t,e,a={}){if("diff3"===a.conflictStyle)throw Ur("diff3 conflict style requires base lines — not supported in v1");const n=a.labels?.ours??"ours",r=a.labels?.theirs??"theirs";if(jr(t)+jr(e)>Lr)throw Ur("conflict output exceeds MAX_CONFLICT_OUTPUT_BYTES");const i=a.markerSize??7,o=_r.encode(`${"<".repeat(i)} ${n}\n`),s=_r.encode(`${"=".repeat(i)}\n`),c=_r.encode(`${">".repeat(i)} ${r}\n`),d=Wr(t),u=Wr(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 zr="HEAD",Fr=t=>t.slice(0,7),qr=(t,e)=>`${Fr(t)} (${e})`,Gr=t=>`parent of ${t}`,Vr=(t,e)=>{const a=qr(t,e);return{ours:zr,theirs:a,base:Gr(a)}},Kr=(t,e)=>{const a=qr(t,e);return{ours:zr,theirs:Gr(a),base:a}},Yr={ours:"Updated upstream",theirs:"Stashed changes",base:"Stash base"},Xr={ours:"ours",theirs:"theirs",base:""};function Jr(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 Zr(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 Qr(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 ti(t,e){const a=Math.min(t.length,e.length);let n=0;for(;n<a&&Ht(t[n],e[n]);)n++;let r=0;for(;r<a-n&&Ht(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 ei(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(!Ht(t[a],e[a]))return!1;return!0}(e.replacement,a.replacement)?"clean-twin":"conflict"}function ai(t){return{kind:"clean",start:t.start,end:t.end,replacement:t.ours.length>0?t.ours[0].replacement:t.theirs[0].replacement}}function ni(t){return t.length>0&&10===t[t.length-1]}function ri(t){let e=0;for(let a=0;a<t.length;a++)e+=t[a].length,a<t.length-1&&!ni(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&&!ni(r)&&(a[n]=10,n+=1)}return a}function ii(t,e,a,n){const r=It(t,e),i=It(t,a),o=r.degraded||i.degraded?[{kind:"conflict",ours:xt(e),theirs:xt(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(ai(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&&Zr(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:ei(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=ti(Qr(t,e.start,e.end,e.ours),Qr(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,Jr(r.hunks,r.theirsLines),Jr(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:ri(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(Br(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 oi=new Uint8Array(0);function si(t,e){return t.id===e.id&&t.mode===e.mode}function ci(t){return t===Nt.GITLINK}function di(t,e){if(void 0!==t&&t.entries.size>vt)throw Rr(`${e} FlatTree exceeds MAX_FLAT_TREE_ENTRIES`)}function ui(t){return{status:"conflict",conflict:t}}function fi(t,e,a,n){return ui({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 li(t,e,a,n){return ui({type:"type-change",path:t,baseId:e.id,ourId:a.id,theirId:n.id,baseMode:e.mode,ourMode:a.mode,theirMode:n.mode})}function hi(t,e,a,n){return void 0===e?{status:"resolved-known",path:t,id:a.id,mode:a.mode}:si(e,a)?{status:"resolved-deleted",path:t}:"our"===n?fi(t,e,a,void 0):fi(t,e,void 0,a)}function wi(t){return"file"===Ct(t)}function mi(t){return t===Nt.SYMLINK}function pi(t,e,a,n,r,i){const o=wi(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 ui({type:"distinct-types",path:t,ourId:e.id,ourMode:e.mode,theirId:a.id,theirMode:a.mode,ourPath:c,theirPath:d});const u=wi(i.mode)?s:t;return ui({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 gi(t,e){if(t.length>Lr)throw Ur(`contentMerger returned oversize ${e}`)}async function yi(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,oi,oi);return"clean"===i.status?(gi(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}):(gi(i.markedBytes,"marked bytes"),{tag:"conflict",bytes:i.markedBytes,conflictType:i.conflictType})}function vi(t,e,a,n,r,i,o){return void 0===a&&void 0===n?{status:"resolved-deleted",path:t}:void 0===a?hi(t,e,n,"their"):void 0===n?hi(t,e,a,"our"):void 0===e?async function(t,e,a,n,r,i){if(si(e,a))return{status:"resolved-known",path:t,id:e.id,mode:e.mode};const o=wi(e.mode),s=wi(a.mode),c=mi(e.mode),d=mi(a.mode);if(o&&d||c&&s)return pi(t,e,a,r,i);if(!o||!s)return function(t,e,a){return ui({type:"add-add",path:t,ourId:e.id,theirId:a.id,ourMode:e.mode,theirMode:a.mode})}(t,e,a);const u=await yi(t,e,a,n);return"resolved"===u.tag?u.outcome:ui({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=si(e,a),c=si(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||si(a,n)?{status:"resolved-known",path:t,id:a.id,mode:a.mode}:function(t,e,a,n,r,i,o){if(ci(a.mode)||ci(n.mode))return ci(a.mode)&&ci(n.mode)&&ci(e.mode)?function(t,e,a,n){return ui({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):li(t,e,a,n);const s=mi(a.mode),c=mi(n.mode);if(s&&c)return function(t,e,a,n){return ui({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 ci(e.mode)?li(t,e,a,n):pi(t,a,n,i,o,e);if(!bt(e.mode,a.mode))return async function(t,e,a,n,r){const i=await yi(t,a,n,r);return"resolved"===i.tag?i.outcome:ui("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,oi,oi);return"clean"===s.status?(gi(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}):(gi(s.markedBytes,"marked bytes"),ui({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 bi(t,e,a,n,r=Xr){di(t,"base"),di(e,"ours"),di(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>vt)throw Rr("union FlatTree exceeds MAX_FLAT_TREE_ENTRIES");return n}(t,e,a),o=gt([...i],t=>t),s=new Set(i),c=[];for(const i of o){const o=vi(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 ki="blob:limit=",$i="tree:",xi=/^(\d+)([kmg])?$/i,Ii=/^\d+$/,Ei=t=>{if(""===t)throw Pt(t,"empty");if("blob:none"===t)return{kind:"blob-none"};if(t.startsWith(ki))return(t=>{const e=t.slice(11).match(xi);if(null===e)throw Pt(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 Pt(t,"bad-blob-limit");return{kind:"blob-limit",bytes:a}})(t);if(t.startsWith($i))return(t=>{const e=t.slice(5);if(!Ii.test(e))throw Pt(t,"bad-tree-depth");const a=Number(e);if(!Number.isSafeInteger(a))throw Pt(t,"bad-tree-depth");return{kind:"tree-depth",depth:a}})(t);throw Pt(t,"unknown-kind")},Ti=t=>{switch(t.kind){case"blob-none":return"blob:none";case"blob-limit":return`${ki}${t.bytes}`;case"tree-depth":return`${$i}${t.depth}`}},Di=new TextDecoder("utf-8",{fatal:!1}),Mi=new TextEncoder,Si=t=>t.endsWith("\n")?t.slice(0,-1):t,Ai=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 Lt(t);return{name:e.slice(0,a),accepted:!1,reason:e.slice(a+1)}}throw Lt(t)},Oi=async t=>{const e=await(async t=>{const e=[];for await(const a of t){if("data"!==a.kind)return e;e.push(Si(Di.decode(a.payload)))}return e})(t);if(0===e.length)throw Lt("");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 Lt(t)})(a);return r.ok?{unpackOk:!0,refUpdates:n.map(Ai)}:{unpackOk:!1,unpackError:r.error,refUpdates:[]}},Hi={second:1,minute:60,hour:3600,day:86400,week:604800,month:2592e3,year:31536e3},Ci=/^(\d{4})-(\d{2})-(\d{2})(?: (\d{2}):(\d{2}):(\d{2}))?$/,Ni=/^(\d+)[ .]([a-z]+?)s?(?:[ .]ago)?$/;function Pi(t,e){const a=t.trim().toLowerCase();return"now"===a?e:"yesterday"===a?e-86400:function(t){const e=Ci.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:Ri[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=Ni.exec(t);if(null===a)return;const[,n,r]=a,i=Hi[r];return void 0===i?void 0:e-Number(n)*i}(a,e)}const Ri=[31,28,31,30,31,30,31,31,30,31,30,31],Ui=t=>[t,`refs/${t}`,`refs/tags/${t}`,`refs/heads/${t}`,`refs/remotes/${t}`,`refs/remotes/${t}/HEAD`],Li=t=>`${t.layout.gitDir}/MERGE_HEAD`,_i=t=>`${t.layout.gitDir}/MERGE_MSG`,ji=t=>`${t.layout.gitDir}/ORIG_HEAD`,Wi=async(t,e)=>{await t.fs.writeUtf8(_i(t),e)},Bi=async(t,e)=>{await t.fs.writeUtf8(ji(t),`${e}\n`)},zi=async t=>{const e=Li(t);if(!await t.fs.exists(e))return;const a=(await t.fs.readUtf8(e)).trim();return 0!==a.length?_t.from(a):void 0},Fi=async t=>{const e=_i(t);if(await t.fs.exists(e))return t.fs.readUtf8(e)},qi=async t=>{for(const e of[Li(t),_i(t)])await t.fs.exists(e)&&await t.fs.rm(e)},Gi=async t=>{const e=_i(t);await t.fs.exists(e)&&await t.fs.rm(e)},Vi=qt.from("HEAD"),Ki=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},Yi=["excludesfile","attributesfile"],Xi=async t=>{const e=await Ki(t);return await(async t=>{const[e,i]=await Promise.all([Bt(t,"core",void 0,Yi),zt(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},Ji=async(e,a)=>{if(await(async t=>{const e=await Ft(t);return e.core?.bare??!1})(e))throw(e=>new t({code:"BARE_REPOSITORY",operation:e}))(a)},Zi=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 jt(Vi);throw e}const r=Wt(n);return"symbolic"===r.type?{kind:"symbolic",target:r.target}:{kind:"direct",id:r.target}},Qi=[{file:"MERGE_HEAD",operation:"merge"},{file:"CHERRY_PICK_HEAD",operation:"cherry-pick"},{file:"REVERT_HEAD",operation:"revert"},{file:"REBASE_HEAD",operation:"rebase"}],to=async(t,a={})=>{const n=a.except,r=t=>Array.isArray(n)?n.includes(t):n===t,i=await Promise.all(Qi.map(e=>t.fs.exists(`${t.layout.gitDir}/${e.file}`)));for(let t=0;t<Qi.length;t+=1){const a=Qi[t];if(void 0!==a&&!r(a.operation)&&!0===i[t])throw e(a.operation)}},eo=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},ao=(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}`}},no=async(t,e)=>{const a=await Gt(t),n=await Vt(t,e);if("commit"!==n.type)throw Kt("commit",n.type,e);const r=await Yt(t);try{const e=await Xt(t),i=await Jt(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()}},ro=async t=>{if(await Xi(t),await Ji(t,"merge --abort"),void 0===await zi(t))throw i("merge");const e=await(async t=>{const e=ji(t);if(!await t.fs.exists(e))return;const a=(await t.fs.readUtf8(e)).trim();return 0!==a.length?_t.from(a):void 0})(t);if(void 0===e)throw i("merge");const a=await Zi(t);if("symbolic"!==a.kind)throw o("merge --abort","cannot abort with detached HEAD");return await no(t,e),await Zt(t,a.target,e,{reflogMessage:"reset: moving to HEAD"}),await qi(t),{origHead:e,branch:a.target}},io=(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:$t,path:n}),oo=Qt,so=(t,e)=>te(t.layout.workDir,e),co=async(t,e)=>{const a=oo(e),n=so(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)},uo=async(t,e,a)=>{const n=oo(e),r=oo(a);await fo(t,so(t,n),so(t,r))},fo=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 fo(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)},lo=new TextEncoder,ho=t=>{for(const e of t){const t=e.startsWith("!")?e.slice(1):e;oo(t),wo(e)}const e=(t=>t.map(Nr))(t),a=e.filter(go).map(t=>vo(t)),n=e.some(yo);return{matcher:e,literalMustMatch:a,hasGlob:n}},wo=t=>{if(lo.encode(t).byteLength>256)throw u("paths","pattern exceeds max length 256 bytes");if(mo(t)>4)throw u("paths","pattern exceeds max **-token count 4")},mo=t=>{let e=0,a=0;for(;a<t.length;)"*"!==t[a]||"*"!==t[a+1]?a+=1:(e+=1,a+=2);return e},po=(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)},go=t=>!t.negated&&t.isLiteral,yo=t=>!t.negated&&!t.isLiteral,vo=t=>t.body,bo=new Set(["FILE_NOT_FOUND","INVALID_INDEX_HEADER","INVALID_INDEX_ENTRY"]),ko=async(t,e,a={})=>{await Xi(t),await Ji(t,"add"),await to(t,{except:["merge","cherry-pick","revert","rebase"]});const n=await ee(t);if(!0===a.all){if(0!==e.length)throw u("all","pathspec must be empty when all=true");return To(t,void 0,n)}if(0===e.length)throw f();return $o(t,e,n)},$o=async(t,e,a)=>{const{matcher:n,literalMustMatch:r,hasGlob:i}=ho(e);return!i&&await Io(t,r)?xo(t,r,a):Eo(t,n,r,a)},xo=async(t,e,a)=>{const n=await Yt(t);try{const r=await Ao(t),i=new Map(r),o=[],s=[];for(const n of e){const e=await Oo(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()}},Io=async(t,e)=>{if(0===e.length)return!1;for(const a of e){const e=await t.fs.lstat(te(t.layout.workDir,a)).catch(()=>{});if(void 0===e)return!1;if(e.isDirectory&&!e.isSymbolicLink)return!1}return!0},Eo=async(t,e,a,n)=>{const r=await ae(t),i=async(t,a)=>!!await r(t,a)||!a&&!Pr(e,t),o=await Yt(t);try{const e=await Ao(t),r=new Map(e),s=[],c=[],d=[],u=new Set;for await(const a of ne(t,{ignore:i})){const i=await So(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 po(a,s),c.sort(),d.sort(),await o.commit(Array.from(r.values())),{added:c,modified:d,removed:[]}}finally{await o.release()}},To=async(t,e,a)=>{const n=await ae(t),r=await Yt(t);try{const e=await Ao(t),i=new Map(e),o=new Set,s=[],c=[];for await(const r of ne(t,{ignore:n})){const n=await So(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 Do(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()}},Do=async(t,e,a)=>{const n=[];for(const[r,i]of t)e.has(r)||i.flags.skipWorktree||await Mo(r,a)||n.push(r);return n},Mo=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},So=async(t,e,a,n,r)=>{const{path:i,stat:o}=e;if(n.add(i),o.size>re)throw l(i,o.size,re);const s=await Ho(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}},Ao=async e=>{try{const t=await Xt(e),a=new Map;for(const e of t.entries)a.set(e.path,e);return a}catch(e){if(e instanceof t&&bo.has(e.data.code))return new Map;throw e}},Oo=async(t,e,a)=>{const n=await t.fs.lstat(te(t.layout.workDir,e)).catch(()=>{});return void 0===n?"missing":Ho(t,e,n,a)},Ho=async(t,e,a,n)=>{const r=await t.fs.lstat(te(t.layout.workDir,e));if(r.isSymbolicLink!==a.isSymbolicLink||r.isDirectory!==a.isDirectory||r.isFile!==a.isFile)throw h();if(r.size>re)throw l(e,r.size,re);const i=ce(r),o=await No(t,e,r),s=await Co(t,e,o,r.isSymbolicLink,n),c=await ie(t,{type:"blob",id:"",content:s});return io(r,i,c,e)},Co=async(t,e,a,n,r)=>{if(void 0===r||void 0===t.command||n)return a;const i=await oe(t,r,e);if("external"!==i.kind||void 0===i.clean)return a;const o=await se(t,t.command,i.clean,a);if(o.ok)return o.bytes;if(i.required)throw w(e,i.name,o.exitCode);return a},No=async(t,e,a)=>{if(a.isSymbolicLink){const a=(new TextEncoder).encode(await t.fs.readlink(te(t.layout.workDir,e)));if(a.byteLength>re)throw l(e,a.byteLength,re);return a}return(async(t,e)=>{const a=oo(e);return t.fs.read(so(t,a))})(t,e)},Po=async(t,e,a)=>{let n=e;for(let e=0;e<5;e+=1){const e=await Vt(t,n);if(e.type===a)return n;if("tag"!==e.type){if("tree"===a&&"commit"===e.type)return e.data.tree;throw de(n)}n=e.data.object}throw de(n)},Ro=async(t,e,a,n)=>{const r=a.split("/"),i=r.length-1;let o=e;for(let e=0;e<i;e+=1){const i=Uo(o,r[e],n,a),s=await Vt(t,i.id);if("tree"!==s.type)throw m(n,a);o=s}return Uo(o,r[i],n,a)},Uo=(t,e,a,n)=>{const r=t.entries.find(t=>t.name===e);if(void 0===r)throw m(a,n);return r},Lo=/^[0-9a-f]{40}$/,_o=/^[0-9a-f]{4,39}$/,jo=/^[0-9a-f]{38}$/,Wo=async(t,e)=>{const a=ue(fe(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&&jo.test(i.name)&&i.name.startsWith(n)&&r.push(e.slice(0,2)+i.name);return r},Bo=async(t,e)=>{const a=await le(t).all(),n=[];for(const t of a)for(const a of he(t.index,e))n.push(a);return n},zo=async(t,e)=>{if(Lo.test(e))return e;if(!_o.test(e))return;const[a,n]=await Promise.all([Wo(t,e),Bo(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))}},Fo=new Set(["commit","tree","blob","tag"]),qo=/^:(\d):(.+)$/,Go=/^[0-9a-f]{1,3}$/,Vo=t=>{throw g(t)},Ko=t=>{if(""===t&&Vo(t),t.startsWith(":"))return Xo(t);const e=Yo(t);return-1!==e?{kind:"tree-path",rev:t.slice(0,e),path:t.slice(e+1)}:t.includes("@{")?Qo(t):Jo(t)},Yo=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},Xo=t=>{const e=qo.exec(t);null===e&&Vo(t);const a=e[2],n=Number(e[1]);return n>3&&Vo(t),{kind:"index-stage",stage:n,path:a}},Jo=t=>{const e=ts(t),a=-1===e?t:t.slice(0,e);return""===a&&Vo(t),Go.test(a)&&-1===e&&Vo(t),{kind:"ref-or-hex",base:a,operations:-1===e?[]:es(t,e)}},Zo=/^\d+$/,Qo=t=>{const e=t.indexOf("@{"),a=t.indexOf("}",e+2),n=t.slice(0,e),r=t.slice(e+2,a);return""===r&&Vo(t),{kind:"ref-or-hex",base:n,reflog:Zo.test(r)?{kind:"index",n:Number(r)}:{kind:"date",raw:r},operations:es(t.slice(a+1),0)}},ts=t=>{for(let e=0;e<t.length;e+=1){const a=t[e];if("~"===a||"^"===a)return e}return-1},es=(t,e)=>{const a=[];let n=e;for(;n<t.length;){const e=t[n];if("~"===e){const e=as(t,n);a.push(e.op),n=e.next}else if("^"===e){const e=ns(t,n);a.push(e.op),n=e.next}else Vo(t)}return a},as=(t,e)=>{let a=e+1;for(;a<t.length&&rs(t.charCodeAt(a));)a+=1;return a===e+1&&Vo(t),{op:{kind:"ancestor",n:Number(t.slice(e+1,a))},next:a}},ns=(t,e)=>{if("{"===t[e+1]){const a=t.indexOf("}",e+2);-1===a&&Vo(t);const n=t.slice(e+2,a);return Fo.has(n)||Vo(t),{op:{kind:"peel",target:n},next:a+1}}let a=e+1;for(;a<t.length&&rs(t.charCodeAt(a));)a+=1;const n=t.slice(e+1,a);return{op:{kind:"parent",n:""===n?1:Number(n)},next:a}},rs=t=>t>=48&&t<=57,is=async(t,e)=>{await Xi(t);const a=Ko(e);return os(t,a,e)},os=async(t,e,a)=>{if("index-stage"===e.kind)return gs(t,e);if("tree-path"===e.kind)return ys(t,e.rev,e.path);const n=Math.floor(Date.now()/1e3);let r=void 0!==e.reflog?await cs(t,e.base,e.reflog,n,a):await ss(t,e.base);for(const a of e.operations)r=await ms(t,r,a);return r},ss=async(t,e)=>{if(/^[0-9a-f]{40}$/.test(e))return _t.from(e);for(const a of Ui(e))try{return await pe(t,a)}catch{}const a=await zo(t,e);if(void 0!==a)return a;throw de(e)},cs=async(t,e,a,n,r)=>{const i=""===e?await ds(t):await us(t,e),o=await me(t,i);if(0===o.length)throw g(r);return"index"===a.kind?hs(o,a.n,i):ws(o,a.raw,n,r)},ds=async t=>{const e=await ge(t).resolveDirect("HEAD");return"symbolic"===e.kind?e.target:"HEAD"},us=async(t,e)=>{const a=fs(e),n=Ui(a);for(const e of n)if(await ye(t,e))return e;for(const e of n)if(await ls(t,e))return e;return a},fs=t=>{try{return be(t)}catch{throw g(t)}},ls=async(t,e)=>{try{return await pe(t,e),!0}catch{return!1}},hs=(t,e,a)=>{const n=t[t.length-1-e];if(void 0===n)throw ve(a,e,t.length);return n.newId},ws=(t,e,a,n)=>{const r=Pi(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},ms=async(t,e,a)=>{if("parent"===a.kind)return ps(t,e,a.n);if("ancestor"===a.kind){let n=e;for(let e=0;e<a.n;e+=1)n=await ps(t,n,1);return n}return Po(t,e,a.target)},ps=async(t,e,a)=>{const n=await Vt(t,e);if("commit"!==n.type)throw de(e);const r=n.data.parents[a-1];if(void 0===r)throw de(e);return r},gs=async(t,e)=>{const a=await Xt(t);for(const t of a.entries)if(t.path===e.path&&t.flags.stage===e.stage)return t.id;throw de(`${e.stage}:${e.path}`)},ys=async(t,e,a)=>{const n=await os(t,Ko(e),e),r=await Po(t,n,"tree");if(""===a)return r;const i=await we(t,r);return(await Ro(t,i,a,e)).id};async function vs(t,e){await Ki(t);const a=await is(t,e.treeish),n=await async function(t,e){const a=await Vt(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 Po(t,e,"commit"),n=await Vt(t,a);if("commit"!==n.type)throw Kt("commit",n.type,a);return{tree:n.data.tree,commit:a,commitTime:n.data.committer.timestamp}}if("tree"===a.type)return{tree:e};throw Kt("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:bs(t,r)}}return{tree:r,entries:bs(t,r)}}async function*bs(t,e){for await(const a of ke(t,e,{maxEntries:Number.MAX_SAFE_INTEGER,maxDepth:Number.MAX_SAFE_INTEGER})){const{path:e,id:n,mode:r}=a;if(r===Nt.DIRECTORY||r===Nt.GITLINK)yield{path:e,mode:r,oid:n};else{const a=await $e(t,n);yield{path:e,mode:r,oid:n,content:a.content}}}}const ks=(t,e)=>{const a=$s(e),n=[],r=[];for(const e of t)xs(e,a,n,r);return{passed:n,kept:r}},$s=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},xs=(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}}},Is=async(t,e)=>{if(/^[0-9a-f]{40}$/.test(e))return e;for(const a of Ui(e))try{return await pe(t,a,{peel:!0})}catch{}const a=await zo(t,e);if(void 0!==a)return a;throw jt(e)},Es=async(t,e)=>{const a=await Vt(t,e);if("commit"!==a.type)throw Kt("commit",a.type,e);return a.data},Ts=async(t,e)=>(await Es(t,e)).tree,Ds=async(t,e)=>{const a=await Zi(t);if("symbolic"!==a.kind)throw o(e,"cannot run with detached HEAD");return a.target},Ms=new TextEncoder,Ss="HEAD",As=async(t,e,a={})=>{await Xi(t);const n=xe.from(e),r={ctx:t,queue:[],finalized:[]};if(!0===a.worktree){if(void 0!==a.rev)throw u("worktree","cannot combine with a revision");await Os(r,n)}else{const e=a.rev??Ss;await Ps(r,await Is(t,e),n,e)}await Rs(r);const i=[...r.finalized].sort((t,e)=>t.finalLine-e.finalLine);return{path:n,lines:Ns(i,a.range)}},Os=async(t,e)=>{Qt(e);const a=await Is(t.ctx,Ss),n=await Es(t.ctx,a),r=await Hs(t.ctx,e),i=xt(r).length;if(0===i)return;const o=[{finalStart:0,count:i,sourceStart:0}],s=await Fs(t.ctx,n.tree,e);if(void 0!==s){const{passed:i,kept:c}=ks(o,It(s,r));return zs(t,a,e,n.committer.timestamp,s,i),void Cs(t,e,r,c,{commit:a,path:e})}if(!(await Xt(t.ctx)).entries.some(t=>t.path===e))throw m(Ss,e);Cs(t,e,r,o,void 0)},Hs=async(t,e)=>{const a=te(t.layout.workDir,e),n=await t.fs.lstat(a).catch(()=>{});if(void 0===n)throw y(e);return n.isSymbolicLink?Ms.encode(await t.fs.readlink(a)):t.fs.read(a)},Cs=(t,e,a,n,r)=>{const i=xt(a);for(const a of n)for(const n of js(a.count))t.finalized.push({committed:!1,..._s(a,n,i,e,r)})},Ns=(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)},Ps=async(t,e,a,n)=>{const r=await Es(t.ctx,e),i=await Fs(t.ctx,r.tree,a);if(void 0===i)throw m(n,a);const o=xt(i).length;0!==o&&zs(t,e,a,r.committer.timestamp,i,[{finalStart:0,count:o,sourceStart:0}])},Rs=async t=>{for(;t.queue.length>0;){const{value:e}=t.queue.shift();await Us(t,e)}},Us=async(t,e)=>{const a=await Es(t.ctx,e.commit),n=xt(e.blob);let r,i=e.entries;for(const n of a.parents){const o=await Ws(t.ctx,n,a.tree,e.path);if(void 0===o)continue;r??={commit:n,path:o.sourcePath};const{passed:s,kept:c}=ks(i,It(o.blob,e.blob));zs(t,n,o.sourcePath,o.date,o.blob,s),i=c}Ls(t,e,a,n,i,r)},Ls=(t,e,a,n,r,i)=>{const o=0===a.parents.length,s=Xn(a.message);for(const c of r)for(const r of js(c.count))t.finalized.push({committed:!0,commit:e.commit,author:a.author,committer:a.committer,summary:s,boundary:o,..._s(c,r,n,e.path,i)})},_s=(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]}),js=t=>Array.from({length:t},(t,e)=>e),Ws=async(t,e,a,n)=>{const r=await Es(t,e),i=r.committer.timestamp,o=await Fs(t,r.tree,n);if(void 0!==o)return{blob:o,sourcePath:n,date:i};const s=await Bs(t,r.tree,a,n);return void 0!==s?{blob:(await $e(t,s.blobId)).content,sourcePath:s.sourcePath,date:i}:void 0},Bs=async(t,e,a,n)=>{const r=await Te(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}},zs=(t,e,a,n,r,i)=>{0!==i.length&&Ee(t.queue,{oid:e,date:n,value:{commit:e,path:a,blob:r,entries:i}})},Fs=async(t,e,a)=>{const n=(await Ie(t,e)).entries.get(a);if(void 0!==n)return(await $e(t,n.id)).content},qs=new TextEncoder,Gs=async(t,e,a)=>{const n=be(e),r=be(a),i=Se(t.layout.gitDir,n),o=qs.encode(De(r));await Me(t,n,i,o)},Vs="refs/heads/",Ks=async t=>{await Xi(t);const e=`${t.layout.gitDir}/refs/heads`;if(!await t.fs.exists(e))return{branches:[]};const a=await Zi(t),n="symbolic"===a.kind&&a.target.startsWith(Vs)?a.target:void 0,r=await t.fs.readdir(e),i=[];for(const e of r){if(!e.isFile)continue;const a=`${Vs}${e.name}`,r=await pe(t,a);i.push({name:a,id:r,current:a===n})}return i.sort((t,e)=>Ys(t.name,e.name)),{branches:i}},Ys=(t,e)=>t<e?-1:t>e?1:0,Xs=async(e,a)=>{await Xi(e);const n=be(`${Vs}${a.name}`),r=a.startPoint??"HEAD",i=await Qs(e,r),o=`branch: Created from ${r}`;try{await Zt(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}},Js=async(t,e)=>{await Xi(t);const a=be(`${Vs}${e.name}`),n=await Zi(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 Zt(t,a,Oe,{delete:!0}),{name:a}},Zs=async(e,a)=>{await Xi(e);const n=be(`${Vs}${a.from}`),r=be(`${Vs}${a.to}`),i=await pe(e,n),o=`branch: renamed ${n} to ${r}`,s=await me(e,n);try{await Zt(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 Ae(e,r,[...s,...await me(e,r)]),await Zt(e,n,Oe,{delete:!0});const c=await Zi(e);return"symbolic"===c.kind&&c.target===n&&await Gs(e,"HEAD",r),{from:n,to:r}},Qs=async(t,e)=>{if(/^[0-9a-f]{40}$/.test(e))return e;const a="HEAD"===e?["HEAD"]:[`${Vs}${e}`,e];for(const e of a)try{return await pe(t,e)}catch{}throw k(e)},tc="# v2 git bundle",ec="# v3 git bundle",ac=/^[0-9a-f]{40}$/,nc=t=>ac.test(t),rc=(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(!nc(r))throw x(e,"malformed-header");return{oid:_t.from(r),comment:i}},ic=(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(!nc(n))throw x(e,"malformed-header");return{oid:_t.from(n),name:qt.from(r)}},oc=(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]===ec)throw $(e,3);if(!n.startsWith(tc)&&!n.startsWith(ec))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===ec)throw $(e,3);if(t!==tc)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(rc(t,a));else{if(t.startsWith("@"))throw x(a,"malformed-header");d.push(ic(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}},sc=t=>`-${t.oid} ${t.comment}\n`,cc=t=>`${t.oid} ${t.name}\n`,dc=async(t,e,a,n,r=0)=>{if(n.has(e))return;if(n.add(e),r>1024)throw Pe(r);if(t.signal?.aborted)throw h();a.add(e);const i=await Vt(t,e);if("tree"===i.type)for(const e of i.entries)Re(e.mode)||(Ue(e.mode)?await dc(t,e.id,a,n,r+1):a.add(e.id))},uc=async(t,e,a,n,r,i=0)=>{if(r.has(e))return;if(r.add(e),i>1024)throw Pe(i);if(t.signal?.aborted)throw h();a.has(e)||Ne(n,e);const o=await Vt(t,e);if("tree"===o.type)for(const e of o.entries)Re(e.mode)||(Ue(e.mode)?await uc(t,e.id,a,n,r,i+1):a.has(e.id)||Ne(n,e.id))},fc=["refs/","refs/tags/","refs/heads/","refs/remotes/"],lc=(t,e)=>{const a=e;if(a.includes(t))return t;for(const e of fc){const n=`${e}${t}`;if(a.includes(n))return n}},hc=async(t,e,a)=>{const n=await pe(t,e);a.refs.push({name:e,oid:n}),a.wants.push(n)},wc=(t,e)=>e.filter(e=>e.startsWith(t)).sort(),mc=async(t,e,a,n)=>{const r=await is(t,e),i=lc(e,a);void 0!==i&&n.refs.push({name:i,oid:r}),n.wants.push(r)},pc=async(t,e,a)=>{const n=await is(t,e);a.haves.push(await Po(t,n,"commit"))},gc=async(t,e,a,n)=>{const[r,i]=e,o=await is(t,r);n.haves.push(await Po(t,o,"commit"));const s=await is(t,i),c=lc(i,a);void 0!==c&&n.refs.push({name:c,oid:s}),n.wants.push(s)},yc=async(t,e,a,n)=>{const[r,i]=e,o=await is(t,r),s=lc(r,a);void 0!==s&&n.refs.push({name:s,oid:o}),n.wants.push(o);const c=await is(t,i),d=lc(i,a);void 0!==d&&n.refs.push({name:d,oid:c}),n.wants.push(c);const u=await We(t,[await Po(t,o,"commit"),await Po(t,c,"commit")],{all:!0});n.haves.push(...u)},vc=async(t,e)=>{await Ki(t);const a=await _e(t),n={refs:[],wants:[],haves:[]};await(async(t,e,a,n)=>{if(!0===e.branches)for(const e of wc("refs/heads/",a))await hc(t,e,n);if(!0===e.tags)for(const e of wc("refs/tags/",a))await hc(t,e,n);if(!0===e.all){for(const e of wc("refs/",a))await hc(t,e,n);await hc(t,"HEAD",n)}})(t,e,a,n),await(async(t,e,a,n)=>{for(const r of e)"tip"in r?await mc(t,r.tip,a,n):"exclude"in r?await pc(t,r.exclude,n):"range"in r?await gc(t,r.range,a,n):await yc(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??Le},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 Ce(t,{from:e,ignoreMissing:!0}))n.add(i.id),r.add(i.id),await dc(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 He(t,n,t=>{Ne(a,t)}));return await(async(t,e,a,n,r)=>{for await(const i of Ce(t,{from:e,until:[...a.commits],ignoreMissing:!0})){Ne(n,i.id),await uc(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 Vt(t,e),e);return{oid:e,comment:Jn(a.data.message)}})))(t,i.boundary),s=await je(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(sc(t));for(const e of t.refs)n.push(cc(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}},bc=async(t,e)=>{const a=await kc(t,e),n=oc(a,e);return{header:n,packBytes:a.subarray(n.packOffset)}},kc=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 $c(e,a);throw n}},$c=async(t,e)=>{try{if((await t.fs.stat(e)).isDirectory)return x(e,"not-a-bundle")}catch{}return T(e)},xc=async(t,e)=>{const{header:a}=await bc(t,e.path),n=Ic(a.refs,e.names);return{version:a.version,refs:n}},Ic=(t,e)=>{if(void 0===e)return t;const a=new Set(e);return t.filter(t=>a.has(t.name))},Ec=async(t,e)=>{const{header:a,packBytes:n}=await bc(t,e.path),r=await Mc(t,a.prerequisites);if(r.length>0)return Tc(a,r);await Be(n,t);const i=a.prerequisites.length>0?Dc(t):void 0;return await ze(t,n,i),Tc(a,[])},Tc=(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}),Dc=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 Vt(e,a),n=Fe(t,e.hashConfig),{contentOffset:r}=qe(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}},Mc=async(t,e)=>{const a=[];for(const n of e)await Sc(t,n.oid)&&a.push(n.oid);return a},Sc=async(e,a)=>{try{return await Vt(e,a),!1}catch(e){if(e instanceof t&&"OBJECT_NOT_FOUND"===e.data.code)return!0;throw e}},Ac=t=>"string"==typeof t?_t.from(t):t,Oc=async(t,e)=>{await Xi(t);const a=e.ids.map(Ac),n=void 0===e.maxBytes?void 0:{maxBytes:e.maxBytes},r=[];for await(const e of Ge(t,a,n))r.push(e);return{kind:"batch",entries:r}},Hc="refs/heads/",Cc="checkout:materialize",Nc=async(t,e)=>{if("HEAD"===e){const e=await pe(t,"HEAD");return(await we(t,e)).id}return(await we(t,e)).id},Pc=async(t,e)=>{await Xi(t),await Ji(t,"checkout"),await to(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(Cc);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}=ho(e.paths),i=(await(async(t,e)=>{if("index"===e)return(await Xt(t)).entries.map(t=>t.path);const a=await Nc(t,e),n=[];for await(const e of ke(t,a))e.mode!==Nt.DIRECTORY&&n.push(e.path);return n})(t,a)).filter(t=>Pr(n,t));po(r,i);const o=new Set(i);if(0===o.size)return{branch:void 0,id:await pe(t,"HEAD"),detached:!1,changedPaths:0};const s="index"===a?await(async(t,e)=>{const a=await Xt(t),n=await Ye(t,a.entries);return Jt(t,{targetTree:n,currentIndex:a,force:!0,forceRewriteAll:!0,paths:e})})(t,o):await(async(t,e,a)=>{const n=await Yt(t);try{const r=await Xt(t),i=await Jt(t,{targetTree:e,currentIndex:r,force:!0,forceRewriteAll:!0,paths:a});return await n.commit(i.newIndexEntries),i}finally{await n.release()}})(t,await Nc(t,a),o),c=await pe(t,"HEAD");return await Ve(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 Zi(t),r=await pe(t,"HEAD");let i,o;if(a)o=await(async(t,e)=>/^[0-9a-f]{40}$/.test(e)?e:pe(t,e))(t,e.rev);else{if(i=be(`${Hc}${e.rev}`),!await t.fs.exists(`${t.layout.gitDir}/${i}`))throw k(i);o=await pe(t,i)}const s=await we(t,o),c=await Gt(t),d=await Yt(t);let u;try{const a=await Xt(t);u=await Jt(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(Hc))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 Ke(t,"HEAD",r,o,`checkout: moving from ${f} to ${o.slice(0,7)}`)):(await Gs(t,"HEAD",i),await Ke(t,"HEAD",r,o,`checkout: moving from ${f} to ${e.rev}`)),await Ve(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(Cc)}},Rc={kind:"text"},Uc={kind:"union"},Lc={kind:"binary"},_c=(t,e)=>!1===e?Promise.resolve(Lc):!0===e||"unspecified"===e?Promise.resolve(Rc):(async(t,e)=>{if("text"===e)return Rc;if("binary"===e)return Lc;if("union"===e)return Uc;const a=(await Ft(t)).merge?.get(e);return void 0===a?.driver?Rc:void 0===a.name?{kind:"external",command:a.driver}:{kind:"external",command:a.driver,name:a.name}})(t,e.set),jc=new Uint8Array(0),Wc=(t,e=Xr)=>{let n,r;return async i=>{await(r??=Je(t,"merge",["driver","name"]).then(t=>{if(void 0!==t)throw a(t.key,t.source,t.line)}));const[o,s,c]=await Promise.all([$e(t,i.ourId,{maxBytes:Lr}),$e(t,i.theirId,{maxBytes:Lr}),void 0!==i.baseId?$e(t,i.baseId,{maxBytes:Lr}):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 _c(t,Xe(n,a,"merge",r)),markerSize:eo(Xe(n,a,"conflict-marker-size",r))}})(t,await(n??=Ze(t)),i.path);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??jc),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+=ao(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 Et(e)||Et(a)||void 0!==t&&Et(t)?{status:"conflict",conflictType:"binary",markedBytes:e}:void 0===t?Ht(e,a)?{status:"clean",bytes:e}:ii(new Uint8Array(0),e,a,n):Ht(e,t)?{status:"clean",bytes:a}:Ht(a,t)||Ht(e,a)?{status:"clean",bytes:e}:ii(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}})}},Bc=(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)},zc=(t,e,a)=>{const n=new Set;for(const e of t)"conflict"!==e.status&&Bc(e,a)&&n.add(e.path);for(const t of e)for(const e of ar(t))n.add(e);return n},Fc=async(t,e)=>{try{return await t.fs.lstat(te(t.layout.workDir,e)),!0}catch{return!1}},qc=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 ee(t),i=[],o=[];for(const a of e){const e=n.get(a);void 0!==e?Qe(await ta(t,e,r))&&i.push(a):await Fc(t,a)&&o.push(a)}return{localChanges:[...i].sort(yt),untracked:[...o].sort(yt)}},Gc=t=>({ctimeSeconds:0,ctimeNanoseconds:0,mtimeSeconds:0,mtimeNanoseconds:0,dev:0,ino:0,mode:t,uid:0,gid:0,fileSize:0}),Vc=(t,e,a)=>({...Gc(a),id:e,flags:$t,path:t}),Kc=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 $e(t,r,{maxBytes:Lr});await ea(t,a,e.content,i)}if(void 0!==n&&void 0!==o&&void 0!==s){const e=await $e(t,o,{maxBytes:Lr});await ea(t,n,e.content,s)}},Yc=new Set(["rename-rename","gitlink"]),Xc=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 ie(t,{type:"blob",content:n.bytes,id:""});a.push(Vc(n.path,e,n.mode));continue}a.push(Vc(n.path,n.id,n.mode))}return Ye(t,a)},Jc=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 $e(t,a,{maxBytes:Lr})).content:void 0}return void 0!==e.ourId?(await $e(t,e.ourId,{maxBytes:Lr})).content:void 0})(t,e);void 0!==n&&await ea(t,e.path,n,a)},Zc=(t,e)=>{const a=[];for(const e of t)"unchanged"!==e.status&&"resolved-known"!==e.status||a.push(Vc(e.path,e.id,e.mode));const n=[...a,...ir(e,Gc)];return n.sort((t,e)=>t.path<e.path?-1:t.path>e.path?1:t.flags.stage-e.flags.stage),n},Qc=async(t,e)=>{const[a,n,r]=await Promise.all([void 0!==e.baseTree?Ie(t,e.baseTree):Promise.resolve(void 0),Ie(t,e.oursTree),Ie(t,e.theirsTree)]),i=await bi(a,n,r,Wc(t,e.labels),e.labels);i.cleanMerge||(t=>{for(const e of t)if(Yc.has(e.type))throw o("apply-merge",`conflict type '${e.type}' not supported (path=${e.path})`)})(i.conflicts);const s=zc(i.outcomes,i.conflicts,n.entries),c=await qc(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 Xc(t,i.outcomes);return{kind:"clean",mergedTree:a,result:await Jt(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 ra(t,a.id);await ia(t,a.path,e)}}else await na(t,a.path,a.bytes);else await aa(t,a.path);for(const e of a)"distinct-types"!==e.type?await Jc(t,e):await Kc(t,e)})(t,i.outcomes,i.conflicts,s),{kind:"conflict",conflicts:i.conflicts,indexEntries:Zc(i.outcomes,i.conflicts)}},td=/^(pick|revert) (\S+) (.*)$/,ed=async(t,e)=>{if(!await t.fs.exists(e))return;const a=(await t.fs.readUtf8(e)).trim();return 0!==a.length?_t.from(a):void 0},ad=t=>`${t.layout.gitDir}/sequencer`,nd=t=>`${ad(t)}/head`,rd=t=>`${ad(t)}/todo`,id=t=>`${ad(t)}/opts`,od=(t,e)=>t.fs.writeUtf8(nd(t),`${e}\n`),sd=t=>ed(t,nd(t)),cd=(t,e)=>t.fs.writeUtf8((t=>`${ad(t)}/abort-safety`)(t),`${e}\n`),dd=(t,e)=>t.fs.writeUtf8(rd(t),(t=>t.map(t=>`${t.command} ${t.oid} ${t.subject}\n`).join(""))(e)),ud=async t=>{const e=rd(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=td.exec(a);if(null===t)throw D(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 zo(t,e.oid);if(void 0===a)throw D(`cannot resolve commit ${e.oid}`);n.push({command:e.command,oid:a,subject:e.subject})}return n},fd=async(t,e)=>{(e.noCommit||e.recordOrigin||e.allowEmpty)&&await t.fs.writeUtf8(id(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))},ld=(t,e)=>t.some(t=>"options"===t.section.toLowerCase()&&t.entries.some(t=>t.key.toLowerCase()===e&&null!==t.value&&"true"===t.value.toLowerCase())),hd=async t=>{const e=ad(t);await t.fs.exists(e)&&await t.fs.rmRecursive(e)},wd=async(t,e)=>{await no(t,e.target),await Zt(t,e.branch,e.target,{reflogMessage:`reset: moving to ${e.target}`}),await e.clearHead(t),await Gi(t),await hd(t)},md=t=>`${t.layout.gitDir}/CHERRY_PICK_HEAD`,pd=t=>ed(t,md(t)),gd=async t=>{const e=md(t);await t.fs.exists(e)&&await t.fs.rm(e)},yd=(t,e)=>`${t.replace(/\s+$/,"")}\n\n# Conflicts:\n${e.map(t=>`#\t${t}\n`).join("")}`,vd=async(t,e,a)=>{const n=await Ie(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},bd=async(t,e)=>{const a=await ee(t),n=[];for(const r of e)r.flags.skipWorktree||"unchanged"!==await ta(t,r,a)&&n.push(r.path);return n},kd=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 Xt(t)).entries),r=new Set([...n,...await vd(t,a,e),...await bd(t,a)]);if(r.size>0)throw M({localChanges:[...r].sort(yt),untracked:[]})},$d=t=>{if(void 0!==t.explicit)return t.explicit;if(void 0!==t.configUser)return t.configUser;throw S()},xd=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 S()},Id=(t,e)=>{const a=(t=>{const e=[];for(const a of t.split("\n")){const t=a.replace(Yn,"");(""!==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`})(t);if(""===a&&!e.allowEmpty)throw A();return a},Ed=t=>t.split("\n").filter(t=>!t.startsWith("#")).join("\n"),Td=async t=>{const e=(await Ft(t)).user;void 0===e&&await sa(t,"user",void 0,["name","email"]);const a=void 0!==e?{name:e.name,email:e.email,timestamp:Math.floor(Date.now()/1e3),timezoneOffset:"+0000"}:void 0;return xd(void 0!==a?{configUser:a}:{})},Dd=t=>t.parents.length>=2,Md=t=>t.map(t=>({path:t.path,type:t.type})),Sd=/^(.+)\.\.(.+)$/,Ad=async(t,e,a)=>{const n=new Set;for await(const a of Ce(t,{from:[e]}))n.add(a.id);const r=[];for await(const e of Ce(t,{from:[a],until:[...n]}))r.push(e.id);return r.reverse()},Od=async(t,e,a,n,r)=>{await od(t,e.sequenceHead),await dd(t,await(async(t,e)=>{const a=[];for(const n of e){const e=await Es(t,n);a.push({command:"pick",oid:n,subject:Xn(e.message)})}return a})(t,a)),await cd(t,n),await fd(t,{recordOrigin:r.recordOrigin,allowEmpty:r.allowEmpty,noCommit:!1})},Hd=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 Es(t,c);if(Dd(d))throw i.multiPick&&await Od(t,i,e.slice(n),o,r),O(c);const u=await Nd(t,c,d,a,o,r);if("committed"===u.kind){s.push({source:c,created:u.id}),o=u.id;continue}await Pd(t,c,d,"conflict"===u.kind?u.conflicts:void 0,r),i.multiPick&&await Od(t,i,e.slice(n),o,r);const f=e.length-(n+1);return"conflict"===u.kind?{kind:"conflict",commit:c,conflicts:Md(u.conflicts),remaining:f}:{kind:"empty",commit:c,remaining:f}}return await hd(t),{kind:"picked",commits:s}},Cd=(t,e,a)=>a?((t,e)=>`${t.replace(/\s+$/,"")}\n\n(cherry picked from commit ${e})`)(t,e):t,Nd=async(t,e,a,n,r,i)=>{const o=a.parents[0],s=void 0!==o?await Ts(t,o):void 0,c=await Ts(t,r),d=await Yt(t);try{const o=await Xt(t),u=await Qc(t,{baseTree:s,oursTree:c,theirsTree:a.tree,currentIndex:o,labels:Vr(e,Xn(a.message))});if("would-overwrite"===u.kind)throw M({localChanges:u.localChanges,untracked:u.untracked});if("conflict"===u.kind)return await d.commit(u.indexEntries),{kind:"conflict",conflicts:u.conflicts};if(u.mergedTree===c&&!i.allowEmpty)return{kind:"empty"};await d.commit(u.result.newIndexEntries);const f=await(async(t,e,a,n,r,i)=>{const o=await Td(t);return ca(t,{tree:r,parents:[n],author:a.author,committer:o,message:Id(Cd(a.message,e,i.recordOrigin),{allowEmpty:!1}),extraHeaders:[]})})(t,e,a,r,u.mergedTree,i);return await Zt(t,n,f,{expected:r,reflogMessage:`cherry-pick: ${Xn(a.message)}`}),{kind:"committed",id:f}}finally{await d.release()}},Pd=async(t,e,a,n,r)=>{await(async(t,e)=>{await t.fs.writeUtf8(md(t),`${e}\n`)})(t,e);const i=Cd(a.message,e,r.recordOrigin),o=void 0!==n&&n.length>0?yd(i,nr(n)):i;await Wi(t,o)},Rd=async(e,a)=>{await Xi(e),await Ji(e,"cherry-pick"),await to(e);const n=await Zi(e);if("symbolic"!==n.kind)throw o("cherry-pick","cannot cherry-pick with detached HEAD");const r=await(async(e,a)=>{try{return await pe(e,a)}catch(e){if(e instanceof t&&"REF_NOT_FOUND"===e.data.code)throw H();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=Sd.exec(n);if(null===e){a.push(await Is(t,n));continue}const r=await is(t,e[1]),i=await is(t,e[2]);a.push(...await Ad(t,r,i))}return a})(e,a.commits);return await kd(e,await Ts(e,r)),!0===a.noCommit?(async(t,e)=>{const a=await Yt(t);try{let n=await Xt(t);for(let r=0;r<e.length;r+=1){const i=e[r],o=await Es(t,i);if(Dd(o))throw O(i);const s=o.parents[0],c=void 0!==s?await Ts(t,s):void 0,d=await Ye(t,n.entries),u=await Qc(t,{baseTree:c,oursTree:d,theirsTree:o.tree,currentIndex:n,labels:Vr(i,Xn(o.message))});if("would-overwrite"===u.kind)throw M({localChanges:u.localChanges,untracked:u.untracked});if("conflict"===u.kind)return await a.commit(u.indexEntries),{kind:"conflict",commit:i,conflicts:Md(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):Hd(e,i,n.target,r,{recordOrigin:a.recordOrigin??!1,allowEmpty:a.allowEmpty??!1},{multiPick:i.length>1,sequenceHead:r})},Ud=async(t,e)=>{if(void 0!==await sd(t)){const e=await(async t=>{const e=id(t);if(!await t.fs.exists(e))return{recordOrigin:!1,allowEmpty:!1,noCommit:!1};const a=oa(await t.fs.readUtf8(e),e);return{noCommit:ld(a,"no-commit"),recordOrigin:ld(a,"record-origin"),allowEmpty:ld(a,"allow-empty")}})(t);return{recordOrigin:e.recordOrigin,allowEmpty:e.allowEmpty}}return{recordOrigin:!1,allowEmpty:e.allowEmpty??!1}},Ld=async(t,e={})=>{await Xi(t),await Ji(t,"cherry-pick --continue");const a=await pd(t),n=await ud(t);if(void 0===a&&(void 0===n||0===n.length))throw i("cherry-pick");const r=await Zi(t);if("symbolic"!==r.kind)throw o("cherry-pick --continue","cannot continue with detached HEAD");const s=await Ud(t,e);let c=await pe(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 Xt(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 Ye(t,i.entries);if(o===await Ts(t,n)&&!r.allowEmpty)return{empty:!0};const s=await(async(t,e,a,n,r)=>{const i=await Es(t,e),o=await Td(t),s=Id(Ed(await Fi(t)??""),{allowEmpty:!1}),c=await ca(t,{tree:r,parents:[a],author:i.author,committer:o,message:s,extraHeaders:[]});return await Zt(t,n,c,{expected:a,reflogMessage:`commit (cherry-pick): ${Xn(s)}`}),c})(t,e,n,a,o);return await gd(t),await Gi(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 hd(t),{kind:"picked",commits:d};const f=await sd(t)??c,l=await Hd(t,u,r.target,c,s,{multiPick:!0,sequenceHead:f});return"picked"===l.kind?{kind:"picked",commits:[...d,...l.commits]}:l},_d=async(t,e={})=>{await Xi(t),await Ji(t,"cherry-pick --skip");const a=await pd(t),n=await ud(t);if(void 0===a&&(void 0===n||0===n.length))throw i("cherry-pick");const r=await Ds(t,"cherry-pick --skip"),o=await pe(t,r),s=await Ud(t,e);await no(t,o),await gd(t),await Gi(t);const c=(n??[]).slice(1).map(t=>t.oid);if(0===c.length)return await hd(t),{kind:"picked",commits:[]};const d=await sd(t)??o;return Hd(t,c,r,o,s,{multiPick:!0,sequenceHead:d})},jd=async t=>{await Xi(t),await Ji(t,"cherry-pick --abort");const e=await pd(t),a=await sd(t);if(void 0===e&&void 0===a)throw i("cherry-pick");const n=await Ds(t,"cherry-pick --abort"),r=a??await pe(t,n);return await wd(t,{branch:n,target:r,clearHead:gd}),{head:r,branch:n}},Wd=async(t,e)=>{const a=be(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}},Bd={attempts:3,backoff:"exponential",baseMs:250,maxDelayMs:5e3},zd=(t,e={})=>{const a=void 0!==e.logger?Fd(e.logger):void 0;let n=t.transport;return n=zn(e.retry??Bd)(n),void 0!==e.auth&&(n=Fn(e.auth)(n)),void 0!==a&&(n=qn({logger:a})(n)),n},Fd=t=>({log:e=>t.log(qd(e))}),qd=t=>"request"===t.kind||"response"===t.kind?{...t,url:Vd(t.url),headers:Gd(t.headers)}:{...t,url:Vd(t.url),errorMessage:Vd(t.errorMessage)},Gd=t=>{const e={};for(const[a,n]of Object.entries(t))e[a]=Vd(n);return e},Vd=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},Kd={"git-upload-pack":"application/x-git-upload-pack-advertisement","git-receive-pack":"application/x-git-receive-pack-advertisement"},Yd=async(t,e,a,n)=>{const r=da(a,n),i=await e.request({url:r,method:"GET",headers:{accept:Kd[n]},...void 0!==t.signal?{signal:t.signal}:{}});if(200!==i.statusCode)throw N(i.statusCode,`${n} discovery returned ${i.statusCode}`);const o=fa(Gn(i.body));return ua(o,n)},Xd=async(t,e,a)=>Yd(t,e,a,"git-upload-pack"),Jd=t=>{const e=wa.filter(t=>"multi_ack_detailed"!==t&&"thin-pack"!==t&&"no-progress"!==t&&t!==ha);return[...la(t,e),ha]},Zd=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},Qd=t=>t.includes("filter"),tu="clone:discover",eu=async(t,e)=>{if(await t.fs.exists(`${t.layout.gitDir}/HEAD`))throw P(t.layout.workDir);if(""===e.url)throw R();const a=void 0!==e.filter?Ti(Ei(e.filter)):void 0;t.progress.start(tu);try{const n=await Wd(t,{initialBranch:e.initialBranch??"main",bare:e.bare??!1});try{return await au(t,e,n.gitDir,a)}catch(e){throw await t.fs.rmRecursive(t.layout.gitDir).catch(()=>{}),e}}finally{t.progress.end(tu)}},au=async(t,e,a,n)=>{const r=zd(t,{...void 0!==t.config?.auth?{auth:t.config.auth}:{}}),i=await Xd(t,r,e.url);if(0===i.refs.length)throw R();if(void 0!==n&&!Qd(i.capabilities))throw ma();const o=Jd(i.capabilities),s=Zd(i.refs),c=await pa(t,r,{wants:s,haves:[],capabilities:o,url:e.url,progressOp:"clone:write-objects",...void 0!==e.depth?{depth:e.depth}:{},...void 0!==n?{filter:n,promisor:!0}:{}});c.shallow.length>0&&await ga(t,{shallow:c.shallow,unshallow:c.unshallow});const d=await ru(t,i,e.url),u=await su(t,i,e.url);return await nu(t,e.url,ou(i),n),{path:a,head:u,fetchedRefs:d}},nu=async(t,e,a,n)=>{await ya(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"}]:[]])},ru=async(t,e,a)=>{const n=ou(e),r=[];for(const i of e.refs)if("HEAD"!==i.name){if(i.name.startsWith("refs/heads/")){const e=i.name.slice(11),o=`refs/remotes/origin/${e}`;if(await iu(t,o,i.id,a),r.push({name:o,id:i.id}),void 0!==n&&e===n){const e=i.name;await iu(t,e,i.id,a),r.push({name:e,id:i.id})}continue}if(i.name.startsWith("refs/tags/")){const e=i.name;await iu(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},iu=async(t,e,a,n)=>{const r=`${t.layout.gitDir}/${e}`;await t.fs.writeUtf8(r,`${a}\n`),await Ke(t,e,Oe,a,`clone: from ${n}`)},ou=t=>{const e=t.capabilities.find(t=>t.startsWith("symref=HEAD:refs/heads/"));if(void 0!==e)return e.slice(23)},su=async(t,e,a)=>{const n=ou(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 cu(t,r,a),e}if(void 0!==e.head)return await t.fs.writeUtf8(`${t.layout.gitDir}/HEAD`,`${e.head.id}\n`),void await cu(t,r,a)},cu=async(t,e,a)=>{void 0!==e&&await Ke(t,"HEAD",Oe,e,`clone: from ${a}`)},du=t=>`${t.layout.gitDir}/REVERT_HEAD`,uu=t=>ed(t,du(t)),fu=async t=>{const e=du(t);await t.fs.exists(e)&&await t.fs.rm(e)},lu=(t,e)=>{return`Revert ${a=Xn(t.message),`"${a.replace(/([\\"])/g,"\\$1")}"`}\n\nThis reverts commit ${e}.\n`;var a},hu=async(t,e)=>{await Xi(t),await Ji(t,"commit");const a=await mu(t),{mergeHead:n,cherryPickHead:r,revertHead:i}=a,o=pu(a);await to(t,void 0!==o?{except:o}:{});const s=e.noVerify??!1;await(async(t,e)=>{e||await va(t,"pre-commit")})(t,s);const c=void 0!==n||void 0!==r||void 0!==i,d=c?"merge":"message",u=await yu(t,e,c),f=await Ft(t),l=$u(f.user);void 0===e.author&&void 0===l&&await sa(t,"user",void 0,["name","email"]);const h=$d(xu(e.author,l)),w=xd(Iu(e.committer,h,l)),m=await Xt(t);ku(m.entries);const p=await Du(t,m.entries),g=await Zi(t),y="symbolic"===g.kind?await Eu(t,g.target):g.id,v=bu(y,n);if(!e.allowEmpty&&void 0!==y&&void 0===n&&await Tu(t,y)===p)throw U();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 va(t,"prepare-commit-msg",{args:[n,a.source]}),a.noVerify||await va(t,"commit-msg",{args:[n]});const r=await t.fs.readUtf8(n);return Id(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 ca(t,k),x="symbolic"===g.kind?g.target:void 0,I=vu(b,y,n,r);return await wu(t,{branch:x,id:$,parentId:y,reflogMessage:I}),await gu(t,a),await Ve(t,"post-commit"),{id:$,tree:p,branch:x,parents:v}},wu=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 Ke(t,"HEAD",r??Oe,n,i)):await Zt(t,a,n,void 0!==r?{expected:r,reflogMessage:i}:{reflogMessage:i})},mu=async t=>({mergeHead:await zi(t),cherryPickHead:await pd(t),revertHead:await uu(t)}),pu=t=>void 0!==t.mergeHead?"merge":void 0!==t.cherryPickHead?"cherry-pick":void 0!==t.revertHead?"revert":void 0,gu=async(t,e)=>{if(void 0===e.mergeHead)return void 0!==e.cherryPickHead?(await gd(t),void await Gi(t)):void(void 0!==e.revertHead&&(await fu(t),await Gi(t)));await qi(t)},yu=async(t,e,a)=>{if(e.message.length>0||!a)return Id(e.message,{allowEmpty:e.allowEmptyMessage??!1});const n=await Fi(t);return Id(Ed(n??""),{allowEmpty:e.allowEmptyMessage??!1})},vu=(t,e,a,n)=>{const r=Xn(t);return void 0===e?`commit (initial): ${r}`:void 0!==a?`commit (merge): ${r}`:void 0!==n?`commit (cherry-pick): ${r}`:`commit: ${r}`},bu=(t,e)=>{const a=[];return void 0!==t&&a.push(t),void 0!==e&&a.push(e),a},ku=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])},$u=t=>{if(void 0!==t)return{name:t.name,email:t.email,timestamp:Math.floor(Date.now()/1e3),timezoneOffset:"+0000"}},xu=(t,e)=>{const a={};return void 0!==t&&(a.explicit=t),void 0!==e&&(a.configUser=e),a},Iu=(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},Eu=async(t,e)=>{try{return await pe(t,e)}catch{return}},Tu=async(t,e)=>{const a=await Vt(t,e);return"commit"!==a.type?Oe:a.data.tree},Du=async(t,e)=>{const a={files:new Map,subdirs:new Map};for(const t of e)Mu(a,t.path.split("/"),t);return Su(t,a)},Mu=(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)),Mu(o,r,a)},Su=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 Su(t,a)})));for(const{name:t,id:e}of n)a.push({mode:"40000",name:t,id:e});return ba(t,a)},Au=t=>t,Ou=async(t,e)=>(await Ki(t),void 0===e.scope?await ka({ctx:t,key:e.key}):await ka({ctx:t,key:e.key,scope:e.scope})),Hu=async(t,e)=>(await Ki(t),void 0===e.scope?await $a({ctx:t,key:e.key}):await $a({ctx:t,key:e.key,scope:e.scope})),Cu=async(t,e)=>{await Ki(t);const a=void 0===e.scope?await xa({ctx:t}):await xa({ctx:t,scope:e.scope}),n=[];for(const{scope:t,section:r}of a)for(const a of r.entries){const i=Ia(r,a.key);e.keyPattern.test(i)&&(void 0===e.valuePattern||e.valuePattern.test(a.value??""))&&n.push({key:Au(i),value:a.value,scope:t})}return{entries:n}},Nu=async(t,e)=>{await Ki(t);const a=void 0===e?.scope?await xa({ctx:t}):await xa({ctx:t,scope:e.scope}),n=[];for(const{scope:t,section:e}of a)for(const a of e.entries){const r=Ia(e,a.key);n.push({key:Au(r),value:a.value,scope:t})}return{entries:n}},Pu=async(t,e)=>{await Ki(t);const a=e.scope??"local",n=await $a({ctx:t,key:e.key,scope:a});if(n.values.length>1)throw L(e.key,n.values.length,"overwrite",a);return await Da({ctx:t,key:e.key,value:e.value,scope:a}),{key:e.key,value:e.value,scope:a}},Ru=async(t,e)=>{await Ki(t);const a=e.scope??"local",n=await $a({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 L(e.key,n.values.length,"remove",a);const[r]=n.values;return await Ma({ctx:t,key:e.key,scope:a}),{key:e.key,scope:a,removed:!0,previousValue:r.value}},Uu=async(t,e)=>{await Ki(t);const a=e.scope??"local",n=await $a({ctx:t,key:e.key,scope:a});return 0===n.values.length?{key:e.key,scope:a,removed:0}:(await Sa({ctx:t,key:e.key,scope:a}),{key:e.key,scope:a,removed:n.values.length})},Lu=async(t,e)=>{await Ki(t);const a=e.scope??"local";return await Ta({ctx:t,oldName:e.oldName,newName:e.newName,scope:a}),{oldName:e.oldName,newName:e.newName,scope:a}},_u=async(t,e)=>{await Ki(t);const a=e.scope??"local";return await Ea({ctx:t,sectionName:e.name,scope:a}),{name:e.name,scope:a}},ju=async(t,e={})=>{if(await Xi(t),await Ji(t,"merge --continue"),void 0===await zi(t))throw i("merge");return hu(t,Wu(e))},Wu=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}}),Bu=(t,e)=>t.depth!==e.depth?t.depth-e.depth:t.foundOrder-e.foundOrder,zu=t=>Ot(t,{anchored:!0}),Fu=(t,e)=>e?t.startsWith("refs/")?t.slice(5):t:t.startsWith("refs/tags/")?t.slice(10):t,qu=(t,e)=>e.priority>t.priority||2===e.priority&&e.taggerDate>t.taggerDate,Gu=async(t,e)=>{let a=await Vt(t,e),n=!1,r=0;for(let e=0;"tag"===a.type;e+=1){if(Aa(e))return;n||(r=a.data.tagger?.timestamp??0),n=!0,a=await Vt(t,a.data.object)}if("commit"===a.type)return{commit:a,viaTag:n,taggerDate:r}},Vu=["candidates","exactMatch","firstParent","dirty","broken"],Ku=t=>void 0===t?[]:"string"==typeof t?[t]:t,Yu=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},Xu=(t,e)=>(t=>{const e=[...t].map(t=>"*"===t?".*":"?"===t?".":t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("");return new RegExp(`^${e}$`)})(t).test(e),Ju=t=>({...t,generation:t.generation+1,distance:t.distance+1}),Zu=(t,e)=>({...t,steps:[...Qu(t),{kind:"parent",number:e}],generation:0,distance:t.distance+65535}),Qu=t=>t.generation>0?[...t.steps,{kind:"ancestor",count:t.generation}]:t.steps,tf=t=>void 0===t?[]:"string"==typeof t?[t]:t,ef=async(t,e)=>Po(t,await is(t,e),"commit"),af=async(t,e)=>Po(t,await is(t,e),"tree"),nf=async(t,e,a={})=>{await Xi(t);const n=await ef(t,e??"HEAD"),r=(t=>({qualifies:e=>"HEAD"!==e&&!(t.tags&&!e.startsWith("refs/tags/"))&&(e=>0===t.refs.length||t.refs.some(t=>Xu(t,e)))(e)&&!(e=>t.exclude.some(t=>Xu(t,e)))(e)}))((t=>({tags:!0===t.tags,refs:tf(t.refs),exclude:tf(t.exclude)}))(a)),i=[...await _e(t)].filter(t=>r.qualifies(t)).sort(),o=new Map;for(const e of i)await rf(t,e,o);const s=o.get(n);return void 0===s?{oid:n,ref:void 0,tagDeref:!1,steps:[]}:{oid:n,ref:s.ref,tagDeref:s.tagDeref,steps:Qu(s)}},rf=async(t,e,a)=>{const n=await of(t,e,a);if(void 0===n)return;const r=[n];for(;r.length>0;){const e=r.pop(),n=a.get(e.id),i=await sf(t,e,n,a);for(let t=i.length-1;t>=0;t-=1)r.push(i[t])}},of=async(t,e,a)=>{const n=await ge(t).resolveDirect(e);if("direct"!==n.kind)return;const r=await Gu(t,n.id);if(void 0===r)return;const i={ref:e,tagDeref:r.viaTag,fromTag:e.startsWith("refs/tags/"),taggerDate:r.viaTag?r.taggerDate:r.commit.data.committer.timestamp,generation:0,distance:0,steps:[]};return cf(a,r.commit.id,i)?r.commit:void 0},sf=async(t,e,a,n)=>{const r=[],i=e.data.parents;for(let e=0;e<i.length;e+=1){const o=i[e],s=0===e?Ju(a):Zu(a,e+1);if(!cf(n,o,s))continue;const c=await Vt(t,o);"commit"===c.type&&r.push(c)}return r},cf=(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))},df="status:scan",uf=async t=>{await Xi(t);const e=await Zi(t),a="symbolic"===e.kind?e.target:void 0,n="direct"===e.kind,r=await Xt(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,tr(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(df);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,df),c=await ee(t),d=await ff(t,i.staged,e,c),u=await lf(t,s),f=await Oa(t),l=hf(r,f,i.unmerged),h=wf(l,d,f,o),w=await vf(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(df)}},ff=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 Ha(t,e,n)),a.tick()})),r},lf=async(t,e)=>{const a=await ae(t),n=[];for await(const{path:r}of ne(t,{ignore:a}))e.has(r)||n.push(r);return n.sort(yt)},hf=(t,e,a)=>{const n=new Map;for(const r of Qn(t,e).changes){const t=kt(r);a.has(t)||n.set(t,pf(r))}return n},wf=(t,e,a,n)=>{const r=new Set(t.keys());for(const[t,a]of e)void 0!==gf(a.status)&&r.add(t);return[...r].map(r=>mf(r,t.get(r),e.get(r),a,n.get(r))).sort((t,e)=>yt(t.path,e.path))},mf=(t,e,a,n,r)=>{const i=n?.entries.get(t),o=void 0===a?void 0:gf(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}}}},pf=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",gf=t=>"absent"===t?"deleted":"type-changed"===t?"type-changed":"mode-changed"===t?"mode-changed":"modified"===t?"modified":void 0,yf=t=>({id:t.id,mode:t.mode}),vf=(t,e)=>Promise.all([...e].map(async([e,a])=>{const n=await bf(t,e);return{kind:Vn(a),path:e,...a.stage1&&{base:yf(a.stage1)},...a.stage2&&{ours:yf(a.stage2)},...a.stage3&&{theirs:yf(a.stage3)},...void 0!==n&&{worktree:{mode:n}}}})),bf=async(t,e)=>{const a=await t.fs.lstat(te(t.layout.workDir,e)).catch(()=>{});return void 0===a?void 0:ce(a)},kf="refs/tags/";async function $f(t,e,a={}){if(await Xi(t),!0===a.contains)return xf(t,e,(t=>{for(const e of Vu)if(void 0!==t[e])throw u(e,`option ${e} cannot be combined with contains`);return{all:!0===t.all,include:Ku(t.match),exclude:Ku(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:Yu(t),always:!0===t.always,firstParent:!0===t.firstParent,include:Ku(t.match),exclude:Ku(t.exclude),dirty:a,broken:n}})(a,void 0!==e),r=await Is(t,e??"HEAD"),i=await Df(t,n),o=await Mf(t,n),s=If(n),c=o.get(r);if(void 0!==c&&c.priority>=s)return Ef(c.name,0,r,i,n.all);if(0===n.maxCandidates){if(n.always)return Tf(r,i);throw _(r)}const{best:d,sawUnannotated:f}=await Af(t,r,o,n,s);if(void 0!==d)return Ef(d.name,d.depth,r,i,n.all);if(n.always)return Tf(r,i);if(0===o.size)throw j(r);throw f?W(r):B(r)}const xf=async(t,e,a)=>{const n=!a.all,r=t=>n?t.map(t=>`${kf}${t}`):[],i=await nf(t,e,{tags:n,refs:r(a.include),exclude:r(a.exclude)});if(void 0===i.ref&&!a.always)throw z(i.oid);return i},If=t=>t.all?0:t.tags?1:2,Ef=(t,e,a,n,r)=>({tag:qt.from(r?`refs/${t}`:`${kf}${t}`),name:t,distance:e,oid:a,exact:0===e,dirty:n}),Tf=(t,e)=>({tag:void 0,name:"",distance:0,oid:t,exact:!1,dirty:e}),Df=async(t,e)=>{if(!e.dirty&&!e.broken)return!1;try{const e=await uf(t);return e.changes.length>0||e.unmerged.length>0}catch(t){if(e.broken)return!0;throw t}},Mf=async(t,e)=>{const a=[...await _e(t)].filter(t=>"HEAD"!==t&&(e.all||t.startsWith(kf))).sort(),n=((t,e)=>{const a=t.map(zu),n=e.map(zu);return{matches:t=>!(0!==a.length&&!a.some(e=>e.test(t))||n.some(e=>e.test(t)))}})(e.include,e.exclude),r=ge(t),i=new Map;for(const o of a){const a=await r.resolveDirect(o);if("direct"!==a.kind)continue;const s=await Gu(t,a.id);if(void 0===s)continue;const c=Fu(o,e.all);if(!n.matches(c))continue;const d=Sf(o,c,s),u=i.get(s.commit.id);(void 0===u||qu(u,d))&&i.set(s.commit.id,d)}return i},Sf=(t,e,a)=>({name:e,priority:t.startsWith(kf)?a.viaTag?2:1:0,taggerDate:a.taggerDate}),Af=async(t,e,a,n,r)=>{const i=a.size,o=new Map,s=[];let c,d=0,u=!1;for await(const f of Ca(t,{from:[e],firstParent:n.firstParent})){if(void 0!==c){Hf(o,f,c,n.firstParent);continue}if(s.length===n.maxCandidates||s.length===i){if(c=Of(s),void 0===c)break;Hf(o,f,c,n.firstParent);continue}const t=f.id;d+=1;const e=a.get(t);if(void 0!==e&&e.priority>=r){const a=s.length;s.push({name:e.name,commitOid:t,depth:d-1,foundOrder:a}),Pf(o,t).add(a)}else void 0!==e&&(u=!0);Cf(s,o.get(t)),Nf(o,f,n.firstParent)}return{best:c??Of(s),sawUnannotated:u}},Of=t=>[...t].sort(Bu)[0],Hf=(t,e,a,n)=>{Cf([a],t.get(e.id)),Nf(t,e,n)},Cf=(t,e)=>{for(const a of t)void 0!==e&&e.has(a.foundOrder)||(a.depth+=1)},Nf=(t,e,a)=>{const n=t.get(e.id);if(void 0!==n)for(const r of Na(e,a)){const e=Pf(t,r);for(const t of n)e.add(t)}},Pf=(t,e)=>{let a=t.get(e);return void 0===a&&(a=new Set,t.set(e,a)),a};async function Rf(t,e={}){await Xi(t);const a=await af(t,e.from??"HEAD"),n=void 0!==e.to?await af(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 Te(t,a,n,r)}const Uf="fetch:negotiate",Lf=async(t,e={})=>{await Xi(t);const a=e.remote??"origin",{url:n,filter:r}=await _f(t,a);t.progress.start(Uf);try{const i=zd(t,void 0!==t.config?.auth?{auth:t.config.auth}:{}),o=await Xd(t,i,n);if(0===o.refs.length)throw R();if(void 0!==r&&!Qd(o.capabilities))throw ma();const s=Jd(o.capabilities),c=Zd(o.refs),d=await jf(t,a),u=await pa(t,i,{wants:c,haves:d,capabilities:s,url:n,progressOp:"fetch:write-objects",...void 0!==e.depth?{depth:e.depth}:{},...void 0!==r?{filter:r,promisor:!0}:{}});(u.shallow.length>0||u.unshallow.length>0)&&await ga(t,{shallow:u.shallow,unshallow:u.unshallow});return{remote:a,url:n,updatedRefs:await qf(t,a,o),prunedRefs:!0===e.prune?await Yf(t,a,o):[],shallow:u.shallow,unshallow:u.unshallow}}finally{t.progress.end(Uf)}},_f=async(t,e)=>{const a=await Ft(t),n=a.remote?.get(e);if(void 0===n?.url||""===n.url)throw await sa(t,"remote",e,["url"]),F(e);const r=void 0!==n.partialCloneFilter?Ti(Ei(n.partialCloneFilter)):void 0;return{url:n.url,filter:r}},jf=async(t,e)=>{const a=await Wf(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>=Pa))return r;const i=a.slice(0,Ra);for await(const e of Ce(t,{from:i,ignoreMissing:!0,verifyHash:!1}))if(!n.has(e.id)&&(n.add(e.id),r.push(e.id),r.length>=Pa))break;return r},Wf=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 Bf(t,n,a)}const r=`refs/remotes/${e}/`,i=await ge(t).getPackedRefs();for(const t of i.entries)(t.name.startsWith(r)||t.name.startsWith("refs/tags/"))&&a.push(t.id);return a},Bf=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 Bf(t,n,a);continue}const i=(await t.fs.readUtf8(n)).trim();Ff(i)&&a.push(i)}},zf=/^[0-9a-f]{40}([0-9a-f]{24})?$/i,Ff=t=>zf.test(t),qf=async(t,e,a)=>{const n=[];for(const r of a.refs){const a=Gf(e,r);if(void 0===a)continue;const i=await Kf(t,a);i!==r.id?(await Zt(t,a,r.id,{reflogMessage:`fetch ${e}: storing head`}),n.push({name:a,oldId:i,newId:r.id})):n.push({name:a,oldId:i,newId:r.id})}return n},Gf=(t,e)=>{if("HEAD"!==e.name&&Vf(e.name)){if(e.name.startsWith("refs/heads/")){const a=`refs/remotes/${t}/${e.name.slice(11)}`;if(!Vf(a))return;return a}return e.name.startsWith("refs/tags/")?e.name:void 0}},Vf=t=>{try{return be(t),!0}catch{return!1}},Kf=async(t,e)=>{be(e);const a=`${t.layout.gitDir}/${e}`;if(!await t.fs.exists(a))return;const n=(await t.fs.readUtf8(a)).trim();return Ff(n)?n:void 0},Yf=async(t,e,a)=>{const n=new Set(a.refs.filter(t=>t.name.startsWith("refs/heads/")).map(t=>t.name.slice(11))),r=`${t.layout.gitDir}/refs/remotes/${e}`;if(!await t.fs.exists(r))return[];const i=[];return await Xf(t,r,"",n,e,i),i},Xf=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 Xf(t,o,c,n,r,i);continue}if(n.has(c))continue;const d=`refs/remotes/${r}/${c}`;if(!Vf(d)){t.logger?.warn?.("fetch.prune: skipping unsafe ref name",{name:d});continue}const u=d;try{await Zt(t,u,Oe,{delete:!0})}catch(e){if(Jf(e)){t.logger?.warn?.("fetch.prune: skipping packed-only ref",{name:u});continue}throw e}i.push(u)}},Jf=e=>e instanceof t&&"UNSUPPORTED_OPERATION"===e.data.code&&"delete-packed-ref"===e.data.operation,Zf=async(t,e,a)=>!!await t.fs.exists(Ua(t.layout.gitDir,a))||void 0!==await e.lookup(a),Qf=async(e,a)=>{await Xi(e);const n=await Ft(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 F(r);const o=await(async(t,e)=>{const a=La(t),n=new Set,r=[];for(const i of e)n.has(i)||(n.add(i),await Zf(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=zd(e,void 0!==e.config?.auth?{auth:e.config.auth}:{}),c=await Xd(e,s,i),d=Jd(c.capabilities);try{await pa(e,s,{wants:o,haves:[],capabilities:d,url:i,progressOp:"fetch-missing:write-objects",promisor:!0})}catch(e){if(!(e=>e instanceof t&&"FILE_EXISTS"===e.data.code)(e))throw e}return{kind:"fetched",remote:r,requested:a.length,fetched:o.length}},tl=async(t,e)=>{const a=await Qf(t,e.oids);if("no-promisor"===a.kind)throw q();return{remote:a.remote,requested:a.requested,fetched:a.fetched}},el=t=>({fetch:async e=>{const a=await Qf(t,e);return"no-promisor"===a.kind?{attempted:!1,requested:e.length,fetched:0}:{attempted:!0,requested:a.requested,fetched:a.fetched}}}),al="badFilemode",nl="badTree",rl="badTreeSha1",il="duplicateEntries",ol="emptyName",sl="fullPathname",cl="hasDot",dl="hasDotdot",ul="hasDotgit",fl="largePathname",ll="nullSha1",hl="treeNotSorted",wl="zeroPaddedFilemode",ml="gitattributesBlob",pl="gitattributesSymlink",gl="gitignoreSymlink",yl="gitmodulesBlob",vl="gitmodulesSymlink",bl="mailmapSymlink",kl="badDate",$l="badDateOverflow",xl="badObjectSha1",Il="badParentSha1",El="badTimezone",Tl="missingAuthor",Dl="missingCommitter",Ml="missingEmail",Sl="missingNameBeforeEmail",Al="missingSpaceBeforeDate",Ol="missingSpaceBeforeEmail",Hl="missingTree",Cl="multipleAuthors",Nl="nulInCommit",Pl="nulInHeader",Rl="zeroPaddedDate",Ul="badTagName",Ll="missingObject",_l="missingTag",jl="missingTagEntry",Wl="missingTaggerEntry",Bl="missingType",zl="missingTypeEntry",Fl="gitmodulesLarge",ql="gitmodulesName",Gl="gitmodulesParse",Vl="gitmodulesUrl",Kl="gitattributesLarge",Yl="gitattributesLineLength",Xl=new Map([[al,"info"],[nl,"error"],[rl,"error"],[il,"error"],[ol,"warning"],[sl,"warning"],[cl,"warning"],[dl,"warning"],[ul,"warning"],[fl,"warning"],[ll,"warning"],[hl,"error"],[wl,"warning"],[ml,"error"],[pl,"info"],[gl,"info"],[yl,"error"],[vl,"error"],[bl,"info"],[kl,"error"],[$l,"error"],["badEmail","error"],["badName","error"],[xl,"error"],[Il,"error"],[El,"error"],["badType","error"],[Tl,"error"],[Dl,"error"],[Ml,"error"],[Sl,"error"],[Al,"error"],[Ol,"error"],[Hl,"error"],[Cl,"error"],[Nl,"warning"],[Pl,"error"],["unknownType","error"],["unterminatedHeader","error"],[Rl,"error"],["badGpgsig","error"],[Ul,"info"],[Ll,"error"],[_l,"error"],[jl,"error"],[Wl,"info"],[Bl,"error"],[zl,"error"],[Fl,"error"],["gitmodulesMissing","error"],[ql,"error"],[Gl,"info"],["gitmodulesPath","error"],["gitmodulesUpdate","error"],[Vl,"error"],[Kl,"error"],[Yl,"error"],["gitattributesMissing","error"]]),Jl=new Set([ol,sl,cl,dl,ul,fl,Nl,ll,wl]);function Zl(t,e){const a=Xl.get(t)??"error";return e&&"warning"===a&&Jl.has(t)?"error":a}const Ql=new TextDecoder,th=new TextEncoder;function eh(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 ah=t=>t.startsWith("-");function nh(t,e,a){return".gitmodules"===a?function(t,e){const a=[];if(t.length>104857600)return a.push({msgId:Fl,severity:Zl(Fl,e)}),a;const n=Ql.decode(t),{names:r,urls:i,parseError:o}=function(t){const e=[],a=[];let n=!1;for(const r of t.split("\n"))n=eh(r.trim(),e,a,n);return{names:e,urls:a,parseError:n}}(n);o&&a.push({msgId:Gl,severity:Zl(Gl,e)});for(const t of i)ah(t)&&a.push({msgId:Vl,severity:Zl(Vl,e)});for(const t of r)_a(t)&&a.push({msgId:ql,severity:Zl(ql,e)});return a}(t,e):".gitattributes"===a?function(t,e){const a=[];if(t.length>104857600)return a.push({msgId:Kl,severity:Zl(Kl,e)}),a;const n=Ql.decode(t);for(const t of n.split("\n"))if(th.encode(t).length>2048)return a.push({msgId:Yl,severity:Zl(Yl,e)}),a;return a}(t,e):[]}const rh=new TextDecoder,ih=/^[0-9a-f]{40}$/,oh=/^[0-9a-f]{64}$/,sh=/^[+-]\d{4}$/;function ch(t){return ih.test(t)||oh.test(t)}function dh(t,e){const a=[],n=t.indexOf("<");if(-1===n)return a.push({msgId:Ml,severity:Zl(Ml,e)}),a;const r=t.slice(0,n);r.endsWith(" ")||a.push({msgId:Ol,severity:Zl(Ol,e)}),""===r.trimEnd()&&a.push({msgId:Sl,severity:Zl(Sl,e)});const i=t.indexOf(">",n);if(-1===i)return a.push({msgId:Ml,severity:Zl(Ml,e)}),a;const o=t.slice(i+1);if(!o.startsWith(" "))return a.push({msgId:Al,severity:Zl(Al,e)}),a;const[s="",c=""]=o.trim().split(/\s+/),d=function(t,e){return t.startsWith("0")&&t.length>1?{msgId:Rl,severity:Zl(Rl,e)}:/^\d+$/.test(t)?function(t){return t.length>19||!(t.length<19)&&t>"9223372036854775807"}(t)?{msgId:$l,severity:Zl($l,e)}:void 0:{msgId:kl,severity:Zl(kl,e)}}(s,e);return void 0!==d?(a.push(d),a):(""===c||function(t){if(!sh.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:El,severity:Zl(El,e)}),a)}const uh=new TextDecoder,fh=/^[0-9a-f]{40}$/,lh=/^[0-9a-f]{64}$/,hh=new Set(["blob","tree","commit","tag"]);function wh(t,e,a){const n=[],r=t[e];if(void 0===r||!r.startsWith("tag "))return n.push({msgId:_l,severity:Zl(_l,a)}),n;const i=r.slice(4);if(""===i)return n.push({msgId:jl,severity:Zl(jl,a)}),n;(i.includes("\0")||i.includes("\n"))&&n.push({msgId:Ul,severity:Zl(Ul,a)});const o=t[e+1];if(void 0===o||!o.startsWith("tagger "))return n.push({msgId:Wl,severity:Zl(Wl,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:Ol,severity:Zl(Ol,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:$l,severity:Zl($l,e)}]:[]}(o.slice(7),a))n.push(t);return n}const mh=new TextDecoder,ph=new TextEncoder,gh=new Set(["100644","100755","120000","40000","160000"]);function yh(t){const e="40000"===t.mode||"040000"===t.mode,a=ph.encode(t.name);if(!e)return a;const n=new Uint8Array(a.length+1);return n.set(a),n[a.length]=47,n}function vh(t,e,a,n){const r=[],{mode:i,name:o,sha:s}=t;i.startsWith("0")&&r.push({msgId:wl,severity:Zl(wl,n)});const c=i.startsWith("0")?i.slice(1):i;gh.has(c)||r.push({msgId:al,severity:Zl(al,n)}),function(t){for(const e of t)if(0!==e)return!1;return!0}(s)&&r.push({msgId:ll,severity:Zl(ll,n)});for(const t of function(t,e){const a=[];return""===t?(a.push({msgId:ol,severity:Zl(ol,e)}),a):("."===t&&a.push({msgId:cl,severity:Zl(cl,e)}),".."===t&&a.push({msgId:dl,severity:Zl(dl,e)}),".git"===t&&a.push({msgId:ul,severity:Zl(ul,e)}),t.includes("/")&&a.push({msgId:sl,severity:Zl(sl,e)}),ph.encode(t).length>4096&&a.push({msgId:fl,severity:Zl(fl,e)}),a)}(o,n))r.push(t);a.has(o)&&r.push({msgId:il,severity:Zl(il,n)}),void 0!==e&&Wa(yh(e),yh(t))>0&&r.push({msgId:hl,severity:Zl(hl,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:vl,severity:Zl(vl,a)}):i||n.push({msgId:yl,severity:Zl(yl,a)})),".gitattributes"===e&&(r?n.push({msgId:pl,severity:Zl(pl,a)}):i||n.push({msgId:ml,severity:Zl(ml,a)})),".gitignore"===e&&r&&n.push({msgId:gl,severity:Zl(gl,a)}),".mailmap"===e&&r&&n.push({msgId:bl,severity:Zl(bl,a)}),n}(i,o,n))r.push(t);return r}function bh(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=ja(t,32,a);if(-1===n||n===a)return{entries:e,badTree:!0};const r=ja(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=mh.decode(o),u=mh.decode(s);e.push({mode:d,name:u,sha:c,offset:a}),a=i}return{entries:e,badTree:!1}}(t);if(n)return[{msgId:nl,severity:Zl(nl,e)}];const r=[],i=new Set;let o;for(const t of a){for(const a of vh(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=rh.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:Pl,severity:Zl(Pl,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:Hl,severity:Zl(Hl,e)}),{findings:a,nextIdx:-1};ch(n.slice(5))||a.push({msgId:rl,severity:Zl(rl,e)});let r=1;for(;r<t.length;){const n=t[r];if(void 0===n||!n.startsWith("parent "))break;ch(n.slice(7))||a.push({msgId:Il,severity:Zl(Il,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:Tl,severity:Zl(Tl,a)}),n;for(const t of dh(i.slice(7),a))n.push(t);for(r++;r<t.length&&t[r]?.startsWith("author ");)n.push({msgId:Cl,severity:Zl(Cl,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:Dl,severity:Zl(Dl,a)}),n;for(const t of dh(o.slice(10),a))n.push(t);return n}(i,s,e))c.push(t);return r.includes("\0")&&c.push({msgId:Nl,severity:Zl(Nl,e)}),c}(e,n);case"tag":return function(t,e){const a=uh.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:Ll,severity:Zl(Ll,e)}],nextIdx:-1};var n;if(n=t[0].slice(7),fh.test(n)||lh.test(n)||a.push({msgId:xl,severity:Zl(xl,e)}),!t[1]?.startsWith("type "))return a.push({msgId:Bl,severity:Zl(Bl,e)}),{findings:a,nextIdx:-1};const r=t[1].slice(5);return""!==r&&hh.has(r)?{findings:a,nextIdx:2}:(a.push({msgId:zl,severity:Zl(zl,e)}),{findings:a,nextIdx:-1})}(r,e);return-1===o?i:[...i,...wh(r,o,e)]}(e,n);case"blob":return nh(e,n,r)}}const kh=new Set([".gitmodules",".gitattributes"]);async function $h(e,a,n,r){const i=[];let o=0;const s=await async function(e,a){const n=await Ba(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}=qe(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 Vt(e,a,{verifyHash:!1}),n=Fe(t,e.hashConfig),{contentOffset:r}=qe(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=bh(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 xh(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!==Nt.GITLINK&&e.add(a.id);else"tag"===t.type&&e.add(t.data.object)}function Ih(t,e){t.universe.has(e)?t.reached.has(e)||t.worklist.push(e):t.missingIds.add(e)}function Eh(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)?Ih(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)?Ih(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===Nt.GITLINK)continue;const a=n.mode===Nt.DIRECTORY?"tree":"blob";t.universe.has(n.id)?Ih(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)?(Ih(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 Th(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 Dh(t,e){const a=e.get(t);return null!=a?a.type:"unknown"}const Mh=/^[0-9a-f]{40}$|^[0-9a-f]{64}$/;function Sh(t,e,a,n){const r=e.replace(/[\r\n]+$/,"");if(r.startsWith("ref: "))return{findings:[],exitBit:0};if(!Mh.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:Oe}),{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 Ah(t,e={}){await Ki(t);const a=await Fa(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 Vt(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)kh.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 $h(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=ge(t),o=await _e(t);for(const t of o){const o=await i.readLooseRaw(t);if(void 0!==o){const{findings:i,exitBit:s}=Sh(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 _e(t);for(const r of n)try{const n=await pe(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 za(t);await Promise.all(a.map(async a=>{try{const n=await me(t,a);for(const t of n)t.oldId!==Oe&&e.add(t.oldId),t.newId!==Oe&&e.add(t.newId)}catch{}}))}(t,n),!1!==e.indexRoot&&await async function(t,e){try{const a=await Xt(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&&xh(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):Eh(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)??Dh(t,r);g.push({type:"missing",id:t,objectType:e})}for(const t of l)g.push({type:"broken-link",...t});Th(m,"unreachable",g,r),Th(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 Oh(t){return t>=65&&t<=90||t>=97&&t<=122||t>=48&&t<=57||95===t}function Hh(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||!Oh(a),i=t.end>=e.length||void 0===n||!Oh(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 Ch=t=>t===Nt.REGULAR||t===Nt.EXECUTABLE;async function Nh(t,e){if(0===e.patterns.length)throw u("patterns","at least one pattern required");const a=Hh(e.patterns,{...!0===e.wholeWord?{wholeWord:!0}:{},...!0===e.invert?{invert:!0}:{}}),n=Hh(e.patterns,{...!0===e.wholeWord?{wholeWord:!0}:{}}),r=void 0!==e.paths&&e.paths.length>0?ho(e.paths):void 0,i=await async function(t,e){const{target:a}=e;if(void 0===a)return(async t=>{const e=await Xt(t),a=[];for(const n of e.entries){if(0!==n.flags.stage)continue;if(!Ch(n.mode))continue;const e=te(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 Xt(t)).entries.filter(t=>0===t.flags.stage&&Ch(t.mode)).map(e=>({path:e.path,load:async()=>(await $e(t,e.id)).content})))(t);const n=await af(t,a.treeish),r=[];for await(const{path:e,id:a,mode:i}of ke(t,n,{recursive:!0})){if(!Ch(i))continue;const n=a;r.push({path:e,load:async()=>(await $e(t,n)).content})}return r}(t,e),o=void 0!==r?i.filter(({path:t})=>Pr(r.matcher,t)):i,s=await qa(o,Ga,async t=>function(t,e,a,n){if(Et(n)){if(!e.matchLine(n.subarray(0,Va)).returned)return;return{path:a,hits:[],binaryMatch:!0}}const r=xt(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 Ph=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 Wd(e,{initialBranch:n,bare:r});return{path:i.gitDir,initialBranch:i.initialBranch,bare:i.bare}},Rh=(t,e)=>Object.freeze({list:()=>(e(),Ks(t)),create:a=>(e(),Xs(t,a)),delete:a=>(e(),Js(t,a)),rename:a=>(e(),Zs(t,a))}),Uh=(t,e)=>Object.freeze({create:a=>(e(),vc(t,a)),verify:a=>(e(),Ec(t,a)),listHeads:a=>(e(),xc(t,a))}),Lh=(t,e)=>Object.freeze({run:a=>(e(),Rd(t,a)),continue:a=>(e(),Ld(t,a)),skip:a=>(e(),_d(t,a)),abort:()=>(e(),jd(t))}),_h=(t,e)=>Object.freeze({get:a=>(e(),Ou(t,a)),getAll:a=>(e(),Hu(t,a)),getRegexp:a=>(e(),Cu(t,a)),list:a=>(e(),Nu(t,a)),set:a=>(e(),Pu(t,a)),unset:a=>(e(),Ru(t,a)),unsetAll:a=>(e(),Uu(t,a)),renameSection:a=>(e(),Lu(t,a)),removeSection:a=>(e(),_u(t,a))}),jh=async(t,e,a={})=>{const n=await Wh(t,e,a);return"fast-forward"!==n.kind&&"merge"!==n.kind||await Ve(t,"post-merge",{args:["0"]}),n},Wh=async(t,e,a)=>{await Xi(t),await Ji(t,"merge"),await to(t);const n=await Zi(t);if("symbolic"!==n.kind)throw o("merge","cannot merge with detached HEAD");const r=await pe(t,n.target),i=await Is(t,e.rev);if(r===i)return{kind:"up-to-date",id:r};const[s]=await We(t,[r,i]);if(s===i)return{kind:"up-to-date",id:r};if(s===r&&"never"!==e.fastForward)return qh(t,await fw(t,i),async()=>(await Zt(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 G(n.target,r,i);return Fh(t,e,a,n.target,r,i,s)},Bh="merge:write-files",zh=new Set(["rename-rename","gitlink"]),Fh=async(t,e,a,n,r,i,o)=>{t.progress.start(Bh);try{const s=await Vh(t,r,i,o,e.rev);return"conflict"===s.kind?Xh(t,e,s,r,i):Gh(t,e,a,n,r,i,s.tree)}finally{t.progress.end(Bh)}},qh=async(e,a,n)=>{const r=await Yt(e);try{const i=await(async(e,a)=>{const n=await Xt(e);try{return(await Jt(e,{targetTree:a,currentIndex:n,force:!1})).newIndexEntries}catch(e){throw(e=>e instanceof t&&"CHECKOUT_OVERWRITE_DIRTY"===e.data.code?M({localChanges:e.data.localChanges,untracked:e.data.untracked}):e)(e)}})(e,a);return await r.commit(i),await n()}finally{await r.release()}},Gh=async(t,e,a,n,r,i,o)=>{const s=await dw(t,e),c=uw(e,s),d=Id(e.message??`Merge ${e.rev}`,{allowEmpty:!1}),u={tree:o,parents:[r,i],author:s,committer:c,message:d,extraHeaders:[]};return qh(t,o,async()=>{const o=await ca(t,u);return await Zt(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]}})},Vh=async(t,e,a,n,r)=>{const i=await fw(t,e),o=await fw(t,a),s=void 0!==n?await fw(t,n):void 0,[c,d,u]=await Promise.all([Ie(t,i),Ie(t,o),void 0!==s?Ie(t,s):Promise.resolve(void 0)]),f=((t,e)=>({ours:zr,theirs:t,base:void 0!==e?Fr(e):""}))(r,n),l=Wc(t,f),h=await bi(u,c,d,l,f);return h.cleanMerge?{kind:"clean",tree:await Kh(t,h.outcomes)}:{kind:"conflict",outcomes:h.outcomes,conflicts:h.conflicts,ours:c.entries}},Kh=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 ie(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 Yh(t,a)},Yh=async(t,e,a=0)=>{if(a>4096)throw Pe(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 Yh(t,n,a+1),mode:Nt.DIRECTORY}))),o=n.map(t=>({name:t.path,id:t.id,mode:t.mode}));return ba(t,[...o,...i])},Xh=async(t,e,a,n,r)=>{Jh(a.conflicts);const i=await Xt(t),o=zc(a.outcomes,a.conflicts,a.ours),{localChanges:s,untracked:c}=await qc(t,o,i);if(s.length>0||c.length>0)throw M({localChanges:s,untracked:c});const d=await Gt(t),u=await Yt(t);try{await Qh(t,a.outcomes,a.conflicts,o,d),await Bi(t,n),await(async(t,e)=>{await t.fs.writeUtf8(Li(t),`${e}\n`)})(t,r);const i=Id(e.message??`Merge ${e.rev}`,{allowEmpty:!1});await Wi(t,i);const s=cw(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}},Jh=t=>{for(const e of t)if(zh.has(e.type))throw o("merge",`conflict type '${e.type}' not supported in v1 (path=${e.path})`)},Zh=(t,e)=>void 0!==t&&!t(e),Qh=async(t,e,a,n,r)=>{const i=e.filter(t=>"conflict"!==t.status&&n.has(t.path));await tw(i,32,e=>ew(t,e,r)),await tw(a,32,e=>aw(t,e))},tw=async(t,e,a)=>{await qa(t,e,a)},ew=async(t,e,a)=>{if("unchanged"===e.status||"resolved-known"===e.status){if(Zh(a,e.path))return;const n=await ra(t,e.id);return void await ia(t,e.path,n)}"resolved-merged"!==e.status?"resolved-deleted"===e.status&&await aa(t,e.path):await na(t,e.path,e.bytes)},aw=async(t,e)=>{if("distinct-types"===e.type)return void await Kc(t,e);const a=e.mergedMode??e.ourMode??e.theirMode;if(void 0===a)return;const n=await ow(t,e);void 0!==n&&await ea(t,e.path,n,a)},nw={maxBytes:Lr},rw=(t,e)=>{if(void 0!==e.ourId)return $e(t,e.ourId,nw).then(t=>t.content)},iw=async(t,e)=>void 0!==e.conflictContent?e.conflictContent:rw(t,e),ow=async(t,e)=>{if("content"===e.type)return iw(t,e);if("add-add"===e.type)return iw(t,e);if("binary"===e.type)return rw(t,e);if("type-change"===e.type)return rw(t,e);if("modify-delete"===e.type){const a=e.ourId??e.theirId;if(void 0===a)return;return(await $e(t,a,nw)).content}},sw=t=>({ctimeSeconds:0,ctimeNanoseconds:0,mtimeSeconds:0,mtimeNanoseconds:0,dev:0,ino:0,mode:t,uid:0,gid:0,fileSize:0}),cw=(t,e,a)=>{const n=[];for(const e of t)"unchanged"!==e.status&&"resolved-known"!==e.status||n.push(Zh(a,e.path)?Ka({path:e.path,id:e.id,mode:e.mode}):{...sw(e.mode),id:e.id,flags:$t,path:e.path});const r=ir(e,sw),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},dw=async(t,e)=>{const a=await Ft(t),n=a.user?{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),$d(r)},uw=(t,e)=>{const a={author:e};return void 0!==t.committer&&(a.explicit=t.committer),xd(a)},fw=async(t,e)=>{const a=await Vt(t,e);if("commit"!==a.type)throw Kt("commit",a.type,e);return a.data.tree},lw=(t,e)=>Object.freeze({run:a=>(e(),jh(t,a)),continue:a=>(e(),ju(t,a)),abort:()=>(e(),ro(t))}),hw=async(t,e,a,n,r=0)=>{const i=Ya(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=Qa(Qa(en(),a,o+1),{kind:"note",key:n,val:r},o+1);return Ja(t,e,Za(i))}const s=Ja(t,e,tn(await Xa(a,i),a.prefix,o));return hw(s,n,r,i,o)})(t,i,o,e,a,n,r):"internal"===o.kind?Ja(t,i,Za(await hw(o.node,e,a,n,r+1))):Qa(t,{kind:"note",key:e,val:a},r)},ww=async(t,e,a,n=0)=>{const r=Ya(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 ww(i.node,e,a,n+1);if(e.startsWith(i.prefix))return ww(await Xa(i,a),e,a,i.prefix.length)}},mw=async(t,e,a,n=0)=>{const r=Ya(e,n),i=t.slots[r];if("empty"===i.kind)return t;if("note"===i.kind)return i.key===e?Ja(t,r,an):t;if("internal"===i.kind)return Ja(t,r,(t=>{if(t.preserved.length>0)return Za(t);const e=t.slots.filter(t=>"empty"!==t.kind);if(0===e.length)return an;const a=e[0];return 1===e.length&&"internal"!==a.kind?a:Za(t)})(await mw(i.node,e,a,n+1)));if(!e.startsWith(i.prefix))return t;const o=Ja(t,r,tn(await Xa(i,a),i.prefix,n));return mw(o,e,a,n)},pw=/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/,gw=/^[0-9a-f]{40}$/,yw=async(t,e)=>gw.test(e)?e:pe(t,e),vw=async(t,e)=>{await Xi(t);const a=await yw(t,e.object),n=await nn(t,e.ref),{trie:r,read:i,notesCommitOid:o}=await rn(t,n);if(void 0!==await ww(r,a,i)&&!0!==e.force)throw V(a);const s=await ie(t,{type:"blob",id:"",content:e.content}),c=await hw(r,a,s,i),d=await Td(t),u=await on(t,{trie:c,read:i,prevCommitOid:o,message:"Notes added by 'git notes add'\n",author:d});return await Zt(t,n,u,{reflogMessage:"notes: Notes added by 'git notes add'"}),{notesCommit:u,note:s}},bw=async(t,e)=>{await Xi(t);const a=await yw(t,e.object),n=await nn(t,e.ref),{trie:r,read:i}=await rn(t,n),o=await ww(r,a,i);return void 0===o?null:{object:a,note:o,content:(await $e(t,o)).content}},kw=async(t,e)=>{await Xi(t);const a=await nn(t,e?.ref),{notesTreeOid:n}=await rn(t,a);if(void 0===n)return[];const r=[];for await(const e of ke(t,n)){if(e.mode!==Nt.REGULAR)continue;const t=e.path.split("/").join("");pw.test(t)&&r.push({object:_t.from(t),note:e.id})}return r.sort((t,e)=>t.object<e.object?-1:1)},$w=async(t,e)=>{await Xi(t);const a=await yw(t,e.object),n=await nn(t,e.ref),{trie:r,read:i,notesCommitOid:o}=await rn(t,n);if(void 0===o)throw K(a);if(void 0===await ww(r,a,i))throw K(a);const s=await mw(r,a,i),c=await Td(t),d=await on(t,{trie:s,read:i,prevCommitOid:o,message:"Notes removed by 'git notes remove'\n",author:c});return await Zt(t,n,d,{reflogMessage:"notes: Notes removed by 'git notes remove'"}),{notesCommit:d}},xw=(t,e)=>Object.freeze({add:a=>(e(),vw(t,a)),read:a=>(e(),bw(t,a)),list:a=>(e(),kw(t,a)),remove:a=>(e(),$w(t,a))}),Iw=t=>`'${t.replaceAll("'","'\\''")}'`,Ew=(t,e)=>{const a=`${e}=`,n=t.find(t=>t.startsWith(a));if(void 0===n)throw sn(e,"missing author-script key");const r=n.slice(a.length);if(r.length<2||!r.startsWith("'")||!r.endsWith("'"))throw sn(n,"author-script value is not single-quoted");return(t=>t.slice(1,-1).replaceAll("'\\''","'"))(r)},Tw=t=>t.replace(/\n+$/,""),Dw=(t,e)=>{return 0===e?`# This is the 1st commit message:\n\n${Tw(t.message)}\n`:!0===t.skip?`\n# The commit message #${e+1} will be skipped:\n\n${a=t.message,Tw(a).split("\n").map(t=>""===t?"#":`# ${t}`).join("\n")}\n`:`\n# This is the commit message #${e+1}:\n\n${Tw(t.message)}\n`;var a},Mw=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+=Dw(t[n],n);return a},Sw=/^(pick|reword|edit|squash|fixup|drop) (\S+) # (.*)$/,Aw=t=>t.map(t=>`${t.action} ${t.oid} # ${t.subject}\n`).join(""),Ow=t=>{const e=[];for(const a of t.split("\n")){if(""===a||a.startsWith("#"))continue;const t=Sw.exec(a);if(null===t)throw D(a);e.push({action:t[1],oid:t[2],subject:t[3]})}return e},Hw=new TextEncoder,Cw=new Uint8Array,Nw=async(t,e)=>{const a=await Vt(t,e);if("commit"!==a.type)throw Kt("commit",a.type,e);return a.data},Pw=async(t,e)=>{const a=await Nw(t,e),n=a.parents[0],r=void 0!==n?(await Nw(t,n)).tree:void 0,i=await Te(t,r,a.tree,{recursive:!0}),o=await cn(t,i.changes),s=Cr(o,{contextLines:3,pathPrefix:{old:"a/",new:"b/"}}),c=o.filter(t=>Et(t.oldContent??Cw)||Et(t.newContent??Cw)).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(Hw.encode(s.split("\n").filter(t=>!t.startsWith("@@ ")&&!t.startsWith("index ")).map(t=>t.replace(/\s/g,"")).join("")+c))},Rw=t=>`${t.layout.gitDir}/rebase-merge`,Uw=(t,e)=>`${Rw(t)}/${e}`,Lw=t=>`${t.layout.gitDir}/REBASE_HEAD`,_w=t=>t.map(([t,e])=>`${t} ${e}\n`).join(""),jw=async(t,e)=>{const a=[...e.done,...e.remaining],n=(e,a)=>t.fs.writeUtf8(Uw(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",Aw(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`${Aw(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",Aw(e.done)),await n("message",e.message),await n("author-script",(r=e.stoppedAuthor,`GIT_AUTHOR_NAME=${Iw(r.name)}\nGIT_AUTHOR_EMAIL=${Iw(r.email)}\nGIT_AUTHOR_DATE=${Iw(`@${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",_w(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(Lw(t),`${e.stoppedSha}\n`)},Ww=t=>ed(t,Lw(t)),Bw=async(t,e)=>{const a=[];for(const n of e){const e=await zo(t,n.oid);if(void 0===e)throw D(`cannot resolve commit ${n.oid}`);a.push({action:n.action,oid:e,subject:n.subject})}return a},zw=async t=>{if(!await(t=>t.fs.exists(Rw(t)))(t))return;const e=(await t.fs.readUtf8(Uw(t,"head-name"))).trimEnd(),a=await ed(t,Uw(t,"onto")),n=await ed(t,Uw(t,"orig-head")),r=await Bw(t,Ow(await t.fs.readUtf8(Uw(t,"done")))),i=await Bw(t,Ow(await t.fs.readUtf8(Uw(t,"git-rebase-todo")))),o=(t=>{const e=t.split("\n"),a=Ew(e,"GIT_AUTHOR_NAME"),n=Ew(e,"GIT_AUTHOR_EMAIL"),r=Ew(e,"GIT_AUTHOR_DATE");if(!r.startsWith("@"))throw sn(r,"author-script date lacks the `@` prefix");const[i,o]=r.slice(1).split(" "),s=Number(i);if(!Number.isSafeInteger(s))throw sn(r,"invalid author-script timestamp");if(void 0===o||!/^[+-]\d{4}$/.test(o))throw sn(r,"invalid author-script timezone offset");return{name:a,email:n,timestamp:s,timezoneOffset:o}})(await t.fs.readUtf8(Uw(t,"author-script"))),s=await t.fs.readUtf8(Uw(t,"message")),c=await ed(t,Uw(t,"amend")),d=await Fw(t),u=await qw(t);return{headName:e,onto:a,origHead:n,done:r,remaining:i,stoppedSha:await Ww(t),author:o,message:s,...void 0!==c?{amend:c}:{},...void 0!==d?{currentFixups:d}:{},...void 0!==u?{rewrittenPending:u}:{}}},Fw=async t=>{const e=Uw(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},qw=async t=>{const e=Uw(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},Gw=async t=>{const e=Uw(t,"rewritten-list");if(!await t.fs.exists(e))return[];const a=[];for(const n of(await t.fs.readUtf8(e)).split("\n")){if(""===n)continue;const[t,e]=n.split(" ");void 0!==t&&void 0!==e&&a.push([t,e])}return a},Vw=async t=>{await t.fs.exists(Rw(t))&&await t.fs.rmRecursive(Rw(t)),await t.fs.exists(Lw(t))&&await t.fs.rm(Lw(t))},Kw="HEAD",Yw=t=>t.slice(0,7),Xw=async(t,e,a)=>{const n=new Set;if(void 0!==e)for await(const a of Ce(t,{from:[e]}))n.add(a.id);const r=[];for await(const e of Ce(t,{from:[a],until:[...n]}))r.push(e.id);return r.reverse()},Jw=async(t,e,a,n)=>{const r=a.parents[0],i=void 0!==r?await Ts(t,r):void 0,o=await Ts(t,n),s=await Yt(t);try{const n=await Xt(t),r=await Qc(t,{baseTree:i,oursTree:o,theirsTree:a.tree,currentIndex:n,labels:Vr(e,Xn(a.message))});if("would-overwrite"===r.kind)throw M({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()}},Zw=async(t,e,a,n)=>{const r=await Jw(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 Td(t),o=await ca(t,{tree:r.mergedTree,parents:[n],author:a.author,committer:i,message:a.message,extraHeaders:[]});return await Zt(t,Kw,o,{expected:n,reflogMessage:`rebase (pick): ${Xn(a.message)}`}),{kind:"committed",id:o}},Qw=async(t,e)=>{const a=e.parents[0],n=void 0!==a?await Ts(t,a):void 0,r=await Te(t,n,e.tree,{recursive:!0});return Cr(await cn(t,r.changes),{contextLines:3,pathPrefix:{old:"a/",new:"b/"}})},tm=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:yd(n.message,nr(r)),rewritten:i,patch:await Qw(t,n),...void 0!==e.backupHeader?{backupHeader:e.backupHeader}:{}};await jw(t,o)},em=async(t,e,a,n,r)=>{void 0!==e&&(await Zt(t,e,n,{expected:a,reflogMessage:`rebase (finish): ${e} onto ${r}`}),await Gs(t,Kw,e),await Ke(t,Kw,n,n,`rebase (finish): returning to ${e}`))},am=(t,e)=>va(t,"pre-rebase",{args:[e]}),nm=async(t,e)=>{0!==e.length&&await Ve(t,"post-rewrite",{args:["rebase"],stdin:_w(e)})},rm=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 Es(t,n),c=await Zw(t,n,s,r);if("committed"!==c.kind){if("empty"!==c.kind)return await tm(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 em(t,e.branch,e.origHead,r,e.onto),await nm(t,o),await Vw(t),{kind:"rebased",commits:i}},im=async(e,a)=>{await Xi(e),await Ji(e,"rebase"),await to(e);const n=await Zi(e),r="symbolic"===n.kind?await(async(e,a)=>{try{return await pe(e,a)}catch(e){if(e instanceof t&&"REF_NOT_FOUND"===e.data.code)throw H();throw e}})(e,n.target):n.id,i="symbolic"===n.kind?n.target:void 0,o=await Is(e,a.upstream),s=void 0!==a.onto?await Is(e,a.onto):o,c=a.onto??a.upstream;await kd(e,await Ts(e,r));const[d]=await We(e,[o,r]);if(void 0!==a.interactive)return await am(e,a.upstream),vm(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 am(e,a.upstream);const u=await Xw(e,d,r),f=await(async(t,e,a,n)=>{const r=await Xw(t,a,n),i=new Set;for(const e of r)i.add(await Pw(t,e));const o=[];for(const a of e)i.has(await Pw(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:Xn((await Es(t,n)).message)});return a})(e,f);await Bi(e,r),await(async(t,e,a,n)=>{await ge(t).writeLoose(Kw,a),await Ke(t,Kw,e,a,`rebase (start): checkout ${n}`),await no(t,a)})(e,r,s,c);const h={branch:i,onto:s,origHead:r,doneBefore:[],todo:l,backupHeader:{shortUpstream:Yw(o),shortOrigHead:Yw(r),shortOnto:Yw(s)}};return rm(e,h,s,{applied:[],rewritten:[]})},om=t=>"detached HEAD"===t?void 0:t,sm=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])},cm=async t=>{await Xi(t),await Ji(t,"rebase --continue");const e=await zw(t);if(void 0===e)throw i("rebase");if(bm(e))return km(t,e);const a=await Xt(t);sm(a.entries);const n=e.done[e.done.length-1],r=await pe(t,Kw),o=await Ye(t,a.entries),s=await Td(t),c=Id(Ed(e.message),{allowEmpty:!1}),d=await ca(t,{tree:o,parents:[r],author:e.author,committer:s,message:c,extraHeaders:[]});await Zt(t,Kw,d,{expected:r,reflogMessage:`rebase (continue): ${Xn(c)}`});const u=[...await Gw(t),[n.oid,d]],f={branch:om(e.headName),onto:e.onto,origHead:e.origHead,doneBefore:e.done,todo:e.remaining};return rm(t,f,d,{applied:[{source:n.oid,created:d}],rewritten:u})},dm=async t=>{await Xi(t),await Ji(t,"rebase --skip");const e=await zw(t);if(void 0===e)throw i("rebase");if(bm(e))return $m(t,e);const a=await pe(t,Kw);await no(t,a);const n={branch:om(e.headName),onto:e.onto,origHead:e.origHead,doneBefore:e.done,todo:e.remaining};return rm(t,n,a,{applied:[],rewritten:await Gw(t)})},um=async t=>{await Xi(t),await Ji(t,"rebase --abort");const e=await zw(t);if(void 0===e)throw i("rebase");const a=om(e.headName),n=await pe(t,Kw);return await no(t,e.origHead),void 0!==a?(await Gs(t,Kw,a),await Ke(t,Kw,n,e.origHead,`rebase (abort): returning to ${a}`)):(await ge(t).writeLoose(Kw,e.origHead),await Ke(t,Kw,n,e.origHead,`rebase (abort): returning to ${e.origHead}`)),await Vw(t),{head:e.origHead,headName:e.headName}},fm=async(t,e)=>{const a=await Td(t),n=await ca(t,{tree:e.tree,parents:[e.parent],author:e.author,committer:a,message:e.message,extraHeaders:[]});return await Zt(t,Kw,n,{expected:e.expected,reflogMessage:e.reflog}),n},lm=async(t,e,a,n,r)=>{if(a.parents[0]===n)return await(async(t,e)=>{const a=await pe(t,Kw);await ge(t).writeLoose(Kw,e),await Ke(t,Kw,a,e,"rebase: fast-forward"),await no(t,e)})(t,e.oid),{kind:"committed",created:e.oid};const i=await Jw(t,e.oid,a,n);return"conflict"===i.kind?{kind:"conflict",conflicts:i.conflicts}:{kind:"committed",created:await fm(t,{tree:i.mergedTree,parent:n,expected:n,author:a.author,message:a.message,reflog:r})}},hm=(t,e,a,n)=>"reword"===e.action?(async(t,e,a,n)=>{const r=Id(e.message??a.message,{allowEmpty:!1}),i=await lm(t,e,a,n,`rebase (reword): ${Xn(a.message)}`);if("conflict"===i.kind)return{kind:"conflict",conflicts:i.conflicts};const o=await Es(t,i.created);return{kind:"advanced",created:await fm(t,{tree:o.tree,parent:o.parents[0],expected:i.created,author:o.author,message:r,reflog:`rebase (reword): ${Xn(r)}`})}})(t,e,a,n):"edit"===e.action?(async(t,e,a,n)=>{const r=await lm(t,e,a,n,`rebase (edit): ${Xn(a.message)}`);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 lm(t,e,a,n,`rebase (pick): ${Xn(a.message)}`);return"conflict"===r.kind?{kind:"conflict",conflicts:r.conflicts}:{kind:"advanced",created:r.created}})(t,e,a,n),wm=async(t,e,a,n)=>{await jw(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}:{}})},mm=(t,e)=>{const a=t[e+1];return void 0!==a&&("squash"===a.action||"fixup"===a.action)},pm=(t,e,a)=>({kind:"conflict",commit:t,conflicts:e.map(t=>({path:t.path,type:t.type})),remaining:a}),gm=async(t,e,a,n,r,i)=>{const o=await Es(t,n),s=await Jw(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=Mw([{message:r.baseMessage},...r.members]),d=i?Id(r.inline??Ed(c),{allowEmpty:!1}):c;return{kind:"committed",created:await fm(t,{tree:s.mergedTree,parent:o.parents[0],expected:n,author:o.author,message:d,reflog:`rebase (${e.action}): ${Xn(d)}`}),message:d}},ym=async(t,e,a,n)=>{let r=a;const i=[...n.applied],o=[...n.rewritten],s={baseMessage:(await Es(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 Es(t,n.oid),d=await Qw(t,c);if("squash"===n.action||"fixup"===n.action){const u=await gm(t,n,c,r,s,!mm(e.todo,a));if("conflict"===u.kind){const r=Mw([{message:s.baseMessage},...s.members,{message:c.message,skip:"fixup"===n.action}]);return await wm(t,e,a,{stoppedSha:n.oid,author:c.author,message:yd(r,nr(u.conflicts)),patch:d,rewritten:o,currentFixups:[...s.fixups,{action:n.action,oid:n.oid}],rewrittenPending:[...s.pending],messageSquash:r}),pm(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 hm(t,n,c,r);if("conflict"===u.kind)return await wm(t,e,a,{stoppedSha:n.oid,author:c.author,message:yd(c.message,nr(u.conflicts)),patch:d,rewritten:o}),pm(n.oid,u.conflicts,e.todo.length-(a+1));if("edit-stop"===u.kind)return await wm(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 Es(t,u.created)).message,s.members=[],s.fixups=[],s.pending=[u.created],s.inline=void 0}return await em(t,e.branch,e.origHead,r,e.onto),await nm(t,o),await Vw(t),{kind:"rebased",commits:i}},vm=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 Xw(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&&""===Id(a.message,{allowEmpty:!0}))throw u("interactive",`${a.action} message must not be empty`);const e=await Is(t,a.oid);if(!i.has(e))throw u("interactive",`commit ${e} is not in the list of commits to be rebased`);const n=Xn((await Es(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 Es(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 Bi(t,e.headCommit),await(async(t,e,a,n)=>{await ge(t).writeLoose(Kw,n),await Ke(t,Kw,e,n,`rebase (start): checkout ${a}`),await no(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:Yw(e.upstream),shortOrigHead:Yw(e.headCommit),shortOnto:Yw(e.onto)}},s={applied:i.map(t=>({source:t.oid,created:t.oid})),rewritten:[]};return ym(t,o,r,s)},bm=t=>[...t.done,...t.remaining].some(t=>"pick"!==t.action),km=async(t,e)=>{const a={branch:om(e.headName),onto:e.onto,origHead:e.origHead,doneBefore:e.done,todo:e.remaining},n=[...await Gw(t)],r=await Xt(t);sm(r.entries);const i=await Ye(t,r.entries),o=await pe(t,Kw),s=e.done[e.done.length-1].oid;let c;if(void 0!==e.currentFixups){const a=await Es(t,o),r=Id(Ed(e.message),{allowEmpty:!1});c=await fm(t,{tree:i,parent:a.parents[0],expected:o,author:a.author,message:r,reflog:`rebase (continue): ${Xn(r)}`}),n.push([s,c])}else if(void 0!==e.amend){const a=await Es(t,e.amend);i===a.tree?c=o:(c=await fm(t,{tree:i,parent:a.parents[0],expected:o,author:e.author,message:a.message,reflog:`rebase (continue): ${Xn(a.message)}`}),n.push([s,c]))}else{const a=Id(Ed(e.message),{allowEmpty:!1});c=await fm(t,{tree:i,parent:o,expected:o,author:e.author,message:a,reflog:`rebase (continue): ${Xn(a)}`}),n.push([s,c])}return ym(t,a,c,{applied:[],rewritten:n})},$m=async(t,e)=>{const a=await pe(t,Kw),n=void 0!==e.amend?(await Es(t,e.amend)).parents[0]:a;await ge(t).writeLoose(Kw,n),await no(t,n);const r={branch:om(e.headName),onto:e.onto,origHead:e.origHead,doneBefore:e.done,todo:e.remaining};return ym(t,r,n,{applied:[],rewritten:await Gw(t)})},xm=(t,e)=>Object.freeze({run:a=>(e(),im(t,a)),continue:()=>(e(),cm(t)),skip:()=>(e(),dm(t)),abort:()=>(e(),um(t))}),Im=t=>"HEAD"===t||t.includes("/")?t:`refs/heads/${t}`,Em=t=>{if(""===t)throw dn(t,"refspec must not be empty");let e=t,a="normal";if(e.startsWith("+")&&(a="force",e=e.slice(1)),""===e)throw dn(t,"refspec must not be empty after force prefix");const n=Tm(e,":");if(n>1)throw dn(t,"refspec must contain at most one colon");if(0===n){const t=Im(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 dn(t,"destination must not be empty");const s=Im(o);if("HEAD"===s)throw dn(t,"destination must not be HEAD");return""===i?{force:a,src:"",dst:s,isDelete:!0}:{force:a,src:Im(i),dst:s,isDelete:!1}},Tm=(t,e)=>{let a=0;for(let n=0;n<t.length;n+=1)t[n]===e&&(a+=1);return a},Dm=/[\n\r\t\0"\\\]/]/,Mm=t=>{if(""===t)throw Y(t,"name must not be empty");if(Dm.test(t))throw Y(t,"name must not contain a newline, tab, NUL, slash, bracket, quote, or backslash");return t},Sm=(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},Am=/[\n\r\0]/,Om=t=>{if(Am.test(t))throw u("remote.url","url must not contain a newline or NUL")},Hm=(t,e)=>({name:t,url:e?.url??"",pushUrl:e?.pushUrl,fetchRefspecs:e?.fetch??[]}),Cm=async t=>{await Ki(t);const e=await Ft(t);if(void 0===e.remote)return{remotes:[]};const a=[];for(const[t,n]of e.remote)a.push(Hm(t,n));return a.sort((t,e)=>t.name<e.name?-1:1),{remotes:a}},Nm=async(t,e)=>{await Ki(t),Mm(e.name),Om(e.url);const a=await Ft(t);if(!0===a.remote?.has(e.name))throw X(e.name);const n=e.fetch??`+refs/heads/*:refs/remotes/${e.name}/*`;Em(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 un(t,r),{remote:{name:e.name,url:e.url,pushUrl:void 0,fetchRefspecs:[n]}}},Pm=async(t,e)=>{const a=`refs/remotes/${e}/`;return(await _e(t)).filter(t=>t.startsWith(a))},Rm=async(t,e)=>{await Ki(t),Mm(e.name);const a=await Ft(t);if(!0!==a.remote?.has(e.name))throw F(e.name);const n=await Pm(t,e.name),r=Sm(a,e.name);for(const e of n)await Zt(t,e,Oe,{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 un(t,i),{name:e.name,removedTrackingRefs:n,clearedBranches:r.map(t=>t.ref)}},Um=async(t,e,a,n)=>{const r=ge(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 Zt(t,a,i.id,{expected:"absent",reflogMessage:n}),await Zt(t,e,Oe,{delete:!0})}},Lm=async(t,e)=>{if(await Ki(t),Mm(e.from),Mm(e.to),e.from===e.to)throw u("remote.rename","from and to must differ");const a=await Ft(t),n=a.remote?.get(e.from);if(void 0===n)throw F(e.from);if(!0===a.remote?.has(e.to))throw X(e.to);const r=await Pm(t,e.from),i=Sm(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 Um(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 un(t,d),{from:e.from,to:e.to,movedTrackingRefs:s,rewrittenBranches:i.map(t=>t.ref)}},_m=async(t,e)=>{await Ki(t),Mm(e.name),Om(e.url);const a=await Ft(t);if(!0!==a.remote?.has(e.name))throw F(e.name);const n=!0===e.push?"pushurl":"url";await un(t,[{kind:"set",section:"remote",subsection:e.name,key:n,value:e.url}]);const r=(await Ft(t)).remote?.get(e.name);return{remote:Hm(e.name,r)}},jm=async(t,e)=>{await Ki(t),Mm(e.name);const a=await Ft(t),n=a.remote?.get(e.name);if(void 0===n)throw F(e.name);const r=await Pm(t,e.name),i=ge(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=Sm(a,e.name);return{remote:{...Hm(e.name,n),trackingRefs:o,trackedBy:s.map(t=>({branch:t.ref,merge:t.merge}))}}},Wm=(t,e)=>Object.freeze({list:()=>(e(),Cm(t)),add:a=>(e(),Nm(t,a)),remove:a=>(e(),Rm(t,a)),rename:a=>(e(),Lm(t,a)),setUrl:a=>(e(),_m(t,a)),show:a=>(e(),jm(t,a))}),Bm=t=>t.parents.length>=2,zm=t=>t.map(t=>({path:t.path,type:t.type})),Fm=t=>ba(t,[]),qm=async(t,e,a,n,r)=>{const i=a.parents[0],o=void 0!==i?await Ts(t,i):await Fm(t),s=await Ts(t,r),c=await Yt(t);try{const i=await Xt(t),d=await Qc(t,{baseTree:a.tree,oursTree:s,theirsTree:o,currentIndex:i,labels:Kr(e,Xn(a.message))});if("would-overwrite"===d.kind)throw M({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 Td(t),o=Id(lu(a,e),{allowEmpty:!1});return{id:await ca(t,{tree:r,parents:[n],author:i,committer:i,message:o,extraHeaders:[]}),subject:Xn(o)}})(t,e,a,r,d.mergedTree);return await Zt(t,n,u,{expected:r,reflogMessage:`revert: ${f}`}),{kind:"committed",id:u}}finally{await c.release()}},Gm=async(t,e,a,n)=>{await od(t,e.sequenceHead),await dd(t,await(async(t,e)=>{const a=[];for(const n of e){const e=await Es(t,n);a.push({command:"revert",oid:n,subject:Xn(e.message)})}return a})(t,a)),await cd(t,n),await fd(t,{recordOrigin:!1,allowEmpty:!1,noCommit:!1})},Vm=async(t,e,a)=>{"conflict"===e.kind&&await(async(t,e,a,n)=>{await(async(t,e)=>{await t.fs.writeUtf8(du(t),`${e}\n`)})(t,e),await Wi(t,yd(lu(a,e),nr(n)))})(t,a.source,a.cData,e.conflicts),a.seq.multiPick&&await Gm(t,a.seq,a.remaining,a.currentHead);const n=a.remaining.length-1;return"conflict"===e.kind?{kind:"conflict",commit:a.source,conflicts:zm(e.conflicts),remaining:n}:{kind:"empty",commit:a.source,remaining:n}},Km=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 Es(t,s);if(Bm(c))throw r.multiPick&&await Gm(t,r,e.slice(n),i),J(s);const d=await qm(t,s,c,a,i);if("committed"!==d.kind){if("empty"!==d.kind||"drop"!==r.onEmpty||0!==n)return Vm(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 hd(t),{kind:"reverted",commits:o}},Ym=/^(.+)\.\.(.+)$/,Xm=async(t,e,a)=>{const n=new Set;for await(const a of Ce(t,{from:[e]}))n.add(a.id);const r=[];for await(const e of Ce(t,{from:[a],until:[...n]}))r.push(e.id);return r},Jm=async(e,a)=>{await Xi(e),await Ji(e,"revert"),await to(e);const n=await Zi(e);if("symbolic"!==n.kind)throw o("revert","cannot revert with detached HEAD");const r=await(async(e,a)=>{try{return await pe(e,a)}catch(e){if(e instanceof t&&"REF_NOT_FOUND"===e.data.code)throw H();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=Ym.exec(n);if(null===e){a.push(await Is(t,n));continue}const r=await is(t,e[1]),i=await is(t,e[2]);a.push(...await Xm(t,r,i))}return a})(e,a.commits);return await kd(e,await Ts(e,r)),!0===a.noCommit?(async(t,e)=>{const a=await Yt(t);try{let n=await Xt(t);for(let r=0;r<e.length;r+=1){const i=e[r],o=await Es(t,i);if(Bm(o))throw J(i);const s=o.parents[0],c=void 0!==s?await Ts(t,s):await Fm(t),d=await Ye(t,n.entries),u=await Qc(t,{baseTree:o.tree,oursTree:d,theirsTree:c,currentIndex:n,labels:Kr(i,Xn(o.message))});if("would-overwrite"===u.kind)throw M({localChanges:u.localChanges,untracked:u.untracked});if("conflict"===u.kind)return await a.commit(u.indexEntries),{kind:"conflict",commit:i,conflicts:zm(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):Km(e,i,n.target,r,{multiPick:i.length>1,sequenceHead:r,onEmpty:"stop"})},Zm=async t=>{await Xi(t),await Ji(t,"revert --continue");const e=await uu(t),a=await ud(t);if(void 0===e&&(void 0===a||0===a.length))throw i("revert");const n=await Zi(t);if("symbolic"!==n.kind)throw o("revert --continue","cannot continue with detached HEAD");let r=await pe(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 Xt(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 Ye(t,n.entries);if(r===await Ts(t,a))return{empty:!0};const i=await(async(t,e,a,n)=>{const r=await Td(t),i=Id(Ed(await Fi(t)??""),{allowEmpty:!1}),o=await ca(t,{tree:n,parents:[e],author:r,committer:r,message:i,extraHeaders:[]});return await Zt(t,a,o,{expected:e,reflogMessage:`commit: ${Xn(i)}`}),o})(t,a,e,r);return await fu(t),await Gi(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 sd(t)??r,u=void 0===e?"drop":"stop",f=await Km(t,c,n.target,r,{multiPick:!0,sequenceHead:d,onEmpty:u});return"reverted"===f.kind?{kind:"reverted",commits:[...s,...f.commits]}:f},Qm=async t=>{await Xi(t),await Ji(t,"revert --skip");const e=await uu(t),a=await ud(t);if(void 0===e&&(void 0===a||0===a.length))throw i("revert");const n=await Ds(t,"revert --skip"),r=await pe(t,n);await no(t,r),await fu(t),await Gi(t);const o=(a??[]).slice(1).map(t=>t.oid),s=await sd(t)??r;return Km(t,o,n,r,{multiPick:!0,sequenceHead:s,onEmpty:"stop"})},tp=async t=>{await Xi(t),await Ji(t,"revert --abort");const e=await uu(t),a=await sd(t);if(void 0===e&&void 0===a)throw i("revert");const n=await Ds(t,"revert --abort"),r=a??await pe(t,n);return await wd(t,{branch:n,target:r,clearHead:fu}),{head:r,branch:n}},ep=(t,e)=>Object.freeze({run:a=>(e(),Jm(t,a)),continue:()=>(e(),Zm(t)),skip:()=>(e(),Qm(t)),abort:()=>(e(),tp(t))}),ap=(t,e)=>void 0===t||t(e),np=t=>({kind:"delete",path:t.path,mode:t.mode,id:void 0,previousId:t.id,previousMode:t.mode}),rp=t=>({kind:"add",path:t.path,mode:t.mode,id:t.id,previousId:void 0,previousMode:void 0}),ip=t=>({kind:"noop",path:t.path,mode:t.mode,id:t.id,previousId:t.id,previousMode:t.mode}),op={ctimeSeconds:0,ctimeNanoseconds:0,mtimeSeconds:0,mtimeNanoseconds:0,dev:0,ino:0,uid:0,gid:0,fileSize:0},sp=t=>({...op,mode:t.mode,id:t.id,flags:{...$t,skipWorktree:!0},path:t.path}),cp=t=>t.flags.skipWorktree?{...t,flags:{...t.flags,skipWorktree:!1}}:t,dp=async(t,e)=>{const a=t.layout.workDir,n=await Yt(t);try{const r=(await Xt(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(ap(n.matcher,s.path)){r.push(s);continue}const a=te(e,s.path),c=await t.fs.exists(a);c&&await ln(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?np(t):ip(t));for(const r of a.included){const a=await t.fs.exists(te(e,r.path));n.push(a?ip(r):rp(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 fn(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)??cp(e));for(const{entry:e}of t.removable)n.push(sp(e));for(const e of t.retained)n.push(cp(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()}},up=async t=>{await Xi(t),await Ji(t,"sparse-checkout"),await to(t)},fp=async t=>{await up(t);const e=await Ft(t);if(!0!==e.core?.sparseCheckout)return{cone:!1,patterns:[]};const a=!0===e.core.sparseCheckoutCone,n=await hn(t)??"";return"cone"===(r=mn(n,a).spec).mode?{cone:!0,patterns:[...r.recursive].sort()}:{cone:!1,patterns:r.rules.map(t=>t.source)};var r},lp=(t,e)=>void 0===e?{matcher:t}:{matcher:t,force:e},hp=async(t,e,a,n)=>{const r=await dp(t,lp(vn(e),n));return await yn(t,a),await wn(t,{sparseCheckout:"true",sparseCheckoutCone:"cone"===e.mode?"true":"false"}),bp("cone"===e.mode,r)},wp=async(t,e)=>{if(await up(t),0===e.patterns.length)throw u("patterns","set requires at least one pattern");const a=await Ft(t),n=e.cone??a.core?.sparseCheckoutCone??!0,{spec:r,text:i}=yp(n,e.patterns);return hp(t,r,i,e.force)},mp=async(t,e)=>{if(await up(t),0===e.patterns.length)throw u("patterns","add requires at least one pattern");const a=await Ft(t);if(!0!==a.core?.sparseCheckout)throw u("action","add requires sparse checkout to be enabled");const n=!0===a.core.sparseCheckoutCone,r=await hn(t)??"",{spec:i,text:o}=vp(n,r,e.patterns);return hp(t,i,o,e.force)},pp=async(t,e)=>{await up(t);const a=await Gt(t);if(void 0===a)throw u("action","reapply requires sparse checkout to be enabled");const n=await Ft(t),r=await dp(t,lp(a,e?.force));return bp(!0===n.core?.sparseCheckoutCone,r)},gp=async(t,e)=>{await up(t);const a=await dp(t,lp(void 0,e?.force));return await wn(t,{sparseCheckout:"false"}),bp(!1,a)},yp=(t,e)=>{if(t){const t=pn(e);return{spec:t,text:gn(t)}}const a=e.join("\n");return{spec:mn(a,!1).spec,text:a}},vp=(t,e,a)=>{if(t){const t=mn(e,!0).spec,n="cone"===t.mode?[...t.recursive,...a]:a,r=pn(n);return{spec:r,text:gn(r)}}const n=(""===e?a:[e,...a]).join("\n");return{spec:mn(n,!1).spec,text:n}},bp=(t,e)=>({cone:t,materialized:e.materialized,removed:e.removed,retained:e.retained}),kp=(t,e)=>Object.freeze({list:()=>(e(),fp(t)),set:a=>(e(),wp(t,a)),add:a=>(e(),mp(t,a)),reapply:a=>(e(),pp(t,a)),disable:a=>(e(),gp(t,a))}),$p="refs/stash",xp=new TextEncoder,Ip=(t,e)=>Me(t,$p,Se(t.layout.gitDir,$p),xp.encode(`${e}\n`)),Ep=async t=>{const e=await me(t,$p),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}})},Tp=async(t,e)=>{const a=await Vt(t,e);if("commit"!==a.type)throw Kt("commit",a.type,e);return a.data.tree},Dp=async(t,e,a)=>{const n=te(t.layout.workDir,e),r=a.isSymbolicLink?(new TextEncoder).encode(await t.fs.readlink(n)):await t.fs.read(n);return{id:await Tn(t,r,{write:!0}),mode:ce(a)}},Mp=async(e,a={})=>{await Xi(e),await Ji(e,"stash"),await to(e);const n=await Zi(e),r=await(async(e,a)=>{const n=await(async(e,a)=>{if("direct"===a.kind)return a.id;try{return await pe(e,a.target)}catch(e){if(e instanceof t&&"REF_NOT_FOUND"===e.data.code)throw H();throw e}})(e,a),r=await Vt(e,n);if("commit"!==r.type)throw Kt("commit",r.type,n);return{b:n,bTree:r.data.tree,branchRef:"symbolic"===a.kind?a.target:void 0,subject:Xn(r.data.message)}})(e,n),i=await Yt(e);try{const t=await Xt(e),n=await Ye(e,t.entries),o=await(async(t,e)=>{const a=[];let n=!1;const r=await ee(t);for(const i of e.entries){if(0!==i.flags.stage)continue;if(i.flags.skipWorktree){a.push(i);continue}const e=await ta(t,i,r);if("absent"===e){n=!0;continue}if("unchanged"===e){a.push(i);continue}n=!0;const o=await t.fs.lstat(te(t.layout.workDir,i.path)),{id:s,mode:c}=await Dp(t,i.path,o);a.push(Vc(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 ae(t),r=[],i=[];for await(const{path:e,stat:o}of ne(t,{ignore:n})){if(a.has(e))continue;const{id:n,mode:s}=await Dp(t,e,o);i.push(Vc(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 Sp(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 ge(t).resolveDirect($p);return"direct"===e.kind?e.id:Oe})(t);await Ip(t,e);const r=await kn(t);await $n(t,$p,{oldId:n,newId:e,identity:r,message:xn(a)})})(e,c.stash,c.message),await Hp(e,i,{base:r,iTree:n,untracked:s,opts:a}),{kind:"saved",stash:c.stash,message:c.message}}finally{await i.release()}},Sp=async(t,e)=>{const{base:a,iTree:n,working:r,untracked:i,opts:o}=e,s=await kn(t),c=(d=a.branchRef,d?.startsWith("refs/heads/")?d.slice(11):"(no branch)");var d;const u=Fr(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)=>ca(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 Ye(t,r.entries);if(0===i.paths.length)return{stash:await h(m,[a.b,w],l),message:l};const p=await Ye(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}},Ap=async t=>(await Xi(t),{entries:await Ep(t)}),Op=async(t,e={})=>(await Xi(t),await Ji(t,"stash drop"),(async(t,e)=>{const a=await me(t,$p),n=a.length-1-e,r=a[n];if(void 0===r)throw Z(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 ge(t).removeLoose($p),await bn(t,$p),{dropped:r.newId,remaining:0};const s=o[o.length-1];return await Ip(t,s.newId),await Ae(t,$p,o),{dropped:r.newId,remaining:o.length}})(t,e.index??0)),Hp=async(t,e,a)=>{const{base:n,iTree:r,untracked:i,opts:o}=a,s=await Xt(t),c=!0===o.keepIndex?r:n.bTree,d=await Jt(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 aa(t,e)},Cp=async(t,e={})=>{await Xi(t),await Ji(t,"stash apply"),await to(t);const a=await(async(t,e)=>{const a=await me(t,$p),n=a[a.length-1-e];if(void 0===n)throw Z(e,a.length);return n.newId})(t,e.index??0),n=await(async(t,e)=>{const a=await Vt(t,e);if("commit"!==a.type)throw Kt("commit",a.type,e);const[n,r,i]=a.data.parents;if(void 0===n||void 0===r)throw In("ref does not point at a stash commit");return{base:n,indexParent:r,untrackedParent:i,wTree:a.data.tree}})(t,a),r=await Tp(t,n.base),i=void 0!==n.untrackedParent?await Tp(t,n.untrackedParent):void 0,o=await Yt(t);try{const s=await Xt(t),c=await Ye(t,s.entries);if(void 0!==i){const e=await(async(t,e)=>{const a=await Ie(t,e),n=[];for(const e of a.entries.keys())await t.fs.exists(te(t.layout.workDir,e))&&n.push(e);return n})(t,i);if(e.length>0)throw Q(e)}const d=await Qc(t,{baseTree:r,oursTree:c,theirsTree:n.wTree,currentIndex:s,labels:Yr});if("would-overwrite"===d.kind)throw Q([...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 Tp(t,a.indexParent),r=await(async(t,e)=>{const[a,n,r]=await Promise.all([void 0!==e.baseTree?Ie(t,e.baseTree):Promise.resolve(void 0),Ie(t,e.oursTree),Ie(t,e.theirsTree)]),i=await bi(a,n,r,Wc(t,e.labels),e.labels);return i.cleanMerge?{kind:"clean",mergedTree:await Xc(t,i.outcomes)}:{kind:"conflict",conflicts:i.conflicts}})(t,{baseTree:a.bTree,oursTree:a.cTree,theirsTree:n,labels:Yr});if("clean"!==r.kind)return;const i=await En(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 Ie(t,e);for(const[e,n]of a.entries){const a=await ra(t,n.id);await ia(t,e,a)}})(t,i),{kind:"applied",stash:a})}finally{await o.release()}},Np=async(t,e={})=>{const a=await Cp(t,e);if("conflict"===a.kind)return a;const n=await Op(t,{index:e.index??0});return{kind:"applied",stash:a.stash,dropped:n.dropped}},Pp=(t,e)=>Object.freeze({push:a=>(e(),Mp(t,a)),list:()=>(e(),Ap(t)),apply:a=>(e(),Cp(t,a)),pop:a=>(e(),Np(t,a)),drop:a=>(e(),Op(t,a))}),Rp=t=>t.split("/").length,Up=(t,e)=>`${"../".repeat(2+Rp(t))}${e}`,Lp="./",_p="../",jp=t=>t.startsWith("/"),Wp=t=>{const e=t.indexOf(":"),a=t.indexOf("/");return e<0||a>=0&&a<e},Bp=(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}},zp=(t,e)=>e.startsWith(Lp)||e.startsWith(_p)?((t,e)=>{if(!Wp(e)||jp(e))return e;let a=t.endsWith("/")?t.slice(0,-1):t;const n=Wp(a)&&!jp(a);n&&(a=(t=>t.startsWith(Lp)||t.startsWith(_p)?t:`${Lp}${t}`)(a));let r=e,i=!1;for(;r.length>0;)if(r.startsWith(_p)){r=r.slice(3);const t=Bp(a,n);a=t.base,i=i||t.colonSep}else{if(!r.startsWith(Lp))break;r=r.slice(2)}const o=`${a}${i?":":"/"}${r}`,s=r.endsWith("/")?o.slice(0,-1):o;return s.startsWith(Lp)?s.slice(2):s})(t,e):e,Fp=new Set(["checkout","rebase","merge","none"]),qp=t=>Fp.has(t)?t:void 0,Gp=".gitmodules",Vp="refs/heads/",Kp="HEAD",Yp=t=>void 0!==t.path&&!_a(t.path),Xp=async t=>{const e=te(t.layout.workDir,Gp);if(!await t.fs.exists(e))return[];const a=await t.fs.stat(e);if(a.size>On)throw l(e,a.size,On);return Hn(await t.fs.readUtf8(e))},Jp=t=>{const e=new Map;for(const a of t){if(void 0===a.update)continue;const t=qp(a.update);if(void 0===t)throw u(`submodule.${a.name}.update`,`invalid value '${a.update}'`);e.set(a.name,t)}return e},Zp=(t,e)=>{const a=t.filter(Yp);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},Qp=async(t,e)=>{const a=await ge(t).resolveDirect(Kp),n="symbolic"===a.kind&&a.target.startsWith(Vp)?a.target.slice(11):void 0,r=(void 0!==n?e.branch?.get(n)?.remote:void 0)??"origin";return e.remote?.get(r)?.url??t.layout.workDir},tg=(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},eg=async(t,e={})=>{await Xi(t);const a=await Xp(t),n=Jp(a),r=Zp(a,e.paths),i=await Ft(t),o=await Qp(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=zp(o,t.url);c.push(...tg(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 un(t,c),{entries:s}},ag=async(t,e,a,n)=>{const r=await Cn(t,e,a);return void 0!==r&&(await un(r,[{kind:"set",section:"remote",subsection:"origin",key:"url",value:n}]),!0)},ng=async(t,e,a,n)=>{await Xi(t);const r=Zp(await Xp(t),e.paths),i=await Ft(t),o=await Qp(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=zp(o,e.url);c.push({kind:"set",section:"submodule",subsection:e.name,key:"url",value:n});const r=await ag(t,e.name,a,n);s.push({name:e.name,path:a,url:n,syncedRemote:r})}if(c.length>0&&await un(t,c),!0===e.recursive&&a<Pn)for(const i of r){const r=`${t.layout.gitDir}/modules/${i.name}`,o=await Cn(t,i.name,i.path,n);void 0!==o&&await ng(o,e,a+1,new Set([...n,r]))}return{entries:s}},rg=(t,e={})=>ng(t,e,0,new Set),ig=async(e,a,n)=>{const r=await Cn(e,a,n);if(void 0!==r&&!(await uf(r)).clean)throw(e=>new t({code:"SUBMODULE_HAS_MODIFICATIONS",path:e}))(n)},og=async(t,e)=>{const a=te(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)},sg=async(t,e={})=>{if(await Xi(t),(void 0===e.paths||0===e.paths.length)&&!0!==e.all)throw u("submodule.deinit","use 'all: true' to deinitialise every submodule");const a=await Xp(t),n=!0===e.all?a.filter(Yp):Zp(a,e.paths),r=await Ft(t),i=[];for(const a of n){const n=a.path;!0!==e.force&&await ig(t,a.name,n);const o=await og(t,n);!0===r.submodule?.has(a.name)&&await un(t,[{kind:"removeSection",section:"submodule",subsection:a.name}]),i.push({name:a.name,path:n,url:a.url??"",cleared:o})}return{entries:i}},cg=async(t,e={})=>{await Xi(t);const a=(t=>Nn(t)?_t.from(t):be(t))(e.ref??"HEAD"),n=!0===e.recursive,r=[];for await(const i of Sn(t,{ref:a,recursive:n,...void 0!==e.maxDepth?{maxDepth:e.maxDepth}:{}}))r.push(i);return{entries:r}},dg=(t,e,a)=>({kind:"set",section:"submodule",subsection:t,key:e,value:a}),ug=async(t,e,a,n,r)=>{await eu(e,{url:a}),await un(e,[{kind:"set",section:"core",key:"worktree",value:Up(n,r)}]),await t.fs.writeUtf8(te(t.layout.workDir,`${r}/.git`),`${((t,e)=>`gitdir: ${"../".repeat(Rp(e))}.git/modules/${t}`)(n,r)}\n`)},fg=async(e,a)=>{await Xi(e),await Ji(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(_a(t))throw u("submodule.add.name",`unsafe name '${t}'`);if(_a(e))throw u("submodule.add.path",`unsafe path '${e}'`)})(n,a.path,a.url),void 0!==a.branch&&be(`${Vp}${a.branch}`),await(async(e,a)=>{if((await Xt(e)).entries.some(t=>t.path===a))throw(e=>new t({code:"SUBMODULE_PATH_EXISTS",path:e}))(a)})(e,a.path);const r=await Ft(e),i=await Qp(e,r),o=zp(i,a.url),s=Dn(e,n,a.path);await ug(e,s,o,n,a.path),void 0!==a.branch?await(async(t,e)=>{const a=await pe(t,`refs/remotes/origin/${e}`),n=`${Vp}${e}`;await t.fs.writeUtf8(`${t.layout.gitDir}/${n}`,`${a}\n`),await Ke(t,n,Oe,a,`branch: Created from origin/${e}`),await un(t,[{kind:"set",section:"branch",subsection:e,key:"remote",value:"origin"},{kind:"set",section:"branch",subsection:e,key:"merge",value:n}]),await Pc(t,{rev:e})})(s,a.branch):await Mn(s);const c="symbolic"===(l=await ge(s).resolveDirect(Kp)).kind&&!0===l.target?.startsWith(Vp)?l.target.slice(11):"",d=await pe(s,Kp),f=await(async(t,e,a,n,r)=>{const i=te(t.layout.workDir,Gp),o=await t.fs.exists(i)?await t.fs.readUtf8(i):"",s=[dg(e,"path",a),dg(e,"url",n)];void 0!==r&&s.push(dg(e,"branch",r));let c=o;for(const t of s)c=An(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 ie(t,{type:"blob",id:"",content:n}),i=await Yt(t);try{const n=await Xt(t),o=new Map(n.entries.map(t=>[t.path,t])),s=await t.fs.lstat(te(t.layout.workDir,e));o.set(e,io(s,Nt.GITLINK,a,e));const c=await t.fs.lstat(te(t.layout.workDir,Gp));o.set(Gp,io(c,Nt.REGULAR,r,Gp)),await i.commit([...o.values()])}finally{await i.release()}})(e,a.path,d,f),await un(e,[dg(n,"url",o),dg(n,"active","true")]),{name:n,path:a.path,url:o,id:d,branch:c}},lg=(t,e)=>t.entries.find(t=>t.path===e&&t.mode===Nt.GITLINK)?.id,hg=(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:qp(r);if(void 0!==r&&void 0===i)throw u(`submodule.${n}.update`,`invalid value '${r}'`);return i??a??"checkout"},wg=async(t,e,a)=>{if("checkout"===a){const a=await ge(t).resolveDirect(Kp);return("direct"!==a.kind||a.id!==e)&&(await Pc(t,{rev:e,detach:!0}),!0)}const n=await pe(t,Kp);return"rebase"===a?await im(t,{upstream:e}):await jh(t,{rev:e}),await pe(t,Kp)!==n},mg=async(t,e={})=>{await Xi(t),await Ji(t,"submodule update");const a=await Xp(t),n=Zp(a,e.paths),r=Jp(a),i=await Xt(t);let o=await Ft(t);const s=[];for(const a of n){const n=lg(i,a.path);if(void 0===n)continue;if(await sa(t,"submodule",a.name,["update"]),void 0===o.submodule?.get(a.name)?.url){if(await sa(t,"submodule",a.name,["url"]),!0!==e.init)continue;await eg(t,{paths:[a.path]}),o=await Ft(t)}const c=hg(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=Dn(t,a.name,a.path),f=!await t.fs.exists(`${u.layout.gitDir}/HEAD`);f&&(await ug(t,u,d,a.name,a.path),await Mn(u)),await Vt(u,n);const l=await wg(u,n,c);s.push({name:a.name,path:a.path,id:n,mode:c,cloned:f,changed:l})}return{entries:s}},pg=(t,e)=>Object.freeze({list:a=>(e(),cg(t,a)),add:a=>(e(),fg(t,a)),init:a=>(e(),eg(t,a)),update:a=>(e(),mg(t,a)),sync:a=>(e(),rg(t,a)),deinit:a=>(e(),sg(t,a))}),gg="refs/tags/",yg=async t=>{await Xi(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=`${gg}${e.name}`,r=await pe(t,a);n.push({name:a,id:r})}return n.sort((t,e)=>t.name<e.name?-1:1),{tags:n}},vg=async(e,a)=>{await Xi(e);const n=be(`${gg}${a.name}`),r=void 0!==a.target?a.target:await kg(e),i=/^[0-9a-f]{40}$/.test(r)?r:await pe(e,r),o=`tag: ${a.name}`;try{await Zt(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 tt(n);throw e}return{name:n,id:i}},bg=async(t,e)=>{await Xi(t);const a=be(`${gg}${e.name}`);if(!await t.fs.exists(`${t.layout.gitDir}/${a}`))throw et(a);return await Zt(t,a,Oe,{delete:!0}),{name:a}},kg=async t=>{const e=await Zi(t);return"direct"===e.kind?e.id:pe(t,e.target)},$g=(t,e)=>Object.freeze({list:()=>(e(),yg(t)),create:a=>(e(),vg(t,a)),delete:a=>(e(),bg(t,a))}),xg=t=>`${t}/.git`,Ig=e=>new t({code:"WORKTREE_PATH_EXISTS",path:e}),Eg=t=>{const e=t.split("/").filter(t=>""!==t);return e[e.length-1]??""},Tg=(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("/")}`},Dg=(t,e)=>t.worktreeFs?.(e)??t.fs,Mg=(t,e,a)=>{const n=fe(t),r=`${n}/worktrees/${e}`,{promisor:i,hooks:o,command:s,...c}=t;return Object.freeze({...c,fs:Dg(t,a),layout:Object.freeze({workDir:a,gitDir:r,commonDir:n,bare:!1,...void 0!==t.layout.homeDir?{homeDir:t.layout.homeDir}:{}}),cwd:a})},Sg=async(t,e)=>{const a=Wt(e);if("direct"===a.type)return{head:a.target,detached:!0};const n=await ge(t).resolveDirect(a.target);return{branch:a.target,detached:!1,..."direct"===n.kind?{head:n.id}:{}}},Ag=async(t,e,a)=>{const n=(await t.fs.readUtf8(`${a}/gitdir`)).trim(),r=n.endsWith("/.git")?n.slice(0,-5):n,i=await Sg(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=Dg(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}:{}}},Og=(t,e)=>t.path<e.path?-1:t.path>e.path?1:0,Hg=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(`${fe(t)}/HEAD`);return{path:e,bare:!1,main:!0,...await Sg(t,a)}})(t),a=`${fe(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 Ag(t,e.name,`${a}/${e.name}`));return n.sort(Og),[e,...n]},Cg="HEAD",Ng="refs/heads/",Pg=async t=>(await Xi(t),{entries:await Hg(t)}),Rg=async(t,e)=>{const a=Dg(t,e);if(await a.exists(e)&&(await a.readdir(e)).length>0)throw Ig(e)},Ug=async(e,a)=>{if(await Xi(e),""===a.path)throw Ig("");const n=Tg(e.cwd,a.path);if(""===(r=Eg(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 Rg(e,n);const i=await ef(e,a.commitish??"HEAD"),o=await we(e,i),s=await(async(t,e,a)=>{if(void 0!==e.branch)return{kind:"create",branchRef:`${Ng}${e.branch}`,name:e.branch};if(!0===e.detach)return{kind:"detached"};if(void 0!==e.commitish){const a=`${Ng}${e.commitish}`;return"direct"===(await ge(t).resolveDirect(a)).kind?{kind:"checkout",branchRef:a}:{kind:"detached"}}const n=Eg(a);return{kind:"create",branchRef:`${Ng}${n}`,name:n}})(e,a,n);"checkout"===s.kind&&await(async(e,a,n)=>{if(n)return;const r=(await Hg(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 Xs(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=`${fe(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})(Eg(e),new Set(n))})(e,n);await(async(t,e,a,n,r)=>{const i=`${fe(t)}/worktrees/${e}`;var o;return await t.fs.writeUtf8(`${i}/commondir`,"../..\n"),await t.fs.writeUtf8(`${i}/gitdir`,`${xg(a)}\n`),await t.fs.writeUtf8(`${i}/HEAD`,`${(t=>"branch"===t.kind?`ref: ${t.ref}`:t.oid)(n)}\n`),await t.fs.writeUtf8(`${i}/ORIG_HEAD`,`${r}\n`),await Dg(t,a).writeUtf8(`${a}/.git`,(o=i,`gitdir: ${o}\n`)),i})(e,d,n,c,i);const f=Mg(e,d,n);return await(async(t,e)=>{const a=await Yt(t);try{const n=await Xt(t),r=await Jt(t,{targetTree:e,currentIndex:n});await a.commit(r.newIndexEntries)}finally{await a.release()}})(f,o.id),await(async(t,e,a)=>{await Ke(t,Cg,Oe,a,""),"detached"!==e.kind&&await Ke(t,Cg,a,a,"reset: moving to HEAD")})(f,s,i),{path:n,id:d,head:i,detached:"detached"===s.kind,..."detached"!==s.kind?{branch:s.branchRef}:{}}},Lg=async(e,a,n)=>{const r=(await Hg(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},_g=(e,a)=>{if(void 0!==e.locked&&!a)throw new t({code:"WORKTREE_LOCKED",path:e.path,reason:e.locked.reason})},jg=async(t,e,a,n={})=>{await Xi(t);const r=Tg(t.cwd,e),i=Tg(t.cwd,a),o=await Lg(t,r,"move");_g(o,!0===n.force),await Rg(t,i),await Dg(t,[r,i]).rename(r,i);const s=`${fe(t)}/worktrees/${o.id}`;return await t.fs.writeUtf8(`${s}/gitdir`,`${xg(i)}\n`),{from:r,to:i,id:o.id}},Wg=async(e,a,n={})=>{await Xi(e);const r=Tg(e.cwd,a),i=await Lg(e,r,"remove");if(_g(i,!0===n.force),!0!==n.force){const a=Mg(e,i.id,r);if(!(await uf(a)).clean)throw(e=>new t({code:"WORKTREE_DIRTY",path:e}))(r)}return await Dg(e,r).rmRecursive(r),await e.fs.rmRecursive(`${fe(e)}/worktrees/${i.id}`),{path:r,id:i.id}},Bg=(t,e)=>Object.freeze({list:()=>(e(),Pg(t)),add:a=>(e(),Ug(t,a)),move:(a,n,r)=>(e(),jg(t,a,n,r)),remove:(a,n)=>(e(),Wg(t,a,n))}),zg=(t,e)=>!(void 0!==e.minParents&&t<e.minParents||void 0!==e.maxParents&&t>e.maxParents),Fg=async(t,e={})=>{await Xi(t);const a=await ef(t,e.rev??"HEAD"),n=await Promise.all((e.excluding??[]).map(e=>ef(t,e))),r=e.before,i="first-parent"===e.order?Ce(t,{from:[a],until:n,order:"first-parent"}):Rn(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)&&zg(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},qg=async(t,e,a,n={})=>{await Xi(t),await Ji(t,"mv"),await to(t);const r=e.map(t=>oo(t)),[i]=r;if(void 0===i)throw f();Qg(r);const o=oo(iy(a)),s=await Yt(t);try{const e=await Gg(t),c=await Vg(t,i,a,o);if("rename"===c.kind&&r.length>1)throw at(i,c.target);const{planned:d,skipped:u}=await Kg(t,e,r,c,n);ty(d);const f=ey(d);if(!0===n.dryRun)return{moved:f,skipped:u};ay(e,d);for(const e of d)await uo(t,e.source,e.target);return await s.commit(Array.from(e.values())),{moved:f,skipped:u}}finally{await s.release()}},Gg=async e=>{const a=await Xt(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},Vg=async(t,e,a,n)=>{const r=await oy(t,n);if(!0===r?.isDirectory&&!0!==r.isSymbolicLink)return{kind:"into-dir",destDir:n};if(a.endsWith("/"))throw rt(e,a);return{kind:"rename",target:n}},Kg=async(t,e,a,n,r)=>{const i=[],o=[];for(const s of a){const a="rename"===n.kind?n.target:Un(n.destDir,it(s)),c=await Yg(t,e,s,a,r);if("skip"in c){if(!0===r.skipErrors){o.push({source:s,reason:c.skip});continue}throw ry(c.skip,s,a)}i.push({source:s,target:a,entries:c.entries})}return{planned:i,skipped:o}},Yg=async(t,e,a,n,r)=>{const i=Xg(e,a);if("untracked"===i.kind)return{skip:"source-not-tracked"};if(!await Jg(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 sy(t,o))throw rt(a,n);return await Zg(t,e,n,i.kind,!0===r.force)?{kind:i.kind,entries:i.entries}:{skip:"destination-exists"}},Xg=(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"}},Jg=async(t,e,a)=>{const n=await oy(t,e);return void 0!==n&&("directory"===a?n.isDirectory&&!n.isSymbolicLink:n.isFile||n.isSymbolicLink)},Zg=async(t,e,a,n,r)=>!(e.has(a)||void 0!==await oy(t,a))||"file"===n&&r,Qg=t=>{for(const e of t)for(const a of t)if(a!==e&&a.startsWith(`${e}/`))throw nt(a,e)},ty=t=>{const e=new Set;for(const a of t){if(e.has(a.target))throw ot(a.source,a.target);e.add(a.target)}},ey=t=>{const e=[];for(const a of t)for(const t of a.entries)e.push({from:t.path,to:ny(t,a.source,a.target)});return e.sort((t,e)=>t.from<e.from?-1:t.from>e.from?1:0)},ay=(t,e)=>{for(const a of e)for(const e of a.entries){const n=ny(e,a.source,a.target);t.delete(e.path),t.set(n,{...e,path:n})}},ny=(t,e,a)=>`${a}${t.path.slice(e.length)}`,ry=(t,e,a)=>{switch(t){case"source-not-tracked":return ut(e,a);case"bad-source":return dt(e,a);case"destination-exists":return ct(e,a);case"into-self":return st(e,a)}},iy=t=>t.endsWith("/")?t.slice(0,-1):t,oy=async(t,e)=>t.fs.lstat(((t,e)=>te(t.layout.workDir,e))(t,e)).catch(()=>{}),sy=async(t,e)=>{const a=await oy(t,e);return!0===a?.isDirectory&&!0!==a.isSymbolicLink},cy="refs/heads/",dy=async(t,e={})=>{await Xi(t),await Ji(t,"pull"),await to(t);const a=await Zi(t),n="symbolic"===a.kind?(r=a.target).startsWith(cy)?r.slice(11):r:void 0;var r;const i="symbolic"===a.kind?a.target:qt.from("HEAD"),{remote:o,branch:s}=await(async(t,e,a,n)=>{const r=await Ft(t);void 0!==e&&await sa(t,"branch",e,["remote","merge"]);const i=void 0!==e?r.branch?.get(e):void 0,o=a.remote??i?.remote??"origin",s=a.ref??(t=>{if(void 0!==t)return t.startsWith(cy)?t.slice(11):t})(i?.merge);if(void 0===s)throw ft(n);return{remote:o,branch:s}})(t,n,e,i),c=await Lf(t,{remote:o,...void 0!==e.prune?{prune:e.prune}:{},...void 0!==e.depth?{depth:e.depth}:{}}),d=await pe(t,`refs/remotes/${o}/${s}`);return{fetch:c,merge:await jh(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"})}},uy="push:enumerate-objects",fy="push:upload",ly=_t.from("0".repeat(40)),hy="refs/heads/",wy=new Set(["side-band-64k","side-band"]),my=async(t,e={})=>{await Xi(t),t.progress.start(uy);try{const a=e.remote??"origin",n=await vy(t,a),r=await by(t,e.refspecs),i=zd(t,void 0!==t.config?.auth?{auth:t.config.auth}:{}),o=await(async(t,e,a)=>Yd(t,e,a,"git-receive-pack"))(t,i,n),s=(await ky(t,r,o,a,e)).filter(t=>t.localOid!==t.remoteOid);return 0===s.length?{remote:a,url:n,pushedRefs:[]}:(await py(t,e.noVerify??!1,a,n,s),{remote:a,url:n,pushedRefs:await My(t,i,n,o,s,a)})}finally{t.progress.end(uy)}},py=async(t,e,a,n,r)=>{if(e)return;const i=r.map(gy).join("");await va(t,"pre-push",{args:[a,n],stdin:i})},gy=t=>`${t.parsed.isDelete?"(delete)":t.parsed.src} ${t.localOid} ${t.parsed.dst} ${t.remoteOid}\n`,yy=/^[A-Za-z0-9._-]+$/,vy=async(t,e)=>{if(!yy.test(e))throw u("remote",`invalid remote name: ${e}`);const a=await Ft(t);await sa(t,"remote",e,["pushurl","url"]);const n=a.remote?.get(e),r=n?.pushUrl??n?.url;if(void 0===r)throw F(e);return r},by=async(t,e)=>{if(void 0!==e&&e.length>0)return e.map(Em);const a=await Zi(t);if("symbolic"!==a.kind)throw u("refspecs","no-default-refspec (HEAD is detached)");const n=a.target;return[Em(`${n}:${n}`)]},ky=async(t,e,a,n,r)=>{const i=$y(a.refs),o=[];for(const a of e)o.push(await xy(t,a,i,n,r));return o},$y=t=>{const e=new Map;for(const a of t)e.set(a.name,a.id);return e},xy=async(t,e,a,n,r)=>{const i=a.get(e.dst)??ly;if(e.isDelete){if(i===ly)throw u("refspecs",`delete target ${e.dst} is not advertised`);return{parsed:e,localOid:ly,remoteOid:i}}const o=await pe(t,e.src);return await Iy(t,e,o,i,n,r),{parsed:e,localOid:o,remoteOid:i}},Iy=async(t,e,a,n,r,i)=>{const o=await Ey(t,e,r,i);if(void 0===o){if("force"!==e.force&&!0!==i.force&&n!==ly&&!await Ty(t,n,a))throw G(e.dst,a,n)}else if(o!==n)throw lt(e.dst,"lease-mismatch",Dy())},Ey=async(t,e,a,n)=>{if(void 0===n.forceWithLease)return;if("auto"!==n.forceWithLease)return n.forceWithLease;if(!e.dst.startsWith(hy))throw u("forceWithLease","lease-on-non-branch");const r=e.dst.slice(11);return pe(t,`refs/remotes/${a}/${r}`)},Ty=async(t,e,a)=>{for await(const n of Ce(t,{from:[a],ignoreMissing:!0}))if(n.id===e)return!0;return!1},Dy=()=>({unpackOk:!0,refUpdates:[]}),My=async(t,e,a,n,r,i)=>{const o=r.filter(t=>!t.parsed.isDelete).map(t=>t.localOid),s=n.refs.map(t=>t.id),c=await Sy(t,o,s),d=await je(t,{oids:c}),u=(t=>{const e=Ln.filter(t=>t!==ha);return[...la(t,e),ha]})(n.capabilities),f=(t=>{if(0===t.updates.length)throw Rt();const e=t.updates.map((e,a)=>((t,e)=>{const a=0===e.length?"":`\0${e.join(" ")}`;return Mi.encode(`${t.oldId} ${t.newId} ${t.name}${a}\n`)})(e,0===a?t.capabilities:[])),a=Ut(e),n=new Uint8Array(a.byteLength+t.packfile.byteLength);return n.set(a,0),n.set(t.packfile,a.byteLength),n})({updates:r.map(Ay),capabilities:u,packfile:d.bytes}),l=await Oy(t,e,a,f),h=await Cy(t,l,u);if(!h.unpackOk)throw lt(r[0]?.parsed.dst,h.unpackError??"unpack failed",h);return await Py(t,r,h.refUpdates,i)},Sy=async(t,e,a)=>{if(0===e.length)return[];const n=[];for await(const r of _n(t,{wants:e,haves:a}))n.push(r);return n},Ay=t=>({name:t.parsed.dst,oldId:t.remoteOid,newId:t.localOid}),Oy=async(t,e,a,n)=>{t.progress.start(fy);try{const r=Hy(a),i=await e.request({url:r,method:"POST",headers:{"content-type":"application/x-git-receive-pack-request",accept:"application/x-git-receive-pack-result"},body:n,...void 0!==t.signal?{signal:t.signal}:{}});if(200!==i.statusCode)throw N(i.statusCode,`git-receive-pack returned ${i.statusCode}`);return i}finally{t.progress.end(fy)}},Hy=t=>{let e;try{e=new URL(t)}catch{throw jn("invalid URL")}if(""!==e.hash)throw jn("fragment must not be set");const a=e.pathname.endsWith("/")?e.pathname.slice(0,-1):e.pathname;return`${e.protocol}//${e.host}${a}/git-receive-pack${e.search}`},Cy=async(t,e,a)=>{const n=Gn(e.body),r=fa(n);if(Ny(a)){const e=Wn(r,{onProgress:e=>t.progress.update(fy,0,void 0,ht(e))});return Oi(fa(e))}return Oi(r)},Ny=t=>t.some(t=>wy.has(t)),Py=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 Ry(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},Ry=async(t,e,a)=>{if(!e.parsed.dst.startsWith(hy))return;if(e.parsed.isDelete)return;const n=`refs/remotes/${a}/${e.parsed.dst.slice(11)}`;Uy(n)&&await Zt(t,n,e.localOid,{reflogMessage:"update by push"})},Uy=t=>{try{return be(t),!0}catch{return!1}},Ly=new TextEncoder,_y=65536,jy=t=>0|t,Wy=(t,e,a)=>t.cost[e+t.columnCount*a],By=(t,e,a)=>{const n=0===a?1:0;let r=jy(Wy(t,n,e)-t.v[n]);for(let n=1;n<t.columnCount;n++){const i=jy(Wy(t,n,e)-t.v[n]);n!==a&&r>i&&(r=i)}t.v[a]=jy(t.v[a]-r)},zy=(t,e,a,n,r)=>{const i=((t,e)=>{let a=0,n=jy(Wy(t,a,e)-t.v[a]),r=-1,i=_y;for(let o=1;o<t.columnCount;o++){const s=jy(Wy(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]=jy(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}},Fy=(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}},qy=(t,e,a)=>{for(let n=a.low;n<a.up;n++)if(-1===t.columnToRow[e[n]])return!0;return!1},Gy=(t,e,a,n,r,i)=>{do{const o=n[r.low++],s=t.columnToRow[o],c=jy(Wy(t,o,s)-t.v[o]-i);for(let o=r.up;o<t.columnCount;o++){const d=n[o],u=jy(Wy(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},Vy=(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]=jy(Wy(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}=Fy(t,e,n,r);if(qy(t,n,r))return{j:s,last:i,min:o};const c=Gy(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]=jy(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)},Ky=(t,e,a)=>t<0?Math.trunc(e*a/100):_y,Yy=(t,e,a,n,r)=>{return a===r?0:a<0&&n<0?(i=e.diff,Dr(Ly.encode(t.diff),Ly.encode(i),3).reduce((t,e)=>t+1+e.body.length,0)):_y;var i},Xy=(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]=Yy(t[d],e[r],a[d],n[r],r);const i=Ky(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=Ky(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++)Wy(t,e,a)>Wy(t,e,n)&&(a=n);t.v[e]=Wy(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:By(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=zy(t,e,r,a,n);a=i.k,n=i.freeCount}}return n})(r,i,o);for(let t=0;t<o;t++)Vy(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]}))}},Jy=new TextEncoder,Zy=(t,e)=>({position:e+1,id:t.id}),Qy=(t,e)=>({status:"only-old",old:Zy(t.patch,e),subject:t.patch.subject}),tv=(t,e)=>({status:"only-new",new:Zy(t.patch,e),subject:t.patch.subject}),ev=(t,e,a,n)=>{const r=t.patch.patch!==e.patch.patch;return{status:r?"changed":"unchanged",old:Zy(t.patch,a),new:Zy(e.patch,n),subject:t.patch.subject,...r?{diffOfDiffs:It(Jy.encode(t.patch.patch),Jy.encode(e.patch.patch))}:{}}},av=new TextDecoder("utf-8",{fatal:!1}),nv=t=>32===t||t>=9&&t<=13,rv=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&&nv(t[a-1]);)a--;return av.decode(t.subarray(0,a))},iv=(t,e,a)=>{const n=e>a?-1:1;for(let r=e;r!==a&&r>=0&&r<t.length;r+=n){const e=rv(t[r]);if(void 0!==e)return{index:r,heading:e}}},ov=new Uint8Array,sv=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})`,cv=t=>"delete"===t.type?t.oldPath:"add"===t.type||"rename"===t.type||"copy"===t.type?t.newPath:t.path,dv=t=>{const e=`${a=t.kind,"context"===a?" ":"delete"===a?"-":"+"}${t.text}`;var a;return t.trailingNoNewline?[e," \"]:[e]},uv=t=>t.oldLen>0?t.oldStart-1:t.oldStart,fv=t=>{const e=t.oldContent??ov,a=t.newContent??ov;return Et(e)||Et(a)?{lines:[lv(t,e,a)],count:1}:((t,e,a)=>{const n=xt(t),r=[];let i=-1,o="";for(const t of e){const e=uv(t),s=iv(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 dv(e))r.push(t)}return{lines:r,count:r.length}})(e,Dr(e,a,3),cv(t.change))},lv=(t,e,a)=>` Binary files ${0===e.length?"/dev/null":cv(t.change)} and ${0===a.length?"/dev/null":cv(t.change)} differ`,hv=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=` ## ${sv(e.change)} ##`,{lines:r,count:i}=fv(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}},wv=async(t,e)=>{const a=e.data.parents[0],n=void 0!==a?await(async(t,e)=>{const a=await Vt(t,e);if("commit"!==a.type)throw Kt("commit",a.type,e);return a.data.tree})(t,a):void 0,r=await Te(t,n,e.data.tree,{recursive:!0,detectRenames:!0}),i=await cn(t,r.changes);return{id:e.id,authorName:e.data.author.name,authorEmail:e.data.author.email,subject:Jn(e.data.message),message:e.data.message,files:i}},mv=async(t,e)=>{const a=await ef(t,e.base),n=await ef(t,e.tip),r=[];for await(const e of Rn(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 wv(t,e[r])}})())),a})(t,r)},pv=async(t,e)=>{await Xi(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(hv),r=e.map(hv),{old:i,new:o}=Xy(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(Qy(t[r],r)),r++;else{for(;i<e.length&&e[i].matching<0;)a.push(tv(e[i],i)),i++;if(i<e.length){const r=e[i].matching;a.push(ev(t[r],e[i],r,i)),n[r]=!0,i++}}}return a})(i,o)})(await mv(t,e.old),await mv(t,e.new),a)},gv=async(t,e,a,n)=>{await Xi(t);const r=await is(t,e),i=await we(t,r),o=await Ro(t,i,a,e),s=await $e(t,o.id,n);return{id:o.id,mode:o.mode,content:s.content}},yv=t=>be(t),vv=async(t,e={})=>(await Xi(t),"exists"===e.action?kv(t,e.ref):"delete"===e.action?$v(t,e):"expire"===e.action?Iv(t,e):bv(t,e.ref??"HEAD")),bv=async(t,e)=>{const a=yv(e),n=await me(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}},kv=async(t,e)=>({kind:"exists",exists:await ye(t,yv(e))}),$v=async(t,e)=>{const a=yv(e.ref);if(!await ye(t,a))throw Bn(a);const n=await me(t,a);if(!Number.isInteger(e.index)||e.index<0)throw ve(a,e.index,n.length);const r=n.length-1-e.index;if(r<0)throw ve(a,e.index,n.length);const i=n[r],o=xv(n,r,!0===e.rewrite);return await Ae(t,a,o),{kind:"delete",removed:i}},xv=(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)},Iv=async(t,e)=>{const a=Math.floor(Date.now()/1e3),n=Ev(e.expire??"90.days.ago",a),r=Ev(e.expireUnreachable??"30.days.ago",a),i=await Dv(t),o=!0===e.all?await za(t):[yv(e.ref??"HEAD")];let s=0,c=0;for(const e of o){const a=await me(t,e),o=a.filter(t=>Tv(t,i,n,r));s+=a.length-o.length,c+=o.length,o.length!==a.length&&await Ae(t,e,o)}return{kind:"expire",removed:s,kept:c}},Ev=(t,e)=>{const a=Pi(t,e);if(void 0===a)throw g(t);return a},Tv=(t,e,a,n)=>{const r=e.has(t.newId)?a:n;return t.identity.timestamp>=r},Dv=async t=>{const e=await Mv(t),a=new Set;if(0===e.length)return a;for await(const n of Ce(t,{from:e,ignoreMissing:!0}))a.add(n.id);return a},Mv=async t=>{const e=new Set;for(const a of await _e(t)){const n=await Sv(t,a);void 0!==n&&e.add(n)}return[...e]},Sv=async(e,a)=>{try{return await pe(e,a)}catch(e){if(e instanceof t)return;throw e}},Av=async(t,e)=>{await Xi(t),"hard"===e.mode&&await Ji(t,"reset --hard"),await to(t);const a=await Cv(t,e.rev);"mixed"===e.mode?await Ov(t,a):"hard"===e.mode&&await Hv(t,a);const n=await Zi(t),r="symbolic"===n.kind?n.target:void 0;return await Zt(t,r??"HEAD",a,{reflogMessage:`reset: moving to ${e.rev}`}),{mode:e.mode,id:a,branch:r}},Ov=async(t,e)=>{const a=await Vt(t,e);if("commit"!==a.type)throw Kt("commit",a.type,e);const n=await Gt(t),r=await Yt(t);try{const e=await Xt(t),i=await En(t,{targetTree:a.data.tree,currentIndex:e,...void 0!==n?{sparse:n}:{}});await r.commit(i)}finally{await r.release()}},Hv=async(t,e)=>{const a=await Vt(t,e);if("commit"!==a.type)throw Kt("commit",a.type,e);const n=await Gt(t),r=await Yt(t);try{const e=await Xt(t),i=await Jt(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()}},Cv=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 pe(t,e)}catch{}throw g(e)},Nv=async(e,a,n={})=>{if(await Xi(e),await Ji(e,"rm"),await to(e),0===a.length)throw f();const{matcher:r,literalMustMatch:i}=ho(a),o=await Yt(e);try{const a=await Xt(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)Pr(r,t)&&(c.push(t),d.push(e));po(i,c),!0!==n.force&&await Pv(e,d,!0===n.cached);for(const t of c)s.delete(t);if(!n.cached)for(const a of c)await co(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()}},Pv=async(t,e,a)=>{const n=await Uv(t),{both:r,stagedOnly:i,localOnly:o}=await(async(t,e,a,n)=>{const r=await ee(t),i=[],o=[],s=[];for(const c of e){const e=await ta(t,c,r);if("absent"===e)continue;const d=Qe(e),u=Rv(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 wt(r);if(i.length>0)throw mt(i);if(o.length>0)throw pt(o)},Rv=(t,e)=>{const a=t.get(e.path);return void 0===a||a.id!==e.id||a.mode!==e.mode},Uv=async t=>(await Oa(t))?.entries??new Map,Lv=/^[ \t\n\v\f\r]+/,_v=t=>{const e=Jn(t).replace(Lv,"");return(e.startsWith("[PATCH")?jv(e):e).replace(Lv,"")},jv=t=>t.slice(t.indexOf("]")+1),Wv=new TextEncoder,Bv=async(t,e={})=>{await Xi(t);const a=await ef(t,e.rev??"HEAD"),n=await Promise.all((e.excluding??[]).map(e=>ef(t,e))),r="committer"===e.by,i=[];for await(const e of Rn(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:_v(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)=>Wa(Wv.encode(t.name),Wv.encode(e.name)))})(i)},zv=async(t,e,a,n=!1)=>{const r=void 0!==e?await Ts(t,e):void 0;return Te(t,r,a,{recursive:!0,detectRenames:!0,...n?{withStat:!0}:{}})};async function Fv(t,e="HEAD",a={}){await Xi(t);const n=!0===a.withStat;if("string"==typeof e)return qv(t,e,n);const r=[];for(const a of e)r.push(await qv(t,a,n));return r}const qv=async(t,e,a)=>Gv(t,await Vt(t,await is(t,e)),a);async function Gv(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 zv(t,e,r,a));return{kind:"commit",id:e.id,commit:e.data,perParent:i}}const i=await zv(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 Gv(t,await Vt(t,e.data.object),a);return{kind:"tag",id:e.id,tag:e.data,target:n}}(t,e,a)}}const Vv=async(t,e={})=>{await Xi(t);const a=await ef(t,e.rev??"HEAD"),n=await Promise.all((e.excluding??[]).map(e=>ef(t,e))),r=e.before,i="first-parent"===e.order?Ce(t,{from:[a],until:n,order:"first-parent"}):Rn(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 zv(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{qg as $,jd as A,Ld as B,Rd as C,_d as D,eu as E,hu as F,Ou as G,Hu as H,Cu as I,Nu as J,_u as K,Lu as L,Pu as M,Ru as N,Uu as O,el as P,$f as Q,Rf as R,Lf as S,tl as T,Ah as U,Nh as V,Ph as W,Fg as X,ro as Y,ju as Z,jh as _,ko as a,nf as a0,vw as a1,kw as a2,bw as a3,$w as a4,dy as a5,my as a6,pv as a7,gv as a8,um as a9,Ap as aA,Np as aB,Mp as aC,uf as aD,fg as aE,sg as aF,eg as aG,cg as aH,rg as aI,mg as aJ,vg as aK,bg as aL,yg as aM,Vv as aN,Ug as aO,Pg as aP,jg as aQ,Wg as aR,Pr as aS,cm as aa,im as ab,dm as ac,vv as ad,Nm as ae,Cm as af,Rm as ag,Lm as ah,_m as ai,jm as aj,Av as ak,is as al,tp as am,Zm as an,Jm as ao,Qm as ap,Nv as aq,Bv as ar,Fv as as,mp as at,gp as au,fp as av,pp as aw,wp as ax,Cp as ay,Op as az,vs as b,Rh as c,Uh as d,Lh as e,_h as f,lw as g,xw as h,xm as i,Wm as j,ep as k,kp as l,Pp as m,pg as n,$g as o,Bg as p,As as q,Xs as r,Js as s,Ks as t,Zs as u,vc as v,xc as w,Ec as x,Oc as y,Pc as z};
2
- //# sourceMappingURL=index-BEI7XKaV.js.map