Documentation
¶
Overview ¶
Package gitutil provides git repository operations: cloning, pulling, commit tracking, origin metadata management, directory copying, and URL parsing.
Index ¶
- func Clone(repoURL, target, ref string) error
- func CopyDir(src, dst string) error
- func DeriveName(source, prefix string) string
- func HasOrigin(dir string) bool
- func HeadCommit(dir string) (string, error)
- func IsGitURL(source string) bool
- func Pull(dir, repoURL string) (oldCommit, newCommit string, err error)
- func ShortCommit(hash string) string
- func WriteOrigin(dir string, origin Origin) error
- type Origin
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Clone ¶
Clone clones a git repository into target with the auth chain. ref is optional (branch or tag name); empty means default branch.
func DeriveName ¶
DeriveName extracts a directory name from a git URL or path. Strips trailing .git, takes the last path segment, and removes the given prefix.
func HeadCommit ¶
HeadCommit returns the current HEAD commit hash of a git repo directory.
func Pull ¶
Pull fetches and pulls the latest changes for an existing git repo. Returns the old and new commit hashes.
func ShortCommit ¶
ShortCommit returns the first 12 characters of a commit hash.
func WriteOrigin ¶
WriteOrigin writes the origin sidecar file to a directory.
Types ¶
type Origin ¶
type Origin struct {
URL string `yaml:"url"`
Ref string `yaml:"ref,omitempty"`
Commit string `yaml:"commit,omitempty"`
Subpath string `yaml:"subpath,omitempty"`
}
Origin tracks where an installable entity was sourced from.
func FindOrigin ¶
FindOrigin walks up from dir looking for .origin.yaml. Returns the origin, the directory where it was found, and whether it was found.
func ReadOrigin ¶
ReadOrigin reads the origin sidecar file from a directory. Returns a zero-value Origin and an error if the file does not exist.