@@ -299,6 +299,68 @@ def test_commit_when_nothing_to_commit(config, mocker: MockFixture):
299299 assert "No files added to staging!" in str (excinfo .value )
300300
301301
302+ @pytest .mark .usefixtures ("staging_is_clean" )
303+ def test_commit_when_nothing_added_to_commit (config , mocker : MockFixture ):
304+ prompt_mock = mocker .patch ("questionary.prompt" )
305+ prompt_mock .return_value = {
306+ "prefix" : "feat" ,
307+ "subject" : "user created" ,
308+ "scope" : "" ,
309+ "is_breaking_change" : False ,
310+ "body" : "" ,
311+ "footer" : "" ,
312+ }
313+
314+ commit_mock = mocker .patch ("commitizen.git.commit" )
315+ commit_mock .return_value = cmd .Command (
316+ 'nothing added to commit but untracked files present (use "git add" to track)' ,
317+ "" ,
318+ b"" ,
319+ b"" ,
320+ 0 ,
321+ )
322+
323+ error_mock = mocker .patch ("commitizen.out.error" )
324+
325+ commands .Commit (config , {"all" : False })()
326+
327+ prompt_mock .assert_called_once ()
328+ error_mock .assert_called_once ()
329+
330+ assert "nothing added" in error_mock .call_args [0 ][0 ]
331+
332+
333+ @pytest .mark .usefixtures ("staging_is_clean" )
334+ def test_commit_when_no_changes_added_to_commit (config , mocker : MockFixture ):
335+ prompt_mock = mocker .patch ("questionary.prompt" )
336+ prompt_mock .return_value = {
337+ "prefix" : "feat" ,
338+ "subject" : "user created" ,
339+ "scope" : "" ,
340+ "is_breaking_change" : False ,
341+ "body" : "" ,
342+ "footer" : "" ,
343+ }
344+
345+ commit_mock = mocker .patch ("commitizen.git.commit" )
346+ commit_mock .return_value = cmd .Command (
347+ 'no changes added to commit (use "git add" and/or "git commit -a")' ,
348+ "" ,
349+ b"" ,
350+ b"" ,
351+ 0 ,
352+ )
353+
354+ error_mock = mocker .patch ("commitizen.out.error" )
355+
356+ commands .Commit (config , {"all" : False })()
357+
358+ prompt_mock .assert_called_once ()
359+ error_mock .assert_called_once ()
360+
361+ assert "no changes added to commit" in error_mock .call_args [0 ][0 ]
362+
363+
302364@pytest .mark .usefixtures ("staging_is_clean" )
303365def test_commit_when_customized_expected_raised (config , mocker : MockFixture , capsys ):
304366 _err = ValueError ()
0 commit comments