From f4d347f1d809529eac85832dd7043b0cbf59d218 Mon Sep 17 00:00:00 2001 From: Peter Somogyvari Date: Thu, 6 May 2021 15:21:03 -0700 Subject: [PATCH] feat(version): add --signoff git flag Signed-off-by: Peter Somogyvari --- commands/version/README.md | 7 +++++++ commands/version/__tests__/git-commit.test.js | 6 ++++++ commands/version/command.js | 4 ++++ commands/version/index.js | 2 ++ commands/version/lib/git-commit.js | 6 +++++- 5 files changed, 24 insertions(+), 1 deletion(-) diff --git a/commands/version/README.md b/commands/version/README.md index 2869048052e..8c261091cde 100644 --- a/commands/version/README.md +++ b/commands/version/README.md @@ -70,6 +70,7 @@ Running `lerna version --conventional-commits` without the above flags will rele - [`--no-private`](#--no-private) - [`--no-push`](#--no-push) - [`--preid`](#--preid) + - [`--signoff-git-commit`](#--signoff-git-commit) - [`--sign-git-commit`](#--sign-git-commit) - [`--sign-git-tag`](#--sign-git-tag) - [`--force-git-tag`](#--force-git-tag) @@ -396,6 +397,12 @@ lerna version prepatch --preid next When run with this flag, `lerna version` will increment `premajor`, `preminor`, `prepatch`, or `prerelease` semver bumps using the specified [prerelease identifier](http://semver.org/#spec-item-9). +### `--signoff-git-commit` + +Adds the `--signoff` flag to the git commit done by lerna version when executed. + +> Note: This is different from `--sign-git-commit` which is about gpg signatures. + ### `--sign-git-commit` This option is analogous to the `npm version` [option](https://docs.npmjs.com/misc/config#sign-git-commit) of the same name. diff --git a/commands/version/__tests__/git-commit.test.js b/commands/version/__tests__/git-commit.test.js index 0d0c3b62dc3..0e21bb08010 100644 --- a/commands/version/__tests__/git-commit.test.js +++ b/commands/version/__tests__/git-commit.test.js @@ -43,4 +43,10 @@ describe("git commit", () => { await gitCommit("nice", { signGitCommit: true }, opts); expect(childProcess.exec).toHaveBeenLastCalledWith("git", ["commit", "--gpg-sign", "-m", "nice"], opts); }); + + test("--signoff-git-commit", async () => { + const opts = { cwd: "signed-off" }; + await gitCommit("nice", { signoffGitCommit: true }, opts); + expect(childProcess.exec).toHaveBeenLastCalledWith("git", ["commit", "--signoff", "-m", "nice"], opts); + }); }); diff --git a/commands/version/command.js b/commands/version/command.js index d82bd24c856..7b0f55b70b2 100644 --- a/commands/version/command.js +++ b/commands/version/command.js @@ -146,6 +146,10 @@ exports.builder = (yargs, composed) => { describe: "Pass the `--gpg-sign` flag to `git commit`.", type: "boolean", }, + "signoff-git-commit": { + describe: "Pass the `--signoff` flag to `git commit`.", + type: "boolean", + }, "sign-git-tag": { describe: "Pass the `--sign` flag to `git tag`.", type: "boolean", diff --git a/commands/version/index.js b/commands/version/index.js index 3fcea7cf5d2..8c3a12e45a7 100644 --- a/commands/version/index.js +++ b/commands/version/index.js @@ -65,6 +65,7 @@ class VersionCommand extends Command { granularPathspec = true, push = true, signGitCommit, + signoffGitCommit, signGitTag, forceGitTag, tagVersionPrefix = "v", @@ -93,6 +94,7 @@ class VersionCommand extends Command { commitHooks, granularPathspec, signGitCommit, + signoffGitCommit, signGitTag, forceGitTag, }; diff --git a/commands/version/lib/git-commit.js b/commands/version/lib/git-commit.js index 42ea41a1359..f92ac03b94b 100644 --- a/commands/version/lib/git-commit.js +++ b/commands/version/lib/git-commit.js @@ -12,7 +12,7 @@ module.exports.gitCommit = gitCommit; * @param {{ amend: boolean; commitHooks: boolean; signGitCommit: boolean; }} gitOpts * @param {import("@lerna/child-process").ExecOpts} opts */ -function gitCommit(message, { amend, commitHooks, signGitCommit }, opts) { +function gitCommit(message, { amend, commitHooks, signGitCommit, signoffGitCommit }, opts) { log.silly("gitCommit", message); const args = ["commit"]; @@ -24,6 +24,10 @@ function gitCommit(message, { amend, commitHooks, signGitCommit }, opts) { args.push("--gpg-sign"); } + if (signoffGitCommit) { + args.push("--signoff"); + } + if (amend) { args.push("--amend", "--no-edit"); } else if (message.indexOf(EOL) > -1) {