@@ -324,6 +324,68 @@ def test_commit_when_nothing_to_commit(config, mocker: MockFixture):
324324 assert "No files added to staging!" in str (excinfo .value )
325325
326326
327+ @pytest .mark .usefixtures ("staging_is_clean" )
328+ def test_commit_when_nothing_added_to_commit (config , mocker : MockFixture ):
329+ prompt_mock = mocker .patch ("questionary.prompt" )
330+ prompt_mock .return_value = {
331+ "prefix" : "feat" ,
332+ "subject" : "user created" ,
333+ "scope" : "" ,
334+ "is_breaking_change" : False ,
335+ "body" : "" ,
336+ "footer" : "" ,
337+ }
338+
339+ commit_mock = mocker .patch ("commitizen.git.commit" )
340+ commit_mock .return_value = cmd .Command (
341+ 'nothing added to commit but untracked files present (use "git add" to track)' ,
342+ "" ,
343+ b"" ,
344+ b"" ,
345+ 0 ,
346+ )
347+
348+ error_mock = mocker .patch ("commitizen.out.error" )
349+
350+ commands .Commit (config , {"all" : False })()
351+
352+ prompt_mock .assert_called_once ()
353+ error_mock .assert_called_once ()
354+
355+ assert "nothing added" in error_mock .call_args [0 ][0 ]
356+
357+
358+ @pytest .mark .usefixtures ("staging_is_clean" )
359+ def test_commit_when_no_changes_added_to_commit (config , mocker : MockFixture ):
360+ prompt_mock = mocker .patch ("questionary.prompt" )
361+ prompt_mock .return_value = {
362+ "prefix" : "feat" ,
363+ "subject" : "user created" ,
364+ "scope" : "" ,
365+ "is_breaking_change" : False ,
366+ "body" : "" ,
367+ "footer" : "" ,
368+ }
369+
370+ commit_mock = mocker .patch ("commitizen.git.commit" )
371+ commit_mock .return_value = cmd .Command (
372+ 'no changes added to commit (use "git add" and/or "git commit -a")' ,
373+ "" ,
374+ b"" ,
375+ b"" ,
376+ 0 ,
377+ )
378+
379+ error_mock = mocker .patch ("commitizen.out.error" )
380+
381+ commands .Commit (config , {"all" : False })()
382+
383+ prompt_mock .assert_called_once ()
384+ error_mock .assert_called_once ()
385+
386+ assert "no changes added to commit" in error_mock .call_args [0 ][0 ]
387+
388+
327389@pytest .mark .usefixtures ("staging_is_clean" )
328390def test_commit_with_allow_empty (config , mocker : MockFixture ):
329391 prompt_mock = mocker .patch ("questionary.prompt" )
0 commit comments