gitpick 5.4.0-canary.2 → 5.4.0-canary.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.mjs +3 -3
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -15,7 +15,7 @@ import e from"node:fs";import t from"node:os";import n from"node:path";import{pa
15
15
  `;let s=f.length>r?E(`${l+1}-${Math.min(l+r,f.length)}/${f.length}`)+E(` • `):``,d=E(`↑↓:navigate esc/q:back`);i+=` ${s}${d}\n`,u.write(i)}function S(e){let t=e.toString();if(t===``){g=!1,_=null,d.removeListener(`data`,S),p(),process.removeListener(`exit`,m),process.removeListener(`SIGINT`,h),a([]);return}if(t===`\x1B`||t===`q`||t===`Q`||t===`\r`){g=!1,_=null,d.removeListener(`data`,S),d.on(`data`,x),y();return}(t===`\x1B[A`||t===`k`)&&c>0&&c--,(t===`\x1B[B`||t===`j`)&&c<f.length-1&&c++,b()}g=!0,_=b,d.on(`data`,S),b()}function x(e){let t=kn(o),n=t.length+1,r=e.toString();if(r===``||r===`q`||r===`Q`){p(),process.removeListener(`exit`,m),process.removeListener(`SIGINT`,h),a([]);return}if(r===`c`||r===`C`){p(),process.removeListener(`exit`,m),process.removeListener(`SIGINT`,h),a(jn(o));return}if((r===`\x1B[A`||r===`k`)&&c>0&&c--,(r===`\x1B[B`||r===`j`)&&c<n-1&&c++,c===0&&(r===` `||r===`\r`)||r===`.`){let e=o.every(e=>e.selected);for(let t of o)W(t,!e)}if(r===` `&&c>0){let e=t[c-1];if(e){let t=!e.node.selected;if(W(e.node,t),t&&e.node.type===`symlink`&&e.node.linkTarget){let t=K(o,G(e.node.path,e.node.linkTarget));t&&W(t,!0)}An(o)}}if(r===`\r`&&c>0){let e=t[c-1];if(e&&e.node.type===`tree`)e.node.expanded=!e.node.expanded;else if(e&&e.node.type===`symlink`&&e.node.linkTarget.endsWith(`/`)){let t=G(e.node.path,e.node.linkTarget),n=t.split(`/`);for(let e=1;e<=n.length;e++){let t=K(o,n.slice(0,e).join(`/`));t&&t.type===`tree`&&(t.expanded=!0)}let r=K(o,t);if(r){r.type===`tree`&&(r.expanded=!0);let e=kn(o).findIndex(e=>e.node===r);e>=0&&(c=e+1)}}else if(e&&i&&(e.node.type===`blob`||e.node.type===`symlink`)){b(e.node);return}}if((r===`\x1B[C`||r===`l`)&&c>0){let e=t[c-1];e&&e.node.type===`tree`&&(e.node.expanded=!0)}if((r===`\x1B[D`||r===`h`)&&c>0){let e=t[c-1];e&&e.node.type===`tree`&&(e.node.expanded=!1)}y()}d.on(`data`,x),y()})}function Pn(e){if(typeof e==`number`||/^\d+$/.test(e))return typeof e==`number`?e:parseInt(e,10);let t=/(\d+)([hms])/g,n=0,r;for(;(r=t.exec(e))!==null;){let e=parseInt(r[1],10);switch(r[2]){case`h`:n+=e*36e5;break;case`m`:n+=e*6e4;break;case`s`:n+=e*1e3;break}}return n}const Fn=async e=>{let t=(await S(`git`,[`ls-remote`,e])).stdout,n=t.match(/(.+)\s+HEAD/)?.[1],r=t.match(RegExp(`${n}\\s+refs/heads/(.+)`))?.[1];if(!r)throw Error(`Could not determine default branch!`);return r},In=[{prefix:`git@github.com:`,host:`github.com`},{prefix:`https://github.com/`,host:`github.com`},{prefix:`https://raw.githubusercontent.com/`,host:`github.com`},{prefix:`git@gitlab.com:`,host:`gitlab.com`},{prefix:`https://gitlab.com/`,host:`gitlab.com`},{prefix:`git@bitbucket.org:`,host:`bitbucket.org`},{prefix:`https://bitbucket.org/`,host:`bitbucket.org`}];async function Ln(e,{branch:t,target:n}){let r=e.match(/^https:\/\/([^@]+)@(github\.com|gitlab\.com|bitbucket\.org)/),i=``;if(r)i=r[1],e=e.replace(`${r[1]}@`,``);else{let t={"github.com":process.env.GITHUB_TOKEN||process.env.GH_TOKEN||``,"gitlab.com":process.env.GITLAB_TOKEN||``,"bitbucket.org":process.env.BITBUCKET_TOKEN||``};for(let{prefix:n,host:r}of In)if(e.startsWith(n)){i=t[r];break}!i&&!e.startsWith(`https://`)&&!e.startsWith(`git@`)&&(i=t[`github.com`])}let a=`github.com`;for(let{prefix:t,host:n}of In)if(e.startsWith(t)){a=n,e=e.replace(t,``);break}let o=e.split(`/`),s=o[0],c=o[1]?.endsWith(`.git`)?o[1].slice(0,-4):o[1],l=`https://${i&&i+`@`}${a}/${s}/${c}`,u,d,f;a===`github.com`?o[2]===`refs`&&[`heads`,`tags`].includes(o[3])?(u=`raw`,d=t||o[4],f=o.slice(5).join(`/`)):o[2]===`refs`&&o[3]===`remotes`?(u=`raw`,d=t||`${o[4]}/${o[5]}`,f=o.slice(6).join(`/`)):o[2]===`blob`?(u=`blob`,d=t||o[3],f=o.slice(4).join(`/`)):o[2]===`tree`?(u=`tree`,d=t||o[3],f=o.slice(4).join(`/`)):o[2]===`commit`?(u=`repository`,d=t||o[3],f=``):(u=`repository`,d=t||await Fn(l),f=``):a===`gitlab.com`?o[2]===`-`&&o[3]===`blob`?(u=`blob`,d=t||o[4],f=o.slice(5).join(`/`)):o[2]===`-`&&o[3]===`tree`?(u=`tree`,d=t||o[4],f=o.slice(5).join(`/`)):(u=`repository`,d=t||await Fn(l),f=``):o[2]===`src`?(u=`tree`,d=t||o[3],f=o.slice(4).join(`/`)):(u=`repository`,d=t||await Fn(l),f=``);let p=n||(u===`blob`?`.`:f.split(`/`).pop()||c);return{token:i,host:a,owner:s,repository:c,type:u,branch:d,path:f,target:p}}const Rn=n.join(t.homedir(),`.cache`,`gitpick`),zn=n.join(Rn,`update-check.json`);function Bn(){try{return JSON.parse(e.readFileSync(zn,`utf-8`))}catch{return null}}function Vn(t){try{e.mkdirSync(Rn,{recursive:!0}),e.writeFileSync(zn,JSON.stringify(t))}catch{}}function Hn(){return new Promise(e=>{let t=d.get(`https://registry.npmjs.org/gitpick/latest`,{headers:{Accept:`application/json`},timeout:3e3},t=>{if(t.statusCode!==200)return t.resume(),e(null);let n=``;t.on(`data`,e=>n+=e),t.on(`end`,()=>{try{e(JSON.parse(n).version||null)}catch{e(null)}})});t.on(`error`,()=>e(null)),t.on(`timeout`,()=>{t.destroy(),e(null)})})}function Un(e,t){let n=e.split(`.`).map(Number),r=t.split(`.`).map(Number);for(let e=0;e<3;e++){if((n[e]||0)>(r[e]||0))return!0;if((n[e]||0)<(r[e]||0))return!1}return!1}function J(e,t){if(t)return;let n=Bn();n&&Un(n.latestVersion,e)&&console.log(E(`\n Update available: ${k(e)} → ${A(T(n.latestVersion))}\n Run ${A(`npm i -g gitpick`)} to update\n`))}function Wn(){let e=Bn();e&&Date.now()-e.lastCheck<864e5||setTimeout(async()=>{let e=await Hn();e&&Vn({lastCheck:Date.now(),latestVersion:e})},0)}const Y=Symbol(`singleComment`),Gn=Symbol(`multiComment`),X=(e,t,n)=>e.slice(t,n).replace(/[^ \t\r\n]/g,` `),Kn=(e,t)=>{let n=t-1,r=0;for(;e[n]===`\\`;)--n,r+=1;return!!(r%2)};function qn(e){if(typeof e!=`string`)throw TypeError(`Expected argument \`jsonString\` to be a \`string\`, got \`${typeof e}\``);let t=!1,n=!1,r=0,i=``,a=``,o=-1;for(let s=0;s<e.length;s++){let c=e[s],l=e[s+1];if(!n&&c===`"`&&(Kn(e,s)||(t=!t)),!t)if(!n&&c+l===`//`)i+=e.slice(r,s),r=s,n=Y,s++;else if(n===Y&&c+l===`\r
16
16
  `){s++,n=!1,i+=X(e,r,s),r=s;continue}else if(n===Y&&c===`
17
17
  `)n=!1,i+=X(e,r,s),r=s;else if(!n&&c+l===`/*`){i+=e.slice(r,s),r=s,n=Gn,s++;continue}else if(n===Gn&&c+l===`*/`){s++,n=!1,i+=X(e,r,s+1),r=s+1;continue}else n||(o===-1?c===`,`&&(a+=i+e.slice(r,s),i=``,r=s,o=s):c===`}`||c===`]`?(i+=e.slice(r,s),a+=X(i,0,1)+i.slice(1),i=``,r=s,o=-1):c!==` `&&c!==` `&&c!==`\r`&&c!==`
18
- `&&(i+=e.slice(r,s),r=s,o=-1))}let s=n===Y?X(e,r):e.slice(r);return a+i+s}const Jn=[`.gitpick.json`,`.gitpick.jsonc`],Yn=async()=>{let t;for(let r of Jn){let i=n.resolve(r);if(e.existsSync(i)){t=i;break}}if(!t)return!1;let r=await e.promises.readFile(t,`utf-8`),i=JSON.parse(qn(r));if(!Array.isArray(i)||!i.every(e=>typeof e==`string`))throw Error(`${n.basename(t)} must be an array of strings`);for(let e of i)await S(process.argv[0],[...process.argv.slice(1),...e.split(/\s+/),`-o`],{stdio:`inherit`});return!0};var Xn=`gitpick`,Z=`5.4.0-canary.2`;const Zn=(e,t)=>`\x1b]8;;${t}\x07${e}\x1b]8;;\x07`,Qn=`
18
+ `&&(i+=e.slice(r,s),r=s,o=-1))}let s=n===Y?X(e,r):e.slice(r);return a+i+s}const Jn=[`.gitpick.json`,`.gitpick.jsonc`],Yn=async()=>{let t;for(let r of Jn){let i=n.resolve(r);if(e.existsSync(i)){t=i;break}}if(!t)return!1;let r=await e.promises.readFile(t,`utf-8`),i=JSON.parse(qn(r));if(!Array.isArray(i)||!i.every(e=>typeof e==`string`))throw Error(`${n.basename(t)} must be an array of strings`);for(let e of i)await S(process.argv[0],[...process.argv.slice(1),...e.split(/\s+/),`-o`],{stdio:`inherit`});return!0};var Xn=`gitpick`,Z=`5.4.0-canary.3`;const Zn=(e,t)=>`\x1b]8;;${t}\x07${e}\x1b]8;;\x07`,Qn=`
19
19
  With ${T(`${Zn(`GitPick`,`https://github.com/nrjdalal/gitpick`)}`)} clone specific directories or files from GitHub, GitLab and Bitbucket!
20
20
 
21
21
  $ gitpick ${k(`<url>`)} ${O(`[target]`)} ${A(`[options]`)}
@@ -52,10 +52,10 @@ ${T(`Examples:`)}
52
52
  $ gitpick https://gitlab.com/owner/repo
53
53
  $ gitpick https://bitbucket.org/owner/repo
54
54
 
55
- 🚀 More awesome tools at ${A(`https://github.com/nrjdalal`)}`,Q=e=>{let r=process.cwd(),i=t.homedir(),a=n.sep;return e===r?`.`:e.startsWith(r+a)?`./`+n.relative(r,e).replaceAll(a,`/`):e.startsWith(i+a)?`~/`+n.relative(i,e).replaceAll(a,`/`):e},$=async(t,r=``)=>{let i=(await e.promises.readdir(t,{withFileTypes:!0})).filter(e=>e.name!==`.git`).sort((e,t)=>e.name.localeCompare(t.name,void 0,{sensitivity:`base`}));for(let a=0;a<i.length;a++){let o=i[a],s=a===i.length-1,c=s?`└── `:`├── `,l=n.join(t,o.name);if(o.isSymbolicLink()){let t=await e.promises.readlink(l),n=!1;try{n=e.statSync(l).isDirectory()}catch{}process.stdout.write(`${r}${c}${k(o.name)} -> ${n?A(t):t}\n`)}else o.isDirectory()?(process.stdout.write(`${r}${c}${A(o.name)}\n`),await $(l,`${r}${s?` `:`│ `}`)):process.stdout.write(`${r}${c}${o.name}\n`)}},$n=e=>{try{return r(e)}catch(e){throw Error(`Error parsing arguments: ${e.message}`)}};(async()=>{Wn();try{let{positionals:r,values:i}=$n({allowPositionals:!0,options:{branch:{type:`string`,short:`b`},"dry-run":{type:`boolean`,short:`n`},force:{type:`boolean`,short:`f`},help:{type:`boolean`,short:`h`},interactive:{type:`boolean`,short:`i`},quiet:{type:`boolean`,short:`q`},tree:{type:`boolean`},verbose:{type:`boolean`},overwrite:{type:`boolean`,short:`o`},recursive:{type:`boolean`,short:`r`},version:{type:`boolean`,short:`v`},watch:{type:`string`,short:`w`}}});r.length||(i.version&&(console.log(`\n${Xn}@${Z}`),process.exit(0)),i.interactive?r.push(`.`):(await Yn()&&process.exit(0),console.log(Qn),process.exit(0))),r[0]===`clone`&&r.shift();let[a,o]=r,s={branch:i.branch,dryRun:i[`dry-run`],force:i.force,interactive:i.interactive,quiet:i.quiet,tree:i.tree,verbose:i.verbose,overwrite:i.overwrite,recursive:i.recursive,watch:i.watch};if((a===`.`||a.startsWith(`./`)||a.startsWith(`../`)||a.startsWith(`/`)||a.startsWith(`~/`)||s.interactive&&!a.includes(`/`)&&!a.startsWith(`http`)&&!a.startsWith(`git@`))&&s.interactive){if(e.existsSync(n.resolve(a.startsWith(`~/`)?a.replace(`~`,t.homedir()):a))||(o=a,a=`.`),!process.stdout.isTTY)throw Error(`Interactive mode requires a TTY`);let r=n.resolve(a.startsWith(`~/`)?a.replace(`~`,t.homedir()):a);if(!e.existsSync(r))throw Error(`Directory not found: ${a}`);if(!e.statSync(r).isDirectory())throw Error(`Not a directory: ${a}`);let i=o?n.resolve(o):null,c=[],l=!1;try{let t=(await S(`git`,[`ls-files`,`--cached`,`--others`,`--exclude-standard`],{cwd:r})).stdout.trim().split(`
55
+ 🚀 More awesome tools at ${A(`https://github.com/nrjdalal`)}`,Q=e=>{let r=process.cwd(),i=t.homedir(),a=n.sep;return e===r?`.`:e.startsWith(r+a)?`./`+n.relative(r,e).replaceAll(a,`/`):e.startsWith(i+a)?`~/`+n.relative(i,e).replaceAll(a,`/`):e},$=async(t,r=``)=>{let i=(await e.promises.readdir(t,{withFileTypes:!0})).filter(e=>e.name!==`.git`).sort((e,t)=>e.name.localeCompare(t.name,void 0,{sensitivity:`base`}));for(let a=0;a<i.length;a++){let o=i[a],s=a===i.length-1,c=s?`└── `:`├── `,l=n.join(t,o.name);if(o.isSymbolicLink()){let t=await e.promises.readlink(l),n=!1;try{n=e.statSync(l).isDirectory()}catch{}process.stdout.write(`${r}${c}${k(o.name)} -> ${n?A(t):t}\n`)}else o.isDirectory()?(process.stdout.write(`${r}${c}${A(o.name)}\n`),await $(l,`${r}${s?` `:`│ `}`)):process.stdout.write(`${r}${c}${o.name}\n`)}},$n=e=>{try{return r(e)}catch(e){throw Error(`Error parsing arguments: ${e.message}`)}};(async()=>{Wn();try{let{positionals:r,values:i}=$n({allowPositionals:!0,options:{branch:{type:`string`,short:`b`},"dry-run":{type:`boolean`,short:`n`},force:{type:`boolean`,short:`f`},help:{type:`boolean`,short:`h`},interactive:{type:`boolean`,short:`i`},quiet:{type:`boolean`,short:`q`},tree:{type:`boolean`},verbose:{type:`boolean`},overwrite:{type:`boolean`,short:`o`},recursive:{type:`boolean`,short:`r`},version:{type:`boolean`,short:`v`},watch:{type:`string`,short:`w`}}});r.length||(i.version&&(console.log(`\n${Xn}@${Z}`),process.exit(0)),i.interactive?r.push(`.`):(await Yn()&&process.exit(0),console.log(Qn),process.exit(0))),r[0]===`clone`&&r.shift();let[a,o]=r,s={branch:i.branch,dryRun:i[`dry-run`],force:i.force,interactive:i.interactive,quiet:i.quiet,tree:i.tree,verbose:i.verbose,overwrite:i.overwrite,recursive:i.recursive,watch:i.watch};if((a===`.`||a.startsWith(`./`)||a.startsWith(`../`)||a.startsWith(`/`)||a.startsWith(`~/`)||s.interactive&&!a.includes(`/`)&&!a.startsWith(`http`)&&!a.startsWith(`git@`))&&s.interactive){if(!e.existsSync(n.resolve(a.startsWith(`~/`)?a.replace(`~`,t.homedir()):a))){if(o)throw Error(`Directory not found: ${a}`);o=a,a=`.`}if(!process.stdout.isTTY)throw Error(`Interactive mode requires a TTY`);let r=n.resolve(a.startsWith(`~/`)?a.replace(`~`,t.homedir()):a);if(!e.existsSync(r))throw Error(`Directory not found: ${a}`);if(!e.statSync(r).isDirectory())throw Error(`Not a directory: ${a}`);let i=o?n.resolve(o):null,c=[],l=!1;try{let t=(await S(`git`,[`ls-files`,`--cached`,`--others`,`--exclude-standard`],{cwd:r})).stdout.trim().split(`
56
56
  `).filter(Boolean);for(let i of t){let t=i.split(`/`);for(let e=1;e<t.length;e++){let n=t.slice(0,e).join(`/`);c.some(e=>e.path===n)||c.push({path:n,type:`tree`})}let a=n.join(r,i);try{let t=await e.promises.lstat(a);if(t.isSymbolicLink()){let t=await e.promises.readlink(a),n=!1;try{n=(await e.promises.stat(a)).isDirectory()}catch{}c.push({path:i,type:`symlink`,linkTarget:n?t+`/`:t})}else c.push({path:i,type:`blob`,size:t.size})}catch{}}l=!0}catch{}if(!l){async function t(r,i){let a;try{a=await e.promises.readdir(r,{withFileTypes:!0})}catch{return}for(let o of a){if(o.name===`.git`)continue;let a=i?`${i}/${o.name}`:o.name,s=n.join(r,o.name);if(o.isSymbolicLink()){let t=await e.promises.readlink(s),n=!1;try{n=(await e.promises.stat(s)).isDirectory()}catch{}c.push({path:a,type:`symlink`,linkTarget:n?t+`/`:t})}else if(o.isDirectory())c.push({path:a,type:`tree`}),await t(s,a);else try{let t=await e.promises.stat(s);c.push({path:a,type:`blob`,size:t.size})}catch{}}}await t(r,``)}c.length||(console.log(k(`
57
57
  Directory is empty.`)),process.exit(0));let u=await Nn(c,`${Q(r)}`,r);if(u.length||(console.log(`
58
- No files selected.`),process.exit(0)),s.dryRun){console.log(`\n${O(`✔`)} Would pick ${u.length} path${u.length===1?``:`s`}:`);for(let e of u)console.log(` ${e}`);console.log(),process.exit(0)}if(!i){console.log(`\n${O(`✔`)} Selected ${u.length} path${u.length===1?``:`s`}:`);for(let e of u)console.log(` ${e}`);console.log(),process.exit(0)}let d=n.resolve(i);if(r===d)throw Error(`Source and target directories are the same`);if(d.startsWith(r+n.sep))throw Error(`Target directory is inside the source directory`);console.log(`\n${O(`✔`)} Picking ${u.length} selected path${u.length===1?``:`s`}...`),s.overwrite=s.overwrite||s.force,e.existsSync(i)&&!s.overwrite&&(await e.promises.readdir(i)).length&&(console.log(`${k(`\nWarning: The target directory exists at ${O(o)} and is not empty. Use ${A(`-f`)} or ${A(`-o`)} to overwrite.`)}`),process.exit(1)),await e.promises.mkdir(i,{recursive:!0});let f=0;for(let t of u){let a=n.join(r,t),o=n.join(i,t),s=await e.promises.stat(a).catch(()=>null);if(s)if(s.isDirectory()){await e.promises.mkdir(o,{recursive:!0});let t=await j(a,o);f+=t.length}else await e.promises.mkdir(n.dirname(o),{recursive:!0}),await e.promises.copyFile(a,o),f++}console.log(O(`✔ Copied ${f} file${f===1?``:`s`} to ${Q(i)}`)),s.tree&&(process.stdout.write(`\n${T(A(Q(i)))}\n`),await $(i),process.stdout.write(`
58
+ No files selected.`),process.exit(0)),s.dryRun){console.log(`\n${O(`✔`)} Would pick ${u.length} path${u.length===1?``:`s`}:`);for(let e of u)console.log(` ${e}`);console.log(),process.exit(0)}if(!i){console.log(`\n${O(`✔`)} Selected ${u.length} path${u.length===1?``:`s`}:`);for(let e of u)console.log(` ${e}`);console.log(),process.exit(0)}let d=n.resolve(i);if(r===d)throw Error(`Source and target directories are the same`);if(d.startsWith(r+n.sep))throw Error(`Target directory is inside the source directory`);console.log(`\n${O(`✔`)} Picking ${u.length} selected path${u.length===1?``:`s`}...`),s.overwrite=s.overwrite||s.force,e.existsSync(i)&&!s.overwrite&&(await e.promises.readdir(i)).length&&(console.log(`${k(`\nWarning: The target directory exists at ${O(o)} and is not empty. Use ${A(`-f`)} or ${A(`-o`)} to overwrite.`)}`),process.exit(1)),await e.promises.mkdir(i,{recursive:!0});let f=0;for(let t of u){let a=n.join(r,t),o=n.join(i,t),s=await e.promises.lstat(a).catch(()=>null);if(s)if(await e.promises.mkdir(n.dirname(o),{recursive:!0}),s.isSymbolicLink()){let t=await e.promises.readlink(a);await e.promises.symlink(t,o).catch(()=>{}),f++}else if(s.isDirectory()){await e.promises.mkdir(o,{recursive:!0});let t=await j(a,o);f+=t.length}else await e.promises.copyFile(a,o),f++}console.log(O(`✔ Copied ${f} file${f===1?``:`s`} to ${Q(i)}`)),s.tree&&(process.stdout.write(`\n${T(A(Q(i)))}\n`),await $(i),process.stdout.write(`
59
59
  `)),process.exit(0)}let c=s.tree||s.quiet;c||console.log(`\nWith ${T(`${Zn(`GitPick`,`https://github.com/nrjdalal/gitpick`)}`)} clone specific files, folders, branches,\ncommits and much more from GitHub, GitLab and Bitbucket!`);let l=await Ln(a,{branch:s.branch,target:o});if(l.type===`blob`){let e=l.target.split(/[/\\]/).filter(e=>e!==``),t=e[e.length-1];t!==`.`&&t!==`..`&&t.includes(`.`)?e.pop():t=l.path.split(`/`).pop()||t,l.target=[...e,t].join(`/`)}c||console.info(`\n${O(`✔`)} ${l.owner}/${l.repository} ${A(l.type+`:`+l.branch)} ${l.type===`repository`?`> ${O(l.target)}`:`${l.path.length?k(l.path)+` >`:`>`} ${O(l.target)}`}`);let u=n.resolve(l.target);if(s.interactive){if(!process.stdout.isTTY)throw Error(`Interactive mode requires a TTY`);let r=n.resolve(t.tmpdir(),`gitpick-interactive-${Date.now()}${Math.random().toString(16).slice(2,6)}`),i=`https://${l.token?l.token+`@`:``}${l.host}/${l.owner}/${l.repository}.git`,a=ie();a.start(`Fetching ${l.owner}/${l.repository}...`);try{await S(`git`,[`clone`,i,r,`--branch`,l.branch,`--depth`,`1`,`--single-branch`,...s.recursive?[`--recursive`]:[]])}catch{await S(`git`,[`clone`,i,r,...s.recursive?[`--recursive`]:[]]),await S(`git`,[`checkout`,l.branch],{cwd:r})}let o=l.path?n.join(r,l.path):r,c=[];async function d(t,r){let i=await e.promises.readdir(t,{withFileTypes:!0});for(let a of i){if(a.name===`.git`)continue;let i=r?`${r}/${a.name}`:a.name,o=n.join(t,a.name);if(a.isSymbolicLink()){let t=await e.promises.readlink(o),n=!1;try{n=(await e.promises.stat(o)).isDirectory()}catch{}c.push({path:i,type:`symlink`,linkTarget:n?t+`/`:t})}else if(a.isDirectory())c.push({path:i,type:`tree`}),await d(o,i);else{let t=await e.promises.stat(o);c.push({path:i,type:`blob`,size:t.size})}}}await d(o,``),a.success(`Fetched ${l.owner}/${l.repository} (${c.length} entries)`),c.length||(await e.promises.rm(r,{recursive:!0,force:!0}),console.log(k(`
60
60
  Repository has no files.`)),process.exit(0));let f=await Nn(c,`${l.owner}/${l.repository} ${A(`repository:`+l.branch)} > ${O(l.target)}`,o);if(f.length||(await e.promises.rm(r,{recursive:!0,force:!0}),console.log(`
61
61
  No files selected.`),process.exit(0)),s.dryRun){console.log(`\n${O(`✔`)} Would pick ${f.length} path${f.length===1?``:`s`}:`);for(let e of f)console.log(` ${e}`);await e.promises.rm(r,{recursive:!0,force:!0}),console.log(),J(Z,!1),process.exit(0)}console.log(`\n${O(`✔`)} Picking ${f.length} selected path${f.length===1?``:`s`}...`),e.existsSync(u)&&!s.overwrite&&(await e.promises.readdir(u)).length&&(await e.promises.rm(r,{recursive:!0,force:!0}),console.log(`${k(`\nWarning: The target directory exists at ${O(l.target)} and is not empty. Use ${A(`-f`)} or ${A(`-o`)} to overwrite.`)}`),process.exit(1)),await e.promises.mkdir(u,{recursive:!0});let p=0;for(let t of f){let r=n.join(o,t),i=n.join(u,t),a=await e.promises.stat(r).catch(()=>null);if(a)if(a.isDirectory()){await e.promises.mkdir(i,{recursive:!0});let t=await j(r,i);p+=t.length}else await e.promises.mkdir(n.dirname(i),{recursive:!0}),await e.promises.copyFile(r,i),p++}await e.promises.rm(r,{recursive:!0,force:!0}),console.log(O(`✔ Copied ${p} file${p===1?``:`s`} to ${Q(u)}`)),s.tree&&(process.stdout.write(`\n${T(A(Q(u)))}\n`),await $(u),process.stdout.write(`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gitpick",
3
- "version": "5.4.0-canary.2",
3
+ "version": "5.4.0-canary.3",
4
4
  "description": "Clone exactly what you need aka straightforward project scaffolding!",
5
5
  "keywords": [
6
6
  "clone",