From 0c143d87d639edc604f7d7b7095ce665aa011772 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Wed, 13 Apr 2022 07:21:08 +0100 Subject: [PATCH 1/6] ci: add `--unshallow` --- bin/cml/ci.js | 5 +++++ src/cml.js | 13 ++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/bin/cml/ci.js b/bin/cml/ci.js index d50e0bc25..baae74343 100644 --- a/bin/cml/ci.js +++ b/bin/cml/ci.js @@ -14,6 +14,11 @@ exports.handler = async (opts) => { exports.builder = (yargs) => yargs.env('CML_CI').options( kebabcaseKeys({ + unshallow: { + type: 'boolean', + description: + 'Fetch as much as possible, converting a shallow repository to a complete one.' + }, userEmail: { type: 'string', default: GIT_USER_EMAIL, diff --git a/src/cml.js b/src/cml.js index a38d73717..f4497c806 100755 --- a/src/cml.js +++ b/src/cml.js @@ -1,4 +1,5 @@ const { execSync } = require('child_process'); +const fse = require('fs-extra'); const gitUrlParse = require('git-url-parse'); const stripAuth = require('strip-url-auth'); const globby = require('globby'); @@ -330,11 +331,21 @@ class CML { } async ci(opts = {}) { - const { userEmail = GIT_USER_EMAIL, userName = GIT_USER_NAME } = opts; + const { + unshallow = false, + userEmail = GIT_USER_EMAIL, + userName = GIT_USER_NAME + } = opts; const driver = getDriver(this); const command = await driver.updateGitConfig({ userName, userEmail }); await exec(command); + if (unshallow) { + const gitdir = await exec('git rev-parse --git-dir'); + if (await fse.pathExists(gitdir + '/shallow')) { + await exec('git fetch --unshallow'); + } + } await exec('git fetch --all'); } From 360c5b13191409212a4e6847e0e88a270c5c2396 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Wed, 13 Apr 2022 07:27:55 +0100 Subject: [PATCH 2/6] update tests --- bin/cml/ci.test.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/cml/ci.test.js b/bin/cml/ci.test.js index e4ddca28c..cf29bcc26 100644 --- a/bin/cml/ci.test.js +++ b/bin/cml/ci.test.js @@ -14,6 +14,8 @@ describe('CML e2e', () => { --version Show version number [boolean] --log Maximum log level [string] [choices: \\"error\\", \\"warn\\", \\"info\\", \\"debug\\"] [default: \\"info\\"] + --unshallow Fetch as much as possible, converting a shallow repository to a + complete one. [boolean] --user-email Set Git user email. [string] [default: \\"olivaw@iterative.ai\\"] --user-name Set Git user name. [string] [default: \\"Olivaw[bot]\\"] --repo Set repository to be used. If unspecified, inferred from the From a02d32a26f00608593a24dc8ebc54e1e929be880 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Wed, 13 Apr 2022 07:31:10 +0100 Subject: [PATCH 3/6] path.join --- src/cml.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cml.js b/src/cml.js index f4497c806..f18ed6070 100755 --- a/src/cml.js +++ b/src/cml.js @@ -1,4 +1,5 @@ const { execSync } = require('child_process'); +const PATH = require('path'); const fse = require('fs-extra'); const gitUrlParse = require('git-url-parse'); const stripAuth = require('strip-url-auth'); @@ -342,7 +343,7 @@ class CML { await exec(command); if (unshallow) { const gitdir = await exec('git rev-parse --git-dir'); - if (await fse.pathExists(gitdir + '/shallow')) { + if (await fse.pathExists(PATH.join(gitdir, 'shallow'))) { await exec('git fetch --unshallow'); } } From 4271c63ab41302e1e57ede245cd6cd0a3fa584b5 Mon Sep 17 00:00:00 2001 From: Helio Machado <0x2b3bfa0+git@googlemail.com> Date: Wed, 13 Apr 2022 06:38:21 +0000 Subject: [PATCH 4/6] Use --is-shallow-repository Simplify conditionals --- src/cml.js | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/cml.js b/src/cml.js index f18ed6070..0f9b74804 100755 --- a/src/cml.js +++ b/src/cml.js @@ -1,6 +1,4 @@ const { execSync } = require('child_process'); -const PATH = require('path'); -const fse = require('fs-extra'); const gitUrlParse = require('git-url-parse'); const stripAuth = require('strip-url-auth'); const globby = require('globby'); @@ -339,14 +337,9 @@ class CML { } = opts; const driver = getDriver(this); - const command = await driver.updateGitConfig({ userName, userEmail }); - await exec(command); - if (unshallow) { - const gitdir = await exec('git rev-parse --git-dir'); - if (await fse.pathExists(PATH.join(gitdir, 'shallow'))) { - await exec('git fetch --unshallow'); - } - } + const shallow = await exec('git rev-parse --is-shallow-repository'); + if (unshallow && shallow === 'true') await exec('git fetch --unshallow'); + await exec(await driver.updateGitConfig({ userName, userEmail })); await exec('git fetch --all'); } From 53fced252f8d51c4326804819e7cf3a48d65020c Mon Sep 17 00:00:00 2001 From: Helio Machado <0x2b3bfa0+git@googlemail.com> Date: Wed, 13 Apr 2022 08:51:16 +0200 Subject: [PATCH 5/6] Apply suggestions from code review Co-authored-by: Casper da Costa-Luis --- src/cml.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/cml.js b/src/cml.js index 0f9b74804..5b053af86 100755 --- a/src/cml.js +++ b/src/cml.js @@ -337,9 +337,12 @@ class CML { } = opts; const driver = getDriver(this); - const shallow = await exec('git rev-parse --is-shallow-repository'); - if (unshallow && shallow === 'true') await exec('git fetch --unshallow'); await exec(await driver.updateGitConfig({ userName, userEmail })); + if (unshallow) { + if ((await exec('git rev-parse --is-shallow-repository')) === 'true') { + await exec('git fetch --unshallow'); + } + } await exec('git fetch --all'); } From be5d0ba783e480c9a361282b2def5d1b87f2bf47 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Wed, 13 Apr 2022 07:53:11 +0100 Subject: [PATCH 6/6] lint --- src/cml.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cml.js b/src/cml.js index 5b053af86..07f0e5b0c 100755 --- a/src/cml.js +++ b/src/cml.js @@ -339,9 +339,9 @@ class CML { const driver = getDriver(this); await exec(await driver.updateGitConfig({ userName, userEmail })); if (unshallow) { - if ((await exec('git rev-parse --is-shallow-repository')) === 'true') { - await exec('git fetch --unshallow'); - } + if ((await exec('git rev-parse --is-shallow-repository')) === 'true') { + await exec('git fetch --unshallow'); + } } await exec('git fetch --all'); }