gitutil

package
v0.0.0-beta Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package gitutil provides git repository operations: cloning, pulling, commit tracking, origin metadata management, directory copying, and URL parsing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clone

func Clone(repoURL, target, ref string) error

Clone clones a git repository into target with the auth chain. ref is optional (branch or tag name); empty means default branch.

func CopyDir

func CopyDir(src, dst string) error

CopyDir recursively copies a directory tree from src to dst.

func DeriveName

func DeriveName(source, prefix string) string

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 HasOrigin

func HasOrigin(dir string) bool

HasOrigin returns true if the directory has a valid origin sidecar with a URL.

func HeadCommit

func HeadCommit(dir string) (string, error)

HeadCommit returns the current HEAD commit hash of a git repo directory.

func IsGitURL

func IsGitURL(source string) bool

IsGitURL returns true if the source looks like a git URL (HTTP/SSH).

func Pull

func Pull(dir, repoURL string) (oldCommit, newCommit string, err error)

Pull fetches and pulls the latest changes for an existing git repo. Returns the old and new commit hashes.

func ShortCommit

func ShortCommit(hash string) string

ShortCommit returns the first 12 characters of a commit hash.

func WriteOrigin

func WriteOrigin(dir string, origin Origin) error

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

func FindOrigin(dir string) (Origin, string, bool)

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

func ReadOrigin(dir string) (Origin, error)

ReadOrigin reads the origin sidecar file from a directory. Returns a zero-value Origin and an error if the file does not exist.

Jump to

Keyboard shortcuts

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