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
1 change: 0 additions & 1 deletion commitizen/commands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ def _install_pre_commit_hook(self):
# .pre-commit-config does not exist
config_data["repos"] = [cz_hook_config]
else:
# breakpoint()
with open(pre_commit_config_filename) as config_file:
yaml_data = yaml.safe_load(config_file)
if yaml_data:
Expand Down
3 changes: 1 addition & 2 deletions commitizen/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ def get_commits(
return []

git_commits = []
for rev_and_commit in c.out.split(delimiter):
rev_and_commit = rev_and_commit.strip()
for rev_and_commit in c.out.split(f"\n{delimiter}\n"):
if not rev_and_commit:
continue
rev, title, author, author_email, *body_list = rev_and_commit.split("\n")
Expand Down
40 changes: 39 additions & 1 deletion tests/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pytest

from commitizen import git
from commitizen import cmd, git
from tests.utils import FakeCommand, create_file_and_commit


Expand Down Expand Up @@ -73,7 +73,45 @@ def test_get_commits_author_and_email():
assert "@" in commit.author_email


def test_get_commits_without_email(mocker):
raw_commit = (
"a515bb8f71c403f6f7d1c17b9d8ebf2ce3959395\n"
"\n"
"user name\n"
"\n"
"----------commit-delimiter----------\n"
"12d3b4bdaa996ea7067a07660bb5df4772297bdd\n"
"feat(users): add username\n"
"user name\n"
"\n"
"----------commit-delimiter----------\n"
)
mocker.patch("commitizen.cmd.run", return_value=FakeCommand(out=raw_commit))

commits = git.get_commits()

assert commits[0].author == "user name"
assert commits[1].author == "user name"

assert commits[0].author_email == ""
assert commits[1].author_email == ""

assert commits[0].title == ""
assert commits[1].title == "feat(users): add username"


def test_get_tag_names_has_correct_arrow_annotation():
arrow_annotation = inspect.getfullargspec(git.get_tag_names).annotations["return"]

assert arrow_annotation == List[Optional[str]]


def test_get_latest_tag_name(tmp_commitizen_project):
with tmp_commitizen_project.as_cwd():
tag_name = git.get_latest_tag_name()
assert tag_name is None

create_file_and_commit("feat(test): test")
cmd.run("git tag 1.0")
tag_name = git.get_latest_tag_name()
assert tag_name == "1.0"