Skip to content

Commit a288fd9

Browse files
authored
Merge pull request #420 from xaviml/fix/clean-stage
fix(commit): correct the stage checker before commiting
2 parents 79b3156 + a2d6312 commit a288fd9

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

commitizen/git.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,9 @@ def find_git_project_root() -> Optional[Path]:
154154

155155

156156
def is_staging_clean() -> bool:
157-
"""Check if staing is clean."""
158-
c = cmd.run("git diff --no-ext-diff --name-only")
159-
c_cached = cmd.run("git diff --no-ext-diff --cached --name-only")
160-
return not (bool(c.out) or bool(c_cached.out))
157+
"""Check if staging is clean."""
158+
c = cmd.run("git diff --no-ext-diff --cached --name-only")
159+
return not bool(c.out)
161160

162161

163162
def is_git_project() -> bool:

tests/test_git.py

+20-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def test_get_commits_author_and_email():
7070
create_file_and_commit("fix: username exception")
7171
commit = git.get_commits()[0]
7272

73-
assert commit.author is not ""
73+
assert commit.author != ""
7474
assert "@" in commit.author_email
7575

7676

@@ -176,12 +176,30 @@ def test_get_latest_tag_name(tmp_commitizen_project):
176176
assert tag_name == "1.0"
177177

178178

179-
def test_is_staging_clean(tmp_commitizen_project):
179+
def test_is_staging_clean_when_adding_file(tmp_commitizen_project):
180+
with tmp_commitizen_project.as_cwd():
181+
assert git.is_staging_clean() is True
182+
183+
cmd.run("touch test_file")
184+
185+
assert git.is_staging_clean() is True
186+
187+
cmd.run("git add test_file")
188+
189+
assert git.is_staging_clean() is False
190+
191+
192+
def test_is_staging_clean_when_updating_file(tmp_commitizen_project):
180193
with tmp_commitizen_project.as_cwd():
181194
assert git.is_staging_clean() is True
182195

183196
cmd.run("touch test_file")
184197
cmd.run("git add test_file")
198+
cmd.run("git commit -m 'add test_file'")
185199
cmd.run("echo 'test' > test_file")
186200

201+
assert git.is_staging_clean() is True
202+
203+
cmd.run("git add test_file")
204+
187205
assert git.is_staging_clean() is False

0 commit comments

Comments
 (0)