scope

package
v2.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 1, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeGlobal = lockfile.ScopeGlobal
	TypeRepo   = lockfile.ScopeRepo
	TypePath   = lockfile.ScopePath
)

Re-export scope type constants from lockfile for convenience

Variables

This section is empty.

Functions

func AliasResolvedForm added in v2.3.1

func AliasResolvedForm(repoURL string) string

AliasResolvedForm returns the normalized form of an SSH remote with its host replaced by the HostName from ~/.ssh/config, or "" when the URL is not an SSH remote or no alias mapping applies. Callers use it both as a match candidate and to tell the user their host is remapped locally.

func CanonicalizeStoredRepoRow added in v2.3.1

func CanonicalizeStoredRepoRow(stored string) string

CanonicalizeStoredRepoRow returns the modern canonical form of an EXISTING stored scope row: a legacy ported row collapses to its portless reading, everything else to the plain normalization. For migrations (sx vault copy) that re-persist stored rows through the user-input write paths — those paths apply NormalizeRepoURL, which would turn "gitea.corp.com:3000/acme/x" into the dead slash form "gitea.corp.com/3000/acme/x" that no reading reconciles. Never use this on live user input: a userless numeric segment in fresh input is kept literal by design (see splitSCPLike).

func CleanRepoURL added in v2.3.1

func CleanRepoURL(repoURL string) string

CleanRepoURL applies the shared pre-normalization cleanup: trim, lowercase, and drop a trailing slash and ".git". Every function that inspects repo URL structure must clean through here so host extraction and normalization can never diverge.

func GetInstallLocations

func GetInstallLocations(asset *lockfile.Asset, currentScope *Scope, repoRoot, globalBase string) []string

GetInstallLocations returns all installation base directories for an asset in the current context An asset can have multiple installation locations if it has multiple repository entries

func LooksLikeSameRepo added in v2.3.1

func LooksLikeSameRepo(remote, stored string) bool

LooksLikeSameRepo reports whether the caller's remote and a stored scope repo name the same owner/repo path even though they don't fully match — the signature of a host form that failed to normalize (an unresolvable alias, a different host for the same project). Full matches, including via the stored side's legacy ported reading, return false.

func MatchRepoURLs

func MatchRepoURLs(url1, url2 string) bool

MatchRepoURLs checks if two repository URLs refer to the same repository. Each side is expanded into its normalized candidate set (the URL as written, plus its SSH alias resolution if one applies) and the URLs match when any candidates coincide. Comparing candidate sets means alias resolution can only widen matching — it never breaks a pair that already matched on the literal host.

func MatchStoredRepoURL added in v2.3.1

func MatchStoredRepoURL(stored, remote string) bool

MatchStoredRepoURL reports whether a stored scope row names the same repository as the caller's remote. On top of the symmetric MatchRepoURLs comparison, the STORED side alone is also read under its legacy ported form ("gitea.corp.com:3000/acme/x", written by the pre-alias normalizer which kept ports) — asymmetric so a live remote with a genuine numeric path segment is never reinterpreted.

func NormalizeRepoURL

func NormalizeRepoURL(repoURL string) string

NormalizeRepoURL normalizes a repository URL for comparison. All transports of the same repository reduce to "host/owner/repo": scp-style SSH remotes (git@host:owner/repo or host:owner/repo) are handled for any host, and userinfo, ports, a trailing ".git", and trailing slashes are dropped. Note that dropping the port collapses distinct git servers hosted on different ports of one hostname — the deliberate trade that lets ssh://host:2222/x match https://host/x. Strings that don't look like a URL are returned cleaned but otherwise as-is.

func NormalizeRepoURLCandidates added in v2.3.1

func NormalizeRepoURLCandidates(repoURL string) []string

NormalizeRepoURLCandidates returns every normalized form repoURL can take: the plain normalization and, when the URL is an SSH remote whose host is an alias defined in the user's ~/.ssh/config, the normalization with the alias replaced by its configured HostName. A remote like git@workgit:acme/x (Host workgit / HostName github.com) therefore also yields github.com/acme/x. The legacy ported reading is deliberately NOT included — only stored vault rows can carry that pre-alias shape, so it is expanded exclusively on the stored side (MatchStoredRepoURL); reinterpreting a live remote's numeric path segment would create false matches.

func SetSSHHostLookup added in v2.3.1

func SetSSHHostLookup(fn func(alias string) (string, bool)) (restore func())

SetSSHHostLookup replaces the ~/.ssh/config hostname lookup and returns a func restoring the previous one. Test seam only: it lets suites in other packages stay hermetic instead of parsing the developer's real ssh config through the process-wide cache.

func StoredRepoRowMatches added in v2.3.1

func StoredRepoRowMatches(stored, needle string) bool

StoredRepoRowMatches reports whether a stored repo row and a user-supplied needle name the same repository, for vault WRITE paths: normalized equality plus the stored row's legacy ported reading, and deliberately no ~/.ssh/config involvement so the same mutation resolves identically on every machine.

Types

type Matcher

type Matcher struct {
	// contains filtered or unexported fields
}

Matcher matches assets based on scope

func NewMatcher

func NewMatcher(currentScope *Scope) *Matcher

NewMatcher creates a new scope matcher

func (*Matcher) MatchesAsset

func (m *Matcher) MatchesAsset(asset *lockfile.Asset) bool

MatchesAsset checks if an asset should be installed in the current scope An asset matches if: - It's global (no scopes) OR - It has a scope entry that matches the current context

func (*Matcher) NearMissScope added in v2.3.1

func (m *Matcher) NearMissScope(asset *lockfile.Asset) (repo string, ok bool)

NearMissScope returns the first repo scope of an asset that failed scope matching yet names the same owner/repo path as the current repo — possibly a URL-form mismatch (unresolvable SSH alias, unexpected host), possibly a genuinely different host carrying the same project path. Callers surface it so the user can make that call, as opposed to an asset simply scoped to a different repo.

type Scope

type Scope struct {
	Type     lockfile.ScopeType // TypeGlobal, TypeRepo, or TypePath
	RepoURL  string             // Repository URL (if in a repo)
	RepoPath string             // Path relative to repo root (if applicable)
}

Scope represents the current working context

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL