Skip to content

Commit bb04076

Browse files
deepyaman0x2b3bfa0dacbdcasperdcl
authored
Add ci --fetch-depth, deprecate ci --unshallow (#1233)
* Add `ci --fetch-depth`, deprecate `ci --unshallow` * Edit formatting of expected `cml ci --help` output * Remove `isNaN` check, already handled by Yargs lib * Fix negative `fetchDepth`s using `coerce` in Yargs * Apply suggestions from code review Co-authored-by: Daniel Barnes <dabarnes2b@gmail.com> * Reduce duplicate logic, and replace `coerce` with different condition Co-authored-by: Casper da Costa-Luis <casper.dcl@physics.org> * Assignment to constant variable Co-authored-by: Helio Machado <0x2b3bfa0+git@googlemail.com> Co-authored-by: Daniel Barnes <dabarnes2b@gmail.com> Co-authored-by: Casper da Costa-Luis <casper.dcl@physics.org>
1 parent b6c5bd6 commit bb04076

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

bin/cml/repo/prepare.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,17 @@ exports.builder = (yargs) =>
2020
.options(exports.options);
2121

2222
exports.options = kebabcaseKeys({
23+
fetchDepth: {
24+
type: 'number',
25+
default: 1,
26+
description:
27+
'Number of commits to fetch. 0 indicates all history for all branches and tags'
28+
},
2329
unshallow: {
2430
type: 'boolean',
2531
description:
26-
'Fetch as much as possible, converting a shallow repository to a complete one'
32+
'Fetch as much as possible, converting a shallow repository to a complete one',
33+
hidden: true
2734
},
2835
userEmail: {
2936
type: 'string',

bin/cml/repo/prepare.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ describe('CML e2e', () => {
2020
--help Show help [boolean]
2121
2222
Options:
23-
--unshallow Fetch as much as possible, converting a shallow repository to a
24-
complete one [boolean]
25-
--user-email Git user email [string] [default: \\"olivaw@iterative.ai\\"]
26-
--user-name Git user name [string] [default: \\"Olivaw[bot]\\"]"
23+
--fetch-depth Number of commits to fetch. 0 indicates all history for all
24+
branches and tags [number] [default: 1]
25+
--user-email Git user email [string] [default: \\"olivaw@iterative.ai\\"]
26+
--user-name Git user name [string] [default: \\"Olivaw[bot]\\"]"
2727
`);
2828
});
2929
});

src/cml.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,15 +469,19 @@ class CML {
469469
userName = GIT_USER_NAME,
470470
remote = GIT_REMOTE
471471
} = opts;
472+
let { fetchDepth = 1 } = opts;
472473

473474
const driver = this.getDriver();
474475
await exec(await driver.updateGitConfig({ userName, userEmail, remote }));
475476
if (unshallow) {
476477
if ((await exec('git rev-parse --is-shallow-repository')) === 'true') {
477-
await exec('git fetch --unshallow');
478+
fetchDepth = 0;
478479
}
479480
}
480-
await exec('git fetch --all');
481+
if (fetchDepth <= 0) {
482+
return await exec('git fetch --all --unshallow');
483+
}
484+
return await exec(`git fetch --all --depth=${fetchDepth}`);
481485
}
482486

483487
async prCreate(opts = {}) {

0 commit comments

Comments
 (0)