Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat(version): add --force-git-tag option (#2594)
Co-authored-by: Daniel Stockman <5605+evocateur@users.noreply.github.com>
  • Loading branch information
jzempel and evocateur committed May 24, 2020
1 parent e58e982 commit 00738e9
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
5 changes: 5 additions & 0 deletions commands/version/README.md
Expand Up @@ -65,6 +65,7 @@ Running `lerna version --conventional-commits` without the above flags will rele
- [`--preid`](#--preid)
- [`--sign-git-commit`](#--sign-git-commit)
- [`--sign-git-tag`](#--sign-git-tag)
- [`--force-git-tag`](#--force-git-tag)
- [`--tag-version-prefix`](#--tag-version-prefix)
- [`--yes`](#--yes)

Expand Down Expand Up @@ -372,6 +373,10 @@ This option is analogous to the `npm version` [option](https://docs.npmjs.com/mi

This option is analogous to the `npm version` [option](https://docs.npmjs.com/misc/config#sign-git-tag) of the same name.

### `--force-git-tag`

This option replaces any existing tag instead of failing.

### `--tag-version-prefix`

This option allows to provide custom prefix instead of the default one: `v`.
Expand Down
9 changes: 9 additions & 0 deletions commands/version/__tests__/git-tag.test.js
Expand Up @@ -25,4 +25,13 @@ describe("gitTag", () => {

expect(mockExec).toHaveBeenLastCalledWith("git", ["tag", tag, "-m", tag, "--sign"], opts);
});

it("forces the tag when configured", async () => {
const tag = "v1.1.1";
const opts = { cwd: "forced" };

await gitTag(tag, { forceGitTag: true }, opts);

expect(mockExec).toHaveBeenLastCalledWith("git", ["tag", tag, "-m", tag, "--force"], opts);
});
});
4 changes: 4 additions & 0 deletions commands/version/command.js
Expand Up @@ -139,6 +139,10 @@ exports.builder = (yargs, composed) => {
describe: "Pass the `--sign` flag to `git tag`.",
type: "boolean",
},
"force-git-tag": {
describe: "Pass the `--force` flag to `git tag`.",
type: "boolean",
},
"tag-version-prefix": {
describe: "Customize the tag prefix. To remove entirely, pass an empty string.",
type: "string",
Expand Down
2 changes: 2 additions & 0 deletions commands/version/index.js
Expand Up @@ -67,6 +67,7 @@ class VersionCommand extends Command {
push = true,
signGitCommit,
signGitTag,
forceGitTag,
tagVersionPrefix = "v",
} = this.options;

Expand All @@ -92,6 +93,7 @@ class VersionCommand extends Command {
commitHooks,
signGitCommit,
signGitTag,
forceGitTag,
};

// https://docs.npmjs.com/misc/config#save-prefix
Expand Down
6 changes: 5 additions & 1 deletion commands/version/lib/git-tag.js
Expand Up @@ -5,11 +5,15 @@ const childProcess = require("@lerna/child-process");

module.exports = gitTag;

function gitTag(tag, { signGitTag }, opts) {
function gitTag(tag, { forceGitTag, signGitTag }, opts) {
log.silly("gitTag", tag);

const args = ["tag", tag, "-m", tag];

if (forceGitTag) {
args.push("--force");
}

if (signGitTag) {
args.push("--sign");
}
Expand Down

0 comments on commit 00738e9

Please sign in to comment.