From fb2b60cb08e197f43bf1ed03bd6aaf8998749e00 Mon Sep 17 00:00:00 2001 From: edvatar <88481784+toroleapinc@users.noreply.github.com> Date: Fri, 27 Feb 2026 11:11:35 -0500 Subject: [PATCH] test: add missing tests for get_filenames_in_commit with git_reference Add test coverage for get_filenames_in_commit() when called with an explicit git_reference parameter. Previously only the error case and the integration test (no git_reference) existed. New tests: - test_get_filenames_in_commit: success case without git_reference - test_get_filenames_in_commit_with_git_reference: success case with explicit reference, verifying the correct git command is called - test_get_filenames_in_commit_error_with_git_reference: error case with explicit reference Closes #1860 Signed-off-by: edvatar <88481784+toroleapinc@users.noreply.github.com> --- tests/test_git.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/test_git.py b/tests/test_git.py index 8efb7ca5c..0cc5e1606 100644 --- a/tests/test_git.py +++ b/tests/test_git.py @@ -387,6 +387,21 @@ def test_commit_with_spaces_in_path( mock_unlink.assert_called_once_with(file_path) +def test_get_filenames_in_commit(util: UtilFixture): + """Test getting filenames from the last commit (default, no git_reference).""" + util.mock_cmd(out="file1.py\nfile2.py\n") + result = git.get_filenames_in_commit() + assert result == ["file1.py", "file2.py"] + + +def test_get_filenames_in_commit_with_git_reference(util: UtilFixture): + """Test getting filenames with an explicit git reference.""" + mock = util.mock_cmd(out="src/main.py\nREADME.md\n") + result = git.get_filenames_in_commit("HEAD~1") + assert result == ["src/main.py", "README.md"] + mock.assert_called_once_with("git show --name-only --pretty=format: HEAD~1") + + def test_get_filenames_in_commit_error(util: UtilFixture): """Test that GitCommandError is raised when git command fails.""" util.mock_cmd(err="fatal: bad object HEAD", return_code=1) @@ -395,6 +410,17 @@ def test_get_filenames_in_commit_error(util: UtilFixture): assert str(excinfo.value) == "fatal: bad object HEAD" +def test_get_filenames_in_commit_error_with_git_reference(util: UtilFixture): + """Test that GitCommandError is raised with an explicit git reference.""" + mock = util.mock_cmd( + err="fatal: bad object abc123", return_code=128 + ) + with pytest.raises(GitCommandError) as excinfo: + git.get_filenames_in_commit("abc123") + assert str(excinfo.value) == "fatal: bad object abc123" + mock.assert_called_once_with("git show --name-only --pretty=format: abc123") + + @pytest.mark.parametrize( "linebreak", ["\n", "\r\n"], ids=["line_feed", "carriage_return"] )