From e9b1254242f83abbee9876194b78cafb7f68663c Mon Sep 17 00:00:00 2001 From: Ian Thomas Date: Thu, 19 Feb 2026 10:15:52 +0000 Subject: [PATCH] Add test for commit message via stdin --- test/test_commit.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/test_commit.py b/test/test_commit.py index f7b17a6..c628d78 100644 --- a/test/test_commit.py +++ b/test/test_commit.py @@ -32,3 +32,37 @@ def test_commit(xtl_clone, commit_env_config, git2cpp_path, tmp_path, all_flag): ) assert p_status_2.returncode == 0 assert "mook_file" not in p_status_2.stdout + + +@pytest.mark.parametrize("commit_msg", ["Added file", ""]) +def test_commit_message_via_stdin(commit_env_config, git2cpp_path, tmp_path, run_in_tmp_path, commit_msg): + cmd = [git2cpp_path, "init", "."] + p_init = subprocess.run(cmd) + assert p_init.returncode == 0 + + (tmp_path / "file.txt").write_text("Some text") + + cmd_add = [git2cpp_path, "add", "file.txt"] + p_add = subprocess.run(cmd_add) + assert p_add.returncode == 0 + + cmd_commit = [git2cpp_path, "commit"] + p_commit = subprocess.run(cmd_commit, text=True, capture_output=True, input=commit_msg) + + if commit_msg == "": + # No commit message + assert p_commit.returncode != 0 + assert "Aborting, no commit message specified" in p_commit.stderr + else: + # Valid commit message + assert p_commit.returncode == 0 + + cmd_log = [git2cpp_path, "log"] + p_log = subprocess.run(cmd_log, text=True, capture_output=True) + assert p_log.returncode == 0 + lines = p_log.stdout.splitlines() + + assert "commit" in lines[0] + assert "Author:" in lines[1] + assert "Date" in lines[2] + assert commit_msg in lines[4]