From e92e07f348a37056215a55c6ce686999d69f931b Mon Sep 17 00:00:00 2001 From: Xavier Moreno Date: Sat, 11 Sep 2021 17:36:33 +0200 Subject: [PATCH 1/2] fix(commit): correct the stage checker before commiting related to #418 --- commitizen/git.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/commitizen/git.py b/commitizen/git.py index 2904d6cb05..080c5a6cb9 100644 --- a/commitizen/git.py +++ b/commitizen/git.py @@ -155,9 +155,8 @@ def find_git_project_root() -> Optional[Path]: def is_staging_clean() -> bool: """Check if staing is clean.""" - c = cmd.run("git diff --no-ext-diff --name-only") - c_cached = cmd.run("git diff --no-ext-diff --cached --name-only") - return not (bool(c.out) or bool(c_cached.out)) + c = cmd.run("git diff --no-ext-diff --cached --name-only") + return not bool(c.out) def is_git_project() -> bool: From a2d6312ee174635c980b2bec6af3d82b5709ae7c Mon Sep 17 00:00:00 2001 From: Xavier Moreno Date: Sun, 12 Sep 2021 12:56:38 +0200 Subject: [PATCH 2/2] test(git): extend test for is_staging_clean --- commitizen/git.py | 2 +- tests/test_git.py | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/commitizen/git.py b/commitizen/git.py index 080c5a6cb9..b196f15115 100644 --- a/commitizen/git.py +++ b/commitizen/git.py @@ -154,7 +154,7 @@ def find_git_project_root() -> Optional[Path]: def is_staging_clean() -> bool: - """Check if staing is clean.""" + """Check if staging is clean.""" c = cmd.run("git diff --no-ext-diff --cached --name-only") return not bool(c.out) diff --git a/tests/test_git.py b/tests/test_git.py index dc8023b956..c764a6d65a 100644 --- a/tests/test_git.py +++ b/tests/test_git.py @@ -70,7 +70,7 @@ def test_get_commits_author_and_email(): create_file_and_commit("fix: username exception") commit = git.get_commits()[0] - assert commit.author is not "" + assert commit.author != "" assert "@" in commit.author_email @@ -176,12 +176,30 @@ def test_get_latest_tag_name(tmp_commitizen_project): assert tag_name == "1.0" -def test_is_staging_clean(tmp_commitizen_project): +def test_is_staging_clean_when_adding_file(tmp_commitizen_project): + with tmp_commitizen_project.as_cwd(): + assert git.is_staging_clean() is True + + cmd.run("touch test_file") + + assert git.is_staging_clean() is True + + cmd.run("git add test_file") + + assert git.is_staging_clean() is False + + +def test_is_staging_clean_when_updating_file(tmp_commitizen_project): with tmp_commitizen_project.as_cwd(): assert git.is_staging_clean() is True cmd.run("touch test_file") cmd.run("git add test_file") + cmd.run("git commit -m 'add test_file'") cmd.run("echo 'test' > test_file") + assert git.is_staging_clean() is True + + cmd.run("git add test_file") + assert git.is_staging_clean() is False