Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions commitizen/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@
"default": False,
"help": "generate the changelog for the newest version",
},
{
"name": ["--no-verify"],
"action": "store_true",
"default": False,
"help": "this option bypasses the pre-commit and commit-msg hooks",
},
{
"name": "--yes",
"action": "store_true",
Expand Down
9 changes: 8 additions & 1 deletion commitizen/commands/bump.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def __init__(self, config: BaseConfig, arguments: dict):
}
self.cz = factory.commiter_factory(self.config)
self.changelog = arguments["changelog"]
self.no_verify = arguments["no_verify"]

def is_initial_tag(self, current_tag_version: str, is_yes: bool = False) -> bool:
"""Check if reading the whole git tree up to HEAD is needed."""
Expand Down Expand Up @@ -145,7 +146,7 @@ def __call__(self): # noqa: C901
changelog()

self.config.set_key("version", new_version.public)
c = git.commit(message, args="-a")
c = git.commit(message, args=self._get_commit_args())
if c.err:
out.error('git.commit errror: "{}"'.format(c.err.strip()))
raise SystemExit(COMMIT_FAILED)
Expand All @@ -154,3 +155,9 @@ def __call__(self): # noqa: C901
out.error(c.err)
raise SystemExit(TAG_FAILED)
out.success("Done!")

def _get_commit_args(self):
commit_args = ["-a"]
if self.no_verify:
commit_args.append("--no-verify")
return " ".join(commit_args)
3 changes: 2 additions & 1 deletion docs/bump.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Some examples:

```bash
$ cz bump --help
usage: cz bump [-h] [--dry-run] [--files-only] [--changelog] [--yes]
usage: cz bump [-h] [--dry-run] [--files-only] [--changelog] [--no-verify] [--yes]
[--tag-format TAG_FORMAT] [--bump-message BUMP_MESSAGE]
[--prerelease {alpha,beta,rc}]
[--increment {MAJOR,MINOR,PATCH}]
Expand All @@ -64,6 +64,7 @@ optional arguments:
--dry-run show output to stdout, no commit, no modified files
--files-only bump version in the files from the config
--changelog, -ch generate the changelog for the newest version
--no-verify this option bypasses the pre-commit and commit-msg hooks
--yes accept automatically questions done
--tag-format TAG_FORMAT
the format used to tag the commit and read it, use it
Expand Down
38 changes: 38 additions & 0 deletions tests/commands/test_bump_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,44 @@ def test_bump_command(mocker):
assert tag_exists is True


@pytest.mark.usefixtures("tmp_commitizen_project")
def test_bump_on_git_with_hooks_no_verify_disabled(mocker, capsys):
cmd.run("mkdir .git/hooks")
with open(".git/hooks/pre-commit", "w") as f:
f.write("#!/usr/bin/env bash\n" 'echo "0.1.0"')
cmd.run("chmod +x .git/hooks/pre-commit")

# MINOR
create_file_and_commit("feat: new file")

testargs = ["cz", "bump", "--yes"]
mocker.patch.object(sys, "argv", testargs)

with pytest.raises(SystemExit):
cli.main()

_, err = capsys.readouterr()
assert 'git.commit errror: "0.1.0"' in err


@pytest.mark.usefixtures("tmp_commitizen_project")
def test_bump_on_git_with_hooks_no_verify_enabled(mocker):
cmd.run("mkdir .git/hooks")
with open(".git/hooks/pre-commit", "w") as f:
f.write("#!/usr/bin/env bash\n" 'echo "0.1.0"')
cmd.run("chmod +x .git/hooks/pre-commit")

# MINOR
create_file_and_commit("feat: new file")

testargs = ["cz", "bump", "--yes", "--no-verify"]
mocker.patch.object(sys, "argv", testargs)
cli.main()

tag_exists = git.tag_exist("0.2.0")
assert tag_exists is True


def test_bump_when_bumpping_is_not_support(mocker, capsys, tmpdir):
with tmpdir.as_cwd():
with open("./pyproject.toml", "w") as f:
Expand Down