Skip to content

Commit fc9e235

Browse files
dacbdcasperdcl
andauthored
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 <casper.dcl@physics.org>
1 parent 17a045e commit fc9e235

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

bin/cml/repo/prepare.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ exports.builder = (yargs) =>
2222
exports.options = kebabcaseKeys({
2323
fetchDepth: {
2424
type: 'number',
25-
default: 1,
26-
description:
27-
'Number of commits to fetch. 0 indicates all history for all branches and tags'
25+
description: 'Number of commits to fetch (use `0` for all branches & tags)'
2826
},
2927
unshallow: {
3028
type: 'boolean',

bin/cml/repo/prepare.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ describe('CML e2e', () => {
2020
--help Show help [boolean]
2121
2222
Options:
23-
--fetch-depth Number of commits to fetch. 0 indicates all history for all
24-
branches and tags [number] [default: 1]
23+
--fetch-depth Number of commits to fetch (use \`0\` for all branches & tags)
24+
[number]
2525
--user-email Git user email [string] [default: \\"olivaw@iterative.ai\\"]
2626
--user-name Git user name [string] [default: \\"Olivaw[bot]\\"]"
2727
`);

src/cml.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -501,19 +501,19 @@ class CML {
501501
userName = GIT_USER_NAME,
502502
remote = GIT_REMOTE
503503
} = opts;
504-
let { fetchDepth = 1 } = opts;
504+
const { fetchDepth = unshallow ? 0 : undefined } = opts;
505505

506506
const driver = this.getDriver();
507507
await exec(await driver.updateGitConfig({ userName, userEmail, remote }));
508-
if (unshallow) {
509-
if ((await exec('git rev-parse --is-shallow-repository')) === 'true') {
510-
fetchDepth = 0;
508+
if (fetchDepth !== undefined) {
509+
if (fetchDepth <= 0) {
510+
if ((await exec('git rev-parse --is-shallow-repository')) === 'true') {
511+
return await exec('git fetch --all --unshallow');
512+
}
513+
} else {
514+
return await exec(`git fetch --all --depth=${fetchDepth}`);
511515
}
512516
}
513-
if (fetchDepth <= 0) {
514-
return await exec('git fetch --all --unshallow');
515-
}
516-
return await exec(`git fetch --all --depth=${fetchDepth}`);
517517
}
518518

519519
async prCreate(opts = {}) {

0 commit comments

Comments
 (0)