UNPKG

simple-git

Version:

Simple GIT interface for node.js

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