Skip to content

test(git): add tests for get_filenames_in_commit with git_reference#1890

Open
HankyStyle wants to merge 1 commit intocommitizen-tools:masterfrom
HankyStyle:test/add-get-filenames-in-commit-tests
Open

test(git): add tests for get_filenames_in_commit with git_reference#1890
HankyStyle wants to merge 1 commit intocommitizen-tools:masterfrom
HankyStyle:test/add-get-filenames-in-commit-tests

Conversation

@HankyStyle
Copy link
Contributor

Description

Add missing test coverage for the get_filenames_in_commit function.

This PR adds:

  • test_get_filenames_in_commit: happy path test without git_reference, verifying correct filenames are returned from the last commit
  • test_get_filenames_in_commit_with_git_reference: happy path test with a specific commit SHA as git_reference, verifying only files from that specific commit are returned

Closes #1860

Checklist

Was generative AI tooling used to co-author this PR?

  • Yes
    Generated-by: Claude Opus 4.6 + Antigravity

Code Changes

  • Add test cases to all the changes you introduce
  • Run uv run poe all locally to ensure this change passes linter check and tests
  • Manually test the changes:
    • Verify the feature/bug fix works as expected in real-world scenarios
    • Test edge cases and error conditions
    • Ensure backward compatibility is maintained
    • Document any manual testing steps performed
  • Update the documentation for the changes

Documentation Changes

  • Run uv run poe doc locally to ensure the documentation pages renders correctly
  • Check and fix any broken links (internal or external)

Expected Behavior

Running uv run pytest tests/test_git.py -k "get_filenames_in_commit" should pass all 3 tests:

  1. test_get_filenames_in_commit — returns correct filename from the last commit
  2. test_get_filenames_in_commit_with_git_reference — returns only files from the specified commit SHA, not from other commits
  3. test_get_filenames_in_commit_error — raises GitCommandError when git command fails (existing test, unchanged)

Steps to Test This Pull Request

  1. Checkout the branch
  2. Run the specific tests:
    uv run pytest tests/test_git.py::test_get_filenames_in_commit tests/test_git.py::test_get_filenames_in_commit_with_git_reference tests/test_git.py::test_get_filenames_in_commit_error -v
    
  3. All 3 tests should pass

Additional Context

Related issue: #1860

@codecov
Copy link

codecov bot commented Mar 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.99%. Comparing base (4fbeae7) to head (926911d).
⚠️ Report is 9 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1890   +/-   ##
=======================================
  Coverage   97.99%   97.99%           
=======================================
  Files          60       60           
  Lines        2689     2689           
=======================================
  Hits         2635     2635           
  Misses         54       54           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

util.create_file_and_commit("feat: add new feature", filename=filename)

filenames = git.get_filenames_in_commit()
assert filename in filenames
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it be

Suggested change
assert filename in filenames
assert [filename] == filenames

instead?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

and probably add another commit with more files to validate the behavior that the function only resolves filenames from the last commit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing test for get_filenames_in_commit with git_reference

3 participants