On this page
Does a go.mod's module path still name where the repository lives? The expected path is origin plus the module's directory, major-version suffix included.
#rlsbl.go_identity
#rlsbl.go_identity
Does a go.mod's module path still name where the repository lives?
A Go module path is not decoration: it is the URL the toolchain fetches from. When a repository is renamed, moved between owners, or absorbed into a monorepo under a new subdirectory, every go.mod in it keeps declaring the OLD path until someone rewrites it -- and a module published under a path that no longer resolves is a module nobody can go get. rlsbl rewrite go-module-path exists to perform that rewrite; this check is what notices it is owed.
What the expected path is -------------------------
The repository's own origin remote, plus the module's directory inside the repository::
[email protected]:owner/repo.git + services/api -> github.com/owner/repo/services/api
Two spellings of the same remote (https://github.com/owner/repo.git and [email protected]:owner/repo.git) normalize to the same identity, so the comparison never depends on how the remote was cloned.
A major-version suffix is part of the module path, not a mismatch: Go requires /v2 and up on the module path itself, so github.com/owner/repo/v2 is accepted where github.com/owner/repo is expected. Go's other major-version layout -- a v2/ DIRECTORY inside the repository -- already puts that element in the expected path, and the suffix is then not accepted a second time.
What it refuses to guess ------------------------
- No origin remote -- there is no identity to compare against, so the check
SKIPS and says so. Inventing one from the directory name is exactly the wrong answer, because the directory name is not the published identity.
- An SSH host alias (
git@gp:owner/repo.git, wheregpis a
~/.ssh/config Host entry, not a domain) names no host that a module path could start with. Rather than guessing github.com, the host segment is left unverified and only the OWNER/REPO/SUBDIRECTORY tail is compared -- the part that actually moves when a repository is renamed. The outcome message says the host was not verified, so a passing result never claims more than it checked.
#RepoIdentity
Where a repository lives, as its origin remote states it.
#host_is_a_domain
def host_is_a_domain(self)True when the remote names something a module path can start with.
An SSH alias (gp) has no dot; every real forge host does.
#parse_remote
def parse_remote(url)Return the :class:RepoIdentity a remote URL states, or None.
Both spellings are normalized to the same (host, owner/repo): an SCP remote ([email protected]:owner/repo.git) and a URL remote (https://github.com/owner/repo.git, ssh://[email protected]/owner/repo).
#expected_module_path
def expected_module_path(identity, subdirectory)The module path a module at subdirectory of this repository owns.
#strip_major_suffix
def strip_major_suffix(module_path)module_path without its trailing /vN (N >= 2), if it has one.
#module_matches
def module_matches(actual, expected_full, expected_tail, *, host_verified)Does actual declare the expected identity?
When the host could not be derived from the remote (an SSH alias), the module's own first segment is accepted as the host and only the tail is compared -- see the module docstring.
A /vN element is accepted on top of the expected path, because Go requires it on the module path and the repository layout does not have to carry it. It is NOT accepted twice: when the module already sits in a vN/ DIRECTORY the expected path ends in that element already, and .../repo/v2/v2 is not a spelling of anything.
#with_major_suffix
def with_major_suffix(expected, actual)expected carrying the /vN element actual declares, if it may.
The suffix is Go's, not the repository's, so a rewrite has to preserve it -- unless the expected path already ends in one, which is the major subdirectory layout and would otherwise be doubled.
#GoIdentityVerdict
Result of comparing every Go module in one repository against origin.
#ok
def ok(self)#read_module_line
def read_module_line(go_mod_path)The module directive of go_mod_path, or None when it has none.
#evaluate_go_module_identity
def evaluate_go_module_identity(repo_root, module_dirs, remote_url)Compare each module's declared path against the repository's identity.
module_dirs are absolute directories expected to contain a go.mod. remote_url is the origin remote URL, or None when the repository has no origin -- which skips, rather than guessing an identity.