simple-git
Version:
Simple GIT interface for node.js
7 lines • 51.2 kB
JavaScript
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("@simple-git/args-pathspec"),Tt=require("@kwsites/file-exists"),Se=require("node:child_process"),it=require("debug"),P=require("@kwsites/promise-deferred"),Re=require("node:path"),Bt=require("@simple-git/argv-parser"),Oe=require("node:events");class C extends Error{constructor(e,n){super(n),this.task=e,Object.setPrototypeOf(this,new.target.prototype)}}class It extends C{constructor(e,n){super(void 0,n),this.config=e}}class x extends C{constructor(e,n,r){super(e,r),this.task=e,this.plugin=n,Object.setPrototypeOf(this,new.target.prototype)}}class W extends C{constructor(e,n){super(void 0,n||String(e)),this.git=e}}class Gt extends C{constructor(e){super(void 0,e)}}const I="\0",H=()=>{};function Ce(t){return typeof t!="function"?H:t}function Ae(t){return typeof t=="function"&&t!==H}function xe(t,e){const n=t.indexOf(e);return n<=0?[t,""]:[t.substr(0,n),t.substr(n+1)]}function Pe(t,e=0){return Ut(t)&&t.length>e?t[e]:void 0}function $(t,e=0){if(Ut(t)&&t.length>e)return t[t.length-1-e]}function Ut(t){return zt(t)}function K(t="",e=!0,n=`
`){return t.split(n).reduce((r,s)=>{const o=e?s.trim():s;return o&&r.push(o),r},[])}function at(t,e){return K(t,!0).map(n=>e(n))}function Ft(t){return Tt.exists(t,Tt.FOLDER)}function R(t,e){return Array.isArray(t)?t.includes(e)||t.push(e):t.add(e),e}function Ne(t,e){return Array.isArray(t)&&!t.includes(e)&&t.push(e),t}function ut(t,e){if(Array.isArray(t)){const n=t.indexOf(e);n>=0&&t.splice(n,1)}else t.delete(e);return e}const ct=Object.prototype.toString.call.bind(Object.prototype.toString);function v(t){return Array.isArray(t)?t:[t]}function qt(t){return t.replace(/[\s-]+(.)/g,(e,n)=>n.toUpperCase())}function j(t){return v(t).map(e=>e instanceof String?e:String(e))}function m(t,e=0){if(t==null)return e;const n=parseInt(t,10);return Number.isNaN(n)?e:n}function G(t,e){const n=[];for(let r=0,s=t.length;r<s;r++)n.push(e,t[r]);return n}function U(t){return(Array.isArray(t)?Buffer.concat(t):t).toString("utf-8")}function $e(t){return t?Buffer.isBuffer(t)?t.length:Buffer.byteLength(t):0}function Me(t,e){const n={};return e.forEach(r=>{t[r]!==void 0&&(n[r]=t[r])}),n}function kt(t=0){return new Promise(e=>setTimeout(e,t))}function _t(t){if(t!==!1)return t}function d(t,e,n){return e(t)?t:arguments.length>2?n:void 0}const V=t=>Array.isArray(t);function st(t,e){const n=S.isPathSpec(t)?"string":typeof t;return/number|string|boolean/.test(n)&&(!e||!e.includes(n))}const p=t=>typeof t=="string"||S.isPathSpec(t),De=t=>p(t)||Buffer.isBuffer(t),F=t=>p(t)||Array.isArray(t)&&t.every(p);function ft(t){return!!t&&ct(t)==="[object Object]"}function je(t){return typeof t=="function"}const zt=t=>t==null||"number|boolean|function".includes(typeof t)?!1:typeof t.length=="number";var Q=(t=>(t[t.SUCCESS=0]="SUCCESS",t[t.ERROR=1]="ERROR",t[t.NOT_FOUND=-2]="NOT_FOUND",t[t.UNCLEAN=128]="UNCLEAN",t))(Q||{});class q{constructor(e,n){this.stdOut=e,this.stdErr=n}asStrings(){return new q(this.stdOut.toString("utf8"),this.stdErr.toString("utf8"))}}function Le(){throw new Error("LineParser:useMatches not implemented")}class l{constructor(e,n){this.matches=[],this.useMatches=Le,this.parse=(r,s)=>(this.resetMatches(),this._regExp.every((o,i)=>this.addMatch(o,i,r(i)))?this.useMatches(s,this.prepareMatches())!==!1:!1),this._regExp=Array.isArray(e)?e:[e],n&&(this.useMatches=n)}resetMatches(){this.matches.length=0}prepareMatches(){return this.matches}addMatch(e,n,r){const s=r&&e.exec(r);return s&&this.pushMatch(n,s),!!s}pushMatch(e,n){this.matches.push(...n.slice(1))}}class N extends l{addMatch(e,n,r){return/^remote:\s/.test(String(r))&&super.addMatch(e,n,r)}pushMatch(e,n){(e>0||n.length>1)&&super.pushMatch(e,n)}}const Be={binary:"git",maxConcurrentProcesses:5,config:[],trimmed:!1};function Ie(...t){const e=process.cwd(),n=Object.assign({baseDir:e,...Be},...t.filter(r=>typeof r=="object"&&r));return n.baseDir=n.baseDir||e,n.trimmed=n.trimmed===!0,n}function Wt(t,e=[]){return ft(t)?Object.keys(t).reduce((n,r)=>{const s=t[r];if(S.isPathSpec(s))n.push(s);else if(st(s,["boolean"]))n.push(r+"="+s);else if(Array.isArray(s))for(const o of s)st(o,["string","number"])||n.push(r+"="+o);else n.push(r);return n},e):e}function h(t,e=0,n=!1){const r=[];for(let s=0,o=e<0?t.length:e;s<o;s++)"string|number".includes(typeof t[s])&&r.push(String(t[s]));return Wt(lt(t),r),n||r.push(...Ge(t)),r}function Ge(t){const e=typeof $(t)=="function";return j(d($(t,e?1:0),V,[]))}function lt(t){const e=je($(t));return d($(t,e?1:0),ft)}function u(t,e=!0){const n=Ce($(t));return e||Ae(n)?n:void 0}function vt(t,e){return t(e.stdOut,e.stdErr)}function E(t,e,n,r=!0){return v(n).forEach(s=>{for(let o=K(s,r),i=0,a=o.length;i<a;i++){const c=(y=0)=>{if(!(i+y>=a))return o[i+y]};e.some(({parse:y})=>y(c,t))}}),t}var Ht=(t=>(t.BARE="bare",t.IN_TREE="tree",t.IS_REPO_ROOT="root",t))(Ht||{});const ht=({exitCode:t},e,n,r)=>{if(t===Q.UNCLEAN&&ze(e))return n(Buffer.from("false"));r(e)},Kt=t=>t.trim()==="true";function Ue(t){switch(t){case"bare":return qe();case"root":return Fe()}return{commands:["rev-parse","--is-inside-work-tree"],format:"utf-8",onError:ht,parser:Kt}}function Fe(){return{commands:["rev-parse","--git-dir"],format:"utf-8",onError:ht,parser(e){return/^\.(git)?$/.test(e.trim())}}}function qe(){return{commands:["rev-parse","--is-bare-repository"],format:"utf-8",onError:ht,parser:Kt}}function ze(t){return/(Not a git repository|Kein Git-Repository)/i.test(String(t))}class We{constructor(e){this.paths=[],this.files=[],this.folders=[],this.dryRun=e}}const He=/^[a-z]+\s*/i,Ke=/^[a-z]+\s+[a-z]+\s*/i,Ve=/\/$/;function Qe(t,e){const n=new We(t),r=t?Ke:He;return K(e).forEach(s=>{const o=s.replace(r,"");n.paths.push(o),(Ve.test(o)?n.folders:n.files).push(o)}),n}const Vt=[];function Xe(t){return{commands:Vt,format:"empty",parser:t}}function b(t){return{commands:Vt,format:"empty",parser(){throw typeof t=="string"?new Gt(t):t}}}function g(t,e=!1){return{commands:t,format:"utf-8",parser(n){return e?String(n).trim():n}}}function Qt(t){return{commands:t,format:"buffer",parser(e){return e}}}function Ye(t){return t.format==="buffer"}function Et(t){return t.format==="empty"||!t.commands.length}const Je="Git clean interactive mode is not supported",Ze='Git clean mode parameter ("n" or "f") is required',tn="Git clean unknown option found in: ";var pt=(t=>(t.DRY_RUN="n",t.FORCE="f",t.IGNORED_INCLUDED="x",t.IGNORED_ONLY="X",t.EXCLUDING="e",t.QUIET="q",t.RECURSIVE="d",t))(pt||{});const Xt=new Set(["i",...j(Object.values(pt))]);function en(t,e){const{cleanMode:n,options:r,valid:s}=sn(t);return n?s.options?(r.push(...e),r.some(un)?b(Je):nn(n,r)):b(tn+JSON.stringify(t)):b(Ze)}function nn(t,e){return{commands:["clean",`-${t}`,...e],format:"utf-8",parser(r){return Qe(t==="n",r)}}}function rn(t){return Array.isArray(t)&&t.every(e=>Xt.has(e))}function sn(t){let e,n=[],r={cleanMode:!1,options:!0};return t.replace(/[^a-z]i/g,"").split("").forEach(s=>{on(s)?(e=s,r.cleanMode=!0):r.options=r.options&&an(n[n.length]=`-${s}`)}),{cleanMode:e,options:n,valid:r}}function on(t){return t==="f"||t==="n"}function an(t){return/^-[a-z]$/i.test(t)&&Xt.has(t.charAt(1))}function un(t){return/^-[^\-]/.test(t)?t.indexOf("i")>0:t==="--interactive"}class cn{constructor(){this.files=[],this.values=Object.create(null)}get all(){return this._all||(this._all=this.files.reduce((e,n)=>Object.assign(e,this.values[n]),{})),this._all}addFile(e){if(!(e in this.values)){const n=$(this.files);this.values[e]=n?Object.create(this.values[n]):{},this.files.push(e)}return this.values[e]}addValue(e,n,r){const s=this.addFile(e);Object.hasOwn(s,n)?Array.isArray(s[n])?s[n].push(r):s[n]=[s[n],r]:s[n]=r,this._all=void 0}}function fn(t){const e=new cn;for(const n of Yt(t))e.addValue(n.file,String(n.key),n.value);return e}function ln(t,e){let n=null;const r=[],s=new Map;for(const o of Yt(t,e))o.key===e&&(r.push(n=o.value),s.has(o.file)||s.set(o.file,[]),s.get(o.file).push(n));return{key:e,paths:Array.from(s.keys()),scopes:s,value:n,values:r}}function hn(t){return t.replace(/^(file):/,"")}function*Yt(t,e=null){const n=t.split("\0");for(let r=0,s=n.length-1;r<s;){const o=hn(n[r++]);let i=n[r++],a=e;if(i.includes(`
`)){const c=xe(i,`
`);a=c[0],i=c[1]}yield{file:o,key:a,value:i}}}var mt=(t=>(t.system="system",t.global="global",t.local="local",t.worktree="worktree",t))(mt||{});function Y(t,e){return typeof t=="string"&&Object.hasOwn(mt,t)?t:e}function pn(t,e,n,r){const s=["config",`--${r}`];return n&&s.push("--add"),s.push(t,e),{commands:s,format:"utf-8",parser(o){return o}}}function mn(t,e){const n=["config","--null","--show-origin","--get-all",t];return e&&n.splice(1,0,`--${e}`),{commands:n,format:"utf-8",parser(r){return ln(r,t)}}}function dn(t){const e=["config","--list","--show-origin","--null"];return t&&e.push(`--${t}`),{commands:e,format:"utf-8",parser(n){return fn(n)}}}function gn(){return{addConfig(t,e,...n){return this._runTask(pn(t,e,n[0]===!0,Y(n[1],"local")),u(arguments))},getConfig(t,e){return this._runTask(mn(t,Y(e,void 0)),u(arguments))},listConfig(...t){return this._runTask(dn(Y(t[0],void 0)),u(arguments))}}}var dt=(t=>(t.ADDED="A",t.COPIED="C",t.DELETED="D",t.MODIFIED="M",t.RENAMED="R",t.CHANGED="T",t.UNMERGED="U",t.UNKNOWN="X",t.BROKEN="B",t))(dt||{});const yn=new Set(Object.values(dt));function wn(t){return yn.has(t)}var St;const bn=["-h"],L=Symbol("grepQuery");class Tn{constructor(){this[St]=[]}*[(St=L,Symbol.iterator)](){for(const e of this[L])yield e}and(...e){return e.length&&this[L].push("--and","(",...G(e,"-e"),")"),this}param(...e){return this[L].push(...G(e,"-e")),this}}function Jt(...t){return new Tn().param(...t)}function kn(t){const e=new Set,n={};return at(t,r=>{const[s,o,i]=r.split(I);e.add(s),(n[s]=n[s]||[]).push({line:m(o),path:s,preview:i})}),{paths:e,results:n}}function _n(){return{grep(t){const e=u(arguments),n=h(arguments);for(const s of bn)if(n.includes(s))return this._runTask(b(`git.grep: use of "${s}" is not supported.`),e);typeof t=="string"&&(t=Jt().param(t));const r=["grep","--null","-n","--full-name",...n,...t];return this._runTask({commands:r,format:"utf-8",parser(s){return kn(s)}},e)}}}var gt=(t=>(t.MIXED="mixed",t.SOFT="soft",t.HARD="hard",t.MERGE="merge",t.KEEP="keep",t))(gt||{});const vn=j(Object.values(gt));function En(t,e){const n=["reset"];return Zt(t)&&n.push(`--${t}`),n.push(...e),g(n)}function Sn(t){if(Zt(t))return t;switch(typeof t){case"string":case"undefined":return"soft"}}function Zt(t){return typeof t=="string"&&vn.includes(t)}it.formatters.L=t=>String(zt(t)?t.length:"-");it.formatters.B=t=>Buffer.isBuffer(t)?t.toString("utf8"):ct(t);function Rn(){return it("simple-git")}function Rt(t,e,n){return!e||!String(e).replace(/\s*/,"")?n?(r,...s)=>{t(r,...s),n(r,...s)}:t:(r,...s)=>{t(`%s ${r}`,e,...s),n&&n(r,...s)}}function On(t,e,{namespace:n}){if(typeof t=="string")return t;const r=e&&e.namespace||"";return r.startsWith(n)?r.substr(n.length+1):r||n}function M(t,e,n,r=Rn()){const s=t&&`[${t}]`||"",o=[],i=typeof e=="string"?r.extend(e):e,a=On(d(e,p),i,r);return y(n);function c(w,T){return R(o,M(t,a.replace(/^[^:]+/,w),T,r))}function y(w){const T=w&&`[${w}]`||"",k=i&&Rt(i,T)||H,A=Rt(r,`${s} ${T}`,k);return Object.assign(i?k:A,{label:t,sibling:c,info:A,step:y})}}const D=class D{constructor(e="GitExecutor"){this.logLabel=e,this._queue=new Map}withProgress(e){return this._queue.get(e)}createProgress(e){const n=D.getName(e.commands[0]),r=M(this.logLabel,n);return{task:e,logger:r,name:n}}push(e){const n=this.createProgress(e);return n.logger("Adding task to the queue, commands = %o",e.commands),this._queue.set(e,n),n}fatal(e){for(const[n,{logger:r}]of Array.from(this._queue.entries()))n===e.task?(r.info("Failed %o",e),r("Fatal exception, any as-yet un-started tasks run through this executor will not be attempted")):r.info("A fatal exception occurred in a previous task, the queue has been purged: %o",e.message),this.complete(n);if(this._queue.size!==0)throw new Error(`Queue size should be zero after fatal: ${this._queue.size}`)}complete(e){this.withProgress(e)&&this._queue.delete(e)}attempt(e){const n=this.withProgress(e);if(!n)throw new C(void 0,"TasksPendingQueue: attempt called for an unknown task");return n.logger("Starting task"),n}static getName(e="empty"){return`task:${e}:${++D.counter}`}};D.counter=0;let ot=D;class Cn{constructor(e,n,r){this._executor=e,this._scheduler=n,this._plugins=r,this._chain=Promise.resolve(),this._queue=new ot}get cwd(){return this._cwd||this._executor.cwd}set cwd(e){this._cwd=e}get env(){return this._executor.env}get outputHandler(){return this._executor.outputHandler}chain(){return this}push(e){return this._queue.push(e),this._chain=this._chain.then(()=>this.attemptTask(e))}async attemptTask(e){const n=await this._scheduler.next(),r=()=>this._queue.complete(e);try{const{logger:s}=this._queue.attempt(e);return await(Et(e)?this.attemptEmptyTask(e,s):this.attemptRemoteTask(e,s))}catch(s){throw this.onFatalException(e,s)}finally{r(),n()}}onFatalException(e,n){const r=n instanceof C?Object.assign(n,{task:e}):new C(e,n&&String(n));return this._chain=Promise.resolve(),this._queue.fatal(r),r}async attemptRemoteTask(e,n){const r=this._plugins.exec("spawn.binary","",this.taskContext(e,e.commands)),s=this._plugins.exec("spawn.args",[...e.commands],this.taskContext(e,e.commands)),o=await this.gitResponse(e,r,s,this.outputHandler,n.step("SPAWN")),i=await this.handleTaskData(e,s,o,n.step("HANDLE"));return n("passing response to task's parser as a %s",e.format),Ye(e)?vt(e.parser,i):vt(e.parser,i.asStrings())}async attemptEmptyTask(e,n){return n("empty task bypassing child process to call to task's parser"),e.parser(this)}handleTaskData(e,n,r,s){const{exitCode:o,rejection:i,stdOut:a,stdErr:c}=r;return new Promise((y,w)=>{s("Preparing to handle process response exitCode=%d stdOut=",o);const{error:T}=this._plugins.exec("task.error",{error:i},{...this.taskContext(e,n),...r});if(T&&e.onError)return s.info("exitCode=%s handling with custom error handler"),e.onError(r,T,k=>{s.info("custom error handler treated as success"),s("custom error returned a %s",ct(k)),y(new q(Array.isArray(k)?Buffer.concat(k):k,Buffer.concat(c)))},w);if(T)return s.info("handling as error: exitCode=%s stdErr=%s rejection=%o",o,c.length,i),w(T);s.info("retrieving task output complete"),y(new q(Buffer.concat(a),Buffer.concat(c)))})}async gitResponse(e,n,r,s,o){const i=o.sibling("output"),a=this._plugins.exec("spawn.options",{cwd:this.cwd,env:this.env,windowsHide:!0},this.taskContext(e,e.commands));return new Promise(c=>{const y=[],w=[];o.info("%s %o",n,r),o("%O",a);let T=this._beforeSpawn(e,r);if(T)return c({stdOut:y,stdErr:w,exitCode:9901,rejection:T});this._plugins.exec("spawn.before",void 0,{...this.taskContext(e,r),kill(A){T=A||T}});const k=Se.spawn(n,r,a);k.stdout.on("data",Ot(y,"stdOut",o,i.step("stdOut"))),k.stderr.on("data",Ot(w,"stdErr",o,i.step("stdErr"))),k.on("error",An(w,o)),s&&(o("Passing child process stdOut/stdErr to custom outputHandler"),s(n,k.stdout,k.stderr,[...r])),this._plugins.exec("spawn.after",void 0,{...this.taskContext(e,r),spawned:k,close(A,Ee){c({stdOut:y,stdErr:w,exitCode:A,rejection:T||Ee})},kill(A){k.killed||(T=A,k.kill("SIGINT"))}})})}_beforeSpawn(e,n){let r;return this._plugins.exec("spawn.before",void 0,{...this.taskContext(e,n),kill(s){r=s||r}}),r}taskContext(e,n){return{method:String(Pe(e.commands)||""),commands:n,env:{...this.env},input:Et(e)?void 0:e.input}}}function An(t,e){return n=>{e("[ERROR] child process exception %o",n),t.push(Buffer.from(String(n.stack),"ascii"))}}function Ot(t,e,n,r){return s=>{n("%s received %L bytes",e,s),r("%B",s),t.push(s)}}class xn{constructor(e,n,r){this.cwd=e,this._scheduler=n,this._plugins=r,this._chain=this.chain()}chain(){return new Cn(this,this._scheduler,this._plugins)}push(e){return this._chain.push(e)}}function Pn(t,e,n=H){const r=o=>{n(null,o)},s=o=>{o?.task===t&&n(o,void 0)};e.then(r,s)}function Ct(t,e){return Xe(n=>{if(!Ft(t))throw new Error(`Git.cwd: cannot change to non-directory "${t}"`);return(e||n).cwd=t})}function J(t){const e=["checkout",...t];return e[1]==="-b"&&e.includes("-B")&&(e[1]=ut(e,"-B")),g(e)}function Nn(){return{checkout(){return this._runTask(J(h(arguments,1)),u(arguments))},checkoutBranch(t,e){return this._runTask(J(["-b",t,e,...h(arguments)]),u(arguments))},checkoutLocalBranch(t){return this._runTask(J(["-b",t,...h(arguments)]),u(arguments))}}}const te=(t,e,n)=>{const r=["clone",...n];return p(t)&&r.push(S.pathspec(t)),p(e)&&r.push(S.pathspec(e)),g(r)},$n=(t,e,n)=>(R(n,"--mirror"),te(t,e,n));function At(t,e,n,...r){return p(n)?e(n,d(r[0],p),h(arguments)):b(`git.${t}() requires a string 'repoPath'`)}function Mn(){return{clone(t,...e){return this._runTask(At("clone",te,d(t,p),...e),u(arguments))},mirror(t,...e){return this._runTask(At("mirror",$n,d(t,p),...e),u(arguments))}}}const Dn=[new l(/^\[([^\s]+)( \([^)]+\))? ([^\]]+)/,(t,[e,n,r])=>{t.branch=e,t.commit=r,t.root=!!n}),new l(/\s*Author:\s(.+)/i,(t,[e])=>{const n=e.split("<"),r=n.pop();!r||!r.includes("@")||(t.author={email:r.substr(0,r.length-1),name:n.join("<").trim()})}),new l(/(\d+)[^,]*(?:,\s*(\d+)[^,]*)(?:,\s*(\d+))/g,(t,[e,n,r])=>{t.summary.changes=parseInt(e,10)||0,t.summary.insertions=parseInt(n,10)||0,t.summary.deletions=parseInt(r,10)||0}),new l(/^(\d+)[^,]*(?:,\s*(\d+)[^(]+\(([+-]))?/,(t,[e,n,r])=>{t.summary.changes=parseInt(e,10)||0;const s=parseInt(n,10)||0;r==="-"?t.summary.deletions=s:r==="+"&&(t.summary.insertions=s)})];function jn(t){return E({author:null,branch:"",commit:"",root:!1,summary:{changes:0,insertions:0,deletions:0}},Dn,t)}function Ln(t,e,n){return{commands:["-c","core.abbrev=40","commit",...G(t,"-m"),...e,...n],format:"utf-8",parser:jn}}function Bn(){return{commit(e,...n){const r=u(arguments),s=t(e)||Ln(v(e),v(d(n[0],F,[])),[...j(d(n[1],V,[])),...h(arguments,0,!0)]);return this._runTask(s,r)}};function t(e){return!F(e)&&b("git.commit: requires the commit message to be supplied as a string/string[]")}}function In(){return{count:0,garbage:0,inPack:0,packs:0,prunePackable:0,size:0,sizeGarbage:0,sizePack:0}}const Gn=new l(/([a-z-]+): (\d+)$/,(t,[e,n])=>{const r=qt(e);Object.hasOwn(t,r)&&(t[r]=m(n))});function Un(){return{countObjects(){return this._runTask({commands:["count-objects","--verbose"],format:"utf-8",parser(t){return E(In(),[Gn],t)}})}}}function Fn(){return{firstCommit(){return this._runTask(g(["rev-list","--max-parents=0","HEAD"],!0),u(arguments))}}}function qn(t,e){const n=["hash-object",t];return e&&n.push("-w"),g(n,!0)}class Z{constructor(e,n,r,s){this.bare=e,this.path=n,this.existing=r,this.gitDir=s}}const zn=/^Init.+ repository in (.+)$/,Wn=/^Rein.+ in (.+)$/;function Hn(t,e,n){const r=String(n).trim();let s;if(s=zn.exec(r))return new Z(t,e,!1,s[1]);if(s=Wn.exec(r))return new Z(t,e,!0,s[1]);let o="";const i=r.split(" ");for(;i.length;)if(i.shift()==="in"){o=i.join(" ");break}return new Z(t,e,/^re/i.test(r),o)}const ee="--bare";function Kn(t){return t.includes(ee)}function Vn(t=!1,e,n){const r=["init",...n];return t&&!Kn(r)&&r.splice(1,0,ee),{commands:r,format:"utf-8",parser(s){return Hn(r.includes("--bare"),e,s)}}}function Qn(t){return t===void 0?b("interpretTrailers called without input content"):{format:"utf-8",parser(e){return Object.fromEntries(at(e,n=>{const r=n.indexOf(":");return[qt(n.substring(0,r).toLowerCase()),n.substring(r+2).trim()]}))},commands:["interpret-trailers","--parse"],input:t}}function Xn(){return{interpretTrailers(t){return this._runTask(Qn(d(t,De)),u(arguments))}}}var O=(t=>(t.NONE="",t.STAT="--stat",t.NUM_STAT="--numstat",t.NAME_ONLY="--name-only",t.NAME_STATUS="--name-status",t))(O||{});const ne=/^--(stat|numstat|name-only|name-status)(=|$)/;function yt(t){for(let e=0;e<t.length;e++){const n=ne.exec(t[e]);if(n)return`--${n[1]}`}return""}function Yn(t){return ne.test(t)}class Jn{constructor(){this.changed=0,this.deletions=0,this.insertions=0,this.files=[]}}const xt=[new l(/^(.+)\s+\|\s+(\d+)(\s+[+\-]+)?$/,(t,[e,n,r=""])=>{t.files.push({file:e.trim(),changes:m(n),insertions:r.replace(/[^+]/g,"").length,deletions:r.replace(/[^-]/g,"").length,binary:!1})}),new l(/^(.+) \|\s+Bin ([0-9.]+) -> ([0-9.]+) ([a-z]+)/,(t,[e,n,r])=>{t.files.push({file:e.trim(),before:m(n),after:m(r),binary:!0})}),new l(/^(.+)\s+\|\s+Bin\s*$/,(t,[e])=>{t.files.push({file:e.trim(),before:0,after:0,binary:!0})}),new l(/(\d+) files? changed\s*((?:, \d+ [^,]+){0,2})/,(t,[e,n])=>{const r=/(\d+) i/.exec(n),s=/(\d+) d/.exec(n);t.changed=m(e),t.insertions=m(r?.[1]),t.deletions=m(s?.[1])})],Zn=[new l(/(\d+)\t(\d+)\t(.+)$/,(t,[e,n,r])=>{const s=m(e),o=m(n);t.changed++,t.insertions+=s,t.deletions+=o,t.files.push({file:r,changes:s+o,insertions:s,deletions:o,binary:!1})}),new l(/-\t-\t(.+)$/,(t,[e])=>{t.changed++,t.files.push({file:e,after:0,before:0,binary:!0})})],tr=[new l(/(.+)$/,(t,[e])=>{t.changed++,t.files.push({file:e,changes:0,insertions:0,deletions:0,binary:!1})})],er=[new l(/([ACDMRTUXB])([0-9]{0,3})\t(.[^\t]*)(\t(.[^\t]*))?$/,(t,[e,n,r,s,o])=>{t.changed++,t.files.push({file:o??r,changes:0,insertions:0,deletions:0,binary:!1,status:_t(wn(e)&&e),from:_t(!!o&&r!==o&&r),similarity:m(n)})})],nr={[O.NONE]:xt,[O.STAT]:xt,[O.NUM_STAT]:Zn,[O.NAME_STATUS]:er,[O.NAME_ONLY]:tr};function re(t=O.NONE){const e=nr[t];return n=>E(new Jn,e,n,!1)}const se="òòòòòò ",oe=" òò",ie=" ò ",rr=["hash","date","message","refs","author_name","author_email"];function sr(t,e){return e.reduce((n,r,s)=>(n[r]=t[s]||"",n),Object.create({diff:null}))}function ae(t=ie,e=rr,n=O.NONE){const r=re(n);return function(s){const o=K(s.trim(),!1,se).map(function(i){const a=i.split(oe),c=sr(a[0].split(t),e);return a.length>1&&a[1].trim()&&(c.diff=r(a[1])),c});return{all:o,latest:o.length&&o[0]||null,total:o.length}}}function or(t){let e=yt(t);const n=["diff"];return e===O.NONE&&(e=O.STAT,n.push("--stat=4096")),n.push(...t),wt(n)||{commands:n,format:"utf-8",parser:re(e)}}function wt(t){const e=t.filter(Yn);if(e.length>1)return b(`Summary flags are mutually exclusive - pick one of ${e.join(",")}`);if(e.length&&t.includes("-z"))return b(`Summary flag ${e} parsing is not compatible with null termination option '-z'`)}var ue=(t=>(t[t["--pretty"]=0]="--pretty",t[t["max-count"]=1]="max-count",t[t.maxCount=2]="maxCount",t[t.n=3]="n",t[t.file=4]="file",t[t.format=5]="format",t[t.from=6]="from",t[t.to=7]="to",t[t.splitter=8]="splitter",t[t.symmetric=9]="symmetric",t[t.mailMap=10]="mailMap",t[t.multiLine=11]="multiLine",t[t.strictDate=12]="strictDate",t))(ue||{});function ir(t,e){const n=[],r=[];return Object.keys(t).forEach(s=>{n.push(s),r.push(String(t[s]))}),[n,r.join(e)]}function ar(t){return Object.keys(t).reduce((e,n)=>(n in ue||(e[n]=t[n]),e),{})}function ce(t={},e=[]){const n=d(t.splitter,p,ie),r=ft(t.format)?t.format:{hash:"%H",date:t.strictDate===!1?"%ai":"%aI",message:"%s",refs:"%D",body:t.multiLine?"%B":"%b",author_name:t.mailMap!==!1?"%aN":"%an",author_email:t.mailMap!==!1?"%aE":"%ae"},[s,o]=ir(r,n),i=[],a=[`--pretty=format:${se}${o}${oe}`,...e],c=t.n||t["max-count"]||t.maxCount;if(c&&a.push(`--max-count=${c}`),t.from||t.to){const y=t.symmetric!==!1?"...":"..";i.push(`${t.from||""}${y}${t.to||""}`)}return p(t.file)&&a.push("--follow",S.pathspec(t.file)),Wt(ar(t),a),{fields:s,splitter:n,commands:[...a,...i]}}function ur(t,e,n){const r=ae(t,e,yt(n));return{commands:["log",...n],format:"utf-8",parser:r}}function cr(){return{log(...n){const r=u(arguments),s=ce(lt(arguments),j(d(arguments[0],V,[]))),o=e(...n)||wt(s.commands)||t(s);return this._runTask(o,r)}};function t(n){return ur(n.splitter,n.fields,n.commands)}function e(n,r){return p(n)&&p(r)&&b("git.log(string, string) should be replaced with git.log({ from: string, to: string })")}}class tt{constructor(e,n=null,r){this.reason=e,this.file=n,this.meta=r}toString(){return`${this.file}:${this.reason}`}}class fr{constructor(){this.conflicts=[],this.merges=[],this.result="success"}get failed(){return this.conflicts.length>0}get reason(){return this.result}toString(){return this.conflicts.length?`CONFLICTS: ${this.conflicts.join(", ")}`:"OK"}}class fe{constructor(){this.remoteMessages={all:[]},this.created=[],this.deleted=[],this.files=[],this.deletions={},this.insertions={},this.summary={changes:0,deletions:0,insertions:0}}}class lr{constructor(){this.remote="",this.hash={local:"",remote:""},this.branch={local:"",remote:""},this.message=""}toString(){return this.message}}function et(t){return t.objects=t.objects||{compressing:0,counting:0,enumerating:0,packReused:0,reused:{count:0,delta:0},total:{count:0,delta:0}}}function Pt(t){const e=/^\s*(\d+)/.exec(t),n=/delta (\d+)/i.exec(t);return{count:m(e&&e[1]||"0"),delta:m(n&&n[1]||"0")}}const hr=[new N(/^remote:\s*(enumerating|counting|compressing) objects: (\d+),/i,(t,[e,n])=>{const r=e.toLowerCase(),s=et(t.remoteMessages);Object.assign(s,{[r]:m(n)})}),new N(/^remote:\s*(enumerating|counting|compressing) objects: \d+% \(\d+\/(\d+)\),/i,(t,[e,n])=>{const r=e.toLowerCase(),s=et(t.remoteMessages);Object.assign(s,{[r]:m(n)})}),new N(/total ([^,]+), reused ([^,]+), pack-reused (\d+)/i,(t,[e,n,r])=>{const s=et(t.remoteMessages);s.total=Pt(e),s.reused=Pt(n),s.packReused=m(r)})],pr=[new N(/^remote:\s*(.+)$/,(t,[e])=>(t.remoteMessages.all.push(e.trim()),!1)),...hr,new N([/create a (?:pull|merge) request/i,/\s(https?:\/\/\S+)$/],(t,[e])=>{t.remoteMessages.pullRequestUrl=e}),new N([/found (\d+) vulnerabilities.+\(([^)]+)\)/i,/\s(https?:\/\/\S+)$/],(t,[e,n,r])=>{t.remoteMessages.vulnerabilities={count:m(e),summary:n,url:r}})];function le(t,e){return E({remoteMessages:new mr},pr,e)}class mr{constructor(){this.all=[]}}const dr=/^\s*(.+?)\s+\|\s+\d+\s*(\+*)(-*)/,gr=/(\d+)\D+((\d+)\D+\(\+\))?(\D+(\d+)\D+\(-\))?/,yr=/^(create|delete) mode \d+ (.+)/,wr=[new l(dr,(t,[e,n,r])=>{t.files.push(e),n&&(t.insertions[e]=n.length),r&&(t.deletions[e]=r.length)}),new l(gr,(t,[e,,n,,r])=>n!==void 0||r!==void 0?(t.summary.changes=+e||0,t.summary.insertions=+n||0,t.summary.deletions=+r||0,!0):!1),new l(yr,(t,[e,n])=>{R(t.files,n),R(e==="create"?t.created:t.deleted,n)})],br=[new l(/^from\s(.+)$/i,(t,[e])=>{t.remote=e}),new l(/^fatal:\s(.+)$/,(t,[e])=>{t.message=e}),new l(/([a-z0-9]+)\.\.([a-z0-9]+)\s+(\S+)\s+->\s+(\S+)$/,(t,[e,n,r,s])=>{t.branch.local=r,t.hash.local=e,t.branch.remote=s,t.hash.remote=n})],Tr=(t,e)=>E(new fe,wr,[t,e]),he=(t,e)=>Object.assign(new fe,Tr(t,e),le(t,e));function kr(t,e){const n=E(new lr,br,[t,e]);return n.message&&n}const _r=[new l(/^Auto-merging\s+(.+)$/,(t,[e])=>{t.merges.push(e)}),new l(/^CONFLICT\s+\((.+)\): Merge conflict in (.+)$/,(t,[e,n])=>{t.conflicts.push(new tt(e,n))}),new l(/^CONFLICT\s+\((.+\/delete)\): (.+) deleted in (.+) and/,(t,[e,n,r])=>{t.conflicts.push(new tt(e,n,{deleteRef:r}))}),new l(/^CONFLICT\s+\((.+)\):/,(t,[e])=>{t.conflicts.push(new tt(e,null))}),new l(/^Automatic merge failed;\s+(.+)$/,(t,[e])=>{t.result=e})],vr=(t,e)=>Object.assign(Er(t),he(t,e)),Er=t=>E(new fr,_r,t);function Nt(t){return t.length?{commands:["merge",...t],format:"utf-8",parser(e,n){const r=vr(e,n);if(r.failed)throw new W(r);return r}}:b("Git.merge requires at least one option")}function Sr(t,e,n){const r=n.includes("deleted"),s=n.includes("tag")||/^refs\/tags/.test(t),o=!n.includes("new");return{deleted:r,tag:s,branch:!s,new:!o,alreadyUpdated:o,local:t,remote:e}}const Rr=[new l(/^Pushing to (.+)$/,(t,[e])=>{t.repo=e}),new l(/^updating local tracking ref '(.+)'/,(t,[e])=>{t.ref={...t.ref||{},local:e}}),new l(/^[=*-]\s+([^:]+):(\S+)\s+\[(.+)]$/,(t,[e,n,r])=>{t.pushed.push(Sr(e,n,r))}),new l(/^Branch '([^']+)' set up to track remote branch '([^']+)' from '([^']+)'/,(t,[e,n,r])=>{t.branch={...t.branch||{},local:e,remote:n,remoteName:r}}),new l(/^([^:]+):(\S+)\s+([a-z0-9]+)\.\.([a-z0-9]+)$/,(t,[e,n,r,s])=>{t.update={head:{local:e,remote:n},hash:{from:r,to:s}}})],Or=(t,e)=>{const n=Cr(t,e),r=le(t,e);return{...n,...r}},Cr=(t,e)=>E({pushed:[]},Rr,[t,e]);function Ar(t={},e){return R(e,"--tags"),pe(t,e)}function pe(t={},e){const n=["push",...e];return t.branch&&n.splice(1,0,t.branch),t.remote&&n.splice(1,0,t.remote),ut(n,"-v"),R(n,"--verbose"),R(n,"--porcelain"),{commands:n,format:"utf-8",parser:Or}}function xr(){return{showBuffer(){const t=["show",...h(arguments,1)];return t.includes("--binary")||t.splice(1,0,"--binary"),this._runTask(Qt(t),u(arguments))},show(){const t=["show",...h(arguments,1)];return this._runTask(g(t),u(arguments))}}}const Pr=/^(.+)\0(.+)$/;class Nr{constructor(e,n,r){if(this.path=e,this.index=n,this.working_dir=r,n==="R"||r==="R"){const s=Pr.exec(e)||[null,e,e];this.from=s[2]||"",this.path=s[1]||""}}}class $r{constructor(){this.not_added=[],this.conflicted=[],this.created=[],this.deleted=[],this.ignored=void 0,this.modified=[],this.renamed=[],this.files=[],this.staged=[],this.ahead=0,this.behind=0,this.current=null,this.tracking=null,this.detached=!1,this.isClean=()=>!this.files.length}}function $t(t){const[e,n]=t.split(I);return{from:n||e,to:e}}function _(t,e,n){return[`${t}${e}`,n]}function nt(t,...e){return e.map(n=>_(t,n,(r,s)=>r.conflicted.push(s)))}const Mr=new Map([_(" ","A",(t,e)=>t.created.push(e)),_(" ","D",(t,e)=>t.deleted.push(e)),_(" ","M",(t,e)=>t.modified.push(e)),_("A"," ",(t,e)=>{t.created.push(e),t.staged.push(e)}),_("A","M",(t,e)=>{t.created.push(e),t.staged.push(e),t.modified.push(e)}),_("D"," ",(t,e)=>{t.deleted.push(e),t.staged.push(e)}),_("M"," ",(t,e)=>{t.modified.push(e),t.staged.push(e)}),_("M","M",(t,e)=>{t.modified.push(e),t.staged.push(e)}),_("R"," ",(t,e)=>{t.renamed.push($t(e))}),_("R","M",(t,e)=>{const n=$t(e);t.renamed.push(n),t.modified.push(n.to)}),_("!","!",(t,e)=>{(t.ignored=t.ignored||[]).push(e)}),_("?","?",(t,e)=>t.not_added.push(e)),...nt("A","A","U"),...nt("D","D","U"),...nt("U","A","D","U"),["##",(t,e)=>{const n=/ahead (\d+)/,r=/behind (\d+)/,s=/^(.+?(?=(?:\.{3}|\s|$)))/,o=/\.{3}(\S*)/,i=/\son\s(\S+?)(?=\.{3}|$)/;let a=n.exec(e);t.ahead=a&&+a[1]||0,a=r.exec(e),t.behind=a&&+a[1]||0,a=s.exec(e),t.current=d(a?.[1],p,null),a=o.exec(e),t.tracking=d(a?.[1],p,null),a=i.exec(e),a&&(t.current=d(a?.[1],p,t.current)),t.detached=/\(no branch\)/.test(e)}]]),Dr=function(t){const e=t.split(I),n=new $r;for(let r=0,s=e.length;r<s;){let o=e[r++].trim();o&&(o.charAt(0)==="R"&&(o+=I+(e[r++]||"")),jr(n,o))}return n};function jr(t,e){const n=e.trim();switch(" "){case n.charAt(2):return r(n.charAt(0),n.charAt(1),n.slice(3));case n.charAt(1):return r(" ",n.charAt(0),n.slice(2));default:return}function r(s,o,i){const a=`${s}${o}`,c=Mr.get(a);c&&c(t,i),a!=="##"&&a!=="!!"&&t.files.push(new Nr(i,s,o))}}const Lr=["--null","-z"];function Br(t){return{format:"utf-8",commands:["status","--porcelain","-b","-u","--null",...t.filter(n=>!Lr.includes(n))],parser(n){return Dr(n)}}}const me="installed=false";function z(t=0,e=0,n=0,r="",s=!0){return Object.defineProperty({major:t,minor:e,patch:n,agent:r,installed:s},"toString",{value(){return`${this.major}.${this.minor}.${this.patch}`},configurable:!1,enumerable:!1})}function Ir(){return z(0,0,0,"",!1)}function Gr(){return{version(){return this._runTask({commands:["--version"],format:"utf-8",parser:Fr,onError(t,e,n,r){if(t.exitCode===Q.NOT_FOUND)return n(Buffer.from(me));r(e)}})}}}const Ur=[new l(/version (\d+)\.(\d+)\.(\d+)(?:\s*\((.+)\))?/,(t,[e,n,r,s=""])=>{Object.assign(t,z(m(e),m(n),m(r),s))}),new l(/version (\d+)\.(\d+)\.(\D+)(.+)?$/,(t,[e,n,r,s=""])=>{Object.assign(t,z(m(e),m(n),r,s))})];function Fr(t){return t===me?Ir():E(z(0,0,0,t),Ur,t)}class de{constructor(e){this._executor=e}_runTask(e,n){const r=this._executor.chain(),s=r.push(e);return n&&Pn(e,s,n),Object.create(this,{then:{value:s.then.bind(s)},catch:{value:s.catch.bind(s)},_executor:{value:r}})}add(e){return this._runTask(g(["add",...v(e)]),u(arguments))}cwd(e){const n=u(arguments);return typeof e=="string"?this._runTask(Ct(e,this._executor),n):typeof e?.path=="string"?this._runTask(Ct(e.path,e.root&&this._executor||void 0),n):this._runTask(b("Git.cwd: workingDirectory must be supplied as a string"),n)}hashObject(e,n){return this._runTask(qn(e,n===!0),u(arguments))}init(e){return this._runTask(Vn(e===!0,this._executor.cwd,h(arguments)),u(arguments))}merge(){return this._runTask(Nt(h(arguments)),u(arguments))}mergeFromTo(e,n){return p(e)&&p(n)?this._runTask(Nt([e,n,...h(arguments)]),u(arguments,!1)):this._runTask(b("Git.mergeFromTo requires that the 'remote' and 'branch' arguments are supplied as strings"))}outputHandler(e){return this._executor.outputHandler=e,this}push(){const e=pe({remote:d(arguments[0],p),branch:d(arguments[1],p)},h(arguments));return this._runTask(e,u(arguments))}stash(){return this._runTask(g(["stash",...h(arguments)]),u(arguments))}status(){return this._runTask(Br(h(arguments)),u(arguments))}}Object.assign(de.prototype,Nn(),Mn(),Bn(),gn(),Un(),Fn(),_n(),Xn(),cr(),xr(),Gr());const qr=(()=>{let t=0;return()=>{t++;const{promise:e,done:n}=P.createDeferred();return{promise:e,done:n,id:t}}})();class zr{constructor(e=2){this.concurrency=e,this.logger=M("","scheduler"),this.pending=[],this.running=[],this.logger("Constructed, concurrency=%s",e)}schedule(){if(!this.pending.length||this.running.length>=this.concurrency){this.logger("Schedule attempt ignored, pending=%s running=%s concurrency=%s",this.pending.length,this.running.length,this.concurrency);return}const e=R(this.running,this.pending.shift());this.logger("Attempting id=%s",e.id),e.done(()=>{this.logger("Completing id=",e.id),ut(this.running,e),this.schedule()})}next(){const{promise:e,id:n}=R(this.pending,qr());return this.logger("Scheduling id=%s",n),this.schedule(),e}}function Wr(t,e){return g(["apply",...e,...t])}var ge=(t=>(t.CURRENT="*",t.LINKED="+",t))(ge||{});class Hr{constructor(){this.all=[],this.branches={},this.current="",this.detached=!1}push(e,n,r,s,o){e==="*"&&(this.detached=n,this.current=r),this.all.push(r),this.branches[r]={current:e==="*",linkedWorkTree:e==="+",name:r,commit:s,label:o}}}const Kr=[new l(/^([*+]\s)?\((?:HEAD )?detached (?:from|at) (\S+)\)\s+([a-z0-9]+)\s(.*)$/,(t,[e,n,r,s])=>{t.push(Mt(e),!0,n,r,s)}),new l(/^([*+]\s)?(\S+)\s+([a-z0-9]+)\s?(.*)$/s,(t,[e,n,r,s])=>{t.push(Mt(e),!1,n,r,s)})],Vr=new l(/^(\S+)$/s,(t,[e])=>{t.push(ge.CURRENT,!1,e,"","")});function Mt(t){return t?t.charAt(0):""}function ye(t,e=!1){return E(new Hr,e?[Vr]:Kr,t)}class Qr{constructor(){this.all=[],this.branches={},this.errors=[]}get success(){return!this.errors.length}}function Xr(t,e){return{branch:t,hash:e,success:!0}}function Yr(t){return{branch:t,hash:null,success:!1}}const Jr=/(\S+)\s+\(\S+\s([^)]+)\)/,we=/^error[^']+'([^']+)'/m,Zr=[new l(Jr,(t,[e,n])=>{const r=Xr(e,n);t.all.push(r),t.branches[e]=r}),new l(we,(t,[e])=>{const n=Yr(e);t.errors.push(n),t.all.push(n),t.branches[e]=n})],bt=(t,e)=>E(new Qr,Zr,[t,e]);function be(t,e){return e===Q.ERROR&&we.test(t)}function ts(t){const e=["-d","-D","--delete"];return t.some(n=>e.includes(n))}function es(t){const e=ts(t),n=t.includes("--show-current"),r=["branch",...t];return r.length===1&&r.push("-a"),r.includes("-v")||r.splice(1,0,"-v"),{format:"utf-8",commands:r,parser(s,o){return e?bt(s,o).all[0]:ye(s,n)}}}function ns(){return{format:"utf-8",commands:["branch","-v"],parser(t){return ye(t)}}}function rs(t,e=!1){return{format:"utf-8",commands:["branch","-v",e?"-D":"-d",...t],parser(n,r){return bt(n,r)},onError({exitCode:n,stdOut:r},s,o,i){if(!be(String(s),n))return i(s);o(r)}}}function ss(t,e=!1){const n={format:"utf-8",commands:["branch","-v",e?"-D":"-d",t],parser(r,s){return bt(r,s).branches[t]},onError({exitCode:r,stdErr:s,stdOut:o},i,a,c){if(!be(String(i),r))return c(i);throw new W(n.parser(U(o),U(s)),String(i))}};return n}function os(t){return{commands:["check-ignore",...t],format:"utf-8",parser:is}}function is(t){return t.split(/\n/g).map(as).filter(Boolean)}function as(t){const e=t.trim().replace(/^["']|["']$/g,"");return e&&Re.normalize(e)}const us=[new l(/From (.+)$/,(t,[e])=>{t.remote=e}),new l(/\* \[new branch]\s+(\S+)\s*-> (.+)$/,(t,[e,n])=>{t.branches.push({name:e,tracking:n})}),new l(/\* \[new tag]\s+(\S+)\s*-> (.+)$/,(t,[e,n])=>{t.tags.push({name:e,tracking:n})}),new l(/- \[deleted]\s+\S+\s*-> (.+)$/,(t,[e])=>{t.deleted.push({tracking:e})}),new l(/\s*([^.]+)\.\.(\S+)\s+(\S+)\s*-> (.+)$/,(t,[e,n,r,s])=>{t.updated.push({name:r,tracking:s,to:n,from:e})})];function cs(t,e){return E({raw:t,remote:null,branches:[],tags:[],updated:[],deleted:[]},us,[t,e])}function fs(t){return/^--upload-pack(=|$)/.test(t)}function ls(t,e,n){const r=["fetch",...n];return t&&e&&r.push(t,e),r.find(fs)?b("git.fetch: potential exploit argument blocked."):{commands:r,format:"utf-8",parser:cs}}const hs=[new l(/^Renaming (.+) to (.+)$/,(t,[e,n])=>{t.moves.push({from:e,to:n})})];function ps(t){return E({moves:[]},hs,t)}function ms(t,e){return{commands:["mv","-v",...v(t),e],format:"utf-8",parser:ps}}function ds(t,e,n){const r=["pull",...n];return t&&e&&r.splice(1,0,t,e),{commands:r,format:"utf-8",parser(s,o){return he(s,o)},onError(s,o,i,a){const c=kr(U(s.stdOut),U(s.stdErr));if(c)return a(new W(c));a(o)}}}function gs(t){const e={};return Te(t,([n])=>e[n]={name:n}),Object.values(e)}function ys(t){const e={};return Te(t,([n,r,s])=>{Object.hasOwn(e,n)||(e[n]={name:n,refs:{fetch:"",push:""}}),s&&r&&(e[n].refs[s.replace(/[^a-z]/g,"")]=r)}),Object.values(e)}function Te(t,e){at(t,n=>e(n.split(/\s+/)))}function ws(t,e,n){return g(["remote","add",...n,t,e])}function bs(t){const e=["remote"];return t&&e.push("-v"),{commands:e,format:"utf-8",parser:t?ys:gs}}function Ts(t){const e=[...t];return e[0]!=="ls-remote"&&e.unshift("ls-remote"),g(e)}function ks(t){const e=[...t];return e[0]!=="remote"&&e.unshift("remote"),g(e)}function _s(t){return g(["remote","remove",t])}function vs(t={},e){const n=ce(t),r=["stash","list",...n.commands,...e],s=ae(n.splitter,n.fields,yt(r));return wt(r)||{commands:r,format:"utf-8",parser:s}}function Es(t,e){return X(["add",t,e])}function Ss(t){return X(["init",...t])}function X(t){const e=[...t];return e[0]!=="submodule"&&e.unshift("submodule"),g(e)}function Rs(t){return X(["update",...t])}class Os{constructor(e,n){this.all=e,this.latest=n}}const Cs=function(t,e=!1){const n=t.split(`
`).map(xs).filter(Boolean);e||n.sort(function(s,o){const i=s.split("."),a=o.split(".");if(i.length===1||a.length===1)return As(B(i[0]),B(a[0]));for(let c=0,y=Math.max(i.length,a.length);c<y;c++){const w=ke(B(i[c]),B(a[c]));if(w)return w}return 0});const r=e?n[0]:[...n].reverse().find(s=>s.indexOf(".")>=0);return new Os(n,r)};function As(t,e){const n=Number.isNaN(t),r=Number.isNaN(e);return n!==r?n?1:-1:n?ke(t,e):0}function ke(t,e){return t===e?0:t>e?1:-1}function xs(t){return t.trim()}function B(t){return typeof t=="string"&&parseInt(t.replace(/^\D+/g,""),10)||0}function Ps(t=[]){const e=t.some(n=>/^--sort=/.test(n));return{format:"utf-8",commands:["tag","-l",...t],parser(n){return Cs(n,e)}}}function Ns(t){return{format:"utf-8",commands:["tag",t],parser(){return{name:t}}}}function $s(t,e){return{format:"utf-8",commands:["tag","-a","-m",e,t],parser(){return{name:t}}}}function f(t,e){this._plugins=e,this._executor=new xn(t.baseDir,new zr(t.maxConcurrentProcesses),e),this._trimmed=t.trimmed}(f.prototype=Object.create(de.prototype)).constructor=f;f.prototype.customBinary=function(t){return this._plugins.reconfigure("binary",t),this};f.prototype.env=function(t,e){return arguments.length===1&&typeof t=="object"?this._executor.env=t:(this._executor.env=this._executor.env||{})[t]=e,this};f.prototype.stashList=function(t){return this._runTask(vs(lt(arguments)||{},V(t)&&t||[]),u(arguments))};f.prototype.mv=function(t,e){return this._runTask(ms(t,e),u(arguments))};f.prototype.checkoutLatestTag=function(t){var e=this;return this.pull(function(){e.tags(function(n,r){e.checkout(r.latest,t)})})};f.prototype.pull=function(t,e,n,r){return this._runTask(ds(d(t,p),d(e,p),h(arguments)),u(arguments))};f.prototype.fetch=function(t,e){return this._runTask(ls(d(t,p),d(e,p),h(arguments)),u(arguments))};f.prototype.tags=function(t,e){return this._runTask(Ps(h(arguments)),u(arguments))};f.prototype.rebase=function(){return this._runTask(g(["rebase",...h(arguments)]),u(arguments))};f.prototype.reset=function(t){return this._runTask(En(Sn(t),h(arguments)),u(arguments))};f.prototype.revert=function(t){const e=u(arguments);return typeof t!="string"?this._runTask(b("Commit must be a string"),e):this._runTask(g(["revert",...h(arguments,0,!0),t]),e)};f.prototype.addTag=function(t){const e=typeof t=="string"?Ns(t):b("Git.addTag requires a tag name");return this._runTask(e,u(arguments))};f.prototype.addAnnotatedTag=function(t,e){return this._runTask($s(t,e),u(arguments))};f.prototype.deleteLocalBranch=function(t,e,n){return this._runTask(ss(t,typeof e=="boolean"?e:!1),u(arguments))};f.prototype.deleteLocalBranches=function(t,e,n){return this._runTask(rs(t,typeof e=="boolean"?e:!1),u(arguments))};f.prototype.branch=function(t,e){return this._runTask(es(h(arguments)),u(arguments))};f.prototype.branchLocal=function(t){return this._runTask(ns(),u(arguments))};f.prototype.raw=function(t){const e=!Array.isArray(t),n=[].slice.call(e?arguments:t,0);for(let s=0;s<n.length&&e;s++)if(!st(n[s])){n.splice(s,n.length-s);break}n.push(...h(arguments,0,!0));var r=u(arguments);return n.length?this._runTask(g(n,this._trimmed),r):this._runTask(b("Raw: must supply one or more command to execute"),r)};f.prototype.submoduleAdd=function(t,e,n){return this._runTask(Es(t,e),u(arguments))};f.prototype.submoduleUpdate=function(t,e){return this._runTask(Rs(h(arguments,!0)),u(arguments))};f.prototype.submoduleInit=function(t,e){return this._runTask(Ss(h(arguments,!0)),u(arguments))};f.prototype.subModule=function(t,e){return this._runTask(X(h(arguments)),u(arguments))};f.prototype.listRemote=function(){return this._runTask(Ts(h(arguments)),u(arguments))};f.prototype.addRemote=function(t,e,n){return this._runTask(ws(t,e,h(arguments)),u(arguments))};f.prototype.removeRemote=function(t,e){return this._runTask(_s(t),u(arguments))};f.prototype.getRemotes=function(t,e){return this._runTask(bs(t===!0),u(arguments))};f.prototype.remote=function(t,e){return this._runTask(ks(h(arguments)),u(arguments))};f.prototype.tag=function(t,e){const n=h(arguments);return n[0]!=="tag"&&n.unshift("tag"),this._runTask(g(n),u(arguments))};f.prototype.updateServerInfo=function(t){return this._runTask(g(["update-server-info"]),u(arguments))};f.prototype.pushTags=function(t,e){const n=Ar({remote:d(t,p)},h(arguments));return this._runTask(n,u(arguments))};f.prototype.rm=function(t){return this._runTask(g(["rm","-f",...v(t)]),u(arguments))};f.prototype.rmKeepLocal=function(t){return this._runTask(g(["rm","--cached",...v(t)]),u(arguments))};f.prototype.catFile=function(t,e){return this._catFile("utf-8",arguments)};f.prototype.binaryCatFile=function(){return this._catFile("buffer",arguments)};f.prototype._catFile=function(t,e){var n=u(e),r=["cat-file"],s=e[0];if(typeof s=="string")return this._runTask(b("Git.catFile: options must be supplied as an array of strings"),n);Array.isArray(s)&&r.push.apply(r,s);const o=t==="buffer"?Qt(r):g(r);return this._runTask(o,n)};f.prototype.diff=function(t,e){const n=p(t)?b("git.diff: supplying options as a single string is no longer supported, switch to an array of strings"):g(["diff",...h(arguments)]);return this._runTask(n,u(arguments))};f.prototype.diffSummary=function(){return this._runTask(or(h(arguments,1)),u(arguments))};f.prototype.applyPatch=function(t){const e=F(t)?Wr(v(t),h([].slice.call(arguments,1))):b("git.applyPatch requires one or more string patches as the first argument");return this._runTask(e,u(arguments))};f.prototype.revparse=function(){const t=["rev-parse",...h(arguments,!0)];return this._runTask(g(t,!0),u(arguments))};f.prototype.clean=function(t,e,n){const r=rn(t),s=r&&t.join("")||d(t,p)||"",o=h([].slice.call(arguments,r?1:0));return this._runTask(en(s,o),u(arguments))};f.prototype.exec=function(t){const e={commands:[],format:"utf-8",parser(){typeof t=="function"&&t()}};return this._runTask(e)};f.prototype.checkIgnore=function(t,e){return this._runTask(os(v(d(t,F,[]))),u(arguments))};f.prototype.checkIsRepo=function(t,e){return this._runTask(Ue(d(t,p)),u(arguments))};function Ms(t){return t?[{type:"spawn.before",action(r,s){t.aborted&&s.kill(new x(void 0,"abort","Abort already signaled"))}},{type:"spawn.after",action(r,s){function o(){s.kill(new x(void 0,"abort","Abort signal received"))}t.addEventListener("abort",o),s.spawned.on("close",()=>t.removeEventListener("abort",o))}}]:void 0}const Ds=M("","plugin:allowEnvironment");function js(t,e=!1){const n=new Set(t.map(r=>r.toLowerCase().trim()));return{type:"spawn.options",action(r,s){const o={...r.env??process.env},i=new Set(Object.keys(s.env).map(a=>a.toLowerCase().trim()));for(const a of Object.keys(o)){const c=a.toLowerCase().trim();if(!(!Ls(c)||n.has(c))){if(i.has(c))throw new x(void 0,"allowEnvironment",`Use of "${a}" is blocked by the environment guard - add it to the allowEnvironment option to permit it`);Ds("removing ambient guarded environment variable %s",a),delete o[a]}}return{...r,env:{...o,GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS:String(!e)}}}}}function Ls(t){const e=t.toLowerCase().trim();return e.startsWith("git_")||Bt.isGitEnvKey(e)}function Bs(t={}){return{type:"spawn.args",action(e,{env:n}){for(const r of Bt.vulnerabilityCheck(e,n))if(t[r.category]!==!0)throw new x(void 0,"unsafe",r.message);return e}}}function Is(t){const e=G(t,"-c");return{type:"spawn.args",action(n){return[...e,...n]}}}const Dt=P.deferred().promise;function Gs({onClose:t=!0,onExit:e=50}={}){function n(){let s=-1;const o={close:P.deferred(),closeTimeout:P.deferred(),exit:P.deferred(),exitTimeout:P.deferred()},i=Promise.race([t===!1?Dt:o.closeTimeout.promise,e===!1?Dt:o.exitTimeout.promise]);return r(t,o.close,o.closeTimeout),r(e,o.exit,o.exitTimeout),{close(a){s=a,o.close.done()},exit(a){s=a,o.exit.done()},get exitCode(){return s},result:i}}function r(s,o,i){s!==!1&&(s===!0?o.promise:o.promise.then(()=>kt(s))).then(i.done)}return{type:"spawn.after",async action(s,{spawned:o,close:i}){const a=n();let c=!0,y=()=>{c=!1};o.stdout?.on("data",y),o.stderr?.on("data",y),o.on("error",y),o.on("close",w=>a.close(w)),o.on("exit",w=>a.exit(w));try{await a.result,c&&await kt(50),i(a.exitCode)}catch(w){i(a.exitCode,w)}}}}const _e=M("","plugin:binary"),Us="Invalid value supplied for custom binary, requires a single string or an array containing either one or two strings",Fs="Invalid value supplied for custom binary, restricted characters must be removed or supply the unsafe.allowUnsafeCustomBinary option";function qs(t){return!t||!/^([a-z]:)?([a-z0-9/.\\_~-]+)$/i.test(t)}function jt(t,e){if(t.length<1||t.length>2)throw new x(void 0,"binary",Us);if(t.some(qs))if(e)_e("permitted unsafe binary %o",t);else throw new x(void 0,"binary",Fs);const[r,s]=t;return{binary:r,prefix:s}}function zs(t,e=["git"],n=!1){let r=jt(v(e),n);t.on("binary",s=>{r=jt(v(s),n),_e.info("reconfiguring %o",r)}),t.append("spawn.binary",()=>r.binary),t.append("spawn.args",s=>r.prefix?[r.prefix,...s]:s)}const ve={DISALLOWED_ABBREVIATED:{text:"disallowed abbreviated or ambiguous option",solution:"Unambiguous abbreviated options blocked with unsafe.allowAbbreviatedOptions setting: {message}"},UNKNOWN:{text:"~ unknown ~",solution:void 0}};function Ws(t){if(!t)return"UNKNOWN";for(const[e,{text:n}]of Object.entries(ve))if(t.startsWith(`fatal: ${n}`))return e;return"UNKNOWN"}class Hs extends C{constructor(e=""){const n=Ws(e);super(void 0,ve[n].solution?.replace("{message}",e)??e),this.reason=n}}function Ks(t){return!!(t.exitCode&&t.stdErr.length)}function Vs(t){return Buffer.concat([...t.stdOut,...t.stdErr])}function Qs(t=!1,e=Ks,n=Vs){return(r,s)=>!t&&r||!e(s)?r:n(s)}function Xs(t,e){return t===128&&e.startsWith("fatal:")?new Hs(e):new C(void 0,e)}function Lt(t){return{type:"task.error",action(e,n){const r=t(e.error,{stdErr:n.stdErr,stdOut:n.stdOut,exitCode:n.exitCode});return Buffer.isBuffer(r)?{error:Xs(n.exitCode,r.toString("utf-8"))}:{error:r}}}}const rt=M("","plugin:input");function Ys(t){return{type:"spawn.after",action(e,{commands:n,input:r,spawned:{stdin:s}}){if(!s)return;const o=t?.([...n])??r;if(!o)return rt("generated zero length content, not writing to stdin");rt("writing %s bytes to stdin",$e(o)),s.on("error",i=>{i.code!=="EPIPE"&&rt("[ERROR] stdin error %o",i)}),s.end(o)}}}class Js{constructor(){this.plugins=new Set,this.events=new Oe.EventEmitter}on(e,n){this.events.on(e,n)}reconfigure(e,n){this.events.emit(e,n)}append(e,n){const r=R(this.plugins,{type:e,action:n});return()=>this.plugins.delete(r)}add(e){const n=[];return v(e).forEach(r=>{r&&this.plugins.add(R(n,r))}),()=>{n.forEach(r=>{this.plugins.delete(r)})}}exec(e,n,r){let s=n;const o=Object.freeze(Object.create(r));for(const i of this.plugins)i.type===e&&(s=i.action(s,o));return s}}function Zs(t){const e="--progress",n=["checkout","clone","fetch","pull","push"];return[{type:"spawn.args",action(o,i){return n.includes(i.method)?Ne(o,e):o}},{type:"spawn.after",action(o,i){i.commands.includes(e)&&i.spawned.stderr?.on("data",a=>{const c=/^([\s\S]+?):\s*(\d+)% \((\d+)\/(\d+)\)/.exec(a.toString("utf8"));c&&t({method:i.method,stage:to(c[1]),progress:m(c[2]),processed:m(c[3]),total:m(c[4])})})}}]}function to(t){return String(t.toLowerCase().split(" ",1))||"unknown"}function eo(t){const e=Me(t,["uid","gid"]);return{type:"spawn.options",action(n){return{...e,...n}}}}function no(){return{type:"spawn.args",action(t){const e=[];let n;function r(s){(n=n||[]).push(...s)}for(let s=0;s<t.length;s++){const o=t[s];if(S.isPathSpec(o)){r(S.toPaths(o));continue}if(o==="--"){r(t.slice(s+1).flatMap(i=>S.isPathSpec(i)&&S.toPaths(i)||i));break}e.push(o)}return n?[...e,"--",...n.map(String)]:e}}}function ro({block:t,stdErr:e=!0,stdOut:n=!0}){if(t>0)return{type:"spawn.after",action(r,s){let o;function i(){o&&clearTimeout(o),o=setTimeout(c,t)}function a(){s.spawned.stdout?.off("data",i),s.spawned.stderr?.off("data",i),s.spawned.off("exit",a),s.spawned.off("close",a),o&&clearTimeout(o)}function c(){a(),s.kill(new x(void 0,"timeout","block timeout reached"))}n&&s.spawned.stdout?.on("data",i),e&&s.spawned.stderr?.on("data",i),s.spawned.on("exit",a),s.spawned.on("close",a),i()}}}const so=(t,e)=>{const n=new Js,r=Ie(t&&(typeof t=="string"?{baseDir:t}:t)||{},e);if(!Ft(r.baseDir))throw new It(r,"Cannot use simple-git on a directory that does not exist");return Array.isArray(r.config)&&n.add(Is(r.config)),n.add(Bs(r.unsafe)),n.add(Gs(r.completion)),r.abort&&n.add(Ms(r.abort)),r.progress&&n.add(Zs(r.progress)),r.timeout&&n.add(ro(r.timeout)),r.spawnOptions&&n.add(eo(r.spawnOptions)),n.add(no()),n.add(Ys(r.input)),n.add(Lt(Qs(!0))),r.errors&&n.add(Lt(r.errors)),zs(n,r.binary,r.unsafe?.allowUnsafeCustomBinary),n.add(js(r.allowEnvironment??[],r.unsafe?.allowAbbreviatedOptions)),new f(r,n)};Object.defineProperty(exports,"pathspec",{enumerable:!0,get:()=>S.pathspec});exports.CheckRepoActions=Ht;exports.CleanOptions=pt;exports.DiffNameStatus=dt;exports.GitConfigScope=mt;exports.GitConstructError=It;exports.GitError=C;exports.GitPluginError=x;exports.GitResponseError=W;exports.ResetMode=gt;exports.TaskConfigurationError=Gt;exports.grepQueryBuilder=Jt;exports.simpleGit=so;
//# sourceMappingURL=index.cjs.map