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