Repository: iterative/cml
Pull request #1277 (2022-12-06 17:50:53)

Allow argument-less cml pr (Revert of the Revert) 
Previously seen in: #1263 #1270
Closes: #1203
Context: #1181

@0x2b3bfa0 can you confirm the intended use cases?

- should a plain `cml pr create`  infer a `cml pr create .`
  + no, `cml pr create` shouldn't try to `git add .`
- a `git commit -am "msg"` followed by a plain `cml pr create` should work? #1203

https://github.com/iterative/cml-playground/actions/workflows/cml-1263.yml

0x2b3bfa0: No, `cml pr create` isn't equivalent to `cml pr create .` because the latter implies `git add . && git commit ...` but the former doesn't.
0x2b3bfa0: > _a `git commit -am "msg"` followed by a plain `cml pr create` should work?_

Yes, it _should_ work.
dacbd: https://github.com/iterative/cml-playground/actions/runs/3632111594/jobs/6127577826#step:7:8 it seems it doesn't
dacbd: sanity test passes.
dacbd: fixed one thing and found the next broken thing: https://github.com/iterative/cml-playground/actions/runs/3652734734/jobs/6171451912
github-actions[bot]: ## Test Comment

![](https://cml.dev/watermark.png "CML watermark")

github-actions[bot]: ## Test Comment

![](https://asset.cml.dev/65c49ca187aaddca0d979dab472f1d0a077b2bd0?cml=png&cache-bypass=0b7733f3-d536-4586-b869-c41843bfba55)

![](https://cml.dev/watermark.png "CML watermark")

casperdcl: [this](https://github.com/iterative/cml/pull/1277#issuecomment-1339920209) is a painful bug. Since #1275 isn't released yet it means there's no way whatsoever to use `cml pr`. Bumping to p0.
casperdcl: updated issue description a tiny bit. Would be great to land this ASAP
github-actions[bot]: ## Test Comment

![](https://asset.cml.dev/65c49ca187aaddca0d979dab472f1d0a077b2bd0?cml=png&cache-bypass=2ad965bd-a738-4d44-b394-32e22048a378)

![](https://cml.dev/watermark.png "CML watermark")

github-actions[bot]: ## Test Comment

![](https://cml.dev/watermark.png "CML watermark")

github-actions[bot]: ## Test Comment

![](https://asset.cml.dev/65c49ca187aaddca0d979dab472f1d0a077b2bd0?cml=png&cache-bypass=3e3ca950-7fb7-4cf6-8751-f1115e4af636)

![](https://cml.dev/watermark.png "CML watermark")

github-actions[bot]: ## Test Comment

![](https://cml.dev/watermark.png "CML watermark")

github-actions[bot]: ## Test Comment

![](https://asset.cml.dev/65c49ca187aaddca0d979dab472f1d0a077b2bd0?cml=png&cache-bypass=b69acab9-b547-43bd-a69c-04c6764f03de)

![](https://cml.dev/watermark.png "CML watermark")

github-actions[bot]: ## Test Comment

![](https://cml.dev/watermark.png "CML watermark")

github-actions[bot]: ## Test Comment

![](https://cml.dev/watermark.png "CML watermark")

github-actions[bot]: ## Test Comment

![](https://asset.cml.dev/65c49ca187aaddca0d979dab472f1d0a077b2bd0?cml=png&cache-bypass=ff4e119d-fd36-4adb-b84e-731fd972ddcf)

![](https://cml.dev/watermark.png "CML watermark")

dacbd: @0x2b3bfa0 something in setupTelemetry function is breaking now: https://github.com/iterative/cml-playground/actions/runs/3734281501/jobs/6336139357
github-actions[bot]: ## Test Comment

![](https://cml.dev/watermark.png "CML watermark")

github-actions[bot]: ## Test Comment

![](https://asset.cml.dev/65c49ca187aaddca0d979dab472f1d0a077b2bd0?cml=png&cache-bypass=5f5db720-c901-448a-9531-4fac8102124a)

![](https://cml.dev/watermark.png "CML watermark")

github-actions[bot]: ## Test Comment

![](https://cml.dev/watermark.png "CML watermark")

github-actions[bot]: ## Test Comment

![](https://asset.cml.dev/65c49ca187aaddca0d979dab472f1d0a077b2bd0?cml=png&cache-bypass=fb03c086-25a4-4b2a-be14-d6fa7c8bd95b)

![](https://cml.dev/watermark.png "CML watermark")

github-actions[bot]: ## Test Comment

![](https://cml.dev/watermark.png "CML watermark")

github-actions[bot]: ## Test Comment

![](https://asset.cml.dev/65c49ca187aaddca0d979dab472f1d0a077b2bd0?cml=png&cache-bypass=6bee8d8f-3f72-4f30-bd2d-911cdedb6a32)

![](https://cml.dev/watermark.png "CML watermark")

0x2b3bfa0: > _@0x2b3bfa0 something in setupTelemetry function is breaking now: https://github.com/iterative/cml-playground/actions/runs/3734281501/jobs/6336139357_

@dacbd, fixed with https://github.com/iterative/cml/pull/1277/commits/21a101d6bc6103025d2a3356dfe6be5a8f073da7; please take another look.


github-actions[bot]: ## Test Comment

![](https://cml.dev/watermark.png "CML watermark")

github-actions[bot]: ## Test Comment

![](https://asset.cml.dev/65c49ca187aaddca0d979dab472f1d0a077b2bd0?cml=png&cache-bypass=e4364869-f861-41e1-a63c-260059852705)

![](https://cml.dev/watermark.png "CML watermark")

github-actions[bot]: ## Test Comment

![](https://cml.dev/watermark.png "CML watermark")

github-actions[bot]: ## Test Comment

![](https://asset.cml.dev/65c49ca187aaddca0d979dab472f1d0a077b2bd0?cml=png&cache-bypass=2312e5f5-35b6-4003-a7ae-46405b6fea8a)

![](https://cml.dev/watermark.png "CML watermark")

github-actions[bot]: ## Test Comment

![](https://cml.dev/watermark.png "CML watermark")

github-actions[bot]: ## Test Comment

![](https://asset.cml.dev/65c49ca187aaddca0d979dab472f1d0a077b2bd0?cml=png&cache-bypass=76532b74-6249-443a-965e-afeab6f43ff3)

![](https://cml.dev/watermark.png "CML watermark")

github-actions[bot]: ## Test Comment

![](https://cml.dev/watermark.png "CML watermark")

github-actions[bot]: ## Test Comment

![](https://asset.cml.dev/65c49ca187aaddca0d979dab472f1d0a077b2bd0?cml=png&cache-bypass=df2f25e0-12af-4f06-9605-5fdc275259ef)

![](https://cml.dev/watermark.png "CML watermark")

github-actions[bot]: ## Test Comment

![](https://cml.dev/watermark.png "CML watermark")

github-actions[bot]: ## Test Comment

![](https://asset.cml.dev/65c49ca187aaddca0d979dab472f1d0a077b2bd0?cml=png&cache-bypass=7f22d8dc-22c5-4bf3-8f6e-899d421222f0)

![](https://cml.dev/watermark.png "CML watermark")

github-actions[bot]: ## Test Comment

![](https://cml.dev/watermark.png "CML watermark")

github-actions[bot]: ## Test Comment

![](https://asset.cml.dev/65c49ca187aaddca0d979dab472f1d0a077b2bd0?cml=png&cache-bypass=3b022465-cfc5-4bb7-affc-18e408bb7f48)

![](https://cml.dev/watermark.png "CML watermark")

github-actions[bot]: ## Test Comment

![](https://cml.dev/watermark.png "CML watermark")

github-actions[bot]: ## Test Comment

![](https://asset.cml.dev/65c49ca187aaddca0d979dab472f1d0a077b2bd0?cml=png&cache-bypass=22138234-c558-49d3-bfae-0cc5bfff77ba)

![](https://cml.dev/watermark.png "CML watermark")


Patch:
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 16e7c0c..4478431 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -31,11 +31,9 @@ jobs:
     steps:
       - uses: actions/checkout@v3
       - run: >
-          gh release create
-          --target ${{ github.event.pull_request.merge_commit_sha }}
-          {--title=CML\ ,}$(basename ${{ github.head_ref }})
-          --generate-notes
-          --draft
+          gh release create --target ${{
+          github.event.pull_request.merge_commit_sha }} {--title=CML\
+          ,}$(basename ${{ github.head_ref }}) --generate-notes --draft
         env:
           GITHUB_TOKEN: ${{ secrets.ADMIN_GITHUB_TOKEN }}
   package:
diff --git a/bin/cml/pr.js b/bin/cml/pr.js
index 4e9f6b3..a28ec4b 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.js b/bin/cml/pr/create.js
index 7a68a28..035937c 100755
--- a/bin/cml/pr/create.js
+++ b/bin/cml/pr/create.js
@@ -6,10 +6,11 @@ const {
   GIT_USER_EMAIL
 } = require('../../../src/cml');
 
-const DESCRIPTION = 'Create a pull request with the specified files';
+const DESCRIPTION = 'Create a pull request (committing any given paths first)';
+
 const DOCSURL = 'https://cml.dev/doc/ref/pr';
 
-exports.command = 'create <glob path...>';
+exports.command = 'create [glob path...]';
 exports.description = `${DESCRIPTION}\n${DOCSURL}`;
 
 exports.handler = async (opts) => {
diff --git a/bin/legacy/commands/ci.js b/bin/legacy/commands/ci.js
index 195c90d..3480436 100644
--- a/bin/legacy/commands/ci.js
+++ b/bin/legacy/commands/ci.js
@@ -1,5 +1,6 @@
-const { handler } = require('../../cml/repo/prepare');
+const { builder, handler } = require('../../cml/repo/prepare');
 
 exports.command = 'ci';
 exports.description = 'Prepare Git repository for CML operations';
 exports.handler = handler;
+exports.builder = builder;
diff --git a/src/cml.js b/src/cml.js
old mode 100755
new mode 100644
index 541cc6b..dcf2177
--- a/src/cml.js
+++ b/src/cml.js
@@ -476,7 +476,15 @@ class CML {
       remote
     });
     for (const command of commands) {
-      await exec(...command);
+      try {
+        await exec(...command);
+      } catch (err) {
+        if (
+          JSON.stringify(command.slice(0, 3)) !==
+          JSON.stringify(['git', 'config', '--unset'])
+        )
+          throw err;
+      }
     }
     if (fetchDepth !== undefined) {
       if (fetchDepth <= 0) {
@@ -502,7 +510,7 @@ class CML {
     const driver = this.getDriver();
     const {
       remote = GIT_REMOTE,
-      globs = ['dvc.lock', '.gitignore'],
+      globs = [],
       md,
       skipCi,
       branch,
@@ -525,15 +533,17 @@ class CML {
     };
 
     const { files } = await git.status();
-    if (!files.length) {
-      winston.warn('No files changed. Nothing to do.');
+
+    if (!files.length && globs.length) {
+      winston.warn('No changed files matched by glob path. Nothing to do.');
       return;
     }
 
     const paths = (await globby(globs)).filter((path) =>
       files.map((file) => file.path).includes(path)
     );
-    if (!paths.length) {
+
+    if (!paths.length && globs.length) {
       winston.warn('Input files are not affected. Nothing to do.');
       return;
     }
@@ -564,14 +574,18 @@ class CML {
       if (url) return renderPr(url);
     } else {
       await exec('git', 'fetch', remote, sha);
-      await exec('git', 'checkout', '-B', target, sha);
+      if (paths.length) 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);
+        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);
     }
 
diff --git a/src/drivers/github.js b/src/drivers/github.js
index ac21ad3..f24e05d 100644
--- a/src/drivers/github.js
+++ b/src/drivers/github.js
@@ -751,7 +751,7 @@ class Github {
     repo.password = this.token;
     repo.username = 'token';
 
-    const commands = [
+    return [
       ['git', 'config', '--unset', 'http.https://github.com/.extraheader'],
       ['git', 'config', 'user.name', userName || this.userName],
       ['git', 'config', 'user.email', userEmail || this.userEmail],
@@ -763,8 +763,6 @@ class Github {
         repo.toString() + (repo.toString().endsWith('.git') ? '' : '.git')
       ]
     ];
-
-    return commands;
   }
 
   get workflowId() {


Test patch:
diff --git a/bin/cml/pr/create.e2e.test.js b/bin/cml/pr/create.e2e.test.js
index 5d59d8c..0510c2d 100644
--- a/bin/cml/pr/create.e2e.test.js
+++ b/bin/cml/pr/create.e2e.test.js
@@ -10,8 +10,8 @@ describe('CML e2e', () => {
       Manage pull requests
 
       Commands:
-        cml.js pr create <glob path...>  Create a pull request with the specified
-                                         files
+        cml.js pr create [glob path...]  Create a pull request (committing any given
+                                         paths first)
                                          https://cml.dev/doc/ref/pr
 
       Global Options:
diff --git a/bin/cml/repo/prepare.test.js b/bin/cml/repo/prepare.test.js
index ab2554c..994296d 100644
--- a/bin/cml/repo/prepare.test.js
+++ b/bin/cml/repo/prepare.test.js
@@ -17,7 +17,13 @@ describe('CML e2e', () => {
                                                                           environment]
         --repo    Repository URL or slug[string] [default: infer from the environment]
         --token   Personal access token [string] [default: infer from the environment]
-        --help    Show help                                                  [boolean]"
+        --help    Show help                                                  [boolean]
+
+      Options:
+        --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]\\"]"
     `);
   });
 });