git

package
v0.4.88 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package git runs the host's git binary for apps deployed from their repository. It knows nothing about CasaOS apps: a folder, a URL, a branch and a way in.

Index

Constants

View Source
const (
	AccessNone  = "none"
	AccessKey   = "key"
	AccessToken = "token"
)

How a remote is reached.

Variables

View Source
var ErrNoSSHClient = errors.New("the ssh client is not installed on this machine")

ErrNoSSHClient is the answer for a deploy key on a machine that cannot use one.

Functions

func AddWorktree

func AddWorktree(ctx context.Context, dir, commit, path string, auth Auth) error

AddWorktree checks commit out, detached, at path, submodules included.

func Attach added in v0.4.62

func Attach(ctx context.Context, dir, branch string) error

Attach puts the work tree at dir on branch, made or moved to the commit it is on: no file moves.

func Clone

func Clone(ctx context.Context, url, branch, dir string, auth Auth) error

Clone clones one branch of url into dir, or one tag, which leaves it in detached HEAD.

func DefaultBranch

func DefaultBranch(ctx context.Context, url string, auth Auth) (string, error)

DefaultBranch is the branch the remote's HEAD points to.

func Detach added in v0.4.62

func Detach(ctx context.Context, dir string) error

Detach leaves the work tree at dir in detached HEAD on the commit it is on: no file and no branch moves.

func DropKeptCommit added in v0.4.62

func DropKeptCommit(ctx context.Context, dir, commit string) error

DropKeptCommit removes the ref KeepCommit made for commit.

func FastForward

func FastForward(ctx context.Context, dir, commit string) error

FastForward moves the checked-out branch forward to commit, and refuses anything else.

func Fetch

func Fetch(ctx context.Context, dir, url, branch string, auth Auth) (string, error)

Fetch fetches the branch from url into dir and returns the commit it points at.

func FetchCommit added in v0.4.62

func FetchCommit(ctx context.Context, dir, url, commit string, auth Auth) error

FetchCommit fetches commit itself from url into dir. Not every forge serves a commit by its hash: one that does not refuses it.

func FetchTag added in v0.4.62

func FetchTag(ctx context.Context, dir, url, tag string, auth Auth) (string, error)

FetchTag fetches the tag from url into dir and returns the commit it names, an annotated tag peeled. No local ref is written.

func HasCommit

func HasCommit(ctx context.Context, dir, commit string) bool

HasCommit reports whether the repository at dir holds commit.

func IsAncestor

func IsAncestor(ctx context.Context, dir, ancestor, descendant string) (bool, error)

IsAncestor reports whether ancestor is descendant or one of its ancestors.

func IsTracked

func IsTracked(ctx context.Context, dir, path string) (bool, error)

IsTracked reports whether path is a tracked file of the work tree at dir.

func KeepCommit added in v0.4.62

func KeepCommit(ctx context.Context, dir, commit string) error

KeepCommit makes dir keep commit, whatever becomes of the refs that brought it.

func KeptCommits added in v0.4.62

func KeptCommits(ctx context.Context, dir string) ([]string, error)

KeptCommits is every commit dir keeps a ref for.

func LsRemote

func LsRemote(ctx context.Context, url, branch string, auth Auth) (string, error)

LsRemote is the commit the branch points at on the remote.

func LsRemoteTags added in v0.4.62

func LsRemoteTags(ctx context.Context, url string, auth Auth) (map[string]string, error)

LsRemoteTags is every tag of the remote and the commit it names. An annotated tag comes twice: its plain line names the tag object, its peeled line `<name>^{}` the commit, which wins. A name that is no valid ref name is left out, so that it never reaches git. So is a line whose hash is no commit hash: a ref name with a newline in it, which a hostile remote can advertise, makes ls-remote print a line of its own that starts with anything.

func Prune

func Prune(ctx context.Context, dir string) error

Prune forgets the worktrees whose folder is gone.

func RemoveWorktree

func RemoveWorktree(ctx context.Context, dir, path string) error

RemoveWorktree removes a worktree AddWorktree made, and what git knows of it.

func ResetKeep

func ResetKeep(ctx context.Context, dir, commit string) error

ResetKeep moves the checked-out branch, or a detached HEAD, to commit, keeping local changes git can keep. A rollback, a revert, a redeployment, a first deployment and every move of an app that follows tags use it: tags do not form a line.

func Subject

func Subject(ctx context.Context, dir, commit string) (string, error)

Subject is the first line of a commit's message.

func ValidRefName added in v0.4.62

func ValidRefName(name string) bool

ValidRefName is a name git reads as a branch or a tag name: not an option, not a revision expression (`..`, `@`, `@{`, `~`, `^`), and no character a ref name forbids. Empty passes: a caller that needs a name checks that itself.

Types

type Auth

type Auth struct {
	Mode           string
	KeyPath        string
	KnownHostsPath string
	Token          string
	// AskpassDir is where a token's askpass helper is written, in a folder of its own that
	// goes after each command. Not /tmp, which may be mounted noexec.
	AskpassDir string
}

Auth is how a remote is reached. It becomes environment, never arguments.

type Error

type Error struct {
	Command string
	Output  string
	Err     error
}

Error is a git command that failed, with what it printed. A token never appears in it.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type Info

type Info struct {
	Toplevel  string
	RemoteURL string
	// Branch is empty in detached HEAD.
	Branch string
	// Head is empty before the first commit.
	Head              string
	TrackedFilesClean bool
}

Info is what a work tree says about itself.

func Describe

func Describe(ctx context.Context, dir string) (Info, error)

Describe says what the work tree at dir is on.

Jump to

Keyboard shortcuts

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