From e95d5f27514e6ff417a14ee0466dd6012d33a2e8 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 a81283f84879..b901128b3835 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 1a54b80e9af7..82e726e95ea1 100644 --- a/packages/cosmic-swingset/test/scenario2.js +++ b/packages/cosmic-swingset/test/scenario2.js @@ -6,9 +6,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) => { @@ -16,7 +15,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); @@ -35,6 +36,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 ../