Skip to content

Commit 926911d

Browse files
committed
test(git): add tests for get_filenames_in_commit with git_reference
1 parent e508091 commit 926911d

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tests/test_git.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,32 @@ def test_commit_with_spaces_in_path(
387387
mock_unlink.assert_called_once_with(file_path)
388388

389389

390+
@pytest.mark.usefixtures("tmp_commitizen_project")
391+
def test_get_filenames_in_commit(util: UtilFixture):
392+
"""Test get_filenames_in_commit returns filenames from the last commit."""
393+
filename = "test_feature_file.txt"
394+
util.create_file_and_commit("feat: add new feature", filename=filename)
395+
396+
filenames = git.get_filenames_in_commit()
397+
assert filename in filenames
398+
399+
400+
@pytest.mark.usefixtures("tmp_commitizen_project")
401+
def test_get_filenames_in_commit_with_git_reference(util: UtilFixture):
402+
"""Test get_filenames_in_commit with a specific git reference (commit SHA)."""
403+
first_filename = "first_feature.txt"
404+
util.create_file_and_commit("feat: first feature", filename=first_filename)
405+
first_commit_rev = cmd.run("git rev-parse HEAD").out.strip()
406+
407+
second_filename = "second_feature.txt"
408+
util.create_file_and_commit("feat: second feature", filename=second_filename)
409+
410+
# Query the first commit by its SHA
411+
filenames = git.get_filenames_in_commit(git_reference=first_commit_rev)
412+
assert first_filename in filenames
413+
assert second_filename not in filenames
414+
415+
390416
def test_get_filenames_in_commit_error(util: UtilFixture):
391417
"""Test that GitCommandError is raised when git command fails."""
392418
util.mock_cmd(err="fatal: bad object HEAD", return_code=1)

0 commit comments

Comments
 (0)