Skip to content

feat: lint commit message from hash range#22

Open
JustBipin wants to merge 3 commits into
opensource-nepal:mainfrom
JustBipin:feat/hash-range
Open

feat: lint commit message from hash range#22
JustBipin wants to merge 3 commits into
opensource-nepal:mainfrom
JustBipin:feat/hash-range

Conversation

@JustBipin
Copy link
Copy Markdown
Member

@JustBipin JustBipin commented May 19, 2026

Adds --from-hash and --to-hash flags to lint all commit messages between two commits, inclusive.

Usage

cocox --from-hash <hash>              # from <hash> to HEAD
cocox --from-hash <hash> --to-hash <hash>   # explicit range

Feature

  • --from-hash and --to-hash flags added to the CLI
  • --to-hash defaults to HEAD when not provided
  • --to-hash requires --from-hash and is mutually exclusive with message, --file, and --hash
  • src/git_helpers.rs: added get_commit_messages_from_hash_range() which fetches all commit messages in the range and prepends the from commit separately, since A..B in git excludes A

Test infrastructure

  • tests/common/git_repo.rs: introduces TestRepo, a temporary git repo with minimal config for use in integration tests
    • TestRepo::new() switches the process working directory into the temp repo
    • Drop restores the original working directory when TestRepo goes out of scope
    • A static Mutex is acquired on construction and released on drop, serializing all tests that use TestRepo to prevent race conditions on the process-global cwd
  • serial_test = "3" added as a dev-dependency
  • Unit tests in src/git_helpers.rs that depended on the project repo's own git history replaced with integration tests in tests/git_helpers.rs using TestRepo, so tests are self-contained and repo-state independent

Integration tests added

  • tests/git_helpers.rs: full coverage of get_commit_message_from_hash and get_commit_messages_from_hash_range with known commit messages
  • tests/cli.rs: success and failure cases for --hash (exact hash, invalid message, ignored message) and --from-hash/--to-hash (invalid commit at from, middle, and to positions; ignored commits in range; single-commit range)
  • tests/cli.rs: extended mutual exclusion tests covering all missing argument combinations (message + --hash, message + --from-hash, --hash + --from-hash, --to-hash with non---from-hash inputs)

TestCoverage: 97%

closes: #10, #12

JustBipin added 3 commits May 19, 2026 14:52
- remove projecet's git dependent tests from src/git_helpers.rs
    * dev-dependency added: `serial_test = "3"` for blocking threads

    - `tests/common/git_repo.rs` to create temporary git repo
    - `src/git_helpers.rs`: replaced project's git dependent unittests
      with integrationtests in tests/git_helpers.rs
    - improved integration tests for --hash flag
    - added integration tests for  hash-range feature

    - extend Cli argument constrains test
        - mutual exclusion of message + --hash (opensource-nepal#12)
- from-hash and to-hash are exclusive to : message, hash, file
- to-hash requires from-hash and from-hash only
@aj3sh aj3sh requested a review from sugat009 May 19, 2026 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: strengthen --hash test with a fixture commit

1 participant