@@ -299,6 +299,60 @@ def test_commit_when_nothing_to_commit(config, mocker: MockFixture):
299
299
assert "No files added to staging!" in str (excinfo .value )
300
300
301
301
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
+ "" , b"" , b"" , 0 )
318
+
319
+ error_mock = mocker .patch ("commitizen.out.error" )
320
+
321
+ commands .Commit (config , {"all" : False })()
322
+
323
+ prompt_mock .assert_called_once ()
324
+ error_mock .assert_called_once ()
325
+
326
+ assert "nothing added" in error_mock .call_args [0 ][0 ]
327
+
328
+
329
+ @pytest .mark .usefixtures ("staging_is_clean" )
330
+ def test_commit_when_no_changes_added_to_commit (config , mocker : MockFixture ):
331
+ prompt_mock = mocker .patch ("questionary.prompt" )
332
+ prompt_mock .return_value = {
333
+ "prefix" : "feat" ,
334
+ "subject" : "user created" ,
335
+ "scope" : "" ,
336
+ "is_breaking_change" : False ,
337
+ "body" : "" ,
338
+ "footer" : "" ,
339
+ }
340
+
341
+ commit_mock = mocker .patch ("commitizen.git.commit" )
342
+ commit_mock .return_value = cmd .Command (
343
+ "no changes added to commit (use \" git add\" and/or \" git commit -a\" )" ,
344
+ "" , b"" , b"" , 0 )
345
+
346
+ error_mock = mocker .patch ("commitizen.out.error" )
347
+
348
+ commands .Commit (config , {"all" : False })()
349
+
350
+ prompt_mock .assert_called_once ()
351
+ error_mock .assert_called_once ()
352
+
353
+ assert "no changes added to commit" in error_mock .call_args [0 ][0 ]
354
+
355
+
302
356
@pytest .mark .usefixtures ("staging_is_clean" )
303
357
def test_commit_when_customized_expected_raised (config , mocker : MockFixture , capsys ):
304
358
_err = ValueError ()
0 commit comments