From 7ce5410bcee156d1ba51dfe09c4248eac2beb023 Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Mon, 17 Jul 2023 15:01:50 -0400 Subject: [PATCH] refactor(agoric-cli): Improve git clone efficiency --- packages/agoric-cli/src/init.js | 3 ++- packages/cosmic-swingset/test/scenario2.js | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/agoric-cli/src/init.js b/packages/agoric-cli/src/init.js index fed07c44c84..5c3aa2c977d 100644 --- a/packages/agoric-cli/src/init.js +++ b/packages/agoric-cli/src/init.js @@ -40,9 +40,10 @@ export default async function initMain(_progname, rawArgs, priv, opts) { dappBranch = ['-b', opts.dappBranch]; } + const shallow = ['--depth', '1', '--shallow-submodules']; const exitStatus = await pspawn( 'git', - ['clone', '--origin=upstream', dappURL, DIR, ...dappBranch], + ['clone', '--origin=upstream', ...shallow, dappURL, DIR, ...dappBranch], { stdio: 'inherit', }, diff --git a/packages/cosmic-swingset/test/scenario2.js b/packages/cosmic-swingset/test/scenario2.js index c37955aa3eb..006a5670c2e 100644 --- a/packages/cosmic-swingset/test/scenario2.js +++ b/packages/cosmic-swingset/test/scenario2.js @@ -5,9 +5,8 @@ const onlyStderr = ['ignore', 'ignore', 'inherit']; const noOutput = ['ignore', 'ignore', 'ignore']; // const noisyDebug = ['ignore', 'inherit', 'inherit']; -export const pspawn = - (bin, { spawn, cwd }) => - (args = [], opts = {}) => { +export const pspawn = (bin, { spawn, cwd }) => { + return (args = [], opts = {}) => { /** @type {import('child_process').ChildProcess} */ let child; const exit = new Promise((resolve, reject) => { @@ -15,7 +14,9 @@ export const pspawn = child = spawn(bin, args, { cwd, ...opts }); child.addListener('exit', code => { if (code !== 0) { - reject(Error(`exit ${code} from: ${bin} ${args}`)); + // TODO: Include ~3 lines from child.stderr or child.stdout if present. + // see https://nodejs.org/api/child_process.html#child_processspawncommand-args-options + reject(Error(`exit ${code} from command: ${bin} ${args}`)); return; } resolve(0); @@ -34,6 +35,7 @@ export const pspawn = // @ts-expect-error child is set in the Promise constructor return { kill, child, exit }; }; +}; /** * Shared state for tests using scenario2 chain in ../