From fc9e235679ff850a646d977da016a4ad2d682634 Mon Sep 17 00:00:00 2001 From: Daniel Barnes Date: Mon, 31 Oct 2022 14:54:15 -0700 Subject: [PATCH] Remove default value for `--fetch-depth` (#1246) * temp * no default for fetch-depth * test update * tidy unshallow logic checks * slight docs update Co-authored-by: Casper da Costa-Luis --- bin/cml/repo/prepare.js | 4 +--- bin/cml/repo/prepare.test.js | 4 ++-- src/cml.js | 16 ++++++++-------- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/bin/cml/repo/prepare.js b/bin/cml/repo/prepare.js index 21d97bb10..82ae22a4f 100644 --- a/bin/cml/repo/prepare.js +++ b/bin/cml/repo/prepare.js @@ -22,9 +22,7 @@ exports.builder = (yargs) => exports.options = kebabcaseKeys({ fetchDepth: { type: 'number', - default: 1, - description: - 'Number of commits to fetch. 0 indicates all history for all branches and tags' + description: 'Number of commits to fetch (use `0` for all branches & tags)' }, unshallow: { type: 'boolean', diff --git a/bin/cml/repo/prepare.test.js b/bin/cml/repo/prepare.test.js index 72254b0ba..6a765847b 100644 --- a/bin/cml/repo/prepare.test.js +++ b/bin/cml/repo/prepare.test.js @@ -20,8 +20,8 @@ describe('CML e2e', () => { --help Show help [boolean] Options: - --fetch-depth Number of commits to fetch. 0 indicates all history for all - branches and tags [number] [default: 1] + --fetch-depth Number of commits to fetch (use \`0\` for all branches & tags) + [number] --user-email Git user email [string] [default: \\"olivaw@iterative.ai\\"] --user-name Git user name [string] [default: \\"Olivaw[bot]\\"]" `); diff --git a/src/cml.js b/src/cml.js index 8087e9e51..f02dfd7d2 100755 --- a/src/cml.js +++ b/src/cml.js @@ -501,19 +501,19 @@ class CML { userName = GIT_USER_NAME, remote = GIT_REMOTE } = opts; - let { fetchDepth = 1 } = opts; + const { fetchDepth = unshallow ? 0 : undefined } = opts; const driver = this.getDriver(); await exec(await driver.updateGitConfig({ userName, userEmail, remote })); - if (unshallow) { - if ((await exec('git rev-parse --is-shallow-repository')) === 'true') { - fetchDepth = 0; + if (fetchDepth !== undefined) { + if (fetchDepth <= 0) { + if ((await exec('git rev-parse --is-shallow-repository')) === 'true') { + return await exec('git fetch --all --unshallow'); + } + } else { + return await exec(`git fetch --all --depth=${fetchDepth}`); } } - if (fetchDepth <= 0) { - return await exec('git fetch --all --unshallow'); - } - return await exec(`git fetch --all --depth=${fetchDepth}`); } async prCreate(opts = {}) {