Documentation
¶
Index ¶
- func EnsureDurableRepoID(root string) (string, error)
- func HashFingerprint(material string) string
- func LegacyFingerprint(absRoot, rawRemoteURL string) string
- func NormalizeRemoteURL(raw string) string
- func RemoteFingerprint(rawURL string) string
- func SameRemoteIdentity(a, b string) bool
- type FakeGitRepo
- func (g *FakeGitRepo) CommonGitDir(root string) (string, error)
- func (g *FakeGitRepo) Discover(cwd string) (string, error)
- func (g *FakeGitRepo) Fingerprint(root string) (string, error)
- func (g *FakeGitRepo) GetFingerprintComponents(root string) (string, string, error)
- func (g *FakeGitRepo) IsIgnored(cwd string, relPaths []string) (map[string]bool, error)
- func (g *FakeGitRepo) RelPath(root, absPath string) (string, error)
- func (g *FakeGitRepo) SetError(err error)
- func (g *FakeGitRepo) SetIgnored(paths ...string)
- func (g *FakeGitRepo) SetUsername(username string)
- func (g *FakeGitRepo) Username(root string) string
- type GitRepo
- type RealGitRepo
- func (g *RealGitRepo) CommonGitDir(root string) (string, error)
- func (g *RealGitRepo) Discover(cwd string) (string, error)
- func (g *RealGitRepo) Fingerprint(root string) (string, error)
- func (g *RealGitRepo) GetFingerprintComponents(root string) (string, string, error)
- func (g *RealGitRepo) IsIgnored(cwd string, relPaths []string) (map[string]bool, error)
- func (g *RealGitRepo) RelPath(root, absPath string) (string, error)
- func (g *RealGitRepo) Username(root string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnsureDurableRepoID ¶ added in v0.3.0
EnsureDurableRepoID returns the durable repository ID, creating one if needed.
Preference:
- repoRoot/.monodev/repo-id when the .monodev directory exists
- <git-common-dir>/monodev/repo-id
A newly generated ID is written to the git-common-dir location, and also to .monodev/repo-id when that directory already exists.
func HashFingerprint ¶ added in v0.3.0
HashFingerprint hashes identity material with SHA-256 hex encoding.
func LegacyFingerprint ¶ added in v0.3.0
LegacyFingerprint is the pre-change fingerprint: SHA-256 of absRoot + "|" + rawRemoteURL. Missing remotes used the literal "unknown".
func NormalizeRemoteURL ¶ added in v0.3.0
NormalizeRemoteURL returns a canonical form of a git remote URL so that equivalent checkouts hash to the same repository fingerprint.
The normalizer:
- strips scheme, userinfo/credentials, query, and fragment
- lowercases the host
- drops default ports (22, 80, 443)
- strips a trailing ".git" suffix and trailing slashes
- treats git@host:org/repo and https://host/org/repo.git as identical
Local paths and file:// URLs are cleaned and have ".git"/trailing slashes stripped, but are not host-lowercased.
func RemoteFingerprint ¶ added in v0.3.0
RemoteFingerprint is the current remote-based fingerprint for a raw git URL.
func SameRemoteIdentity ¶ added in v0.3.0
SameRemoteIdentity reports whether two raw git remote URLs name the same repository.
It is the comparison counterpart of NormalizeRemoteURL: two remotes match when they normalize identically, and additionally when both are absolute local paths that resolve to the same location on this filesystem. The second rule covers aliases such as macOS `/tmp` -> `/private/tmp`, or a symlinked checkout parent, which normalization alone cannot collapse because it never touches the filesystem.
Filesystem resolution is deliberately kept out of NormalizeRemoteURL: that function feeds repository fingerprints, which must stay stable and reproducible without disk access. An empty identity is never equivalent to anything, so unknown remotes fail closed.
Types ¶
type FakeGitRepo ¶
type FakeGitRepo struct {
// contains filtered or unexported fields
}
FakeGitRepo implements GitRepo with predetermined values for testing.
func NewFakeGitRepo ¶
func NewFakeGitRepo(root, fingerprint string) *FakeGitRepo
NewFakeGitRepo creates a new FakeGitRepo.
func NewFakeGitRepoWithComponents ¶ added in v0.2.2
func NewFakeGitRepoWithComponents(root, fingerprint, absPath, gitURL string) *FakeGitRepo
NewFakeGitRepoWithComponents creates a new FakeGitRepo with custom components.
func (*FakeGitRepo) CommonGitDir ¶ added in v0.3.0
func (g *FakeGitRepo) CommonGitDir(root string) (string, error)
CommonGitDir returns the conventional metadata location beneath the fake repository root.
func (*FakeGitRepo) Discover ¶
func (g *FakeGitRepo) Discover(cwd string) (string, error)
Discover returns the predetermined root.
func (*FakeGitRepo) Fingerprint ¶
func (g *FakeGitRepo) Fingerprint(root string) (string, error)
Fingerprint returns the predetermined fingerprint.
func (*FakeGitRepo) GetFingerprintComponents ¶ added in v0.2.2
func (g *FakeGitRepo) GetFingerprintComponents(root string) (string, string, error)
GetFingerprintComponents returns the predetermined components.
func (*FakeGitRepo) IsIgnored ¶ added in v0.3.0
IsIgnored reports the predetermined ignored set, or nothing ignored by default.
func (*FakeGitRepo) RelPath ¶
func (g *FakeGitRepo) RelPath(root, absPath string) (string, error)
RelPath computes the relative path (works like real implementation).
func (*FakeGitRepo) SetError ¶
func (g *FakeGitRepo) SetError(err error)
SetError sets an error to be returned by all methods.
func (*FakeGitRepo) SetIgnored ¶ added in v0.3.0
func (g *FakeGitRepo) SetIgnored(paths ...string)
SetIgnored configures which relative paths IsIgnored reports as ignored.
func (*FakeGitRepo) SetUsername ¶ added in v0.2.5
func (g *FakeGitRepo) SetUsername(username string)
SetUsername sets the username to return from Username().
func (*FakeGitRepo) Username ¶ added in v0.2.5
func (g *FakeGitRepo) Username(root string) string
Username returns the predetermined username or "user".
type GitRepo ¶
type GitRepo interface {
// Discover finds the git repository root starting from cwd.
Discover(cwd string) (root string, err error)
// CommonGitDir resolves the shared git directory, including when root is a
// linked worktree whose .git entry is a file.
CommonGitDir(root string) (string, error)
// Fingerprint computes a stable fingerprint for the repository.
Fingerprint(root string) (string, error)
// RelPath computes the relative path from repo root to the given absolute path.
RelPath(root, absPath string) (string, error)
// GetFingerprintComponents returns the absolute path and git URL used to compute the fingerprint.
GetFingerprintComponents(root string) (absPath string, gitURL string, err error)
// Username returns the GitHub username derived from the remote origin URL,
// or falls back to git config user.name. Returns "user" if neither is available.
Username(root string) string
// IsIgnored reports which of the given paths (relative to cwd) are
// excluded by standard git ignore rules (.gitignore, .git/info/exclude,
// global excludes). Paths not present in the result are not ignored.
IsIgnored(cwd string, relPaths []string) (map[string]bool, error)
}
GitRepo provides an abstraction for git repository operations.
type RealGitRepo ¶
type RealGitRepo struct{}
RealGitRepo implements GitRepo using actual git commands.
func (*RealGitRepo) CommonGitDir ¶ added in v0.3.0
func (g *RealGitRepo) CommonGitDir(root string) (string, error)
CommonGitDir returns the repository's shared git directory. Git owns the indirection for linked worktrees, so do not infer this from root/.git.
func (*RealGitRepo) Discover ¶
func (g *RealGitRepo) Discover(cwd string) (string, error)
Discover finds the git repository root by walking up from cwd looking for .git directory.
func (*RealGitRepo) Fingerprint ¶
func (g *RealGitRepo) Fingerprint(root string) (string, error)
Fingerprint computes a stable fingerprint for the repository.
Identity precedence:
- Durable repo ID (`.monodev/repo-id`, else git-common-dir `monodev/repo-id`)
- Normalized remote URL (origin, otherwise the first `git remote`)
- Newly persisted durable ID for a git repo with no remotes
- Absolute path for non-git directories
The clone's absolute path is not part of (1)–(3), so moving a clone does not change the fingerprint. A linked git worktree shares the repo-identity material with the main checkout (same durable ID / remote), but a worktree-specific suffix is mixed in afterward so the two never collide — see worktreeDiscriminator.
func (*RealGitRepo) GetFingerprintComponents ¶ added in v0.2.2
func (g *RealGitRepo) GetFingerprintComponents(root string) (string, string, error)
GetFingerprintComponents returns the absolute repository path and the raw origin URL (empty when origin is unset). The fingerprint no longer hashes these values directly; callers use them for display and legacy migration.
func (*RealGitRepo) IsIgnored ¶ added in v0.3.0
IsIgnored reports which of relPaths (interpreted relative to cwd) are excluded by git's ignore rules, using a single batched `git check-ignore` call. A failure to run git (e.g. cwd is not inside a repository) is returned as an error; callers that want best-effort behavior should treat that as "nothing is ignored" rather than failing discovery outright.
func (*RealGitRepo) RelPath ¶
func (g *RealGitRepo) RelPath(root, absPath string) (string, error)
RelPath computes the relative path from repo root to the given absolute path.
func (*RealGitRepo) Username ¶ added in v0.2.5
func (g *RealGitRepo) Username(root string) string
Username returns the GitHub username from the remote origin URL, falling back to git config user.name, then "user".