Skip to main content

Pre-commit hook that checks and maintains .mailmap completeness

Project description

mailmap-checker

PyPI version Python versions CI License: MIT

A pre-commit hook that detects unmapped Git identities by comparing your .mailmap against the full commit history. It groups authors and committers by email address and email local-part so duplicates are caught even across domain changes.

Follows the gitmailmap specification: all four mapping formats are supported, and both names and emails are matched case-insensitively.

How it works

The checker scans git log for all unique author and committer identities and groups them using two rules:

Rule 1 — Same email (case-insensitive)

Identities that share the exact same email address are the same person.

Alice Johnson <alice@acme.com>
alice.j       <alice@acme.com>   ← same email, grouped together

Rule 2 — Same email local-part (different domain)

Identities whose email local-part (the part before @) and name match are likely the same person who changed companies or used a different address. Local-parts shorter than 8 characters are automatically skipped to reduce false positives.

Alice Johnson <alice.johnson@acme.com>
Alice Johnson <alice.johnson@oldcorp.com>    ← same local-part + name, grouped

Once groups are built, the checker looks for identities that are not mapped in .mailmap. If a group has more than one identity and any of them is missing from the file, the hook fails and reports the gap.

Example

Given these identities in git history and an empty .mailmap:

Alice Johnson <alice.johnson@acme.com>
Alice Johnson <alice.johnson@oldcorp.com>
alice.j       <alice.johnson@acme.com>

mailmap-checker check detects the gap:

  Canonical: Alice Johnson <alice.johnson@acme.com> (42 commits)
    - Alice Johnson <alice.johnson@oldcorp.com> (15 commits)
    - alice.j <alice.johnson@acme.com> (3 commits)

Found 2 unmapped identities in 1 group (canonical chosen by name heuristic
— prefers names that start with a letter and contain a space
(e.g. 'Jane Doe' over 'jdoe')).

Tip: Use --by-commit-count to choose canonical by highest commit count.

mailmap-checker fix --dry-run suggests entries to add:

Suggested .mailmap entries (canonical chosen by name heuristic):

  Alice Johnson <alice.johnson@acme.com> Alice Johnson <alice.johnson@oldcorp.com>
  Alice Johnson <alice.johnson@acme.com> alice.j <alice.johnson@acme.com>

Disabling local-part matching

If Rule 2 produces false positives on very large repositories, disable it with --no-local-part-matching.

Installation

Pre-commit hook (recommended)

# .pre-commit-config.yaml
repos:
  - repo: https://github.com/cansarigol/mailmap-checker
    rev: ""  # run: pre-commit autoupdate
    hooks:
      - id: mailmap-check

Then run pre-commit autoupdate to pin the latest release.

Available hooks

Hook ID Description
mailmap-check Fail if any identity is missing from .mailmap
mailmap-fix Automatically add missing entries to .mailmap
mailmap-fix-dry-run Preview suggested entries without modifying the file

Standalone

pip install mailmap-checker

Usage

check

Scan all Git authors and committers and exit non-zero if any identity is missing from .mailmap.

mailmap-checker check

init

Create a .mailmap file (if it does not exist) and run a full check.

mailmap-checker init

fix

Preview or apply suggested .mailmap entries. New entries are inserted in sorted order and the existing blank-line style of the file is preserved (separator-style files keep separators; compact files stay compact).

The canonical identity for each group is chosen by a name heuristic — preferring names that look like real person names (e.g. Alice Johnson) over usernames (alicej), git config artifacts (--global), or handle-style names (@username). Use --by-commit-count to choose the identity with the most commits instead.

# Preview
mailmap-checker fix --dry-run

# Apply
mailmap-checker fix

# Choose canonical by commit count
mailmap-checker fix --by-commit-count

Common options

Flag Description
--mailmap <path> Custom .mailmap file path (default: git config mailmap.file, then .mailmap)
--git-dir <path> Path to git repository (default: current directory)
--no-local-part-matching Disable grouping by email local-part across domains
--by-commit-count Choose canonical identity by highest commit count instead of name heuristic

Contributing

git clone https://github.com/cansarigol/mailmap-checker.git
cd mailmap-checker
uv sync
uv run poe setup   # installs pre-commit and commit-msg hooks
uv run poe check    # lint + security + tests

Commits must follow Conventional Commits with a required scope (e.g. feat(cli): add --verbose flag).

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mailmap_checker-0.3.3.tar.gz (18.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mailmap_checker-0.3.3-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file mailmap_checker-0.3.3.tar.gz.

File metadata

  • Download URL: mailmap_checker-0.3.3.tar.gz
  • Upload date:
  • Size: 18.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for mailmap_checker-0.3.3.tar.gz
Algorithm Hash digest
SHA256 05f763c1681a6b54d2edb702308893c0828ac64fee1e2dfc944550eca5cefe5e
MD5 2354916c76192fa84fb0ce87d2c317bc
BLAKE2b-256 3debfb0bca105398c44caeb939daf41931745f09c6291c78fcec0845e208570c

See more details on using hashes here.

File details

Details for the file mailmap_checker-0.3.3-py3-none-any.whl.

File metadata

  • Download URL: mailmap_checker-0.3.3-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for mailmap_checker-0.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 37e445e016a69c9b138f314c509e2d9557aa0a67cf52daf204242b5775cb131e
MD5 e1d3c387900b992be607a39cf9968242
BLAKE2b-256 7142494a2bf92605d5365f36b0e628fc59e905db30cd305503ae48bb0564afd7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page