repomatic.metadata.git module¶

Git commit-range logic of Metadata.

Resolves the commit range an event bundles, the release commits inside it, what those commits changed, and the per-commit matrices. Every read goes through the git object store, so the checkout and the working tree never move.

repomatic.metadata.git.version_at(ref)[source]¶

Return the version bump-my-version manages, as committed at ref.

Reads BUMPVERSION_SOURCES from the object store, so a past commit is read without a checkout. A file that is absent at ref, or does not parse, is skipped like a file without the key.

Parameters:

ref (str) – The commit to read.

Return type:

str | None

Returns:

The current_version value, or None when no source holds one.

repomatic.metadata.git.commit_matrix(shas)[source]¶

Pre-compute a matrix of commits, in the order given.

Each entry carries the long and short SHA, and the version the commit declares, read by version_at(). Returns a ready-to-use matrix structure, here for a release push listing its commits oldest first:

{
    "commit": [
        "346ce664f055fbd042a25ee0b7e96702e95",
        "6f27db47612aaee06fdf08744b09a9f5f6c2",
    ],
    "include": [
        {
            "commit": "346ce664f055fbd042a25ee0b7e96702e95",
            "short_sha": "346ce66",
            "current_version": "2.0.0",
        },
        {
            "commit": "6f27db47612aaee06fdf08744b09a9f5f6c2",
            "short_sha": "6f27db4",
            "current_version": "2.0.1.dev0",
        },
    ],
}
Parameters:

shas (Sequence[str] | None) – Full commit SHAs.

Return type:

Matrix | None

Returns:

The matrix, or None when shas is empty.

class repomatic.metadata.git.GitMetadata[source]¶

Bases: object

Commit ranges, changed files, and the per-commit matrices.

A concern mixin of Metadata: never instantiated on its own, and reads sibling concerns through self.

property changed_files: tuple[str, ...] | None[source]¶

Returns the files changed in the current event’s commit range.

Diffs the trees of the two ends of commit_range. An end that is missing from a shallow clone is fetched first, on its own: the diff needs that commit’s tree, not the history in between.

Returns None when the range is unknown: outside CI, on a push that creates a branch or a tag (its start is NULL_SHA), or when git cannot produce an end of the range.

property binary_affecting_paths: tuple[str, ...][source]¶

Path prefixes that affect compiled binaries for this project.

Combines the static BINARY_AFFECTING_PATHS (common files like pyproject.toml, uv.lock, tests/) with the project’s source directories, from two places:

  • The top-level package of each [project.scripts] entry point. A project with mpm = "meta_package_manager.__main__:main" adds meta_package_manager/.

  • The [tool.repomatic] workflow.source-paths directories, or the import name they default to. This is what covers a src/ layout, whose package does not sit at the root the entry point names.

This makes the check reusable across downstream repositories without hardcoding source directories.

property head_commit_message: str[source]¶

Returns github.event.head_commit.message from the event payload.

Set for push events. Empty string for events that do not carry a head commit (pull_request, schedule, workflow_dispatch).

property yaml_changed: bool[source]¶

Whether the current event’s commit range touches a YAML file.

Lets per-job lint gates short-circuit on pushes / PRs that don’t touch YAML. Falls back to “repo contains any YAML file” when the commit range is unavailable (workflow_dispatch), preserving the existing behavior of those manual runs.

property shfmt_changed: bool[source]¶

Whether the current event’s commit range touches a shfmt_files file.

Gates the ShellCheck lint job, which reads the files shfmt formats. Falls back to “repo contains any such file” when the commit range is unavailable.

property zsh_changed: bool[source]¶

Whether the current event’s commit range touches a Zsh file.

Falls back to “repo contains any Zsh file” when the commit range is unavailable.

property workflows_changed: bool[source]¶

Whether the current event’s commit range touches a GitHub workflow file.

Falls back to “repo contains any workflow file” when the commit range is unavailable.

property skip_binary_build: bool[source]¶

Returns True if binary builds should be skipped for this event.

Binary builds are expensive and time-consuming. This property identifies contexts where the changes cannot possibly affect compiled binaries, allowing workflows to skip Nuitka compilation jobs.

Three mechanisms are checked:

  1. Branch name: PRs from known non-code branches (documentation, .mailmap, .gitignore, etc.) are skipped.

  2. Version-bump commit: Push events whose head commit is a user-initiated version bump (Bump (major|minor) version to) are skipped: the bump merge changes only version strings and uv.lock, so the new binary differs from the previous one only in the baked-in version string. The [changelog] Post-release bump prefix is deliberately not checked here: the prepare-release merge bundles the release commit with the post-release-bump commit, and the release commit must still produce its binary.

  3. Changed files: Push events where all changed files fall outside binary_affecting_paths are skipped. This avoids ~2h of Nuitka builds for documentation-only commits to main.

property commit_range: tuple[str | None, str] | None[source]¶

Range of commits bundled within the triggering event.

A workflow run is triggered by a singular event, which might encapsulate one or more commits. This means the workflow will only run once on the last commit, even if multiple new commits were pushed.

This is critical for releases where two commits are pushed together:

  1. [changelog] Release vX.Y.Z: the release commit

  2. [changelog] Post-release bump vX.Y.Z → vX.Y.Z: the post-release bump

Without extracting the full commit range, the release commit would be missed since github.event.head_commit only exposes the post-release bump.

This property also enables processing each commit individually when we want to keep a carefully constructed commit history. The typical example is a pull request that is merged upstream but we’d like to produce artifacts (builds, packages, etc.) for each individual commit.

The default GITHUB_SHA environment variable is not enough as it only points to the last commit. We need to inspect the commit history to find all new ones. New commits need to be fetched differently in push and pull_request events.

See also

Pull request events on GitHub are a bit complex, see: The Many SHAs of a GitHub Pull Request.

property current_commit_matrix: Matrix | None[source]¶

Pre-computed matrix with long and short SHA values of the current commit.

property new_commits: tuple[Commit, ...] | None[source]¶

Returns list of all Commit objects bundled within the triggering event.

This extracts all commits from the push event, not just head_commit. For releases, this typically includes both the release commit and the post-release bump commit, allowing downstream jobs to process each one.

Commits are returned in chronological order (oldest first, most recent last).

A shallow clone is completed as far as the range needs: both ends are fetched, then the clone is deepened until they share history. See deepen_until_related() for why both ends being present is not enough.

property new_commits_matrix: Matrix | None[source]¶

Pre-computed matrix with long and short SHA values of new commits.

property release_commits: tuple[Commit, ...] | None[source]¶

Returns list of Commit objects to be tagged within the triggering event.

This filters new_commits to find release commits that need special handling: tagging, PyPI publishing, and GitHub release creation.

This is essential because when a release is pushed, github.event.head_commit only exposes the post-release bump commit, not the release commit. By extracting all commits from the event (via new_commits) and filtering for release commits here, we ensure the release workflow can properly identify and process the [changelog] Release vX.Y.Z commit.

We cannot identify a release commit based on the presence of a vX.Y.Z tag alone. That’s because the tag is not present in the prepare-release pull request produced by the changelog.yaml workflow. The tag is created later by the release.yaml workflow, when the pull request is merged to main.

Our best option is to identify a release based on the full commit message, using the template from the changelog.yaml workflow.

property release_commits_matrix: Matrix | None[source]¶

Pre-computed matrix with long and short SHA values of release commits.

property is_release_push: bool[source]¶

Whether the event lands release commits on the release branch.

The test every job that tags, attests or publishes runs before it acts: a release commit reached through another ref (a manual run on a feature branch) must not publish anything.

property release_commit: str | None[source]¶

The commit a job checks out to work on the tree being released.

A rebase-merged release pull request pushes the freeze commit and the post-release bump together, so the event’s own commit already carries the next .devN version. This is the newest release commit of the event, and the event’s own commit when it carries none.

release_commits lists the commits oldest first, so the newest one is the last.