Skip to content

fix(commit): correct the stage checker before commiting #420

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 12, 2021
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
7 changes: 3 additions & 4 deletions commitizen/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,9 @@ 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))
"""Check if staging is clean."""
c = cmd.run("git diff --no-ext-diff --cached --name-only")
return not bool(c.out)


def is_git_project() -> bool:
Expand Down
22 changes: 20 additions & 2 deletions tests/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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