function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var t=require("fs"),r=e(require("https")),o=require("path"),s=require("tar"),n=e(require("hosted-git-info"));exports.createClone=async function(e,i,{force:a=!1}={}){const c=n.fromUrl(e),h=c.type,p="gitlab"===h?function(e){return`https://gitlab.com/api/v4/projects/${encodeURIComponent(`${e.user}/${e.project}`)}/repository/archive.tar.gz${e.committish?`?sha=${e.committish}`:""}`}(c):c.tarball();if(!p)throw new Error("Unable to determine where to download the archive for this repository");const u=new URL(p);await async function(e){try{await t.promises.mkdir(e)}catch(e){if("EEXIST"!==e.code)throw e}}(i),a||await async function(e){try{if((await t.promises.readdir(e)).length>0)throw new Error(`The output directory already contains files (${o.resolve(e)})`)}catch(e){if("ENOENT"!==e.code)throw e}}(i),await function e(t,o,n){return new Promise((i,a)=>{const c={};"github"===o&&process.env.GITHUB_TOKEN&&(c.Authorization=`token ${process.env.GITHUB_TOKEN}`),"gitlab"===o&&process.env.GITLAB_TOKEN&&(c["PRIVATE-TOKEN"]=process.env.GITLAB_TOKEN),"bitbucket"===o&&process.env.BITBUCKET_USER&&process.env.BITBUCKET_TOKEN&&(t.username=process.env.BITBUCKET_USER,t.password=process.env.BITBUCKET_TOKEN),r.get(t,{headers:c},t=>{const r=t.statusCode;if(!r||r>=400)return a({code:r,message:t.statusMessage});if(r>=300)return e(new URL(t.headers.location),o,n).then(i).catch(a);const c=s.extract({cwd:n,strip:1});t.pipe(c).on("finish",i).on("error",a)}).on("error",a)})}(u,h,i)};