import{a as R}from"./chunk-VJEKDBGZ.js";import{e as l}from"./chunk-E24W34C4.js";import{f as I}from"./chunk-3QVXHF6I.js";import{d as n}from"./chunk-ELIH6GCC.js";import{Ea as b,Fb as a,Hb as s,Pb as f,Ta as G,Wa as C}from"./chunk-EYDNSYYE.js";import{a as k,r as w}from"./chunk-JCNRQYRP.js";import{q as g}from"./chunk-773TIA5M.js";import{e as D,g as $}from"./chunk-VKWPEFWQ.js";$();var A=D(R());async function r(t,e){try{return(await l("git",t,{cwd:e})).stdout}catch(o){if(o instanceof Error){let i=new n(o.message);throw i.stack=o.stack,"exitCode"in o&&Object.assign(i,{exitCode:o.exitCode}),i}throw o}}async function K(t,e="main"){f(s`Initializing git repository at ${a.path(t)}...`),await h(),await r(["init"],t),await r(["checkout","-b",e],t)}async function Q(t,e){try{return(await r(["check-ignore",...e],t)).split(`
`).filter(Boolean)}catch(o){if(o instanceof n&&"exitCode"in o&&o.exitCode===1)return[];throw o}}async function V(t){return I("cmd_all_timing_network_ms")(async()=>{let{repoUrl:e,destination:o,shallow:i,latestTag:m}=t;if(f(s`Git-cloning repository ${e} into ${a.path(o)}...`),await h(),await G(o)){if(!await b(o))throw new n(s`Can't clone to ${a.path(o)}`,"The path exists but isn't a directory.");if((await C(["*",".*"],{cwd:o,deep:1,onlyFiles:!1})).length>0)throw new n(s`Directory ${a.path(o)} already exists and is not empty`,s`Choose a different name or remove the existing directory first.`)}let[v,d]=e.split("#");if(d&&m)throw new n("Error cloning the repository. Git can't clone the latest release with a 'branch'.");if(i&&m)throw new n("Error cloning the repository. Git can't clone the latest release with the 'shallow' property.");let u=["clone","--recurse-submodules"];d&&u.push("--branch",d),i&&u.push("--depth","1"),k()||u.push("-c","core.askpass=true"),u.push(v,o);try{if(await l("git",u),m){let c=await S(o,e);await r(["checkout",c],o)}}catch(c){if(c instanceof n)throw c;if(c instanceof Error){let x=new n(c.message);throw x.stack=c.stack,x}throw c}})}async function S(t,e){let o=await F(t);if(!o)throw new n(`Couldn't obtain the most recent tag of the repository ${e}`);return o}async function X(t){let o=await r(["log","-1","--format=%H%x00%ai%x00%s%x00%D%x00%b%x00%an%x00%ae"],t);if(!o.trim())throw new n("Must have at least one commit to run command",s`Run ${a.genericShellCommand("git commit -m 'Initial commit'")} to create your first commit.`);let i=o.split("\0");return{hash:i[0],date:i[1],message:i[2],refs:i[3],body:i[4],author_name:i[5],author_email:i[6]}}async function Y(t){await r(["add","--all"],t)}async function Z(t,e){let o=["commit","-m",t];return e?.author&&o.push("--author",e.author),await r(o,e?.directory),(await r(["rev-parse","HEAD"],e?.directory)).trim()}async function h(){if(!await w())throw new n("Git is necessary in the environment to continue",s`Install ${a.link("git","https://git-scm.com/book/en/v2/Getting-Started-Installing-Git")}`)}var p=class extends n{};async function N(t){if(await h(),!await E(t))throw new p(`${a.path(t??g())} is not a Git directory`)}async function tt(t){return await w()?E(t):!1}async function E(t){try{return await l("git",["rev-parse","--git-dir"],{cwd:t}),!0}catch(e){if(e instanceof Error&&"exitCode"in e&&e.exitCode===128)return!1;throw e}}var y=class extends n{};async function et(t){if(!await T(t))throw new y(`${a.path(t??g())} is not a clean Git directory`)}async function T(t){return(await r(["status","--porcelain"],t)).trim()===""}async function F(t){try{return(await r(["describe","--tags","--abbrev=0"],t)).trim()||void 0}catch(e){if(e instanceof n&&"exitCode"in e&&e.exitCode===128)return;throw e}}async function ot(t,e="origin"){if(f(s`Removing git remote ${e} from ${a.path(t)}...`),await h(),!(await r(["remote"],t)).split(`
`).filter(Boolean).includes(e)){f(s`Remote ${e} does not exist, no action needed`);return}await r(["remote","remove",e],t)}export{K as a,Q as b,V as c,X as d,Y as e,Z as f,N as g,tt as h,y as i,et as j,T as k,ot as l};
