deps

package
v1.0.35 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package deps provides Git operations using go-git/v5 for dependency management.

Package deps provides artifact path discovery, cache operations, and reference resolution for SpecLedger dependencies.

The package handles: - Auto-discovery of artifact_path from SpecLedger repositories - Manual artifact_path specification for non-SpecLedger repos - Cache operations for ~/.specledger/cache/ - Reference resolution using alias:artifact syntax

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CacheDir

func CacheDir() (string, error)

CacheDir returns the global cache directory for SpecLedger dependencies. Defaults to ~/.specledger/cache/, but can be overridden via SPECLEDGER_CACHE_DIR env var.

func CachePathForDependency

func CachePathForDependency(alias, url string) (string, error)

CachePathForDependency returns the cache path for a specific dependency. Uses the alias if available, otherwise generates a directory name from the URL.

func Checkout

func Checkout(repo *git.Repository, ref string) error

Checkout checks out a specific commit or branch in a repository.

func Clone

func Clone(opts CloneOptions) (*git.Repository, string, error)

Clone clones a Git repository using go-git/v5. Returns the cloned repository and the resolved commit SHA.

func DetectArtifactPathFromRemote

func DetectArtifactPathFromRemote(repoURL, branch, cacheDir string) (string, error)

DetectArtifactPathFromRemote clones a repository (shallow clone for speed), reads its specledger.yaml, and returns the artifact_path value.

This is useful for detecting artifact_path before adding a dependency.

Parameters:

  • repoURL: Git repository URL
  • branch: Branch to clone (default "main")
  • cacheDir: Temporary directory for cloning

Returns:

  • artifact_path value from specledger.yaml
  • error if clone fails, not a SpecLedger repo, or artifact_path missing

func DetectArtifactPathFromSpecLedgerRepo

func DetectArtifactPathFromSpecLedgerRepo(repoPath string) (string, error)

DetectArtifactPathFromSpecLedgerRepo reads specledger.yaml from a local repository and returns the artifact_path value.

Parameters:

  • repoPath: Local path to the cloned repository

Returns:

  • artifact_path value from specledger.yaml
  • error if specledger.yaml not found or artifact_path is missing/empty

func Fetch

func Fetch(repo *git.Repository, branch string) error

Fetch fetches the latest changes from a repository.

func Log

func Log(repo *git.Repository, from, to string, limit int) (string, error)

Log returns commit log between two revisions. limit specifies the maximum number of commits to return (0 for unlimited).

func OpenRepository

func OpenRepository(path string) (*git.Repository, error)

OpenRepository opens an existing Git repository.

func Pull

func Pull(repo *git.Repository, branch string) (string, error)

Pull pulls the latest changes from a repository's remote branch.

func ResolveHead

func ResolveHead(repo *git.Repository) (string, error)

ResolveHead resolves the current HEAD commit of a repository.

func ResolveReference

func ResolveReference(projectArtifactPath, depAlias, artifactName, projectRoot string) (string, error)

ResolveReference resolves a dependency reference to a local file path.

The reference format is: <alias>:<artifact-name>

Resolution formula: <project.artifact_path> + "deps/" + <dependency.alias> + "/" + <artifact-name>

Example:

project.artifact_path: specledger/
dependency.alias: platform
artifact_name: api.md
Result: specledger/deps/platform/api.md

Parameters:

  • projectArtifactPath: The artifact_path from the project's specledger.yaml
  • depAlias: The alias of the dependency
  • artifactName: The name of the artifact file (e.g., "api.md", "openapi.yaml")
  • projectRoot: The root directory of the project (for absolute path resolution)

Returns:

  • The resolved file path (relative to project root)
  • An error if resolution fails

func ResolveReferenceWithCache

func ResolveReferenceWithCache(projectArtifactPath, depAlias, depArtifactPath, artifactName, projectRoot, cachePath string) (string, string, error)

ResolveReferenceWithCache resolves a dependency reference, checking both the project's artifact directory and the dependency's cache directory.

This is useful when artifacts from dependencies need to be copied or symlinked into the project's artifact directory.

Parameters:

  • projectArtifactPath: The artifact_path from the project's specledger.yaml
  • depAlias: The alias of the dependency
  • depArtifactPath: The artifact_path from the dependency's specledger.yaml
  • artifactName: The name of the artifact file
  • projectRoot: The root directory of the project
  • cachePath: The cache directory where the dependency is cloned

Returns:

  • The project-local resolved path (specledger/deps/<alias>/<artifact>)
  • The cache-resolved path (in the dependency's clone)
  • An error if resolution fails

func ResolveRemoteCommit

func ResolveRemoteCommit(repo *git.Repository, branch string) (string, error)

ResolveRemoteCommit resolves the commit SHA of a remote branch.

Types

type CloneOptions

type CloneOptions struct {
	URL       string // Repository URL
	Branch    string // Branch to clone (default "main")
	TargetDir string // Directory to clone to
	Shallow   bool   // Whether to do a shallow clone
}

CloneOptions contains options for cloning a dependency repository.

Jump to

Keyboard shortcuts

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