diff --git a/bin/cml/pr.js b/bin/cml/pr.js index 4e9f6b3a3..a28ec4b1f 100644 --- a/bin/cml/pr.js +++ b/bin/cml/pr.js @@ -17,5 +17,4 @@ exports.builder = (yargs) => ) ) .option('options', { default: options, hidden: true }) - .check(({ globpath }) => globpath) .strict(); diff --git a/bin/cml/pr/create.e2e.test.js b/bin/cml/pr/create.e2e.test.js index f2d669799..fc49cbc7e 100644 --- a/bin/cml/pr/create.e2e.test.js +++ b/bin/cml/pr/create.e2e.test.js @@ -10,7 +10,7 @@ describe('CML e2e', () => { Manage pull requests Commands: - cml.js pr create Create a pull request with the specified + cml.js pr create [glob path...] Create a pull request with the specified files https://cml.dev/doc/ref/pr diff --git a/bin/cml/pr/create.js b/bin/cml/pr/create.js index 7a68a2801..e8eaebb98 100755 --- a/bin/cml/pr/create.js +++ b/bin/cml/pr/create.js @@ -9,7 +9,7 @@ const { const DESCRIPTION = 'Create a pull request with the specified files'; const DOCSURL = 'https://cml.dev/doc/ref/pr'; -exports.command = 'create '; +exports.command = 'create [glob path...]'; exports.description = `${DESCRIPTION}\n${DOCSURL}`; exports.handler = async (opts) => { diff --git a/src/cml.js b/src/cml.js index 15bb176ea..be0627c1a 100755 --- a/src/cml.js +++ b/src/cml.js @@ -543,7 +543,7 @@ class CML { }; const { files } = await git.status(); - if (!files.length) { + if (!files.length && globs.length) { winston.warn('No files changed. Nothing to do.'); return; } @@ -551,10 +551,6 @@ class CML { const paths = (await globby(globs)).filter((path) => files.map((file) => file.path).includes(path) ); - if (!paths.length) { - winston.warn('Input files are not affected. Nothing to do.'); - return; - } const sha = await this.triggerSha(); const shaShort = sha.substr(0, 8); @@ -581,12 +577,16 @@ class CML { await exec(`git fetch ${remote} ${sha}`); await exec(`git checkout -B ${target} ${sha}`); await exec(`git checkout -b ${source}`); - await exec(`git add ${paths.join(' ')}`); - let commitMessage = message || `CML PR for ${shaShort}`; - if (skipCi || (!message && !(merge || rebase || squash))) { - commitMessage += ' [skip ci]'; + + if (paths.length) { + await exec(`git add ${paths.join(' ')}`); + let commitMessage = message || `CML PR for ${shaShort}`; + if (skipCi || (!message && !(merge || rebase || squash))) { + commitMessage += ' [skip ci]'; + } + await exec(`git commit -m "${commitMessage}"`); } - await exec(`git commit -m "${commitMessage}"`); + await exec(`git push --set-upstream ${remote} ${source}`); }