Documentation
¶
Overview ¶
Package gitx runs the system git binary for a workspace. Chapar does not bundle a git implementation: the user's git knows their credentials, hooks and config, and gives the same results as their terminal.
Index ¶
- Constants
- Variables
- func AskPass(args []string, out io.Writer) int
- func ForgetAuth(remote string) error
- func IsHTTP(remote string) bool
- func SaveAuth(remote string, a Auth) error
- type Auth
- type Branch
- type Change
- type ChangeKind
- type Commit
- type ExitError
- type Git
- type Op
- type Repo
- func (r *Repo) Abort(ctx context.Context, op Op) error
- func (r *Repo) Branches(ctx context.Context) ([]Branch, error)
- func (r *Repo) Commit(ctx context.Context, message string, changes []Change) (string, error)
- func (r *Repo) CommitChanges(ctx context.Context, c Commit) ([]Change, error)
- func (r *Repo) CommitDiff(ctx context.Context, c Commit, ch Change) ([]byte, error)
- func (r *Repo) ConflictVersions(ctx context.Context, path string) (Versions, error)
- func (r *Repo) Contained() bool
- func (r *Repo) Continue(ctx context.Context, op Op) error
- func (r *Repo) CreateBranch(ctx context.Context, name string) error
- func (r *Repo) Diff(ctx context.Context, c Change) ([]byte, error)
- func (r *Repo) Discard(ctx context.Context, c Change) error
- func (r *Repo) Fetch(ctx context.Context, auth Auth) error
- func (r *Repo) HasCommits(ctx context.Context) bool
- func (r *Repo) Identity(ctx context.Context) (name, email string)
- func (r *Repo) InProgress(ctx context.Context) (Op, string)
- func (r *Repo) Log(ctx context.Context, n int) ([]Commit, error)
- func (r *Repo) Merge(ctx context.Context, ref string) (bool, error)
- func (r *Repo) Pull(ctx context.Context, auth Auth, st *Status) (bool, error)
- func (r *Repo) Push(ctx context.Context, auth Auth, st *Status) error
- func (r *Repo) Remote(ctx context.Context) (name, url string, err error)
- func (r *Repo) Resolve(ctx context.Context, path string, data []byte) error
- func (r *Repo) Revert(ctx context.Context, c Commit) (bool, error)
- func (r *Repo) SetIdentity(ctx context.Context, name, email string) error
- func (r *Repo) SetRemote(ctx context.Context, url string) error
- func (r *Repo) ShowFile(ctx context.Context, rev, path string) ([]byte, error)
- func (r *Repo) Status(ctx context.Context) (*Status, error)
- func (r *Repo) Switch(ctx context.Context, b Branch) error
- type Status
- type Versions
Constants ¶
const (
AskPassEnv = "CHAPAR_GIT_ASKPASS"
)
Environment variables that pass credentials to the askpass helper. The helper is the chapar binary itself, run by git with AskPassEnv set.
Variables ¶
var ErrAuth = errors.New("the remote needs a user name and token")
ErrAuth means the remote refused the credentials, or git needed some and had none.
var ErrDiverged = errors.New("this branch and the remote both have new commits")
ErrDiverged means a pull can't fast-forward: both sides have new commits.
var ErrNoUpstream = errors.New("the remote has no branch to pull from")
ErrNoUpstream means the branch doesn't track a remote branch and the remote has no branch of the same name.
var ErrNotInstalled = errors.New("git is not installed")
ErrNotInstalled means no working git binary was found.
var ErrNotRepo = errors.New("not a git repository")
ErrNotRepo means the directory is not inside a git work tree.
var ErrRejected = errors.New("the remote has commits this branch doesn't have; pull first")
ErrRejected means the remote has commits the local branch lacks.
Functions ¶
func AskPass ¶
AskPass answers a git credential prompt from the environment: the user name for a "Username for ..." prompt, the token for a "Password for ..." one. It returns the exit code; git treats a non-zero code as no answer.
func ForgetAuth ¶
ForgetAuth removes the credentials saved for remote's server.
Types ¶
type Auth ¶
Auth is a user name and token (or password) for an HTTPS remote. The zero Auth leaves authentication to the user's own git setup: credential helpers, SSH keys and agents.
type Branch ¶
type Branch struct {
// Name is "main" for a local branch, "origin/main" for a remote one.
Name string
Remote bool
Current bool
// Upstream is the remote branch a local branch tracks, or "".
Upstream string
}
Branch is a local branch, or a remote one with no local branch of the same name.
type Change ¶
type Change struct {
// Path is relative to the workspace, with forward slashes.
Path string
// OrigPath is the path before a rename. It is "" when the file was
// renamed from outside the workspace.
OrigPath string
Kind ChangeKind
// Staged and Unstaged are git's X and Y status letters, '.' for none.
Staged, Unstaged byte
}
Change is a file that differs from the last commit, staged or not.
type ChangeKind ¶
type ChangeKind int
ChangeKind is how a file differs from the last commit.
const ( Modified ChangeKind = iota Added Deleted Renamed Untracked Conflicted )
func (ChangeKind) String ¶
func (k ChangeKind) String() string
type Commit ¶
type Commit struct {
Hash string
Short string
Parents []string
Author string
Email string
When time.Time
Subject string
}
Commit is one entry of the history.
type Git ¶
type Git struct {
// contains filtered or unexported fields
}
Git is a git binary that was found and runs.
func Find ¶
Find looks git up on PATH, then in the places installers put it, and checks that it runs. A GUI app may start with a shorter PATH than a shell, and on Windows it keeps the PATH it started with after git is installed. On macOS /usr/bin/git is a stub that fails until the command line tools are installed, so finding the file is not enough.
func (*Git) Init ¶
Init makes dir the root of a new repository. A git that has no default branch configured starts on main.
type Repo ¶
type Repo struct {
// Dir is the workspace directory.
Dir string
// Root is the top of the work tree.
Root string
// contains filtered or unexported fields
}
Repo is a workspace directory inside a git work tree. The work tree may be the workspace itself or a directory above it; paths Repo takes and returns are relative to the workspace and use forward slashes.
func (*Repo) Abort ¶
Abort gives up the operation in progress and puts the branch and files back as they were before it.
func (*Repo) Branches ¶
Branches lists the local branches, then the remote branches no local branch tracks.
func (*Repo) Commit ¶
Commit records the changes, and only them, with message. Other changes, staged or not, are left as they are. It returns the new commit's id.
func (*Repo) CommitChanges ¶
CommitChanges lists the workspace files c changed, compared with its first parent.
func (*Repo) CommitDiff ¶
CommitDiff is the patch c made to one file.
func (*Repo) ConflictVersions ¶
ConflictVersions reads the common ancestor's, this branch's and the incoming version of a conflicted file.
func (*Repo) Contained ¶
Contained reports whether the work tree is the workspace itself rather than a directory above it.
func (*Repo) Continue ¶
Continue records the operation in progress once its conflicts are resolved, with git's own commit message for it.
func (*Repo) CreateBranch ¶
CreateBranch starts a branch named name at HEAD and checks it out.
func (*Repo) Diff ¶
Diff is the patch from the last commit to the work tree for one change, staged and unstaged edits together.
func (*Repo) Discard ¶
Discard puts a changed file back the way the last commit has it: an edited or deleted file is restored, a new file is deleted.
func (*Repo) HasCommits ¶
HasCommits reports whether HEAD points at a commit. It is false in a repository nobody has committed to yet.
func (*Repo) Identity ¶
Identity is the name and email commits are made with, from any level of git config. Either is "" when it is not set.
func (*Repo) InProgress ¶
InProgress reports the operation git stopped in, for the user to finish or abort, and its message (the merge or revert commit's first line).
func (*Repo) Log ¶
Log returns up to n commits that touched the workspace, newest first. It returns no commits, and no error, before the first commit.
func (*Repo) Merge ¶
Merge merges ref, such as "origin/main", into the current branch. It reports whether git stopped with conflicts for the user to resolve; the merge is then in progress.
func (*Repo) Pull ¶
Pull brings in the remote branch's new commits when the local branch has none of its own. A branch with no upstream starts tracking the remote's branch of the same name. It reports whether HEAD moved.
func (*Repo) Push ¶
Push sends the branch's commits to the remote. A branch with no upstream is pushed to the remote branch of the same name and tracks it.
func (*Repo) Remote ¶
Remote is the repository's remote: origin, or the first one when there is no origin. Both are "" when the repository has none.
func (*Repo) Resolve ¶
Resolve settles a conflicted file with data, or deletes it when data is nil, and marks it resolved.
func (*Repo) Revert ¶
Revert makes a commit that undoes c. A merge commit is undone against its first parent. It reports whether git stopped with conflicts.
func (*Repo) SetIdentity ¶
SetIdentity sets the name and email for commits in this repository only.
func (*Repo) SetRemote ¶
SetRemote points origin, or the remote Remote returns, at url, adding origin when the repository has no remote.
type Status ¶
type Status struct {
// Branch is the checked out branch, or "" when HEAD is detached.
Branch string
// Head is the commit HEAD points at, or "" before the first commit.
Head string
// Upstream is the branch Branch tracks, such as "origin/main", or "".
Upstream string
// Ahead and Behind count commits against Upstream.
Ahead, Behind int
// Changes are the files in the workspace that differ from Head.
Changes []Change
}
Status is the state of the work tree and its branch.