@@ -81,3 +81,45 @@ def test_commit_message_via_stdin(
8181 assert "Author:" in lines [1 ]
8282 assert "Date" in lines [2 ]
8383 assert commit_msg_out in lines [4 ]
84+
85+
86+ def test_commit_no_changes_initial (commit_env_config , git2cpp_path , tmp_path ):
87+ """Commit on fresh repo with no staged files should fail"""
88+ cmd_init = [git2cpp_path , "init" , "." ]
89+ p_init = subprocess .run (cmd_init , capture_output = True , cwd = tmp_path )
90+ assert p_init .returncode == 0
91+
92+ # Do NOT add any files — attempt to commit immediately
93+ cmd_commit = [git2cpp_path , "commit" , "-m" , "empty commit" ]
94+ p_commit = subprocess .run (cmd_commit , capture_output = True , cwd = tmp_path , text = True )
95+
96+ # Should fail: nothing to commit
97+ assert p_commit .returncode != 0
98+ assert "nothing to commit" in p_commit .stderr or "nothing to commit" in p_commit .stdout
99+
100+
101+ def test_commit_no_changes_after_first_commit (commit_env_config , git2cpp_path , tmp_path ):
102+ """Commit twice without changes between commits should fail"""
103+ cmd_init = [git2cpp_path , "init" , "." ]
104+ p_init = subprocess .run (cmd_init , capture_output = True , cwd = tmp_path )
105+ assert p_init .returncode == 0
106+
107+ # Create and commit a file
108+ (tmp_path / "file.txt" ).write_text ("hello" )
109+ subprocess .run ([git2cpp_path , "add" , "file.txt" ], cwd = tmp_path , check = True )
110+ p_first = subprocess .run (
111+ [git2cpp_path , "commit" , "-m" , "first commit" ], cwd = tmp_path , capture_output = True , text = True
112+ )
113+ assert p_first .returncode == 0
114+
115+ # Try to commit again without any new changes
116+ p_second = subprocess .run (
117+ [git2cpp_path , "commit" , "-m" , "second commit (no changes)" ],
118+ cwd = tmp_path ,
119+ capture_output = True ,
120+ text = True ,
121+ )
122+
123+ # Should fail: nothing to commit
124+ assert p_second .returncode != 0
125+ assert "nothing to commit" in p_second .stderr or "nothing to commit" in p_second .stdout
0 commit comments