rlsbl v0.92.0 /rlsbl.git_util
On this page

Shared git path-filtering utilities: get_commit_files, file_matches_project with path prefix and watch globs, and filter_commits_for_project.

#rlsbl.git_util

#rlsbl.git_util

Shared path-filtering utilities for matching commits to projects.

Provides functions to retrieve files changed by a commit, check whether a file belongs to a project (by path prefix or watch globs), filter a set of commits to those touching a specific project's files, validate SSH host consistency between origin and subtree remotes, and detect manual pushes to release branches.

#get_commit_files

python
def get_commit_files(sha)

Get the list of files changed by a single commit.

Returns a list of file paths relative to the repo root, or None on error.

#file_matches_project

python
def file_matches_project(filepath, project)

Check whether a file path belongs to a project.

A file belongs to a project if:

  • It starts with the project's path prefix, OR
  • It matches any of the project's watch globs

#filter_commits_for_project

python
def filter_commits_for_project(commits, project)

Filter commits to only those that touch files belonging to a project.

Takes a set of commit SHAs and a project dict. For each commit, gets its changed files and checks whether any file matches the project (by path prefix or watch globs).

Returns the subset of commits where at least one file belongs to the project.

#filter_commits_for_releasable

python
def filter_commits_for_releasable(commits, member_projects)

Filter commits to those touching files in any of the member projects.

Like filter_commits_for_project but accepts a list of projects (the members of a releasable). Calls get_commit_files() once per commit and checks in-memory against the combined path prefixes and watch globs of all member projects.

Args:

  • commits: set of commit SHAs to filter.
  • member_projects: list of project dicts/WorkspaceProject instances,

each with path and optionally watch keys.

Returns:

  • The subset of commits where at least one file belongs to any
  • member project.

#extract_ssh_host

python
def extract_ssh_host(git_url)

Extract the SSH host from a git URL.

Supports SCP-like syntax (git@host:owner/repo.git) and explicit SSH URLs (ssh://git@host/owner/repo.git). Returns the host string, or None for HTTPS URLs, empty strings, or unparseable formats.

#validate_subtree_remote_ssh_host

python
def validate_subtree_remote_ssh_host(subtree_remote, project_root)

Validate that subtree_remote and origin use the same SSH host.

Hard error (sys.exit(1)) when both URLs are SSH and their hosts differ. Silently passes when either URL is not SSH or when origin cannot be read.

#get_push_changed_files

python
def get_push_changed_files(refs)

Get the list of files changed across all pushed refs.

Takes a list of (local_sha, remote_sha) tuples (as returned by _parse_stdin_refs in pre_push_check.py).

Returns a set of file paths relative to the repo root, or None if git commands fail.

#affected_projects

python
def affected_projects(changed_files, projects)

Determine which projects are affected by the changed files.

Returns a list of project dicts that have at least one changed file matching their path prefix or watch globs.

#detect_manual_push_branches

python
def detect_manual_push_branches(stdin_lines, release_branches)

Return list of release branch names being pushed to manually.

Parses pre-push hook stdin lines for refs/heads/ patterns and returns branch names that match release_branches.

Returns an empty list if no release branches are being pushed to, if stdin_lines is empty/None, or if RLSBL_RELEASE_PUSH is set (indicating a legitimate release push).