Skip to content

Commit 6c91b45

Browse files
authored
test(git): add tests for get_filenames_in_commit with git_reference (#1890)
1 parent 339d80e commit 6c91b45

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/test_git.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,34 @@ 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+
util.create_file_and_commit("feat: old feature", filename="old_file.txt")
394+
395+
filename = "test_feature_file.txt"
396+
util.create_file_and_commit("feat: add new feature", filename=filename)
397+
398+
filenames = git.get_filenames_in_commit()
399+
assert [filename] == filenames
400+
401+
402+
@pytest.mark.usefixtures("tmp_commitizen_project")
403+
def test_get_filenames_in_commit_with_git_reference(util: UtilFixture):
404+
"""Test get_filenames_in_commit with a specific git reference (commit SHA)."""
405+
first_filename = "first_feature.txt"
406+
util.create_file_and_commit("feat: first feature", filename=first_filename)
407+
first_commit_rev = cmd.run("git rev-parse HEAD").out.strip()
408+
409+
second_filename = "second_feature.txt"
410+
util.create_file_and_commit("feat: second feature", filename=second_filename)
411+
412+
# Query the first commit by its SHA
413+
filenames = git.get_filenames_in_commit(git_reference=first_commit_rev)
414+
assert first_filename in filenames
415+
assert second_filename not in filenames
416+
417+
390418
def test_get_filenames_in_commit_error(util: UtilFixture):
391419
"""Test that GitCommandError is raised when git command fails."""
392420
util.mock_cmd(err="fatal: bad object HEAD", return_code=1)

0 commit comments

Comments
 (0)