git

package
v0.4.59 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2026 License: Apache-2.0 Imports: 11 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 Clone

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

Clone clones one branch of url into dir.

func DefaultBranch

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

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

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 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 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 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 to commit, keeping local changes git can keep. Only a rollback or a revert uses it.

func Subject

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

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

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