Skip to content

feat(parser): support abbreviated SHAs in commit parsers - #1642

Merged
orhun merged 2 commits into
orhun:mainfrom
yuefdev:feat/abbreviated-commit-parser-sha
Oct 31, 2026
Merged

orhun merged 2 commits into
orhun:mainfrom
yuefdev:feat/abbreviated-commit-parser-sha

Conversation

@yuefdev

@yuefdev yuefdev commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Description

The sha of a commit parser can now be an abbreviated SHA (at least 4 characters). Before the commits are processed, each parser SHA is expanded to the full SHA of the commit it matches:

  • a SHA that equals a commit id is used as is (no change for existing configs)
  • an abbreviated SHA that matches exactly one commit is expanded to that commit's full SHA
  • an abbreviated SHA that matches more than one commit is an error, like in git: commit parser SHA `076f` is ambiguous, it matches 3 commits
  • SHAs shorter than 4 characters, or ones that match nothing, are left alone as before

The resolution happens once in Changelog::process_commits, so Commit::parse still does an exact comparison.

Motivation and Context

Closes #1638. git cliff -vv prints short SHAs, so it's handy to be able to paste them into commit_parsers directly.

How Has This Been Tested?

  • New unit tests changelog_resolves_abbreviated_commit_parser_shas and changelog_rejects_ambiguous_commit_parser_sha.
  • cargo test --workspace (full clone): everything passes except open_jujutsu_repo and discover_jujutsu_repo, which fail the same way on main on Windows (path canonicalization).
  • Manually, on this repo's history with a config using { sha = "<short>", group = "Picked" }:
    • f07a7c8 picks that commit.
    • 076f fails with the ambiguity error (3 commits share that prefix).
    • 076fc85 picks the intended commit.

Types of Changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (no code change)
  • Refactor (refactoring production code)
  • Other

Checklist:

  • My code follows the code style of this project.
  • I have updated the documentation accordingly (if applicable).
  • I have formatted the code with rustfmt.
    • cargo +nightly fmt --all
  • I checked the lints with clippy.
    • cargo clippy --tests --verbose -- -D warnings (no warnings from this change; on Windows the only error is the unused super::* in command.rs, whose test is Unix-only)
  • I have added tests to cover my changes.
  • All new and existing tests passed.
    • cargo test

The `sha` of a commit parser can now be an abbreviated SHA (at least 4
characters), e.g. the short SHA printed by `git cliff -vv`. It is
expanded to the full SHA of the matching commit before the commits are
processed. Like git, an abbreviated SHA that matches more than one
commit is an error.

Closes orhun#1638
@yuefdev
yuefdev requested a review from orhun as a code owner September 14, 2026 07:38
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.07692% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 53.37%. Comparing base (28c8bab) to head (41ad6ec).

Files with missing lines Patch % Lines
git-cliff-core/src/changelog.rs 73.08% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1642      +/-   ##
==========================================
+ Coverage   53.22%   53.37%   +0.16%     
==========================================
  Files          28       28              
  Lines        2631     2657      +26     
==========================================
+ Hits         1400     1418      +18     
- Misses       1231     1239       +8     
Flag Coverage Δ
unit-tests 53.37% <73.08%> (+0.16%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@orhun orhun left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

LGTM, thanks!

@orhun
orhun merged commit a81737c into orhun:main Oct 31, 2026
114 of 117 checks passed
@welcome

welcome Bot commented Oct 31, 2026

Copy link
Copy Markdown

Congrats on merging your first pull request! ⛰️

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.

Support short SHAs in commit_parsers

3 participants